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