From a54910e9b98e78cf543c5245417eeaf9256b242e Mon Sep 17 00:00:00 2001 From: vasraz Date: Thu, 3 Aug 2023 18:36:34 +0100 Subject: Fix 'Import use case fails when interfaces in template do not exist in system'-bug (p.1) - Fix NPE - Rollback if fail Signed-off-by: Vasyl Razinkov Change-Id: I5cfea53d96064317aaf979d97bb41d394fddca0c Issue-ID: SDC-4591 --- .../be/components/impl/ResourceImportManager.java | 38 +++++++++++----------- .../impl/ServiceImportBusinessLogic.java | 11 +++---- 2 files changed, 24 insertions(+), 25 deletions(-) (limited to 'catalog-be/src') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java index 1e2cea5c64..8976753638 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java @@ -436,8 +436,7 @@ public class ResourceImportManager { Either, ResultStatusEnum> toscaElement = ImportUtils .findFirstToscaMapElement(toscaJson, ToscaTagNamesEnum.NODE_TYPES); if (toscaElement.isLeft() && toscaElement.left().value().size() == 1) { - String toscaResourceName = toscaElement.left().value().keySet().iterator().next(); - return toscaResourceName; + return toscaElement.left().value().keySet().iterator().next(); } return null; } @@ -463,13 +462,16 @@ public class ResourceImportManager { map = Collections.emptyMap(); } if (existingResource.isLeft()) { - final Map userCreatedInterfaceDefinitions = - existingResource.left().value().getInterfaces().entrySet().stream() - .filter(i -> i.getValue().isUserCreated()) - .filter(i -> !map.containsKey(i.getValue().getType())) - .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); - if (MapUtils.isNotEmpty(userCreatedInterfaceDefinitions)) { - moduleInterfaces.putAll(userCreatedInterfaceDefinitions); + final Map interfaces = existingResource.left().value().getInterfaces(); + if (MapUtils.isNotEmpty(interfaces)) { + final Map userCreatedInterfaceDefinitions = + interfaces.entrySet().stream() + .filter(i -> i.getValue().isUserCreated()) + .filter(i -> !map.containsKey(i.getValue().getType())) + .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); + if (MapUtils.isNotEmpty(userCreatedInterfaceDefinitions)) { + moduleInterfaces.putAll(userCreatedInterfaceDefinitions); + } } } @@ -583,16 +585,14 @@ public class ResourceImportManager { for (final Entry entry : propertyDefinitionMap.entrySet()) { addPropertyToList(resource.getName(), propertiesList, entry); } - if (existingResource.isLeft()) { - if ( CollectionUtils.isNotEmpty(existingResource.left().value().getProperties())) { - final List userCreatedResourceProperties = - existingResource.left().value().getProperties().stream() - .filter(PropertyDataDefinition::isUserCreated) - .filter(propertyDefinition -> !propertyDefinitionMap.containsKey(propertyDefinition.getName())) - .collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(userCreatedResourceProperties)) { - propertiesList.addAll(userCreatedResourceProperties); - } + if (existingResource.isLeft() && CollectionUtils.isNotEmpty(existingResource.left().value().getProperties())) { + final List userCreatedResourceProperties = + existingResource.left().value().getProperties().stream() + .filter(PropertyDataDefinition::isUserCreated) + .filter(propertyDefinition -> !propertyDefinitionMap.containsKey(propertyDefinition.getName())) + .collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(userCreatedResourceProperties)) { + propertiesList.addAll(userCreatedResourceProperties); } } 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 c022304d8b..641e294e42 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 @@ -821,7 +821,7 @@ public class ServiceImportBusinessLogic { ASDCKpiApi.countCreatedResourcesKPI(); return service; - } catch (ComponentException | StorageException | BusinessLogicException e) { + } catch (Exception e) { rollback = true; serviceImportParseLogic.rollback(inTransaction, service, createdArtifacts, nodeTypesNewCreatedArtifacts); throw e; @@ -2390,23 +2390,22 @@ public class ServiceImportBusinessLogic { Map operations = uploadInterfaceInfo.getOperations(); for (Map.Entry operation : operations.entrySet()) { - OperationDataDefinition templateOperation = currentInterfaceDef.getOperationsMap().get(operation.getKey()); OperationDataDefinition instanceOperation = operation.getValue(); + OperationDataDefinition templateOperation = currentInterfaceDef.getOperationsMap().getOrDefault(operation.getKey(), new Operation(instanceOperation)); //Inputs ListDataDefinition instanceInputs = instanceOperation.getInputs(); - mergeOperationInputDefinitions(templateOperation.getInputs(), instanceInputs); if (null != instanceInputs) { + mergeOperationInputDefinitions(templateOperation.getInputs(), instanceInputs); component.getProperties() .forEach(property -> instanceInputs.getListToscaDataDefinition().stream() .filter(instanceInput -> instanceInput.getToscaFunction() instanceof ToscaGetFunctionDataDefinition && property.getName().equals(instanceInput.getToscaFunction() != null ? - ((ToscaGetFunctionDataDefinition) instanceInput.getToscaFunction()).getPropertyName() : - null)) + ((ToscaGetFunctionDataDefinition) instanceInput.getToscaFunction()).getPropertyName() : null)) .forEach(oldInput -> oldInput.setType(property.getType())) ); + templateOperation.setInputs(instanceInputs); } - templateOperation.setInputs(instanceInputs); //Implementation templateOperation.setImplementation(instanceOperation.getImplementation()); //Description -- cgit 1.2.3-korg