Merge "Update postman collection to utilize newest yang files"
[cps.git] / cps-ncmp-service / src / main / java / org / onap / cps / ncmp / api / impl / utils / AlternateIdChecker.java
index 4ac6537..f14439f 100644 (file)
@@ -38,6 +38,10 @@ import org.springframework.stereotype.Service;
 @RequiredArgsConstructor
 public class AlternateIdChecker {
 
+    public enum Operation {
+        CREATE, UPDATE
+    }
+
     private final InventoryPersistence inventoryPersistence;
 
     private static final String NO_CURRENT_ALTERNATE_ID = "";
@@ -96,15 +100,16 @@ public class AlternateIdChecker {
     }
 
     /**
-     * Check all alternate ids of a batch of NEW cm handles.
+     * Check all alternate ids of a batch of cm handles.
      * Includes cross-checks in the batch itself for duplicates. Only the first entry encountered wil be accepted.
-     * This method can only be used for NEW cm handle registrations NOT for updating existing ones
      *
      * @param newNcmpServiceCmHandles the proposed new cm handles
+     * @param operation type of operation being executed
      * @return collection of cm handles ids which are acceptable
      */
     public Collection<String> getIdsOfCmHandlesWithRejectedAlternateId(
-                                    final Collection<NcmpServiceCmHandle> newNcmpServiceCmHandles) {
+                                    final Collection<NcmpServiceCmHandle> newNcmpServiceCmHandles,
+                                    final Operation operation) {
         final Set<String> acceptedAlternateIds = new HashSet<>(newNcmpServiceCmHandles.size());
         final Collection<String> rejectedCmHandleIds = new ArrayList<>();
         for (final NcmpServiceCmHandle ncmpServiceCmHandle : newNcmpServiceCmHandles) {
@@ -119,7 +124,11 @@ public class AlternateIdChecker {
                     log.warn("Alternate id update ignored, cannot update cm handle {}, alternate id is already "
                         + "assigned to a different cm handle (in this batch)", cmHandleId);
                 } else {
-                    isAcceptable = canApplyAlternateId(cmHandleId, NO_CURRENT_ALTERNATE_ID, proposedAlternateId);
+                    if (Operation.CREATE.equals(operation)) {
+                        isAcceptable = canApplyAlternateId(cmHandleId, NO_CURRENT_ALTERNATE_ID, proposedAlternateId);
+                    } else {
+                        isAcceptable = canApplyAlternateId(cmHandleId, proposedAlternateId);
+                    }
                 }
             }
             if (isAcceptable) {