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