From c3322117d0aba0a00feaf9126a579f233318d013 Mon Sep 17 00:00:00 2001 From: talig Date: Wed, 30 May 2018 11:57:05 +0300 Subject: Refactor get vsp questionnaire To prevent NullPointerException for old vsps with missing data Change-Id: Ieb549080d5e048ae3424a35b74c9c15c25e20628 Issue-ID: SDC-1384 Signed-off-by: talig --- .../VendorSoftwareProductInfoDaoZusammenImpl.java | 52 ++++++++++++---------- .../ElementToVSPQuestionnaireConvertor.java | 18 +++----- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VendorSoftwareProductInfoDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VendorSoftwareProductInfoDaoZusammenImpl.java index 482536342b..e1be8b9dec 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VendorSoftwareProductInfoDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/VendorSoftwareProductInfoDaoZusammenImpl.java @@ -15,22 +15,17 @@ */ package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen; -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.ZusammenElement; import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.item.Action; import com.amdocs.zusammen.datatypes.item.ElementContext; import com.amdocs.zusammen.datatypes.item.Info; -import java.io.ByteArrayInputStream; -import java.util.Collection; -import java.util.stream.Collectors; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.datatypes.model.ElementType; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToVSPGeneralConvertor; import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToVSPQuestionnaireConvertor; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OnboardingMethod; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; import org.openecomp.sdc.versioning.ActionVersioningManagerFactory; @@ -38,6 +33,13 @@ import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; import org.openecomp.sdc.versioning.types.VersionableEntityStoreType; +import java.io.ByteArrayInputStream; +import java.util.Collection; +import java.util.stream.Collectors; + +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + public class VendorSoftwareProductInfoDaoZusammenImpl implements VendorSoftwareProductInfoDao { private static final String EMPTY_DATA = "{}"; @@ -171,13 +173,15 @@ public class VendorSoftwareProductInfoDaoZusammenImpl implements VendorSoftwareP SessionContext context = createSessionContext(); ElementContext elementContext = new ElementContext(vspDetails.getId(), vspDetails.getVersion().getId()); - VspDetails vsp = zusammenAdaptor.getElementInfoByName(context, elementContext, null, + return zusammenAdaptor.getElementInfoByName(context, elementContext, null, ElementType.VendorSoftwareProduct.name()) .map(new ElementToVSPGeneralConvertor()::convert) + .map(vsp -> { + vsp.setId(vspDetails.getId()); + vsp.setVersion(vspDetails.getVersion()); + return vsp; + }) .orElse(null); - vsp.setId(vspDetails.getId()); - vsp.setVersion(vspDetails.getVersion()); - return vsp; } @Override @@ -204,12 +208,11 @@ public class VendorSoftwareProductInfoDaoZusammenImpl implements VendorSoftwareP @Override public VspQuestionnaireEntity getQuestionnaire(String vspId, Version version) { - SessionContext context = createSessionContext(); - ElementToVSPQuestionnaireConvertor convertor = new ElementToVSPQuestionnaireConvertor(); - VspQuestionnaireEntity entity = convertor.convert(zusammenAdaptor + VspQuestionnaireEntity entity = new ElementToVSPQuestionnaireConvertor().convert(zusammenAdaptor .getElementByName(context, new ElementContext(vspId, version.getId()), null, - ElementType.VSPQuestionnaire.name()).map(element -> element).orElse(null)); + ElementType.VSPQuestionnaire.name()) + .orElse(null)); entity.setId(vspId); entity.setVersion(version); return entity; @@ -218,10 +221,8 @@ public class VendorSoftwareProductInfoDaoZusammenImpl implements VendorSoftwareP @Override public boolean isManual(String vspId, Version version) { final VspDetails vspDetails = get(new VspDetails(vspId, version)); - if (vspDetails != null && "Manual".equals(vspDetails.getOnboardingMethod())) { - return true; - } - return false; + return vspDetails != null && + OnboardingMethod.Manual.name().equals(vspDetails.getOnboardingMethod()); } private ZusammenElement mapVspDetailsToZusammenElement(VspDetails vspDetails, Action action) { @@ -247,11 +248,14 @@ public class VendorSoftwareProductInfoDaoZusammenImpl implements VendorSoftwareP info.addProperty(InfoPropertyName.VENDOR_ID.getValue(), vspDetails.getVendorId()); info.addProperty(InfoPropertyName.VENDOR_NAME.getValue(), vspDetails.getVendorName()); if (vspDetails.getVlmVersion() != null) { - info.addProperty(InfoPropertyName.VENDOR_VERSION.getValue(), vspDetails.getVlmVersion().getId()); + info.addProperty(InfoPropertyName.VENDOR_VERSION.getValue(), + vspDetails.getVlmVersion().getId()); } - info.addProperty(InfoPropertyName.LICENSE_AGREEMENT.getValue(), vspDetails.getLicenseAgreement()); + info.addProperty(InfoPropertyName.LICENSE_AGREEMENT.getValue(), + vspDetails.getLicenseAgreement()); info.addProperty(InfoPropertyName.FEATURE_GROUPS.getValue(), vspDetails.getFeatureGroups()); - info.addProperty(InfoPropertyName.ON_BOARDING_METHOD.getValue(), vspDetails.getOnboardingMethod()); + info.addProperty(InfoPropertyName.ON_BOARDING_METHOD.getValue(), + vspDetails.getOnboardingMethod()); } public enum InfoPropertyName { @@ -269,11 +273,11 @@ public class VendorSoftwareProductInfoDaoZusammenImpl implements VendorSoftwareP private String value; - InfoPropertyName(String value){ - this.value=value; + InfoPropertyName(String value) { + this.value = value; } - public String getValue(){ + public String getValue() { return value; } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/convertor/ElementToVSPQuestionnaireConvertor.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/convertor/ElementToVSPQuestionnaireConvertor.java index 1dffe7e979..b8797cf8e2 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/convertor/ElementToVSPQuestionnaireConvertor.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/convertor/ElementToVSPQuestionnaireConvertor.java @@ -4,9 +4,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. @@ -21,17 +21,13 @@ import com.amdocs.zusammen.utils.fileutils.FileUtils; import org.openecomp.convertor.ElementConvertor; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; -public class ElementToVSPQuestionnaireConvertor extends ElementConvertor { - +public class ElementToVSPQuestionnaireConvertor extends ElementConvertor { + @Override - public VspQuestionnaireEntity convert( Element element) { - - if(element == null) { - return null; - } - + public VspQuestionnaireEntity convert(Element element) { VspQuestionnaireEntity entity = new VspQuestionnaireEntity(); - entity.setQuestionnaireData(new String(FileUtils.toByteArray(element.getData()))); + entity.setQuestionnaireData( + element == null ? "{}" : new String(FileUtils.toByteArray(element.getData()))); return entity; } } -- cgit 1.2.3-korg