2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 Nordix Foundation
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
21 package org.oransc.enrichment.repository;
23 import java.util.Collection;
24 import java.util.HashMap;
26 import java.util.Vector;
28 import org.oransc.enrichment.exceptions.ServiceException;
31 * Dynamic representation of all existing EI jobs.
34 private Map<String, EiJob> allEiJobs = new HashMap<>();
36 private MultiMap<EiJob> jobsByType = new MultiMap<>();
37 private MultiMap<EiJob> jobsByOwner = new MultiMap<>();
39 public synchronized void put(EiJob job) {
40 allEiJobs.put(job.id(), job);
41 jobsByType.put(job.type().getId(), job.id(), job);
42 jobsByOwner.put(job.owner(), job.id(), job);
45 public synchronized Collection<EiJob> getJobs() {
46 return new Vector<>(allEiJobs.values());
49 public synchronized EiJob getJob(String id) throws ServiceException {
50 EiJob ric = allEiJobs.get(id);
52 throw new ServiceException("Could not find EI job: " + id);
57 public synchronized Collection<EiJob> getJobsForType(String typeId) {
58 return jobsByType.get(typeId);
61 public synchronized Collection<EiJob> getJobsForType(EiType type) {
62 return jobsByType.get(type.getId());
65 public synchronized Collection<EiJob> getJobsForOwner(String owner) {
66 return jobsByOwner.get(owner);
69 public synchronized EiJob get(String id) {
70 return allEiJobs.get(id);
73 public synchronized EiJob remove(String id) {
74 EiJob job = allEiJobs.get(id);
81 public synchronized void remove(EiJob job) {
82 this.allEiJobs.remove(job.id());
83 jobsByType.remove(job.type().getId(), job.id());
84 jobsByOwner.remove(job.owner(), job.id());
87 public synchronized int size() {
88 return allEiJobs.size();
91 public synchronized void clear() {
92 this.allEiJobs.clear();
93 this.jobsByType.clear();