aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/main')
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java303
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java253
2 files changed, 220 insertions, 336 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java
index 64b0006acd..9b9cd80385 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java
@@ -16,28 +16,54 @@
package org.openecomp.sdc.tosca.services;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
-import org.onap.sdc.tosca.datatypes.model.*;
+import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.onap.sdc.tosca.datatypes.model.CapabilityAssignment;
+import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.onap.sdc.tosca.datatypes.model.Constraint;
+import org.onap.sdc.tosca.datatypes.model.EntrySchema;
+import org.onap.sdc.tosca.datatypes.model.GroupDefinition;
+import org.onap.sdc.tosca.datatypes.model.Import;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
+import org.onap.sdc.tosca.datatypes.model.PolicyDefinition;
+import org.onap.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.onap.sdc.tosca.datatypes.model.RelationshipTemplate;
+import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
+import org.onap.sdc.tosca.datatypes.model.TopologyTemplate;
import org.onap.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt;
import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.common.utils.CommonUtil;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
-import org.openecomp.sdc.tosca.errors.*;
+import org.openecomp.sdc.tosca.errors.InvalidAddActionNullEntityErrorBuilder;
+import org.openecomp.sdc.tosca.errors.InvalidRequirementAssignmentErrorBuilder;
import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
-import java.io.*;
-import java.util.*;
-
/**
* The type Data model util.
*/
@@ -46,7 +72,6 @@ public class DataModelUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(DataModelUtil.class);
private static final String SERVICE_TEMPLATE = "Service Template";
private static final String NODE_TYPE = "Node Type";
- private static final String OPERATIONS = "operations";
private DataModelUtil() {
// prevent instantiation
@@ -59,7 +84,7 @@ public class DataModelUtil {
* @param substitutionMapping the substitution mapping
*/
public static void addSubstitutionMapping(ServiceTemplate serviceTemplate,
- SubstitutionMapping substitutionMapping) {
+ SubstitutionMapping substitutionMapping) {
if (serviceTemplate == null) {
throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping", SERVICE_TEMPLATE)
.build());
@@ -92,11 +117,11 @@ public class DataModelUtil {
* @param substitutionMappingRequirementList the substitution mapping requirement list
*/
public static void addSubstitutionMappingReq(ServiceTemplate serviceTemplate,
- String substitutionMappingRequirementId,
- List<String> substitutionMappingRequirementList) {
+ String substitutionMappingRequirementId, List<String> substitutionMappingRequirementList) {
if (serviceTemplate == null) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Requirements",
- SERVICE_TEMPLATE).build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Requirements", SERVICE_TEMPLATE)
+ .build());
}
if (serviceTemplate.getTopology_template() == null) {
@@ -121,8 +146,7 @@ public class DataModelUtil {
* @param substitutionMappingCapabilityList the substitution mapping capability list
*/
public static void addSubstitutionMappingCapability(ServiceTemplate serviceTemplate,
- String substitutionMappingCapabilityId,
- List<String> substitutionMappingCapabilityList) {
+ String substitutionMappingCapabilityId, List<String> substitutionMappingCapabilityList) {
if (serviceTemplate == null) {
throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Capabilities",
SERVICE_TEMPLATE).build());
@@ -180,10 +204,10 @@ public class DataModelUtil {
* @param nodeTemplate the node template
*/
public static void addNodeTemplate(ServiceTemplate serviceTemplate, String nodeTemplateId,
- NodeTemplate nodeTemplate) {
+ NodeTemplate nodeTemplate) {
if (serviceTemplate == null) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Node Template", SERVICE_TEMPLATE)
- .build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Node Template", SERVICE_TEMPLATE).build());
}
TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
if (Objects.isNull(topologyTemplate)) {
@@ -208,8 +232,8 @@ public class DataModelUtil {
}
if (nodeType == null) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Capability Definition", NODE_TYPE)
- .build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Capability Definition", NODE_TYPE).build());
}
if (MapUtils.isEmpty(nodeType.getCapabilities())) {
@@ -256,10 +280,10 @@ public class DataModelUtil {
* @param policyDefinition the policy definition
*/
public static void addPolicyDefinition(ServiceTemplate serviceTemplate, String policyId,
- PolicyDefinition policyDefinition) {
+ PolicyDefinition policyDefinition) {
if (serviceTemplate == null) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Policy Definition", SERVICE_TEMPLATE)
- .build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Policy Definition", SERVICE_TEMPLATE).build());
}
TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
if (Objects.isNull(topologyTemplate)) {
@@ -297,10 +321,10 @@ public class DataModelUtil {
* @param relationshipTemplate the relationship template
*/
public static void addRelationshipTemplate(ServiceTemplate serviceTemplate, String relationshipTemplateId,
- RelationshipTemplate relationshipTemplate) {
+ RelationshipTemplate relationshipTemplate) {
if (serviceTemplate == null) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Relationship Template",
- SERVICE_TEMPLATE).build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Relationship Template", SERVICE_TEMPLATE).build());
}
if (serviceTemplate.getTopology_template() == null) {
serviceTemplate.setTopology_template(new TopologyTemplate());
@@ -320,10 +344,11 @@ public class DataModelUtil {
* @param requirementAssignment the requirement assignment
*/
public static void addRequirementAssignment(NodeTemplate nodeTemplate, String requirementId,
- RequirementAssignment requirementAssignment) {
+ RequirementAssignment requirementAssignment) {
if (nodeTemplate == null) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Requirement Assignment",
- "Node Template").build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Requirement Assignment",
+ "Node Template").build());
}
if (requirementAssignment.getNode() == null) {
throw new CoreException(new InvalidRequirementAssignmentErrorBuilder(requirementId).build());
@@ -401,8 +426,8 @@ public class DataModelUtil {
* @param requirementsDefinitionList requirement definition list
* @param requirementKey requirement key
*/
- public static Optional<RequirementDefinition> getRequirementDefinition(List<Map<String, RequirementDefinition>> requirementsDefinitionList,
- String requirementKey) {
+ public static Optional<RequirementDefinition> getRequirementDefinition(
+ List<Map<String, RequirementDefinition>> requirementsDefinitionList, String requirementKey) {
if (CollectionUtils.isEmpty(requirementsDefinitionList)) {
return Optional.empty();
}
@@ -427,7 +452,7 @@ public class DataModelUtil {
* @return the capability definition
*/
public static Optional<CapabilityDefinition> getCapabilityDefinition(NodeType nodeType,
- String capabilityDefinitionId) {
+ String capabilityDefinitionId) {
if (nodeType == null || nodeType.getCapabilities() == null || capabilityDefinitionId == null) {
return Optional.empty();
}
@@ -442,10 +467,10 @@ public class DataModelUtil {
* @param group the group
*/
public static void addGroupDefinitionToTopologyTemplate(ServiceTemplate serviceTemplate, String groupName,
- GroupDefinition group) {
+ GroupDefinition group) {
if (serviceTemplate == null) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Group Definition", SERVICE_TEMPLATE)
- .build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Group Definition", SERVICE_TEMPLATE).build());
}
TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
@@ -500,8 +525,7 @@ public class DataModelUtil {
* @return the property definition
*/
public static ParameterDefinition createParameterDefinition(String type, String description, boolean required,
- List<Constraint> constraints,
- EntrySchema entrySchema, Object defaultVal) {
+ List<Constraint> constraints, EntrySchema entrySchema, Object defaultVal) {
ParameterDefinition paramDef = new ParameterDefinition();
paramDef.setType(type);
paramDef.setDescription(description);
@@ -522,7 +546,7 @@ public class DataModelUtil {
* @return the requirement definition
*/
public static RequirementDefinition createRequirement(String capability, String node, String relationship,
- Object[] occurrences) {
+ Object[] occurrences) {
RequirementDefinition requirementDefinition = new RequirementDefinition();
requirementDefinition.setCapability(capability);
requirementDefinition.setNode(node);
@@ -562,7 +586,7 @@ public class DataModelUtil {
* @return the map
*/
public static Map createGetInputPropertyValueFromListParameter(String inputPropertyListName, int indexInTheList,
- String... nestedPropertyName) {
+ String... nestedPropertyName) {
List<Object> propertyList = new ArrayList<>();
propertyList.add(inputPropertyListName);
propertyList.add(indexInTheList);
@@ -607,7 +631,7 @@ public class DataModelUtil {
* @return the parameter definition ext
*/
public static ParameterDefinitionExt convertAttributeDefToParameterDef(AttributeDefinition attributeDefinition,
- Map<String, List> outputValue) {
+ Map<String, List> outputValue) {
if (attributeDefinition == null) {
return null;
}
@@ -630,11 +654,11 @@ public class DataModelUtil {
* @param parameterDefinition the parameter definition
*/
public static void addInputParameterToTopologyTemplate(ServiceTemplate serviceTemplate,
- String parameterDefinitionId,
- ParameterDefinition parameterDefinition) {
+ String parameterDefinitionId, ParameterDefinition parameterDefinition) {
if (Objects.isNull(serviceTemplate)) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Topology Template Input Parameter",
- SERVICE_TEMPLATE).build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Topology Template Input Parameter", SERVICE_TEMPLATE)
+ .build());
}
TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
if (Objects.isNull(topologyTemplate)) {
@@ -655,11 +679,11 @@ public class DataModelUtil {
* @param parameterDefinition the parameter definition
*/
public static void addOutputParameterToTopologyTemplate(ServiceTemplate serviceTemplate,
- String parameterDefinitionId,
- ParameterDefinition parameterDefinition) {
+ String parameterDefinitionId, ParameterDefinition parameterDefinition) {
if (Objects.isNull(serviceTemplate)) {
- throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Topology Template Output Parameter",
- SERVICE_TEMPLATE).build());
+ throw new CoreException(
+ new InvalidAddActionNullEntityErrorBuilder("Topology Template Output Parameter", SERVICE_TEMPLATE)
+ .build());
}
TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
if (Objects.isNull(topologyTemplate)) {
@@ -679,7 +703,7 @@ public class DataModelUtil {
* @param requirementDef added requirement def
*/
public static void addRequirementToList(List<Map<String, RequirementDefinition>> requirementList,
- Map<String, RequirementDefinition> requirementDef) {
+ Map<String, RequirementDefinition> requirementDef) {
if (requirementDef == null) {
return;
}
@@ -710,9 +734,8 @@ public class DataModelUtil {
ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
for (Map<String, RequirementAssignment> requirementAssignmentMap : templateRequirements) {
for (Map.Entry<String, RequirementAssignment> requirementEntry : requirementAssignmentMap.entrySet()) {
- RequirementAssignment requirementAssignment =
- (toscaExtensionYamlUtil.yamlToObject(toscaExtensionYamlUtil.objectToYaml(requirementEntry.getValue()),
- RequirementAssignment.class));
+ RequirementAssignment requirementAssignment = (toscaExtensionYamlUtil.yamlToObject(
+ toscaExtensionYamlUtil.objectToYaml(requirementEntry.getValue()), RequirementAssignment.class));
nodeTemplateRequirementsAssignment.put(requirementEntry.getKey(), requirementAssignment);
}
}
@@ -757,8 +780,8 @@ public class DataModelUtil {
* @param requirementsAssignmentList requirement definition list
* @param requirementKey requirement key
*/
- public static Optional<List<RequirementAssignment>> getRequirementAssignment(List<Map<String, RequirementAssignment>> requirementsAssignmentList,
- String requirementKey) {
+ public static Optional<List<RequirementAssignment>> getRequirementAssignment(
+ List<Map<String, RequirementAssignment>> requirementsAssignmentList, String requirementKey) {
if (CollectionUtils.isEmpty(requirementsAssignmentList)) {
return Optional.empty();
}
@@ -786,7 +809,7 @@ public class DataModelUtil {
* @param requirementKey requirement key
*/
public static void removeRequirementsDefinition(List<Map<String, RequirementDefinition>> requirementsDefinitionList,
- String requirementKey) {
+ String requirementKey) {
if (requirementsDefinitionList == null) {
return;
}
@@ -810,7 +833,7 @@ public class DataModelUtil {
* @param requirementKey requirement key
*/
public static void removeRequirementsAssignment(List<Map<String, RequirementAssignment>> requirementsAssignmentList,
- String requirementKey) {
+ String requirementKey) {
if (requirementsAssignmentList == null) {
return;
}
@@ -836,7 +859,7 @@ public class DataModelUtil {
* @param requirementAssignmentToBeDeleted the requirement assignment to be deleted
*/
public static void removeRequirementAssignment(NodeTemplate nodeTemplate, String requirementKey,
- RequirementAssignment requirementAssignmentToBeDeleted) {
+ RequirementAssignment requirementAssignmentToBeDeleted) {
ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
List<Map<String, RequirementAssignment>> nodeTemplateRequirements = nodeTemplate.getRequirements();
if (nodeTemplateRequirements == null) {
@@ -960,7 +983,7 @@ public class DataModelUtil {
* @return node template properties
*/
public static Map<String, Object> getNodeTemplateProperties(ServiceTemplate serviceTemplate,
- String nodeTemplateId) {
+ String nodeTemplateId) {
if (serviceTemplate == null || serviceTemplate.getTopology_template() == null
|| serviceTemplate.getTopology_template().getNode_templates() == null
|| serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) == null) {
@@ -1097,8 +1120,7 @@ public class DataModelUtil {
* @return the substitution mapping
*/
public static SubstitutionMapping createSubstitutionTemplateSubMapping(String nodeTypeKey,
- NodeType substitutionNodeType,
- Map<String, Map<String, List<String>>> mapping) {
+ NodeType substitutionNodeType, Map<String, Map<String, List<String>>> mapping) {
SubstitutionMapping substitutionMapping = new SubstitutionMapping();
substitutionMapping.setNode_type(nodeTypeKey);
substitutionMapping.setCapabilities(manageCapabilityMapping(substitutionNodeType.getCapabilities(),
@@ -1117,8 +1139,7 @@ public class DataModelUtil {
* @param capabilityAttributes the capability attributes
*/
public static void addNodeTemplateCapability(NodeTemplate nodeTemplate, String capabilityId,
- Map<String, Object> capabilityProperties,
- Map<String, Object> capabilityAttributes) {
+ Map<String, Object> capabilityProperties, Map<String, Object> capabilityAttributes) {
Map<String, CapabilityAssignment> capabilities = nodeTemplate.getCapabilities();
if (Objects.isNull(capabilities)) {
capabilities = new HashMap<>();
@@ -1130,8 +1151,9 @@ public class DataModelUtil {
nodeTemplate.setCapabilities(capabilities);
}
- private static Map<String, List<String>> manageRequirementMapping(List<Map<String, RequirementDefinition>> requirementList,
- Map<String, List<String>> requirementSubstitutionMapping) {
+ private static Map<String, List<String>> manageRequirementMapping(
+ List<Map<String, RequirementDefinition>> requirementList,
+ Map<String, List<String>> requirementSubstitutionMapping) {
if (requirementList == null) {
return null;
}
@@ -1149,7 +1171,7 @@ public class DataModelUtil {
}
private static Map<String, List<String>> manageCapabilityMapping(Map<String, CapabilityDefinition> capabilities,
- Map<String, List<String>> capabilitySubstitutionMapping) {
+ Map<String, List<String>> capabilitySubstitutionMapping) {
if (capabilities == null) {
return null;
}
@@ -1165,153 +1187,8 @@ public class DataModelUtil {
return capabilityMapping;
}
- /**
- * Add interface operation.
- *
- * @param serviceTemplate the service template
- * @param interfaceId the interface id
- * @param operationId the operation id
- * @param operationDefinition the operation definition
- */
- public static void addInterfaceOperation(ServiceTemplate serviceTemplate, String interfaceId, String operationId,
- OperationDefinition operationDefinition) {
- Map<String, Object> interfaceTypes = serviceTemplate.getInterface_types();
- if (MapUtils.isEmpty(interfaceTypes) || Objects.isNull(interfaceTypes.get(interfaceId))) {
- return;
- }
-
- Object interfaceObject = interfaceTypes.get(interfaceId);
- Map<String, Object> interfaceAsMap = CommonUtil.getObjectAsMap(interfaceObject);
- interfaceAsMap.put(operationId, operationDefinition);
- }
-
- public static Map<String, InterfaceType> getInterfaceTypes(ServiceTemplate serviceTemplate) {
- Map<String, Object> interfaceTypes = serviceTemplate.getInterface_types();
-
- if (MapUtils.isEmpty(interfaceTypes)) {
- return new HashMap<>();
- }
-
- Map<String, InterfaceType> convertedInterfaceTypes = new HashMap<>();
- for (Map.Entry<String, Object> interfaceEntry : interfaceTypes.entrySet()) {
- try {
- Optional<InterfaceType> interfaceType =
- convertObjToInterfaceType(interfaceEntry.getKey(), interfaceEntry.getValue());
- interfaceType.ifPresent(
- interfaceValue -> convertedInterfaceTypes.put(interfaceEntry.getKey(), interfaceValue));
- } catch (Exception e) {
- LOGGER.error("Cannot create interface object", e);
- throw new CoreException(new ToscaInvalidInterfaceValueErrorBuilder(e.getMessage()).build());
- }
- }
-
- return convertedInterfaceTypes;
- }
-
- public static <T extends InterfaceDefinition> Optional<T> convertObjToInterfaceDefinition(String interfaceId,
- Object interfaceObj,
- Class<T> interfaceClass) {
- try {
- Optional<T> interfaceDefinition = CommonUtil.createObjectUsingSetters(interfaceObj, interfaceClass);
- interfaceDefinition.ifPresent(interfaceDefinitionType1 -> updateInterfaceDefinitionOperations(
- CommonUtil.getObjectAsMap(interfaceObj), interfaceDefinitionType1));
- return interfaceDefinition;
- } catch (Exception ex) {
- LOGGER.error("Could not create {} from {}", InterfaceDefinitionType.class.getName(), interfaceId, ex);
- throw new CoreException(new CreateInterfaceObjectErrorBuilder(InterfaceDefinitionType.class.getName(),
- interfaceId, ex.getMessage()).build());
- }
-
- }
-
-
- public static Optional<InterfaceType> convertObjToInterfaceType(String interfaceId, Object interfaceObj) {
- try {
- Optional<InterfaceType> interfaceType =
- CommonUtil.createObjectUsingSetters(interfaceObj, InterfaceType.class);
- interfaceType.ifPresent(
- interfaceType1 -> updateInterfaceTypeOperations(CommonUtil.getObjectAsMap(interfaceObj),
- interfaceType1));
- return interfaceType;
- } catch (Exception ex) {
- LOGGER.error("Could not create {} from {}", InterfaceType.class.getName(), interfaceId, ex);
- throw new CoreException(new CreateInterfaceObjectErrorBuilder(InterfaceType.class.getName(), interfaceId,
- ex.getMessage()).build());
- }
- }
-
- public static Optional<Object> convertInterfaceTypeToObj(InterfaceType interfaceType) {
- return converInterfaceToToscaInterfaceObj(interfaceType);
- }
-
- public static Optional<Object> convertInterfaceDefinitionTypeToObj(InterfaceDefinitionType interfaceDefinitionType) {
- return converInterfaceToToscaInterfaceObj(interfaceDefinitionType);
- }
-
- private static Optional<Object> converInterfaceToToscaInterfaceObj(Object interfaceEntity) {
- if (Objects.isNull(interfaceEntity)) {
- return Optional.empty();
- }
-
- Map<String, Object> interfaceAsMap = CommonUtil.getObjectAsMap(interfaceEntity);
- Map<String, Object> operations = (Map<String, Object>) interfaceAsMap.get(OPERATIONS);
- if (MapUtils.isNotEmpty(operations)) {
- interfaceAsMap.remove(OPERATIONS);
- interfaceAsMap.putAll(operations);
- }
-
- ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
- return Optional.of(objectMapper.convertValue(interfaceAsMap, Object.class));
- }
-
- private static void updateInterfaceTypeOperations(Map<String, Object> interfaceAsMap, InterfaceType interfaceType) {
-
- Set<String> fieldNames = CommonUtil.getClassFieldNames(InterfaceType.class);
-
- for (Map.Entry<String, Object> entry : interfaceAsMap.entrySet()) {
- Optional<? extends OperationDefinition> operationDefinition =
- createOperation(entry.getKey(), entry.getValue(), fieldNames, OperationDefinitionType.class);
- operationDefinition.ifPresent(operation -> interfaceType.addOperation(entry.getKey(), operation));
- }
- }
-
- private static Optional<? extends OperationDefinition> createOperation(String propertyName,
- Object operationCandidate,
- Set<String> fieldNames,
- Class<? extends OperationDefinition> operationClass) {
- if (!fieldNames.contains(propertyName)) {
- try {
- return CommonUtil.createObjectUsingSetters(operationCandidate, operationClass);
- } catch (Exception ex) {
- LOGGER.error("Could not create Operation from {}", propertyName, ex);
- throw new CoreException(new CreateInterfaceOperationObjectErrorBuilder(propertyName, ex.getMessage())
- .build());
- }
- }
-
- return Optional.empty();
- }
-
- private static <T extends OperationDefinition> void updateInterfaceDefinitionOperations(Map<String, Object> interfaceAsMap,
- InterfaceDefinition interfaceDefinition) {
-
- Set<String> fieldNames = CommonUtil.getClassFieldNames(InterfaceDefinitionType.class);
- Optional<? extends OperationDefinition> operationDefinition;
-
- for (Map.Entry<String, Object> entry : interfaceAsMap.entrySet()) {
- operationDefinition = createOperation(entry.getKey(), entry.getValue(), fieldNames,
- interfaceDefinition instanceof InterfaceDefinitionType ? OperationDefinitionType.class :
- OperationDefinitionTemplate.class);
- operationDefinition.ifPresent(operation -> interfaceDefinition.addOperation(entry.getKey(), operation));
- }
-
- }
-
-
public static void addSubstitutionNodeTypeRequirements(NodeType substitutionNodeType,
- List<Map<String, RequirementDefinition>> requirementsList,
- String templateName) {
+ List<Map<String, RequirementDefinition>> requirementsList, String templateName) {
if (CollectionUtils.isEmpty(requirementsList)) {
return;
}
@@ -1341,7 +1218,7 @@ public class DataModelUtil {
* @return the relationship template
*/
public static Optional<RelationshipTemplate> getRelationshipTemplate(ServiceTemplate serviceTemplate,
- String relationshipId) {
+ String relationshipId) {
if (serviceTemplate == null || serviceTemplate.getTopology_template() == null
|| serviceTemplate.getTopology_template().getRelationship_templates() == null
|| serviceTemplate.getTopology_template().getRelationship_templates().get(relationshipId) == null) {
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 2d0d3fb59c..b254671dc7 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
@@ -16,10 +16,35 @@
package org.openecomp.sdc.tosca.services.impl;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
-import org.onap.sdc.tosca.datatypes.model.*;
+import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
+import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
+import org.onap.sdc.tosca.datatypes.model.CapabilityType;
+import org.onap.sdc.tosca.datatypes.model.DataType;
+import org.onap.sdc.tosca.datatypes.model.DefinitionOfDataType;
+import org.onap.sdc.tosca.datatypes.model.Import;
+import org.onap.sdc.tosca.datatypes.model.InterfaceDefinitionType;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.NodeType;
+import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
+import org.onap.sdc.tosca.datatypes.model.PropertyDefinition;
+import org.onap.sdc.tosca.datatypes.model.PropertyType;
+import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.sdc.common.errors.CoreException;
@@ -27,29 +52,31 @@ import org.openecomp.sdc.common.errors.SdcRuntimeException;
import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes;
import org.openecomp.sdc.tosca.datatypes.ToscaFlatData;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-import org.openecomp.sdc.tosca.errors.*;
+import org.openecomp.sdc.tosca.errors.ToscaElementTypeNotFoundErrorBuilder;
+import org.openecomp.sdc.tosca.errors.ToscaFileNotFoundErrorBuilder;
+import org.openecomp.sdc.tosca.errors.ToscaInvalidEntryNotFoundErrorBuilder;
+import org.openecomp.sdc.tosca.errors.ToscaInvalidSubstituteNodeTemplatePropertiesErrorBuilder;
+import org.openecomp.sdc.tosca.errors.ToscaInvalidSubstitutionServiceTemplateErrorBuilder;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaAnalyzerService;
import org.openecomp.sdc.tosca.services.ToscaConstants;
import org.openecomp.sdc.tosca.services.ToscaUtil;
-import java.lang.reflect.InvocationTargetException;
-import java.util.*;
-
public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
private static final String GET_NODE_TYPE_METHOD_NAME = "getNode_types";
private static final String GET_DERIVED_FROM_METHOD_NAME = "getDerived_from";
private static final String GET_TYPE_METHOD_NAME = "getType";
private static final String GET_DATA_TYPE_METHOD_NAME = "getData_types";
- private static final String GET_INTERFACE_TYPE_METHOD_NAME = "getInterface_types";
+ private static final String GET_INTERFACE_TYPE_METHOD_NAME = "getNormalizeInterfaceTypes";
private static final String GET_CAPABILITY_TYPE_METHOD_NAME = "getCapability_types";
private static final String TOSCA_DOT = "tosca.";
private static final String DOT_ROOT = ".Root";
@Override
- public List<Map<String, RequirementDefinition>> calculateExposedRequirements(List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList,
- Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment) {
+ public List<Map<String, RequirementDefinition>> calculateExposedRequirements(
+ List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList,
+ Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment) {
if (nodeTypeRequirementsDefinitionList == null) {
return Collections.emptyList();
@@ -73,19 +100,19 @@ 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()).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);
@@ -112,8 +139,9 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
@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;
@@ -122,6 +150,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
.entrySet()) {
for (Map.Entry<String, RequirementAssignment> fullFilledEntry : entry.getValue().entrySet()) {
+
capability = fullFilledEntry.getValue().getCapability();
node = fullFilledEntry.getValue().getNode();
capabilityKey = capability + "_" + node;
@@ -143,8 +172,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private void updateNodeTypeCapabilitiesDefinition(Map<String, CapabilityDefinition> nodeTypeCapabilitiesDefinition,
- String capabilityKey,
- CapabilityDefinition clonedCapabilityDefinition) {
+ String capabilityKey, CapabilityDefinition clonedCapabilityDefinition) {
if (evaluateCapabilityFulfillment(clonedCapabilityDefinition)) {
nodeTypeCapabilitiesDefinition.remove(capabilityKey);
} else {
@@ -175,13 +203,13 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
*/
@Override
public Map<String, NodeTemplate> getNodeTemplatesByType(ServiceTemplate serviceTemplate, String nodeType,
- ToscaServiceModel toscaServiceModel) {
+ 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()) {
+ .getNode_templates().entrySet()) {
if (isTypeOf(nodeTemplateEntry.getValue(), nodeType, serviceTemplate, toscaServiceModel)) {
nodeTemplates.put(nodeTemplateEntry.getKey(), nodeTemplateEntry.getValue());
}
@@ -194,21 +222,38 @@ 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) {
+ 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);
+ }
+
+ @Override
+ public boolean isTypeOf(DefinitionOfDataType parameterDefinition, String dataType, ServiceTemplate serviceTemplate,
+ 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);
+ }
+
+ @Override
public List<RequirementAssignment> getRequirements(NodeTemplate nodeTemplate, String requirementId) {
List<RequirementAssignment> requirements = new ArrayList<>();
List<Map<String, RequirementAssignment>> requirementList = nodeTemplate.getRequirements();
@@ -225,9 +270,9 @@ 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();
@@ -235,14 +280,14 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
@Override
public Optional<String> getSubstituteServiceTemplateName(String substituteNodeTemplateId,
- NodeTemplate substitutableNodeTemplate) {
+ NodeTemplate substitutableNodeTemplate) {
if (!isSubstitutableNodeTemplate(substitutableNodeTemplate)) {
return Optional.empty();
}
- if (substitutableNodeTemplate.getProperties() != null &&
- substitutableNodeTemplate.getProperties().get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME)
- != null) {
+ 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) {
@@ -252,14 +297,14 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
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());
}
}
@@ -285,9 +330,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
@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();
@@ -297,10 +341,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
String mappedNodeTemplateId = requirementMapping.get(0);
Optional<NodeTemplate> mappedNodeTemplate =
getNodeTemplateById(substituteServiceTemplate, mappedNodeTemplateId);
- mappedNodeTemplate.orElseThrow(
- () -> new CoreException(new ToscaInvalidEntryNotFoundErrorBuilder("Node Template",
- mappedNodeTemplateId)
- .build()));
+ mappedNodeTemplate.orElseThrow(() -> new CoreException(
+ new ToscaInvalidEntryNotFoundErrorBuilder("Node Template", mappedNodeTemplateId).build()));
Map.Entry<String, NodeTemplate> mappedNodeTemplateEntry = new Map.Entry<String, NodeTemplate>() {
@Override
public String getKey() {
@@ -329,7 +371,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
*/
@Override
public boolean isDesiredRequirementAssignment(RequirementAssignment requirementAssignment, String capability,
- String node, String relationship) {
+ String node, String relationship) {
if (isSameCapability(requirementAssignment, capability)) {
return false;
}
@@ -347,14 +389,14 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
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));
+ .equals(node));
}
private boolean isSameCapability(RequirementAssignment requirementAssignment, String capability) {
@@ -365,7 +407,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
@Override
public ToscaFlatData getFlatEntity(ToscaElementTypes elementType, String typeId, ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaModel) {
+ ToscaServiceModel toscaModel) {
ToscaFlatData flatData = new ToscaFlatData();
flatData.setElementType(elementType);
@@ -380,7 +422,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
flatData.setFlatEntity(new DataType());
break;
default:
- throw new RuntimeException("Entity[" + elementType + "] id[" + typeId + "] flat not supported");
+ throw new SdcRuntimeException("Entity[" + elementType + "] id[" + typeId + "] flat not supported");
}
boolean isEntityFound =
@@ -399,10 +441,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private <T> Optional<Boolean> isTypeExistInServiceTemplateHierarchy(String typeToMatch, String typeToSearch,
- String getTypesMethodName,
- ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel,
- Set<String> analyzedImportFiles)
+ 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);
@@ -430,8 +470,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private Optional<Boolean> isTypeExistInImports(String typeToMatch, String typeToSearch, String getTypesMethodName,
- ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel, Set<String> filesScanned)
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel, Set<String> filesScanned)
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
List<Map<String, Import>> imports = serviceTemplate.getImports();
if (CollectionUtils.isEmpty(imports)) {
@@ -469,7 +508,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
private void handleImportWithNoFileEntry(Import anImport) {
if (Objects.isNull(anImport) || Objects.isNull(anImport.getFile())) {
- throw new RuntimeException("import without file entry");
+ throw new SdcRuntimeException("import without file entry");
}
}
@@ -486,12 +525,13 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private boolean isSubstitutionServiceTemplate(String substituteServiceTemplateFileName,
- ServiceTemplate substituteServiceTemplate) {
+ ServiceTemplate substituteServiceTemplate) {
if (substituteServiceTemplate != null && substituteServiceTemplate.getTopology_template() != 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;
}
@@ -500,8 +540,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private boolean scanAnFlatEntity(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel,
- List<String> filesScanned, int rootScanStartInx) {
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned,
+ int rootScanStartInx) {
boolean entityFound =
@@ -526,8 +566,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private boolean isFlatEntity(Map<String, Import> importMap, ToscaFlatData flatData, ServiceTemplate serviceTemplate,
- List<String> filesScanned, ToscaServiceModel toscaModel,
- ToscaElementTypes elementType, String typeId) {
+ List<String> filesScanned, ToscaServiceModel toscaModel, ToscaElementTypes elementType, String typeId) {
boolean found = false;
ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
for (Object importObject : importMap.values()) {
@@ -564,10 +603,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private boolean enrichEntityFromCurrentServiceTemplate(ToscaElementTypes elementType, String typeId,
- ToscaFlatData flatData,
- ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaModel,
- List<String> filesScanned, int rootScanStartInx) {
+ ToscaFlatData flatData, ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel,
+ List<String> filesScanned, int rootScanStartInx) {
switch (elementType) {
case CAPABILITY_TYPE:
if (enrichCapabilityType(elementType, typeId, flatData, serviceTemplate, toscaModel, filesScanned,
@@ -588,7 +625,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
break;
default:
- throw new RuntimeException("Entity[" + elementType + "] id[" + typeId + "] flat not supported");
+ throw new SdcRuntimeException("Entity[" + elementType + "] id[" + typeId + "] flat not supported");
}
return true;
@@ -597,8 +634,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private boolean enrichNodeTypeInfo(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel,
- List<String> filesScanned, int rootScanStartInx) {
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned,
+ int rootScanStartInx) {
String derivedFrom;
if (serviceTemplate.getNode_types() != null && serviceTemplate.getNode_types().containsKey(typeId)) {
@@ -623,8 +660,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private boolean enrichDataTypeInfo(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel,
- List<String> filesScanned, int rootScanStartInx) {
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned,
+ int rootScanStartInx) {
String derivedFrom;
if (serviceTemplate.getData_types() != null && serviceTemplate.getData_types().containsKey(typeId)) {
@@ -655,11 +692,11 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
private boolean enrichCapabilityType(ToscaElementTypes elementType, String typeId, ToscaFlatData flatData,
- ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel,
- List<String> filesScanned, int rootScanStartInx) {
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel, List<String> filesScanned,
+ int rootScanStartInx) {
String derivedFrom;
if (serviceTemplate.getCapability_types() != null && serviceTemplate.getCapability_types()
- .containsKey(typeId)) {
+ .containsKey(typeId)) {
filesScanned.clear();
flatData.addInheritanceHierarchyType(typeId);
@@ -699,16 +736,6 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
- private InterfaceDefinitionType getInterfaceDefinitionType(String interfaceName, Object interfaceDefTypeObj) {
- Optional<InterfaceDefinitionType> interfaceDefinitionType = DataModelUtil.convertObjToInterfaceDefinition(
- interfaceName, interfaceDefTypeObj, InterfaceDefinitionType.class);
- if (!interfaceDefinitionType.isPresent()) {
- throw new CoreException(new CreateInterfaceObjectErrorBuilder("InterfaceDefinitionType", interfaceName,
- "Invalid interface object").build());
- }
- return interfaceDefinitionType.get();
- }
-
private void combineNodeTypeInterfaceInfo(NodeType sourceNodeType, NodeType targetNodeType) {
Optional<Map<String, Object>> interfaceNoMerge = combineInterfaceNoMerge(sourceNodeType, targetNodeType);
if (interfaceNoMerge.isPresent()) {
@@ -723,9 +750,9 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
for (Map.Entry<String, Object> sourceInterfaceDefEntry : sourceNodeType.getInterfaces().entrySet()) {
String interfaceName = sourceInterfaceDefEntry.getKey();
if (!MapUtils.isEmpty(targetNodeType.getInterfaces()) && targetNodeType.getInterfaces()
- .containsKey(interfaceName)) {
+ .containsKey(interfaceName)) {
combineInterfaces.put(interfaceName,
- combineInterfaceDefinition(interfaceName, sourceInterfaceDefEntry.getValue(),
+ combineInterfaceDefinition(sourceInterfaceDefEntry.getValue(),
targetNodeType.getInterfaces().get(interfaceName)));
} else {
combineInterfaces.put(sourceInterfaceDefEntry.getKey(), sourceInterfaceDefEntry.getValue());
@@ -758,18 +785,17 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
- private Object combineInterfaceDefinition(String interfaceName, Object sourceInterfaceDefType,
- Object targetInterfaceDefType) {
- InterfaceDefinitionType sourceInterface = getInterfaceDefinitionType(interfaceName, sourceInterfaceDefType);
- InterfaceDefinitionType targetInterface = getInterfaceDefinitionType(interfaceName, targetInterfaceDefType);
+ private Object combineInterfaceDefinition(Object sourceInterfaceDefType, Object targetInterfaceDefType) {
+ InterfaceDefinitionType sourceInterface = new InterfaceDefinitionType(sourceInterfaceDefType);
+ InterfaceDefinitionType targetInterface = new InterfaceDefinitionType(targetInterfaceDefType);
InterfaceDefinitionType combineInterface = new InterfaceDefinitionType();
combineInterface.setType(sourceInterface.getType());
combineInterface.setInputs(CommonMethods.mergeMaps(targetInterface.getInputs(), sourceInterface.getInputs()));
combineInterface.setOperations(
CommonMethods.mergeMaps(targetInterface.getOperations(), sourceInterface.getOperations()));
- Optional<Object> interfaceDefObject = DataModelUtil.convertInterfaceDefinitionTypeToObj(combineInterface);
- if( !interfaceDefObject.isPresent()){
+ Optional<Object> interfaceDefObject = combineInterface.convertInterfaceDefinitionTypeToToscaObj();
+ if (!interfaceDefObject.isPresent()) {
throw new SdcRuntimeException("Illegal Statement");
}
return interfaceDefObject.get();
@@ -785,7 +811,6 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
CommonMethods.mergeLists(targetDataType.getConstraints(), sourceDataType.getConstraints()));
}
-
private void combineCapabilityTypeInfo(CapabilityType sourceCapabilityType, CapabilityType targetCapabilityType) {
targetCapabilityType.setAttributes(
@@ -820,7 +845,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
*/
@Override
public NodeType createInitSubstitutionNodeType(ServiceTemplate substitutionServiceTemplate,
- String nodeTypeDerivedFromValue) {
+ String nodeTypeDerivedFromValue) {
NodeType substitutionNodeType = new NodeType();
substitutionNodeType.setDerived_from(nodeTypeDerivedFromValue);
substitutionNodeType.setDescription(substitutionServiceTemplate.getDescription());
@@ -830,7 +855,8 @@ 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) {
@@ -866,7 +892,8 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
}
- 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) {
@@ -906,35 +933,15 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
*/
@Override
public boolean isRequirementExistInNodeTemplate(NodeTemplate nodeTemplate, String requirementId,
- RequirementAssignment requirementAssignment) {
+ 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)));
}
- @Override
- 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) {
- 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);
- }
-
-
private <T> boolean isTypeOf(T object, String type, String getTypesMethodName, ServiceTemplate serviceTemplate,
- ToscaServiceModel toscaServiceModel) {
+ ToscaServiceModel toscaServiceModel) {
if (object == null) {
return false;
}