summaryrefslogtreecommitdiffstats
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/ComponentDataHealer.java53
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ManufacturerReferenceNumberHealer.java131
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/NetworkPackageHealer.java278
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/OwnerHealer.java105
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ToscaServiceModelHealer.java146
5 files changed, 294 insertions, 419 deletions
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ComponentDataHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ComponentDataHealer.java
index 1e6299ce17..7dd86ddb5b 100644
--- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ComponentDataHealer.java
+++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ComponentDataHealer.java
@@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.healing.healers;
import com.google.common.annotations.VisibleForTesting;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+import java.util.Collection;
+import java.util.Objects;
import org.apache.commons.lang.StringUtils;
import org.openecomp.sdc.healing.interfaces.Healer;
import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
@@ -26,14 +27,11 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
import org.openecomp.sdc.versioning.dao.types.Version;
-import java.util.Collection;
-import java.util.Objects;
-
public class ComponentDataHealer implements Healer {
private static final String VFC_CODE = "vfcCode"; //earlier present in composition data
private static final String NFC_FUNCTION = "nfcFunction";
- private static final String NFC_NAMING_CODE = "nfcNamingCode";
+ private static final String NFC_NAMING_CODE = "nfcNamingCode";
private static final String GENERAL = "general";
private final ComponentDao componentDao;
@@ -46,12 +44,22 @@ public class ComponentDataHealer implements Healer {
this.componentDao = componentDao;
}
+ private static void moveAttribute(JsonObject compositionJsonObj, JsonObject questJsonObject, JsonObject general, String compositionAttrName,
+ String questAttrName) {
+ if (Objects.nonNull(compositionJsonObj.get(compositionAttrName))) {
+ if (general == null) {
+ general = new JsonObject();
+ }
+ general.addProperty(questAttrName, compositionJsonObj.get(compositionAttrName).getAsString());
+ questJsonObject.add(GENERAL, general);
+ compositionJsonObj.remove(compositionAttrName);
+ }
+ }
+
@Override
public boolean isHealingNeeded(String itemId, Version version) {
- final Collection<ComponentEntity> componentEntities =
- componentDao.listCompositionAndQuestionnaire(itemId, version);
- return Objects.nonNull(componentEntities) && !componentEntities.isEmpty() &&
- componentEntities.stream().anyMatch(this::checkNfcParams);
+ final Collection<ComponentEntity> componentEntities = componentDao.listCompositionAndQuestionnaire(itemId, version);
+ return Objects.nonNull(componentEntities) && !componentEntities.isEmpty() && componentEntities.stream().anyMatch(this::checkNfcParams);
}
private boolean checkNfcParams(ComponentEntity componentEntity) {
@@ -66,8 +74,7 @@ public class ComponentDataHealer implements Healer {
@Override
public void heal(String itemId, Version version) throws Exception {
- final Collection<ComponentEntity> componentEntities =
- componentDao.listCompositionAndQuestionnaire(itemId, version);
+ final Collection<ComponentEntity> componentEntities = componentDao.listCompositionAndQuestionnaire(itemId, version);
if (Objects.nonNull(componentEntities) && !componentEntities.isEmpty()) {
componentEntities.forEach(componentEntity -> {
final String compositionData = componentEntity.getCompositionData();
@@ -76,32 +83,18 @@ public class ComponentDataHealer implements Healer {
}
}
- private void updateComponentData(String itemId, Version version, ComponentEntity componentEntity,
- String questionnaireData, String compositionData) {
+ private void updateComponentData(String itemId, Version version, ComponentEntity componentEntity, String questionnaireData,
+ String compositionData) {
if (!StringUtils.isEmpty(compositionData)) {
JsonParser jsonParser = new JsonParser();
JsonObject json = (JsonObject) jsonParser.parse(compositionData);
JsonObject questionnaireJson = (JsonObject) jsonParser.parse(questionnaireData);
- moveAttribute(json, questionnaireJson, questionnaireJson.getAsJsonObject(GENERAL), VFC_CODE,
- NFC_NAMING_CODE);
- moveAttribute(json, questionnaireJson, questionnaireJson.getAsJsonObject(GENERAL), NFC_FUNCTION,
- NFC_FUNCTION);
+ moveAttribute(json, questionnaireJson, questionnaireJson.getAsJsonObject(GENERAL), VFC_CODE, NFC_NAMING_CODE);
+ moveAttribute(json, questionnaireJson, questionnaireJson.getAsJsonObject(GENERAL), NFC_FUNCTION, NFC_FUNCTION);
componentEntity.setCompositionData(json.toString());
componentDao.update(componentEntity);
componentEntity.setQuestionnaireData(questionnaireJson.toString());
- componentDao.updateQuestionnaireData(itemId,version,componentEntity.getId(), questionnaireJson.toString());
- }
- }
-
- private static void moveAttribute(JsonObject compositionJsonObj, JsonObject questJsonObject,
- JsonObject general, String compositionAttrName, String questAttrName ) {
- if (Objects.nonNull(compositionJsonObj.get(compositionAttrName))) {
- if (general == null) {
- general = new JsonObject();
- }
- general.addProperty(questAttrName, compositionJsonObj.get(compositionAttrName).getAsString());
- questJsonObject.add(GENERAL, general);
- compositionJsonObj.remove(compositionAttrName);
+ componentDao.updateQuestionnaireData(itemId, version, componentEntity.getId(), questionnaireJson.toString());
}
}
}
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ManufacturerReferenceNumberHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ManufacturerReferenceNumberHealer.java
index 0416cc9479..e371463ef3 100644
--- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ManufacturerReferenceNumberHealer.java
+++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ManufacturerReferenceNumberHealer.java
@@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.healing.healers;
+import java.util.Collection;
+import java.util.Objects;
+import java.util.Set;
import org.openecomp.sdc.healing.interfaces.Healer;
import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao;
import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDaoFactory;
@@ -26,90 +28,71 @@ import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory;
import org.openecomp.sdc.versioning.dao.types.Version;
-import java.util.Collection;
-import java.util.Objects;
-import java.util.Set;
-
public class ManufacturerReferenceNumberHealer implements Healer {
- private static final String MANUFACTURER_REFERENCE_NUMBER = "MRN";
- private final VendorLicenseFacade vendorLicenseFacade;
- private final FeatureGroupDao featureGroupDao;
-
- public ManufacturerReferenceNumberHealer() {
- this(VendorLicenseFacadeFactory.getInstance().createInterface(), FeatureGroupDaoFactory
- .getInstance().createInterface());
- }
-
- public ManufacturerReferenceNumberHealer(VendorLicenseFacade vendorLicenseFacade,
- FeatureGroupDao featureGroupDao) {
- this.vendorLicenseFacade = vendorLicenseFacade;
- this.featureGroupDao = featureGroupDao;
- }
+ private static final String MANUFACTURER_REFERENCE_NUMBER = "MRN";
+ private final VendorLicenseFacade vendorLicenseFacade;
+ private final FeatureGroupDao featureGroupDao;
- @Override
- public boolean isHealingNeeded(String itemId, Version version) {
- return Objects.isNull(vendorLicenseFacade.listEntitlementPools
- (itemId, version).iterator().next().getManufacturerReferenceNumber()) ? true :
- false;
- }
-
- @Override
- public void heal(String itemId, Version version) throws Exception {
-
- healEntitlementPools(itemId, version);
- healLicenseKeyGroups(itemId, version);
- healFeatureGroups(itemId, version);
- }
-
- private void healEntitlementPools(String itemId, Version version) {
- Collection<EntitlementPoolEntity> entitlementPoolEntities = vendorLicenseFacade
- .listEntitlementPools(itemId, version);
-
- for (EntitlementPoolEntity entitlementPoolEntity : entitlementPoolEntities) {
- Set<String> referencingFeatureGroup = entitlementPoolEntity.getReferencingFeatureGroups();
+ public ManufacturerReferenceNumberHealer() {
+ this(VendorLicenseFacadeFactory.getInstance().createInterface(), FeatureGroupDaoFactory.getInstance().createInterface());
+ }
- if (referencingFeatureGroup.size() == 1) {
- entitlementPoolEntity.setManufacturerReferenceNumber(getMRN(itemId, version,
- referencingFeatureGroup));
- } else {
- entitlementPoolEntity.setManufacturerReferenceNumber(MANUFACTURER_REFERENCE_NUMBER);
- }
- vendorLicenseFacade.updateEntitlementPool(entitlementPoolEntity);
+ public ManufacturerReferenceNumberHealer(VendorLicenseFacade vendorLicenseFacade, FeatureGroupDao featureGroupDao) {
+ this.vendorLicenseFacade = vendorLicenseFacade;
+ this.featureGroupDao = featureGroupDao;
}
- }
- private void healLicenseKeyGroups(String itemId, Version version) {
- Collection<LicenseKeyGroupEntity> licenseKeyGroupEntities = vendorLicenseFacade
- .listLicenseKeyGroups(itemId, version);
+ @Override
+ public boolean isHealingNeeded(String itemId, Version version) {
+ return Objects.isNull(vendorLicenseFacade.listEntitlementPools(itemId, version).iterator().next().getManufacturerReferenceNumber()) ? true
+ : false;
+ }
- for (LicenseKeyGroupEntity licenseKeyGroupEntity : licenseKeyGroupEntities) {
- Set<String> referencingFeatureGroup = licenseKeyGroupEntity.getReferencingFeatureGroups();
- if (referencingFeatureGroup.size() == 1) {
- licenseKeyGroupEntity.setManufacturerReferenceNumber(getMRN(itemId, version,
- referencingFeatureGroup));
- } else {
- licenseKeyGroupEntity.setManufacturerReferenceNumber(MANUFACTURER_REFERENCE_NUMBER);
- }
- vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroupEntity);
+ @Override
+ public void heal(String itemId, Version version) throws Exception {
+ healEntitlementPools(itemId, version);
+ healLicenseKeyGroups(itemId, version);
+ healFeatureGroups(itemId, version);
}
- }
- private String getMRN(String itemId, Version
- version, Set<String> referencingFeatureGroup) {
- FeatureGroupEntity featureGroupEntity = vendorLicenseFacade.getFeatureGroup(new
- FeatureGroupEntity(itemId, version, referencingFeatureGroup.iterator().next()));
- return featureGroupEntity.getManufacturerReferenceNumber();
- }
+ private void healEntitlementPools(String itemId, Version version) {
+ Collection<EntitlementPoolEntity> entitlementPoolEntities = vendorLicenseFacade.listEntitlementPools(itemId, version);
+ for (EntitlementPoolEntity entitlementPoolEntity : entitlementPoolEntities) {
+ Set<String> referencingFeatureGroup = entitlementPoolEntity.getReferencingFeatureGroups();
+ if (referencingFeatureGroup.size() == 1) {
+ entitlementPoolEntity.setManufacturerReferenceNumber(getMRN(itemId, version, referencingFeatureGroup));
+ } else {
+ entitlementPoolEntity.setManufacturerReferenceNumber(MANUFACTURER_REFERENCE_NUMBER);
+ }
+ vendorLicenseFacade.updateEntitlementPool(entitlementPoolEntity);
+ }
+ }
- private void healFeatureGroups(String itemId, Version version) {
+ private void healLicenseKeyGroups(String itemId, Version version) {
+ Collection<LicenseKeyGroupEntity> licenseKeyGroupEntities = vendorLicenseFacade.listLicenseKeyGroups(itemId, version);
+ for (LicenseKeyGroupEntity licenseKeyGroupEntity : licenseKeyGroupEntities) {
+ Set<String> referencingFeatureGroup = licenseKeyGroupEntity.getReferencingFeatureGroups();
+ if (referencingFeatureGroup.size() == 1) {
+ licenseKeyGroupEntity.setManufacturerReferenceNumber(getMRN(itemId, version, referencingFeatureGroup));
+ } else {
+ licenseKeyGroupEntity.setManufacturerReferenceNumber(MANUFACTURER_REFERENCE_NUMBER);
+ }
+ vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroupEntity);
+ }
+ }
- Collection<FeatureGroupEntity> featureGroupEntities = vendorLicenseFacade.listFeatureGroups
- (itemId, version);
+ private String getMRN(String itemId, Version version, Set<String> referencingFeatureGroup) {
+ FeatureGroupEntity featureGroupEntity = vendorLicenseFacade
+ .getFeatureGroup(new FeatureGroupEntity(itemId, version, referencingFeatureGroup.iterator().next()));
+ return featureGroupEntity.getManufacturerReferenceNumber();
+ }
- for (FeatureGroupEntity featureGroupEntity : featureGroupEntities) {
- featureGroupEntity.setManufacturerReferenceNumber(null);
- featureGroupDao.update(featureGroupEntity);
+ private void healFeatureGroups(String itemId, Version version) {
+ Collection<FeatureGroupEntity> featureGroupEntities = vendorLicenseFacade.listFeatureGroups(itemId, version);
+ for (FeatureGroupEntity featureGroupEntity : featureGroupEntities) {
+ featureGroupEntity.setManufacturerReferenceNumber(null);
+ featureGroupDao.update(featureGroupEntity);
+ }
}
- }
}
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/NetworkPackageHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/NetworkPackageHealer.java
index 3b716da1ca..d4ce921133 100644
--- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/NetworkPackageHealer.java
+++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/NetworkPackageHealer.java
@@ -16,9 +16,12 @@
* Modifications copyright (c) 2019 Nokia
* ================================================================================
*/
-
package org.openecomp.sdc.healing.healers;
+import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement;
+import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
+import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
+
import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
@@ -27,6 +30,12 @@ import com.amdocs.zusammen.datatypes.SessionContext;
import com.amdocs.zusammen.datatypes.item.Action;
import com.amdocs.zusammen.datatypes.item.ElementContext;
import com.amdocs.zusammen.utils.fileutils.FileUtils;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.Objects;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
@@ -51,49 +60,31 @@ import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.
import org.openecomp.sdc.vendorsoftwareproduct.services.utils.CandidateEntityBuilder;
import org.openecomp.sdc.versioning.dao.types.Version;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.Objects;
-
-import static org.openecomp.core.zusammen.api.ZusammenUtil.*;
-
public class NetworkPackageHealer implements Healer {
private static final byte[] EMPTY_DATA_BYTES = "{}".getBytes();
- private static final String MISSING_ORCHESTRATION_TEMPLATE_CANDIDATE_ERROR =
- "Vsp with invalid structure: does not contain element OrchestrationTemplateCandidate";
+ private static final String MISSING_ORCHESTRATION_TEMPLATE_CANDIDATE_ERROR = "Vsp with invalid structure: does not contain element OrchestrationTemplateCandidate";
private static final String MISSING_ORCHESTRATION_TEMPLATE_CANDIDATE_CONTENT_ERROR =
- "Vsp with invalid structure: does not contain element OrchestrationTemplateCandidateContent"
- + " under OrchestrationTemplateCandidate";
-
- private static final String MISSING_VSP_MODEL_ERROR =
- "Vsp with invalid structure: does not contain element VspModel";
+ "Vsp with invalid structure: does not contain element OrchestrationTemplateCandidateContent" + " under OrchestrationTemplateCandidate";
+ private static final String MISSING_VSP_MODEL_ERROR = "Vsp with invalid structure: does not contain element VspModel";
private static final String MISSING_ORCHESTRATION_TEMPLATE_ERROR =
- "Vsp with invalid structure: does not contain element OrchestrationTemplate" + " under VspModel element";
+ "Vsp with invalid structure: does not contain element OrchestrationTemplate" + " under VspModel element";
private static final String MISSING_ORCHESTRATION_TEMPLATE_VALIDATE_DATA_ERROR =
- "Vsp with invalid structure: does not contain element OrchestrationTemplateValidationData"
- + " under OrchestrationTemplate element";
-
+ "Vsp with invalid structure: does not contain element OrchestrationTemplateValidationData" + " under OrchestrationTemplate element";
private final VendorSoftwareProductInfoDao vspInfoDao;
private final ZusammenAdaptor zusammenAdaptor;
private final CandidateEntityBuilder candidateEntityBuilder;
public NetworkPackageHealer() {
- this(VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(),
- ZusammenAdaptorFactory.getInstance().createInterface(),
- CandidateServiceFactory.getInstance().createInterface());
+ this(VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(), ZusammenAdaptorFactory.getInstance().createInterface(),
+ CandidateServiceFactory.getInstance().createInterface());
}
- private NetworkPackageHealer(VendorSoftwareProductInfoDao vspInfoDao, ZusammenAdaptor zusammenAdaptor,
- CandidateService candidateService) {
+ private NetworkPackageHealer(VendorSoftwareProductInfoDao vspInfoDao, ZusammenAdaptor zusammenAdaptor, CandidateService candidateService) {
this(vspInfoDao, zusammenAdaptor, new CandidateEntityBuilder(candidateService));
}
- NetworkPackageHealer(VendorSoftwareProductInfoDao vspInfoDao, ZusammenAdaptor zusammenAdaptor,
- CandidateEntityBuilder candidateEntityBuilder) {
+ NetworkPackageHealer(VendorSoftwareProductInfoDao vspInfoDao, ZusammenAdaptor zusammenAdaptor, CandidateEntityBuilder candidateEntityBuilder) {
this.vspInfoDao = vspInfoDao;
this.zusammenAdaptor = zusammenAdaptor;
this.candidateEntityBuilder = candidateEntityBuilder;
@@ -101,242 +92,170 @@ public class NetworkPackageHealer implements Healer {
@Override
public boolean isHealingNeeded(String itemId, Version version) {
- return OnboardingMethod.NetworkPackage.name()
- .equals(vspInfoDao.get(new VspDetails(itemId, version)).getOnboardingMethod())
- && isVspMissingAddedElements(itemId, version);
+ return OnboardingMethod.NetworkPackage.name().equals(vspInfoDao.get(new VspDetails(itemId, version)).getOnboardingMethod())
+ && isVspMissingAddedElements(itemId, version);
}
@Override
public void heal(String itemId, Version version) throws Exception {
SessionContext context = createSessionContext();
ElementContext elementContext = new ElementContext(itemId, version.getId());
-
Element candidateElement = getElement(context, elementContext, null, ElementType.OrchestrationTemplateCandidate,
- MISSING_ORCHESTRATION_TEMPLATE_CANDIDATE_ERROR);
-
- Collection<Element> candidateSubs =
- zusammenAdaptor.listElementData(context, elementContext, candidateElement.getElementId());
-
- Id candidateValidationElementId =
- creatIfAbsentCandidateValidationElementId(candidateSubs, context, elementContext, candidateElement);
-
+ MISSING_ORCHESTRATION_TEMPLATE_CANDIDATE_ERROR);
+ Collection<Element> candidateSubs = zusammenAdaptor.listElementData(context, elementContext, candidateElement.getElementId());
+ Id candidateValidationElementId = creatIfAbsentCandidateValidationElementId(candidateSubs, context, elementContext, candidateElement);
Element orchestrationTemplateElement = getOrchestrationTemplateElement(context, elementContext);
-
- Collection<Element> orchestrationTemplateSubs =
- zusammenAdaptor.listElementData(context, elementContext, orchestrationTemplateElement.getElementId());
-
- Id structureElementId = createIfAbsentStructureElementId(orchestrationTemplateSubs, context, elementContext,
- orchestrationTemplateElement);
-
- Element orchestrationTemplateValidationElement =
- getOrchestrationTemplateValidationElement(orchestrationTemplateSubs);
-
- OrchestrationTemplateEntity orchestrationTemplateEntity =
- getOrchestrationTemplateEntity(orchestrationTemplateElement, orchestrationTemplateValidationElement);
-
+ Collection<Element> orchestrationTemplateSubs = zusammenAdaptor
+ .listElementData(context, elementContext, orchestrationTemplateElement.getElementId());
+ Id structureElementId = createIfAbsentStructureElementId(orchestrationTemplateSubs, context, elementContext, orchestrationTemplateElement);
+ Element orchestrationTemplateValidationElement = getOrchestrationTemplateValidationElement(orchestrationTemplateSubs);
+ OrchestrationTemplateEntity orchestrationTemplateEntity = getOrchestrationTemplateEntity(orchestrationTemplateElement,
+ orchestrationTemplateValidationElement);
if (StringUtils.isEmpty(orchestrationTemplateEntity.getFileSuffix())) {
return;
}
-
Element candidateContentElement = getCandidateContentElement(candidateSubs);
-
VspDetails vspDetails = vspInfoDao.get(new VspDetails(itemId, version));
if (isEqual(orchestrationTemplateEntity, getCandidateData(candidateElement, candidateContentElement))) {
-
if (isProcessedEntityValid(orchestrationTemplateEntity)) {
- emptyStructureElementAndSub(context, elementContext, candidateElement.getElementId(),
- ElementType.OrchestrationTemplateCandidate, candidateContentElement.getElementId(),
- ElementType.OrchestrationTemplateCandidateContent);
-
- populateOrchestrationTemplateStructure(orchestrationTemplateElement.getData(), structureElementId,
- vspDetails, context, elementContext);
+ emptyStructureElementAndSub(context, elementContext, candidateElement.getElementId(), ElementType.OrchestrationTemplateCandidate,
+ candidateContentElement.getElementId(), ElementType.OrchestrationTemplateCandidateContent);
+ populateOrchestrationTemplateStructure(orchestrationTemplateElement.getData(), structureElementId, vspDetails, context,
+ elementContext);
} else {
- emptyStructureElementAndSub(context, elementContext, orchestrationTemplateElement.getElementId(),
- ElementType.OrchestrationTemplate, orchestrationTemplateValidationElement.getElementId(),
- ElementType.OrchestrationTemplateValidationData);
-
+ emptyStructureElementAndSub(context, elementContext, orchestrationTemplateElement.getElementId(), ElementType.OrchestrationTemplate,
+ orchestrationTemplateValidationElement.getElementId(), ElementType.OrchestrationTemplateValidationData);
populateCandidateValidationData(context, elementContext, candidateValidationElementId,
- orchestrationTemplateEntity.getValidationData());
+ orchestrationTemplateEntity.getValidationData());
}
} else {
- populateOrchestrationTemplateStructure(orchestrationTemplateElement.getData(), structureElementId,
- vspDetails, context, elementContext);
+ populateOrchestrationTemplateStructure(orchestrationTemplateElement.getData(), structureElementId, vspDetails, context, elementContext);
}
}
private boolean isVspMissingAddedElements(String vspId, Version version) {
SessionContext context = createSessionContext();
ElementContext elementContext = new ElementContext(vspId, version.getId());
-
- return zusammenAdaptor.listElementsByName(context, elementContext, null,
- ElementType.OrchestrationTemplateCandidate.name()).stream().noneMatch(
- candidateSub -> ElementType.OrchestrationTemplateCandidateValidationData.name()
- .equals(candidateSub.getInfo().getName()));
+ return zusammenAdaptor.listElementsByName(context, elementContext, null, ElementType.OrchestrationTemplateCandidate.name()).stream()
+ .noneMatch(candidateSub -> ElementType.OrchestrationTemplateCandidateValidationData.name().equals(candidateSub.getInfo().getName()));
}
private boolean isEqual(OrchestrationTemplateEntity orchestrationTemplateEntity,
- OrchestrationTemplateCandidateData orchestrationTemplateCandidateData) {
- return orchestrationTemplateEntity.getFileName().equals(orchestrationTemplateCandidateData.getFileName())
- && orchestrationTemplateEntity.getFileSuffix()
- .equals(orchestrationTemplateCandidateData.getFileSuffix());
+ OrchestrationTemplateCandidateData orchestrationTemplateCandidateData) {
+ return orchestrationTemplateEntity.getFileName().equals(orchestrationTemplateCandidateData.getFileName()) && orchestrationTemplateEntity
+ .getFileSuffix().equals(orchestrationTemplateCandidateData.getFileSuffix());
}
private boolean isProcessedEntityValid(OrchestrationTemplateEntity orchestrationTemplateEntity) {
return !orchestrationTemplateEntity.getValidationData().contains(ErrorLevel.ERROR.name());
}
- private void populateCandidateValidationData(SessionContext context, ElementContext elementContext,
- Id candidateValidationElementId, String validationData) {
- ZusammenElement candidateValidationElement =
- buildStructuralElement(ElementType.OrchestrationTemplateCandidateValidationData, Action.UPDATE);
+ private void populateCandidateValidationData(SessionContext context, ElementContext elementContext, Id candidateValidationElementId,
+ String validationData) {
+ ZusammenElement candidateValidationElement = buildStructuralElement(ElementType.OrchestrationTemplateCandidateValidationData, Action.UPDATE);
candidateValidationElement.setElementId(candidateValidationElementId);
candidateValidationElement.setData(new ByteArrayInputStream(validationData.getBytes()));
-
- zusammenAdaptor.saveElement(context, elementContext, candidateValidationElement,
- "Healed Orchestration Template Candidate Validation data");
+ zusammenAdaptor.saveElement(context, elementContext, candidateValidationElement, "Healed Orchestration Template Candidate Validation data");
}
- private void populateOrchestrationTemplateStructure(InputStream processedFile, Id structureElementId,
- VspDetails vspDetails, SessionContext context, ElementContext elementContext) throws Exception {
+ private void populateOrchestrationTemplateStructure(InputStream processedFile, Id structureElementId, VspDetails vspDetails,
+ SessionContext context, ElementContext elementContext) throws Exception {
byte[] byteData = FileUtils.toByteArray(processedFile);
FileContentHandler contentMap = CommonUtil.validateAndUploadFileContent(OnboardingTypesEnum.ZIP, byteData);
- OrchestrationTemplateCandidateData orchestrationTemplateEntityData =
- candidateEntityBuilder
- .buildCandidateEntityFromZip(vspDetails, byteData, contentMap, null);
+ OrchestrationTemplateCandidateData orchestrationTemplateEntityData = candidateEntityBuilder
+ .buildCandidateEntityFromZip(vspDetails, byteData, contentMap, null);
String fileDataStructure = orchestrationTemplateEntityData.getFilesDataStructure();
-
- ZusammenElement orchestrationTemplateStructure =
- buildStructuralElement(ElementType.OrchestrationTemplateStructure, Action.UPDATE);
+ ZusammenElement orchestrationTemplateStructure = buildStructuralElement(ElementType.OrchestrationTemplateStructure, Action.UPDATE);
orchestrationTemplateStructure.setElementId(structureElementId);
orchestrationTemplateStructure.setData(new ByteArrayInputStream(fileDataStructure.getBytes()));
-
- zusammenAdaptor.saveElement(context, elementContext, orchestrationTemplateStructure,
- "Healed Orchestration Template Structure");
+ zusammenAdaptor.saveElement(context, elementContext, orchestrationTemplateStructure, "Healed Orchestration Template Structure");
}
private Element getOrchestrationTemplateElement(SessionContext context, ElementContext elementContext) {
- ElementInfo vspModelElement =
- zusammenAdaptor.getElementInfoByName(context, elementContext, null, ElementType.VspModel.name())
- .orElseThrow(() -> new CoreException(
- new ErrorCode.ErrorCodeBuilder().withMessage(MISSING_VSP_MODEL_ERROR).build()));
-
- return getElement(context, elementContext, vspModelElement.getId(), ElementType.OrchestrationTemplate,
- MISSING_ORCHESTRATION_TEMPLATE_ERROR);
+ ElementInfo vspModelElement = zusammenAdaptor.getElementInfoByName(context, elementContext, null, ElementType.VspModel.name())
+ .orElseThrow(() -> new CoreException(new ErrorCode.ErrorCodeBuilder().withMessage(MISSING_VSP_MODEL_ERROR).build()));
+ return getElement(context, elementContext, vspModelElement.getId(), ElementType.OrchestrationTemplate, MISSING_ORCHESTRATION_TEMPLATE_ERROR);
}
private Element getOrchestrationTemplateValidationElement(Collection<Element> orchestrationTemplateSubs) {
- return orchestrationTemplateSubs.stream()
- .filter(orchestrationTemplateSub -> ElementType.OrchestrationTemplateValidationData.name()
- .equals(orchestrationTemplateSub.getInfo()
- .getName())).findFirst().orElseThrow(
- () -> new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withMessage(MISSING_ORCHESTRATION_TEMPLATE_VALIDATE_DATA_ERROR)
- .build()));
-
+ return orchestrationTemplateSubs.stream().filter(
+ orchestrationTemplateSub -> ElementType.OrchestrationTemplateValidationData.name().equals(orchestrationTemplateSub.getInfo().getName()))
+ .findFirst().orElseThrow(
+ () -> new CoreException(new ErrorCode.ErrorCodeBuilder().withMessage(MISSING_ORCHESTRATION_TEMPLATE_VALIDATE_DATA_ERROR).build()));
}
private Element getCandidateContentElement(Collection<Element> candidateSubs) {
- return candidateSubs.stream().filter(candidateSub -> ElementType.OrchestrationTemplateCandidateContent.name()
- .equals(candidateSub.getInfo().getName()))
- .findFirst().orElseThrow(() -> new CoreException(new ErrorCode.ErrorCodeBuilder().withMessage(
- MISSING_ORCHESTRATION_TEMPLATE_CANDIDATE_CONTENT_ERROR).build()));
+ return candidateSubs.stream()
+ .filter(candidateSub -> ElementType.OrchestrationTemplateCandidateContent.name().equals(candidateSub.getInfo().getName())).findFirst()
+ .orElseThrow(() -> new CoreException(
+ new ErrorCode.ErrorCodeBuilder().withMessage(MISSING_ORCHESTRATION_TEMPLATE_CANDIDATE_CONTENT_ERROR).build()));
}
- private Id createIfAbsentStructureElementId(Collection<Element> orchestrationTemplateSubs, SessionContext context,
- ElementContext elementContext, Element orchestrationTemplateElement) {
- return orchestrationTemplateSubs.stream()
- .filter(orchestrationTemplateSub -> ElementType.OrchestrationTemplateStructure.name()
- .equals(orchestrationTemplateSub.getInfo()
- .getName())).findFirst()
- .map(Element::getElementId).orElse(addStructureSubElement(context, elementContext,
- ElementType.OrchestrationTemplateStructure, orchestrationTemplateElement.getElementId()));
+ private Id createIfAbsentStructureElementId(Collection<Element> orchestrationTemplateSubs, SessionContext context, ElementContext elementContext,
+ Element orchestrationTemplateElement) {
+ return orchestrationTemplateSubs.stream().filter(
+ orchestrationTemplateSub -> ElementType.OrchestrationTemplateStructure.name().equals(orchestrationTemplateSub.getInfo().getName()))
+ .findFirst().map(Element::getElementId).orElse(addStructureSubElement(context, elementContext, ElementType.OrchestrationTemplateStructure,
+ orchestrationTemplateElement.getElementId()));
}
- private Id creatIfAbsentCandidateValidationElementId(Collection<Element> candidateSubs, SessionContext context,
- ElementContext elementContext, Element candidateElement) {
+ private Id creatIfAbsentCandidateValidationElementId(Collection<Element> candidateSubs, SessionContext context, ElementContext elementContext,
+ Element candidateElement) {
return candidateSubs.stream()
- .filter(candidateSub -> ElementType.OrchestrationTemplateCandidateValidationData.name()
- .equals(candidateSub.getInfo().getName())).findFirst()
- .map(Element::getElementId).orElse(addStructureSubElement(context, elementContext,
- ElementType.OrchestrationTemplateCandidateValidationData, candidateElement.getElementId()));
+ .filter(candidateSub -> ElementType.OrchestrationTemplateCandidateValidationData.name().equals(candidateSub.getInfo().getName()))
+ .findFirst().map(Element::getElementId).orElse(
+ addStructureSubElement(context, elementContext, ElementType.OrchestrationTemplateCandidateValidationData,
+ candidateElement.getElementId()));
}
- private Element getElement(SessionContext context, ElementContext elementContext, Id parentElementId,
- ElementType elementType, String errorMessage) {
+ private Element getElement(SessionContext context, ElementContext elementContext, Id parentElementId, ElementType elementType,
+ String errorMessage) {
return zusammenAdaptor.getElementByName(context, elementContext, parentElementId, elementType.name())
- .orElseThrow(() -> new CoreException(
- new ErrorCode.ErrorCodeBuilder().withMessage(errorMessage).build()));
+ .orElseThrow(() -> new CoreException(new ErrorCode.ErrorCodeBuilder().withMessage(errorMessage).build()));
}
- private OrchestrationTemplateEntity getOrchestrationTemplateEntity(Element orchestrationTemplateElement,
- Element validationDataElement) {
+ private OrchestrationTemplateEntity getOrchestrationTemplateEntity(Element orchestrationTemplateElement, Element validationDataElement) {
OrchestrationTemplateEntity orchestrationTemplateEntity = new OrchestrationTemplateEntity();
-
if (isNotEmpty(orchestrationTemplateElement.getData())) {
- orchestrationTemplateEntity
- .setContentData(ByteBuffer.wrap(FileUtils.toByteArray(orchestrationTemplateElement.getData())));
+ orchestrationTemplateEntity.setContentData(ByteBuffer.wrap(FileUtils.toByteArray(orchestrationTemplateElement.getData())));
}
- orchestrationTemplateEntity
- .setFileSuffix(validationDataElement.getInfo().getProperty(InfoPropertyName.FILE_SUFFIX.getVal()));
- orchestrationTemplateEntity
- .setFileName(validationDataElement.getInfo().getProperty(InfoPropertyName.FILE_NAME.getVal()));
+ orchestrationTemplateEntity.setFileSuffix(validationDataElement.getInfo().getProperty(InfoPropertyName.FILE_SUFFIX.getVal()));
+ orchestrationTemplateEntity.setFileName(validationDataElement.getInfo().getProperty(InfoPropertyName.FILE_NAME.getVal()));
if (isNotEmpty(validationDataElement.getData())) {
- orchestrationTemplateEntity
- .setValidationData(new String(FileUtils.toByteArray(validationDataElement.getData())));
+ orchestrationTemplateEntity.setValidationData(new String(FileUtils.toByteArray(validationDataElement.getData())));
}
return orchestrationTemplateEntity;
}
- private OrchestrationTemplateCandidateData getCandidateData(Element candidateElement,
- Element candidateContentElement) {
+ private OrchestrationTemplateCandidateData getCandidateData(Element candidateElement, Element candidateContentElement) {
OrchestrationTemplateCandidateData candidateData = new OrchestrationTemplateCandidateData();
candidateData.setFilesDataStructure(new String(FileUtils.toByteArray(candidateElement.getData())));
candidateData.setContentData(ByteBuffer.wrap(FileUtils.toByteArray(candidateContentElement.getData())));
- candidateData
- .setFileSuffix(candidateContentElement.getInfo().getProperty(InfoPropertyName.FILE_SUFFIX.getVal()));
+ candidateData.setFileSuffix(candidateContentElement.getInfo().getProperty(InfoPropertyName.FILE_SUFFIX.getVal()));
candidateData.setFileName(candidateContentElement.getInfo().getProperty(InfoPropertyName.FILE_NAME.getVal()));
return candidateData;
}
- private Id addStructureSubElement(SessionContext context, ElementContext elementContext, ElementType elementType,
- Id parentElementId) {
+ private Id addStructureSubElement(SessionContext context, ElementContext elementContext, ElementType elementType, Id parentElementId) {
ZusammenElement newElement = buildStructuralElement(elementType, Action.CREATE);
-
ZusammenElement parentElement = buildElement(parentElementId, Action.IGNORE);
parentElement.addSubElement(newElement);
-
return zusammenAdaptor.saveElement(context, elementContext, parentElement,
- String.format("Add element %s under element id %s", elementType.name(), parentElementId))
- .getSubElements().iterator().next().getElementId();
+ String.format("Add element %s under element id %s", elementType.name(), parentElementId)).getSubElements().iterator().next()
+ .getElementId();
}
- private void emptyStructureElementAndSub(SessionContext context, ElementContext elementContext, Id elementId,
- ElementType elementType, Id subElementId, ElementType subElementType) {
+ private void emptyStructureElementAndSub(SessionContext context, ElementContext elementContext, Id elementId, ElementType elementType,
+ Id subElementId, ElementType subElementType) {
ZusammenElement subElement = buildStructuralElement(subElementType, Action.UPDATE);
subElement.setElementId(subElementId);
subElement.setData(new ByteArrayInputStream(EMPTY_DATA_BYTES));
-
ZusammenElement element = buildStructuralElement(elementType, Action.UPDATE);
element.setElementId(elementId);
element.setData(new ByteArrayInputStream(EMPTY_DATA_BYTES));
element.addSubElement(subElement);
-
zusammenAdaptor.saveElement(context, elementContext, element,
- String.format("Empty element %s and its sub element %s", elementType.name(), subElementType.name()));
- }
-
- public enum InfoPropertyName {
- FILE_SUFFIX("fileSuffix"), FILE_NAME("fileName");
-
- private String val;
-
- InfoPropertyName(String val) {
- this.val = val;
- }
-
- private String getVal() {
- return val;
- }
+ String.format("Empty element %s and its sub element %s", elementType.name(), subElementType.name()));
}
private boolean isNotEmpty(InputStream elementData) {
@@ -351,4 +270,17 @@ public class NetworkPackageHealer implements Healer {
}
return !ArrayUtils.isEmpty(byteElementData);
}
+
+ public enum InfoPropertyName {
+ FILE_SUFFIX("fileSuffix"), FILE_NAME("fileName");
+ private String val;
+
+ InfoPropertyName(String val) {
+ this.val = val;
+ }
+
+ private String getVal() {
+ return val;
+ }
+ }
}
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/OwnerHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/OwnerHealer.java
index 9fcc6e5b74..2d89661d26 100644
--- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/OwnerHealer.java
+++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/OwnerHealer.java
@@ -7,9 +7,9 @@
* 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.
@@ -17,9 +17,13 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.healing.healers;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Optional;
import org.openecomp.sdc.common.errors.SdcRuntimeException;
import org.openecomp.sdc.common.session.SessionContextProviderFactory;
import org.openecomp.sdc.healing.interfaces.Healer;
@@ -34,70 +38,57 @@ import org.openecomp.sdc.versioning.dao.ItemDaoFactory;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.types.Item;
-import java.util.*;
-
/**
* Created by ayalaben on 8/28/2017
*/
public class OwnerHealer implements Healer {
- private static final String HEALING_USER_SUFFIX = "_healer";
- private static final ItemPermissionsDao permissionsDao =
- ItemPermissionsDaoFactory.getInstance().createInterface();
- private static final ItemDao itemDao = ItemDaoFactory.getInstance().createInterface();
-
- private static final SubscribersDao subscribersDao = SubscribersDaoFactory.getInstance()
- .createInterface();
-
- @Override
- public boolean isHealingNeeded(String itemId, Version version) {
- return permissionsDao.listItemPermissions(itemId).stream().noneMatch(this::isOwnerPermission) ||
- isOwnerMissingOnItem(itemId);
- }
-
- public void heal(String itemId, Version version) {
- Collection<ItemPermissionsEntity> itemPermissions = permissionsDao.listItemPermissions(itemId);
- if (itemPermissions.stream().noneMatch(this::isOwnerPermission)) {
- String currentUserId =
- SessionContextProviderFactory.getInstance().createInterface().get().getUser().getUserId()
- .replace(HEALING_USER_SUFFIX, "");
+ private static final String HEALING_USER_SUFFIX = "_healer";
+ private static final ItemPermissionsDao permissionsDao = ItemPermissionsDaoFactory.getInstance().createInterface();
+ private static final ItemDao itemDao = ItemDaoFactory.getInstance().createInterface();
+ private static final SubscribersDao subscribersDao = SubscribersDaoFactory.getInstance().createInterface();
- permissionsDao.updateItemPermissions(itemId, PermissionTypes.Owner.name(),
- Collections.singleton(currentUserId), new HashSet<>());
-
- updateItemOwner(itemId, currentUserId);
-
- subscribersDao.subscribe(currentUserId, itemId);
+ @Override
+ public boolean isHealingNeeded(String itemId, Version version) {
+ return permissionsDao.listItemPermissions(itemId).stream().noneMatch(this::isOwnerPermission) || isOwnerMissingOnItem(itemId);
+ }
- } else if (isOwnerMissingOnItem(itemId)) {
- Optional<ItemPermissionsEntity> ownerOpt =
- itemPermissions.stream().filter(this::isOwnerPermission).findFirst();
- if (ownerOpt.isPresent()) {
- updateItemOwner(itemId, ownerOpt.get().getUserId());
- } else {
- throw new SdcRuntimeException("Unexpected error in Owner Healer. Item id: " + itemId);
- }
+ public void heal(String itemId, Version version) {
+ Collection<ItemPermissionsEntity> itemPermissions = permissionsDao.listItemPermissions(itemId);
+ if (itemPermissions.stream().noneMatch(this::isOwnerPermission)) {
+ String currentUserId = SessionContextProviderFactory.getInstance().createInterface().get().getUser().getUserId()
+ .replace(HEALING_USER_SUFFIX, "");
+ permissionsDao.updateItemPermissions(itemId, PermissionTypes.Owner.name(), Collections.singleton(currentUserId), new HashSet<>());
+ updateItemOwner(itemId, currentUserId);
+ subscribersDao.subscribe(currentUserId, itemId);
+ } else if (isOwnerMissingOnItem(itemId)) {
+ Optional<ItemPermissionsEntity> ownerOpt = itemPermissions.stream().filter(this::isOwnerPermission).findFirst();
+ if (ownerOpt.isPresent()) {
+ updateItemOwner(itemId, ownerOpt.get().getUserId());
+ } else {
+ throw new SdcRuntimeException("Unexpected error in Owner Healer. Item id: " + itemId);
+ }
+ }
}
- }
- private void updateItemOwner(String itemId, String userId) {
- Item item = new Item();
- item.setId(itemId);
- Item retrievedItem = itemDao.get(item);
- if (Objects.nonNull(retrievedItem)) {
- retrievedItem.setOwner(userId);
- itemDao.update(retrievedItem);
+ private void updateItemOwner(String itemId, String userId) {
+ Item item = new Item();
+ item.setId(itemId);
+ Item retrievedItem = itemDao.get(item);
+ if (Objects.nonNull(retrievedItem)) {
+ retrievedItem.setOwner(userId);
+ itemDao.update(retrievedItem);
+ }
}
- }
- private boolean isOwnerMissingOnItem(String itemId) {
- Item item = new Item();
- item.setId(itemId);
- Item retrievedItem = itemDao.get(item);
- return Objects.nonNull(retrievedItem) && Objects.isNull(retrievedItem.getOwner());
- }
+ private boolean isOwnerMissingOnItem(String itemId) {
+ Item item = new Item();
+ item.setId(itemId);
+ Item retrievedItem = itemDao.get(item);
+ return Objects.nonNull(retrievedItem) && Objects.isNull(retrievedItem.getOwner());
+ }
- private boolean isOwnerPermission(ItemPermissionsEntity permissionsEntity) {
- return permissionsEntity.getPermission().equals(PermissionTypes.Owner.name());
- }
+ private boolean isOwnerPermission(ItemPermissionsEntity permissionsEntity) {
+ return permissionsEntity.getPermission().equals(PermissionTypes.Owner.name());
+ }
}
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ToscaServiceModelHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ToscaServiceModelHealer.java
index 1aed46163d..b65629002a 100644
--- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ToscaServiceModelHealer.java
+++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ToscaServiceModelHealer.java
@@ -7,9 +7,9 @@
* 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.
@@ -17,9 +17,11 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.healing.healers;
+import java.io.IOException;
+import java.util.Objects;
+import java.util.Optional;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.converter.ToscaConverter;
import org.openecomp.core.converter.factory.ToscaConverterFactory;
@@ -40,99 +42,73 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDaoFacto
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity;
import org.openecomp.sdc.versioning.dao.types.Version;
-import java.io.IOException;
-import java.util.Objects;
-import java.util.Optional;
-
public class ToscaServiceModelHealer implements Healer {
- private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
- private OrchestrationTemplateDao orchestrationTemplateDao;
- private static final String VALIDATION_FAILURE_MESSAGE = "Product was updated. Please " +
- "update the uploaded Heat file according to these validation errors: \n";
-
- public ToscaServiceModelHealer() {
- this.serviceModelDao = ServiceModelDaoFactory.getInstance().createInterface();
- this.orchestrationTemplateDao = OrchestrationTemplateDaoFactory.getInstance().createInterface();
- }
-
- public ToscaServiceModelHealer(
- ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao,
- OrchestrationTemplateDao orchestrationTemplateDao) {
- this.serviceModelDao = serviceModelDao;
- this.orchestrationTemplateDao = orchestrationTemplateDao;
- }
-
- @Override
- public boolean isHealingNeeded(String itemId, Version version) {
- OrchestrationTemplateEntity orchestrationTemplate =
- orchestrationTemplateDao.get(itemId, version);
- OnboardingTypesEnum onboardingTypes =
- OnboardingTypesEnum.getOnboardingTypesEnum(orchestrationTemplate.getFileSuffix());
- return Objects.nonNull(onboardingTypes) &&
- Objects.nonNull(orchestrationTemplate.getContentData());
- }
+ private static final String VALIDATION_FAILURE_MESSAGE =
+ "Product was updated. Please " + "update the uploaded Heat file according to these validation errors: \n";
+ private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
+ private OrchestrationTemplateDao orchestrationTemplateDao;
- @Override
- public void heal(String itemId, Version version) throws Exception {
- OrchestrationTemplateEntity orchestrationTemplateEntity =
- orchestrationTemplateDao.get(itemId, version);
- OnboardingTypesEnum type =
- OnboardingTypesEnum.getOnboardingTypesEnum(orchestrationTemplateEntity.getFileSuffix());
-
- Optional<ToscaServiceModel> healedServiceModel =
- healServiceModel(orchestrationTemplateEntity, type);
-
- healedServiceModel.ifPresent(serviceModel -> serviceModelDao
- .overrideServiceModel(itemId, version, serviceModel));
- }
-
- private Optional<ToscaServiceModel> healServiceModel(
- OrchestrationTemplateEntity orchestrationTemplateEntity,
- OnboardingTypesEnum type) throws IOException {
- switch (type) {
- case ZIP:
- return Optional.of(healServiceModelFromZip(
- getFileContentHandlerForHealing(orchestrationTemplateEntity, type)));
+ public ToscaServiceModelHealer() {
+ this.serviceModelDao = ServiceModelDaoFactory.getInstance().createInterface();
+ this.orchestrationTemplateDao = OrchestrationTemplateDaoFactory.getInstance().createInterface();
+ }
- case CSAR:
- return Optional.of(healServiceModelFromCsar(
- getFileContentHandlerForHealing(orchestrationTemplateEntity, type)));
+ public ToscaServiceModelHealer(ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao,
+ OrchestrationTemplateDao orchestrationTemplateDao) {
+ this.serviceModelDao = serviceModelDao;
+ this.orchestrationTemplateDao = orchestrationTemplateDao;
+ }
- default:
- return Optional.empty();
+ @Override
+ public boolean isHealingNeeded(String itemId, Version version) {
+ OrchestrationTemplateEntity orchestrationTemplate = orchestrationTemplateDao.get(itemId, version);
+ OnboardingTypesEnum onboardingTypes = OnboardingTypesEnum.getOnboardingTypesEnum(orchestrationTemplate.getFileSuffix());
+ return Objects.nonNull(onboardingTypes) && Objects.nonNull(orchestrationTemplate.getContentData());
}
- }
- private FileContentHandler getFileContentHandlerForHealing(
- OrchestrationTemplateEntity orchestrationTemplateEntity, OnboardingTypesEnum type)
- throws IOException {
- byte[] uploadedFileContent = orchestrationTemplateEntity.getContentData().array();
- return CommonUtil.validateAndUploadFileContent(type, uploadedFileContent);
- }
+ @Override
+ public void heal(String itemId, Version version) throws Exception {
+ OrchestrationTemplateEntity orchestrationTemplateEntity = orchestrationTemplateDao.get(itemId, version);
+ OnboardingTypesEnum type = OnboardingTypesEnum.getOnboardingTypesEnum(orchestrationTemplateEntity.getFileSuffix());
+ Optional<ToscaServiceModel> healedServiceModel = healServiceModel(orchestrationTemplateEntity, type);
+ healedServiceModel.ifPresent(serviceModel -> serviceModelDao.overrideServiceModel(itemId, version, serviceModel));
+ }
- private ToscaServiceModel healServiceModelFromZip(FileContentHandler contentMap) {
- TranslatorOutput translatorOutput =
- HeatToToscaUtil.loadAndTranslateTemplateData(contentMap);
+ private Optional<ToscaServiceModel> healServiceModel(OrchestrationTemplateEntity orchestrationTemplateEntity, OnboardingTypesEnum type)
+ throws IOException {
+ switch (type) {
+ case ZIP:
+ return Optional.of(healServiceModelFromZip(getFileContentHandlerForHealing(orchestrationTemplateEntity, type)));
+ case CSAR:
+ return Optional.of(healServiceModelFromCsar(getFileContentHandlerForHealing(orchestrationTemplateEntity, type)));
+ default:
+ return Optional.empty();
+ }
+ }
- if (areThereValidationErrors(translatorOutput)) {
- String validationErrorsAsString = MessageContainerUtil.getErrorMessagesListAsString
- (MessageContainerUtil
- .getMessageByLevel(ErrorLevel.ERROR, translatorOutput.getErrorMessages()));
- throw new RuntimeException(VALIDATION_FAILURE_MESSAGE + validationErrorsAsString);
+ private FileContentHandler getFileContentHandlerForHealing(OrchestrationTemplateEntity orchestrationTemplateEntity, OnboardingTypesEnum type)
+ throws IOException {
+ byte[] uploadedFileContent = orchestrationTemplateEntity.getContentData().array();
+ return CommonUtil.validateAndUploadFileContent(type, uploadedFileContent);
}
- return translatorOutput.getToscaServiceModel();
- }
+ private ToscaServiceModel healServiceModelFromZip(FileContentHandler contentMap) {
+ TranslatorOutput translatorOutput = HeatToToscaUtil.loadAndTranslateTemplateData(contentMap);
+ if (areThereValidationErrors(translatorOutput)) {
+ String validationErrorsAsString = MessageContainerUtil
+ .getErrorMessagesListAsString(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, translatorOutput.getErrorMessages()));
+ throw new RuntimeException(VALIDATION_FAILURE_MESSAGE + validationErrorsAsString);
+ }
+ return translatorOutput.getToscaServiceModel();
+ }
- private boolean areThereValidationErrors(TranslatorOutput translatorOutput) {
- return MapUtils.isNotEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR,
- translatorOutput.getErrorMessages()));
- }
+ private boolean areThereValidationErrors(TranslatorOutput translatorOutput) {
+ return MapUtils.isNotEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, translatorOutput.getErrorMessages()));
+ }
- private ToscaServiceModel healServiceModelFromCsar(FileContentHandler contentMap)
- throws IOException {
- ToscaConverter toscaConverter = ToscaConverterFactory.getInstance().createInterface();
- return toscaConverter.convert(contentMap);
- }
+ private ToscaServiceModel healServiceModelFromCsar(FileContentHandler contentMap) throws IOException {
+ ToscaConverter toscaConverter = ToscaConverterFactory.getInstance().createInterface();
+ return toscaConverter.convert(contentMap);
+ }
}