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 static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE;
20 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY;
21 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES;
22 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES;
23 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.NFC_NAMING_CODE;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.HashMap;
28 import java.util.List;
30 import org.openecomp.core.utilities.json.JsonUtil;
31 import org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants;
32 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
33 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
34 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao;
35 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDaoFactory;
36 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
37 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
38 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
39 import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire;
40 import org.openecomp.sdc.versioning.dao.types.Version;
43 public class ComponentQuestionnaireData {
45 ComponentDao componentDao = ComponentDaoFactory.getInstance().createInterface();
46 ComponentDependencyModelDao componentDependencyModelDao =
47 ComponentDependencyModelDaoFactory.getInstance().createInterface();
49 private Map<String, String> sourceToTargetComponent;
51 public Map<String, String> getSourceToTargetComponent() {
52 return sourceToTargetComponent;
55 public void setSourceToTargetComponent(Map<String, String> sourceToTargetComponent) {
56 this.sourceToTargetComponent = sourceToTargetComponent;
59 public Map<String, Map<String, Object>> getPropertiesfromCompQuestionnaire(String key,
61 Map<String, Map<String, Object>> componentProperties = new HashMap<>();
63 final Collection<ComponentEntity> componentEntities =
64 componentDao.listCompositionAndQuestionnaire(key, version);
66 Map<String, String> sourceToTarget = new HashMap<>();
68 for (ComponentEntity component : componentEntities) {
69 Map<String, Object> questionnaireParams = new HashMap<>();
71 final ComponentQuestionnaire componentQuestionnaire =
72 JsonUtil.json2Object(component.getQuestionnaireData(), ComponentQuestionnaire.class);
74 final ComponentData componentData =
75 JsonUtil.json2Object(component.getCompositionData(), ComponentData.class);
77 sourceToTarget.put(component.getId(), componentData.getDisplayName());
79 String nfcNamingCode = componentQuestionnaire.getGeneral().getNfcNamingCode();
80 questionnaireParams.put(NFC_NAMING_CODE, nfcNamingCode);
82 String vfcDescription = componentQuestionnaire.getGeneral().getNfcFunction();
83 questionnaireParams.put(EnrichmentConstants.NFC_FUNCTION, vfcDescription);
86 if (componentQuestionnaire.getHighAvailabilityAndLoadBalancing() != null) {
87 String mandatory = componentQuestionnaire.getHighAvailabilityAndLoadBalancing()
88 .getIsComponentMandatory();
89 questionnaireParams.put(MANDATORY, mandatory);
91 String mode = componentQuestionnaire.getHighAvailabilityAndLoadBalancing()
92 .getHighAvailabilityMode();
94 questionnaireParams.put(HIGH_AVAIL_MODE, mode);
97 final Integer maxVms =
98 componentQuestionnaire.getCompute() != null ? (componentQuestionnaire.getCompute()
99 .getNumOfVMs() != null ? componentQuestionnaire.getCompute().getNumOfVMs()
100 .getMaximum() : null) : null;
102 final Integer minVms =
103 componentQuestionnaire.getCompute() != null ? (componentQuestionnaire.getCompute()
104 .getNumOfVMs() != null ? componentQuestionnaire.getCompute().getNumOfVMs()
105 .getMinimum() : null) : null;
107 questionnaireParams.put(MIN_INSTANCES, minVms != null && minVms == 0 ? null : minVms);
108 questionnaireParams.put(MAX_INSTANCES, maxVms != null && maxVms == 0 ? null : maxVms);
110 if (!questionnaireParams.isEmpty()) {
111 componentProperties.put(JsonUtil.json2Object(component.getCompositionData(),
112 ComponentData.class).getDisplayName(), questionnaireParams);
116 setSourceToTargetComponent(sourceToTarget);
118 return componentProperties;
121 public Map<String, List<String>> populateDependencies(String vspId, Version version, Map<String,
122 String> componentNameData) {
123 Collection<ComponentDependencyModelEntity> componentDependencies =
124 componentDependencyModelDao.list(new ComponentDependencyModelEntity(vspId, version, null));
126 Map<String, List<String>> dependencies = new HashMap<>();
127 List<String> targetComponents;
128 for (ComponentDependencyModelEntity dependency : componentDependencies) {
129 String sourceComponentName = componentNameData.get(dependency.getSourceComponentId());
130 String targetComponentName = componentNameData.get(dependency.getTargetComponentId());
131 if (!dependencies.containsKey(sourceComponentName)) {
132 targetComponents = new ArrayList<>();
134 targetComponents = dependencies.get(sourceComponentName);
136 targetComponents.add(targetComponentName);
137 dependencies.put(sourceComponentName, targetComponents);