Merge "Added STD sim 2.0.0 tests"
[nonrtric.git] / policy-agent / src / main / java / org / oransc / policyagent / repository / Rics.java
index 6b8138f..7faa376 100644 (file)
@@ -23,6 +23,8 @@ package org.oransc.policyagent.repository;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Optional;
+import java.util.Vector;
 
 import org.oransc.policyagent.exceptions.ServiceException;
 
@@ -30,33 +32,46 @@ import org.oransc.policyagent.exceptions.ServiceException;
  * Dynamic representation of all Rics in the system.
  */
 public class Rics {
-    Map<String, Ric> rics = new HashMap<>();
+    Map<String, Ric> registeredRics = new HashMap<>();
 
     public synchronized void put(Ric ric) {
-        rics.put(ric.name(), ric);
+        registeredRics.put(ric.name(), ric);
     }
 
-    public Collection<Ric> getRics() {
-        return rics.values();
+    public synchronized Collection<Ric> getRics() {
+        return new Vector<>(registeredRics.values());
     }
 
-    public Ric getRic(String name) throws ServiceException {
-        Ric ric = rics.get(name);
+    public synchronized Ric getRic(String name) throws ServiceException {
+        Ric ric = registeredRics.get(name);
         if (ric == null) {
             throw new ServiceException("Could not find ric: " + name);
         }
         return ric;
     }
 
-    public Ric get(String name) {
-        return rics.get(name);
+    public synchronized Ric get(String name) {
+        return registeredRics.get(name);
     }
 
-    public int size() {
-        return rics.size();
+    public synchronized void remove(String name) {
+        registeredRics.remove(name);
     }
 
-    public void clear() {
-        this.rics.clear();
+    public synchronized int size() {
+        return registeredRics.size();
+    }
+
+    public synchronized void clear() {
+        this.registeredRics.clear();
+    }
+
+    public synchronized Optional<Ric> lookupRicForManagedElement(String managedElementId) {
+        for (Ric ric : this.registeredRics.values()) {
+            if (ric.getManagedElementIds().contains(managedElementId)) {
+                return Optional.of(ric);
+            }
+        }
+        return Optional.empty();
     }
 }