From 8d59b022d1b35a4549ff4a1f3aeea0c11214c6fb Mon Sep 17 00:00:00 2001 From: JvD_Ericsson Date: Thu, 19 Oct 2023 15:48:27 +0100 Subject: Unable to import service template with interface Issue-ID: SDC-4661 Signed-off-by: JvD_Ericsson Change-Id: Ic7146428502a3f3eb976f6d347a5611b301776ed --- .../impl/ServiceImportBusinessLogic.java | 40 ++++++++++++++++------ 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'catalog-be/src/main') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java index d4f67ec13d..8671d9e27a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java @@ -221,10 +221,10 @@ public class ServiceImportBusinessLogic { private final GroupTypeOperation groupTypeOperation; private final CapabilityTypeImportManager capabilityTypeImportManager; private final CapabilityTypeOperation capabilityTypeOperation; - private ApplicationDataTypeCache applicationDataTypeCache; private final InterfaceLifecycleOperation interfaceLifecycleTypeOperation; private final InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager; private final ModelOperation modelOperation; + private ApplicationDataTypeCache applicationDataTypeCache; public ServiceImportBusinessLogic(final GroupBusinessLogic groupBusinessLogic, final ArtifactsBusinessLogic artifactsBusinessLogic, final ComponentsUtils componentsUtils, final ToscaOperationFacade toscaOperationFacade, @@ -2190,7 +2190,7 @@ public class ServiceImportBusinessLogic { private List addImplicitAttributeValues(Resource originResource, UploadComponentInstanceInfo uploadComponentInstanceInfo) { if (uploadComponentInstanceInfo.getAttributes() == null) { - return Collections.emptyList(); + return Collections.emptyList(); } List origAttributes = originResource.getAttributes().stream().map(AttributeDefinition::getName).collect(toList()); Map uploadAttributes = uploadComponentInstanceInfo.getAttributes(); @@ -2210,7 +2210,7 @@ public class ServiceImportBusinessLogic { } }); List attributesToAdd = new ArrayList<>(); - for (PropertyDefinition prop: propsToAddAsAttributes) { + for (PropertyDefinition prop : propsToAddAsAttributes) { attributesToAdd.add(getPropertyAsAttribute(prop)); } return attributesToAdd; @@ -2463,13 +2463,13 @@ public class ServiceImportBusinessLogic { Map instanceInterfacesMap = uploadComponentInstanceInfo.getInterfaces(); Map currInterfacesMap = new HashMap<>(); Map interfacesFromNodeType = originResource.getInterfaces(); - if ((MapUtils.isNotEmpty(instanceInterfacesMap)) && (MapUtils.isEmpty(interfacesFromNodeType))) { + if (interfacesFromNodeType == null) { + interfacesFromNodeType = new HashMap<>(); + } + if (MapUtils.isEmpty(instanceInterfacesMap) && MapUtils.isEmpty(instanceInterfacesMap)) { log.debug("failed to find interfaces "); return componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT); } - if (interfacesFromNodeType == null || interfacesFromNodeType.isEmpty()) { - return componentsUtils.getResponseFormat(ActionStatus.OK); - } for (Map.Entry entryInstances : interfacesFromNodeType.entrySet()) { String interfaceName = entryInstances.getKey().substring(entryInstances.getKey().lastIndexOf(".") + 1); if (!currInterfacesMap.containsKey(interfaceName)) { @@ -2481,11 +2481,16 @@ public class ServiceImportBusinessLogic { if (MapUtils.isNotEmpty(instanceInterfacesMap)) { for (UploadInterfaceInfo uploadInterfaceInfo : instanceInterfacesMap.values()) { String interfaceName = uploadInterfaceInfo.getName(); + InterfaceDefinition currentInterfaceDef; if (!currInterfacesMap.containsKey(interfaceName)) { - log.debug("failed to find interface {} ", interfaceName); - return componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceName); + currentInterfaceDef = getInterfaceDef(interfaceName, component.getModel()); + if (currentInterfaceDef == null) { + log.debug("failed to find interface {} ", interfaceName); + return componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceName); + } + } else { + currentInterfaceDef = currInterfacesMap.get(interfaceName); } - InterfaceDefinition currentInterfaceDef = currInterfacesMap.get(interfaceName); Map operationsToAdd = new HashMap<>(); Map operations = uploadInterfaceInfo.getOperations(); @@ -2533,6 +2538,21 @@ public class ServiceImportBusinessLogic { return componentsUtils.getResponseFormat(ActionStatus.OK); } + private InterfaceDefinition getInterfaceDef(String interfaceName, String model) { + Either, StorageOperationStatus> interfaceLifecycleTypesEither = + interfaceLifecycleTypeOperation.getAllInterfaceLifecycleTypes(model); + if (interfaceLifecycleTypesEither.isRight()) { + return null; + } + Map interfaceLifecycleTypes = interfaceLifecycleTypesEither.left().value(); + Optional interfaceType = + interfaceLifecycleTypes.values().stream().filter(interfaceDef -> interfaceDef.getUniqueId().contains(interfaceName)).findFirst(); + if (interfaceType.isEmpty()) { + return null; + } + return interfaceType.get(); + } + private void mergeOperationInputDefinitions(ListDataDefinition inputsFromNodeType, ListDataDefinition instanceInputs) { if (inputsFromNodeType == null || CollectionUtils.isEmpty(inputsFromNodeType.getListToscaDataDefinition()) || instanceInputs == null -- cgit 1.2.3-korg