Merge "Add test for ApplicationConfig"
[nonrtric.git] / policy-agent / src / main / java / org / oransc / policyagent / repository / Rics.java
index 6b8138f..6f3b3e8 100644 (file)
@@ -20,9 +20,9 @@
 
 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;
 
@@ -36,11 +36,11 @@ public class Rics {
         rics.put(ric.name(), ric);
     }
 
-    public Collection<Ric> getRics() {
+    public synchronized Iterable<Ric> getRics() {
         return rics.values();
     }
 
-    public Ric getRic(String name) throws ServiceException {
+    public synchronized Ric getRic(String name) throws ServiceException {
         Ric ric = rics.get(name);
         if (ric == null) {
             throw new ServiceException("Could not find ric: " + name);
@@ -48,15 +48,28 @@ public class Rics {
         return ric;
     }
 
-    public Ric get(String name) {
+    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();
+    }
 }