2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.healing.healers;
23 import org.openecomp.core.utilities.json.JsonSchemaDataGenerator;
24 import org.openecomp.sdc.common.utils.SdcCommon;
25 import org.openecomp.sdc.healing.interfaces.Healer;
26 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
27 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
28 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
29 import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao;
30 import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDaoFactory;
31 import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao;
32 import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory;
33 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
34 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
35 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
36 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity;
37 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity;
38 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity;
39 import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator;
40 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
41 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext;
42 import org.openecomp.sdc.versioning.dao.types.Version;
44 import java.util.Collection;
46 import java.util.Objects;
48 public class SubEntitiesQuestionnaireHealer implements Healer {
49 private static Version version00 = new Version(0, 0);
50 private MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
52 private static final VendorSoftwareProductDao vendorSoftwareProductDao =
53 VendorSoftwareProductDaoFactory.getInstance().createInterface();
54 private static ComponentDao componentDao = ComponentDaoFactory.getInstance().createInterface();
55 private static NicDao nicDao = NicDaoFactory.getInstance().createInterface();
56 private static NetworkDao networkDao = NetworkDaoFactory.getInstance().createInterface();
58 private static String emptyString = "";
59 private static String emptyJson = "{}";
62 public Object heal(Map<String, Object> healingParams) throws Exception {
65 mdcDataDebugMessage.debugEntryMessage(null);
67 String vspId = (String) healingParams.get(SdcCommon.VSP_ID);
68 Version version = version00.equals(healingParams.get(SdcCommon.VERSION)) ? new Version
70 : (Version) healingParams.get(SdcCommon.VERSION);
72 Collection<ComponentEntity> componentEntities =
73 componentDao.listCompositionAndQuestionnaire(vspId, version);
75 networkDao.list(new NetworkEntity(vspId, version, null));
77 Collection<NicEntity> nicEntities = vendorSoftwareProductDao.listNicsByVsp(vspId, version);
79 healCompositionEntityQuestionnaire(componentEntities, version, CompositionEntityType.component);
80 healCompositionEntityQuestionnaire(nicEntities, version, CompositionEntityType.nic);
82 mdcDataDebugMessage.debugExitMessage(null);
87 private void healCompositionEntityQuestionnaire(Collection
89 Version newVersion, CompositionEntityType type) {
92 mdcDataDebugMessage.debugEntryMessage(null);
94 for (Object entity : compositionEntities) {
95 CompositionEntity compositionEntity = (CompositionEntity) entity;
96 if (isQuestionnaireNeedsToGetHealed(compositionEntity)) {
97 compositionEntity.setVersion(newVersion);
98 updateNullQuestionnaire(compositionEntity, type);
102 mdcDataDebugMessage.debugExitMessage(null);
105 private boolean isQuestionnaireNeedsToGetHealed(CompositionEntity compositionEntity) {
106 return Objects.isNull(compositionEntity.getQuestionnaireData())
107 || emptyString.equals(compositionEntity.getQuestionnaireData())
108 || emptyJson.equals(compositionEntity.getQuestionnaireData());
111 private void updateNullQuestionnaire(CompositionEntity entity,
112 CompositionEntityType type) {
115 mdcDataDebugMessage.debugEntryMessage(null);
117 entity.setQuestionnaireData(
118 new JsonSchemaDataGenerator(SchemaGenerator
119 .generate(SchemaTemplateContext.questionnaire, type,
120 null)).generateData());
124 ComponentEntity component = (ComponentEntity) entity;
125 componentDao.updateQuestionnaireData(component.getVspId(), component
126 .getVersion(), component.getId(), component.getQuestionnaireData());
130 NicEntity nic = (NicEntity) entity;
131 nicDao.updateQuestionnaireData(nic.getVspId(), nic.getVersion(), nic.getComponentId(),
132 nic.getId(), nic.getQuestionnaireData());
135 mdcDataDebugMessage.debugExitMessage(null);