From fda41360dcb7e68c8e3003c73fdb98db2514bf5f Mon Sep 17 00:00:00 2001 From: vasraz Date: Fri, 18 Aug 2023 19:40:44 +0100 Subject: Fix 'Fail to import service with CP'-bug Signed-off-by: Vasyl Razinkov Change-Id: I7261b03eb7e796aaa66ac3dbd0116bc62d2d6e71 Issue-ID: SDC-4599 --- .../impl/ServiceImportBusinessLogic.java | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'catalog-be') 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 1ba74a1594..bf27d030b5 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 @@ -539,7 +539,8 @@ public class ServiceImportBusinessLogic { && result.left().value().getProperties().size() != dataType.get("properties").size(); } - private void createNodeTypes(List nodeTypesToCreate, Map instancesFromCsar, String model, User user) { + private void createNodeTypes(List nodeTypesToCreate, Map instancesFromCsar, String model, + User user) { NodeTypesMetadataList nodeTypesMetadataList = new NodeTypesMetadataList(); List nodeTypeMetadataList = new ArrayList<>(); final Map allTypesToCreate = new HashMap<>(); @@ -611,7 +612,7 @@ public class ServiceImportBusinessLogic { private void combineInterfacesIntoToscaTemplate(Map> newInterfaces, Map> existingInterfaces, Map combinedMappedToscaTemplate) { - Map> combinedInterfaces = combineAdditionalInterfaces(existingInterfaces, newInterfaces); + Map> combinedInterfaces = combineAdditionalInterfaces(newInterfaces, existingInterfaces); if ((MapUtils.isEmpty(existingInterfaces) && MapUtils.isNotEmpty(combinedInterfaces)) || (MapUtils.isNotEmpty(existingInterfaces) && !existingInterfaces.equals(combinedInterfaces))) { combinedMappedToscaTemplate.put("interfaces", combinedInterfaces); @@ -654,8 +655,11 @@ public class ServiceImportBusinessLogic { } } - private Map> combineAdditionalInterfaces(Map> existingInterfaces, - Map> newInterfaces) { + private Map> combineAdditionalInterfaces(Map> newInterfaces, + Map> existingInterfaces) { + if (MapUtils.isNotEmpty(newInterfaces) && MapUtils.isNotEmpty(existingInterfaces) && newInterfaces.equals(existingInterfaces)) { + return new HashMap<>(existingInterfaces); + } if (MapUtils.isEmpty(newInterfaces)) { newInterfaces = new HashMap<>(); } @@ -676,6 +680,9 @@ public class ServiceImportBusinessLogic { private List> combineAdditionalRequirements(List> newReqs, List> existingResourceReqs) { + if (CollectionUtils.isNotEmpty(newReqs) && CollectionUtils.isNotEmpty(existingResourceReqs) && newReqs.equals(existingResourceReqs)) { + return new ArrayList<>(existingResourceReqs); + } if (CollectionUtils.isEmpty(existingResourceReqs)) { existingResourceReqs = new ArrayList<>(); } @@ -690,6 +697,9 @@ public class ServiceImportBusinessLogic { } private Map combineEntries(Map newMap, Map existingMap) { + if (MapUtils.isNotEmpty(newMap) && MapUtils.isNotEmpty(existingMap) && newMap.equals(existingMap)) { + return new HashMap<>(existingMap); + } if (MapUtils.isEmpty(newMap)) { newMap = new HashMap<>(); } @@ -861,7 +871,8 @@ public class ServiceImportBusinessLogic { } } if (CollectionUtils.isNotEmpty(propertyMissingNames)) { - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.MISSING_PROPERTIES_ERROR, propertyMissingNames.toString())); + throw new ComponentException( + componentsUtils.getResponseFormat(ActionStatus.MISSING_PROPERTIES_ERROR, propertyMissingNames.toString())); } Either, StorageOperationStatus> either = toscaOperationFacade.updateInputsToComponent(inputs, componentUniqueId); if (either.isRight()) { @@ -927,8 +938,8 @@ public class ServiceImportBusinessLogic { } private String associateInputToServiceProperty(final String userId, - final InputDefinition input, final Service component, - final Map> substitutionMappingProperties) { + final InputDefinition input, final Service component, + final Map> substitutionMappingProperties) { final List properties = component.getProperties(); if (CollectionUtils.isNotEmpty(properties) && MapUtils.isNotEmpty(substitutionMappingProperties)) { AtomicReference propertyNameFromInput = new AtomicReference<>(" "); @@ -2388,7 +2399,8 @@ public class ServiceImportBusinessLogic { Map operations = uploadInterfaceInfo.getOperations(); for (Map.Entry operation : operations.entrySet()) { OperationDataDefinition instanceOperation = operation.getValue(); - OperationDataDefinition templateOperation = currentInterfaceDef.getOperationsMap().getOrDefault(operation.getKey(), new Operation(instanceOperation)); + OperationDataDefinition templateOperation = currentInterfaceDef.getOperationsMap() + .getOrDefault(operation.getKey(), new Operation(instanceOperation)); //Inputs ListDataDefinition instanceInputs = instanceOperation.getInputs(); if (null != instanceInputs) { -- cgit 1.2.3-korg