2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.enrichment.impl.tosca;
19 import org.openecomp.core.utilities.json.JsonUtil;
20 import org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants;
21 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
22 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
23 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao;
24 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDaoFactory;
25 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
26 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
27 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
28 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire;
29 import org.openecomp.sdc.versioning.dao.types.Version;
31 import java.util.ArrayList;
32 import java.util.Collection;
33 import java.util.HashMap;
34 import java.util.List;
37 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE;
38 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY;
39 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES;
40 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES;
41 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.NFC_NAMING_CODE;
44 public class ComponentQuestionnaireData {
46 ComponentDao componentDao = ComponentDaoFactory.getInstance().createInterface();
47 ComponentDependencyModelDao componentDependencyModelDao =
48 ComponentDependencyModelDaoFactory.getInstance().createInterface();
50 private Map<String, String> sourceToTargetComponent;
52 public Map<String, String> getSourceToTargetComponent() {
53 return sourceToTargetComponent;
56 public void setSourceToTargetComponent(Map<String, String> sourceToTargetComponent) {
57 this.sourceToTargetComponent = sourceToTargetComponent;
60 public Map<String, Map<String, Object>> getPropertiesfromCompQuestionnaire(String key,
62 Map<String, Map<String, Object>> componentProperties =
63 new HashMap<String, Map<String, Object>>();
65 ComponentEntity entity = new ComponentEntity(key, version, null);
66 final Collection<ComponentEntity> componentEntities =
67 componentDao.listCompositionAndQuestionnaire(key, version);
69 Map<String, String> sourceToTarget = new HashMap<>();
71 for (ComponentEntity component : componentEntities) {
72 Map<String, Object> questionnaireParams = new HashMap<>();
74 final ComponentQuestionnaire componentQuestionnaire =
75 JsonUtil.json2Object(component.getQuestionnaireData(), ComponentQuestionnaire.class);
77 final ComponentData componentData =
78 JsonUtil.json2Object(component.getCompositionData(), ComponentData.class);
80 sourceToTarget.put(component.getId(), componentData.getDisplayName());
82 String nfcNamingCode = componentQuestionnaire.getGeneral().getNfcNamingCode() != null ?
83 componentQuestionnaire.getGeneral().getNfcNamingCode() : null;
84 questionnaireParams.put(NFC_NAMING_CODE, nfcNamingCode);
86 String vfcDescription = componentQuestionnaire.getGeneral().getNfcFunction() != null ?
87 componentQuestionnaire.getGeneral().getNfcFunction() : null;
88 questionnaireParams.put(EnrichmentConstants.NFC_FUNCTION, vfcDescription);
91 if (componentQuestionnaire.getHighAvailabilityAndLoadBalancing() != null) {
92 String mandatory = componentQuestionnaire.getHighAvailabilityAndLoadBalancing()
93 .getIsComponentMandatory();
94 questionnaireParams.put(MANDATORY, mandatory);
96 String mode = componentQuestionnaire.getHighAvailabilityAndLoadBalancing()
97 .getHighAvailabilityMode();
99 questionnaireParams.put(HIGH_AVAIL_MODE, mode);
102 final Integer maxVms =
103 componentQuestionnaire.getCompute() != null ? (componentQuestionnaire.getCompute()
104 .getNumOfVMs() != null ? componentQuestionnaire.getCompute().getNumOfVMs()
105 .getMaximum() : null) : null;
107 final Integer minVms =
108 componentQuestionnaire.getCompute() != null ? (componentQuestionnaire.getCompute()
109 .getNumOfVMs() != null ? componentQuestionnaire.getCompute().getNumOfVMs()
110 .getMinimum() : null) : null;
112 questionnaireParams.put(MIN_INSTANCES, minVms != null && minVms == 0 ? null : minVms);
113 questionnaireParams.put(MAX_INSTANCES, maxVms != null && maxVms == 0 ? null : maxVms);
115 if (!questionnaireParams.isEmpty()) {
116 componentProperties.put(JsonUtil.json2Object(component.getCompositionData(),
117 ComponentData.class).getDisplayName(), questionnaireParams);
121 setSourceToTargetComponent(sourceToTarget);
123 return componentProperties;
126 public Map<String, List<String>> populateDependencies(String vspId, Version version, Map<String,
127 String> componentNameData) {
128 Collection<ComponentDependencyModelEntity> componentDependencies =
129 componentDependencyModelDao.list(new ComponentDependencyModelEntity(vspId, version, null));
131 Map<String, List<String>> sourceToTargetComponent = new HashMap<String, List<String>>();
132 List<String> targetComponents = null;
133 for (ComponentDependencyModelEntity dependency : componentDependencies) {
134 String sourceComponentName = componentNameData.get(dependency.getSourceComponentId());
135 String targetComponentName = componentNameData.get(dependency.getTargetComponentId());
136 if (!sourceToTargetComponent.containsKey(sourceComponentName)) {
137 targetComponents = new ArrayList<String>();
139 targetComponents = sourceToTargetComponent.get(sourceComponentName);
141 targetComponents.add(targetComponentName);
142 sourceToTargetComponent.put(sourceComponentName, targetComponents);
145 return sourceToTargetComponent;