Service Import - Node Template Interface Definitions
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / impl / ServiceImportParseLogic.java
index 507f4ad..8cc5bd6 100644 (file)
  */
 package org.openecomp.sdc.be.components.impl;
 
-import static java.util.stream.Collectors.joining;
-import static java.util.stream.Collectors.toList;
-import static java.util.stream.Collectors.toMap;
-import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
-
 import fj.data.Either;
-import java.util.ArrayList;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.Function;
 import lombok.Getter;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.collections.CollectionUtils;
@@ -52,6 +37,7 @@ import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
@@ -88,6 +74,7 @@ import org.openecomp.sdc.be.model.Service;
 import org.openecomp.sdc.be.model.UploadCapInfo;
 import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
 import org.openecomp.sdc.be.model.UploadInfo;
+import org.openecomp.sdc.be.model.UploadInterfaceInfo;
 import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
 import org.openecomp.sdc.be.model.UploadPropInfo;
 import org.openecomp.sdc.be.model.UploadReqInfo;
@@ -116,6 +103,22 @@ import org.openecomp.sdc.exception.ResponseFormat;
 import org.yaml.snakeyaml.DumperOptions;
 import org.yaml.snakeyaml.Yaml;
 
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
+
+import static java.util.stream.Collectors.joining;
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
+
 @Getter
 @org.springframework.stereotype.Component
 public class ServiceImportParseLogic {
@@ -2003,6 +2006,32 @@ public class ServiceImportParseLogic {
         }
     }
 
+    public void associateComponentInstanceInterfacesToComponent(
+            String yamlName,
+            Service service,
+            Map<String, Map<String, InterfaceDefinition>> instInterfaces
+    ) {
+        if (MapUtils.isNotEmpty(instInterfaces)) {
+            Either<Map<String, MapInterfaceDataDefinition>, StorageOperationStatus> addInterfaceToInst =
+                    toscaOperationFacade
+                    .associateComponentInstanceInterfacesToComponent(
+                            instInterfaces,
+                            service.getUniqueId()
+                    );
+            if (addInterfaceToInst.isRight()) {
+                log.error("failed to associate interfaces value of service {}, status is {}", service.getUniqueId(), addInterfaceToInst.right().value());
+                throw new ComponentException(
+                    componentsUtils.getResponseFormat(
+                        componentsUtils.convertFromStorageResponse(
+                            addInterfaceToInst.right().value()
+                        ),
+                        yamlName
+                    )
+                );
+            }
+        }
+    }
+
     public void associateDeploymentArtifactsToInstances(User user, String yamlName, Resource resource,
                                                         Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts) {
         StorageOperationStatus addArtToInst = toscaOperationFacade.associateDeploymentArtifactsToInstances(instDeploymentArtifacts, resource, user);