summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2023-08-03 18:36:34 +0100
committerFrancisco Javier Paradela Vila <javier.paradela.vila@est.tech>2023-08-17 13:10:26 +0000
commita54910e9b98e78cf543c5245417eeaf9256b242e (patch)
treeb262da6dc1d09a969705be64898577b1a1871260 /catalog-be/src/main
parentadb7f7496af6e71e1cced44ee2f7485c9917a806 (diff)
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 <vasyl.razinkov@est.tech> Change-Id: I5cfea53d96064317aaf979d97bb41d394fddca0c Issue-ID: SDC-4591
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java38
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java11
2 files changed, 24 insertions, 25 deletions
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<Map<String, Object>, 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<String, InterfaceDefinition> 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<String, InterfaceDefinition> interfaces = existingResource.left().value().getInterfaces();
+ if (MapUtils.isNotEmpty(interfaces)) {
+ final Map<String, InterfaceDefinition> 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<String, PropertyDefinition> entry : propertyDefinitionMap.entrySet()) {
addPropertyToList(resource.getName(), propertiesList, entry);
}
- if (existingResource.isLeft()) {
- if ( CollectionUtils.isNotEmpty(existingResource.left().value().getProperties())) {
- final List<PropertyDefinition> 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<PropertyDefinition> 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<String, OperationDataDefinition> operations = uploadInterfaceInfo.getOperations();
for (Map.Entry<String, OperationDataDefinition> 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<OperationInputDefinition> 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