1 package org.openecomp.sdc.enrichment.impl.tosca;
4 import org.openecomp.core.utilities.json.JsonUtil;
5 import org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants;
6 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
7 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
8 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao;
9 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDaoFactory;
10 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
11 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
12 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
13 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire;
14 import org.openecomp.sdc.versioning.dao.types.Version;
16 import java.util.ArrayList;
17 import java.util.Collection;
18 import java.util.HashMap;
19 import java.util.List;
22 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE;
23 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY;
24 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES;
25 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES;
26 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_NAMING_CODE;
30 public class ComponentQuestionnaireData {
32 ComponentDao componentDao = ComponentDaoFactory.getInstance().createInterface();
33 ComponentDependencyModelDao componentDependencyModelDao = ComponentDependencyModelDaoFactory.getInstance()
36 private Map<String,String> sourceToTargetComponent;
38 public Map<String,String> getSourceToTargetComponent() {
39 return sourceToTargetComponent;
42 public void setSourceToTargetComponent(Map<String,String> sourceToTargetComponent) {
43 this.sourceToTargetComponent = sourceToTargetComponent;
46 public Map<String, Map<String, Object>> getPropertiesfromCompQuestionnaire(String key,
48 Map<String, Map<String,Object>> componentProperties =
49 new HashMap<String, Map<String,Object>>();
51 ComponentEntity entity = new ComponentEntity(key, version, null);
52 final Collection<ComponentEntity> componentEntities =
53 componentDao.listCompositionAndQuestionnaire(key, version);
55 Map<String,String> sourceToTarget = new HashMap<String, String>();
57 for (ComponentEntity component : componentEntities) {
58 Map<String, Object> questionnaireParams = new HashMap<String, Object>();
60 final ComponentQuestionnaire componentQuestionnaire =
61 JsonUtil.json2Object(component.getQuestionnaireData(), ComponentQuestionnaire.class);
63 final ComponentData componentData =
64 JsonUtil.json2Object(component.getCompositionData(), ComponentData.class);
66 sourceToTarget.put(component.getId(), componentData.getDisplayName());
68 String vfc_code = componentData != null ? componentData.getVfcCode() : null;
69 questionnaireParams.put(VFC_NAMING_CODE, vfc_code);
71 String nfcCode = componentData.getNfcCode() != null ? componentData.getNfcCode() : null;
72 questionnaireParams.put(EnrichmentConstants.VFC_CODE, nfcCode);
74 String vfcDescription =
75 componentData.getNfcFunction() != null ? componentData.getNfcFunction() :
77 questionnaireParams.put(EnrichmentConstants.VFC_FUNCTION, vfcDescription);
80 if (componentQuestionnaire.getHighAvailabilityAndLoadBalancing() != null ) {
81 String mandatory = componentQuestionnaire.getHighAvailabilityAndLoadBalancing()
82 .getIsComponentMandatory();
83 questionnaireParams.put(MANDATORY, mandatory);
85 String mode = componentQuestionnaire.getHighAvailabilityAndLoadBalancing()
86 .getHighAvailabilityMode();
88 questionnaireParams.put(HIGH_AVAIL_MODE, mode);
91 final Integer maxVms =
92 componentQuestionnaire.getCompute() != null ? (componentQuestionnaire.getCompute()
93 .getNumOfVMs() != null ? componentQuestionnaire.getCompute().getNumOfVMs()
94 .getMaximum(): null) : null;
96 final Integer minVms =
97 componentQuestionnaire.getCompute() != null ? (componentQuestionnaire.getCompute()
98 .getNumOfVMs() != null ? componentQuestionnaire.getCompute().getNumOfVMs()
99 .getMinimum(): null) : null;
101 questionnaireParams.put(MIN_INSTANCES,minVms != null && minVms == 0 ? null : minVms);
102 questionnaireParams.put(MAX_INSTANCES,maxVms != null && maxVms == 0 ? null : maxVms);
104 if (! questionnaireParams.isEmpty())
105 componentProperties.put(JsonUtil.json2Object(component.getCompositionData(),
106 ComponentData.class).getDisplayName(), questionnaireParams);
109 setSourceToTargetComponent(sourceToTarget);
111 return componentProperties;
114 public Map<String,List<String>> populateDependencies(String vspId, Version version, Map<String,
115 String> componentNameData) {
116 Collection<ComponentDependencyModelEntity> componentDependencies =
117 componentDependencyModelDao.list(new ComponentDependencyModelEntity(vspId, version, null));
119 Map<String,List<String>> sourceToTargetComponent = new HashMap<String, List<String>>();
120 List<String> targetComponents = null;
121 for (ComponentDependencyModelEntity dependency : componentDependencies) {
122 String sourceComponentName = componentNameData.get(dependency.getSourceComponentId());
123 String targetComponentName = componentNameData.get(dependency.getTargetComponentId());
124 if (!sourceToTargetComponent.containsKey(sourceComponentName)) {
125 targetComponents = new ArrayList<String>();
127 targetComponents = sourceToTargetComponent.get(sourceComponentName);
129 targetComponents.add(targetComponentName);
130 sourceToTargetComponent.put(sourceComponentName, targetComponents);
133 return sourceToTargetComponent;