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