summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java')
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java108
1 files changed, 60 insertions, 48 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
index 55f92aa11a..c321e5954f 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
@@ -36,7 +36,7 @@ public class ToscaConverterImpl implements ToscaConverter {
@Override
public ToscaServiceModel convert(FileContentHandler fileContentHandler)
- throws IOException {
+ throws IOException {
Map<String, byte[]> csarFiles = new HashMap<>(fileContentHandler.getFiles());
ToscaServiceModel toscaServiceModel = new ToscaServiceModel();
Map<String, ServiceTemplate> serviceTemplates = new HashMap<>();
@@ -89,9 +89,9 @@ public class ToscaConverterImpl implements ToscaConverter {
}
} catch (YAMLException ye) {
throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withMessage("Invalid YAML content in file " + key + ". reason - "
- + ye.getMessage())
- .withCategory(ErrorCategory.APPLICATION).build());
+ .withMessage("Invalid YAML content in file " + key + ". reason - "
+ + ye.getMessage())
+ .withCategory(ErrorCategory.APPLICATION).build());
}
}
@@ -112,7 +112,7 @@ public class ToscaConverterImpl implements ToscaConverter {
GlobalSubstitutionServiceTemplate globalSubstitutionServiceTemplate,
Map<String, byte[]> csarFiles) {
Collection<ServiceTemplate> globalServiceTemplates =
- GlobalTypesGenerator.getGlobalTypesServiceTemplate().values();
+ GlobalTypesGenerator.getGlobalTypesServiceTemplate().values();
addGlobalServiceTemplates(globalServiceTemplates, serviceTemplates);
toscaServiceModel.setEntryDefinitionServiceTemplate(mainStName);
toscaServiceModel.setServiceTemplates(serviceTemplates);
@@ -137,10 +137,10 @@ public class ToscaConverterImpl implements ToscaConverter {
String fileName, Map<String, byte[]> csarFiles,
Map<String, ServiceTemplate> serviceTemplates) {
Optional<ServiceTemplate> serviceTemplate =
- getServiceTemplateFromCsar(fileName, csarFiles);
+ getServiceTemplateFromCsar(fileName, csarFiles);
serviceTemplate.ifPresent(
- serviceTemplate1 -> addServiceTemplate(serviceTemplateName, serviceTemplate1,
- serviceTemplates));
+ serviceTemplateValue -> addServiceTemplate(serviceTemplateName, serviceTemplateValue,
+ serviceTemplates));
}
private void addServiceTemplate(String serviceTemplateName,
@@ -172,7 +172,7 @@ public class ToscaConverterImpl implements ToscaConverter {
ServiceTemplate serviceTemplate = new ServiceTemplate();
try {
ServiceTemplateReaderService readerService =
- new ServiceTemplateReaderServiceImpl(fileContent);
+ new ServiceTemplateReaderServiceImpl(fileContent);
convertMetadata(serviceTemplateName, serviceTemplate, readerService);
convertToscaVersion(serviceTemplate, readerService);
convertImports(serviceTemplate);
@@ -181,9 +181,9 @@ public class ToscaConverterImpl implements ToscaConverter {
} catch (YAMLException ye) {
throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withMessage("Invalid YAML content in file" + serviceTemplateName + ". reason - "
- + ye.getMessage())
- .withCategory(ErrorCategory.APPLICATION).build());
+ .withMessage("Invalid YAML content in file" + serviceTemplateName + ". reason - "
+ + ye.getMessage())
+ .withCategory(ErrorCategory.APPLICATION).build());
}
@@ -199,7 +199,7 @@ public class ToscaConverterImpl implements ToscaConverter {
private void convertImports(ServiceTemplate serviceTemplate) {
serviceTemplate.setImports(new ArrayList<>());
serviceTemplate.getImports()
- .add(createImportMap(openecompHeatIndex, "openecomp-heat/_index.yml"));
+ .add(createImportMap(openecompHeatIndex, "openecomp-heat/_index.yml"));
serviceTemplate.getImports().add(createImportMap(globalSubstitution, globalStName));
}
@@ -222,7 +222,7 @@ public class ToscaConverterImpl implements ToscaConverter {
if (MapUtils.isNotEmpty(metadataToConvert)) {
for (Map.Entry<String, Object> metadataEntry : metadataToConvert.entrySet()) {
if (Objects.isNull(metadataEntry.getValue()) ||
- !(metadataEntry.getValue() instanceof String)) {
+ !(metadataEntry.getValue() instanceof String)) {
continue;
}
finalMetadata.put(metadataEntry.getKey(), (String) metadataEntry.getValue());
@@ -240,10 +240,12 @@ public class ToscaConverterImpl implements ToscaConverter {
}
for (Map.Entry<String, Object> nodeTypeEntry : nodeTypes.entrySet()) {
- DataModelUtil
- .addNodeType(serviceTemplate, nodeTypeEntry.getKey(),
- (NodeType) createObjectFromClass(nodeTypeEntry.getKey(), nodeTypeEntry.getValue(),
- NodeType.class));
+ Optional<NodeType> nodeType = ToscaConverterUtil
+ .createObjectFromClass(nodeTypeEntry.getKey(), nodeTypeEntry.getValue(),
+ NodeType.class);
+
+ nodeType.ifPresent(nodeTypeValue -> DataModelUtil
+ .addNodeType(serviceTemplate, nodeTypeEntry.getKey(), nodeTypeValue));
}
}
@@ -276,11 +278,28 @@ public class ToscaConverterImpl implements ToscaConverter {
}
for (Map.Entry<String, Object> entry : mapToConvert.entrySet()) {
- ParameterDefinition parameterDefinition =
- (ParameterDefinition) createObjectFromClass(
- entry.getKey(), entry.getValue(), ParameterDefinition.class);
- addToServiceTemplateAccordingToSection(
- serviceTemplate, inputsOrOutputs, entry.getKey(), parameterDefinition);
+ Optional<ParameterDefinition> parameterDefinition =
+ ToscaConverterUtil.createObjectFromClass(
+ entry.getKey(), entry.getValue(), ParameterDefinition.class);
+
+ parameterDefinition.ifPresent(parameterDefinitionValue -> {
+ handleDefaultValue(entry.getValue(), parameterDefinition.get());
+ addToServiceTemplateAccordingToSection(
+ serviceTemplate, inputsOrOutputs, entry.getKey(), parameterDefinition.get());
+ } );
+ }
+ }
+
+ private void handleDefaultValue(Object entryValue,
+ ParameterDefinition parameterDefinition) {
+ if(!(entryValue instanceof Map)
+ || Objects.isNull(parameterDefinition)){
+ return;
+ }
+
+ Object defaultValue = ((Map) entryValue).get("default");
+ if(Objects.nonNull(defaultValue)) {
+ parameterDefinition.set_default(defaultValue);
}
}
@@ -291,11 +310,11 @@ public class ToscaConverterImpl implements ToscaConverter {
switch (inputsOrOutputs) {
case inputs:
DataModelUtil
- .addInputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition);
+ .addInputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition);
break;
case outputs:
DataModelUtil
- .addOutputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition);
+ .addOutputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition);
}
}
@@ -327,15 +346,15 @@ public class ToscaConverterImpl implements ToscaConverter {
substitutionMapping.setNode_type((String) substitutionMappings.get(nodeType));
substitutionMapping.setCapabilities(
- convertSubstitutionMappingsSections((Map<String, Object>) substitutionMappings.get(capabilities)));
+ convertSubstitutionMappingsSections((Map<String, Object>) substitutionMappings.get(capabilities)));
substitutionMapping.setRequirements(
- convertSubstitutionMappingsSections((Map<String, Object>) substitutionMappings.get(requirements)));
+ convertSubstitutionMappingsSections((Map<String, Object>) substitutionMappings.get(requirements)));
return substitutionMapping;
}
private Map<String, List<String>> convertSubstitutionMappingsSections(
- Map<String, Object> sectionToConvert) {
+ Map<String, Object> sectionToConvert) {
Map<String, List<String>> convertedSection = new HashMap<>();
if (MapUtils.isEmpty(sectionToConvert)) {
return null;
@@ -385,14 +404,14 @@ public class ToscaConverterImpl implements ToscaConverter {
nodeTemplate.setDescription((String) nodeTemplateAsMap.get("description"));
nodeTemplate.setDirectives((List<String>) nodeTemplateAsMap.get("directives"));
nodeTemplate.setInterfaces(
- (Map<String, InterfaceDefinition>) nodeTemplateAsMap.get("interfaces"));
+ (Map<String, InterfaceDefinition>) nodeTemplateAsMap.get("interfaces"));
nodeTemplate.setNode_filter((NodeFilter) nodeTemplateAsMap.get("node_filter"));
nodeTemplate.setProperties((Map<String, Object>) nodeTemplateAsMap.get("properties"));
nodeTemplate.setRequirements(
- (List<Map<String, RequirementAssignment>>) nodeTemplateAsMap.get("requirements"));
+ (List<Map<String, RequirementAssignment>>) nodeTemplateAsMap.get("requirements"));
nodeTemplate.setType((String) nodeTemplateAsMap.get("type"));
nodeTemplate.setCapabilities(
- convertCapabilities((Map<String, Object>) nodeTemplateAsMap.get("capabilities")));
+ convertCapabilities((Map<String, Object>) nodeTemplateAsMap.get("capabilities")));
return nodeTemplate;
}
@@ -404,27 +423,20 @@ public class ToscaConverterImpl implements ToscaConverter {
}
for (Map.Entry<String, Object> capabilityAssignmentEntry : capabilities.entrySet()) {
Map<String, CapabilityAssignment> tempMap = new HashMap<>();
- tempMap.put(capabilityAssignmentEntry.getKey(),
- (CapabilityAssignment) createObjectFromClass
- (capabilityAssignmentEntry.getKey(), capabilityAssignmentEntry.getValue(), CapabilityAssignment.class));
- convertedCapabilities.add(tempMap);
+ Optional<CapabilityAssignment> capabilityAssignment = ToscaConverterUtil.createObjectFromClass
+ (capabilityAssignmentEntry.getKey(), capabilityAssignmentEntry.getValue(),
+ CapabilityAssignment.class);
+
+ capabilityAssignment.ifPresent(capabilityAssignmentValue -> {
+ tempMap.put(capabilityAssignmentEntry.getKey(), capabilityAssignmentValue);
+ convertedCapabilities.add(tempMap);
+ }
+ );
+
}
return convertedCapabilities;
}
- private Object createObjectFromClass(String nodeTypeId,
- Object objectCandidate,
- Class classToCreate) {
- try {
- return JsonUtil.json2Object(objectCandidate.toString(), classToCreate);
- } catch (Exception e) {
- //todo - return error to user?
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withCategory(ErrorCategory.APPLICATION)
- .withMessage("Can't create " + classToCreate.getSimpleName() + " from " +
- nodeTypeId).build());
- }
- }
private boolean isMainServiceTemplate(String fileName) {
return fileName.endsWith(mainStName);