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;
29 public class ComponentQuestionnaireData {
31 ComponentDao componentDao = ComponentDaoFactory.getInstance().createInterface();
32 ComponentDependencyModelDao componentDependencyModelDao =
33 ComponentDependencyModelDaoFactory.getInstance().createInterface();
35 private Map<String, String> sourceToTargetComponent;
37 public Map<String, String> getSourceToTargetComponent() {
38 return sourceToTargetComponent;
41 public void setSourceToTargetComponent(Map<String, String> sourceToTargetComponent) {
42 this.sourceToTargetComponent = sourceToTargetComponent;
45 public Map<String, Map<String, Object>> getPropertiesfromCompQuestionnaire(String key,
47 Map<String, Map<String, Object>> componentProperties =
48 new HashMap<String, Map<String, Object>>();
50 ComponentEntity entity = new ComponentEntity(key, version, null);
51 final Collection<ComponentEntity> componentEntities =
52 componentDao.listCompositionAndQuestionnaire(key, version);
54 Map<String, String> sourceToTarget = new HashMap<>();
56 for (ComponentEntity component : componentEntities) {
57 Map<String, Object> questionnaireParams = new HashMap<>();
59 final ComponentQuestionnaire componentQuestionnaire =
60 JsonUtil.json2Object(component.getQuestionnaireData(), ComponentQuestionnaire.class);
62 final ComponentData componentData =
63 JsonUtil.json2Object(component.getCompositionData(), ComponentData.class);
65 sourceToTarget.put(component.getId(), componentData.getDisplayName());
67 String vfc_code = componentData != null ? componentData.getVfcCode() : null;
68 questionnaireParams.put(VFC_NAMING_CODE, vfc_code);
70 String nfcCode = componentData.getNfcCode() != null ? componentData.getNfcCode() : null;
71 questionnaireParams.put(EnrichmentConstants.VFC_CODE, nfcCode);
73 String vfcDescription =
74 componentData.getNfcFunction() != null ? componentData.getNfcFunction() :
76 questionnaireParams.put(EnrichmentConstants.VFC_FUNCTION, vfcDescription);
79 if (componentQuestionnaire.getHighAvailabilityAndLoadBalancing() != null) {
80 String mandatory = componentQuestionnaire.getHighAvailabilityAndLoadBalancing()
81 .getIsComponentMandatory();
82 questionnaireParams.put(MANDATORY, mandatory);
84 String mode = componentQuestionnaire.getHighAvailabilityAndLoadBalancing()
85 .getHighAvailabilityMode();
87 questionnaireParams.put(HIGH_AVAIL_MODE, mode);
90 final Integer maxVms =
91 componentQuestionnaire.getCompute() != null ? (componentQuestionnaire.getCompute()
92 .getNumOfVMs() != null ? componentQuestionnaire.getCompute().getNumOfVMs()
93 .getMaximum() : null) : null;
95 final Integer minVms =
96 componentQuestionnaire.getCompute() != null ? (componentQuestionnaire.getCompute()
97 .getNumOfVMs() != null ? componentQuestionnaire.getCompute().getNumOfVMs()
98 .getMinimum() : null) : null;
100 questionnaireParams.put(MIN_INSTANCES, minVms != null && minVms == 0 ? null : minVms);
101 questionnaireParams.put(MAX_INSTANCES, maxVms != null && maxVms == 0 ? null : maxVms);
103 if (!questionnaireParams.isEmpty()) {
104 componentProperties.put(JsonUtil.json2Object(component.getCompositionData(),
105 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;