update SDC-TOSCA package names
[sdc/sdc-tosca.git] / src / main / java / org / onap / sdc / tosca / parser / impl / SdcCsarHelperImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * sdc-distribution-client
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.onap.sdc.tosca.parser.impl;
22
23 import java.util.*;
24 import java.util.Map.Entry;
25 import java.util.stream.Collectors;
26
27 import org.apache.commons.lang3.tuple.ImmutablePair;
28 import org.apache.commons.lang3.tuple.Pair;
29 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
30 import org.onap.sdc.tosca.parser.config.ConfigurationManager;
31 import org.onap.sdc.tosca.parser.utils.GeneralUtility;
32 import org.onap.sdc.tosca.parser.utils.SdcToscaUtility;
33 import org.onap.sdc.toscaparser.api.*;
34 import org.onap.sdc.toscaparser.api.elements.Metadata;
35 import org.onap.sdc.toscaparser.api.elements.NodeType;
36 import org.onap.sdc.toscaparser.api.functions.Function;
37 import org.onap.sdc.toscaparser.api.parameters.Input;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 public class SdcCsarHelperImpl implements ISdcCsarHelper {
42
43     private static final String PATH_DELIMITER = "#";
44     private static final String CUSTOMIZATION_UUID = "customizationUUID";
45     private ToscaTemplate toscaTemplate;
46     private ConfigurationManager configurationManager;
47     private static Logger log = LoggerFactory.getLogger(SdcCsarHelperImpl.class.getName());
48
49     public SdcCsarHelperImpl(ToscaTemplate toscaTemplate) {
50         this.toscaTemplate = toscaTemplate;
51     }
52
53     public SdcCsarHelperImpl(ToscaTemplate toscaTemplate, ConfigurationManager configurationManager) {
54         this.toscaTemplate = toscaTemplate;
55         this.configurationManager = configurationManager;
56     }
57
58     @Override
59     //Sunny flow  - covered with UT, flat and nested
60     public String getNodeTemplatePropertyLeafValue(NodeTemplate nodeTemplate, String leafValuePath) {
61         if (nodeTemplate == null) {
62             log.error("getNodeTemplatePropertyLeafValue - nodeTemplate is null");
63             return null;
64         }
65         if (GeneralUtility.isEmptyString(leafValuePath)) {
66             log.error("getNodeTemplatePropertyLeafValue - leafValuePath is null or empty");
67             return null;
68         }
69         String[] split = getSplittedPath(leafValuePath);
70         LinkedHashMap<String, Property> properties = nodeTemplate.getProperties();
71         Object property = processProperties(split, properties);
72         return property == null || property instanceof Function ? null : String.valueOf(property);
73     }
74
75     @Override
76     public Object getNodeTemplatePropertyAsObject(NodeTemplate nodeTemplate, String leafValuePath) {
77         if (nodeTemplate == null) {
78             log.error("getNodeTemplatePropertyAsObject - nodeTemplate is null");
79             return null;
80         }
81         if (GeneralUtility.isEmptyString(leafValuePath)) {
82             log.error("getNodeTemplatePropertyAsObject - leafValuePath is null or empty");
83             return null;
84         }
85         String[] split = getSplittedPath(leafValuePath);
86         LinkedHashMap<String, Property> properties = nodeTemplate.getProperties();
87         return processProperties(split, properties);
88     }
89     
90     public Map<String, Map<String, Object>> getCpPropertiesFromVfcAsObject(NodeTemplate vfc) {
91         if (vfc == null) {
92             log.error("getCpPropertiesFromVfc - vfc is null");
93             return new HashMap<>();
94         }
95
96         String presetProperty = "_ip_requirements";
97         Map<String, Map<String, Object>> cps = new HashMap<>();
98
99         Map<String, Property> props = vfc.getProperties();
100         if (props != null) {
101             // find all port names by pre-set property (ip_requirements)
102             for (Map.Entry<String, Property> entry : props.entrySet()) {
103                 if (entry.getKey().endsWith(presetProperty)) {
104                     String portName = entry.getKey().replaceAll(presetProperty, "");
105                     cps.put(portName, new HashMap<>());
106                 }
107             }
108
109             if (cps.size() > 0) {
110                 // ports found - find all their properties
111                 for (String portName : cps.keySet()) {
112                     for (Map.Entry<String, Property> property: props.entrySet()) {
113                         if (property.getKey().startsWith(portName)) {
114                             String portProperty = property.getKey().replaceFirst(portName + "_", "");
115                             if (property.getValue() != null) {
116                                 cps.get(portName).put(portProperty, property.getValue().getValue());
117                             }
118                         }
119                     }
120                 }
121             }
122         }
123
124         return cps;
125     }
126
127     public Map<String, Map<String, Object>> getCpPropertiesFromVfc(NodeTemplate vfc) {
128
129         if (vfc == null) {
130             log.error("getCpPropertiesFromVfc - vfc is null");
131             return new HashMap<>();
132         }
133
134         String presetProperty = "_ip_requirements";
135         Map<String, Map<String, Object>> cps = new HashMap<>();
136
137         Map<String, Property> props = vfc.getProperties();
138         if (props != null) {
139             // find all port names by pre-set property (ip_requirements)
140             for (Map.Entry<String, Property> entry : props.entrySet()) {
141                 if (entry.getKey().endsWith(presetProperty)) {
142                     String portName = entry.getKey().replaceAll(presetProperty, "");
143                     cps.put(portName, new HashMap<>());
144                 }
145             }
146
147             if (cps.size() > 0) {
148                 // ports found - find all their properties
149                 for (String portName : cps.keySet()) {
150                     for (Map.Entry<String, Property> property: props.entrySet()) {
151                         if (property.getKey().startsWith(portName)) {
152                             Map<String, Object> portPaths = new HashMap<>();
153                             String portProperty = property.getKey().replaceFirst(portName + "_", "");
154                             buildPathMappedToValue(portProperty, property.getValue().getValue(), portPaths);
155
156                             cps.get(portName).putAll(portPaths);
157                         }
158                     }
159                 }
160             }
161         }
162
163         return cps;
164     }
165
166     @SuppressWarnings("unchecked")
167     private void buildPathMappedToValue(String path, Object property, Map<String, Object> pathsMap) {
168         if (property instanceof Map) {
169             for (Map.Entry<String, Object> item : ((Map<String, Object>) property).entrySet()) {
170                 if (item.getValue() instanceof Map || item.getValue() instanceof List) {
171                     buildPathMappedToValue(path + PATH_DELIMITER + item.getKey(), item.getValue(), pathsMap);
172                 } else {
173                     pathsMap.put(path + PATH_DELIMITER + item.getKey(), item.getValue());
174                 }
175             }
176         } else if (property instanceof List) {
177             for (Object item: (List<Object>)property) {
178                 buildPathMappedToValue(path, item, pathsMap);
179             }
180         } else {
181             pathsMap.put(path, property);
182         }
183
184     }
185
186     @Override
187     //Sunny flow - covered with UT
188     public List<NodeTemplate> getServiceVlList() {
189         List<NodeTemplate> serviceVlList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VL);
190         return serviceVlList;
191     }
192
193     @Override
194     //Sunny flow - covered with UT
195     public List<NodeTemplate> getServiceVfList() {
196         List<NodeTemplate> serviceVfList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VF);
197         return serviceVfList;
198     }
199
200     @Override
201     //Sunny flow - covered with UT
202     public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName) {
203         if (GeneralUtility.isEmptyString(metadataPropertyName)) {
204             log.error("getMetadataPropertyValue - the metadataPropertyName is null or empty");
205             return null;
206         }
207         if (metadata == null) {
208             log.error("getMetadataPropertyValue - the metadata is null");
209             return null;
210         }
211         String metadataPropertyValue = metadata.getValue(metadataPropertyName);
212         return metadataPropertyValue;
213     }
214
215
216     @Override
217     //Sunny flow - covered with UT
218     public List<NodeTemplate> getServiceNodeTemplatesByType(String nodeType) {
219         if (GeneralUtility.isEmptyString(nodeType)) {
220             log.error("getServiceNodeTemplatesByType - nodeType - is null or empty");
221             return new ArrayList<>();
222         }
223
224         List<NodeTemplate> res = new ArrayList<>();
225         List<NodeTemplate> nodeTemplates = toscaTemplate.getNodeTemplates();
226         for (NodeTemplate nodeTemplate : nodeTemplates) {
227             if (nodeType.equals(nodeTemplate.getTypeDefinition().getType())) {
228                 res.add(nodeTemplate);
229             }
230         }
231
232         return res;
233     }
234
235
236     @Override
237     public List<NodeTemplate> getServiceNodeTemplates() {
238         List<NodeTemplate> nodeTemplates = toscaTemplate.getNodeTemplates();
239         return nodeTemplates;
240     }
241
242     @Override
243     //Sunny flow - covered with UT
244     public List<NodeTemplate> getVfcListByVf(String vfCustomizationId) {
245         if (GeneralUtility.isEmptyString(vfCustomizationId)) {
246             log.error("getVfcListByVf - vfCustomizationId - is null or empty");
247             return new ArrayList<>();
248         }
249
250         List<NodeTemplate> serviceVfList = getServiceVfList();
251         NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId);
252         List<NodeTemplate> vfcs = getNodeTemplateBySdcType(vfInstance, SdcTypes.VFC);
253         vfcs.addAll(getNodeTemplateBySdcType(vfInstance, SdcTypes.CVFC));
254
255         return vfcs;
256     }
257
258     @Override
259     //Sunny flow - covered with UT
260     public List<Group> getVfModulesByVf(String vfCustomizationUuid) {
261         List<NodeTemplate> serviceVfList = getServiceVfList();
262         NodeTemplate nodeTemplateByCustomizationUuid = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid);
263         if (nodeTemplateByCustomizationUuid != null) {
264             /*SubstitutionMappings substitutionMappings = nodeTemplateByCustomizationUuid.getSubstitutionMappings();
265                         if (substitutionMappings != null){
266                                 List<Group> groups = substitutionMappings.getGroups();
267                                 if (groups != null){
268                                         List<Group> collect = groups.stream().filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType())).collect(Collectors.toList());
269                                         log.debug("getVfModulesByVf - VfModules are {}", collect);
270                                         return collect;
271                                 }
272                         }*/
273             String name = nodeTemplateByCustomizationUuid.getName();
274             String normaliseComponentInstanceName = SdcToscaUtility.normaliseComponentInstanceName(name);
275             List<Group> serviceLevelGroups = toscaTemplate.getTopologyTemplate().getGroups();
276             log.debug("getVfModulesByVf - VF node template name {}, normalized name {}. Searching groups on service level starting with VF normalized name...", name, normaliseComponentInstanceName);
277             if (serviceLevelGroups != null) {
278                 List<Group> collect = serviceLevelGroups
279                         .stream()
280                         .filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType()) && x.getName().startsWith(normaliseComponentInstanceName))
281                         .collect(Collectors.toList());
282                 return collect;
283             }
284         }
285         return new ArrayList<>();
286     }
287
288     @Override
289     //Sunny flow - covered with UT
290     public String getServiceInputLeafValueOfDefault(String inputLeafValuePath) {
291         if (GeneralUtility.isEmptyString(inputLeafValuePath)) {
292             log.error("getServiceInputLeafValueOfDefault - inputLeafValuePath is null or empty");
293             return null;
294         }
295
296         String[] split = getSplittedPath(inputLeafValuePath);
297         if (split.length < 2 || !split[1].equals("default")) {
298             log.error("getServiceInputLeafValue - inputLeafValuePath should be of format <input name>#default[optionally #<rest of path>] ");
299             return null;
300         }
301
302         List<Input> inputs = toscaTemplate.getInputs();
303         if (inputs != null) {
304             Optional<Input> findFirst = inputs.stream().filter(x -> x.getName().equals(split[0])).findFirst();
305             if (findFirst.isPresent()) {
306                 Input input = findFirst.get();
307                 Object current = input.getDefault();
308                 Object property = iterateProcessPath(2, current, split);
309                 return property == null || property instanceof Function? null : String.valueOf(property);
310             }
311         }
312         log.error("getServiceInputLeafValue - value not found");
313         return null;
314     }
315
316     @Override
317     public Object getServiceInputLeafValueOfDefaultAsObject(String inputLeafValuePath) {
318         if (GeneralUtility.isEmptyString(inputLeafValuePath)) {
319             log.error("getServiceInputLeafValueOfDefaultAsObject - inputLeafValuePath is null or empty");
320             return null;
321         }
322
323         String[] split = getSplittedPath(inputLeafValuePath);
324         if (split.length < 2 || !split[1].equals("default")) {
325             log.error("getServiceInputLeafValueOfDefaultAsObject - inputLeafValuePath should be of format <input name>#default[optionally #<rest of path>] ");
326             return null;
327         }
328
329         List<Input> inputs = toscaTemplate.getInputs();
330         if (inputs != null) {
331             Optional<Input> findFirst = inputs.stream().filter(x -> x.getName().equals(split[0])).findFirst();
332             if (findFirst.isPresent()) {
333                 Input input = findFirst.get();
334                 Object current = input.getDefault();
335                 return iterateProcessPath(2, current, split);
336             }
337         }
338         log.error("getServiceInputLeafValueOfDefaultAsObject - value not found");
339         return null;
340     }
341
342     @SuppressWarnings({ "unchecked", "rawtypes" })
343     private Object iterateProcessPath(Integer index, Object current, String[] split) {
344         if (current == null) {
345             log.error("iterateProcessPath - this input has no default");
346             return null;
347         }
348         if (split.length > index) {
349             for (int i = index; i < split.length; i++) {
350                 if (current instanceof Map) {
351                     current = ((Map<String, Object>) current).get(split[i]);
352                 } else if (current instanceof List) {
353                     current = ((List) current).get(0);
354                     i--;
355                 }
356                  else {
357                         log.error("iterateProcessPath - found an unexpected leaf where expected to find a complex type");
358                         return null;
359                 }
360             }
361         }
362         if (current != null) {
363             return current;
364         }
365         log.error("iterateProcessPath - Path not Found");
366         return null;
367     }
368
369     private String[] getSplittedPath(String inputLeafValuePath) {
370         return inputLeafValuePath.split(PATH_DELIMITER);
371     }
372
373
374     @Override
375     //Sunny flow - covered with UT
376     public String getServiceSubstitutionMappingsTypeName() {
377         SubstitutionMappings substitutionMappings = toscaTemplate.getTopologyTemplate().getSubstitutionMappings();
378         if (substitutionMappings == null) {
379             log.debug("getServiceSubstitutionMappingsTypeName - No Substitution Mappings defined");
380             return null;
381         }
382
383         NodeType nodeType = substitutionMappings.getNodeDefinition();
384         if (nodeType == null) {
385             log.debug("getServiceSubstitutionMappingsTypeName - No Substitution Mappings node defined");
386             return null;
387         }
388
389         return nodeType.getType();
390     }
391
392     @Override
393     //Sunny flow - covered with UT
394     public Metadata getServiceMetadata() {
395         return toscaTemplate.getMetaData();
396     }
397
398     @Override
399     //Sunny flow - covered with UT
400     public Map<String, Object> getServiceMetadataProperties() {
401         if (toscaTemplate.getMetaData() == null){
402             return null;
403         }
404         return new HashMap<>(toscaTemplate.getMetaData().getAllProperties());
405     }
406
407     @Override
408     public Map<String, String> getServiceMetadataAllProperties() {
409         if (toscaTemplate.getMetaData() == null){
410             return null;
411         }
412         return toscaTemplate.getMetaData().getAllProperties();
413     }
414
415     @Override
416     //Sunny flow - covered with UT
417     public List<Input> getServiceInputs() {
418         return toscaTemplate.getInputs();
419     }
420
421     @Override
422     //Sunny flow - covered with UT
423     public String getGroupPropertyLeafValue(Group group, String leafValuePath) {
424         if (group == null) {
425             log.error("getGroupPropertyLeafValue - group is null");
426             return null;
427         }
428
429         if (GeneralUtility.isEmptyString(leafValuePath)) {
430             log.error("getGroupPropertyLeafValue - leafValuePath is null or empty");
431             return null;
432         }
433
434         String[] split = getSplittedPath(leafValuePath);
435         LinkedHashMap<String, Property> properties = group.getProperties();
436         Object property = processProperties(split, properties);
437         return property == null || property instanceof Function? null : String.valueOf(property);
438     }
439
440     @Override
441     public Object getGroupPropertyAsObject(Group group, String leafValuePath) {
442         if (group == null) {
443             log.error("getGroupPropertyAsObject - group is null");
444             return null;
445         }
446
447         if (GeneralUtility.isEmptyString(leafValuePath)) {
448             log.error("getGroupPropertyAsObject - leafValuePath is null or empty");
449             return null;
450         }
451
452         String[] split = getSplittedPath(leafValuePath);
453         LinkedHashMap<String, Property> properties = group.getProperties();
454         return processProperties(split, properties);
455     }
456
457     @Override
458     //Sunny flow - covered with UT
459     public List<NodeTemplate> getCpListByVf(String vfCustomizationId) {
460         List<NodeTemplate> cpList = new ArrayList<>();
461         if (GeneralUtility.isEmptyString(vfCustomizationId)) {
462             log.error("getCpListByVf vfCustomizationId string is empty");
463             return cpList;
464         }
465
466         List<NodeTemplate> serviceVfList = getServiceVfList();
467         if (serviceVfList == null || serviceVfList.size() == 0) {
468             log.error("getCpListByVf Vfs not exist for vfCustomizationId {}", vfCustomizationId);
469             return cpList;
470         }
471         NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId);
472         if (vfInstance == null) {
473             log.debug("getCpListByVf vf list is null");
474             return cpList;
475         }
476         cpList = getNodeTemplateBySdcType(vfInstance, SdcTypes.CP);
477         if (cpList == null || cpList.size() == 0)
478             log.debug("getCpListByVf cps not exist for vfCustomizationId {}", vfCustomizationId);
479         return cpList;
480     }
481
482     @Override
483     //Sunny flow - covered with UT
484     public List<NodeTemplate> getMembersOfVfModule(NodeTemplate vf, Group serviceLevelVfModule) {
485         if (vf == null) {
486             log.error("getMembersOfVfModule - vf is null");
487             return new ArrayList<>();
488         }
489
490         if (serviceLevelVfModule == null || serviceLevelVfModule.getMetadata() == null || serviceLevelVfModule.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID) == null) {
491             log.error("getMembersOfVfModule - vfModule or its metadata is null. Cannot match a VF group based on invariantUuid from missing metadata.");
492             return new ArrayList<>();
493         }
494
495
496         SubstitutionMappings substitutionMappings = vf.getSubMappingToscaTemplate();
497         if (substitutionMappings != null) {
498             List<Group> groups = substitutionMappings.getGroups();
499             if (groups != null) {
500                 Optional<Group> findFirst = groups
501                         .stream()
502                         .filter(x -> (x.getMetadata() != null && serviceLevelVfModule.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID).equals(x.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)))).findFirst();
503                 if (findFirst.isPresent()) {
504                     List<String> members = findFirst.get().getMembers();
505                     if (members != null) {
506                         List<NodeTemplate> collect = substitutionMappings.getNodeTemplates().stream().filter(x -> members.contains(x.getName())).collect(Collectors.toList());
507                         return collect;
508                     }
509                 }
510             }
511         }
512         return new ArrayList<>();
513     }
514
515     @Override
516     //Sunny flow - covered with UT
517     @SuppressWarnings("unchecked")
518     public List<Pair<NodeTemplate, NodeTemplate>> getNodeTemplatePairsByReqName(
519             List<NodeTemplate> listOfReqNodeTemplates, List<NodeTemplate> listOfCapNodeTemplates, String reqName) {
520
521         if (listOfReqNodeTemplates == null) {
522             log.error("getNodeTemplatePairsByReqName - listOfReqNodeTemplates is null");
523             return new ArrayList<>();
524         }
525
526         if (listOfCapNodeTemplates == null) {
527             log.error("getNodeTemplatePairsByReqName - listOfCapNodeTemplates is null");
528             return new ArrayList<>();
529         }
530
531         if (GeneralUtility.isEmptyString(reqName)) {
532             log.error("getNodeTemplatePairsByReqName - reqName is null or empty");
533             return new ArrayList<>();
534         }
535
536         List<Pair<NodeTemplate, NodeTemplate>> pairsList = new ArrayList<>();
537
538         for (NodeTemplate reqNodeTemplate : listOfReqNodeTemplates) {
539             List<RequirementAssignment> requirements = reqNodeTemplate.getRequirements().getRequirementsByName(reqName).getAll();
540             for (RequirementAssignment reqEntry : requirements) {
541                 String node = reqEntry.getNodeTemplateName();
542                 if (node != null) {
543                     Optional<NodeTemplate> findFirst = listOfCapNodeTemplates.stream().filter(x -> x.getName().equals(node)).findFirst();
544                     if (findFirst.isPresent()) {
545                         pairsList.add(new ImmutablePair<NodeTemplate, NodeTemplate>(reqNodeTemplate, findFirst.get()));
546                     }
547                 }
548             }
549         }
550
551         return pairsList;
552     }
553
554     @Override
555     //Sunny flow - covered with UT
556     //TODO constant strings
557     public List<NodeTemplate> getAllottedResources() {
558         List<NodeTemplate> nodeTemplates = null;
559         nodeTemplates = toscaTemplate.getTopologyTemplate().getNodeTemplates();
560         if (nodeTemplates.isEmpty()) {
561             log.error("getAllottedResources nodeTemplates not exist");
562         }
563         nodeTemplates = nodeTemplates.stream().filter(
564                 x -> x.getMetaData() != null && x.getMetaData().getValue("category").equals("Allotted Resource"))
565                 .collect(Collectors.toList());
566         if (nodeTemplates.isEmpty()) {
567             log.debug("getAllottedResources -  allotted resources not exist");
568         } else {
569         }
570
571         return nodeTemplates;
572     }
573
574     @Override
575     //Sunny flow - covered with UT
576     public String getTypeOfNodeTemplate(NodeTemplate nodeTemplate) {
577         if (nodeTemplate == null) {
578
579             log.error("getTypeOfNodeTemplate nodeTemplate is null");
580             return null;
581         }
582         return nodeTemplate.getTypeDefinition().getType();
583     }
584
585     /**
586      * This methdd is returning the csarConformanceLevel for input CSAR
587      * When csarConformanceLevel is configured with failOnError as False in Error Configuration; it
588      * assigns the default value to csarConformanceLevel which is the max level provided in
589      * Configuration file
590      * @return csarConformanceLevel
591      */
592     @Override
593     public String getConformanceLevel() {
594       LinkedHashMap<String, Object> csarMeta = toscaTemplate.getMetaProperties("csar.meta");
595       if (csarMeta == null){
596         log.warn("No csar.meta file is found in CSAR - this file should hold the conformance level of the CSAR. This might be OK for older CSARs.");
597         if (configurationManager != null && !configurationManager.getErrorConfiguration()
598             .getErrorInfo("CONFORMANCE_LEVEL_ERROR").getFailOnError()){
599           String csarConLevel = configurationManager.getConfiguration().getConformanceLevel().getMaxVersion();
600           log.warn("csarConformanceLevel is not found in input csar; defaulting to max version {}" , csarConLevel);
601           return csarConLevel;
602         }
603         else {
604           log.warn("csarConformanceLevel is not found in input csar; returning null as no defaults defined in error configuration");
605           return null;
606         }
607       }
608
609       Object conformanceLevel = csarMeta.get("SDC-TOSCA-Definitions-Version");
610       if (conformanceLevel != null){
611         String confLevelStr = conformanceLevel.toString();
612         log.debug("CSAR conformance level is {}", confLevelStr);
613         return confLevelStr;
614       } else {
615         log.error("Invalid csar.meta file - no entry found for SDC-TOSCA-Definitions-Version key. This entry should hold the conformance level.");
616         return null;
617       }
618     }
619         
620         
621         @Override
622         public String getNodeTemplateCustomizationUuid(NodeTemplate nt) {
623                 String res = null;
624                 if (nt != null && nt.getMetaData() != null){
625                         res = nt.getMetaData().getValue(CUSTOMIZATION_UUID);
626                 } else {
627                         log.error("Node template or its metadata is null");
628                 }
629                 return res;
630         }
631
632     public List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType) {
633         return getNodeTemplateBySdcType(parentNodeTemplate, sdcType, false); 
634     }
635     
636     private List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType, boolean isVNF)  {
637         
638         if (parentNodeTemplate == null) {
639             log.error("getNodeTemplateBySdcType - nodeTemplate is null or empty");
640             return new ArrayList<>();
641         }
642
643         if (sdcType == null) {
644             log.error("getNodeTemplateBySdcType - sdcType is null or empty");
645             return new ArrayList<>();
646         }
647
648         SubstitutionMappings substitutionMappings = parentNodeTemplate.getSubMappingToscaTemplate();
649
650         if (substitutionMappings != null) {
651             List<NodeTemplate> nodeTemplates = substitutionMappings.getNodeTemplates();
652             if (nodeTemplates != null && nodeTemplates.size() > 0) {
653                 if (sdcType.equals(SdcTypes.VFC) && isVNF)  {
654                         return nodeTemplates.stream()
655                                 .filter(x -> (x.getMetaData() != null &&
656                                         sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) &&  isVNFType(x))
657                                 .collect(Collectors.toList());
658                 }
659                 else {
660                     return nodeTemplates.stream()
661                                 .filter(x -> (x.getMetaData() != null &&
662                                         sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) &&  !isVNFType(x))
663                                 .collect(Collectors.toList());
664                 }
665             }
666             else {
667                 log.debug("getNodeTemplateBySdcType - SubstitutionMappings' node Templates not exist");
668             }
669         } else
670             log.debug("getNodeTemplateBySdcType - SubstitutionMappings not exist");
671
672         return new ArrayList<>();
673     }
674
675     public Map<String, String> filterNodeTemplatePropertiesByValue(NodeTemplate nodeTemplate, FilterType filterType, String pattern) {
676         Map<String, String> filterMap = new HashMap<>();
677
678         if (nodeTemplate == null) {
679             log.error("filterNodeTemplatePropertiesByValue nodeTemplate is null");
680             return filterMap;
681         }
682
683         if (filterType == null) {
684             log.error("filterNodeTemplatePropertiesByValue filterType is null");
685             return filterMap;
686         }
687
688         if (GeneralUtility.isEmptyString(pattern)) {
689             log.error("filterNodeTemplatePropertiesByValue pattern string is empty");
690             return filterMap;
691         }
692
693         Map<String, Property> ntProperties = nodeTemplate.getProperties();
694
695         if (ntProperties != null && ntProperties.size() > 0) {
696
697             for (Property current : ntProperties.values()) {
698                 filterProperties(current.getValue(), current.getName(), filterType, pattern, filterMap);
699             }
700         }
701
702         log.trace("filterNodeTemplatePropertiesByValue - filterMap value: {}", filterMap);
703
704         return filterMap;
705     }
706     
707         public NodeTemplate getVnfConfig(String vfCustomizationUuid) {
708                 
709                 if (GeneralUtility.isEmptyString(vfCustomizationUuid)) {
710             log.error("getVnfConfig - vfCustomizationId - is null or empty");
711             return null;
712         }
713
714         List<NodeTemplate> serviceVfList = getServiceVfList();
715         NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid);
716         NodeTemplate vnfConfig = getNodeTemplateBySdcType(vfInstance, SdcTypes.VFC, true).stream().findAny().orElse(null);
717                 return vnfConfig;
718         }
719
720     @Override
721     public boolean hasTopology(NodeTemplate nodeTemplate) {
722         if (nodeTemplate == null) {
723             log.error("hasTopology - nodeTemplate - is null");
724             return false;
725         }
726
727         if (nodeTemplate.getMetaData() != null) {
728             String type = nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE);
729             log.debug("hasTopology - node template {} is a {} type", nodeTemplate.getName(), type);
730             return SdcTypes.isComplex(type);
731         }
732
733         return false;
734     }
735
736     @Override
737     public List<NodeTemplate> getNodeTemplateChildren(NodeTemplate nodeTemplate) {
738         if (nodeTemplate == null) {
739             log.error("getNodeTemplateChildren - nodeTemplate - is null");
740             return new ArrayList<>();
741         }
742
743         SubstitutionMappings substitutionMappings = nodeTemplate.getSubMappingToscaTemplate();
744         if (substitutionMappings != null) {
745             List<NodeTemplate> nodeTemplates = substitutionMappings.getNodeTemplates();
746             if (nodeTemplates != null && nodeTemplates.size() > 0) {
747
748                 return nodeTemplates.stream()
749                         .filter(x -> !isVNFType(x))
750                         .collect(Collectors.toList());
751             }
752             else {
753                 log.debug("getNodeTemplateChildren - SubstitutionMappings' node Templates not exist");
754             }
755         } else
756             log.debug("getNodeTemplateChildren - SubstitutionMappings not exist");
757
758         return new ArrayList<>();
759     }
760
761     @Override
762     public NodeTemplate getServiceNodeTemplateByNodeName(String nodeName) {
763         if (GeneralUtility.isEmptyString(nodeName)) {
764             log.error("getServiceNodeTemplateByNodeName - nodeName - is null or empty");
765             return null;
766         }
767
768         List<NodeTemplate> nodeTemplates = getServiceNodeTemplates();
769         Optional<NodeTemplate> findFirst =  nodeTemplates.stream().filter(nt -> nt.getName().equals(nodeName)).findFirst();
770
771         return findFirst.isPresent() ? findFirst.get() : null;
772     }
773
774     @Override
775     public Metadata getNodeTemplateMetadata(NodeTemplate nt) {
776         if (nt == null) {
777             log.error("getNodeTemplateMetadata - nt (node template) - is null");
778             return null;
779         }
780
781         return nt.getMetaData();
782     }
783
784     @Override
785     public CapabilityAssignments getCapabilitiesOf(NodeTemplate nt) {
786         if (nt == null) {
787             log.error("getCapabilitiesOf - nt (node template) - is null");
788             return null;
789         }
790
791         return nt.getCapabilities();
792     }
793
794     @Override
795     public RequirementAssignments getRequirementsOf(NodeTemplate nt) {
796         if (nt == null) {
797             log.error("getRequirementsOf - nt (node template) - is null");
798             return null;
799         }
800
801         return nt.getRequirements();
802     }
803
804     @Override
805     public String getCapabilityPropertyLeafValue(CapabilityAssignment capability, String pathToPropertyLeafValue) {
806         if (capability == null) {
807             log.error("getCapabilityPropertyLeafValue - capability is null");
808             return null;
809         }
810
811         if (GeneralUtility.isEmptyString(pathToPropertyLeafValue)) {
812             log.error("getCapabilityPropertyLeafValue - pathToPropertyLeafValue is null or empty");
813             return null;
814         }
815
816         String[] split = getSplittedPath(pathToPropertyLeafValue);
817         LinkedHashMap<String, Property> properties = capability.getProperties();
818         Object property = processProperties(split, properties);
819         return property == null || property instanceof Function ? null : String.valueOf(property);
820     }
821
822     /************************************* helper functions ***********************************/
823     private boolean isVNFType(NodeTemplate nt) {
824         return nt.getType().endsWith("VnfConfiguration");
825     }
826
827     @SuppressWarnings("unchecked")
828     private Map<String, String> filterProperties(Object property, String path, FilterType filterType, String pattern, Map<String, String> filterMap) {
829
830         if (property instanceof Map) {
831             for (Map.Entry<String, Object> item: ((Map<String, Object>) property).entrySet()) {
832                 String itemPath = path + PATH_DELIMITER + item.getKey();
833                 filterProperties(item.getValue(), itemPath, filterType, pattern, filterMap);
834             }
835         } else if (property instanceof List) {
836             for (Object item: (List<Object>)property) {
837                 filterProperties(item, path, filterType, pattern, filterMap);
838             }
839         } else {
840             if (filterType.isMatch(property.toString(), pattern)) {
841                 filterMap.put(path, property.toString());
842             }
843         }
844
845         return filterMap;
846     }
847
848     public List<NodeTemplate> getServiceNodeTemplateBySdcType(SdcTypes sdcType) {
849         if (sdcType == null) {
850             log.error("getServiceNodeTemplateBySdcType - sdcType is null or empty");
851             return new ArrayList<>();
852         }
853
854         TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate();
855         return getNodeTemplateBySdcType(topologyTemplate, sdcType);
856     }
857  
858
859     /************************************* helper functions ***********************************/
860     private List<NodeTemplate> getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, SdcTypes sdcType) {
861         if (sdcType == null) {
862             log.error("getNodeTemplateBySdcType - sdcType is null or empty");
863             return new ArrayList<>();
864         }
865
866         if (topologyTemplate == null) {
867             log.error("getNodeTemplateBySdcType - topologyTemplate is null");
868             return new ArrayList<>();
869         }
870
871         List<NodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates();
872
873         if (nodeTemplates != null && nodeTemplates.size() > 0)
874             return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList());
875
876         log.debug("getNodeTemplateBySdcType - topologyTemplate's nodeTemplates not exist");
877         return new ArrayList<>();
878     }
879
880     //Assumed to be unique property for the list
881     private NodeTemplate getNodeTemplateByCustomizationUuid(List<NodeTemplate> nodeTemplates, String customizationId) {
882        if (customizationId != null) {
883             Optional<NodeTemplate> findFirst = nodeTemplates.stream().filter(x -> (x.getMetaData() != null && customizationId.equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)))).findFirst();
884             return findFirst.isPresent() ? findFirst.get() : null;
885         }
886         else {
887             log.error("getNodeTemplateByCustomizationUuid - customizationId is null");
888             return null;
889         }
890     }
891
892     private Object processProperties(String[] split, LinkedHashMap<String, Property> properties) {
893         Optional<Entry<String, Property>> findFirst = properties.entrySet().stream().filter(x -> x.getKey().equals(split[0])).findFirst();
894         if (findFirst.isPresent()) {
895             Property property = findFirst.get().getValue();
896             Object current = property.getValue();
897             return iterateProcessPath(1, current, split);
898         }
899         String propName = (split != null && split.length > 0 ? split[0] : null);
900         log.error("processProperties - property {} not found", propName);
901         return null;
902     }
903
904         
905
906     
907     
908 }