summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java')
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java517
1 files changed, 188 insertions, 329 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
index 3ce9badea0..c5deee4ebd 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.tosca.services.impl;
import java.io.ByteArrayInputStream;
@@ -91,18 +90,58 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
private static final String TOSCA_META_FILE = "TOSCA-Metadata/TOSCA.meta";
private static final String ENTRY_DEFINITIONS = "Entry-Definitions";
+ private static boolean isFile(String currentEntryName) {
+ return !(currentEntryName.endsWith("\\") || currentEntryName.endsWith("/"));
+ }
+
+ private static boolean evaluateRequirementFulfillment(RequirementDefinition requirementDefinition) {
+ Object[] occurrences = requirementDefinition.getOccurrences();
+ if (occurrences == null) {
+ requirementDefinition.setOccurrences(new Object[]{1, 1});
+ return false;
+ }
+ if (occurrences[1].equals(ToscaConstants.UNBOUNDED)) {
+ return false;
+ }
+ if (occurrences[1].equals(1)) {
+ return true;
+ }
+ occurrences[1] = (Integer) occurrences[1] - 1;
+ return false;
+ }
+
+ private static boolean evaluateCapabilityFulfillment(CapabilityDefinition capabilityDefinition) {
+ Object[] occurrences = capabilityDefinition.getOccurrences();
+ if (occurrences == null) {
+ capabilityDefinition.setOccurrences(new Object[]{1, ToscaConstants.UNBOUNDED});
+ return false;
+ }
+ if (occurrences[1].equals(ToscaConstants.UNBOUNDED)) {
+ return false;
+ }
+ if (occurrences[1].equals(1)) {
+ return true;
+ }
+ occurrences[1] = (Integer) occurrences[1] - 1;
+ return false;
+ }
+
+ private static boolean isPrimitiveType(String toscaType) {
+ return (toscaType.equals(PropertyType.STRING.getDisplayName()) || toscaType.equals(PropertyType.INTEGER.getDisplayName()) || toscaType
+ .equals(PropertyType.FLOAT.getDisplayName()));
+ }
+
@Override
public List<Map<String, RequirementDefinition>> calculateExposedRequirements(
- List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList,
- Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment) {
-
+ List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList,
+ Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment) {
if (nodeTypeRequirementsDefinitionList == null) {
return Collections.emptyList();
}
for (Map.Entry<String, RequirementAssignment> entry : nodeTemplateRequirementsAssignment.entrySet()) {
if (entry.getValue().getNode() != null) {
- Optional<RequirementDefinition> requirementDefinition =
- DataModelUtil.getRequirementDefinition(nodeTypeRequirementsDefinitionList, entry.getKey());
+ Optional<RequirementDefinition> requirementDefinition = DataModelUtil
+ .getRequirementDefinition(nodeTypeRequirementsDefinitionList, entry.getKey());
RequirementDefinition cloneRequirementDefinition;
if (requirementDefinition.isPresent()) {
cloneRequirementDefinition = requirementDefinition.get().clone();
@@ -122,7 +161,6 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
ToscaServiceModel toscaServiceModel = new ToscaServiceModel();
ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
FileContentHandler artifactFiles = new FileContentHandler();
-
try (ZipInputStream inputZipStream = new ZipInputStream(new ByteArrayInputStream(toscaCsarPackage))) {
ZipEntry zipEntry;
while ((zipEntry = inputZipStream.getNextEntry()) != null) {
@@ -144,7 +182,6 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
if (StringUtils.isEmpty(toscaServiceModel.getEntryDefinitionServiceTemplate())) {
handleToscaCsarWithoutToscaMetadata(toscaServiceModel);
}
-
} catch (IOException | ZipSlipException exc) {
throw new SdcRuntimeException(exc.getMessage(), exc);
}
@@ -172,22 +209,16 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
toscaServiceModel.setEntryDefinitionServiceTemplate(entryDefinition);
}
- void loadToscaYamlFile(ToscaServiceModel toscaServiceModel, ToscaExtensionYamlUtil toscaExtensionYamlUtil,
- byte[] fileContent, String fileFullName) {
+ void loadToscaYamlFile(ToscaServiceModel toscaServiceModel, ToscaExtensionYamlUtil toscaExtensionYamlUtil, byte[] fileContent,
+ String fileFullName) {
try {
- ServiceTemplate serviceTemplate =
- toscaExtensionYamlUtil.yamlToObject(new String(fileContent), ServiceTemplate.class);
+ ServiceTemplate serviceTemplate = toscaExtensionYamlUtil.yamlToObject(new String(fileContent), ServiceTemplate.class);
toscaServiceModel.addServiceTemplate(fileFullName, serviceTemplate);
-
} catch (Exception exc) {
throw new CoreException(new InvalidToscaFile(fileFullName, exc.getMessage()).build());
}
}
- private static boolean isFile(String currentEntryName) {
- return !(currentEntryName.endsWith("\\") || currentEntryName.endsWith("/"));
- }
-
private boolean isYamlFile(String fileName) {
return fileName.endsWith("yaml") || fileName.endsWith("yml");
}
@@ -198,57 +229,33 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private void updateMinMaxOccurencesForNodeTypeRequirement(Map.Entry<String, RequirementAssignment> entry,
- Map<String, RequirementDefinition> nodeTypeRequirementsMap) {
+ Map<String, RequirementDefinition> nodeTypeRequirementsMap) {
Object max = nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences() != null
- && nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences().length > 0
- ? nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences()[1] : 1;
+ && nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences().length > 0 ? nodeTypeRequirementsMap.get(entry.getKey())
+ .getOccurrences()[1] : 1;
Object min = nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences() != null
- && nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences().length > 0
- ? nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences()[0] : 1;
- nodeTypeRequirementsMap.get(entry.getKey()).setOccurrences(new Object[] {min, max});
+ && nodeTypeRequirementsMap.get(entry.getKey()).getOccurrences().length > 0 ? nodeTypeRequirementsMap.get(entry.getKey())
+ .getOccurrences()[0] : 1;
+ nodeTypeRequirementsMap.get(entry.getKey()).setOccurrences(new Object[]{min, max});
}
- private void updateRequirementDefinition(
- List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList,
- Map.Entry<String, RequirementAssignment> entry, RequirementDefinition cloneRequirementDefinition) {
+ private void updateRequirementDefinition(List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList,
+ Map.Entry<String, RequirementAssignment> entry, RequirementDefinition cloneRequirementDefinition) {
if (!evaluateRequirementFulfillment(cloneRequirementDefinition)) {
- CommonMethods
- .mergeEntryInList(entry.getKey(), cloneRequirementDefinition, nodeTypeRequirementsDefinitionList);
+ CommonMethods.mergeEntryInList(entry.getKey(), cloneRequirementDefinition, nodeTypeRequirementsDefinitionList);
} else {
DataModelUtil.removeRequirementsDefinition(nodeTypeRequirementsDefinitionList, entry.getKey());
}
}
- private static boolean evaluateRequirementFulfillment(RequirementDefinition requirementDefinition) {
- Object[] occurrences = requirementDefinition.getOccurrences();
- if (occurrences == null) {
- requirementDefinition.setOccurrences(new Object[] {1, 1});
- return false;
- }
- if (occurrences[1].equals(ToscaConstants.UNBOUNDED)) {
- return false;
- }
-
- if (occurrences[1].equals(1)) {
- return true;
- }
- occurrences[1] = (Integer) occurrences[1] - 1;
- return false;
- }
-
@Override
- public Map<String, CapabilityDefinition> calculateExposedCapabilities(
- Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition,
- Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinitionMap) {
-
+ public Map<String, CapabilityDefinition> calculateExposedCapabilities(Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition,
+ Map<String, Map<String, RequirementAssignment>> fullFilledRequirementsDefinitionMap) {
String capabilityKey;
String capability;
String node;
- for (Map.Entry<String, Map<String, RequirementAssignment>> entry : fullFilledRequirementsDefinitionMap
- .entrySet()) {
+ for (Map.Entry<String, Map<String, RequirementAssignment>> entry : fullFilledRequirementsDefinitionMap.entrySet()) {
for (Map.Entry<String, RequirementAssignment> fullFilledEntry : entry.getValue().entrySet()) {
-
-
capability = fullFilledEntry.getValue().getCapability();
node = fullFilledEntry.getValue().getNode();
capabilityKey = capability + "_" + node;
@@ -256,12 +263,10 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
if (capabilityDefinition != null) {
CapabilityDefinition clonedCapabilityDefinition = capabilityDefinition.clone();
nodeTypeCapabilitiesDefinition.put(capabilityKey, capabilityDefinition.clone());
- updateNodeTypeCapabilitiesDefinition(nodeTypeCapabilitiesDefinition, capabilityKey,
- clonedCapabilityDefinition);
+ updateNodeTypeCapabilitiesDefinition(nodeTypeCapabilitiesDefinition, capabilityKey, clonedCapabilityDefinition);
}
}
}
-
Map<String, CapabilityDefinition> exposedCapabilitiesDefinition = new HashMap<>();
for (Map.Entry<String, CapabilityDefinition> entry : nodeTypeCapabilitiesDefinition.entrySet()) {
exposedCapabilitiesDefinition.put(entry.getKey(), entry.getValue());
@@ -269,8 +274,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
return exposedCapabilitiesDefinition;
}
- private void updateNodeTypeCapabilitiesDefinition(Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition,
- String capabilityKey, CapabilityDefinition clonedCapabilityDefinition) {
+ private void updateNodeTypeCapabilitiesDefinition(Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition, String capabilityKey,
+ CapabilityDefinition clonedCapabilityDefinition) {
if (evaluateCapabilityFulfillment(clonedCapabilityDefinition)) {
nodeTypeCapabilitiesDefinition.remove(capabilityKey);
} else {
@@ -278,40 +283,18 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
}
- private static boolean evaluateCapabilityFulfillment(CapabilityDefinition capabilityDefinition) {
-
- Object[] occurrences = capabilityDefinition.getOccurrences();
- if (occurrences == null) {
- capabilityDefinition.setOccurrences(new Object[] {1, ToscaConstants.UNBOUNDED});
- return false;
- }
- if (occurrences[1].equals(ToscaConstants.UNBOUNDED)) {
- return false;
- }
-
- if (occurrences[1].equals(1)) {
- return true;
- }
- occurrences[1] = (Integer) occurrences[1] - 1;
- return false;
- }
-
/*
node template with type equal to node type or derived from node type
*/
@Override
- public Map<String, NodeTemplate> getNodeTemplatesByType(ServiceTemplate serviceTemplate, String nodeType,
- ToscaServiceModel toscaServiceModel) {
+ public Map<String, NodeTemplate> getNodeTemplatesByType(ServiceTemplate serviceTemplate, String nodeType, ToscaServiceModel toscaServiceModel) {
Map<String, NodeTemplate> nodeTemplates = new HashMap<>();
-
- if (Objects.nonNull(serviceTemplate.getTopology_template()) && MapUtils.isNotEmpty(
- serviceTemplate.getTopology_template().getNode_templates())) {
- for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : serviceTemplate.getTopology_template()
- .getNode_templates().entrySet()) {
+ if (Objects.nonNull(serviceTemplate.getTopology_template()) && MapUtils
+ .isNotEmpty(serviceTemplate.getTopology_template().getNode_templates())) {
+ for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : serviceTemplate.getTopology_template().getNode_templates().entrySet()) {
if (isTypeOf(nodeTemplateEntry.getValue(), nodeType, serviceTemplate, toscaServiceModel)) {
nodeTemplates.put(nodeTemplateEntry.getKey(), nodeTemplateEntry.getValue());
}
-
}
}
return nodeTemplates;
@@ -320,38 +303,31 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
@Override
public Optional<NodeType> fetchNodeType(String nodeTypeKey, Collection<ServiceTemplate> serviceTemplates) {
Optional<Map<String, NodeType>> nodeTypeMap = serviceTemplates.stream().map(ServiceTemplate::getNode_types)
- .filter(nodeTypes -> Objects.nonNull(nodeTypes)
- && nodeTypes
- .containsKey(
- nodeTypeKey))
- .findFirst();
+ .filter(nodeTypes -> Objects.nonNull(nodeTypes) && nodeTypes.containsKey(nodeTypeKey)).findFirst();
return nodeTypeMap.map(stringNodeTypeMap -> stringNodeTypeMap.get(nodeTypeKey));
}
@Override
- public boolean isTypeOf(NodeTemplate nodeTemplate, String nodeType, ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel) {
+ public boolean isTypeOf(NodeTemplate nodeTemplate, String nodeType, ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel) {
return isTypeOf(nodeTemplate, nodeType, GET_NODE_TYPE_METHOD_NAME, serviceTemplate, toscaServiceModel);
}
@Override
- public boolean isTypeOf(InterfaceDefinitionType interfaceDefinition, String interfaceType,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel) {
- return isTypeOf(interfaceDefinition, interfaceType, GET_INTERFACE_TYPE_METHOD_NAME, serviceTemplate,
- toscaServiceModel);
+ public boolean isTypeOf(InterfaceDefinitionType interfaceDefinition, String interfaceType, ServiceTemplate serviceTemplate,
+ ToscaServiceModel toscaServiceModel) {
+ return isTypeOf(interfaceDefinition, interfaceType, GET_INTERFACE_TYPE_METHOD_NAME, serviceTemplate, toscaServiceModel);
}
@Override
public boolean isTypeOf(DefinitionOfDataType parameterDefinition, String dataType, ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel) {
+ ToscaServiceModel toscaServiceModel) {
return isTypeOf(parameterDefinition, dataType, GET_DATA_TYPE_METHOD_NAME, serviceTemplate, toscaServiceModel);
}
@Override
- public boolean isTypeOf(CapabilityDefinition capabilityDefinition, String capabilityType,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel) {
- return isTypeOf(capabilityDefinition, capabilityType, GET_CAPABILITY_TYPE_METHOD_NAME, serviceTemplate,
- toscaServiceModel);
+ public boolean isTypeOf(CapabilityDefinition capabilityDefinition, String capabilityType, ServiceTemplate serviceTemplate,
+ ToscaServiceModel toscaServiceModel) {
+ return isTypeOf(capabilityDefinition, capabilityType, GET_CAPABILITY_TYPE_METHOD_NAME, serviceTemplate, toscaServiceModel);
}
@Override
@@ -361,8 +337,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
if (requirementList != null) {
requirementList.stream().filter(reqMap -> reqMap.get(requirementId) != null).forEach(reqMap -> {
ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
- RequirementAssignment reqAssignment = toscaExtensionYamlUtil.yamlToObject(
- toscaExtensionYamlUtil.objectToYaml(reqMap.get(requirementId)), RequirementAssignment.class);
+ RequirementAssignment reqAssignment = toscaExtensionYamlUtil
+ .yamlToObject(toscaExtensionYamlUtil.objectToYaml(reqMap.get(requirementId)), RequirementAssignment.class);
requirements.add(reqAssignment);
});
}
@@ -371,53 +347,43 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
@Override
public Optional<NodeTemplate> getNodeTemplateById(ServiceTemplate serviceTemplate, String nodeTemplateId) {
- if ((serviceTemplate.getTopology_template() != null) && (
- serviceTemplate.getTopology_template().getNode_templates() != null) && (
- serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) != null)) {
+ if ((serviceTemplate.getTopology_template() != null) && (serviceTemplate.getTopology_template().getNode_templates() != null) && (
+ serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) != null)) {
return Optional.of(serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId));
}
return Optional.empty();
}
@Override
- public Optional<String> getSubstituteServiceTemplateName(String substituteNodeTemplateId,
- NodeTemplate substitutableNodeTemplate) {
+ public Optional<String> getSubstituteServiceTemplateName(String substituteNodeTemplateId, NodeTemplate substitutableNodeTemplate) {
if (!isSubstitutableNodeTemplate(substitutableNodeTemplate)) {
return Optional.empty();
}
-
- if (substitutableNodeTemplate.getProperties() != null &&
- substitutableNodeTemplate.getProperties().get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME)
- != null) {
- Object serviceTemplateFilter =
- substitutableNodeTemplate.getProperties().get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME);
+ if (substitutableNodeTemplate.getProperties() != null
+ && substitutableNodeTemplate.getProperties().get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME) != null) {
+ Object serviceTemplateFilter = substitutableNodeTemplate.getProperties().get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME);
if (serviceTemplateFilter instanceof Map) {
- Object substituteServiceTemplate =
- ((Map) serviceTemplateFilter).get(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME);
+ Object substituteServiceTemplate = ((Map) serviceTemplateFilter).get(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME);
handleNoSubstituteServiceTemplate(substituteNodeTemplateId, substituteServiceTemplate);
return Optional.of(substituteServiceTemplate.toString());
}
}
- throw new CoreException(
- new ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder(substituteNodeTemplateId).build());
+ throw new CoreException(new ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder(substituteNodeTemplateId).build());
}
private void handleNoSubstituteServiceTemplate(String substituteNodeTemplateId, Object substituteServiceTemplate) {
if (substituteServiceTemplate == null) {
- throw new CoreException(
- new ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder(substituteNodeTemplateId).build());
+ throw new CoreException(new ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder(substituteNodeTemplateId).build());
}
}
@Override
public Map<String, NodeTemplate> getSubstitutableNodeTemplates(ServiceTemplate serviceTemplate) {
Map<String, NodeTemplate> substitutableNodeTemplates = new HashMap<>();
-
if (serviceTemplate == null || serviceTemplate.getTopology_template() == null
- || serviceTemplate.getTopology_template().getNode_templates() == null) {
+ || serviceTemplate.getTopology_template().getNode_templates() == null) {
return substitutableNodeTemplates;
}
-
Map<String, NodeTemplate> nodeTemplates = serviceTemplate.getTopology_template().getNode_templates();
for (Map.Entry<String, NodeTemplate> entry : nodeTemplates.entrySet()) {
String nodeTemplateId = entry.getKey();
@@ -426,24 +392,23 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
substitutableNodeTemplates.put(nodeTemplateId, nodeTemplate);
}
}
-
return substitutableNodeTemplates;
}
@Override
- public Optional<Map.Entry<String, NodeTemplate>> getSubstitutionMappedNodeTemplateByExposedReq(
- String substituteServiceTemplateFileName, ServiceTemplate substituteServiceTemplate, String requirementId) {
+ public Optional<Map.Entry<String, NodeTemplate>> getSubstitutionMappedNodeTemplateByExposedReq(String substituteServiceTemplateFileName,
+ ServiceTemplate substituteServiceTemplate,
+ String requirementId) {
if (isSubstitutionServiceTemplate(substituteServiceTemplateFileName, substituteServiceTemplate)) {
- Map<String, List<String>> substitutionMappingRequirements =
- substituteServiceTemplate.getTopology_template().getSubstitution_mappings().getRequirements();
+ Map<String, List<String>> substitutionMappingRequirements = substituteServiceTemplate.getTopology_template().getSubstitution_mappings()
+ .getRequirements();
if (substitutionMappingRequirements != null) {
List<String> requirementMapping = substitutionMappingRequirements.get(requirementId);
if (requirementMapping != null && !requirementMapping.isEmpty()) {
String mappedNodeTemplateId = requirementMapping.get(0);
- Optional<NodeTemplate> mappedNodeTemplate =
- getNodeTemplateById(substituteServiceTemplate, mappedNodeTemplateId);
- mappedNodeTemplate.orElseThrow(() -> new CoreException(
- new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", mappedNodeTemplateId).build()));
+ Optional<NodeTemplate> mappedNodeTemplate = getNodeTemplateById(substituteServiceTemplate, mappedNodeTemplateId);
+ mappedNodeTemplate.orElseThrow(
+ () -> new CoreException(new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", mappedNodeTemplateId).build()));
Map.Entry<String, NodeTemplate> mappedNodeTemplateEntry = new Map.Entry<String, NodeTemplate>() {
@Override
public String getKey() {
@@ -471,47 +436,36 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
match only for the input which is not null
*/
@Override
- public boolean isDesiredRequirementAssignment(RequirementAssignment requirementAssignment, String capability,
- String node, String relationship) {
+ public boolean isDesiredRequirementAssignment(RequirementAssignment requirementAssignment, String capability, String node, String relationship) {
if (isSameCapability(requirementAssignment, capability)) {
return false;
}
-
if (isSameRequirement(requirementAssignment, node)) {
return false;
}
-
if (isSameRelationship(requirementAssignment, relationship)) {
return false;
}
-
return !(capability == null && node == null && relationship == null);
-
}
private boolean isSameRelationship(RequirementAssignment requirementAssignment, String relationship) {
- return relationship != null && (requirementAssignment.getRelationship() == null || !requirementAssignment
- .getRelationship()
- .equals(relationship));
+ return relationship != null && (requirementAssignment.getRelationship() == null || !requirementAssignment.getRelationship()
+ .equals(relationship));
}
private boolean isSameRequirement(RequirementAssignment requirementAssignment, String node) {
- return node != null && (requirementAssignment.getNode() == null || !requirementAssignment.getNode()
- .equals(node));
+ return node != null && (requirementAssignment.getNode() == null || !requirementAssignment.getNode().equals(node));
}
private boolean isSameCapability(RequirementAssignment requirementAssignment, String capability) {
- return capability != null && (requirementAssignment.getCapability() == null || !requirementAssignment
- .getCapability()
- .equals(capability));
+ return capability != null && (requirementAssignment.getCapability() == null || !requirementAssignment.getCapability().equals(capability));
}
@Override
- public ToscaFlatData getFlatEntity(ToscaElementTypes elementType, String typeId, ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaModel) {
+ public ToscaFlatData getFlatEntity(ToscaElementTypes elementType, String typeId, ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel) {
ToscaFlatData flatData = new ToscaFlatData();
flatData.setElementType(elementType);
-
switch (elementType) {
case CAPABILITY_TYPE:
flatData.setFlatEntity(new CapabilityType());
@@ -525,87 +479,69 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
default:
throw new SdcRuntimeException("Entity[" + elementType + "] id[" + typeId + "] flat not supported");
}
-
- boolean isEntityFound =
- scanAnFlatEntity(elementType, typeId, flatData, serviceTemplate, toscaModel, new ArrayList<>(), 0);
+ boolean isEntityFound = scanAnFlatEntity(elementType, typeId, flatData, serviceTemplate, toscaModel, new ArrayList<>(), 0);
if (!isEntityFound) {
throw new CoreException(new ToscaElementTypeNotFoundErrorBuilder(typeId).build());
}
-
return flatData;
}
@Override
public boolean isSubstitutableNodeTemplate(NodeTemplate nodeTemplate) {
- return nodeTemplate.getDirectives() != null && nodeTemplate.getDirectives().contains(
- ToscaConstants.NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE);
+ return nodeTemplate.getDirectives() != null && nodeTemplate.getDirectives().contains(ToscaConstants.NODE_TEMPLATE_DIRECTIVE_SUBSTITUTABLE);
}
- private <T> Optional<Boolean> isTypeExistInServiceTemplateHierarchy(String typeToMatch, String typeToSearch,
- String getTypesMethodName, ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel,
- Set<String> analyzedImportFiles)
- throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
- Map<String, T> searchableTypes =
- (Map<String, T>) serviceTemplate.getClass().getMethod(getTypesMethodName).invoke(serviceTemplate);
-
+ private <T> Optional<Boolean> isTypeExistInServiceTemplateHierarchy(String typeToMatch, String typeToSearch, String getTypesMethodName,
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel,
+ Set<String> analyzedImportFiles)
+ throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ Map<String, T> searchableTypes = (Map<String, T>) serviceTemplate.getClass().getMethod(getTypesMethodName).invoke(serviceTemplate);
if (!MapUtils.isEmpty(searchableTypes)) {
T typeObject = searchableTypes.get(typeToSearch);
if (Objects.nonNull(typeObject)) {
- String derivedFromTypeVal =
- (String) typeObject.getClass().getMethod(GET_DERIVED_FROM_METHOD_NAME).invoke(typeObject);
+ String derivedFromTypeVal = (String) typeObject.getClass().getMethod(GET_DERIVED_FROM_METHOD_NAME).invoke(typeObject);
if (Objects.equals(derivedFromTypeVal, typeToMatch)) {
return Optional.of(true);
} else if (Objects.isNull(derivedFromTypeVal) || isTypeIsToscaRoot(derivedFromTypeVal)) {
return Optional.of(false);
} else {
- return isTypeExistInServiceTemplateHierarchy(typeToMatch, derivedFromTypeVal, getTypesMethodName,
- serviceTemplate, toscaServiceModel, null);
+ return isTypeExistInServiceTemplateHierarchy(typeToMatch, derivedFromTypeVal, getTypesMethodName, serviceTemplate,
+ toscaServiceModel, null);
}
} else {
- return isTypeExistInImports(typeToMatch, typeToSearch, getTypesMethodName, serviceTemplate,
- toscaServiceModel, analyzedImportFiles);
+ return isTypeExistInImports(typeToMatch, typeToSearch, getTypesMethodName, serviceTemplate, toscaServiceModel, analyzedImportFiles);
}
}
- return isTypeExistInImports(typeToMatch, typeToSearch, getTypesMethodName, serviceTemplate, toscaServiceModel,
- analyzedImportFiles);
+ return isTypeExistInImports(typeToMatch, typeToSearch, getTypesMethodName, serviceTemplate, toscaServiceModel, analyzedImportFiles);
}
private Optional<Boolean> isTypeExistInImports(String typeToMatch, String typeToSearch, String getTypesMethodName,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel, Set<String> filesScanned)
- throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel, Set<String> filesScanned)
+ throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
List<Map<String, Import>> imports = serviceTemplate.getImports();
if (CollectionUtils.isEmpty(imports)) {
return Optional.empty();
}
-
Set<String> createdFilesScanned = createFilesScannedSet(filesScanned);
-
for (Map<String, Import> map : imports) {
ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
- Import anImport = toscaExtensionYamlUtil
- .yamlToObject(toscaExtensionYamlUtil.objectToYaml(map.values().iterator().next()),
- Import.class);
+ Import anImport = toscaExtensionYamlUtil.yamlToObject(toscaExtensionYamlUtil.objectToYaml(map.values().iterator().next()), Import.class);
handleImportWithNoFileEntry(anImport);
String importFile = anImport.getFile();
- ServiceTemplate template = toscaServiceModel.getServiceTemplates()
- .get(fetchFullFileNameForImport(importFile,
- serviceTemplate.getMetadata() == null ? null :
- serviceTemplate.getMetadata().get("filename"),
- serviceTemplate, toscaServiceModel));
- if (Objects.isNull(template) || createdFilesScanned
- .contains(ToscaUtil.getServiceTemplateFileName(template))) {
+ ServiceTemplate template = toscaServiceModel.getServiceTemplates().get(
+ fetchFullFileNameForImport(importFile, serviceTemplate.getMetadata() == null ? null : serviceTemplate.getMetadata().get("filename"),
+ serviceTemplate, toscaServiceModel));
+ if (Objects.isNull(template) || createdFilesScanned.contains(ToscaUtil.getServiceTemplateFileName(template))) {
continue;
} else {
createdFilesScanned.add(ToscaUtil.getServiceTemplateFileName(template));
}
- Optional<Boolean> typeExistInServiceTemplateHierarchy =
- isTypeExistInServiceTemplateHierarchy(typeToMatch, typeToSearch, getTypesMethodName, template,
- toscaServiceModel, createdFilesScanned);
+ Optional<Boolean> typeExistInServiceTemplateHierarchy = isTypeExistInServiceTemplateHierarchy(typeToMatch, typeToSearch,
+ getTypesMethodName, template, toscaServiceModel, createdFilesScanned);
if (typeExistInServiceTemplateHierarchy.isPresent() && (typeExistInServiceTemplateHierarchy.get())) {
createdFilesScanned.clear();
return Optional.of(true);
}
-
}
return Optional.of(false);
}
@@ -628,29 +564,21 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
return (type.contains(TOSCA_DOT) && type.contains(DOT_ROOT));
}
- private boolean isSubstitutionServiceTemplate(String substituteServiceTemplateFileName,
- ServiceTemplate substituteServiceTemplate) {
+ private boolean isSubstitutionServiceTemplate(String substituteServiceTemplateFileName, ServiceTemplate substituteServiceTemplate) {
if (substituteServiceTemplate != null && substituteServiceTemplate.getTopology_template() != null
- && substituteServiceTemplate.getTopology_template().getSubstitution_mappings() != null) {
+ && substituteServiceTemplate.getTopology_template().getSubstitution_mappings() != null) {
if (substituteServiceTemplate.getTopology_template().getSubstitution_mappings().getNode_type() == null) {
- throw new CoreException(
- new ToscaInvalidSubstitutionServiceTemplateErrorBuilder(substituteServiceTemplateFileName)
- .build());
+ throw new CoreException(new ToscaInvalidSubstitutionServiceTemplateErrorBuilder(substituteServiceTemplateFileName).build());
}
return true;
}
return false;
-
}
- private boolean scanAnFlatEntity(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned,
- int rootScanStartInx) {
-
-
- boolean entityFound =
- enrichEntityFromCurrentServiceTemplate(elementType, typeId, flatData, serviceTemplate, toscaModel,
- filesScanned, rootScanStartInx);
+ private boolean scanAnFlatEntity(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData, ServiceTemplate serviceTemplate,
+ ToscaServiceModel toscaModel, List<String> filesScanned, int rootScanStartInx) {
+ boolean entityFound = enrichEntityFromCurrentServiceTemplate(elementType, typeId, flatData, serviceTemplate, toscaModel, filesScanned,
+ rootScanStartInx);
if (!entityFound) {
List<Map<String, Import>> imports = serviceTemplate.getImports();
if (CollectionUtils.isEmpty(imports)) {
@@ -661,25 +589,21 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
if (found) {
return true;
}
- found = isFlatEntity(importMap, flatData, serviceTemplate, filesScanned, toscaModel, elementType,
- typeId);
+ found = isFlatEntity(importMap, flatData, serviceTemplate, filesScanned, toscaModel, elementType, typeId);
}
return found;
}
return true;
}
- private boolean isFlatEntity(Map<String, Import> importMap, ToscaFlatData flatData, ServiceTemplate serviceTemplate,
- List<String> filesScanned, ToscaServiceModel toscaModel, ToscaElementTypes elementType, String typeId) {
+ private boolean isFlatEntity(Map<String, Import> importMap, ToscaFlatData flatData, ServiceTemplate serviceTemplate, List<String> filesScanned,
+ ToscaServiceModel toscaModel, ToscaElementTypes elementType, String typeId) {
boolean found = false;
ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
for (Object importObject : importMap.values()) {
- Import importServiceTemplate = toscaExtensionYamlUtil
- .yamlToObject(toscaExtensionYamlUtil.objectToYaml(importObject),
- Import.class);
+ Import importServiceTemplate = toscaExtensionYamlUtil.yamlToObject(toscaExtensionYamlUtil.objectToYaml(importObject), Import.class);
String fileName = fetchFullFileNameForImport(importServiceTemplate.getFile(),
- serviceTemplate.getMetadata() == null ? null : serviceTemplate.getMetadata().get("filename"),
- serviceTemplate, toscaModel);
+ serviceTemplate.getMetadata() == null ? null : serviceTemplate.getMetadata().get("filename"), serviceTemplate, toscaModel);
if (filesScanned.contains(fileName)) {
return false;
} else {
@@ -689,28 +613,24 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
if (Objects.isNull(template)) {
throw new CoreException(new ToscaFileNotFoundErrorBuilder(fileName).build());
}
- found = scanAnFlatEntity(elementType, typeId, flatData, template, toscaModel, filesScanned,
- filesScanned.size());
+ found = scanAnFlatEntity(elementType, typeId, flatData, template, toscaModel, filesScanned, filesScanned.size());
}
return found;
}
- String fetchFullFileNameForImport(String importServiceTemplateFile, String currentMetadatafileName,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel) {
- Optional<Map.Entry<String, ServiceTemplate>> serviceTemplateEntry =
- toscaServiceModel.getServiceTemplates().entrySet().stream()
- .filter(entry -> entry.getValue() == serviceTemplate).findFirst();
+ String fetchFullFileNameForImport(String importServiceTemplateFile, String currentMetadatafileName, ServiceTemplate serviceTemplate,
+ ToscaServiceModel toscaServiceModel) {
+ Optional<Map.Entry<String, ServiceTemplate>> serviceTemplateEntry = toscaServiceModel.getServiceTemplates().entrySet().stream()
+ .filter(entry -> entry.getValue() == serviceTemplate).findFirst();
if (!serviceTemplateEntry.isPresent()) {
if (importServiceTemplateFile.contains("../")) {
return importServiceTemplateFile.replace("../", "");
} else if (currentMetadatafileName != null && currentMetadatafileName.indexOf('/') != -1) {
- return currentMetadatafileName.substring(0, currentMetadatafileName.indexOf('/')) + "/"
- + importServiceTemplateFile;
+ return currentMetadatafileName.substring(0, currentMetadatafileName.indexOf('/')) + "/" + importServiceTemplateFile;
} else {
return importServiceTemplateFile;
}
}
-
Path currentPath = Paths.get(serviceTemplateEntry.get().getKey()).getParent();
if (currentPath == null) {
currentPath = Paths.get("");
@@ -718,52 +638,43 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
return currentPath.resolve(importServiceTemplateFile).normalize().toString().replaceAll("\\\\", "/");
}
- private boolean enrichEntityFromCurrentServiceTemplate(ToscaElementTypes elementType, String typeId,
- ToscaFlatData flatData, ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel,
- List<String> filesScanned, int rootScanStartInx) {
+ private boolean enrichEntityFromCurrentServiceTemplate(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData,
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned,
+ int rootScanStartInx) {
switch (elementType) {
case CAPABILITY_TYPE:
- if (enrichCapabilityType(elementType, typeId, flatData, serviceTemplate, toscaModel, filesScanned,
- rootScanStartInx)) {
+ if (enrichCapabilityType(elementType, typeId, flatData, serviceTemplate, toscaModel, filesScanned, rootScanStartInx)) {
return false;
}
break;
case NODE_TYPE:
- if (enrichNodeTypeInfo(elementType, typeId, flatData, serviceTemplate, toscaModel, filesScanned,
- rootScanStartInx)) {
+ if (enrichNodeTypeInfo(elementType, typeId, flatData, serviceTemplate, toscaModel, filesScanned, rootScanStartInx)) {
return false;
}
break;
case DATA_TYPE:
- if (enrichDataTypeInfo(elementType, typeId, flatData, serviceTemplate, toscaModel, filesScanned,
- rootScanStartInx)) {
+ if (enrichDataTypeInfo(elementType, typeId, flatData, serviceTemplate, toscaModel, filesScanned, rootScanStartInx)) {
return false;
}
break;
default:
throw new SdcRuntimeException("Entity[" + elementType + "] id[" + typeId + "] flat not supported");
}
-
return true;
-
-
}
- private boolean enrichNodeTypeInfo(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned,
- int rootScanStartInx) {
+ private boolean enrichNodeTypeInfo(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData, ServiceTemplate serviceTemplate,
+ ToscaServiceModel toscaModel, List<String> filesScanned, int rootScanStartInx) {
String derivedFrom;
if (serviceTemplate.getNode_types() != null && serviceTemplate.getNode_types().containsKey(typeId)) {
-
filesScanned.clear();
flatData.addInheritanceHierarchyType(typeId);
NodeType targetNodeType = (NodeType) flatData.getFlatEntity();
NodeType sourceNodeType = serviceTemplate.getNode_types().get(typeId);
derivedFrom = sourceNodeType.getDerived_from();
if (derivedFrom != null) {
- boolean isEntityFound =
- scanAnFlatEntity(elementType, derivedFrom, flatData, serviceTemplate, toscaModel, filesScanned,
- rootScanStartInx);
+ boolean isEntityFound = scanAnFlatEntity(elementType, derivedFrom, flatData, serviceTemplate, toscaModel, filesScanned,
+ rootScanStartInx);
if (!isEntityFound) {
throw new CoreException(new ToscaElementTypeNotFoundErrorBuilder(typeId).build());
}
@@ -775,21 +686,18 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
return false;
}
- private boolean enrichDataTypeInfo(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned,
- int rootScanStartInx) {
+ private boolean enrichDataTypeInfo(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData, ServiceTemplate serviceTemplate,
+ ToscaServiceModel toscaModel, List<String> filesScanned, int rootScanStartInx) {
String derivedFrom;
if (serviceTemplate.getData_types() != null && serviceTemplate.getData_types().containsKey(typeId)) {
-
filesScanned.clear();
flatData.addInheritanceHierarchyType(typeId);
DataType targetDataType = (DataType) flatData.getFlatEntity();
DataType sourceDataType = serviceTemplate.getData_types().get(typeId);
derivedFrom = sourceDataType.getDerived_from();
if (derivedFrom != null && !isPrimitiveType(derivedFrom)) {
- boolean isEntityFound =
- scanAnFlatEntity(elementType, derivedFrom, flatData, serviceTemplate, toscaModel, filesScanned,
- rootScanStartInx);
+ boolean isEntityFound = scanAnFlatEntity(elementType, derivedFrom, flatData, serviceTemplate, toscaModel, filesScanned,
+ rootScanStartInx);
if (!isEntityFound) {
throw new CoreException(new ToscaElementTypeNotFoundErrorBuilder(typeId).build());
}
@@ -801,28 +709,18 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
return false;
}
- private static boolean isPrimitiveType(String toscaType) {
- return (toscaType.equals(PropertyType.STRING.getDisplayName()) || toscaType.equals(PropertyType.INTEGER
- .getDisplayName())
- || toscaType.equals(PropertyType.FLOAT.getDisplayName()));
- }
-
- private boolean enrichCapabilityType(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned,
- int rootScanStartInx) {
+ private boolean enrichCapabilityType(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData, ServiceTemplate serviceTemplate,
+ ToscaServiceModel toscaModel, List<String> filesScanned, int rootScanStartInx) {
String derivedFrom;
- if (serviceTemplate.getCapability_types() != null && serviceTemplate.getCapability_types()
- .containsKey(typeId)) {
-
+ if (serviceTemplate.getCapability_types() != null && serviceTemplate.getCapability_types().containsKey(typeId)) {
filesScanned.clear();
flatData.addInheritanceHierarchyType(typeId);
CapabilityType targetCapabilityType = (CapabilityType) flatData.getFlatEntity();
CapabilityType sourceCapabilityType = serviceTemplate.getCapability_types().get(typeId);
derivedFrom = sourceCapabilityType.getDerived_from();
if (derivedFrom != null) {
- boolean isEntityFound =
- scanAnFlatEntity(elementType, derivedFrom, flatData, serviceTemplate, toscaModel, filesScanned,
- rootScanStartInx);
+ boolean isEntityFound = scanAnFlatEntity(elementType, derivedFrom, flatData, serviceTemplate, toscaModel, filesScanned,
+ rootScanStartInx);
if (!isEntityFound) {
throw new CoreException(new ToscaElementTypeNotFoundErrorBuilder(typeId).build());
}
@@ -838,18 +736,12 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
targetNodeType.setDerived_from(sourceNodeType.getDerived_from());
targetNodeType.setDescription(sourceNodeType.getDescription());
targetNodeType.setVersion(sourceNodeType.getVersion());
- targetNodeType
- .setProperties(CommonMethods.mergeMaps(targetNodeType.getProperties(), sourceNodeType.getProperties()));
+ targetNodeType.setProperties(CommonMethods.mergeMaps(targetNodeType.getProperties(), sourceNodeType.getProperties()));
combineNodeTypeInterfaceInfo(sourceNodeType, targetNodeType);
- targetNodeType
- .setArtifacts(CommonMethods.mergeMaps(targetNodeType.getArtifacts(), sourceNodeType.getArtifacts()));
- targetNodeType
- .setAttributes(CommonMethods.mergeMaps(targetNodeType.getAttributes(), sourceNodeType.getAttributes()));
- targetNodeType.setCapabilities(
- CommonMethods.mergeMaps(targetNodeType.getCapabilities(), sourceNodeType.getCapabilities()));
- targetNodeType.setRequirements(
- CommonMethods.mergeListsOfMap(targetNodeType.getRequirements(), sourceNodeType.getRequirements()));
-
+ targetNodeType.setArtifacts(CommonMethods.mergeMaps(targetNodeType.getArtifacts(), sourceNodeType.getArtifacts()));
+ targetNodeType.setAttributes(CommonMethods.mergeMaps(targetNodeType.getAttributes(), sourceNodeType.getAttributes()));
+ targetNodeType.setCapabilities(CommonMethods.mergeMaps(targetNodeType.getCapabilities(), sourceNodeType.getCapabilities()));
+ targetNodeType.setRequirements(CommonMethods.mergeListsOfMap(targetNodeType.getRequirements(), sourceNodeType.getRequirements()));
}
private void combineNodeTypeInterfaceInfo(NodeType sourceNodeType, NodeType targetNodeType) {
@@ -868,22 +760,19 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
Map<String, Object> combineInterfaces = new HashMap<>();
for (Map.Entry<String, Object> sourceInterfaceDefEntry : sourceNodeType.getInterfaces().entrySet()) {
String interfaceName = sourceInterfaceDefEntry.getKey();
- if (!MapUtils.isEmpty(targetNodeType.getInterfaces()) && targetNodeType.getInterfaces()
- .containsKey(interfaceName)) {
- combineInterfaces.put(interfaceName, combineInterfaceDefinition(sourceInterfaceDefEntry.getValue(),
- targetNodeType.getInterfaces().get(interfaceName)));
+ if (!MapUtils.isEmpty(targetNodeType.getInterfaces()) && targetNodeType.getInterfaces().containsKey(interfaceName)) {
+ combineInterfaces.put(interfaceName,
+ combineInterfaceDefinition(sourceInterfaceDefEntry.getValue(), targetNodeType.getInterfaces().get(interfaceName)));
} else {
combineInterfaces.put(sourceInterfaceDefEntry.getKey(), sourceInterfaceDefEntry.getValue());
}
}
-
for (Map.Entry<String, Object> targetInterfaceDefEntry : targetNodeType.getInterfaces().entrySet()) {
String interfaceName = targetInterfaceDefEntry.getKey();
if (!sourceNodeType.getInterfaces().containsKey(interfaceName)) {
combineInterfaces.put(targetInterfaceDefEntry.getKey(), targetInterfaceDefEntry.getValue());
}
}
-
return Optional.of(combineInterfaces);
}
@@ -891,16 +780,13 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
if ((MapUtils.isEmpty(sourceNodeType.getInterfaces()) && MapUtils.isEmpty(targetNodeType.getInterfaces()))) {
return Optional.empty();
}
-
if (MapUtils.isEmpty(sourceNodeType.getInterfaces()) && !MapUtils.isEmpty(targetNodeType.getInterfaces())) {
return Optional.of(targetNodeType.getInterfaces());
}
-
if (!MapUtils.isEmpty(sourceNodeType.getInterfaces()) && MapUtils.isEmpty(targetNodeType.getInterfaces())) {
return Optional.of(sourceNodeType.getInterfaces());
}
return Optional.empty();
-
}
private Object combineInterfaceDefinition(Object sourceInterfaceDefType, Object targetInterfaceDefType) {
@@ -909,9 +795,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
InterfaceDefinitionType combineInterface = new InterfaceDefinitionType();
combineInterface.setType(sourceInterface.getType());
combineInterface.setInputs(CommonMethods.mergeMaps(targetInterface.getInputs(), sourceInterface.getInputs()));
- combineInterface.setOperations(
- CommonMethods.mergeMaps(targetInterface.getOperations(), sourceInterface.getOperations()));
-
+ combineInterface.setOperations(CommonMethods.mergeMaps(targetInterface.getOperations(), sourceInterface.getOperations()));
Optional<Object> interfaceDefObject = combineInterface.convertInterfaceDefinitionTypeToToscaObj();
if (!interfaceDefObject.isPresent()) {
throw new SdcRuntimeException("Illegal Statement");
@@ -923,22 +807,15 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
targetDataType.setDerived_from(sourceDataType.getDerived_from());
targetDataType.setDescription(sourceDataType.getDescription());
targetDataType.setVersion(sourceDataType.getVersion());
- targetDataType
- .setProperties(CommonMethods.mergeMaps(targetDataType.getProperties(), sourceDataType.getProperties()));
- targetDataType.setConstraints(
- CommonMethods.mergeLists(targetDataType.getConstraints(), sourceDataType.getConstraints()));
+ targetDataType.setProperties(CommonMethods.mergeMaps(targetDataType.getProperties(), sourceDataType.getProperties()));
+ targetDataType.setConstraints(CommonMethods.mergeLists(targetDataType.getConstraints(), sourceDataType.getConstraints()));
}
private void combineCapabilityTypeInfo(CapabilityType sourceCapabilityType, CapabilityType targetCapabilityType) {
-
- targetCapabilityType.setAttributes(
- CommonMethods.mergeMaps(targetCapabilityType.getAttributes(), sourceCapabilityType.getAttributes()));
- targetCapabilityType.setProperties(
- CommonMethods.mergeMaps(targetCapabilityType.getProperties(), sourceCapabilityType.getProperties()));
- targetCapabilityType.setValid_source_types(CommonMethods
- .mergeLists(targetCapabilityType.getValid_source_types(),
- sourceCapabilityType.getValid_source_types()));
-
+ targetCapabilityType.setAttributes(CommonMethods.mergeMaps(targetCapabilityType.getAttributes(), sourceCapabilityType.getAttributes()));
+ targetCapabilityType.setProperties(CommonMethods.mergeMaps(targetCapabilityType.getProperties(), sourceCapabilityType.getProperties()));
+ targetCapabilityType.setValid_source_types(
+ CommonMethods.mergeLists(targetCapabilityType.getValid_source_types(), sourceCapabilityType.getValid_source_types()));
if (StringUtils.isNotEmpty(sourceCapabilityType.getDerived_from())) {
targetCapabilityType.setDerived_from(sourceCapabilityType.getDerived_from());
}
@@ -948,11 +825,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
if (StringUtils.isNotEmpty(sourceCapabilityType.getVersion())) {
targetCapabilityType.setVersion(sourceCapabilityType.getVersion());
}
-
-
}
-
/*
* Create node type according to the input substitution service template, while the substitution
* service template can be mappted to this node type, for substitution mapping.
@@ -962,8 +836,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
* @return the node type
*/
@Override
- public NodeType createInitSubstitutionNodeType(ServiceTemplate substitutionServiceTemplate,
- String nodeTypeDerivedFromValue) {
+ public NodeType createInitSubstitutionNodeType(ServiceTemplate substitutionServiceTemplate, String nodeTypeDerivedFromValue) {
NodeType substitutionNodeType = new NodeType();
substitutionNodeType.setDerived_from(nodeTypeDerivedFromValue);
substitutionNodeType.setDescription(substitutionServiceTemplate.getDescription());
@@ -973,21 +846,18 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
@Override
- public Map<String, PropertyDefinition> manageSubstitutionNodeTypeProperties(
- ServiceTemplate substitutionServiceTemplate) {
+ public Map<String, PropertyDefinition> manageSubstitutionNodeTypeProperties(ServiceTemplate substitutionServiceTemplate) {
Map<String, PropertyDefinition> substitutionNodeTypeProperties = new HashMap<>();
Map<String, ParameterDefinition> properties = substitutionServiceTemplate.getTopology_template().getInputs();
if (properties == null) {
return null;
}
-
PropertyDefinition propertyDefinition;
String toscaPropertyName;
for (Map.Entry<String, ParameterDefinition> entry : properties.entrySet()) {
toscaPropertyName = entry.getKey();
propertyDefinition = new PropertyDefinition();
- ParameterDefinition parameterDefinition =
- substitutionServiceTemplate.getTopology_template().getInputs().get(toscaPropertyName);
+ ParameterDefinition parameterDefinition = substitutionServiceTemplate.getTopology_template().getInputs().get(toscaPropertyName);
propertyDefinition.setType(parameterDefinition.getType());
propertyDefinition.setDescription(parameterDefinition.getDescription());
propertyDefinition.set_default(parameterDefinition.get_default());
@@ -1009,9 +879,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
return substitutionNodeTypeProperties;
}
-
- private Map<String, AttributeDefinition> manageSubstitutionNodeTypeAttributes(
- ServiceTemplate substitutionServiceTemplate) {
+ private Map<String, AttributeDefinition> manageSubstitutionNodeTypeAttributes(ServiceTemplate substitutionServiceTemplate) {
Map<String, AttributeDefinition> substitutionNodeTypeAttributes = new HashMap<>();
Map<String, ParameterDefinition> attributes = substitutionServiceTemplate.getTopology_template().getOutputs();
if (attributes == null) {
@@ -1019,12 +887,10 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
AttributeDefinition attributeDefinition;
String toscaAttributeName;
-
for (Map.Entry<String, ParameterDefinition> entry : attributes.entrySet()) {
attributeDefinition = new AttributeDefinition();
toscaAttributeName = entry.getKey();
- ParameterDefinition parameterDefinition =
- substitutionServiceTemplate.getTopology_template().getOutputs().get(toscaAttributeName);
+ ParameterDefinition parameterDefinition = substitutionServiceTemplate.getTopology_template().getOutputs().get(toscaAttributeName);
if (parameterDefinition.getType() != null && !parameterDefinition.getType().isEmpty()) {
attributeDefinition.setType(parameterDefinition.getType());
} else {
@@ -1050,36 +916,29 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
* @return true if the requirement already exists and false otherwise
*/
@Override
- public boolean isRequirementExistInNodeTemplate(NodeTemplate nodeTemplate, String requirementId,
- RequirementAssignment requirementAssignment) {
+ public boolean isRequirementExistInNodeTemplate(NodeTemplate nodeTemplate, String requirementId, RequirementAssignment requirementAssignment) {
List<Map<String, RequirementAssignment>> nodeTemplateRequirements = nodeTemplate.getRequirements();
return nodeTemplateRequirements != null && nodeTemplateRequirements.stream().anyMatch(
- requirement -> requirement.containsKey(requirementId) && DataModelUtil.compareRequirementAssignment(
- requirementAssignment, requirement.get(requirementId)));
+ requirement -> requirement.containsKey(requirementId) && DataModelUtil
+ .compareRequirementAssignment(requirementAssignment, requirement.get(requirementId)));
}
private <T> boolean isTypeOf(T object, String type, String getTypesMethodName, ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel) {
+ ToscaServiceModel toscaServiceModel) {
if (object == null) {
return false;
}
-
try {
String objectType = (String) object.getClass().getMethod(GET_TYPE_METHOD_NAME).invoke(object);
if (Objects.equals(objectType, type)) {
return true;
}
-
- Optional<Boolean> typeExistInServiceTemplateHierarchy =
- isTypeExistInServiceTemplateHierarchy(type, objectType, getTypesMethodName, serviceTemplate,
- toscaServiceModel, null);
- return typeExistInServiceTemplateHierarchy.orElseThrow(
- () -> new CoreException(new ToscaElementTypeNotFoundErrorBuilder(objectType).build()));
-
+ Optional<Boolean> typeExistInServiceTemplateHierarchy = isTypeExistInServiceTemplateHierarchy(type, objectType, getTypesMethodName,
+ serviceTemplate, toscaServiceModel, null);
+ return typeExistInServiceTemplateHierarchy
+ .orElseThrow(() -> new CoreException(new ToscaElementTypeNotFoundErrorBuilder(objectType).build()));
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new SdcRuntimeException(e);
}
}
}
-
-