[SDC] Onboarding 1710 rebase.
[sdc.git] / openecomp-be / lib / openecomp-healing-lib / openecomp-sdc-healing-impl / src / main / java / org / openecomp / sdc / healing / healers / ComponentQuestionnaireHealer.java
1 package org.openecomp.sdc.healing.healers;
2
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;
14
15 import java.util.Collection;
16 import java.util.Map;
17
18
19 public class ComponentQuestionnaireHealer implements Healer {
20   /*private static final VendorSoftwareProductDao vendorSoftwareProductDao =
21       VendorSoftwareProductDaoFactory.getInstance().createInterface();*/
22
23   private static final ComponentDao componentDao =
24       ComponentDaoFactory.getInstance().createInterface();
25   private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
26
27   public ComponentQuestionnaireHealer(){
28
29   }
30   @Override
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");
49         }
50
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");
57           }
58           if (json.getAsJsonObject("compute").getAsJsonObject("numOfVMs").
59               get("MemoryRAM") != null ) {
60             json.getAsJsonObject("compute").getAsJsonObject("numOfVMs").remove("MemoryRAM");
61           }
62         }
63
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");
68         }
69       String questionnaireData = json.toString();
70         /*vendorSoftwareProductDao.updateComponentQuestionnaire(vspId, version, componentEntity
71             .getId(),questionnaireData);*/
72         componentDao.updateQuestionnaireData(vspId, version, componentEntity.getId(),
73             questionnaireData);
74       }
75     });
76     return componentEntities;
77   }
78 }