Rename packages from openecomp to onap.
[sdc.git] / openecomp-be / lib / openecomp-sdc-translator-lib / openecomp-sdc-translator-core / src / main / java / org / openecomp / sdc / translator / datatypes / heattotosca / TranslationContext.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.translator.datatypes.heattotosca;
18
19 import com.google.common.collect.ArrayListMultimap;
20 import com.google.common.collect.ListMultimap;
21 import org.apache.commons.collections.MapUtils;
22 import org.onap.config.api.Configuration;
23 import org.onap.config.api.ConfigurationManager;
24 import org.openecomp.core.utilities.CommonMethods;
25 import org.openecomp.core.utilities.file.FileContentHandler;
26 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
27 import org.openecomp.sdc.common.errors.CoreException;
28 import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
29 import org.openecomp.sdc.heat.datatypes.manifest.FileData;
30 import org.openecomp.sdc.heat.datatypes.manifest.ManifestFile;
31 import org.openecomp.sdc.heat.datatypes.model.Resource;
32 import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
33 import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
34 import org.openecomp.sdc.tosca.services.ToscaUtil;
35 import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource;
36 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionEntity;
37 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedSubstitutionData;
38 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ConsolidationData;
39 import org.openecomp.sdc.translator.services.heattotosca.ConfigConstants;
40 import org.openecomp.sdc.translator.services.heattotosca.Constants;
41 import org.openecomp.sdc.translator.services.heattotosca.NameExtractor;
42 import org.openecomp.sdc.translator.services.heattotosca.errors.DuplicateResourceIdsInDifferentFilesErrorBuilder;
43 import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
44
45 import java.io.InputStream;
46 import java.util.HashMap;
47 import java.util.HashSet;
48 import java.util.List;
49 import java.util.Map;
50 import java.util.Objects;
51 import java.util.Optional;
52 import java.util.Set;
53
54
55 public class TranslationContext {
56
57
58   private static Map<String, Map<String, Map<String, String>>> translationMapping;
59   private static Map<String, ServiceTemplate> globalServiceTemplates;
60   private static Map<String, ImplementationConfiguration> nameExtractorImplMap;
61   private static Map<String, ImplementationConfiguration> supportedConsolidationComputeResources;
62   private static Map<String, ImplementationConfiguration> supportedConsolidationPortResources;
63   private static List<String> vfcGroupSubInterfaceExposedProperties;
64   private static List<String> enrichPortResourceProperties;
65   private static ImplementationConfiguration vfcInstanceGroupConfiguration;
66   private ManifestFile manifest;
67   private FileContentHandler files = new FileContentHandler();
68   private Map<String, FileData.Type> manifestFiles = new HashMap<>();
69   //Key - file name, value - file type
70   private Set<String> nestedHeatsFiles = new HashSet<>();
71   private FileContentHandler externalArtifacts = new FileContentHandler();
72   // Key - heat file name,value - set of heat resource ids which were translated
73   private Map<String, Set<String>> translatedResources = new HashMap<>();
74   // Key - heat file name, value - translated Node template id
75   private Map<String, Set<String>> heatStackGroupMembers = new HashMap<>();
76   // Key - heat file name, value - Map with Key - heat resource Id, Value - tosca entity template id
77   private Map<String, Map<String, String>> translatedIds = new HashMap<>();
78   // key - service template type, value - translated service templates
79   private Map<String, ServiceTemplate> translatedServiceTemplates = new HashMap<>();
80   //key - heat param name, value - shared resource data
81   private Map<String, TranslatedHeatResource> heatSharedResourcesByParam = new HashMap<>();
82   //key - translated substitute service template file name, value - source nested heat file name
83   private Map<String, String> nestedHeatFileName = new HashMap<>();
84   //Key - heat file name,value - Map eith key - heat pseudo param name,
85   // value - translated tosca parameter name
86   private Map<String, Map<String, String>> usedHeatPseudoParams = new HashMap<>();
87   //Consolidation data gathered for Unified TOSCA model
88   private ConsolidationData consolidationData = new ConsolidationData();
89   private Map<String, UnifiedSubstitutionData> unifiedSubstitutionData = new HashMap<>();
90   private Set<String> unifiedHandledServiceTemplates = new HashSet<>();
91
92   private Map<String, Map<String, Map<String, Integer>>>
93       requirementIdAppearanceInNodeTemplate = new HashMap<>();
94
95   private Set<String> serviceTemplatesWithoutNodeTemplateSection = new HashSet<>();
96
97   private Set<String> nodeTemplateIdsPointingToStWithoutNodeTemplates = new HashSet<>();
98
99   //Key - service template name, value - Map of key: node template id, value: properties with %index%
100   private Map<String, ListMultimap<String, String>> indexVarProperties = new HashMap<>();
101
102   static {
103     Configuration config = ConfigurationManager.lookup();
104     translationMapping =
105             config.generateMap(ConfigConstants.MAPPING_NAMESPACE, ConfigConstants.RESOURCE_MAPPING_KEY);
106     try {
107       globalServiceTemplates =
108               GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.ZIP);
109     } catch (Exception exc) {
110       throw new RuntimeException("Failed to load GlobalTypes", exc);
111     }
112     nameExtractorImplMap = config.populateMap(ConfigConstants.TRANSLATOR_NAMESPACE,
113             ConfigConstants.NAMING_CONVENTION_EXTRACTOR_IMPL_KEY, ImplementationConfiguration.class);
114     supportedConsolidationComputeResources = config.populateMap(ConfigConstants
115             .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
116             .SUPPORTED_CONSOLIDATION_COMPUTE_RESOURCES_KEY, ImplementationConfiguration.class);
117     supportedConsolidationPortResources = config.populateMap(ConfigConstants
118             .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
119             .SUPPORTED_CONSOLIDATION_PORT_RESOURCES_KEY, ImplementationConfiguration.class);
120     enrichPortResourceProperties = config.getAsStringValues(ConfigConstants
121             .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants
122             .ENRICH_PORT_RESOURCE_PROP);
123     vfcInstanceGroupConfiguration = getVfcInstanceGroupConfiguration(config);
124     vfcGroupSubInterfaceExposedProperties = config.getAsStringValues(ConfigConstants
125         .UNIFIED_MODEL_NAMESPACE, ConfigConstants.FULL_EXPOSED_PROPERTIES_KEY);
126   }
127
128
129   private static ImplementationConfiguration getVfcInstanceGroupConfiguration(Configuration config) {
130     Map<String, ImplementationConfiguration> supportedUnifiedModelProperties =
131         config.populateMap(ConfigConstants.UNIFIED_MODEL_NAMESPACE, ConfigConstants.UNIFIED_MODEL_IMPL_KEY,
132             ImplementationConfiguration.class);
133     return MapUtils.isEmpty(supportedUnifiedModelProperties) ? null :
134         supportedUnifiedModelProperties.get(ConfigConstants.VFC_INSTANCE_GROUP_KEY);
135   }
136
137   public static boolean isVfcInstanceGroupingEnabled() {
138     return Objects.nonNull(vfcInstanceGroupConfiguration) && vfcInstanceGroupConfiguration.isEnable();
139   }
140
141   public static List<String> getExposedVfcInstanceGroupingProperties() {
142     return vfcGroupSubInterfaceExposedProperties;
143   }
144
145   public static List<String> getEnrichPortResourceProperties() {
146     return enrichPortResourceProperties;
147   }
148
149   public static Map<String, ImplementationConfiguration>
150   getSupportedConsolidationComputeResources() {
151     return supportedConsolidationComputeResources;
152   }
153
154   public static void setSupportedConsolidationComputeResources(
155       Map<String, ImplementationConfiguration> supportedConsolidationComputeResources) {
156     TranslationContext.supportedConsolidationComputeResources =
157         supportedConsolidationComputeResources;
158   }
159
160   public static Map<String, ImplementationConfiguration> getSupportedConsolidationPortResources() {
161     return supportedConsolidationPortResources;
162   }
163
164   public static void setSupportedConsolidationPortResources(
165       Map<String, ImplementationConfiguration> supportedConsolidationPortResources) {
166     TranslationContext.supportedConsolidationPortResources = supportedConsolidationPortResources;
167   }
168
169   /**
170    * Get nameExtractor implemetation class instance.
171    *
172    * @param extractorImplKey configuration key for the implementation class
173    * @return implemetation class instance
174    */
175   public static NameExtractor getNameExtractorImpl(String extractorImplKey) {
176     String nameExtractorImplClassName =
177         nameExtractorImplMap.get(extractorImplKey).getImplementationClass();
178
179     return CommonMethods.newInstance(nameExtractorImplClassName, NameExtractor.class);
180   }
181
182   public Map<String, UnifiedSubstitutionData> getUnifiedSubstitutionData() {
183     return unifiedSubstitutionData;
184   }
185
186   public void setUnifiedSubstitutionData(
187       Map<String, UnifiedSubstitutionData> unifiedSubstitutionData) {
188     this.unifiedSubstitutionData = unifiedSubstitutionData;
189   }
190
191   public void addCleanedNodeTemplate(String serviceTemplateName,
192                                      String nodeTemplateId,
193                                      UnifiedCompositionEntity unifiedCompositionEntity,
194                                      NodeTemplate nodeTemplate) {
195     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
196     this.unifiedSubstitutionData
197         .get(serviceTemplateName)
198         .addCleanedNodeTemplate(nodeTemplateId, unifiedCompositionEntity, nodeTemplate);
199   }
200
201   public Optional<List<String>> getIndexVarProperties(String serviceTemplateName,
202                                     String nodeTemplateId) {
203     ListMultimap<String, String> serviceTemplateIndexVarProperties = this.indexVarProperties
204         .get(serviceTemplateName);
205     if (Objects.nonNull(serviceTemplateIndexVarProperties)) {
206       return Optional.of(this.indexVarProperties.get(serviceTemplateName).get(nodeTemplateId));
207     }
208     return Optional.empty();
209   }
210
211   public void addIndexVarProperties(String serviceTemplateName,
212                                      String nodeTemplateId,
213                                      List<String> indexVarProperties) {
214     this.indexVarProperties.putIfAbsent(serviceTemplateName, ArrayListMultimap.create());
215     this.indexVarProperties
216         .get(serviceTemplateName)
217         .putAll(nodeTemplateId, indexVarProperties);
218   }
219
220   public NodeTemplate getCleanedNodeTemplate(String serviceTemplateName,
221                                              String nodeTemplateId) {
222     return this.unifiedSubstitutionData.get(serviceTemplateName)
223         .getCleanedNodeTemplate(nodeTemplateId);
224   }
225
226   public void addUnifiedNestedNodeTemplateId(String serviceTemplateName,
227                                              String nestedNodeTemplateId,
228                                              String unifiedNestedNodeTemplateId) {
229     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
230     this.unifiedSubstitutionData.get(serviceTemplateName)
231         .addUnifiedNestedNodeTemplateId(nestedNodeTemplateId, unifiedNestedNodeTemplateId);
232   }
233
234   public Optional<String> getUnifiedNestedNodeTemplateId(String serviceTemplateName,
235                                                          String nestedNodeTemplateId) {
236     return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty()
237         : this.unifiedSubstitutionData.get(serviceTemplateName)
238             .getUnifiedNestedNodeTemplateId(nestedNodeTemplateId);
239   }
240
241   public void addUnifiedNestedNodeTypeId(String serviceTemplateName,
242                                          String nestedNodeTypeId,
243                                          String unifiedNestedNodeTypeId) {
244     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
245     this.unifiedSubstitutionData.get(serviceTemplateName)
246         .addUnifiedNestedNodeTypeId(nestedNodeTypeId, unifiedNestedNodeTypeId);
247   }
248
249   public Optional<String> getUnifiedNestedNodeTypeId(String serviceTemplateName,
250                                                      String nestedNodeTemplateId) {
251     return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty()
252         : this.unifiedSubstitutionData.get(serviceTemplateName)
253             .getUnifiedNestedNodeTypeId(nestedNodeTemplateId);
254   }
255
256   public ConsolidationData getConsolidationData() {
257     return consolidationData;
258   }
259
260   public void setConsolidationData(ConsolidationData consolidationData) {
261     this.consolidationData = consolidationData;
262   }
263
264   public void addManifestFile(String fileName, FileData.Type fileType) {
265     this.manifestFiles.put(fileName, fileType);
266   }
267
268   public Set<String> getNestedHeatsFiles() {
269     return nestedHeatsFiles;
270   }
271
272   public Map<String, Set<String>> getHeatStackGroupMembers() {
273     return heatStackGroupMembers;
274   }
275
276   public FileContentHandler getFiles() {
277     return files;
278   }
279
280   public void setFiles(Map<String, byte[]> files) {
281     this.files.putAll(files);
282   }
283
284   public InputStream getFileContent(String fileName) {
285     return files.getFileContent(fileName);
286   }
287
288   public void addFile(String name, byte[] content) {
289     files.addFile(name, content);
290   }
291
292   public ManifestFile getManifest() {
293     return manifest;
294   }
295
296   public void setManifest(ManifestFile manifest) {
297     this.manifest = manifest;
298   }
299
300   public Map<String, Set<String>> getTranslatedResources() {
301     return translatedResources;
302   }
303
304   public Map<String, Map<String, String>> getTranslatedIds() {
305     return translatedIds;
306   }
307
308   public Set<String> getAllTranslatedResourceIdsFromDiffNestedFiles(String
309                                                                         nestedHeatFileNameToSkip) {
310     Set<String> allTranslatedResourceIds = new HashSet<>();
311
312     this.translatedIds.entrySet().stream().filter(
313         heatFileNameToTranslatedIdsEntry -> !heatFileNameToTranslatedIdsEntry.getKey()
314             .equals(nestedHeatFileNameToSkip)).forEach(heatFileNameToTranslatedIdsEntry ->
315       allTranslatedResourceIds.addAll(heatFileNameToTranslatedIdsEntry.getValue().keySet())
316     );
317
318     return allTranslatedResourceIds;
319   }
320
321   // get tosca name from mapping configuration file
322   //element type - parameter/attribute
323   // element name - heat parameter/attribute name
324   //return value - tosca parameter/attribute name
325   public String getElementMapping(String resourceType, String elementType, String elementName) {
326     if (Objects.isNull(translationMapping.get(resourceType))) {
327       return null;
328     }
329     if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
330       return null;
331     }
332     return translationMapping.get(resourceType).get(elementType).get(elementName);
333   }
334
335   public Map<String, String> getElementMapping(String resourceType, String elementType) {
336     if (Objects.isNull(translationMapping.get(resourceType))) {
337       return null;
338     }
339     return translationMapping.get(resourceType).get(elementType);
340   }
341
342   public Set<String> getElementSet(String resourceType, String elementType) {
343     if (Objects.isNull(translationMapping.get(resourceType))) {
344       return new HashSet<>();
345     }
346     if (Objects.isNull(translationMapping.get(resourceType).get(elementType))) {
347       return new HashSet<>();
348     }
349     return translationMapping.get(resourceType).get(elementType).keySet();
350   }
351
352   public Map<String, ServiceTemplate> getTranslatedServiceTemplates() {
353     return translatedServiceTemplates;
354   }
355
356   public ServiceTemplate getGlobalSubstitutionServiceTemplate() {
357     return getTranslatedServiceTemplates().get(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
358   }
359
360   public FileContentHandler getExternalArtifacts() {
361     return externalArtifacts;
362   }
363
364   public void addExternalArtifacts(String name, byte[] content) {
365     this.externalArtifacts.addFile(name, content);
366   }
367
368   public Map<String, TranslatedHeatResource> getHeatSharedResourcesByParam() {
369     return heatSharedResourcesByParam;
370   }
371
372   public void addHeatSharedResourcesByParam(String parameterName, String resourceId,
373                                             Resource resource) {
374     this.addHeatSharedResourcesByParam(parameterName,
375         new TranslatedHeatResource(resourceId, resource));
376   }
377
378   private void addHeatSharedResourcesByParam(String parameterName,
379                                              TranslatedHeatResource translatedHeatResource) {
380     this.heatSharedResourcesByParam.put(parameterName, translatedHeatResource);
381   }
382
383   public Map<String, ServiceTemplate> getGlobalServiceTemplates() {
384     return globalServiceTemplates;
385   }
386
387   public Map<String, String> getNestedHeatFileName() {
388     return nestedHeatFileName;
389   }
390
391   public void addNestedHeatFileName(String substituteServiceTempalteName,
392                                     String nestedHeatFileName) {
393     this.nestedHeatFileName.put(substituteServiceTempalteName, nestedHeatFileName);
394   }
395
396   public Map<String, Map<String, String>> getUsedHeatPseudoParams() {
397     return usedHeatPseudoParams;
398   }
399
400   public void addUsedHeatPseudoParams(String heatFileName, String heatPseudoParam, String
401       translatedToscaParam) {
402     if (Objects.isNull(this.usedHeatPseudoParams.get(heatFileName))) {
403       this.usedHeatPseudoParams.put(heatFileName, new HashMap<>());
404     }
405     this.usedHeatPseudoParams.get(heatFileName).put(heatPseudoParam, translatedToscaParam);
406   }
407
408   public Set<String> getTranslatedResourceIdsFromOtherFiles(String fileNameToIgnore){
409     if(MapUtils.isEmpty(this.translatedResources)){
410       return new HashSet<>();
411     }
412
413     Set<String> translatedResourceIds = new HashSet<>();
414
415     this.translatedResources.entrySet().stream().filter(entry -> !entry.getKey().equals(fileNameToIgnore))
416         .forEach(entry -> translatedResourceIds.addAll(entry.getValue()));
417
418     return translatedResourceIds;
419   }
420
421   /**
422    * Add the unified substitution data info in context. Contains a mapping of original node
423    * template id and the new node template id in the abstract substitute
424    *
425    * @param serviceTemplateFileName the service template file name
426    * @param originalNodeTemplateId  the original node template id
427    * @param abstractNodeTemplateId  the node template id in the abstract substitute
428    */
429   public void addUnifiedSubstitutionData(String serviceTemplateFileName,
430                                          String originalNodeTemplateId,
431                                          String abstractNodeTemplateId) {
432
433     Map<String, String> nodeAbstractNodeTemplateIdMap = this.getUnifiedSubstitutionData()
434         .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
435         .getNodesRelatedAbstractNode();
436
437     if (nodeAbstractNodeTemplateIdMap == null) {
438       nodeAbstractNodeTemplateIdMap = new HashMap<>();
439     }
440
441     if(nodeAbstractNodeTemplateIdMap.containsKey(originalNodeTemplateId)){
442       throw new CoreException(new DuplicateResourceIdsInDifferentFilesErrorBuilder(originalNodeTemplateId).build());
443     }
444     nodeAbstractNodeTemplateIdMap.put(originalNodeTemplateId, abstractNodeTemplateId);
445     this.getUnifiedSubstitutionData().get(serviceTemplateFileName).setNodesRelatedAbstractNode(
446         nodeAbstractNodeTemplateIdMap);
447   }
448
449   /**
450    * Add the unified substitution data info in context. Contains a mapping of original node
451    * template id and the new node template id in the abstract substitute
452    *
453    * @param serviceTemplateFileName                   the service template file name
454    * @param originalNodeTemplateId                    the original node template id
455    * @param substitutionServiceTemplateNodeTemplateId the node template id in the substitution
456    *                                                  service template
457    */
458   public void addSubstitutionServiceTemplateUnifiedSubstitutionData(
459       String serviceTemplateFileName,
460       String originalNodeTemplateId,
461       String substitutionServiceTemplateNodeTemplateId) {
462
463     Map<String, String> nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = this
464         .getUnifiedSubstitutionData()
465         .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData())
466         .getNodesRelatedSubstitutionServiceTemplateNode();
467
468     if (nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap == null) {
469       nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = new HashMap<>();
470     }
471     nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap.put(originalNodeTemplateId,
472         substitutionServiceTemplateNodeTemplateId);
473     this.getUnifiedSubstitutionData().get(serviceTemplateFileName)
474         .setNodesRelatedSubstitutionServiceTemplateNode(
475             nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap);
476   }
477
478   /**
479    * Get unified abstract node template which is mapped to the input node template id.
480    *
481    * @param serviceTemplate the service template
482    * @param nodeTemplateId  the node template id
483    */
484   public String getUnifiedAbstractNodeTemplateId(ServiceTemplate serviceTemplate,
485                                                  String nodeTemplateId) {
486     UnifiedSubstitutionData unifiedSubsData =
487         this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate));
488     return unifiedSubsData.getNodesRelatedAbstractNode().get(nodeTemplateId);
489   }
490
491   /**
492    * Get unified node template in the substitution service template which is mapped to the
493    * original input node template id.
494    *
495    * @param serviceTemplate the service template
496    * @param nodeTemplateId  the node template id
497    */
498   public String getUnifiedSubstitutionNodeTemplateId(ServiceTemplate serviceTemplate,
499                                                      String nodeTemplateId) {
500     UnifiedSubstitutionData unifiedSubsData =
501         this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate));
502     return unifiedSubsData.getNodesRelatedSubstitutionServiceTemplateNode()
503         .get(nodeTemplateId);
504   }
505
506   public int getHandledNestedComputeNodeTemplateIndex(String serviceTemplateName,
507                                                       String computeType) {
508     return this.unifiedSubstitutionData.get(serviceTemplateName)
509         .getHandledNestedComputeNodeTemplateIndex(computeType);
510   }
511
512   public void updateHandledComputeType(String serviceTemplateName,
513                                        String handledComputeType,
514                                        String nestedServiceTemplateFileName) {
515     String globalSTName =
516         ToscaUtil.getServiceTemplateFileName(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME);
517     this.unifiedSubstitutionData.putIfAbsent(
518         globalSTName, new UnifiedSubstitutionData());
519     this.unifiedSubstitutionData.get(globalSTName)
520         .addHandledComputeType(handledComputeType);
521     this.unifiedSubstitutionData.get(globalSTName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
522
523     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
524     this.unifiedSubstitutionData.get(serviceTemplateName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName);
525   }
526
527   public void addHandledComputeTypeInServiceTemplate(String serviceTemplateName,
528                                                      String handledComputeType){
529     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
530     this.unifiedSubstitutionData.get(serviceTemplateName).addHandledComputeType(handledComputeType);
531   }
532
533   public boolean isComputeTypeHandledInServiceTemplate(String serviceTemplateName,
534                                                        String computeType) {
535     return !Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))
536         && this.unifiedSubstitutionData.get(serviceTemplateName)
537         .isComputeTypeHandledInServiceTemplate(computeType);
538   }
539
540   public boolean isNestedServiceTemplateWasHandled(String serviceTemplateName,
541                                                    String nestedServiceTemplateFileName) {
542     if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
543       return false;
544     }
545     return this.unifiedSubstitutionData.get(serviceTemplateName)
546         .isNestedServiceTemplateWasHandled(nestedServiceTemplateFileName);
547   }
548
549   public Set<String> getAllRelatedNestedNodeTypeIds() {
550     String globalName = "GlobalSubstitutionTypes";
551     if (Objects.isNull(this.unifiedSubstitutionData)
552         || Objects.isNull(this.unifiedSubstitutionData.get(globalName))) {
553       return new HashSet<>();
554     }
555
556     return this.unifiedSubstitutionData.get(globalName).getAllRelatedNestedNodeTypeIds();
557   }
558
559   public boolean isUnifiedHandledServiceTemplate(ServiceTemplate serviceTemplate) {
560     String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
561     if (unifiedHandledServiceTemplates.contains(serviceTemplateFileName)) {
562       return true;
563     }
564     return false;
565   }
566
567
568
569   public void addUnifiedHandledServiceTeamplte(ServiceTemplate serviceTemplate) {
570     String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
571     this.unifiedHandledServiceTemplates.add(serviceTemplateFileName);
572   }
573
574   public boolean isNestedNodeWasHandled(String serviceTemplateName,
575                                         String nestedNodeTemplateId) {
576     if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
577       return false;
578     }
579     return this.unifiedSubstitutionData.get(serviceTemplateName)
580         .isNestedNodeWasHandled(nestedNodeTemplateId);
581   }
582
583   public void addNestedNodeAsHandled(String serviceTemplateName,
584                                      String nestedNodeTemplateId) {
585     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
586     this.unifiedSubstitutionData.get(serviceTemplateName)
587         .addHandledNestedNodes(nestedNodeTemplateId);
588   }
589
590   public void updateUsedTimesForNestedComputeNodeType(String serviceTemplateName,
591                                                       String computeType) {
592     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
593
594     this.unifiedSubstitutionData.get(serviceTemplateName)
595         .updateUsedTimesForNestedComputeNodeType(computeType);
596   }
597
598   public int getGlobalNodeTypeIndex(String serviceTemplateName,
599                                     String computeType) {
600     if (Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))) {
601       return 0;
602     }
603     return this.unifiedSubstitutionData.get(serviceTemplateName).getGlobalNodeTypeIndex
604         (computeType);
605   }
606
607   public void addNewPropertyIdToNodeTemplate(String serviceTemplateName,
608                                              String newPropertyId,
609                                              Object origPropertyValue){
610     this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData());
611     this.unifiedSubstitutionData.get(serviceTemplateName).addNewPropertyIdToNodeTemplate(
612         newPropertyId, origPropertyValue);
613   }
614
615   public Optional<Object> getNewPropertyInputParamId(String serviceTemplateName,
616                                                      String newPropertyId){
617     if(Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))){
618       return Optional.empty();
619     }
620
621     return this.unifiedSubstitutionData.get(serviceTemplateName).getNewPropertyInputParam
622         (newPropertyId);
623   }
624
625   public Map<String, Object> getAllNewPropertyInputParamIdsPerNodeTenplateId(String serviceTemplateName){
626     if(Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName))){
627       return new HashMap<>();
628     }
629
630     return this.unifiedSubstitutionData.get(serviceTemplateName).getAllNewPropertyInputParamIds();
631
632   }
633
634   public boolean isServiceTemplateWithoutNodeTemplatesSection(String serviceTemplateName){
635     return Objects.nonNull(serviceTemplateName)
636           && serviceTemplatesWithoutNodeTemplateSection.contains(serviceTemplateName);
637   }
638
639   public void addServiceTemplateWithoutNodeTemplates(String serviceTemplateName){
640     this.serviceTemplatesWithoutNodeTemplateSection.add(serviceTemplateName);
641   }
642
643   public void addNestedNodeTemplateIdPointsToStWithoutNodeTemplates(String nodeTemplateId){
644     this.nodeTemplateIdsPointingToStWithoutNodeTemplates.add(nodeTemplateId);
645   }
646
647   public boolean isNodeTemplateIdPointsToStWithoutNodeTemplates(String nodeTemplateId){
648     return Objects.nonNull(nodeTemplateId)
649         && nodeTemplateIdsPointingToStWithoutNodeTemplates.contains(nodeTemplateId);
650   }
651
652   public void updateRequirementAssignmentIdIndex(String serviceTemplateName,
653                                                  String nodeTemplateId,
654                                                  String requirementId){
655     requirementIdAppearanceInNodeTemplate.putIfAbsent(serviceTemplateName, new HashMap<>());
656     requirementIdAppearanceInNodeTemplate
657         .get(serviceTemplateName).putIfAbsent(nodeTemplateId, new HashMap<>());
658
659     Map<String, Integer> requirementIdToAppearance =
660         requirementIdAppearanceInNodeTemplate.get(serviceTemplateName).get(nodeTemplateId);
661
662     if(requirementIdToAppearance.containsKey(requirementId)){
663       requirementIdToAppearance
664           .put(requirementId, requirementIdToAppearance.get(requirementId) + 1);
665     } else {
666       requirementIdToAppearance.put(requirementId, 0);
667     }
668   }
669
670 }