package org.oransc.policyagent.repository;
-import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
+
+import org.oransc.policyagent.exceptions.ServiceException;
/**
* Dynamic representation of all Rics in the system.
public class Rics {
Map<String, Ric> rics = new HashMap<>();
- public void put(Ric ric) {
+ public synchronized void put(Ric ric) {
rics.put(ric.name(), ric);
}
- public Collection<Ric> getRics() {
+ public synchronized Iterable<Ric> getRics() {
return rics.values();
}
- public Ric getRic(String name) {
+ public synchronized Ric getRic(String name) throws ServiceException {
+ Ric ric = rics.get(name);
+ if (ric == null) {
+ throw new ServiceException("Could not find ric: " + name);
+ }
+ return ric;
+ }
+
+ public synchronized Ric get(String name) {
return rics.get(name);
}
- public int size() {
+ public synchronized void remove(String name) {
+ rics.remove(name);
+ }
+
+ public synchronized int size() {
return rics.size();
}
- public void clear() {
+ public synchronized void clear() {
this.rics.clear();
}
+
+ public synchronized Optional<Ric> lookupRicForManagedElement(String managedElementId) {
+ for (Ric ric : this.rics.values()) {
+ if (ric.getConfig().managedElementIds().contains(managedElementId)) {
+ return Optional.of(ric);
+ }
+ }
+ return Optional.empty();
+ }
}