aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src')
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/CompositionDataHealer.java224
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/FileDataStructureHealer.java116
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/HeatToToscaTranslationHealer.java82
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/SubEntitiesQuestionnaireHealer.java129
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/VspQuestionnaireHealer.java88
5 files changed, 639 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/CompositionDataHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/CompositionDataHealer.java
new file mode 100644
index 0000000000..283f6c83b6
--- /dev/null
+++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/CompositionDataHealer.java
@@ -0,0 +1,224 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.healing.healers;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.openecomp.core.model.dao.ServiceModelDao;
+import org.openecomp.core.model.dao.ServiceModelDaoFactory;
+import org.openecomp.core.model.types.ServiceElement;
+import org.openecomp.core.translator.datatypes.TranslatorOutput;
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.sdc.common.utils.CommonUtil;
+import org.openecomp.sdc.common.utils.SdcCommon;
+import org.openecomp.sdc.healing.interfaces.Healer;
+import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
+import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionDataExtractorFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor;
+import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionData;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+public class CompositionDataHealer implements Healer {
+ private static final Version VERSION00 = new Version(0, 0);
+ private static final Version VERSION01 = new Version(0, 1);
+ private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
+
+ private static final OrchestrationTemplateDao orchestrationTemplateDataDao =
+ OrchestrationTemplateDaoFactory.getInstance().createInterface();
+
+ private static ComponentDao componentDao = ComponentDaoFactory.getInstance().createInterface();
+ private static NicDao nicDao = NicDaoFactory.getInstance().createInterface();
+ private static NetworkDao networkDao = NetworkDaoFactory.getInstance().createInterface();
+
+ private static final ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao =
+ ServiceModelDaoFactory.getInstance().createInterface();
+ private static CompositionDataExtractor compositionDataExtractor =
+ CompositionDataExtractorFactory.getInstance().createInterface();
+ private static CompositionEntityDataManager compositionEntityDataManager =
+ CompositionEntityDataManagerFactory.getInstance().createInterface();
+
+ public CompositionDataHealer() {
+ }
+
+ @Override
+ public Optional<CompositionData> heal(Map<String, Object> healingParams) throws IOException {
+ mdcDataDebugMessage.debugEntryMessage(null);
+
+ String vspId = (String) healingParams.get(SdcCommon.VSP_ID);
+ Version version = VERSION00.equals(healingParams.get(SdcCommon.VERSION))
+ ? VERSION01
+ : (Version) healingParams.get(SdcCommon.VERSION);
+
+ Collection<ComponentEntity> componentEntities =
+ componentDao.list(new ComponentEntity(vspId, version, null));
+ Collection<NicEntity> nicEntities = nicDao.listByVsp(vspId, version);
+ Collection<NetworkEntity> networkEntities =
+ networkDao.list(new NetworkEntity(vspId, version, null));
+
+ Optional<ToscaServiceModel> serviceModelForHealing = getServiceModelForHealing(vspId, version);
+
+ if (!doesVspNeedCompositionDataHealing(componentEntities, networkEntities,
+ nicEntities)) {
+ updateComponentsDisplayNames(componentEntities);
+ mdcDataDebugMessage.debugExitMessage(null);
+ return Optional.empty();
+ }
+
+
+ if (!serviceModelForHealing.isPresent()) {
+ mdcDataDebugMessage.debugExitMessage(null);
+ return Optional.empty();
+ }
+
+ CompositionData compositionData = healCompositionData(vspId, version, serviceModelForHealing);
+
+ mdcDataDebugMessage.debugExitMessage(null);
+ return Optional.of(compositionData);
+ }
+
+ private CompositionData healCompositionData(String vspId, Version version,
+ Optional<ToscaServiceModel> serviceModelForHealing) {
+ ToscaServiceModel toscaServiceModel = serviceModelForHealing.get();
+ CompositionData compositionData =
+ getCompositionDataForHealing(vspId, version, toscaServiceModel);
+ compositionEntityDataManager.saveCompositionData(vspId, version, compositionData);
+ return compositionData;
+ }
+
+ private boolean doesVspNeedCompositionDataHealing(Collection<ComponentEntity> componentEntities,
+ Collection<NetworkEntity> networkEntities,
+ Collection<NicEntity> nicEntities) {
+
+ return (CollectionUtils.isEmpty(componentEntities) && CollectionUtils.isEmpty(nicEntities) &&
+ CollectionUtils.isEmpty(networkEntities));
+ }
+
+ private CompositionData getCompositionDataForHealing(String vspId, Version version,
+ ToscaServiceModel toscaServiceModel) {
+ mdcDataDebugMessage.debugEntryMessage(null);
+
+ if (Objects.isNull(toscaServiceModel)) {
+ return null;
+ }
+
+ CompositionData compositionData = new CompositionData();
+ if (Objects.nonNull(toscaServiceModel)) {
+ compositionData = compositionDataExtractor
+ .extractServiceCompositionData(toscaServiceModel);
+ serviceModelDao.storeServiceModel(vspId, version, toscaServiceModel);
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null);
+ return compositionData;
+ }
+
+ private void updateComponentsDisplayNames(Collection<ComponentEntity> componentEntities) {
+ if (CollectionUtils.isEmpty(componentEntities)) {
+ return;
+ }
+
+ for (ComponentEntity component : componentEntities) {
+ updateComponentName(component);
+ componentDao.update(component);
+ }
+ }
+
+ private void updateComponentName(ComponentEntity component) {
+ mdcDataDebugMessage.debugEntryMessage("VSP id, component id", component.getVspId(), component
+ .getId());
+
+ ComponentData componentData =
+ JsonUtil.json2Object(component.getCompositionData(), ComponentData.class);
+ componentData
+ .setDisplayName(compositionDataExtractor.getComponentDisplayName(componentData.getName()));
+ componentData.setVfcCode(componentData.getDisplayName());
+ component.setCompositionData(JsonUtil.object2Json(componentData));
+
+ mdcDataDebugMessage.debugExitMessage("VSP id, component id", component.getVspId(), component
+ .getId());
+
+ }
+
+ private Optional<ToscaServiceModel> getServiceModelForHealing(String vspId, Version version)
+ throws IOException {
+ mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
+
+ /*UploadDataEntity uploadData =
+ vendorSoftwareProductDao.getUploadData(new UploadDataEntity(vspId, version));*/
+ UploadDataEntity uploadData =
+ orchestrationTemplateDataDao.getOrchestrationTemplate(vspId, version);
+
+ if (Objects.isNull(uploadData) || Objects.isNull(uploadData.getContentData())) {
+ return Optional.empty();
+ }
+
+ TranslatorOutput translatorOutput = getTranslatorOutputForHealing(uploadData);
+
+ if (Objects.isNull(translatorOutput)) {
+ return Optional.empty();
+ }
+
+ try {
+ serviceModelDao.storeServiceModel(vspId, version,
+ translatorOutput.getToscaServiceModel());
+ }catch (Exception e){
+ return Optional.empty();
+ }
+
+ mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+ return Optional.of(translatorOutput.getToscaServiceModel());
+ }
+
+ private TranslatorOutput getTranslatorOutputForHealing(UploadDataEntity uploadData){
+
+ FileContentHandler fileContentHandler;
+ try {
+ fileContentHandler =
+ CommonUtil.loadUploadFileContent(uploadData.getContentData().array());
+ return HeatToToscaUtil.loadAndTranslateTemplateData(fileContentHandler);
+ }catch (Exception e){
+ return null;
+ }
+ }
+}
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/FileDataStructureHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/FileDataStructureHealer.java
new file mode 100644
index 0000000000..14fe885d53
--- /dev/null
+++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/FileDataStructureHealer.java
@@ -0,0 +1,116 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.healing.healers;
+
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.sdc.common.utils.CommonUtil;
+import org.openecomp.sdc.common.utils.SdcCommon;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import org.openecomp.sdc.healing.interfaces.Healer;
+import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
+import org.openecomp.sdc.vendorsoftwareproduct.factory.CandidateServiceFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
+import org.openecomp.sdc.vendorsoftwareproduct.services.utils.CandidateEntityBuilder;
+import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public class FileDataStructureHealer implements Healer {
+ private static final OrchestrationTemplateDao orchestrationTemplateDataDao =
+ OrchestrationTemplateDaoFactory.getInstance().createInterface();
+ private static CandidateService candidateService =
+ CandidateServiceFactory.getInstance().createInterface();
+ private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
+
+ public FileDataStructureHealer() {
+ }
+
+ @Override
+ public Optional<FilesDataStructure> heal(Map<String, Object> healingParams) throws Exception {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null);
+
+ Optional<FilesDataStructure> healingResult = Optional.empty();
+ String vspId = (String) healingParams.get(SdcCommon.VSP_ID);
+ Version version = (Version) healingParams.get(SdcCommon.VERSION);
+ String user = (String) healingParams.get(SdcCommon.USER);
+
+ UploadDataEntity uploadData =
+ orchestrationTemplateDataDao.getOrchestrationTemplate(vspId,version);
+ if (uploadData == null || uploadData.getContentData() == null) {
+ FilesDataStructure emptyFilesDataStructure = new FilesDataStructure();
+ return Optional.of(emptyFilesDataStructure);
+ }
+
+ Optional<FilesDataStructure> candidateFileDataStructure =
+ candidateService.getOrchestrationTemplateCandidateFileDataStructure(vspId, version);
+
+ if (!candidateFileDataStructure.isPresent()) {
+ healingResult = healFilesDataStructure(vspId, version, user, uploadData);
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null);
+ return healingResult;
+ }
+
+ private Optional<FilesDataStructure> healFilesDataStructure(String vspId, Version version,
+ String user,
+ UploadDataEntity uploadData)
+ throws Exception {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null);
+
+ Optional<FilesDataStructure> healingResult;
+ byte[] byteContentData = uploadData.getContentData().array();
+ FileContentHandler fileContentHandler;
+ try{
+ fileContentHandler = CommonUtil.loadUploadFileContent(byteContentData);
+ Map<String, List<ErrorMessage>> errors = new HashMap<>();
+ OrchestrationTemplateCandidateData candidateDataEntity =
+ new CandidateEntityBuilder(candidateService)
+ .buildCandidateEntityFromZip(new VspDetails(vspId, version), byteContentData,
+ fileContentHandler, errors, user);
+
+ healingResult = getFileDataStructureFromJson(candidateDataEntity.getFilesDataStructure());
+ }catch (Exception e){
+ return Optional.empty();
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null);
+ return healingResult;
+ }
+
+ private Optional<FilesDataStructure> getFileDataStructureFromJson(String fileDataStructureJson) {
+ return Optional.of(JsonUtil.json2Object(fileDataStructureJson, FilesDataStructure.class));
+ }
+}
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/HeatToToscaTranslationHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/HeatToToscaTranslationHealer.java
new file mode 100644
index 0000000000..fb9dfe7e4f
--- /dev/null
+++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/HeatToToscaTranslationHealer.java
@@ -0,0 +1,82 @@
+package org.openecomp.sdc.healing.healers;
+
+
+import org.openecomp.core.model.dao.ServiceModelDao;
+import org.openecomp.core.model.dao.ServiceModelDaoFactory;
+import org.openecomp.core.model.dao.ServiceTemplateDaoFactory;
+import org.openecomp.core.model.dao.ServiceTemplateDaoInter;
+import org.openecomp.core.model.types.ServiceElement;
+import org.openecomp.core.translator.datatypes.TranslatorOutput;
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.sdc.common.utils.CommonUtil;
+import org.openecomp.sdc.common.utils.SdcCommon;
+import org.openecomp.sdc.healing.interfaces.Healer;
+import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
+import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+public class HeatToToscaTranslationHealer implements Healer {
+
+ private static final OrchestrationTemplateDao orchestrationTemplateDao =
+ OrchestrationTemplateDaoFactory.getInstance().createInterface();
+ private static final ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao =
+ ServiceModelDaoFactory.getInstance().createInterface();
+ public static final ServiceTemplateDaoInter
+ templateDao = ServiceTemplateDaoFactory.getInstance().createInterface();
+ private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
+
+ public HeatToToscaTranslationHealer(){
+
+ }
+
+ @Override
+ public Object heal(Map<String, Object> healingParams) throws Exception {
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+ String vspId = (String) healingParams.get(SdcCommon.VSP_ID);
+ Version version = (Version) healingParams.get(SdcCommon.VERSION);
+ String user = (String) healingParams.get(SdcCommon.USER);
+ UploadDataEntity uploadData =
+ orchestrationTemplateDao.getOrchestrationTemplate(vspId, version);
+
+ if (Objects.isNull(uploadData) || Objects.isNull(uploadData.getContentData())) {
+ return Optional.empty();
+ }
+
+ FileContentHandler fileContentHandler;
+ TranslatorOutput translatorOutput;
+ try {
+ fileContentHandler = CommonUtil.loadUploadFileContent(uploadData
+ .getContentData().array());
+ translatorOutput =
+ HeatToToscaUtil.loadAndTranslateTemplateData(fileContentHandler);
+ }catch (Exception e){
+ return Optional.empty();
+ }
+
+ if(Objects.isNull(translatorOutput)){
+ return Optional.empty();
+ }
+
+ if (translatorOutput != null && translatorOutput.getToscaServiceModel() == null) {
+ return Optional.empty();
+ }
+ //templateDao.deleteAll(vspId, version);
+ serviceModelDao.deleteAll(vspId,version);
+ serviceModelDao.storeServiceModel(vspId, version,
+ translatorOutput.getToscaServiceModel());
+ mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+
+ return translatorOutput;
+
+ }
+}
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/SubEntitiesQuestionnaireHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/SubEntitiesQuestionnaireHealer.java
new file mode 100644
index 0000000000..4e8de71ea3
--- /dev/null
+++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/SubEntitiesQuestionnaireHealer.java
@@ -0,0 +1,129 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.healing.healers;
+
+import org.openecomp.core.utilities.json.JsonSchemaDataGenerator;
+import org.openecomp.sdc.common.utils.SdcCommon;
+import org.openecomp.sdc.healing.interfaces.Healer;
+import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.CompositionEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
+import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Objects;
+
+public class SubEntitiesQuestionnaireHealer implements Healer {
+ private static Version version00 = new Version(0, 0);
+ private MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
+
+ private static final VendorSoftwareProductDao vendorSoftwareProductDao =
+ VendorSoftwareProductDaoFactory.getInstance().createInterface();
+ private static ComponentDao componentDao = ComponentDaoFactory.getInstance().createInterface();
+ private static NicDao nicDao = NicDaoFactory.getInstance().createInterface();
+ private static NetworkDao networkDao = NetworkDaoFactory.getInstance().createInterface();
+
+ @Override
+ public Object heal(Map<String, Object> healingParams) throws Exception {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null);
+
+ String vspId = (String) healingParams.get(SdcCommon.VSP_ID);
+ Version version = version00.equals(healingParams.get(SdcCommon.VERSION)) ? new Version
+ (0, 1)
+ : (Version) healingParams.get(SdcCommon.VERSION);
+
+ Collection<ComponentEntity> componentEntities =
+
+ componentDao.listCompositionAndQuestionnaire(vspId, version);
+ networkDao.list(new NetworkEntity(vspId, version,null));
+
+ Collection<NicEntity> nicEntities = vendorSoftwareProductDao.listNicsByVsp(vspId, version);
+
+ healCompositionEntityQuestionnaire(componentEntities, version, CompositionEntityType.component);
+ healCompositionEntityQuestionnaire(nicEntities, version, CompositionEntityType.nic);
+
+ mdcDataDebugMessage.debugExitMessage(null);
+ return new Object();
+ }
+
+
+ private void healCompositionEntityQuestionnaire(Collection
+ compositionEntities,
+ Version newVersion, CompositionEntityType type) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null);
+
+ for (Object entity : compositionEntities) {
+ CompositionEntity compositionEntity = (CompositionEntity) entity;
+ if (Objects.isNull(compositionEntity.getQuestionnaireData())) {
+ compositionEntity.setVersion(newVersion);
+ updateNullQuestionnaire(compositionEntity, type);
+ }
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null);
+ }
+
+ private void updateNullQuestionnaire(CompositionEntity entity,
+ CompositionEntityType type) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null);
+
+ entity.setQuestionnaireData(
+ new JsonSchemaDataGenerator(SchemaGenerator
+ .generate(SchemaTemplateContext.questionnaire, type,
+ null)).generateData());
+
+ switch (type) {
+ case component:
+ ComponentEntity component = (ComponentEntity) entity;
+ componentDao.updateQuestionnaireData(component.getVspId(), component
+ .getVersion(), component.getId(), component.getQuestionnaireData());
+ break;
+
+ case nic:
+ NicEntity nic = (NicEntity) entity;
+ nicDao.updateQuestionnaireData(nic.getVspId(), nic.getVersion(), nic.getComponentId(),
+ nic.getId(), nic.getQuestionnaireData());
+ break;
+ }
+ mdcDataDebugMessage.debugExitMessage(null);
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/VspQuestionnaireHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/VspQuestionnaireHealer.java
new file mode 100644
index 0000000000..4d2b26df8b
--- /dev/null
+++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/VspQuestionnaireHealer.java
@@ -0,0 +1,88 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.healing.healers;
+
+import org.openecomp.core.utilities.json.JsonSchemaDataGenerator;
+import org.openecomp.sdc.common.utils.SdcCommon;
+import org.openecomp.sdc.healing.interfaces.Healer;
+import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity;
+import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator;
+import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
+import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateContext;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+public class VspQuestionnaireHealer implements Healer {
+ private static final VendorSoftwareProductInfoDao vspInfoDao =
+ VendorSoftwareProductInfoDaoFactory.getInstance().createInterface();
+ private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
+
+ public VspQuestionnaireHealer() {
+ }
+
+ @Override
+ public Object heal(Map<String, Object> healingParams) throws IOException {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ Optional<String> questionnaireData = null;
+ String vspId = (String) healingParams.get(SdcCommon.VSP_ID);
+ Version version = (Version) healingParams.get(SdcCommon.VERSION);
+
+ VspQuestionnaireEntity vspQuestionnaireEntity =
+ vspInfoDao.getQuestionnaire(vspId, version);
+
+ if(Objects.isNull(vspQuestionnaireEntity.getQuestionnaireData())) {
+ questionnaireData = healQuestionnaire(vspId, version);
+ }
+
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return questionnaireData;
+ }
+
+ private Optional<String> healQuestionnaire(String vspId, Version version) {
+
+
+ mdcDataDebugMessage.debugEntryMessage(null, null);
+
+ String questionnaireData;
+ String generatedSchema = SchemaGenerator
+ .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, null);
+ try {
+ questionnaireData = new JsonSchemaDataGenerator(generatedSchema).generateData();
+ vspInfoDao.updateQuestionnaireData(vspId, version, questionnaireData);
+ }catch(Exception e){
+ return Optional.empty();
+ }
+ mdcDataDebugMessage.debugExitMessage(null, null);
+ return Optional.of(questionnaireData);
+ }
+}