Workflow artifact in distribution notification
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / utils / InterfaceOperationUtils.java
index 2727a8b..0ee6264 100644 (file)
@@ -23,9 +23,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
-
+import java.util.stream.Collectors;
 import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.MapUtils;
+import org.apache.commons.collections4.MapUtils;
 import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
@@ -180,4 +180,11 @@ public class InterfaceOperationUtils {
                 ? fullOutputIdentifier.substring(fullOutputIdentifier.lastIndexOf('.') + 1)
                 : fullOutputIdentifier;
     }
+
+    public static boolean isArtifactInUse(Component component, String operationId, String artifactUniqueId) {
+        return MapUtils.emptyIfNull(component.getInterfaces()).values().stream()
+                       .filter(o -> MapUtils.isNotEmpty(o.getOperations()) && !o.getOperations().containsKey(operationId))
+                       .flatMap(o -> o.getOperations().values().stream()).collect(Collectors.toList()).stream()
+                       .anyMatch(op -> op.getImplementation().getUniqueId().equals(artifactUniqueId));
+    }
 }