Update link to Security Vulnerability
[vid.git] / vid-app-common / src / main / java / org / onap / vid / asdc / parser / ToscaParserImpl2.java
1 package org.onap.vid.asdc.parser;
2
3 import org.onap.vid.asdc.beans.Service;
4 import org.onap.vid.model.*;
5 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
6 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
7 import org.onap.sdc.tosca.parser.impl.FilterType;
8 import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
9 import org.onap.sdc.tosca.parser.impl.SdcTypes;
10 import org.onap.sdc.toscaparser.api.Group;
11 import org.onap.sdc.toscaparser.api.*;
12 import org.onap.sdc.toscaparser.api.elements.Metadata;
13 import org.onap.sdc.toscaparser.api.parameters.Input;
14
15 import java.nio.file.Path;
16 import java.util.*;
17 import java.util.stream.Collectors;
18
19 import static java.util.stream.Collectors.toMap;
20 import static org.onap.vid.asdc.parser.ToscaParserImpl2.Constants.VF_MODULE_LABEL;
21
22 public class ToscaParserImpl2 {
23
24     
25         public class Constants {
26                 public final static String UUID = "UUID";
27                 public final static String DESCRIPTION = "description";
28                 public final static String SERVICE_TYPE = "serviceType";
29         public final static String SERVICE_ROLE = "serviceRole";
30         public final static String ECOMP_GENERATED_NAMING = "ecompGeneratedNaming";
31
32         public final static String CUSTOMIZATION_UUID = "customizationUUID";
33                 public final static String VF_MODULE_MODEL_VERSION = "vfModuleModelVersion";
34                 public final static String VF_MODULE_MODEL_CUSTOMIZATION_UUID = "vfModuleModelCustomizationUUID";
35                 public final static String VOLUME_GROUP = "volume_group";
36                 public final static String VF_MODULE_MODEL_INVARIANT_UUID = "vfModuleModelInvariantUUID";
37                 public final static String VF_MODULE_MODEL_UUID = "vfModuleModelUUID";
38                 public final static String INVARIANT_UUID = "invariantUUID";
39                 public final static String VERSION = "version";
40                 public final static String NAME = "name";
41                 public final static String CATEGORY = "category";
42                 public final static String VF_MODULE_MODEL_NAME = "vfModuleModelName";
43                 public final static String GET_INPUT = "get_input";
44                 public final static String TYPE = "type";
45
46                 public final static String INSTANTIATION_TYPE = "instantiationType";
47         //instantiation type
48         public final static String BOTH = "Both";
49         public final static String MACRO = "Macro";
50         public final static String A_LA_CARTE = "A-La-Carte";
51         public final static String CLIENT_CONFIG = "ClientConfig";
52
53         //group properties
54         public final static String MIN_VF_MODULE_INSTANCES = "min_vf_module_instances";
55         public final static String MAX_VF_MODULE_INSTANCES = "max_vf_module_instances";
56         public final static String INITIAL_COUNT = "initial_count";
57         public final static String VF_MODULE_LABEL = "vf_module_label";
58
59         //collection resource properties
60         public final static String SUBCATEGORY = "subcategory";
61         public final static String RESOURCE_VENDOR = "resourceVendor";
62         public final static String RESOURCE_VENDOR_RELEASE = "resourceVendorRelease";
63         public final static String RESOURCE_VENDOR_MODEL_NUMBER = "resourceVendorModelNumber";
64         public final static String ORG_OPENECOMP_GROUPS_NETWORK_COLLECTION = "org.openecomp.groups.NetworkCollection";
65         public final static String NETWORK_COLLECTION_FUNCTION = "network_collection_function";
66         public final static String NETWORK_COLLECTION_DESCRIPTION = "network_collection_description";
67
68         //vfc instance group properties
69         public final static String VFC_INSTANCE_GROUP_TYPE = "org.openecomp.groups.VfcInstanceGroup";
70         public final static String VFC_PARENT_PORT_ROLE = "vfc_parent_port_role";
71         public final static String SUBINTERFACE_ROLE = "subinterface_role";
72         public final static String VFC_INSTANCE_GROUP_FUNCTION = "vfc_instance_group_function";
73     }
74         
75         public ToscaParserImpl2() {}
76
77     public ServiceModel  makeServiceModel(Path path, Service asdcServiceMetadata) throws SdcToscaParserException {
78         ServiceModel serviceModel = new ServiceModel();
79         SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
80         ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(path.toFile().getAbsolutePath(),false);
81
82         serviceModel.setService(extractServiceFromCsar(asdcServiceMetadata, sdcCsarHelper));
83         serviceModel.setVolumeGroups(extractVolumeGroups(sdcCsarHelper));
84         serviceModel.setVfModules(extractVfModuleFromCsar(sdcCsarHelper));
85         serviceModel.setVnfs(extractVnfsFromCsar(sdcCsarHelper));
86         serviceModel.setConfigurations(extractPortMirroringConfigFromCsar(sdcCsarHelper));
87         serviceModel.setServiceProxies(extractServiceProxyFromCsar(sdcCsarHelper));
88         serviceModel.setNetworks(extractNetworksFromCsar(sdcCsarHelper));
89         serviceModel.setPnfs(extractPnfsFromCsar(sdcCsarHelper));
90         serviceModel.setCollectionResource(extractCRFromCsar(sdcCsarHelper));
91         return serviceModel;
92     }
93
94
95
96     private  org.onap.vid.model.Service extractServiceFromCsar(Service asdcServiceMetadata, ISdcCsarHelper csarHelper) throws SdcToscaParserException {
97         org.onap.vid.model.Service service = new  org.onap.vid.model.Service();
98
99         service.setName(csarHelper.getServiceMetadata().getValue(Constants.NAME));
100         service.setCategory(csarHelper.getServiceMetadata().getValue(Constants.CATEGORY));
101         service.setInvariantUuid(csarHelper.getServiceMetadata().getValue(Constants.INVARIANT_UUID));
102         service.setUuid(csarHelper.getServiceMetadata().getValue(Constants.UUID));
103         service.setVersion(asdcServiceMetadata.getVersion());
104         service.setDescription(csarHelper.getServiceMetadata().getValue(Constants.DESCRIPTION));
105         service.setInputs(inputsListToInputsMap(csarHelper.getInputsWithAnnotations()));
106         service.setServiceEcompNaming(csarHelper.getServiceMetadata().getValue(Constants.ECOMP_GENERATED_NAMING));
107         service.setServiceType(csarHelper.getServiceMetadata().getValue(Constants.SERVICE_TYPE));
108         service.setServiceRole(csarHelper.getServiceMetadata().getValue(Constants.SERVICE_ROLE));
109         service.setInstantiationType(validateInstantiationType(csarHelper));
110         return service;
111     }
112
113     private Map<String,CR> extractCRFromCsar(ISdcCsarHelper sdcCsarHelper) {
114             List<NodeTemplate> nodeTemplates = sdcCsarHelper.getServiceNodeTemplates();
115             Map<String, CR> collectionResourceMap = new HashMap<>();
116
117             for(NodeTemplate nodeTemplate: nodeTemplates){
118                 if(nodeTemplate.getMetaData().getValue(Constants.TYPE).equals(SdcTypes.CR.getValue())) {
119                 CR cr = new CR();
120                 populateCrFromNodeTemplate(nodeTemplate, sdcCsarHelper, cr);
121                 collectionResourceMap.put(nodeTemplate.getName(), cr);
122             }
123         }
124
125         return collectionResourceMap;
126     }
127
128     private void populateCrFromNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper sdcCsarHelper, CR cr) {
129         populateNodeFromNodeTemplate(nodeTemplate, sdcCsarHelper, cr);
130         cr.setCustomizationUUID(nodeTemplate.getMetaData().getValue(Constants.CUSTOMIZATION_UUID));
131         cr.setCategory(nodeTemplate.getMetaData().getValue(Constants.CATEGORY));
132             cr.setSubcategory(nodeTemplate.getMetaData().getValue(Constants.SUBCATEGORY));
133             cr.setResourceVendor(nodeTemplate.getMetaData().getValue(Constants.RESOURCE_VENDOR));
134             cr.setResourceVendorRelease(nodeTemplate.getMetaData().getValue(Constants.RESOURCE_VENDOR_RELEASE));
135             cr.setResourceVendorModelNumber(nodeTemplate.getMetaData().getValue(Constants.RESOURCE_VENDOR_MODEL_NUMBER));
136             cr.setNetworksCollection(getNetworksCollectionMapFromGroupsList(sdcCsarHelper, nodeTemplate));
137     }
138
139     private Map<String, NetworkCollection> getNetworksCollectionMapFromGroupsList(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) {
140         List<Group> groups = sdcCsarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, Constants.ORG_OPENECOMP_GROUPS_NETWORK_COLLECTION);
141         Map<String, NetworkCollection> networksCollectionMap = new HashMap<String, NetworkCollection>();
142         for(Group group: groups){
143             networksCollectionMap.put(group.getName(), populateCollectionNetworkFromGroup(group, nodeTemplate));
144         }
145         return networksCollectionMap;
146     }
147
148     private NetworkCollection populateCollectionNetworkFromGroup(Group group, NodeTemplate nodeTemplate) {
149         NetworkCollection networkCollection = new NetworkCollection();
150         networkCollection.setUuid(group.getMetadata().getValue(Constants.UUID));
151         networkCollection.setInvariantUuid(group.getMetadata().getValue(Constants.INVARIANT_UUID));
152         networkCollection.setVersion(group.getMetadata().getValue(Constants.VERSION));
153         networkCollection.setName(group.getMetadata().getValue(Constants.NAME));
154         extractPropertiesOfCollectionNetworkFromCsar(group, nodeTemplate, networkCollection);
155
156         return networkCollection;
157     }
158
159     private void extractPropertiesOfCollectionNetworkFromCsar(Group group, NodeTemplate nodeTemplate, NetworkCollection networkCollection) {
160         LinkedHashMap<String, Property> properties = group.getProperties();
161         Map<String, Property> nodeTemplateProperties = nodeTemplate.getProperties();
162
163         String networkCollectionFunction = (String)((Map)(properties.get(Constants.NETWORK_COLLECTION_FUNCTION).getValue())).get(Constants.GET_INPUT);
164         String networkCollectionDescription = (String)((Map)(properties.get(Constants.NETWORK_COLLECTION_DESCRIPTION).getValue())).get(Constants.GET_INPUT);
165
166         networkCollection.getNetworkCollectionProperties().setNetworkCollectionDescription((String)nodeTemplateProperties.get(networkCollectionDescription).getValue());
167         networkCollection.getNetworkCollectionProperties().setNetworkCollectionFunction((String)nodeTemplateProperties.get(networkCollectionFunction).getValue());
168     }
169
170
171     private Map<String, VNF> extractVnfsFromCsar(ISdcCsarHelper csarHelper) {
172         List<NodeTemplate> nodeTemplates = csarHelper.getServiceVfList();
173         Map<String, VNF> vnfsMaps = new HashMap<String, VNF>();
174
175         for (NodeTemplate nodeTemplate : nodeTemplates) {
176             VNF vnf = new VNF();
177             populateNodeFromNodeTemplate(nodeTemplate, csarHelper, vnf);
178             vnf.setModelCustomizationName(nodeTemplate.getName());
179             vnf.setVfModules(getVfModulesFromVF(csarHelper, vnf.getCustomizationUuid()));
180             vnf.setVolumeGroups(getVolumeGroupsFromVF(csarHelper, vnf.getCustomizationUuid()));
181             vnf.setVfcInstanceGroups(getVfcInstanceGroup(csarHelper, nodeTemplate));
182
183             vnfsMaps.put(nodeTemplate.getName(), vnf);
184         }
185         return vnfsMaps;
186     }
187
188     private Map<String,VfcInstanceGroup> getVfcInstanceGroup(ISdcCsarHelper csarHelper, NodeTemplate nodeTemplate) {
189             List<Group> vfcList = csarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, Constants.VFC_INSTANCE_GROUP_TYPE);
190         return vfcList.stream()
191                 .collect(toMap(Group::getName, group -> populateVfcInstanceGroupFromGroup(group, csarHelper, nodeTemplate)));
192     }
193
194     private VfcInstanceGroup populateVfcInstanceGroupFromGroup(Group group, ISdcCsarHelper csarHelper, NodeTemplate nodeTemplate) {
195             VfcInstanceGroup vfcInstanceGroup = new VfcInstanceGroup();
196             vfcInstanceGroup.setUuid(group.getMetadata().getValue(Constants.UUID));
197             vfcInstanceGroup.setInvariantUuid(group.getMetadata().getValue(Constants.INVARIANT_UUID));
198             vfcInstanceGroup.setVersion(group.getMetadata().getValue(Constants.VERSION));
199             vfcInstanceGroup.setName(group.getMetadata().getValue(Constants.NAME));
200             vfcInstanceGroup.setVfcInstanceGroupProperties(getVfcPropertiesFromGroup(nodeTemplate, group));
201
202         return vfcInstanceGroup;
203
204     }
205
206     private VfcInstanceGroupProperties getVfcPropertiesFromGroup(NodeTemplate nodeTemplate, Group group) {
207         VfcInstanceGroupProperties vfcInstanceGroupProperties = new VfcInstanceGroupProperties();
208         vfcInstanceGroupProperties.setVfcParentPortRole((String) group.getProperties().get(Constants.VFC_PARENT_PORT_ROLE).getValue());
209         vfcInstanceGroupProperties.setSubinterfaceRole((String) group.getProperties().get(Constants.SUBINTERFACE_ROLE).getValue());
210
211         String networkCollectionFunction = (String)((Map)(group.getProperties().get(Constants.NETWORK_COLLECTION_FUNCTION).getValue())).get(Constants.GET_INPUT);
212         String vfcInstanceGroupFunction = (String)((Map)(group.getProperties().get(Constants.VFC_INSTANCE_GROUP_FUNCTION).getValue())).get(Constants.GET_INPUT);
213
214         if(nodeTemplate.getProperties().get(networkCollectionFunction) != null)
215             vfcInstanceGroupProperties.setNetworkCollectionFunction((String) nodeTemplate.getProperties().get(networkCollectionFunction).getValue());
216         if(nodeTemplate.getProperties().get(vfcInstanceGroupFunction) != null)
217             vfcInstanceGroupProperties.setVfcInstanceGroupFunction((String) nodeTemplate.getProperties().get(vfcInstanceGroupFunction).getValue());
218
219         return vfcInstanceGroupProperties;
220     }
221
222     private Map<String, PortMirroringConfig> extractPortMirroringConfigFromCsar(ISdcCsarHelper csarHelper) {
223         List<NodeTemplate> nodeTemplates = csarHelper.getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION);
224         Map<String, PortMirroringConfig> configMaps = new HashMap<>();
225
226         for (NodeTemplate nodeTemplate : nodeTemplates) {
227             PortMirroringConfig pmConfig = new PortMirroringConfig();
228             populateNodeFromNodeTemplate(nodeTemplate, csarHelper, pmConfig);
229
230             pmConfig.setModelCustomizationName(nodeTemplate.getName());
231             pmConfig.setRequirementAssignments(nodeTemplate.getRequirements());
232             setSourceAndCollectorProxyNodes(csarHelper, pmConfig, nodeTemplate);
233
234             configMaps.put(nodeTemplate.getName(), pmConfig);
235         }
236
237         return configMaps;
238         }
239
240     private Map<String, ServiceProxy> extractServiceProxyFromCsar(ISdcCsarHelper csarHelper) {
241         List<NodeTemplate> nodeTemplates = csarHelper.getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY);
242         Map<String, ServiceProxy> serviceProxies = new HashMap<>();
243         for (NodeTemplate nodeTemplate: nodeTemplates) {
244             ServiceProxy serviceProxy = new ServiceProxy();
245             populateNodeFromNodeTemplate(nodeTemplate, csarHelper, serviceProxy);
246
247             Map<String, String> metadata = nodeTemplate.getMetaData().getAllProperties();
248             serviceProxy.setSourceModelUuid(metadata.get("sourceModelUuid"));
249             serviceProxy.setSourceModelInvariant(metadata.get("sourceModelInvariant"));
250             serviceProxy.setSourceModelName(metadata.get("sourceModelName"));
251
252             serviceProxies.put(nodeTemplate.getName(), serviceProxy);
253         }
254
255         return serviceProxies;
256     }
257
258         private void setSourceAndCollectorProxyNodes(ISdcCsarHelper csarHelper, PortMirroringConfig portMirroringConfig, NodeTemplate nodeTemplate) {
259             RequirementAssignments requirementAssignments = nodeTemplate.getRequirements();
260
261         List<String> sourceNodes = getRequirementsNodesNames(requirementAssignments.getRequirementsByName("source").getAll());
262         portMirroringConfig.setSourceNodes(sourceNodes);
263
264         List<String> collectorNodes = getRequirementsNodesNames(requirementAssignments.getRequirementsByName("collector").getAll());
265         if (!collectorNodes.isEmpty()) { // vprobe
266             portMirroringConfig.setCollectorNodes(collectorNodes);
267         } else { // pprobe - configuration by policy
268             String collectorNodeName = csarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "collector_node");
269             if (collectorNodeName != null) {
270                 portMirroringConfig.setCollectorNodes(Arrays.asList(collectorNodeName));
271                 portMirroringConfig.setConfigurationByPolicy(true);
272             }
273         }
274     }
275
276     private List<String> getRequirementsNodesNames(List<RequirementAssignment> requirements) {
277
278         List<String> requirementsNodes = new ArrayList<>();
279         if (requirements != null && requirements.size() > 0) {
280             requirementsNodes =  requirements.stream().map(RequirementAssignment::getNodeTemplateName).collect(Collectors.toList());
281         }
282
283         return requirementsNodes;
284     }
285
286     Map<String, VfModule> getVfModulesFromVF(ISdcCsarHelper csarHelper, String vfUuid) {
287         List<Group> vfModulesByVf = csarHelper.getVfModulesByVf(vfUuid);
288         return vfModulesByVf.stream()
289                 .collect(toMap(Group::getName, group -> populateVfModuleFromGroup(group, csarHelper)));
290     }
291
292     Map<String, VolumeGroup> getVolumeGroupsFromVF(ISdcCsarHelper csarHelper, String vfCustomizationUuid) {
293         List<Group> vfModulesByVf = csarHelper.getVfModulesByVf(vfCustomizationUuid);
294         return vfModulesByVf.stream()
295                 .filter((group -> isVolumeGroup(group)))
296                 .collect(toMap(Group::getName, group -> populateVolumeGroupFromGroup(group, csarHelper)));
297     }
298
299     private static Boolean isVolumeGroup(Group group) {
300         return Boolean.valueOf(group.getPropertyValue(Constants.VOLUME_GROUP).toString());
301     }
302
303     private Map<String, Network> extractNetworksFromCsar(ISdcCsarHelper csarHelper) {
304         List<NodeTemplate> nodeTemplates = csarHelper.getServiceVlList();
305         Map<String, Network> networksMap = new HashMap<String, Network>();
306
307         for (NodeTemplate nodeTemplate : nodeTemplates) {
308             Network newNetwork = new Network();
309             populateNodeFromNodeTemplate(nodeTemplate, csarHelper, newNetwork);
310             newNetwork.setModelCustomizationName(nodeTemplate.getName());
311             networksMap.put(nodeTemplate.getName(), newNetwork);
312         }
313         return networksMap;
314         }
315
316         private Map<String,Node> extractPnfsFromCsar(ISdcCsarHelper csarHelper) {
317         List<NodeTemplate> nodeTemplates = csarHelper.getServiceNodeTemplateBySdcType(SdcTypes.PNF);
318         HashMap<String, Node> pnfHashMap = new HashMap<>();
319
320         for (NodeTemplate nodeTemplate : nodeTemplates) {
321             Node pnf = new Node();
322             populateNodeFromNodeTemplate(nodeTemplate, csarHelper, pnf);
323             pnfHashMap.put(nodeTemplate.getName(), pnf);
324         }
325         return pnfHashMap;
326     }
327
328     private Map<String, VfModule> extractVfModuleFromCsar(ISdcCsarHelper csarHelper) {
329         List<NodeTemplate> serviceVfList = csarHelper.getServiceVfList();
330         HashMap<String, VfModule> vfModuleHashMap = new HashMap<>();
331
332         for (NodeTemplate nodeTemplate : serviceVfList) {
333             Map<String, VfModule> nodeTemplateVfModule =
334                     getVfModulesFromVF(csarHelper, nodeTemplate.getMetaData().getValue(Constants.CUSTOMIZATION_UUID));
335             vfModuleHashMap.putAll(nodeTemplateVfModule);
336         }
337         return vfModuleHashMap;
338     }
339
340     private Map<String, VolumeGroup> extractVolumeGroups(ISdcCsarHelper csarHelper) {
341         HashMap<String, VolumeGroup> volumeGroupHashMap = new HashMap<>();
342         for (NodeTemplate nodeTemplate : csarHelper.getServiceVfList()) {
343             Map<String, VolumeGroup> nodeTemplateVolumeGroups =
344                     getVolumeGroupsFromVF(csarHelper, csarHelper.getNodeTemplateCustomizationUuid(nodeTemplate));
345             volumeGroupHashMap.putAll(nodeTemplateVolumeGroups);
346         }
347         return volumeGroupHashMap;
348     }
349
350     private Map<String, org.onap.vid.asdc.beans.tosca.Input> inputsListToInputsMap(List<org.onap.sdc.toscaparser.api.parameters.Input> inputList) {
351         Map<String, org.onap.vid.asdc.beans.tosca.Input> inputs = new HashMap<>();
352         for (org.onap.sdc.toscaparser.api.parameters.Input input : inputList) {
353             //Set only inputs without annotation to the service level
354             if(input.getAnnotations() == null)
355                 inputs.put(input.getName(), convertInput(input, new org.onap.vid.asdc.beans.tosca.Input(), null));
356         }
357         return inputs;
358     }
359
360     private Node populateNodeFromNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper csarHelper, Node newNode) {
361         newNode.setCustomizationUuid(csarHelper.getNodeTemplateCustomizationUuid(nodeTemplate));
362         newNode.setDescription(nodeTemplate.getMetaData().getValue(Constants.DESCRIPTION));
363         newNode.setInvariantUuid(nodeTemplate.getMetaData().getValue(Constants.INVARIANT_UUID));
364         newNode.setUuid(nodeTemplate.getMetaData().getValue(Constants.UUID));
365         newNode.setName(nodeTemplate.getMetaData().getValue(Constants.NAME));
366         newNode.setVersion(nodeTemplate.getMetaData().getValue(Constants.VERSION));
367         newNode.setInputs(extractInputsAndCommandsForNodeTemplate(nodeTemplate, csarHelper, newNode));
368         newNode.setType(nodeTemplate.getMetaData().getValue(Constants.TYPE));
369         Map<String, String> propertiesMap = setPropertiesOfVnf(nodeTemplate.getPropertiesObjects());
370         newNode.setProperties(propertiesMap);
371         return newNode;
372     }
373
374     private VfModule populateVfModuleFromGroup(Group group, ISdcCsarHelper csarHelper){
375         VfModule vfModule = new VfModule();
376         extractBasicPropertiesForGroup(vfModule, group, csarHelper);
377         vfModule.setVolumeGroupAllowed(isVolumeGroup(group));
378         return vfModule;
379     }
380
381     private VolumeGroup populateVolumeGroupFromGroup(Group group, ISdcCsarHelper csarHelper){
382         VolumeGroup volumeGroup = new VolumeGroup();
383         extractBasicPropertiesForGroup(volumeGroup, group, csarHelper);
384         return volumeGroup;
385     }
386
387     private void extractBasicPropertiesForGroup(org.onap.vid.model.Group newGroup, Group group, ISdcCsarHelper csarHelper) {
388         newGroup.setDescription(group.getDescription());
389         newGroup.setVersion(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_VERSION));
390         newGroup.setCustomizationUuid(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_CUSTOMIZATION_UUID));
391         newGroup.setModelCustomizationName(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_NAME));
392         newGroup.setName(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_NAME));
393         newGroup.setUuid(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_UUID));
394         newGroup.setInvariantUuid(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_INVARIANT_UUID));
395         newGroup.setProperties(extractVfModuleProperties(group, csarHelper));
396         newGroup.setInputs(extractVfInputsFromCsarByAnnotation(csarHelper, newGroup));
397     }
398
399
400     private Map<String,org.onap.vid.asdc.beans.tosca.Input> extractVfInputsFromCsarByAnnotation(ISdcCsarHelper csarHelper, org.onap.vid.model.Group group) {
401         Map<String, org.onap.vid.asdc.beans.tosca.Input> inputMap = new HashMap<>();
402         if(group.getProperties().getVfModuleLabel() != null){
403             List<Input> inputsList = csarHelper.getInputsWithAnnotations();
404             for(Input input: inputsList){
405                 if(input.getAnnotations() != null){
406                     List<Property> annotationProperties = input.getAnnotations().get("source").getProperties();
407                     if(isInputMatchesToGroup(annotationProperties, group)){
408                         inputMap.put(input.getName(), new org.onap.vid.asdc.beans.tosca.Input(input ,annotationProperties));
409                     }
410                 }
411             }
412         }
413         return inputMap;
414     }
415
416
417     private boolean isInputMatchesToGroup(List<Property> annotationProperties, org.onap.vid.model.Group group){
418         for(Property property: annotationProperties){
419             if(property.getName().equals(VF_MODULE_LABEL)){
420                 return getPropertyValueAsString(property).equals(group.getProperties().getVfModuleLabel());
421             }
422         }
423         return false;
424     }
425
426     public String getPropertyValueAsString(Property property) {
427         return removeSquareBrackets(property.getValue().toString());
428     }
429
430     private String removeSquareBrackets(String stringWithSquareBrackets){
431         return stringWithSquareBrackets.substring(1, stringWithSquareBrackets.length()-1);
432     }
433
434     private GroupProperties extractVfModuleProperties(Group group, ISdcCsarHelper csarHelper){
435         GroupProperties vfModuleProperties = new GroupProperties();
436         if(csarHelper.getGroupPropertyAsObject(group, Constants.MIN_VF_MODULE_INSTANCES) != null)
437             vfModuleProperties.setMinCountInstances((Integer)csarHelper.getGroupPropertyAsObject(group, Constants.MIN_VF_MODULE_INSTANCES));
438         if(csarHelper.getGroupPropertyAsObject(group, Constants.MAX_VF_MODULE_INSTANCES) != null)
439             vfModuleProperties.setMaxCountInstances((Integer)csarHelper.getGroupPropertyAsObject(group, Constants.MAX_VF_MODULE_INSTANCES));
440         if(csarHelper.getGroupPropertyAsObject(group, Constants.INITIAL_COUNT) != null)
441             vfModuleProperties.setInitialCount((Integer)csarHelper.getGroupPropertyAsObject(group, Constants.INITIAL_COUNT));
442         if(csarHelper.getGroupPropertyAsObject(group, VF_MODULE_LABEL) != null)
443             vfModuleProperties.setVfModuleLabel((String) csarHelper.getGroupPropertyAsObject(group, VF_MODULE_LABEL));
444         return vfModuleProperties;
445     }
446
447
448
449
450     private Map<String, org.onap.vid.asdc.beans.tosca.Input> extractInputsAndCommandsForNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper csarHelper, Node newNode){
451         Map<String, org.onap.vid.asdc.beans.tosca.Input> inputMap = new HashMap<>();
452         Map<String, CommandProperty> commandPropertyMap = new HashMap<>();
453
454         List<Input> inputs = csarHelper.getServiceInputs();
455         Map<String, String> properties  = csarHelper.filterNodeTemplatePropertiesByValue(nodeTemplate, FilterType.CONTAINS, Constants.GET_INPUT);
456         for (Map.Entry<String, String> property : properties.entrySet()) {
457             String inputKey = property.getValue();
458             String key = extractInputValue(inputKey);
459             for (Input input: inputs){
460                 if(input.getName().equals(key)){
461                     org.onap.vid.asdc.beans.tosca.Input localInput = new org.onap.vid.asdc.beans.tosca.Input();
462                     localInput = convertInput(input, localInput, nodeTemplate);
463                     String name = property.getKey();
464                     commandPropertyMap.put(name, extractCommands(name, key));
465                     inputMap.put(name, localInput);
466                 }
467             }
468         }
469         newNode.setCommands(commandPropertyMap);
470         return inputMap;
471     }
472
473     private String extractInputValue(String inputKey) {
474         return inputKey.substring(inputKey.indexOf(":") + 1);
475     }
476
477     private org.onap.vid.asdc.beans.tosca.Input convertInput(Input parserInput, org.onap.vid.asdc.beans.tosca.Input localInput, NodeTemplate nodeTemplate){
478         localInput.setDefault(parserInput.getDefault());
479         localInput.setDescription(parserInput.getDescription());
480         localInput.setRequired(parserInput.isRequired());
481         localInput.setType(parserInput.getType());
482         localInput.setConstraints(parserInput.getConstraints());
483 //        localInput.setentry_schema()
484         
485         //if inputs of inner nodeTemplate - tell its details
486         if(nodeTemplate != null) {
487             Metadata metadata = nodeTemplate.getMetaData();
488             localInput.setTemplateName(metadata.getValue("name"));
489             localInput.setTemplateUUID(metadata.getValue("UUID"));
490             localInput.setTemplateInvariantUUID(metadata.getValue("invariantUUID"));
491             localInput.setTemplateCustomizationUUID(metadata.getValue("customizationUUID"));
492         }
493         
494         return localInput;
495     }
496
497     private CommandProperty extractCommands(String displayName, String inputName){
498         CommandProperty commandProperty = new CommandProperty();
499         commandProperty.setDisplayName(displayName);
500         commandProperty.setCommand(Constants.GET_INPUT);
501         commandProperty.setInputName(inputName);
502         return commandProperty;
503     }
504
505     private Map<String, String> setPropertiesOfVnf(List<Property> properties) {
506         Map<String, String> propertiesMap = new HashMap<String, String>();
507         for (Property property : properties) {
508             //special handling to necessary sub-property "ecomp_generated_naming"
509             if(property.getName().equals("nf_naming")){
510                 propertiesMap.put(removeSquareBrackets(((LinkedHashMap)(property.getValue())).keySet().toString()) ,((LinkedHashMap)(property.getValue())).get("ecomp_generated_naming").toString());
511             }
512             propertiesMap.put(property.getName(), property.getValue().toString());
513         }
514         return propertiesMap;
515     }
516
517     private String validateInstantiationType(ISdcCsarHelper csarHelper){
518         String instantiationType = csarHelper.getServiceMetadata().getValue(Constants.INSTANTIATION_TYPE);
519         String validatedInstantiationType = Constants.CLIENT_CONFIG;
520         if(instantiationType != null && !instantiationType.isEmpty()){
521             if(instantiationType.equalsIgnoreCase(Constants.MACRO) || instantiationType.equalsIgnoreCase(Constants.BOTH))
522                 validatedInstantiationType = Constants.MACRO;
523             else if(instantiationType.equalsIgnoreCase(Constants.A_LA_CARTE))
524                 validatedInstantiationType = Constants.A_LA_CARTE;
525         }
526         return validatedInstantiationType;
527     }
528
529
530 }