[sdc] update code of sdc
[sdc.git] / openecomp-be / lib / openecomp-tosca-lib / src / main / java / org / openecomp / sdc / tosca / services / DataModelUtil.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.tosca.services;
22
23 import org.apache.commons.collections4.CollectionUtils;
24 import org.apache.commons.collections4.MapUtils;
25 import org.openecomp.core.utilities.CommonMethods;
26 import org.openecomp.core.utilities.yaml.YamlUtil;
27 import org.openecomp.sdc.common.errors.CoreException;
28 import org.openecomp.sdc.datatypes.error.ErrorLevel;
29 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
30 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
31 import org.openecomp.sdc.logging.types.LoggerConstants;
32 import org.openecomp.sdc.logging.types.LoggerErrorCode;
33 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
34 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
35 import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
36 import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
37 import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
38 import org.openecomp.sdc.tosca.datatypes.model.CapabilityType;
39 import org.openecomp.sdc.tosca.datatypes.model.Constraint;
40 import org.openecomp.sdc.tosca.datatypes.model.EntrySchema;
41 import org.openecomp.sdc.tosca.datatypes.model.GroupDefinition;
42 import org.openecomp.sdc.tosca.datatypes.model.Import;
43 import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
44 import org.openecomp.sdc.tosca.datatypes.model.NodeType;
45 import org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition;
46 import org.openecomp.sdc.tosca.datatypes.model.PolicyDefinition;
47 import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
48 import org.openecomp.sdc.tosca.datatypes.model.RelationshipTemplate;
49 import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment;
50 import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
51 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
52 import org.openecomp.sdc.tosca.datatypes.model.Status;
53 import org.openecomp.sdc.tosca.datatypes.model.SubstitutionMapping;
54 import org.openecomp.sdc.tosca.datatypes.model.TopologyTemplate;
55 import org.openecomp.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt;
56 import org.openecomp.sdc.tosca.errors.InvalidAddActionNullEntityErrorBuilder;
57 import org.openecomp.sdc.tosca.errors.InvalidRequirementAssignmentErrorBuilder;
58 import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
59 import org.openecomp.sdc.tosca.services.yamlutil.ToscaExtensionYamlUtil;
60
61 import java.util.ArrayList;
62 import java.util.Arrays;
63 import java.util.Collections;
64 import java.util.HashMap;
65 import java.util.List;
66 import java.util.ListIterator;
67 import java.util.Map;
68 import java.util.Objects;
69 import java.util.Optional;
70
71 /**
72  * The type Data model util.
73  */
74 public class DataModelUtil {
75
76   /**
77    * Add substitution mapping.
78    */
79
80   private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
81
82   /**
83    * Add substitution mapping.
84    *
85    * @param serviceTemplate     the service template
86    * @param substitutionMapping the substitution mapping
87    */
88   public static void addSubstitutionMapping(ServiceTemplate serviceTemplate,
89                                             SubstitutionMapping substitutionMapping) {
90     mdcDataDebugMessage.debugEntryMessage(null, null);
91
92     if (serviceTemplate == null) {
93       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
94           LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
95           LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
96       throw new CoreException(
97           new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping", "Service Template")
98               .build());
99     }
100
101     if (serviceTemplate.getTopology_template() == null) {
102       serviceTemplate.setTopology_template(new TopologyTemplate());
103     }
104     serviceTemplate.getTopology_template().setSubstitution_mappings(substitutionMapping);
105
106     mdcDataDebugMessage.debugExitMessage(null, null);
107   }
108
109   /**
110    * Add substitution mapping req.
111    *
112    * @param serviceTemplate                    the service template
113    * @param substitutionMappingRequirementId   the substitution mapping requirement id
114    * @param substitutionMappingRequirementList the substitution mapping requirement list
115    */
116   public static void addSubstitutionMappingReq(ServiceTemplate serviceTemplate,
117                                                String substitutionMappingRequirementId,
118                                                List<String> substitutionMappingRequirementList) {
119
120
121     mdcDataDebugMessage.debugEntryMessage(null, null);
122
123     if (serviceTemplate == null) {
124       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
125           LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
126           LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
127       throw new CoreException(
128           new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Requirements",
129               "Service Template").build());
130     }
131
132     if (serviceTemplate.getTopology_template() == null) {
133       serviceTemplate.setTopology_template(new TopologyTemplate());
134     }
135     if (serviceTemplate.getTopology_template().getSubstitution_mappings() == null) {
136       serviceTemplate.getTopology_template().setSubstitution_mappings(new SubstitutionMapping());
137     }
138     if (serviceTemplate.getTopology_template().getSubstitution_mappings().getRequirements()
139         == null) {
140       serviceTemplate.getTopology_template().getSubstitution_mappings()
141           .setRequirements(new HashMap<>());
142     }
143
144     serviceTemplate.getTopology_template().getSubstitution_mappings().getRequirements()
145         .put(substitutionMappingRequirementId, substitutionMappingRequirementList);
146
147     mdcDataDebugMessage.debugExitMessage(null, null);
148   }
149
150   /**
151    * Add node template.
152    *
153    * @param serviceTemplate the service template
154    * @param nodeTemplateId  the node template id
155    * @param nodeTemplate    the node template
156    */
157   public static void addNodeTemplate(ServiceTemplate serviceTemplate, String nodeTemplateId,
158                                      NodeTemplate nodeTemplate) {
159
160
161     mdcDataDebugMessage.debugEntryMessage(null, null);
162
163     if (serviceTemplate == null) {
164       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
165           LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
166           LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
167       throw new CoreException(
168           new InvalidAddActionNullEntityErrorBuilder("Node Template", "Service Template").build());
169     }
170     TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
171     if (Objects.isNull(topologyTemplate)) {
172       topologyTemplate = new TopologyTemplate();
173       serviceTemplate.setTopology_template(topologyTemplate);
174     }
175     if (topologyTemplate.getNode_templates() == null) {
176       topologyTemplate.setNode_templates(new HashMap<>());
177     }
178     topologyTemplate.getNode_templates().put(nodeTemplateId, nodeTemplate);
179
180     mdcDataDebugMessage.debugExitMessage(null, null);
181
182   }
183
184   /**
185    * Add capability def.
186    *
187    * @param nodeType             the node type
188    * @param capabilityId         the capability id
189    * @param capabilityDefinition the capability definition
190    */
191   public static void addCapabilityDef(NodeType nodeType, String capabilityId,
192                                       CapabilityDefinition capabilityDefinition) {
193
194
195     mdcDataDebugMessage.debugEntryMessage(null, null);
196
197     if (nodeType == null) {
198       throw new CoreException(
199           new InvalidAddActionNullEntityErrorBuilder("Capability Definition", "Node Type").build());
200     }
201     if (Objects.isNull(nodeType.getCapabilities())) {
202       nodeType.setCapabilities(new HashMap<>());
203     }
204     nodeType.getCapabilities().put(capabilityId, capabilityDefinition);
205
206     mdcDataDebugMessage.debugExitMessage(null, null);
207   }
208
209   /**
210    * Add capabilities def to node type.
211    *
212    * @param nodeType     the node type
213    * @param capabilities the capability definitions
214    */
215   public static void addNodeTypeCapabilitiesDef(NodeType nodeType,
216                                                 Map<String, CapabilityDefinition> capabilities) {
217     mdcDataDebugMessage.debugEntryMessage(null, null);
218
219     if (capabilities == null || capabilities.entrySet().size() == 0) {
220       return;
221     }
222
223     if (nodeType == null) {
224       throw new CoreException(
225           new InvalidAddActionNullEntityErrorBuilder("Capability Definition", "Node Type").build());
226     }
227
228     if (MapUtils.isEmpty(nodeType.getCapabilities())) {
229       nodeType.setCapabilities(new HashMap<>());
230     }
231     if (capabilities.size() > 0) {
232       nodeType.setCapabilities(new HashMap<>());
233     }
234     for (Map.Entry<String, CapabilityDefinition> entry : capabilities.entrySet()) {
235       nodeType.getCapabilities().put(entry.getKey(), entry.getValue());
236     }
237
238     mdcDataDebugMessage.debugExitMessage(null, null);
239   }
240
241   /**
242    * Add policy definition.
243    *
244    * @param serviceTemplate  the service template
245    * @param policyId         the policy id
246    * @param policyDefinition the policy definition
247    */
248   public static void addPolicyDefinition(ServiceTemplate serviceTemplate, String policyId,
249                                          PolicyDefinition policyDefinition) {
250
251
252     mdcDataDebugMessage.debugEntryMessage(null, null);
253
254     if (serviceTemplate == null) {
255       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
256           LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
257           LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
258       throw new CoreException(
259           new InvalidAddActionNullEntityErrorBuilder("Policy Definition", "Service Template")
260               .build());
261     }
262     TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
263     if (Objects.isNull(topologyTemplate)) {
264       topologyTemplate = new TopologyTemplate();
265       serviceTemplate.setTopology_template(topologyTemplate);
266     }
267     if (topologyTemplate.getPolicies() == null) {
268       topologyTemplate.setPolicies(new HashMap<>());
269     }
270     topologyTemplate.getPolicies().put(policyId, policyDefinition);
271
272     mdcDataDebugMessage.debugExitMessage(null, null);
273   }
274
275   /**
276    * Add node type.
277    *
278    * @param serviceTemplate the service template
279    * @param nodeTypeId      the node type id
280    * @param nodeType        the node type
281    */
282   public static void addNodeType(ServiceTemplate serviceTemplate, String nodeTypeId,
283                                  NodeType nodeType) {
284
285
286     mdcDataDebugMessage.debugEntryMessage(null, null);
287
288     if (serviceTemplate == null) {
289       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
290           LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
291           LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
292       throw new CoreException(
293           new InvalidAddActionNullEntityErrorBuilder("Node Type", "Service Template").build());
294     }
295     if (serviceTemplate.getNode_types() == null) {
296       serviceTemplate.setNode_types(new HashMap<>());
297     }
298     serviceTemplate.getNode_types().put(nodeTypeId, nodeType);
299
300     mdcDataDebugMessage.debugExitMessage(null, null);
301   }
302
303   /**
304    * Add relationship template.
305    *
306    * @param serviceTemplate        the service template
307    * @param relationshipTemplateId the relationship template id
308    * @param relationshipTemplate   the relationship template
309    */
310   public static void addRelationshipTemplate(ServiceTemplate serviceTemplate,
311                                              String relationshipTemplateId,
312                                              RelationshipTemplate relationshipTemplate) {
313
314
315     mdcDataDebugMessage.debugEntryMessage(null, null);
316
317     if (serviceTemplate == null) {
318       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
319           LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
320           LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
321       throw new CoreException(
322           new InvalidAddActionNullEntityErrorBuilder("Relationship Template", "Service Template")
323               .build());
324     }
325     if (serviceTemplate.getTopology_template() == null) {
326       serviceTemplate.setTopology_template(new TopologyTemplate());
327     }
328     if (serviceTemplate.getTopology_template().getRelationship_templates() == null) {
329       serviceTemplate.getTopology_template().setRelationship_templates(new HashMap<>());
330     }
331     serviceTemplate.getTopology_template().getRelationship_templates()
332         .put(relationshipTemplateId, relationshipTemplate);
333
334     mdcDataDebugMessage.debugExitMessage(null, null);
335   }
336
337   /**
338    * Add requirement assignment.
339    *
340    * @param nodeTemplate          the node template
341    * @param requirementId         the requirement id
342    * @param requirementAssignment the requirement assignment
343    */
344   public static void addRequirementAssignment(NodeTemplate nodeTemplate, String requirementId,
345                                               RequirementAssignment requirementAssignment) {
346
347
348     mdcDataDebugMessage.debugEntryMessage(null, null);
349
350     if (nodeTemplate == null) {
351       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
352           LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
353           LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
354       throw new CoreException(
355           new InvalidAddActionNullEntityErrorBuilder("Requirement Assignment", "Node Template")
356               .build());
357     }
358     if (requirementAssignment.getNode() == null) {
359       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
360           LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
361           LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
362       throw new CoreException(new InvalidRequirementAssignmentErrorBuilder(requirementId).build());
363     }
364
365     if (nodeTemplate.getRequirements() == null) {
366       nodeTemplate.setRequirements(new ArrayList<>());
367     }
368     Map<String, RequirementAssignment> requirement = new HashMap<>();
369     requirement.put(requirementId, requirementAssignment);
370     nodeTemplate.getRequirements().add(requirement);
371
372     mdcDataDebugMessage.debugExitMessage(null, null);
373   }
374
375   /**
376    * Gets node template.
377    *
378    * @param serviceTemplate the service template
379    * @param nodeTemplateId  the node template id
380    * @return the node template
381    */
382   public static NodeTemplate getNodeTemplate(ServiceTemplate serviceTemplate,
383                                              String nodeTemplateId) {
384
385     mdcDataDebugMessage.debugEntryMessage(null, null);
386
387     if (serviceTemplate == null
388         || serviceTemplate.getTopology_template() == null
389         || serviceTemplate.getTopology_template().getNode_templates() == null) {
390       return null;
391     }
392
393     mdcDataDebugMessage.debugExitMessage(null, null);
394     return serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId);
395   }
396
397   /**
398    * Gets node type.
399    *
400    * @param serviceTemplate the service template
401    * @param nodeTypeId      the node type id
402    * @return the node type
403    */
404   public static NodeType getNodeType(ServiceTemplate serviceTemplate, String nodeTypeId) {
405
406
407     mdcDataDebugMessage.debugEntryMessage(null, null);
408     if (serviceTemplate == null || serviceTemplate.getNode_types() == null) {
409       return null;
410     }
411
412     mdcDataDebugMessage.debugExitMessage(null, null);
413     return serviceTemplate.getNode_types().get(nodeTypeId);
414   }
415
416   /**
417    * Gets requirement definition.
418    *
419    * @param nodeType                the node type
420    * @param requirementDefinitionId the requirement definition id
421    * @return the requirement definition
422    */
423   public static Optional<RequirementDefinition> getRequirementDefinition(
424       NodeType nodeType,
425       String requirementDefinitionId) {
426
427
428     mdcDataDebugMessage.debugEntryMessage(null, null);
429
430     if (nodeType == null || nodeType.getRequirements() == null || requirementDefinitionId == null) {
431       return Optional.empty();
432     }
433     for (Map<String, RequirementDefinition> reqMap : nodeType.getRequirements()) {
434       if (reqMap.containsKey(requirementDefinitionId)) {
435         return Optional.of(reqMap.get(requirementDefinitionId));
436       }
437     }
438
439     mdcDataDebugMessage.debugExitMessage(null, null);
440     return Optional.empty();
441   }
442
443   /**
444    * get requirement defenition from requirement defenition list by req key.
445    *
446    * @param requirementsDefinitionList requirement defenition list
447    * @param requirementKey             requirement key
448    */
449   public static Optional<RequirementDefinition> getRequirementDefinition(
450       List<Map<String, RequirementDefinition>> requirementsDefinitionList,
451       String requirementKey) {
452     mdcDataDebugMessage.debugEntryMessage(null, null);
453     if (CollectionUtils.isEmpty(requirementsDefinitionList)) {
454       return Optional.empty();
455     }
456
457     for (Map<String, RequirementDefinition> requirementMap : requirementsDefinitionList) {
458       if (requirementMap.containsKey(requirementKey)) {
459         mdcDataDebugMessage.debugExitMessage(null, null);
460         return Optional.of(requirementMap.get(requirementKey));
461       }
462     }
463
464     mdcDataDebugMessage.debugExitMessage(null, null);
465     return Optional.empty();
466   }
467
468   /**
469    * Gets capability definition.
470    *
471    * @param nodeType               the node type
472    * @param capabilityDefinitionId the capability definition id
473    * @return the capability definition
474    */
475   public static Optional<CapabilityDefinition> getCapabilityDefinition(
476       NodeType nodeType,
477       String capabilityDefinitionId) {
478
479
480     mdcDataDebugMessage.debugEntryMessage(null, null);
481
482     if (nodeType == null || nodeType.getCapabilities() == null || capabilityDefinitionId == null) {
483       return Optional.empty();
484     }
485
486     mdcDataDebugMessage.debugExitMessage(null, null);
487     return Optional.ofNullable(nodeType.getCapabilities().get(capabilityDefinitionId));
488   }
489
490   /**
491    * Add group definition to topology template.
492    *
493    * @param serviceTemplate the service template
494    * @param groupName       the group name
495    * @param group           the group
496    */
497   public static void addGroupDefinitionToTopologyTemplate(ServiceTemplate serviceTemplate,
498                                                           String groupName, GroupDefinition group) {
499
500
501     mdcDataDebugMessage.debugEntryMessage(null, null);
502
503     if (serviceTemplate == null) {
504       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
505           LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
506           LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
507       throw new CoreException(
508           new InvalidAddActionNullEntityErrorBuilder("Group Definition", "Service Template")
509               .build());
510     }
511
512     TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
513     if (Objects.isNull(topologyTemplate)) {
514       topologyTemplate = new TopologyTemplate();
515       serviceTemplate.setTopology_template(topologyTemplate);
516     }
517     if (topologyTemplate.getGroups() == null) {
518       topologyTemplate.setGroups(new HashMap<>());
519     }
520     if (serviceTemplate.getTopology_template().getGroups() == null) {
521       Map<String, GroupDefinition> groups = new HashMap<>();
522       serviceTemplate.getTopology_template().setGroups(groups);
523     }
524
525     serviceTemplate.getTopology_template().getGroups().put(groupName, group);
526     mdcDataDebugMessage.debugExitMessage(null, null);
527   }
528
529   /**
530    * Create property definition property definition.
531    *
532    * @param type        the type
533    * @param description the description
534    * @param required    the required
535    * @param constraints the constraints
536    * @param status      the status
537    * @param entrySchema the entry schema
538    * @param defaultVal  the default val
539    * @return the property definition
540    */
541   public static PropertyDefinition createPropertyDefinition(String type, String description,
542                                                             boolean required,
543                                                             List<Constraint> constraints,
544                                                             Status status,
545                                                             EntrySchema entrySchema,
546                                                             Object defaultVal) {
547
548
549     mdcDataDebugMessage.debugEntryMessage(null, null);
550
551     PropertyDefinition propDef = new PropertyDefinition();
552     propDef.setType(type);
553     propDef.setDescription(description);
554     propDef.setRequired(required);
555     propDef.setConstraints(constraints);
556     if (status != null) {
557       propDef.setStatus(status);
558     }
559     propDef.setEntry_schema(entrySchema);
560     propDef.set_default(defaultVal);
561
562     mdcDataDebugMessage.debugExitMessage(null, null);
563     return propDef;
564   }
565
566   /**
567    * Create parameter definition property definition.
568    *
569    * @param type        the type
570    * @param description the description
571    * @param value       the value
572    * @param required    the required
573    * @param constraints the constraints
574    * @param status      the status
575    * @param entrySchema the entry schema
576    * @param defaultVal  the default val
577    * @return the property definition
578    */
579   public static ParameterDefinition createParameterDefinition(String type, String description,
580                                                               Object value, boolean required,
581                                                               List<Constraint> constraints,
582                                                               Status status,
583                                                               EntrySchema entrySchema,
584                                                               Object defaultVal) {
585
586
587     mdcDataDebugMessage.debugEntryMessage(null, null);
588
589     ParameterDefinition paramDef = new ParameterDefinition();
590     paramDef.setType(type);
591     paramDef.setDescription(description);
592     paramDef.setValue(value);
593     paramDef.setRequired(required);
594     paramDef.setConstraints(constraints);
595     if (status != null) {
596       paramDef.setStatus(status);
597     }
598     paramDef.setEntry_schema(entrySchema == null ? null : entrySchema.clone());
599     paramDef.set_default(defaultVal);
600
601     mdcDataDebugMessage.debugExitMessage(null, null);
602     return paramDef;
603   }
604
605   /**
606    * Create requirement requirement definition.
607    *
608    * @param capability   the capability
609    * @param node         the node
610    * @param relationship the relationship
611    * @param occurrences  the occurrences
612    * @return the requirement definition
613    */
614   public static RequirementDefinition createRequirement(String capability, String node,
615                                                         String relationship, Object[] occurrences) {
616
617
618     mdcDataDebugMessage.debugEntryMessage(null, null);
619
620     RequirementDefinition requirementDefinition = new RequirementDefinition();
621     requirementDefinition.setCapability(capability);
622     requirementDefinition.setNode(node);
623     requirementDefinition.setRelationship(relationship);
624     if (occurrences != null) {
625       requirementDefinition.setOccurrences(occurrences);
626     }
627
628     mdcDataDebugMessage.debugExitMessage(null, null);
629     return requirementDefinition;
630   }
631
632   /**
633    * Create attribute definition attribute definition.
634    *
635    * @param type        the type
636    * @param description the description
637    * @param status      the status
638    * @param entrySchema the entry schema
639    * @param defaultVal  the default val
640    * @return the attribute definition
641    */
642   public static AttributeDefinition createAttributeDefinition(String type, String description,
643                                                               Status status,
644                                                               EntrySchema entrySchema,
645                                                               Object defaultVal) {
646
647
648     mdcDataDebugMessage.debugEntryMessage(null, null);
649
650     AttributeDefinition attributeDef = new AttributeDefinition();
651     attributeDef.setType(type);
652
653     if (description != null) {
654       attributeDef.setDescription(description);
655     }
656     if (status != null) {
657       attributeDef.setStatus(status);
658     }
659     attributeDef.setEntry_schema(entrySchema);
660     attributeDef.set_default(defaultVal);
661
662     mdcDataDebugMessage.debugExitMessage(null, null);
663     return attributeDef;
664   }
665
666   /**
667    * Create valid values constraint constraint.
668    *
669    * @param values the values
670    * @return the constraint
671    */
672   public static Constraint createValidValuesConstraint(Object... values) {
673
674
675     mdcDataDebugMessage.debugEntryMessage(null, null);
676
677     Constraint validValues = new Constraint();
678     for (Object value : values) {
679       validValues.addValidValue(value);
680     }
681
682     mdcDataDebugMessage.debugExitMessage(null, null);
683     return validValues;
684   }
685
686   /**
687    * Create metadata metadata.
688    *
689    * @param templateName    the template name
690    * @param templateVersion the template version
691    * @param templateAuthor  the template author
692    * @return the metadata
693    */
694   public static Map<String, String> createMetadata(String templateName, String templateVersion,
695                                         String templateAuthor) {
696
697
698     mdcDataDebugMessage.debugEntryMessage(null, null);
699     Map<String, String> metadata = new HashMap<>();
700     metadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, templateName);
701     metadata.put("template_version", templateVersion);
702     metadata.put("template_author", templateAuthor);
703
704     mdcDataDebugMessage.debugExitMessage(null, null);
705     return metadata;
706   }
707
708   /**
709    * Create entry schema entry schema.
710    *
711    * @param type        the type
712    * @param description the description
713    * @param constraints the constraints
714    * @return the entry schema
715    */
716   public static EntrySchema createEntrySchema(String type, String description,
717                                               List<Constraint> constraints) {
718
719
720     mdcDataDebugMessage.debugEntryMessage(null, null);
721
722     EntrySchema entrySchema = new EntrySchema();
723     entrySchema.setType(type);
724     entrySchema.setDescription(description);
725     entrySchema.setConstraints(constraints);
726
727     mdcDataDebugMessage.debugExitMessage(null, null);
728     return entrySchema;
729   }
730
731   /**
732    * Create valid values constraints list list.
733    *
734    * @param values the values
735    * @return the list
736    */
737   public static List<Constraint> createValidValuesConstraintsList(String... values) {
738
739
740     mdcDataDebugMessage.debugEntryMessage(null, null);
741
742     List<Constraint> constraints;
743     Constraint validValues;
744     constraints = new ArrayList<>();
745     validValues = DataModelUtil.createValidValuesConstraint(values);
746     constraints.add(validValues);
747
748     mdcDataDebugMessage.debugExitMessage(null, null);
749     return constraints;
750   }
751
752   /**
753    * Create greater or equal constrain constraint.
754    *
755    * @param value the value
756    * @return the constraint
757    */
758   public static Constraint createGreaterOrEqualConstrain(Object value) {
759     mdcDataDebugMessage.debugEntryMessage(null, null);
760
761     Constraint constraint = new Constraint();
762     constraint.setGreater_or_equal(value);
763
764     mdcDataDebugMessage.debugExitMessage(null, null);
765     return constraint;
766   }
767
768   /**
769    * Gets constrain list.
770    *
771    * @param constrains the constrains
772    * @return the constrain list
773    */
774   public static List<Constraint> getConstrainList(Constraint... constrains) {
775     return Arrays.asList(constrains);
776
777   }
778
779   /**
780    * Create get input property value from list parameter map.
781    *
782    * @param inputPropertyListName the input property list name
783    * @param indexInTheList        the index in the list
784    * @param nestedPropertyName    the nested property name
785    * @return the map
786    */
787   public static Map createGetInputPropertyValueFromListParameter(String inputPropertyListName,
788                                                                  int indexInTheList,
789                                                                  String... nestedPropertyName) {
790
791
792     mdcDataDebugMessage.debugEntryMessage(null, null);
793
794     List propertyList = new ArrayList<>();
795     propertyList.add(inputPropertyListName);
796     propertyList.add(indexInTheList);
797     if (nestedPropertyName != null) {
798       Collections.addAll(propertyList, nestedPropertyName);
799     }
800     Map getInputProperty = new HashMap<>();
801     getInputProperty.put(ToscaFunctions.GET_INPUT.getDisplayName(), propertyList);
802
803     mdcDataDebugMessage.debugExitMessage(null, null);
804     return getInputProperty;
805   }
806
807   /**
808    * Convert property def to parameter def parameter definition ext.
809    *
810    * @param propertyDefinition the property definition
811    * @return the parameter definition ext
812    */
813   public static ParameterDefinitionExt convertPropertyDefToParameterDef(
814       PropertyDefinition propertyDefinition) {
815
816
817     mdcDataDebugMessage.debugEntryMessage(null, null);
818
819     if (propertyDefinition == null) {
820       return null;
821     }
822
823     ParameterDefinitionExt parameterDefinition = new ParameterDefinitionExt();
824     parameterDefinition.setType(propertyDefinition.getType());
825     parameterDefinition.setDescription(propertyDefinition.getDescription());
826     parameterDefinition.setRequired(propertyDefinition.getRequired());
827     parameterDefinition.set_default(propertyDefinition.get_default());
828     parameterDefinition.setStatus(propertyDefinition.getStatus());
829     parameterDefinition.setConstraints(propertyDefinition.getConstraints());
830     parameterDefinition.setEntry_schema(Objects.isNull(propertyDefinition.getEntry_schema()) ? null
831         : propertyDefinition.getEntry_schema().clone());
832     parameterDefinition.setHidden(false);
833     parameterDefinition.setImmutable(false);
834
835     mdcDataDebugMessage.debugExitMessage(null, null);
836     return parameterDefinition;
837   }
838
839   /**
840    * Convert attribute def to parameter def parameter definition ext.
841    *
842    * @param attributeDefinition the attribute definition
843    * @param outputValue         the output value
844    * @return the parameter definition ext
845    */
846   public static ParameterDefinitionExt convertAttributeDefToParameterDef(
847       AttributeDefinition attributeDefinition, Map<String, List> outputValue) {
848
849
850     mdcDataDebugMessage.debugEntryMessage(null, null);
851
852     if (attributeDefinition == null) {
853       return null;
854     }
855     ParameterDefinitionExt parameterDefinition = new ParameterDefinitionExt();
856     parameterDefinition.setDescription(attributeDefinition.getDescription());
857     parameterDefinition.setValue(outputValue);
858
859     mdcDataDebugMessage.debugExitMessage(null, null);
860     return parameterDefinition;
861   }
862
863   /**
864    * Convert capability type to capability definition capability definition.
865    *
866    * @param capabilityTypeId the capability type id
867    * @param capabilityType   the capability type
868    * @param properties       the properties
869    * @return the capability definition
870    */
871   public static CapabilityDefinition convertCapabilityTypeToCapabilityDefinition(
872       String capabilityTypeId, CapabilityType capabilityType, Map<String, Object> properties) {
873
874
875     mdcDataDebugMessage.debugEntryMessage(null, null);
876
877     CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
878     capabilityDefinition.setAttributes(cloneAttributeDefinitionMap(capabilityType.getAttributes()));
879     capabilityDefinition.setProperties(clonePropertyDefinitionMap(capabilityType.getProperties()));
880     capabilityDefinition.setDescription(capabilityType.getDescription());
881     capabilityDefinition.setType(capabilityTypeId);
882
883     capabilityDefinition.getProperties()
884         .entrySet()
885         .stream()
886         .filter(entry -> properties.containsKey(entry.getKey()))
887         .forEach(entry -> entry.getValue()
888             .set_default(properties.get(entry.getKey())));
889
890     mdcDataDebugMessage.debugExitMessage(null, null);
891     return capabilityDefinition;
892   }
893
894   /**
895    * Clone property definition map map.
896    *
897    * @param propertyDefinitionMap the property definition map
898    * @return the map
899    */
900   public static Map clonePropertyDefinitionMap(
901       Map<String, PropertyDefinition> propertyDefinitionMap) {
902
903
904     mdcDataDebugMessage.debugEntryMessage(null, null);
905
906     Map outMap = new HashMap<>();
907     for (String propertyDefKey : propertyDefinitionMap.keySet()) {
908       PropertyDefinition propertyDefValue = propertyDefinitionMap.get(propertyDefKey);
909       outMap.put(new String(propertyDefKey), propertyDefValue.clone());
910     }
911
912     mdcDataDebugMessage.debugExitMessage(null, null);
913     return outMap;
914   }
915
916   /**
917    * Clone attribute definition map map.
918    *
919    * @param attributeDefinitionMap the attribute definition map
920    * @return the map
921    */
922   public static Map cloneAttributeDefinitionMap(
923       Map<String, AttributeDefinition> attributeDefinitionMap) {
924
925
926     mdcDataDebugMessage.debugEntryMessage(null, null);
927
928     Map outMap = new HashMap<>();
929     for (String attributeDefKey : attributeDefinitionMap.keySet()) {
930       AttributeDefinition attributeDefinition = attributeDefinitionMap.get(attributeDefKey);
931       outMap.put(new String(attributeDefKey), attributeDefinition.clone());
932     }
933
934     mdcDataDebugMessage.debugExitMessage(null, null);
935     return outMap;
936   }
937
938   public static boolean isNodeTemplate(String entryId, ServiceTemplate serviceTemplate) {
939     return serviceTemplate.getTopology_template().getNode_templates() != null
940         && serviceTemplate.getTopology_template().getNode_templates().get(entryId) != null;
941   }
942
943   /**
944    * Add Input parameter.
945    *
946    * @param serviceTemplate       the service template
947    * @param parameterDefinitionId the parameter definition id
948    * @param parameterDefinition   the parameter definition
949    */
950   public static void addInputParameterToTopologyTemplate(ServiceTemplate serviceTemplate,
951                                                          String parameterDefinitionId,
952                                                          ParameterDefinition parameterDefinition) {
953
954
955     mdcDataDebugMessage.debugEntryMessage(null, null);
956
957     if (Objects.isNull(serviceTemplate)) {
958       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
959           LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
960           LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
961       throw new CoreException(
962           new InvalidAddActionNullEntityErrorBuilder("Topology Template Input Parameter",
963               "Service Template").build());
964     }
965     TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
966     if (Objects.isNull(topologyTemplate)) {
967       topologyTemplate = new TopologyTemplate();
968       serviceTemplate.setTopology_template(topologyTemplate);
969     }
970     if (topologyTemplate.getInputs() == null) {
971       topologyTemplate.setInputs(new HashMap<>());
972     }
973     topologyTemplate.getInputs().put(parameterDefinitionId, parameterDefinition);
974
975     mdcDataDebugMessage.debugExitMessage(null, null);
976
977   }
978
979   /**
980    * Add Output parameter.
981    *
982    * @param serviceTemplate       the service template
983    * @param parameterDefinitionId the parameter definition id
984    * @param parameterDefinition   the parameter definition
985    */
986   public static void addOutputParameterToTopologyTemplate(ServiceTemplate serviceTemplate,
987                                                           String parameterDefinitionId,
988                                                           ParameterDefinition parameterDefinition) {
989
990
991     mdcDataDebugMessage.debugEntryMessage(null, null);
992
993     if (Objects.isNull(serviceTemplate)) {
994       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
995           LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
996           LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
997       throw new CoreException(
998           new InvalidAddActionNullEntityErrorBuilder("Topology Template Ouput Parameter",
999               "Service Template").build());
1000     }
1001     TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
1002     if (Objects.isNull(topologyTemplate)) {
1003       topologyTemplate = new TopologyTemplate();
1004       serviceTemplate.setTopology_template(topologyTemplate);
1005     }
1006     if (topologyTemplate.getOutputs() == null) {
1007       topologyTemplate.setOutputs(new HashMap<>());
1008     }
1009     topologyTemplate.getOutputs().put(parameterDefinitionId, parameterDefinition);
1010
1011     mdcDataDebugMessage.debugExitMessage(null, null);
1012
1013   }
1014
1015   /**
1016    * Add requirement def to requirement def list.
1017    *
1018    * @param requirementList requirement list
1019    * @param requirementDef  added requirement def
1020    */
1021   public static void addRequirementToList(List<Map<String, RequirementDefinition>> requirementList,
1022                                           Map<String, RequirementDefinition> requirementDef) {
1023     if (requirementDef == null) {
1024       return;
1025     }
1026     if (requirementList == null) {
1027       requirementList = new ArrayList<Map<String, RequirementDefinition>>();
1028     }
1029
1030     for (Map.Entry<String, RequirementDefinition> entry : requirementDef.entrySet()) {
1031       CommonMethods.mergeEntryInList(entry.getKey(), entry.getValue(), requirementList);
1032     }
1033   }
1034
1035   /**
1036    * get node template requirement.
1037    *
1038    * @param nodeTemplate node template
1039    */
1040   public static Map<String, RequirementAssignment> getNodeTemplateRequirements(
1041       NodeTemplate nodeTemplate) {
1042     mdcDataDebugMessage.debugEntryMessage(null, null);
1043
1044     if (Objects.isNull(nodeTemplate)) {
1045       return null;
1046     }
1047     List<Map<String, RequirementAssignment>> templateRequirements = nodeTemplate.getRequirements();
1048
1049     Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment = new HashMap<>();
1050     if (CollectionUtils.isEmpty(templateRequirements)) {
1051       return nodeTemplateRequirementsAssignment;
1052     }
1053     YamlUtil yamlUtil = new YamlUtil();
1054     for (Map<String, RequirementAssignment> requirementAssignmentMap : templateRequirements) {
1055       for (Map.Entry<String, RequirementAssignment> requirementEntry : requirementAssignmentMap
1056           .entrySet()) {
1057         RequirementAssignment requirementAssignment = (yamlUtil
1058             .yamlToObject(yamlUtil.objectToYaml(requirementEntry.getValue()),
1059                 RequirementAssignment.class));
1060         nodeTemplateRequirementsAssignment
1061             .put(requirementEntry.getKey(), requirementAssignment);
1062       }
1063     }
1064
1065     mdcDataDebugMessage.debugExitMessage(null, null);
1066     return nodeTemplateRequirementsAssignment;
1067   }
1068
1069   /**
1070    * Gets the list of requirements for the node template.
1071    *
1072    * @param nodeTemplate the node template
1073    * @return the node template requirement list and null if the node has no requirements
1074    */
1075   public static List<Map<String, RequirementAssignment>> getNodeTemplateRequirementList(
1076       NodeTemplate nodeTemplate) {
1077     mdcDataDebugMessage.debugEntryMessage(null, null);
1078     ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
1079     //Creating concrete objects
1080     List<Map<String, RequirementAssignment>> requirements = nodeTemplate.getRequirements();
1081     List<Map<String, RequirementAssignment>> concreteRequirementList = null;
1082     if (requirements != null) {
1083       concreteRequirementList = new ArrayList<>();
1084       ListIterator<Map<String, RequirementAssignment>> reqListIterator = requirements
1085           .listIterator();
1086       while (reqListIterator.hasNext()) {
1087         Map<String, RequirementAssignment> requirement = reqListIterator.next();
1088         Map<String, RequirementAssignment> concreteRequirement = new HashMap<>();
1089         for (Map.Entry<String, RequirementAssignment> reqEntry : requirement.entrySet()) {
1090           RequirementAssignment requirementAssignment = (toscaExtensionYamlUtil
1091               .yamlToObject(toscaExtensionYamlUtil.objectToYaml(reqEntry.getValue()),
1092                   RequirementAssignment.class));
1093           concreteRequirement.put(reqEntry.getKey(), requirementAssignment);
1094           concreteRequirementList.add(concreteRequirement);
1095           reqListIterator.remove();
1096         }
1097       }
1098       requirements.clear();
1099       requirements.addAll(concreteRequirementList);
1100       nodeTemplate.setRequirements(requirements);
1101     }
1102     mdcDataDebugMessage.debugExitMessage(null, null);
1103     return concreteRequirementList;
1104   }
1105
1106   /**
1107    * get requirement assignment from requirement assignment list by req key.
1108    *
1109    * @param requirementsAssignmentList requirement defenition list
1110    * @param requirementKey             requirement key
1111    */
1112   public static Optional<List<RequirementAssignment>> getRequirementAssignment(
1113       List<Map<String, RequirementAssignment>> requirementsAssignmentList,
1114       String requirementKey) {
1115
1116     mdcDataDebugMessage.debugEntryMessage(null, null);
1117     if (CollectionUtils.isEmpty(requirementsAssignmentList)) {
1118       return Optional.empty();
1119     }
1120
1121     List<RequirementAssignment> matchRequirementAssignmentList = new ArrayList<>();
1122     for (Map<String, RequirementAssignment> requirementMap : requirementsAssignmentList) {
1123       if (requirementMap.containsKey(requirementKey)) {
1124         YamlUtil yamlUtil = new YamlUtil();
1125         RequirementAssignment requirementAssignment = (yamlUtil
1126             .yamlToObject(yamlUtil.objectToYaml(requirementMap.get(requirementKey)),
1127                 RequirementAssignment.class));
1128         matchRequirementAssignmentList.add(requirementAssignment);
1129       }
1130     }
1131
1132     mdcDataDebugMessage.debugExitMessage(null, null);
1133     return Optional.ofNullable(matchRequirementAssignmentList);
1134   }
1135
1136   /**
1137    * remove requirement defenition from requirement defenition list by req key.
1138    *
1139    * @param requirementsDefinitionList requirement defenition list
1140    * @param requirementKey             requirement key
1141    */
1142   public static void removeRequirementsDefinition(
1143       List<Map<String, RequirementDefinition>> requirementsDefinitionList,
1144       String requirementKey) {
1145     mdcDataDebugMessage.debugEntryMessage(null, null);
1146     if (requirementsDefinitionList == null) {
1147       return;
1148     }
1149
1150     List<Map<String, RequirementDefinition>> mapToBeRemoved = new ArrayList<>();
1151     for (Map<String, RequirementDefinition> reqMap : requirementsDefinitionList) {
1152       reqMap.remove(requirementKey);
1153       if (reqMap.isEmpty()) {
1154         mapToBeRemoved.add(reqMap);
1155       }
1156     }
1157     for (Map<String, RequirementDefinition> removeMap : mapToBeRemoved) {
1158       requirementsDefinitionList.remove(removeMap);
1159     }
1160
1161     mdcDataDebugMessage.debugExitMessage(null, null);
1162   }
1163
1164   /**
1165    * remove requirement assignment from requirement defenition list by req key.
1166    *
1167    * @param requirementsAssignmentList requirement Assignment list
1168    * @param requirementKey             requirement key
1169    */
1170   public static void removeRequirementsAssignment(
1171       List<Map<String, RequirementAssignment>> requirementsAssignmentList,
1172       String requirementKey) {
1173     mdcDataDebugMessage.debugEntryMessage(null, null);
1174     if (requirementsAssignmentList == null) {
1175       return;
1176     }
1177
1178     List<Map<String, RequirementAssignment>> mapToBeRemoved = new ArrayList<>();
1179     for (Map<String, RequirementAssignment> reqMap : requirementsAssignmentList) {
1180       reqMap.remove(requirementKey);
1181       if (reqMap.isEmpty()) {
1182         mapToBeRemoved.add(reqMap);
1183       }
1184     }
1185     for (Map<String, RequirementAssignment> removeMap : mapToBeRemoved) {
1186       requirementsAssignmentList.remove(removeMap);
1187     }
1188
1189     mdcDataDebugMessage.debugExitMessage(null, null);
1190   }
1191
1192
1193   /**
1194    * Remove requirement assignment.
1195    *
1196    * @param nodeTemplate                     the node template
1197    * @param requirementKey                   the requirement key
1198    * @param requirementAssignmentToBeDeleted the requirement assignment to be deleted
1199    */
1200   public static void removeRequirementAssignment(
1201       NodeTemplate nodeTemplate,
1202       String requirementKey,
1203       RequirementAssignment requirementAssignmentToBeDeleted) {
1204     mdcDataDebugMessage.debugEntryMessage(null, null);
1205     ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
1206     List<Map<String, RequirementAssignment>> nodeTemplateRequirements = nodeTemplate
1207         .getRequirements();
1208     if (nodeTemplateRequirements == null) {
1209       return;
1210     }
1211
1212     Map<String, RequirementAssignment> mapToBeRemoved = new HashMap<>();
1213     ListIterator<Map<String, RequirementAssignment>> iter = nodeTemplateRequirements.listIterator();
1214     while (iter.hasNext()) {
1215       Map<String, RequirementAssignment> reqMap = iter.next();
1216       RequirementAssignment requirementAssignment = reqMap.get(requirementKey);
1217       if (requirementAssignment != null) {
1218         boolean isDesiredRequirementAssignment = toscaAnalyzerService
1219             .isDesiredRequirementAssignment(requirementAssignment,
1220                 requirementAssignmentToBeDeleted.getCapability(),
1221                 requirementAssignmentToBeDeleted.getNode(),
1222                 requirementAssignmentToBeDeleted.getRelationship());
1223         if (isDesiredRequirementAssignment) {
1224           iter.remove();
1225         }
1226       }
1227     }
1228
1229     mdcDataDebugMessage.debugExitMessage(null, null);
1230   }
1231
1232   /**
1233    * Return the suffix of the input namespace
1234    * For an exmpale - for abc.sdf.vsrx, retrun vsrx
1235    *
1236    * @param namespace namespace
1237    * @return String namespace suffix
1238    */
1239   public static String getNamespaceSuffix(String namespace) {
1240     if (namespace == null) {
1241       return null;
1242     }
1243     String delimiterChar = ".";
1244     if (namespace.contains(delimiterChar)) {
1245       return namespace.substring(namespace.lastIndexOf(delimiterChar) + 1);
1246     }
1247     return namespace;
1248   }
1249
1250   /**
1251    * Return true if the input import exist in the input imports list.
1252    *
1253    * @param imports  namespace
1254    * @param importId namespace
1255    * @return true if exist, flase if not exist
1256    */
1257   public static boolean isImportAddedToServiceTemplate(List<Map<String, Import>> imports,
1258                                                        String importId) {
1259     for (Map<String, Import> anImport : imports) {
1260       if (anImport.containsKey(importId)) {
1261         return true;
1262       }
1263     }
1264     return false;
1265   }
1266
1267   /**
1268    * Get output parameter according to the input outputParameterId.
1269    *
1270    * @param serviceTemplate   service template
1271    * @param outputParameterId output parameter id
1272    * @return ParameterDefinition - output parameter
1273    */
1274   public static ParameterDefinition getOuputParameter(ServiceTemplate serviceTemplate,
1275                                                       String outputParameterId) {
1276     mdcDataDebugMessage.debugEntryMessage(null, null);
1277
1278     if (serviceTemplate == null
1279         || serviceTemplate.getTopology_template() == null
1280         || serviceTemplate.getTopology_template().getOutputs() == null) {
1281       return null;
1282     }
1283
1284     mdcDataDebugMessage.debugExitMessage(null, null);
1285     return serviceTemplate.getTopology_template().getOutputs().get(outputParameterId);
1286   }
1287
1288   /**
1289    * Gets input parameters in a service template.
1290    *
1291    * @param serviceTemplate the service template
1292    * @return the input parameters
1293    */
1294   public static Map<String, ParameterDefinition> getInputParameters(ServiceTemplate
1295                                                                         serviceTemplate) {
1296     if (serviceTemplate == null
1297         || serviceTemplate.getTopology_template() == null
1298         || serviceTemplate.getTopology_template().getInputs() == null) {
1299       return null;
1300     }
1301     return serviceTemplate.getTopology_template().getInputs();
1302   }
1303
1304   /**
1305    * Gets relationship templates in a service template.
1306    *
1307    * @param serviceTemplate the service template
1308    * @return the relationship template
1309    */
1310   public static Map<String, RelationshipTemplate> getRelationshipTemplates(ServiceTemplate
1311                                                                         serviceTemplate) {
1312     if (serviceTemplate == null
1313         || serviceTemplate.getTopology_template() == null
1314         || serviceTemplate.getTopology_template().getRelationship_templates() == null) {
1315       return null;
1316     }
1317     return serviceTemplate.getTopology_template().getRelationship_templates();
1318   }
1319
1320   /**
1321    * Get property value according to the input propertyId.
1322    *
1323    * @param nodeTemplate node template
1324    * @param propertyId   property id
1325    * @return Object        property Value
1326    */
1327   public static Object getPropertyValue(NodeTemplate nodeTemplate,
1328                                         String propertyId) {
1329     mdcDataDebugMessage.debugEntryMessage(null, null);
1330
1331     if (nodeTemplate == null
1332         || nodeTemplate.getProperties() == null) {
1333       return null;
1334     }
1335
1336     mdcDataDebugMessage.debugExitMessage(null, null);
1337     return nodeTemplate.getProperties().get(propertyId);
1338   }
1339
1340   /**
1341    * Get node template properties according to the input node template id.
1342    *
1343    * @param serviceTemplate       service template
1344    * @param nodeTemplateId        node template id
1345    * @return node template properties
1346    */
1347   public static Map<String, Object> getNodeTemplateProperties(ServiceTemplate serviceTemplate,
1348                                                               String nodeTemplateId) {
1349     mdcDataDebugMessage.debugEntryMessage(null, null);
1350
1351     if (serviceTemplate == null
1352         || serviceTemplate.getTopology_template() == null
1353         || serviceTemplate.getTopology_template().getNode_templates() == null
1354         || serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) == null) {
1355       return null;
1356     }
1357
1358     mdcDataDebugMessage.debugExitMessage(null, null);
1359     return serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId)
1360         .getProperties();
1361   }
1362
1363   /**
1364    * Compare two requirement assignment objects for equality.
1365    *
1366    * @param first  the first requirement assignement object
1367    * @param second the second  requirement assignement object
1368    * @return true if objects are equal and false otherwise
1369    */
1370   public static boolean compareRequirementAssignment(RequirementAssignment first,
1371                                                      RequirementAssignment second) {
1372     if (first.getCapability().equals(second.getCapability())
1373         && first.getNode().equals(second.getNode())
1374         && first.getRelationship().equals(second.getRelationship())) {
1375       return true;
1376     }
1377     return false;
1378   }
1379 }