1 package org.openecomp.sdc.enrichment.impl.tosca;
3 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE;
4 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY;
5 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES;
6 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES;
7 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_NAMING_CODE;
9 import org.openecomp.core.utilities.json.JsonUtil;
10 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
11 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
12 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao;
13 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDaoFactory;
14 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
15 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
16 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
17 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire;
18 import org.openecomp.sdc.versioning.dao.types.Version;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.HashMap;
23 import java.util.List;
26 public class ComponentQuestionnaireData {
28 ComponentDao componentDao = ComponentDaoFactory.getInstance().createInterface();
29 ComponentDependencyModelDao componentDependencyModelDao = ComponentDependencyModelDaoFactory.getInstance()
32 private Map<String,String> sourceToTargetComponent;
34 public Map<String,String> getSourceToTargetComponent() {
35 return sourceToTargetComponent;
38 public void setSourceToTargetComponent(Map<String,String> sourceToTargetComponent) {
39 this.sourceToTargetComponent = sourceToTargetComponent;
42 public Map<String, Map<String, Object>> getPropertiesfromCompQuestionnaire(String key,
44 Map<String, Map<String,Object>> componentProperties =
45 new HashMap<String, Map<String,Object>>();
47 ComponentEntity entity = new ComponentEntity(key, version, null);
48 final Collection<ComponentEntity> componentEntities =
49 componentDao.listCompositionAndQuestionnaire(key, version);
51 Map<String,String> sourceToTarget = new HashMap<String, String>();
53 for (ComponentEntity component : componentEntities) {
54 Map<String, Object> questionnaireParams = new HashMap<String, Object>();
56 final ComponentQuestionnaire componentQuestionnaire =
57 JsonUtil.json2Object(component.getQuestionnaireData(), ComponentQuestionnaire.class);
59 final ComponentData componentData =
60 JsonUtil.json2Object(component.getCompositionData(), ComponentData.class);
62 sourceToTarget.put(component.getId(), componentData.getDisplayName());
64 String vfc_code = componentData != null ? componentData.getVfcCode() : null;
65 questionnaireParams.put(VFC_NAMING_CODE, vfc_code);
67 if (componentQuestionnaire.getHighAvailabilityAndLoadBalancing() != null ) {
68 String mandatory = componentQuestionnaire.getHighAvailabilityAndLoadBalancing()
69 .getIsComponentMandatory();
70 questionnaireParams.put(MANDATORY, mandatory);
72 String mode = componentQuestionnaire.getHighAvailabilityAndLoadBalancing()
73 .getHighAvailabilityMode();
75 questionnaireParams.put(HIGH_AVAIL_MODE, mode);
78 final Integer maxVms =
79 componentQuestionnaire.getCompute() != null ? (componentQuestionnaire.getCompute()
80 .getNumOfVMs() != null ? componentQuestionnaire.getCompute().getNumOfVMs()
81 .getMaximum(): null) : null;
83 final Integer minVms =
84 componentQuestionnaire.getCompute() != null ? (componentQuestionnaire.getCompute()
85 .getNumOfVMs() != null ? componentQuestionnaire.getCompute().getNumOfVMs()
86 .getMinimum(): null) : null;
88 questionnaireParams.put(MIN_INSTANCES,minVms != null && minVms == 0 ? null : minVms);
89 questionnaireParams.put(MAX_INSTANCES,maxVms != null && maxVms == 0 ? null : maxVms);
91 if (! questionnaireParams.isEmpty())
92 componentProperties.put(JsonUtil.json2Object(component.getCompositionData(),
93 ComponentData.class).getDisplayName(), questionnaireParams);
96 setSourceToTargetComponent(sourceToTarget);
98 return componentProperties;
101 public Map<String,List<String>> populateDependencies(String vspId, Version version, Map<String,
102 String> componentNameData) {
103 Collection<ComponentDependencyModelEntity> componentDependencies =
104 componentDependencyModelDao.list(new ComponentDependencyModelEntity(vspId, version, null));
106 Map<String,List<String>> sourceToTargetComponent = new HashMap<String, List<String>>();
107 List<String> targetComponents = null;
108 for (ComponentDependencyModelEntity dependency : componentDependencies) {
109 String sourceComponentName = componentNameData.get(dependency.getSourceComponentId());
110 String targetComponentName = componentNameData.get(dependency.getTargetComponentId());
111 if (!sourceToTargetComponent.containsKey(sourceComponentName)) {
112 targetComponents = new ArrayList<String>();
114 targetComponents = sourceToTargetComponent.get(sourceComponentName);
116 targetComponents.add(targetComponentName);
117 sourceToTargetComponent.put(sourceComponentName, targetComponents);
120 return sourceToTargetComponent;