Adding tenant relationship and generic vnf post endpoints
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / aai-simulator / src / main / java / org / onap / so / aaisimulator / service / providers / GenericVnfCacheServiceProviderImpl.java
index 472ca17..fed79d8 100644 (file)
@@ -80,22 +80,6 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv
         return Optional.empty();
     }
 
-    @Override
-    public boolean addRelationShip(final String vnfId, final Relationship relationship) {
-        final Optional<GenericVnf> optional = getGenericVnf(vnfId);
-        if (optional.isPresent()) {
-            final GenericVnf genericVnf = optional.get();
-            RelationshipList relationshipList = genericVnf.getRelationshipList();
-            if (relationshipList == null) {
-                relationshipList = new RelationshipList();
-                genericVnf.setRelationshipList(relationshipList);
-            }
-            return relationshipList.getRelationship().add(relationship);
-        }
-        LOGGER.error("Unable to find GenericVnf ...");
-        return false;
-    }
-
     @Override
     public Optional<String> getGenericVnfId(final String vnfName) {
         final Cache cache = getCache(GENERIC_VNF_CACHE.getName());
@@ -133,7 +117,13 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv
                         outGoingRelationShip, targetUrl, Relationship.class);
                 if (optionalRelationship.isPresent()) {
                     final Relationship resultantRelationship = optionalRelationship.get();
-                    if (addRelationShip(vnfId, resultantRelationship)) {
+
+                    RelationshipList relationshipList = genericVnf.getRelationshipList();
+                    if (relationshipList == null) {
+                        relationshipList = new RelationshipList();
+                        genericVnf.setRelationshipList(relationshipList);
+                    }
+                    if (relationshipList.getRelationship().add(resultantRelationship)) {
                         LOGGER.info("added relationship {} in cache successfully", resultantRelationship);
                         return true;
                     }
@@ -146,6 +136,40 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv
         return false;
     }
 
+    @Override
+    public Optional<Relationship> addRelationShip(final String vnfId, final Relationship relationship,
+            final String requestURI) {
+        final Optional<GenericVnf> optional = getGenericVnf(vnfId);
+        if (optional.isPresent()) {
+            final GenericVnf genericVnf = optional.get();
+            RelationshipList relationshipList = genericVnf.getRelationshipList();
+            if (relationshipList == null) {
+                relationshipList = new RelationshipList();
+                genericVnf.setRelationshipList(relationshipList);
+            }
+            relationshipList.getRelationship().add(relationship);
+            LOGGER.info("Successfully added relation to GenericVnf for vnfId: {}", vnfId);
+
+            final Relationship resultantRelationship = getRelationship(requestURI, genericVnf);
+            return Optional.of(resultantRelationship);
+        }
+        return Optional.empty();
+    }
+
+    @Override
+    public boolean patchGenericVnf(final String vnfId, final GenericVnf genericVnf) {
+        final Optional<GenericVnf> optional = getGenericVnf(vnfId);
+        if (optional.isPresent()) {
+            final GenericVnf cachedGenericVnf = optional.get();
+            LOGGER.info("Changing OrchestrationStatus from {} to {} ", cachedGenericVnf.getOrchestrationStatus(),
+                    genericVnf.getOrchestrationStatus());
+            cachedGenericVnf.setOrchestrationStatus(genericVnf.getOrchestrationStatus());
+            return true;
+        }
+        LOGGER.error("Unable to find GenericVnf ...");
+        return false;
+    }
+
     private String getTargetUrl(final String targetBaseUrl, final String relatedLink) {
         return UriComponentsBuilder.fromUriString(targetBaseUrl).path(relatedLink)
                 .path(BI_DIRECTIONAL_RELATIONSHIP_LIST_URL).toUriString();