1 package org.openecomp.sdc.healing.healers;
3 import com.google.gson.JsonObject;
4 import com.google.gson.JsonParser;
5 import org.openecomp.sdc.common.utils.SdcCommon;
6 import org.openecomp.sdc.healing.interfaces.Healer;
7 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
8 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
9 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
10 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
11 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
12 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
13 import org.openecomp.sdc.versioning.dao.types.Version;
15 import java.util.Collection;
19 public class ComponentQuestionnaireHealer implements Healer {
20 /*private static final VendorSoftwareProductDao vendorSoftwareProductDao =
21 VendorSoftwareProductDaoFactory.getInstance().createInterface();*/
23 private static final ComponentDao componentDao =
24 ComponentDaoFactory.getInstance().createInterface();
25 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
27 public ComponentQuestionnaireHealer(){
31 public Object heal(Map<String, Object> healingParams) throws Exception {
32 mdcDataDebugMessage.debugEntryMessage(null, null);
33 String vspId = (String) healingParams.get(SdcCommon.VSP_ID);
34 Version version = (Version) healingParams.get(SdcCommon.VERSION);
35 String user = (String) healingParams.get(SdcCommon.USER);
36 Collection<ComponentEntity> componentEntities =
37 componentDao.list(new ComponentEntity(vspId, version, null));
38 componentEntities.forEach(componentEntity -> {
39 /*String questionnaire=vendorSoftwareProductDao.getComponent(vspId, version, componentEntity
40 .getId()).getQuestionnaireData();*/
41 String questionnaire = componentDao.getQuestionnaireData(vspId, version, componentEntity
42 .getId()).getQuestionnaireData();
43 if (questionnaire != null) {
44 JsonParser jsonParser = new JsonParser();
45 JsonObject json = (JsonObject) jsonParser.parse(questionnaire);
46 if (json.getAsJsonObject("compute") != null && json.getAsJsonObject("compute")
47 .getAsJsonObject("vmSizing") != null) {
48 json.getAsJsonObject("compute").remove("vmSizing");
51 if (json.getAsJsonObject("compute") != null && json.getAsJsonObject("compute")
52 .getAsJsonObject("numOfVMs") != null ) {
53 if (json.getAsJsonObject("compute").getAsJsonObject("numOfVMs").
54 get("CpuOverSubscriptionRatio") != null ) {
55 json.getAsJsonObject("compute").getAsJsonObject("numOfVMs").remove
56 ("CpuOverSubscriptionRatio");
58 if (json.getAsJsonObject("compute").getAsJsonObject("numOfVMs").
59 get("MemoryRAM") != null ) {
60 json.getAsJsonObject("compute").getAsJsonObject("numOfVMs").remove("MemoryRAM");
64 if (json.getAsJsonObject("general") != null && json.getAsJsonObject("general")
65 .getAsJsonObject("image") != null && json.getAsJsonObject("general").getAsJsonObject
66 ("image").get("format") != null) {
67 json.getAsJsonObject("general").getAsJsonObject("image").remove("format");
69 String questionnaireData = json.toString();
70 /*vendorSoftwareProductDao.updateComponentQuestionnaire(vspId, version, componentEntity
71 .getId(),questionnaireData);*/
72 componentDao.updateQuestionnaireData(vspId, version, componentEntity.getId(),
76 return componentEntities;