summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib/src/main/java
diff options
context:
space:
mode:
authorsiddharth0905 <siddharth.singh4@amdocs.com>2018-10-08 16:49:26 +0530
committerOren Kleks <orenkle@amdocs.com>2018-10-15 09:44:34 +0000
commit2fb914997d3d063d9b2e4ee02697baa8af48c7fe (patch)
treea318375e8caf3860a66fb17b2d8b02329dd013be /openecomp-be/lib/openecomp-tosca-lib/src/main/java
parent1f50c72eb501af42c61c4ddbb011302a6290afdb (diff)
Test coverage : openecomp-tosca-lib
Increase test coverage Change-Id: I6d6a9005d16b03f36b50c867d13db5f063fe3d07 Issue-ID: SDC-1673 Signed-off-by: siddharth0905 <siddharth.singh4@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/main/java')
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaArtifactType.java12
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java199
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java140
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java1
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java178
5 files changed, 273 insertions, 257 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaArtifactType.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaArtifactType.java
index c43fcaa2bb..376d643d0d 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaArtifactType.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaArtifactType.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,11 +27,11 @@ import org.openecomp.sdc.tosca.services.ConfigConstants;
public class ToscaArtifactType {
- private static Configuration config = ConfigurationManager.lookup();
+ private static Configuration config = ConfigurationManager.lookup();
- public static final String ARTIFACT_TYPE_PREFIX =
- config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_ARTIFACT_TYPE);
+ public static final String ARTIFACT_TYPE_PREFIX =
+ config.getAsString(ConfigConstants.NAMESPACE, ConfigConstants.PREFIX_ARTIFACT_TYPE);
- public static final String NATIVE_DEPLOYMENT = "tosca.artifacts.Deployment";
+ public static final String NATIVE_DEPLOYMENT = "tosca.artifacts.Deployment";
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java
index 3493d933e3..91a25783b5 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,113 +20,114 @@
package org.openecomp.sdc.tosca.datatypes;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
import org.apache.commons.collections.MapUtils;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.sdc.datatypes.model.AsdcModel;
import org.openecomp.sdc.tosca.services.DataModelUtil;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-
/**
* Tosca service model.
*/
public class ToscaServiceModel implements AsdcModel {
- private FileContentHandler artifactFiles;
- private Map<String, ServiceTemplate> serviceTemplates;
- private String entryDefinitionServiceTemplate;
-
- public ToscaServiceModel() {
- }
-
- /**
- * Instantiates a new Tosca service model.
- *
- * @param artifactFiles the artifact files
- * @param serviceTemplates the service templates
- * @param entryDefinitionServiceTemplate the entry definition service template
- */
- public ToscaServiceModel(FileContentHandler artifactFiles,
- Map<String, ServiceTemplate> serviceTemplates,
- String entryDefinitionServiceTemplate) {
- this.artifactFiles = artifactFiles;
- this.serviceTemplates = serviceTemplates;
- this.entryDefinitionServiceTemplate = entryDefinitionServiceTemplate;
- }
-
- /**
- * Gets artifact files.
- *
- * @return the artifact files
- */
- public FileContentHandler getArtifactFiles() {
- return artifactFiles;
- }
-
- public void setArtifactFiles(FileContentHandler artifactFiles) {
- this.artifactFiles = artifactFiles;
- }
-
- /**
- * Gets service templates.
- *
- * @return the service templates
- */
- public Map<String, ServiceTemplate> getServiceTemplates() {
- return Collections.unmodifiableMap(serviceTemplates);
- }
-
- public Optional<ServiceTemplate> getServiceTemplate(String serviceTemplateName) {
- return MapUtils.isEmpty(this.serviceTemplates) ? Optional.empty()
- : Optional.of(this.serviceTemplates.get(serviceTemplateName));
- }
-
- public void addServiceTemplate(String serviceTemplateName,
- ServiceTemplate serviceTemplate) {
- if(MapUtils.isEmpty(serviceTemplates)){
- serviceTemplates = new HashMap<>();
+
+ private FileContentHandler artifactFiles;
+ private Map<String, ServiceTemplate> serviceTemplates;
+ private String entryDefinitionServiceTemplate;
+
+ public ToscaServiceModel() {
+ }
+
+ /**
+ * Instantiates a new Tosca service model.
+ *
+ * @param artifactFiles the artifact files
+ * @param serviceTemplates the service templates
+ * @param entryDefinitionServiceTemplate the entry definition service template
+ */
+ public ToscaServiceModel(FileContentHandler artifactFiles,
+ Map<String, ServiceTemplate> serviceTemplates,
+ String entryDefinitionServiceTemplate) {
+ this.artifactFiles = artifactFiles;
+ this.serviceTemplates = serviceTemplates;
+ this.entryDefinitionServiceTemplate = entryDefinitionServiceTemplate;
+ }
+
+ /**
+ * Gets artifact files.
+ *
+ * @return the artifact files
+ */
+ public FileContentHandler getArtifactFiles() {
+ return artifactFiles;
}
- serviceTemplates.put(serviceTemplateName, serviceTemplate);
- }
-
- /**
- * Sets service templates.
- *
- * @param serviceTemplates the service templates
- */
- public void setServiceTemplates(Map<String, ServiceTemplate> serviceTemplates) {
- this.serviceTemplates = serviceTemplates;
- }
-
- /**
- * Gets entry definition service template.
- *
- * @return the entry definition service template
- */
- public String getEntryDefinitionServiceTemplate() {
- return entryDefinitionServiceTemplate;
- }
-
- /**
- * Sets entry definition service template.
- *
- * @param entryDefinitionServiceTemplate the entry definition service template
- */
- public void setEntryDefinitionServiceTemplate(String entryDefinitionServiceTemplate) {
- this.entryDefinitionServiceTemplate = entryDefinitionServiceTemplate;
- }
-
- /**
- * Gets cloned service model.
- *
- * @param toscaServiceModel the tosca service model
- * @return the cloned service model
- */
- public static ToscaServiceModel getClonedServiceModel(ToscaServiceModel toscaServiceModel) {
- return ToscaServiceModel.class.cast(DataModelUtil.getClonedObject(toscaServiceModel));
- }
+ public void setArtifactFiles(FileContentHandler artifactFiles) {
+ this.artifactFiles = artifactFiles;
+ }
+
+ /**
+ * Gets service templates.
+ *
+ * @return the service templates
+ */
+ public Map<String, ServiceTemplate> getServiceTemplates() {
+ return Collections.unmodifiableMap(serviceTemplates);
+ }
+
+ public Optional<ServiceTemplate> getServiceTemplate(String serviceTemplateName) {
+ return MapUtils.isEmpty(this.serviceTemplates) ? Optional.empty()
+ : Optional.of(this.serviceTemplates.get(serviceTemplateName));
+ }
+
+ public void addServiceTemplate(String serviceTemplateName,
+ ServiceTemplate serviceTemplate) {
+ if (MapUtils.isEmpty(serviceTemplates)) {
+ serviceTemplates = new HashMap<>();
+ }
+
+ serviceTemplates.put(serviceTemplateName, serviceTemplate);
+ }
+
+ /**
+ * Sets service templates.
+ *
+ * @param serviceTemplates the service templates
+ */
+ public void setServiceTemplates(Map<String, ServiceTemplate> serviceTemplates) {
+ this.serviceTemplates = serviceTemplates;
+ }
+
+ /**
+ * Gets entry definition service template.
+ *
+ * @return the entry definition service template
+ */
+ public String getEntryDefinitionServiceTemplate() {
+ return entryDefinitionServiceTemplate;
+ }
+
+ /**
+ * Sets entry definition service template.
+ *
+ * @param entryDefinitionServiceTemplate the entry definition service template
+ */
+ public void setEntryDefinitionServiceTemplate(String entryDefinitionServiceTemplate) {
+ this.entryDefinitionServiceTemplate = entryDefinitionServiceTemplate;
+ }
+
+ /**
+ * Gets cloned service model.
+ *
+ * @param toscaServiceModel the tosca service model
+ * @return the cloned service model
+ */
+ public static ToscaServiceModel getClonedServiceModel(ToscaServiceModel toscaServiceModel) {
+ return ToscaServiceModel.class.cast(DataModelUtil.getClonedObject(toscaServiceModel));
+ }
}
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 9b9cd80385..2fc10d2d2b 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
@@ -30,6 +30,9 @@ import java.util.ListIterator;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
@@ -67,16 +70,13 @@ import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
/**
* The type Data model util.
*/
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
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 DataModelUtil() {
- // prevent instantiation
- }
-
/**
* Add substitution mapping.
*
@@ -87,7 +87,7 @@ public class DataModelUtil {
SubstitutionMapping substitutionMapping) {
if (serviceTemplate == null) {
throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping", SERVICE_TEMPLATE)
- .build());
+ .build());
}
if (serviceTemplate.getTopology_template() == null) {
@@ -117,7 +117,8 @@ 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)
@@ -135,7 +136,7 @@ public class DataModelUtil {
}
serviceTemplate.getTopology_template().getSubstitution_mappings().getRequirements()
- .put(substitutionMappingRequirementId, substitutionMappingRequirementList);
+ .put(substitutionMappingRequirementId, substitutionMappingRequirementList);
}
/**
@@ -146,10 +147,11 @@ 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());
+ SERVICE_TEMPLATE).build());
}
if (serviceTemplate.getTopology_template() == null) {
@@ -163,7 +165,7 @@ public class DataModelUtil {
}
serviceTemplate.getTopology_template().getSubstitution_mappings().getCapabilities()
- .putIfAbsent(substitutionMappingCapabilityId, substitutionMappingCapabilityList);
+ .putIfAbsent(substitutionMappingCapabilityId, substitutionMappingCapabilityList);
}
/**
@@ -174,7 +176,7 @@ public class DataModelUtil {
*/
public static Map<String, NodeTemplate> getNodeTemplates(ServiceTemplate serviceTemplate) {
if (Objects.isNull(serviceTemplate) || Objects.isNull(serviceTemplate.getTopology_template())
- || MapUtils.isEmpty(serviceTemplate.getTopology_template().getNode_templates())) {
+ || MapUtils.isEmpty(serviceTemplate.getTopology_template().getNode_templates())) {
return new HashMap<>();
}
@@ -189,7 +191,7 @@ public class DataModelUtil {
*/
public static Map<String, GroupDefinition> getGroups(ServiceTemplate serviceTemplate) {
if (Objects.isNull(serviceTemplate) || Objects.isNull(serviceTemplate.getTopology_template())
- || MapUtils.isEmpty(serviceTemplate.getTopology_template().getGroups())) {
+ || MapUtils.isEmpty(serviceTemplate.getTopology_template().getGroups())) {
return new HashMap<>();
}
@@ -204,7 +206,7 @@ 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());
@@ -227,7 +229,7 @@ public class DataModelUtil {
* @param capabilities the capability definitions
*/
public static void addNodeTypeCapabilitiesDef(NodeType nodeType, Map<String, CapabilityDefinition> capabilities) {
- if (MapUtils.isEmpty(capabilities) || capabilities.entrySet().isEmpty()) {
+ if (MapUtils.isEmpty(capabilities)) {
return;
}
@@ -239,12 +241,12 @@ public class DataModelUtil {
if (MapUtils.isEmpty(nodeType.getCapabilities())) {
nodeType.setCapabilities(new HashMap<>());
}
-
+
for (Map.Entry<String, CapabilityDefinition> entry : capabilities.entrySet()) {
nodeType.getCapabilities().put(entry.getKey(), entry.getValue());
}
}
-
+
/**
* Set capabilities def to node type.
*
@@ -252,23 +254,25 @@ public class DataModelUtil {
* @param capabilities the capability definitions
*/
public static void setNodeTypeCapabilitiesDef(NodeType nodeType, Map<String, CapabilityDefinition> capabilities) {
- if (MapUtils.isEmpty(capabilities) || capabilities.entrySet().isEmpty()) {
+ if (MapUtils.isEmpty(capabilities)) {
return;
}
if (nodeType == null) {
throw new CoreException(new InvalidAddActionNullEntityErrorBuilder("Capability Definition", NODE_TYPE)
- .build());
+ .build());
}
if (MapUtils.isEmpty(nodeType.getCapabilities())) {
nodeType.setCapabilities(new HashMap<>());
}
- if (capabilities.size() > 0) {
+
+ if (MapUtils.isNotEmpty(capabilities)) {
nodeType.setCapabilities(new HashMap<>());
- }
- for (Map.Entry<String, CapabilityDefinition> entry : capabilities.entrySet()) {
- nodeType.getCapabilities().put(entry.getKey(), entry.getValue());
+
+ for (Map.Entry<String, CapabilityDefinition> entry : capabilities.entrySet()) {
+ nodeType.getCapabilities().put(entry.getKey(), entry.getValue());
+ }
}
}
@@ -280,7 +284,7 @@ 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());
@@ -321,7 +325,7 @@ 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());
@@ -333,7 +337,7 @@ public class DataModelUtil {
serviceTemplate.getTopology_template().setRelationship_templates(new HashMap<>());
}
serviceTemplate.getTopology_template().getRelationship_templates()
- .put(relationshipTemplateId, relationshipTemplate);
+ .put(relationshipTemplateId, relationshipTemplate);
}
/**
@@ -344,11 +348,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());
+ "Node Template").build());
}
if (requirementAssignment.getNode() == null) {
throw new CoreException(new InvalidRequirementAssignmentErrorBuilder(requirementId).build());
@@ -385,7 +389,7 @@ public class DataModelUtil {
*/
public static NodeTemplate getNodeTemplate(ServiceTemplate serviceTemplate, String nodeTemplateId) {
if (serviceTemplate == null || serviceTemplate.getTopology_template() == null
- || serviceTemplate.getTopology_template().getNode_templates() == null) {
+ || serviceTemplate.getTopology_template().getNode_templates() == null) {
return null;
}
return serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId);
@@ -413,7 +417,7 @@ public class DataModelUtil {
* @return the requirement definition
*/
public static Optional<RequirementDefinition> getRequirementDefinition(NodeType nodeType,
- String requirementDefinitionId) {
+ String requirementDefinitionId) {
if (nodeType == null || nodeType.getRequirements() == null || requirementDefinitionId == null) {
return Optional.empty();
}
@@ -452,7 +456,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();
}
@@ -467,7 +471,7 @@ 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());
@@ -499,7 +503,7 @@ public class DataModelUtil {
public static void addGroupMember(ServiceTemplate serviceTemplate, String groupName, String groupMemberId) {
TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
if (Objects.isNull(topologyTemplate) || topologyTemplate.getGroups() == null
- || topologyTemplate.getGroups().get(groupName) == null) {
+ || topologyTemplate.getGroups().get(groupName) == null) {
return;
}
@@ -525,7 +529,8 @@ 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);
@@ -546,7 +551,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);
@@ -586,7 +591,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);
@@ -617,7 +622,7 @@ public class DataModelUtil {
parameterDefinition.setStatus(propertyDefinition.getStatus());
parameterDefinition.setConstraints(propertyDefinition.getConstraints());
parameterDefinition.setEntry_schema(Objects.isNull(propertyDefinition.getEntry_schema()) ? null :
- propertyDefinition.getEntry_schema().clone());
+ propertyDefinition.getEntry_schema().clone());
parameterDefinition.setHidden(false);
parameterDefinition.setImmutable(false);
return parameterDefinition;
@@ -631,7 +636,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;
}
@@ -643,7 +648,7 @@ public class DataModelUtil {
public static boolean isNodeTemplate(String entryId, ServiceTemplate serviceTemplate) {
return serviceTemplate.getTopology_template().getNode_templates() != null
- && serviceTemplate.getTopology_template().getNode_templates().get(entryId) != null;
+ && serviceTemplate.getTopology_template().getNode_templates().get(entryId) != null;
}
/**
@@ -654,7 +659,8 @@ 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)
@@ -679,7 +685,8 @@ 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)
@@ -703,7 +710,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;
}
@@ -809,7 +816,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;
}
@@ -833,7 +840,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;
}
@@ -859,7 +866,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) {
@@ -872,12 +879,12 @@ public class DataModelUtil {
RequirementAssignment requirementAssignment = reqMap.get(requirementKey);
if (requirementAssignment != null) {
boolean isDesiredRequirementAssignment = toscaAnalyzerService
- .isDesiredRequirementAssignment(requirementAssignment,
- requirementAssignmentToBeDeleted
- .getCapability(),
- requirementAssignmentToBeDeleted.getNode(),
- requirementAssignmentToBeDeleted
- .getRelationship());
+ .isDesiredRequirementAssignment(requirementAssignment,
+ requirementAssignmentToBeDeleted
+ .getCapability(),
+ requirementAssignmentToBeDeleted.getNode(),
+ requirementAssignmentToBeDeleted
+ .getRelationship());
if (isDesiredRequirementAssignment) {
iter.remove();
}
@@ -927,7 +934,7 @@ public class DataModelUtil {
*/
public static ParameterDefinition getOuputParameter(ServiceTemplate serviceTemplate, String outputParameterId) {
if (serviceTemplate == null || serviceTemplate.getTopology_template() == null
- || serviceTemplate.getTopology_template().getOutputs() == null) {
+ || serviceTemplate.getTopology_template().getOutputs() == null) {
return null;
}
return serviceTemplate.getTopology_template().getOutputs().get(outputParameterId);
@@ -941,7 +948,7 @@ public class DataModelUtil {
*/
public static Map<String, ParameterDefinition> getInputParameters(ServiceTemplate serviceTemplate) {
if (serviceTemplate == null || serviceTemplate.getTopology_template() == null
- || serviceTemplate.getTopology_template().getInputs() == null) {
+ || serviceTemplate.getTopology_template().getInputs() == null) {
return null;
}
return serviceTemplate.getTopology_template().getInputs();
@@ -955,7 +962,7 @@ public class DataModelUtil {
*/
public static Map<String, RelationshipTemplate> getRelationshipTemplates(ServiceTemplate serviceTemplate) {
if (serviceTemplate == null || serviceTemplate.getTopology_template() == null
- || serviceTemplate.getTopology_template().getRelationship_templates() == null) {
+ || serviceTemplate.getTopology_template().getRelationship_templates() == null) {
return null;
}
return serviceTemplate.getTopology_template().getRelationship_templates();
@@ -983,10 +990,10 @@ 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) {
+ || serviceTemplate.getTopology_template().getNode_templates() == null
+ || serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) == null) {
return null;
}
return serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId).getProperties();
@@ -1019,7 +1026,7 @@ public class DataModelUtil {
*/
public static SubstitutionMapping getSubstitutionMappings(ServiceTemplate serviceTemplate) {
if (serviceTemplate == null || serviceTemplate.getTopology_template() == null
- || serviceTemplate.getTopology_template().getSubstitution_mappings() == null) {
+ || serviceTemplate.getTopology_template().getSubstitution_mappings() == null) {
return null;
}
return serviceTemplate.getTopology_template().getSubstitution_mappings();
@@ -1035,7 +1042,7 @@ public class DataModelUtil {
*/
public static boolean compareRequirementAssignment(RequirementAssignment first, RequirementAssignment second) {
return (first.getCapability().equals(second.getCapability()) && first.getNode().equals(second.getNode())
- && first.getRelationship().equals(second.getRelationship()));
+ && first.getRelationship().equals(second.getRelationship()));
}
/**
@@ -1120,7 +1127,8 @@ 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(),
@@ -1139,7 +1147,8 @@ 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<>();
@@ -1171,7 +1180,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;
}
@@ -1188,7 +1197,8 @@ public class DataModelUtil {
}
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;
}
@@ -1218,10 +1228,10 @@ 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) {
+ || serviceTemplate.getTopology_template().getRelationship_templates() == null
+ || serviceTemplate.getTopology_template().getRelationship_templates().get(relationshipId) == null) {
return Optional.empty();
}
return Optional.of(serviceTemplate.getTopology_template().getRelationship_templates().get(relationshipId));
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java
index d81983057d..14b216a040 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaConstants.java
@@ -70,6 +70,7 @@ public class ToscaConstants {
public static final String HEAT_NODE_TYPE_SUFFIX = "heat.";
public static final String CAPABILITY = "capability";
public static final String REQUIREMENT = "requirement";
+ public static final String SERVICE_TEMPLATE_FILE_POSTFIX = "ServiceTemplate.yaml";
private ToscaConstants() {
//Hiding the implicit public constructor
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java
index 0cbc71fcb6..7c8e48ac88 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,11 +20,6 @@
package org.openecomp.sdc.tosca.services;
-import org.apache.commons.collections4.MapUtils;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.openecomp.core.utilities.file.FileUtils;
-
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -32,102 +27,111 @@ import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.commons.collections4.MapUtils;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.core.utilities.file.FileUtils;
+
/**
* The type Tosca util.
*/
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ToscaUtil {
- /**
- * Gets service template file name.
- *
- * @param serviceTemplate the service template
- * @return the service template file name
- */
- public static String getServiceTemplateFileName(ServiceTemplate serviceTemplate) {
- if (serviceTemplate == null) {
- return null;
+ /**
+ * Gets service template file name.
+ *
+ * @param serviceTemplate the service template
+ * @return the service template file name
+ */
+ public static String getServiceTemplateFileName(ServiceTemplate serviceTemplate) {
+ if (serviceTemplate == null) {
+ return null;
+ }
+ if (serviceTemplate.getMetadata() == null) {
+ return UUID.randomUUID().toString() + ToscaConstants.SERVICE_TEMPLATE_FILE_POSTFIX;
+ }
+ return getServiceTemplateFileName(serviceTemplate.getMetadata());
}
- if (serviceTemplate.getMetadata() == null) {
- return UUID.randomUUID().toString() + "ServiceTemplate.yaml";
+
+ /**
+ * Gets service template file name.
+ *
+ * @param metadata the file name
+ * @return the service template file name
+ */
+ public static String getServiceTemplateFileName(Map<String, String> metadata) {
+ if (metadata.get(ToscaConstants.ST_METADATA_FILE_NAME) != null) {
+ return metadata.get(ToscaConstants.ST_METADATA_FILE_NAME);
+ } else if (metadata.get(ToscaConstants.ST_METADATA_TEMPLATE_NAME) != null) {
+ return metadata.get(ToscaConstants.ST_METADATA_TEMPLATE_NAME)
+ + ToscaConstants.SERVICE_TEMPLATE_FILE_POSTFIX;
+ }
+ return UUID.randomUUID().toString() + ToscaConstants.SERVICE_TEMPLATE_FILE_POSTFIX;
+
}
- return getServiceTemplateFileName(serviceTemplate.getMetadata());
- }
-
- /**
- * Gets service template file name.
- *
- * @param metadata the file name
- * @return the service template file name
- */
- public static String getServiceTemplateFileName(Map<String, String> metadata) {
- if (metadata.get(ToscaConstants.ST_METADATA_FILE_NAME) != null) {
- return metadata.get(ToscaConstants.ST_METADATA_FILE_NAME);
- } else if (metadata.get(ToscaConstants.ST_METADATA_TEMPLATE_NAME) != null) {
- return metadata.get(ToscaConstants.ST_METADATA_TEMPLATE_NAME) + "ServiceTemplate.yaml";
+
+ public static String getServiceTemplateFileName(String templateName) {
+ Map<String, String> metadata = new HashMap<>();
+ metadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, templateName);
+ return getServiceTemplateFileName(metadata);
}
- return UUID.randomUUID().toString() + "ServiceTemplate.yaml";
- }
+ public static Optional<String> getSubstitutableGroupMemberId(String heatFileName,
+ ServiceTemplate serviceTemplate) {
+
+ Map<String, NodeTemplate> nodeTemplates =
+ DataModelUtil.getNodeTemplates(serviceTemplate);
+
+ if (MapUtils.isEmpty(nodeTemplates)) {
+ return Optional.empty();
+ }
- public static Optional<String> getSubstitutableGroupMemberId(String heatFileName,
- ServiceTemplate serviceTemplate){
+ String heatFileNameWithoutExt = FileUtils.getFileWithoutExtention(heatFileName);
- Map<String, NodeTemplate> nodeTemplates =
- DataModelUtil.getNodeTemplates(serviceTemplate);
+ for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplates.entrySet()) {
+ String subServiceTemplateName =
+ getSubstitutionServiceTemplateNameFromProperties(nodeTemplateEntry);
- if(MapUtils.isEmpty(nodeTemplates)){
- return Optional.empty();
+ if (Objects.nonNull(subServiceTemplateName)
+ && isGroupMemberIdSubstitutable(heatFileNameWithoutExt, subServiceTemplateName)) {
+ return Optional.of(nodeTemplateEntry.getKey());
+ }
+ }
+
+ return Optional.empty();
+ }
+
+ private static boolean isGroupMemberIdSubstitutable(String heatFileNameWithoutExt,
+ String subServiceTemplateName) {
+ return subServiceTemplateName.startsWith(heatFileNameWithoutExt);
}
- String heatFileNameWithoutExt = FileUtils.getFileWithoutExtention(heatFileName);
+ private static String getSubstitutionServiceTemplateNameFromProperties(
+ Map.Entry<String, NodeTemplate> nodeTemplateEntry) {
+ Map<String, Object> properties =
+ nodeTemplateEntry.getValue().getProperties() == null ? Collections.emptyMap() :
+ nodeTemplateEntry.getValue().getProperties();
- for(Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplates.entrySet()){
- String subServiceTemplateName =
- getSubstitutionServiceTemplateNameFromProperties(nodeTemplateEntry);
+ Map<String, Object> serviceTemplateFilter =
+ properties.containsKey(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME) ?
+ (Map<String, Object>) properties.get(ToscaConstants
+ .SERVICE_TEMPLATE_FILTER_PROPERTY_NAME) : Collections.emptyMap();
- if(Objects.nonNull(subServiceTemplateName)
- && isGroupMemberIdSubstitutable(heatFileNameWithoutExt, subServiceTemplateName)){
- return Optional.of(nodeTemplateEntry.getKey());
- }
+ return (String) serviceTemplateFilter.get(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME);
}
- return Optional.empty();
- }
-
- private static boolean isGroupMemberIdSubstitutable(String heatFileNameWithoutExt,
- String subServiceTemplateName) {
- return subServiceTemplateName.startsWith(heatFileNameWithoutExt);
- }
-
- private static String getSubstitutionServiceTemplateNameFromProperties(
- Map.Entry<String, NodeTemplate> nodeTemplateEntry) {
- Map<String, Object> properties =
- nodeTemplateEntry.getValue().getProperties() == null ? Collections.emptyMap() :
- nodeTemplateEntry.getValue().getProperties();
-
- Map<String, Object> serviceTemplateFilter =
- properties.containsKey(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME)?
- (Map<String, Object>) properties.get(ToscaConstants
- .SERVICE_TEMPLATE_FILTER_PROPERTY_NAME) : Collections.emptyMap();
-
- return (String) serviceTemplateFilter.get(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME);
- }
-
-
- /**
- * Add service template to map with key file name.
- *
- * @param serviceTemplateMap the service template map
- * @param serviceTemplate the service template
- */
- public static void addServiceTemplateToMapWithKeyFileName(
- Map<String, ServiceTemplate> serviceTemplateMap, ServiceTemplate serviceTemplate) {
- serviceTemplateMap.put(ToscaUtil.getServiceTemplateFileName(serviceTemplate), serviceTemplate);
- }
-
- public static String getServiceTemplateFileName(String templateName) {
- Map<String, String> metadata = new HashMap<>();
- metadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, templateName);
- return getServiceTemplateFileName(metadata);
- }
+
+ /**
+ * Add service template to map with key file name.
+ *
+ * @param serviceTemplateMap the service template map
+ * @param serviceTemplate the service template
+ */
+ public static void addServiceTemplateToMapWithKeyFileName(
+ Map<String, ServiceTemplate> serviceTemplateMap, ServiceTemplate serviceTemplate) {
+ serviceTemplateMap.put(ToscaUtil.getServiceTemplateFileName(serviceTemplate), serviceTemplate);
+ }
}