diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl')
21 files changed, 1111 insertions, 1506 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/EntitlementPoolDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/EntitlementPoolDaoFactoryImpl.java index bcabffb4cd..c456fc5339 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/EntitlementPoolDaoFactoryImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/EntitlementPoolDaoFactoryImpl.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorlicense.dao.impl; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; @@ -21,13 +20,12 @@ import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao; import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDaoFactory; import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.EntitlementPoolZusammenDaoImpl; - public class EntitlementPoolDaoFactoryImpl extends EntitlementPoolDaoFactory { - private static EntitlementPoolDao instance = new EntitlementPoolZusammenDaoImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public EntitlementPoolDao createInterface() { - return instance; - } + private static EntitlementPoolDao instance = new EntitlementPoolZusammenDaoImpl(ZusammenAdaptorFactory.getInstance().createInterface()); + + @Override + public EntitlementPoolDao createInterface() { + return instance; + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/FeatureGroupDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/FeatureGroupDaoFactoryImpl.java index ca0e090567..295f3c82a1 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/FeatureGroupDaoFactoryImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/FeatureGroupDaoFactoryImpl.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorlicense.dao.impl; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; @@ -21,13 +20,12 @@ import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao; import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDaoFactory; import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.FeatureGroupDaoZusammenImpl; - public class FeatureGroupDaoFactoryImpl extends FeatureGroupDaoFactory { - private static FeatureGroupDao instance = new FeatureGroupDaoZusammenImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public FeatureGroupDao createInterface() { - return instance; - } + private static FeatureGroupDao instance = new FeatureGroupDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface()); + + @Override + public FeatureGroupDao createInterface() { + return instance; + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LicenseAgreementDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LicenseAgreementDaoFactoryImpl.java index 25a5f69f02..3a18f6a92e 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LicenseAgreementDaoFactoryImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LicenseAgreementDaoFactoryImpl.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorlicense.dao.impl; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; @@ -22,12 +21,11 @@ import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDaoFactory; import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.LicenseAgreementDaoZusammenImpl; public class LicenseAgreementDaoFactoryImpl extends LicenseAgreementDaoFactory { - - private static final LicenseAgreementDao INSTANCE = new LicenseAgreementDaoZusammenImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public LicenseAgreementDao createInterface() { - return INSTANCE; - } + private static final LicenseAgreementDao INSTANCE = new LicenseAgreementDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface()); + + @Override + public LicenseAgreementDao createInterface() { + return INSTANCE; + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LicenseKeyGroupDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LicenseKeyGroupDaoFactoryImpl.java index fbe7dd517e..fe614d8d28 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LicenseKeyGroupDaoFactoryImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LicenseKeyGroupDaoFactoryImpl.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorlicense.dao.impl; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; @@ -22,11 +21,11 @@ import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDaoFactory; import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.LicenseKeyGroupZusammenDaoImpl; public class LicenseKeyGroupDaoFactoryImpl extends LicenseKeyGroupDaoFactory { - private static final LicenseKeyGroupDao INSTANCE = new LicenseKeyGroupZusammenDaoImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public LicenseKeyGroupDao createInterface() { - return INSTANCE; - } + private static final LicenseKeyGroupDao INSTANCE = new LicenseKeyGroupZusammenDaoImpl(ZusammenAdaptorFactory.getInstance().createInterface()); + + @Override + public LicenseKeyGroupDao createInterface() { + return INSTANCE; + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LimitDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LimitDaoFactoryImpl.java index bad6d3299f..980fc557a2 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LimitDaoFactoryImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LimitDaoFactoryImpl.java @@ -26,11 +26,10 @@ import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.LimitZusammenDaoImpl; public class LimitDaoFactoryImpl extends LimitDaoFactory { - private static final LimitDao INSTANCE = new LimitZusammenDaoImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); + private static final LimitDao INSTANCE = new LimitZusammenDaoImpl(ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public LimitDao createInterface() { - return INSTANCE; - } + @Override + public LimitDao createInterface() { + return INSTANCE; + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/VendorLicenseModelDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/VendorLicenseModelDaoFactoryImpl.java index 79d0677da7..6cdec701c1 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/VendorLicenseModelDaoFactoryImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/VendorLicenseModelDaoFactoryImpl.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,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorlicense.dao.impl; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; @@ -27,11 +26,10 @@ import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VendorLicenseModelDaoZu public class VendorLicenseModelDaoFactoryImpl extends VendorLicenseModelDaoFactory { - private static VendorLicenseModelDao INSTANCE = new VendorLicenseModelDaoZusammenImpl( - ZusammenAdaptorFactory.getInstance().createInterface()); + private static VendorLicenseModelDao INSTANCE = new VendorLicenseModelDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface()); - @Override - public VendorLicenseModelDao createInterface() { - return INSTANCE; - } + @Override + public VendorLicenseModelDao createInterface() { + return INSTANCE; + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/ElementPropertyName.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/ElementPropertyName.java index 4b81cfcd87..540bf50362 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/ElementPropertyName.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/ElementPropertyName.java @@ -19,7 +19,4 @@ */ package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; -public enum ElementPropertyName { - type, - compositionData -} +public enum ElementPropertyName {type, compositionData} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/ElementType.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/ElementType.java index 6807476605..4dd9ac22e5 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/ElementType.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/ElementType.java @@ -19,7 +19,4 @@ */ package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; -public enum ElementType { - Limit - -} +public enum ElementType {Limit} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/EntitlementPoolZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/EntitlementPoolZusammenDaoImpl.java index e084cf1c1b..aa90df8389 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/EntitlementPoolZusammenDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/EntitlementPoolZusammenDaoImpl.java @@ -19,6 +19,8 @@ */ package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; + 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 +29,11 @@ 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.util.ArrayList; +import java.util.Collection; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.core.zusammen.api.ZusammenUtil; import org.openecomp.sdc.datatypes.model.ElementType; @@ -35,228 +42,162 @@ import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToEnti import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; import org.openecomp.types.ElementPropertyName; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; - -import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; - public class EntitlementPoolZusammenDaoImpl implements EntitlementPoolDao { - private ZusammenAdaptor zusammenAdaptor; - - public EntitlementPoolZusammenDaoImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } - - @Override - public void registerVersioning(String versionableEntityType) { - //no need - } - - @Override - public void create(EntitlementPoolEntity entitlementPool) { - ZusammenElement entitlementPoolElement = - buildEntitlementPoolElement(entitlementPool, Action.CREATE); - - ZusammenElement entitlementPoolsElement = - ZusammenUtil.buildStructuralElement(ElementType.EntitlementPools, Action.IGNORE); - - ZusammenElement limitsElement = - ZusammenUtil.buildStructuralElement(ElementType.Limits, Action.CREATE); - - entitlementPoolElement.addSubElement(limitsElement); - entitlementPoolsElement.addSubElement(entitlementPoolElement); - - SessionContext context = ZusammenUtil.createSessionContext(); - Element epsSavedElement = zusammenAdaptor.saveElement(context, - new ElementContext(entitlementPool.getVendorLicenseModelId(), - entitlementPool.getVersion().getId()), - entitlementPoolsElement, "Create entitlement pool"); + private ZusammenAdaptor zusammenAdaptor; - entitlementPool - .setId(epsSavedElement.getSubElements().iterator().next().getElementId().getValue()); - } - - @Override - public void update(EntitlementPoolEntity entitlementPool) { - ZusammenElement entitlmentpoolElement = - buildEntitlementPoolElement(entitlementPool, Action.UPDATE); - - SessionContext context = ZusammenUtil.createSessionContext(); - ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), - entitlementPool.getVersion().getId()); - - Optional<ElementInfo> epFromDb = zusammenAdaptor.getElementInfo(context, elementContext, - new Id(entitlementPool.getId())); + public EntitlementPoolZusammenDaoImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } - if (epFromDb.isPresent()) { - if (entitlmentpoolElement.getRelations() == null) { - entitlmentpoolElement.setRelations(new ArrayList<>()); - } - if (epFromDb.get().getRelations() != null && !epFromDb.get().getRelations().isEmpty()) { - entitlmentpoolElement.getRelations().addAll(epFromDb.get().getRelations()); - } + @Override + public void registerVersioning(String versionableEntityType) { + //no need } - zusammenAdaptor.saveElement(context, elementContext, entitlmentpoolElement, - String.format("Update entitlement pool with id %s", entitlementPool.getId())); - } + @Override + public void create(EntitlementPoolEntity entitlementPool) { + ZusammenElement entitlementPoolElement = buildEntitlementPoolElement(entitlementPool, Action.CREATE); + ZusammenElement entitlementPoolsElement = ZusammenUtil.buildStructuralElement(ElementType.EntitlementPools, Action.IGNORE); + ZusammenElement limitsElement = ZusammenUtil.buildStructuralElement(ElementType.Limits, Action.CREATE); + entitlementPoolElement.addSubElement(limitsElement); + entitlementPoolsElement.addSubElement(entitlementPoolElement); + SessionContext context = ZusammenUtil.createSessionContext(); + Element epsSavedElement = zusammenAdaptor + .saveElement(context, new ElementContext(entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().getId()), + entitlementPoolsElement, "Create entitlement pool"); + entitlementPool.setId(epsSavedElement.getSubElements().iterator().next().getElementId().getValue()); + } - @Override - public EntitlementPoolEntity get(EntitlementPoolEntity entitlementPool) { - SessionContext context = ZusammenUtil.createSessionContext(); - ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), - entitlementPool.getVersion().getId()); - ElementToEntitlementPoolConvertor convertor = new ElementToEntitlementPoolConvertor(); - return zusammenAdaptor.getElementInfo(context, elementContext, new Id(entitlementPool.getId())) - .map(elementInfo -> { - EntitlementPoolEntity entity = convertor.convert(elementInfo); - entity.setVendorLicenseModelId(entitlementPool.getVendorLicenseModelId()); - entity.setVersion(entitlementPool.getVersion()); - return entity; - }) - .orElse(null); - } + @Override + public void update(EntitlementPoolEntity entitlementPool) { + ZusammenElement entitlmentpoolElement = buildEntitlementPoolElement(entitlementPool, Action.UPDATE); + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().getId()); + Optional<ElementInfo> epFromDb = zusammenAdaptor.getElementInfo(context, elementContext, new Id(entitlementPool.getId())); + if (epFromDb.isPresent()) { + if (entitlmentpoolElement.getRelations() == null) { + entitlmentpoolElement.setRelations(new ArrayList<>()); + } + if (epFromDb.get().getRelations() != null && !epFromDb.get().getRelations().isEmpty()) { + entitlmentpoolElement.getRelations().addAll(epFromDb.get().getRelations()); + } + } + zusammenAdaptor.saveElement(context, elementContext, entitlmentpoolElement, + String.format("Update entitlement pool with id %s", entitlementPool.getId())); + } - @Override - public void delete(EntitlementPoolEntity entitlementPool) { - ZusammenElement zusammenElement = buildElement(new Id(entitlementPool.getId()), Action.DELETE); + @Override + public EntitlementPoolEntity get(EntitlementPoolEntity entitlementPool) { + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().getId()); + ElementToEntitlementPoolConvertor convertor = new ElementToEntitlementPoolConvertor(); + return zusammenAdaptor.getElementInfo(context, elementContext, new Id(entitlementPool.getId())).map(elementInfo -> { + EntitlementPoolEntity entity = convertor.convert(elementInfo); + entity.setVendorLicenseModelId(entitlementPool.getVendorLicenseModelId()); + entity.setVersion(entitlementPool.getVersion()); + return entity; + }).orElse(null); + } - SessionContext context = ZusammenUtil.createSessionContext(); - ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), - entitlementPool.getVersion().getId()); - zusammenAdaptor.saveElement(context, elementContext, zusammenElement, - "delete entitlement pool. id:" + entitlementPool.getId() + "."); - } + @Override + public void delete(EntitlementPoolEntity entitlementPool) { + ZusammenElement zusammenElement = buildElement(new Id(entitlementPool.getId()), Action.DELETE); + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "delete entitlement pool. id:" + entitlementPool.getId() + "."); + } - @Override - public Collection<EntitlementPoolEntity> list(EntitlementPoolEntity entitlementPool) { - SessionContext context = ZusammenUtil.createSessionContext(); - ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), - entitlementPool.getVersion().getId()); - ElementToEntitlementPoolConvertor convertor = new ElementToEntitlementPoolConvertor(); - return zusammenAdaptor - .listElementsByName(context, elementContext, null, ElementType.EntitlementPools.name()) - .stream().map(elementInfo -> { - EntitlementPoolEntity entity = convertor.convert(elementInfo); - entity.setVendorLicenseModelId(entitlementPool.getVendorLicenseModelId()); - entity.setVersion(entitlementPool.getVersion()); - return entity; + @Override + public Collection<EntitlementPoolEntity> list(EntitlementPoolEntity entitlementPool) { + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().getId()); + ElementToEntitlementPoolConvertor convertor = new ElementToEntitlementPoolConvertor(); + return zusammenAdaptor.listElementsByName(context, elementContext, null, ElementType.EntitlementPools.name()).stream().map(elementInfo -> { + EntitlementPoolEntity entity = convertor.convert(elementInfo); + entity.setVendorLicenseModelId(entitlementPool.getVendorLicenseModelId()); + entity.setVersion(entitlementPool.getVersion()); + return entity; }).collect(Collectors.toList()); - } - - @Override - public long count(EntitlementPoolEntity entitlementPool) { - SessionContext context = ZusammenUtil.createSessionContext(); - ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), - entitlementPool.getVersion().getId()); - - return zusammenAdaptor - .listElementsByName(context, elementContext, null, ElementType.EntitlementPools.name()) - .size(); - } - - @Override - public void removeReferencingFeatureGroup(EntitlementPoolEntity entitlementPool, - String referencingFeatureGroupId) { - SessionContext context = ZusammenUtil.createSessionContext(); - ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), - entitlementPool.getVersion().getId()); - - Optional<ElementInfo> elementInfo = - zusammenAdaptor.getElementInfo(context, elementContext, new Id(entitlementPool.getId())); - - if (elementInfo.isPresent()) { - ZusammenElement zusammenElement = VlmZusammenUtil.getZusammenElement(elementInfo.get()); - zusammenElement.setAction(Action.UPDATE); - zusammenElement.setRelations(elementInfo.get().getRelations().stream() - .filter(relation -> !referencingFeatureGroupId - .equals(relation.getEdge2().getElementId().getValue())) - .collect(Collectors.toList())); - - zusammenAdaptor.saveElement(context, elementContext, zusammenElement, - "remove referencing feature group"); } - } - @Override - public void addReferencingFeatureGroup(EntitlementPoolEntity entitlementPool, - String referencingFeatureGroupId) { - SessionContext context = ZusammenUtil.createSessionContext(); - ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), - entitlementPool.getVersion().getId()); + @Override + public long count(EntitlementPoolEntity entitlementPool) { + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().getId()); + return zusammenAdaptor.listElementsByName(context, elementContext, null, ElementType.EntitlementPools.name()).size(); + } - Optional<ElementInfo> elementInfo = - zusammenAdaptor.getElementInfo(context, elementContext, new Id(entitlementPool.getId())); + @Override + public void removeReferencingFeatureGroup(EntitlementPoolEntity entitlementPool, String referencingFeatureGroupId) { + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().getId()); + Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(entitlementPool.getId())); + if (elementInfo.isPresent()) { + ZusammenElement zusammenElement = VlmZusammenUtil.getZusammenElement(elementInfo.get()); + zusammenElement.setAction(Action.UPDATE); + zusammenElement.setRelations(elementInfo.get().getRelations().stream() + .filter(relation -> !referencingFeatureGroupId.equals(relation.getEdge2().getElementId().getValue())).collect(Collectors.toList())); + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "remove referencing feature group"); + } + } - if (elementInfo.isPresent()) { - ZusammenElement zusammenElement = VlmZusammenUtil.getZusammenElement(elementInfo.get()); - zusammenElement.setAction(Action.UPDATE); - if (zusammenElement.getRelations() == null) { - zusammenElement.setRelations(new ArrayList<>()); - } - zusammenElement.getRelations().add(VlmZusammenUtil - .createRelation(RelationType.EntitlmentPoolToReferencingFeatureGroup, - referencingFeatureGroupId)); - zusammenAdaptor - .saveElement(context, elementContext, zusammenElement, "add referencing feature group"); + @Override + public void addReferencingFeatureGroup(EntitlementPoolEntity entitlementPool, String referencingFeatureGroupId) { + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().getId()); + Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(entitlementPool.getId())); + if (elementInfo.isPresent()) { + ZusammenElement zusammenElement = VlmZusammenUtil.getZusammenElement(elementInfo.get()); + zusammenElement.setAction(Action.UPDATE); + if (zusammenElement.getRelations() == null) { + zusammenElement.setRelations(new ArrayList<>()); + } + zusammenElement.getRelations() + .add(VlmZusammenUtil.createRelation(RelationType.EntitlmentPoolToReferencingFeatureGroup, referencingFeatureGroupId)); + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "add referencing feature group"); + } } - } - @Override - public void deleteAll(EntitlementPoolEntity entitlementPool) { - //not supported - } + @Override + public void deleteAll(EntitlementPoolEntity entitlementPool) { + //not supported + } - @Override - public String getManufacturerReferenceNumber(EntitlementPoolEntity entitlementPoolEntity) { - SessionContext context = ZusammenUtil.createSessionContext(); - ElementContext elementContext = - new ElementContext(entitlementPoolEntity.getVendorLicenseModelId(), + @Override + public String getManufacturerReferenceNumber(EntitlementPoolEntity entitlementPoolEntity) { + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(entitlementPoolEntity.getVendorLicenseModelId(), entitlementPoolEntity.getVersion().getId()); - - Optional<ElementInfo> elementInfo1 = zusammenAdaptor - .getElementInfo(context, elementContext, new Id(entitlementPoolEntity.getId())); - Map<String, Object> properties = elementInfo1.get().getInfo().getProperties(); - String manufacturerReferenceNumber = null; - if (properties != null && properties.containsKey("manufacturerReferenceNumber")) { - manufacturerReferenceNumber = (String) properties.get("manufacturerReferenceNumber"); + Optional<ElementInfo> elementInfo1 = zusammenAdaptor.getElementInfo(context, elementContext, new Id(entitlementPoolEntity.getId())); + Map<String, Object> properties = elementInfo1.get().getInfo().getProperties(); + String manufacturerReferenceNumber = null; + if (properties != null && properties.containsKey("manufacturerReferenceNumber")) { + manufacturerReferenceNumber = (String) properties.get("manufacturerReferenceNumber"); + } + return manufacturerReferenceNumber; } - return manufacturerReferenceNumber; - } - - private ZusammenElement buildEntitlementPoolElement(EntitlementPoolEntity entitlementPool, - Action action) { - ZusammenElement entitlementPoolElement = - buildElement(entitlementPool.getId() == null ? null : new Id(entitlementPool.getId()), - action); - Info info = new Info(); - info.setName(entitlementPool.getName()); - info.setDescription(entitlementPool.getDescription()); - info.addProperty(ElementPropertyName.elementType.name(), ElementType.EntitlementPool); - info.addProperty("version_uuid", entitlementPool.getVersionUuId()); - info.addProperty("EntitlementPoolType", entitlementPool.getType()); - info.addProperty("thresholdValue", entitlementPool.getThresholdValue()); - info.addProperty("threshold_unit", entitlementPool.getThresholdUnit()); - info.addProperty("increments", entitlementPool.getIncrements()); - info.addProperty("operational_scope", entitlementPool.getOperationalScope()); - info.addProperty("startDate", entitlementPool.getStartDate()); - info.addProperty("expiryDate", entitlementPool.getExpiryDate()); - info.addProperty("manufacturerReferenceNumber", entitlementPool.getManufacturerReferenceNumber()); - entitlementPoolElement.setInfo(info); - if (entitlementPool.getReferencingFeatureGroups() != null - && !entitlementPool.getReferencingFeatureGroups().isEmpty()) { - entitlementPoolElement.setRelations(entitlementPool.getReferencingFeatureGroups().stream() - .map(rel -> VlmZusammenUtil - .createRelation(RelationType.EntitlmentPoolToReferencingFeatureGroup, rel)) - .collect(Collectors.toList())); + private ZusammenElement buildEntitlementPoolElement(EntitlementPoolEntity entitlementPool, Action action) { + ZusammenElement entitlementPoolElement = buildElement(entitlementPool.getId() == null ? null : new Id(entitlementPool.getId()), action); + Info info = new Info(); + info.setName(entitlementPool.getName()); + info.setDescription(entitlementPool.getDescription()); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.EntitlementPool); + info.addProperty("version_uuid", entitlementPool.getVersionUuId()); + info.addProperty("EntitlementPoolType", entitlementPool.getType()); + info.addProperty("thresholdValue", entitlementPool.getThresholdValue()); + info.addProperty("threshold_unit", entitlementPool.getThresholdUnit()); + info.addProperty("increments", entitlementPool.getIncrements()); + info.addProperty("operational_scope", entitlementPool.getOperationalScope()); + info.addProperty("startDate", entitlementPool.getStartDate()); + info.addProperty("expiryDate", entitlementPool.getExpiryDate()); + info.addProperty("manufacturerReferenceNumber", entitlementPool.getManufacturerReferenceNumber()); + entitlementPoolElement.setInfo(info); + if (entitlementPool.getReferencingFeatureGroups() != null && !entitlementPool.getReferencingFeatureGroups().isEmpty()) { + entitlementPoolElement.setRelations(entitlementPool.getReferencingFeatureGroups().stream() + .map(rel -> VlmZusammenUtil.createRelation(RelationType.EntitlmentPoolToReferencingFeatureGroup, rel)).collect(Collectors.toList())); + } + return entitlementPoolElement; } - return entitlementPoolElement; - } - - } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/FeatureGroupDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/FeatureGroupDaoZusammenImpl.java index fce2722e63..aacb10982d 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/FeatureGroupDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/FeatureGroupDaoZusammenImpl.java @@ -19,6 +19,10 @@ */ package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; +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; @@ -28,6 +32,11 @@ import com.amdocs.zusammen.datatypes.item.Action; import com.amdocs.zusammen.datatypes.item.ElementContext; import com.amdocs.zusammen.datatypes.item.Info; import com.amdocs.zusammen.datatypes.item.Relation; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.datatypes.model.ElementType; import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao; @@ -35,289 +44,199 @@ import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToFeat import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; import org.openecomp.types.ElementPropertyName; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import static org.openecomp.core.zusammen.api.ZusammenUtil.*; - public class FeatureGroupDaoZusammenImpl implements FeatureGroupDao { - private ZusammenAdaptor zusammenAdaptor; - - public FeatureGroupDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } - - @Override - public void registerVersioning(String versionableEntityType) { - //no need - } - - @Override - public void create(FeatureGroupEntity featureGroup) { - ZusammenElement featureGroupElement = buildFeatureGroupElement(featureGroup, Action.CREATE); - - ZusammenElement featureGroupsElement = - buildStructuralElement(ElementType.FeatureGroups, Action.IGNORE); - - featureGroupsElement.addSubElement(featureGroupElement); - - SessionContext context = createSessionContext(); - Element featureGroupsSavedElement = zusammenAdaptor.saveElement(context, - new ElementContext(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion().getId()), featureGroupsElement, "Create feature group"); - - featureGroup.setId( - featureGroupsSavedElement.getSubElements().iterator().next().getElementId().getValue()); - } - - @Override - public void update(FeatureGroupEntity featureGroup) { - ZusammenElement featureGroupElement = buildFeatureGroupElement(featureGroup, Action.UPDATE); - - SessionContext context = createSessionContext(); - zusammenAdaptor.saveElement(context, new ElementContext(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion().getId()), featureGroupElement, - String.format("Update feature group with id %s", featureGroup.getId())); - } - - @Override - public FeatureGroupEntity get(FeatureGroupEntity featureGroup) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion().getId()); - - return zusammenAdaptor.getElementInfo(context, elementContext, new Id(featureGroup.getId())) - .map(elementInfo -> { - FeatureGroupEntity entity = new ElementToFeatureGroupConvertor().convert(elementInfo); - entity.setVendorLicenseModelId(featureGroup.getVendorLicenseModelId()); - entity.setVersion(featureGroup.getVersion()); - return entity; - }) - .orElse(null); - } + private ZusammenAdaptor zusammenAdaptor; - @Override - public void delete(FeatureGroupEntity featureGroup) { - ZusammenElement zusammenElement = buildElement(new Id(featureGroup.getId()), Action.DELETE); - - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion().getId()); - zusammenAdaptor.saveElement(context, elementContext, zusammenElement, - "delete feature group. id:" + featureGroup.getId() + "."); - } - - @Override - public Collection<FeatureGroupEntity> list(FeatureGroupEntity featureGroup) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion().getId()); - - ElementToFeatureGroupConvertor convertor = new ElementToFeatureGroupConvertor(); - return zusammenAdaptor - .listElementsByName(context, elementContext, null, ElementType.FeatureGroups.name()) - .stream().map(elementInfo -> { - FeatureGroupEntity entity = convertor.convert( - elementInfo); - entity.setVendorLicenseModelId(featureGroup.getVendorLicenseModelId()); - entity.setVersion(featureGroup.getVersion()); - return entity; - }) - .collect(Collectors.toList()); - } - - @Override - public long count(FeatureGroupEntity featureGroup) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion().getId()); - - return zusammenAdaptor - .listElementsByName(context, elementContext, null, ElementType.FeatureGroups.name()) - .size(); - } - - @Override - public void removeEntitlementPool(FeatureGroupEntity featureGroup, String entitlementPoolId) { - removeRelationToContainedEntity(featureGroup, entitlementPoolId, "entitlement pool"); - } - - @Override - public void removeLicenseKeyGroup(FeatureGroupEntity featureGroup, String licenseKeyGroupId) { - removeRelationToContainedEntity(featureGroup, licenseKeyGroupId, "license Key Group"); - } - - private void removeRelationToContainedEntity(FeatureGroupEntity featureGroup, - String containedEntityId, - String containedEntityType) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion().getId()); - - Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, - elementContext, new Id(featureGroup.getId())); - if (elementInfo.isPresent()) { - ZusammenElement zusammenElement = VlmZusammenUtil.getZusammenElement(elementInfo.get()); - zusammenElement.setAction(Action.UPDATE); - zusammenElement.setRelations(elementInfo.get().getRelations().stream() - .filter( - relation -> !containedEntityId.equals(relation.getEdge2().getElementId().getValue())) - .collect(Collectors.toList())); - zusammenAdaptor.saveElement(context, elementContext, zusammenElement, - String.format("remove %s", containedEntityType)); + public FeatureGroupDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; } - } - - @Override - public void updateFeatureGroup(FeatureGroupEntity featureGroup, - Set<String> addedEntitlementPools, - Set<String> removedEntitlementPools, - Set<String> addedLicenseKeyGroups, - Set<String> removedLicenseKeyGroups) { - ZusammenElement featureGroupElement = buildFeatureGroupElement(featureGroup, Action.UPDATE); - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion().getId()); - ElementToFeatureGroupConvertor convertor = new ElementToFeatureGroupConvertor(); - Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, - elementContext, new Id(featureGroup.getId())); - if (elementInfo.isPresent()) { - FeatureGroupEntity currentFeatureGroup = convertor.convert(elementInfo.get()); - currentFeatureGroup.setVendorLicenseModelId(featureGroup.getVendorLicenseModelId()); - currentFeatureGroup.setVersion(featureGroup.getVersion()); - if (!(removedEntitlementPools == null)) { - currentFeatureGroup.getEntitlementPoolIds().removeAll(removedEntitlementPools); - } - if (!(addedEntitlementPools == null)) { - currentFeatureGroup.getEntitlementPoolIds().addAll(addedEntitlementPools); - } - - if (featureGroupElement.getRelations() == null) { - featureGroupElement.setRelations(new ArrayList<>()); - } - featureGroupElement.getRelations() - .addAll(currentFeatureGroup.getEntitlementPoolIds().stream() - .map(relation -> VlmZusammenUtil - .createRelation(RelationType.FeatureGroupToEntitlmentPool, relation)) - .collect(Collectors.toList())); - if (!(removedLicenseKeyGroups == null)) { - currentFeatureGroup.getLicenseKeyGroupIds().removeAll(removedLicenseKeyGroups); - } - if (!(addedLicenseKeyGroups == null)) { - currentFeatureGroup.getLicenseKeyGroupIds().addAll(addedLicenseKeyGroups); - } - - featureGroupElement.getRelations() - .addAll(currentFeatureGroup.getLicenseKeyGroupIds().stream() - .map(relation -> VlmZusammenUtil - .createRelation(RelationType.FeatureGroupToLicenseKeyGroup, relation)) - .collect(Collectors.toList())); - - Collection<Relation> laRelations = elementInfo.get().getRelations().stream().filter - (rel -> rel.getType() - .equals(RelationType.FeatureGroupToReferencingLicenseAgreement.name())) - .map(rel -> VlmZusammenUtil.createRelation(RelationType - .FeatureGroupToReferencingLicenseAgreement, rel.getEdge2().getElementId().toString())) - .collect(Collectors.toList()); + @Override + public void registerVersioning(String versionableEntityType) { + //no need + } - featureGroupElement.getRelations().addAll(laRelations); + @Override + public void create(FeatureGroupEntity featureGroup) { + ZusammenElement featureGroupElement = buildFeatureGroupElement(featureGroup, Action.CREATE); + ZusammenElement featureGroupsElement = buildStructuralElement(ElementType.FeatureGroups, Action.IGNORE); + featureGroupsElement.addSubElement(featureGroupElement); + SessionContext context = createSessionContext(); + Element featureGroupsSavedElement = zusammenAdaptor + .saveElement(context, new ElementContext(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().getId()), featureGroupsElement, + "Create feature group"); + featureGroup.setId(featureGroupsSavedElement.getSubElements().iterator().next().getElementId().getValue()); + } - zusammenAdaptor - .saveElement(context, elementContext, featureGroupElement, "update feature group"); + @Override + public void update(FeatureGroupEntity featureGroup) { + ZusammenElement featureGroupElement = buildFeatureGroupElement(featureGroup, Action.UPDATE); + SessionContext context = createSessionContext(); + zusammenAdaptor + .saveElement(context, new ElementContext(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().getId()), featureGroupElement, + String.format("Update feature group with id %s", featureGroup.getId())); } - } - @Override - public void deleteAll(FeatureGroupEntity featureGroup) { - //not supported - } + @Override + public FeatureGroupEntity get(FeatureGroupEntity featureGroup) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().getId()); + return zusammenAdaptor.getElementInfo(context, elementContext, new Id(featureGroup.getId())).map(elementInfo -> { + FeatureGroupEntity entity = new ElementToFeatureGroupConvertor().convert(elementInfo); + entity.setVendorLicenseModelId(featureGroup.getVendorLicenseModelId()); + entity.setVersion(featureGroup.getVersion()); + return entity; + }).orElse(null); + } + @Override + public void delete(FeatureGroupEntity featureGroup) { + ZusammenElement zusammenElement = buildElement(new Id(featureGroup.getId()), Action.DELETE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "delete feature group. id:" + featureGroup.getId() + "."); + } - @Override - public void addReferencingLicenseAgreement(FeatureGroupEntity featureGroup, - String licenseAgreementId) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion().getId()); + @Override + public Collection<FeatureGroupEntity> list(FeatureGroupEntity featureGroup) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().getId()); + ElementToFeatureGroupConvertor convertor = new ElementToFeatureGroupConvertor(); + return zusammenAdaptor.listElementsByName(context, elementContext, null, ElementType.FeatureGroups.name()).stream().map(elementInfo -> { + FeatureGroupEntity entity = convertor.convert(elementInfo); + entity.setVendorLicenseModelId(featureGroup.getVendorLicenseModelId()); + entity.setVersion(featureGroup.getVersion()); + return entity; + }).collect(Collectors.toList()); + } - Optional<ElementInfo> elementInfo = - zusammenAdaptor.getElementInfo(context, elementContext, new Id(featureGroup.getId())); - if (elementInfo.isPresent()) { - ZusammenElement zusammenElement = VlmZusammenUtil.getZusammenElement(elementInfo.get()); - zusammenElement.setAction(Action.UPDATE); - zusammenElement.getRelations().add(VlmZusammenUtil - .createRelation(RelationType.FeatureGroupToReferencingLicenseAgreement, - licenseAgreementId)); - zusammenAdaptor.saveElement(context, elementContext, zusammenElement, - "add referencing license agreement"); + @Override + public long count(FeatureGroupEntity featureGroup) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().getId()); + return zusammenAdaptor.listElementsByName(context, elementContext, null, ElementType.FeatureGroups.name()).size(); } - } - @Override - public void removeReferencingLicenseAgreement(FeatureGroupEntity featureGroup, - String licenseAgreementId) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion().getId()); + @Override + public void removeEntitlementPool(FeatureGroupEntity featureGroup, String entitlementPoolId) { + removeRelationToContainedEntity(featureGroup, entitlementPoolId, "entitlement pool"); + } - Optional<ElementInfo> elementInfo = - zusammenAdaptor.getElementInfo(context, elementContext, new Id(featureGroup.getId())); - if (elementInfo.isPresent()) { - ZusammenElement zusammenElement = VlmZusammenUtil.getZusammenElement(elementInfo.get()); - zusammenElement.setAction(Action.UPDATE); - zusammenElement.setRelations(elementInfo.get().getRelations().stream() - .filter( - relation -> !licenseAgreementId.equals(relation.getEdge2().getElementId().getValue())) - .collect(Collectors.toList())); + @Override + public void removeLicenseKeyGroup(FeatureGroupEntity featureGroup, String licenseKeyGroupId) { + removeRelationToContainedEntity(featureGroup, licenseKeyGroupId, "license Key Group"); + } - zusammenAdaptor.saveElement(context, elementContext, zusammenElement, - "remove referencing license agreement"); + private void removeRelationToContainedEntity(FeatureGroupEntity featureGroup, String containedEntityId, String containedEntityType) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().getId()); + Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(featureGroup.getId())); + if (elementInfo.isPresent()) { + ZusammenElement zusammenElement = VlmZusammenUtil.getZusammenElement(elementInfo.get()); + zusammenElement.setAction(Action.UPDATE); + zusammenElement.setRelations( + elementInfo.get().getRelations().stream().filter(relation -> !containedEntityId.equals(relation.getEdge2().getElementId().getValue())) + .collect(Collectors.toList())); + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, String.format("remove %s", containedEntityType)); + } } - } - private ZusammenElement buildFeatureGroupElement(FeatureGroupEntity featureGroup, Action action) { - ZusammenElement featureGroupElement = - buildElement(featureGroup.getId() == null ? null : new Id(featureGroup.getId()), action); - Info info = new Info(); - info.setName(featureGroup.getName()); - info.setDescription(featureGroup.getDescription()); - info.addProperty(ElementPropertyName.elementType.name(), ElementType.FeatureGroup); - info.addProperty("partNumber", featureGroup.getPartNumber()); - featureGroupElement.setInfo(info); + @Override + public void updateFeatureGroup(FeatureGroupEntity featureGroup, Set<String> addedEntitlementPools, Set<String> removedEntitlementPools, + Set<String> addedLicenseKeyGroups, Set<String> removedLicenseKeyGroups) { + ZusammenElement featureGroupElement = buildFeatureGroupElement(featureGroup, Action.UPDATE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().getId()); + ElementToFeatureGroupConvertor convertor = new ElementToFeatureGroupConvertor(); + Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(featureGroup.getId())); + if (elementInfo.isPresent()) { + FeatureGroupEntity currentFeatureGroup = convertor.convert(elementInfo.get()); + currentFeatureGroup.setVendorLicenseModelId(featureGroup.getVendorLicenseModelId()); + currentFeatureGroup.setVersion(featureGroup.getVersion()); + if (!(removedEntitlementPools == null)) { + currentFeatureGroup.getEntitlementPoolIds().removeAll(removedEntitlementPools); + } + if (!(addedEntitlementPools == null)) { + currentFeatureGroup.getEntitlementPoolIds().addAll(addedEntitlementPools); + } + if (featureGroupElement.getRelations() == null) { + featureGroupElement.setRelations(new ArrayList<>()); + } + featureGroupElement.getRelations().addAll(currentFeatureGroup.getEntitlementPoolIds().stream() + .map(relation -> VlmZusammenUtil.createRelation(RelationType.FeatureGroupToEntitlmentPool, relation)).collect(Collectors.toList())); + if (!(removedLicenseKeyGroups == null)) { + currentFeatureGroup.getLicenseKeyGroupIds().removeAll(removedLicenseKeyGroups); + } + if (!(addedLicenseKeyGroups == null)) { + currentFeatureGroup.getLicenseKeyGroupIds().addAll(addedLicenseKeyGroups); + } + featureGroupElement.getRelations().addAll(currentFeatureGroup.getLicenseKeyGroupIds().stream() + .map(relation -> VlmZusammenUtil.createRelation(RelationType.FeatureGroupToLicenseKeyGroup, relation)).collect(Collectors.toList())); + Collection<Relation> laRelations = elementInfo.get().getRelations().stream() + .filter(rel -> rel.getType().equals(RelationType.FeatureGroupToReferencingLicenseAgreement.name())).map(rel -> VlmZusammenUtil + .createRelation(RelationType.FeatureGroupToReferencingLicenseAgreement, rel.getEdge2().getElementId().toString())) + .collect(Collectors.toList()); + featureGroupElement.getRelations().addAll(laRelations); + zusammenAdaptor.saveElement(context, elementContext, featureGroupElement, "update feature group"); + } + } - featureGroupElement.setRelations(new ArrayList<>()); + @Override + public void deleteAll(FeatureGroupEntity featureGroup) { + //not supported + } - if (featureGroup.getEntitlementPoolIds() != null && - !featureGroup.getEntitlementPoolIds().isEmpty()) { - featureGroupElement.getRelations().addAll(featureGroup.getEntitlementPoolIds().stream() - .map(rel -> VlmZusammenUtil - .createRelation(RelationType.FeatureGroupToEntitlmentPool, rel)) - .collect(Collectors.toList())); + @Override + public void addReferencingLicenseAgreement(FeatureGroupEntity featureGroup, String licenseAgreementId) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().getId()); + Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(featureGroup.getId())); + if (elementInfo.isPresent()) { + ZusammenElement zusammenElement = VlmZusammenUtil.getZusammenElement(elementInfo.get()); + zusammenElement.setAction(Action.UPDATE); + zusammenElement.getRelations() + .add(VlmZusammenUtil.createRelation(RelationType.FeatureGroupToReferencingLicenseAgreement, licenseAgreementId)); + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "add referencing license agreement"); + } } - if (featureGroup.getLicenseKeyGroupIds() != null && - !featureGroup.getLicenseKeyGroupIds().isEmpty()) { - featureGroupElement.getRelations() - .addAll(featureGroup.getLicenseKeyGroupIds().stream() - .map(rel -> VlmZusammenUtil - .createRelation(RelationType.FeatureGroupToLicenseKeyGroup, rel)) - .collect(Collectors.toList())); + @Override + public void removeReferencingLicenseAgreement(FeatureGroupEntity featureGroup, String licenseAgreementId) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().getId()); + Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(featureGroup.getId())); + if (elementInfo.isPresent()) { + ZusammenElement zusammenElement = VlmZusammenUtil.getZusammenElement(elementInfo.get()); + zusammenElement.setAction(Action.UPDATE); + zusammenElement.setRelations(elementInfo.get().getRelations().stream() + .filter(relation -> !licenseAgreementId.equals(relation.getEdge2().getElementId().getValue())).collect(Collectors.toList())); + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "remove referencing license agreement"); + } } - if (featureGroup.getReferencingLicenseAgreements() != null && - !featureGroup.getReferencingLicenseAgreements().isEmpty()) { - featureGroupElement.getRelations() - .addAll(featureGroup.getReferencingLicenseAgreements().stream() - .map(rel -> VlmZusammenUtil - .createRelation(RelationType.FeatureGroupToReferencingLicenseAgreement, - rel)) - .collect(Collectors.toList())); + private ZusammenElement buildFeatureGroupElement(FeatureGroupEntity featureGroup, Action action) { + ZusammenElement featureGroupElement = buildElement(featureGroup.getId() == null ? null : new Id(featureGroup.getId()), action); + Info info = new Info(); + info.setName(featureGroup.getName()); + info.setDescription(featureGroup.getDescription()); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.FeatureGroup); + info.addProperty("partNumber", featureGroup.getPartNumber()); + featureGroupElement.setInfo(info); + featureGroupElement.setRelations(new ArrayList<>()); + if (featureGroup.getEntitlementPoolIds() != null && !featureGroup.getEntitlementPoolIds().isEmpty()) { + featureGroupElement.getRelations().addAll(featureGroup.getEntitlementPoolIds().stream() + .map(rel -> VlmZusammenUtil.createRelation(RelationType.FeatureGroupToEntitlmentPool, rel)).collect(Collectors.toList())); + } + if (featureGroup.getLicenseKeyGroupIds() != null && !featureGroup.getLicenseKeyGroupIds().isEmpty()) { + featureGroupElement.getRelations().addAll(featureGroup.getLicenseKeyGroupIds().stream() + .map(rel -> VlmZusammenUtil.createRelation(RelationType.FeatureGroupToLicenseKeyGroup, rel)).collect(Collectors.toList())); + } + if (featureGroup.getReferencingLicenseAgreements() != null && !featureGroup.getReferencingLicenseAgreements().isEmpty()) { + featureGroupElement.getRelations().addAll(featureGroup.getReferencingLicenseAgreements().stream() + .map(rel -> VlmZusammenUtil.createRelation(RelationType.FeatureGroupToReferencingLicenseAgreement, rel)) + .collect(Collectors.toList())); + } + return featureGroupElement; } - return featureGroupElement; - } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseAgreementDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseAgreementDaoZusammenImpl.java index d30931c8c7..1e4f7ce29c 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseAgreementDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseAgreementDaoZusammenImpl.java @@ -13,9 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; +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; @@ -24,6 +27,10 @@ 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.util.Collection; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; import lombok.AllArgsConstructor; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.datatypes.model.ElementType; @@ -32,187 +39,134 @@ import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToLice import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity; import org.openecomp.types.ElementPropertyName; -import java.util.Collection; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import static org.openecomp.core.zusammen.api.ZusammenUtil.*; - @AllArgsConstructor public class LicenseAgreementDaoZusammenImpl implements LicenseAgreementDao { - private ZusammenAdaptor zusammenAdaptor; - - @Override - public void registerVersioning(String versionableEntityType) { - //no need - } - - @Override - public void create(LicenseAgreementEntity licenseAgreement) { - ZusammenElement licenseAgreementElement = - buildLicenseAgreementElement(licenseAgreement, Action.CREATE); - ZusammenElement licenseAgreementsElement = - buildStructuralElement(ElementType.LicenseAgreements, Action.IGNORE); - licenseAgreementsElement.addSubElement(licenseAgreementElement); - - SessionContext context = createSessionContext(); - Element licenseAgreementsSavedElement = zusammenAdaptor.saveElement(context, - new ElementContext(licenseAgreement.getVendorLicenseModelId(), - licenseAgreement.getVersion().getId()), licenseAgreementsElement, - "Create license agreement"); - licenseAgreement - .setId(licenseAgreementsSavedElement.getSubElements().iterator().next().getElementId() - .getValue()); - } + private ZusammenAdaptor zusammenAdaptor; - @Override - public void update(LicenseAgreementEntity licenseAgreement) { - ZusammenElement licenseAgreementElement = - buildLicenseAgreementElement(licenseAgreement, Action.UPDATE); - - SessionContext context = createSessionContext(); - zusammenAdaptor.saveElement(context, - new ElementContext(licenseAgreement.getVendorLicenseModelId(), - licenseAgreement.getVersion().getId()), licenseAgreementElement, - String.format("Update license agreement with id %s", licenseAgreement.getId())); - } - - @Override - public LicenseAgreementEntity get(LicenseAgreementEntity licenseAgreement) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), - licenseAgreement.getVersion().getId()); - ElementToLicenseAgreementConvertor convertor = new ElementToLicenseAgreementConvertor(); - return zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseAgreement.getId())) - .map(elementInfo -> { - LicenseAgreementEntity entity = convertor.convert(elementInfo); - entity.setVendorLicenseModelId(licenseAgreement.getVendorLicenseModelId()); - entity.setVersion(licenseAgreement.getVersion()); - return entity; - }) - .orElse(null); - } - - @Override - public void delete(LicenseAgreementEntity licenseAgreement) { - ZusammenElement zusammenElement = buildElement(new Id(licenseAgreement.getId()), Action.DELETE); - - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), - licenseAgreement.getVersion().getId()); - zusammenAdaptor.saveElement(context, elementContext, zusammenElement, - "delete license agreement. id:" + licenseAgreement.getId() + "."); - } - - - @Override - public Collection<LicenseAgreementEntity> list(LicenseAgreementEntity licenseAgreement) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), - licenseAgreement.getVersion().getId()); - ElementToLicenseAgreementConvertor convertor = new ElementToLicenseAgreementConvertor(); - return zusammenAdaptor - .listElementsByName(context, elementContext, null, - ElementType.LicenseAgreements.name()) - .stream().map(elementInfo -> { - LicenseAgreementEntity entity = convertor.convert(elementInfo); - entity.setVendorLicenseModelId(licenseAgreement.getVendorLicenseModelId()); - entity.setVersion(licenseAgreement.getVersion()); - return entity; - }) - .collect(Collectors.toList()); - } + @Override + public void registerVersioning(String versionableEntityType) { + //no need + } - @Override - public long count(LicenseAgreementEntity licenseAgreement) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), - licenseAgreement.getVersion().getId()); + @Override + public void create(LicenseAgreementEntity licenseAgreement) { + ZusammenElement licenseAgreementElement = buildLicenseAgreementElement(licenseAgreement, Action.CREATE); + ZusammenElement licenseAgreementsElement = buildStructuralElement(ElementType.LicenseAgreements, Action.IGNORE); + licenseAgreementsElement.addSubElement(licenseAgreementElement); + SessionContext context = createSessionContext(); + Element licenseAgreementsSavedElement = zusammenAdaptor + .saveElement(context, new ElementContext(licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().getId()), + licenseAgreementsElement, "Create license agreement"); + licenseAgreement.setId(licenseAgreementsSavedElement.getSubElements().iterator().next().getElementId().getValue()); + } - return zusammenAdaptor.listElementsByName(context, elementContext, null, - ElementType.LicenseAgreements.name()) - .size(); - } + @Override + public void update(LicenseAgreementEntity licenseAgreement) { + ZusammenElement licenseAgreementElement = buildLicenseAgreementElement(licenseAgreement, Action.UPDATE); + SessionContext context = createSessionContext(); + zusammenAdaptor.saveElement(context, new ElementContext(licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().getId()), + licenseAgreementElement, String.format("Update license agreement with id %s", licenseAgreement.getId())); + } - @Override - public void deleteAll(LicenseAgreementEntity entity) { - //not supported - } + @Override + public LicenseAgreementEntity get(LicenseAgreementEntity licenseAgreement) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().getId()); + ElementToLicenseAgreementConvertor convertor = new ElementToLicenseAgreementConvertor(); + return zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseAgreement.getId())).map(elementInfo -> { + LicenseAgreementEntity entity = convertor.convert(elementInfo); + entity.setVendorLicenseModelId(licenseAgreement.getVendorLicenseModelId()); + entity.setVersion(licenseAgreement.getVersion()); + return entity; + }).orElse(null); + } - @Override - public void removeFeatureGroup(LicenseAgreementEntity licenseAgreement, String featureGroupId) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), - licenseAgreement.getVersion().getId()); + @Override + public void delete(LicenseAgreementEntity licenseAgreement) { + ZusammenElement zusammenElement = buildElement(new Id(licenseAgreement.getId()), Action.DELETE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "delete license agreement. id:" + licenseAgreement.getId() + "."); + } - Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, - elementContext, new Id(licenseAgreement.getId())); - if (elementInfo.isPresent()) { - ZusammenElement zusammenElement = VlmZusammenUtil.getZusammenElement(elementInfo.get()); - zusammenElement.setAction(Action.UPDATE); - zusammenElement.setRelations(elementInfo.get().getRelations().stream() - .filter(relation -> !featureGroupId.equals(relation.getEdge2().getElementId().getValue())) - .collect(Collectors.toList())); - zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "remove feature group"); + @Override + public Collection<LicenseAgreementEntity> list(LicenseAgreementEntity licenseAgreement) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().getId()); + ElementToLicenseAgreementConvertor convertor = new ElementToLicenseAgreementConvertor(); + return zusammenAdaptor.listElementsByName(context, elementContext, null, ElementType.LicenseAgreements.name()).stream().map(elementInfo -> { + LicenseAgreementEntity entity = convertor.convert(elementInfo); + entity.setVendorLicenseModelId(licenseAgreement.getVendorLicenseModelId()); + entity.setVersion(licenseAgreement.getVersion()); + return entity; + }).collect(Collectors.toList()); } - } - @Override - public void updateColumnsAndDeltaFeatureGroupIds(LicenseAgreementEntity licenseAgreement, - Set<String> addedFeatureGroupIds, - Set<String> removedFeatureGroupIds) { - ZusammenElement licenseAgreementElement = - buildLicenseAgreementElement(licenseAgreement, Action.UPDATE); + @Override + public long count(LicenseAgreementEntity licenseAgreement) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().getId()); + return zusammenAdaptor.listElementsByName(context, elementContext, null, ElementType.LicenseAgreements.name()).size(); + } - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), - licenseAgreement.getVersion().getId()); - ElementToLicenseAgreementConvertor convertor = new ElementToLicenseAgreementConvertor(); - Optional<ElementInfo> elementInfo = - zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseAgreement.getId())); - if (elementInfo.isPresent()) { - LicenseAgreementEntity currentLicenseAgreement = - convertor.convert(elementInfo.get()); - currentLicenseAgreement.setVendorLicenseModelId(licenseAgreement.getVendorLicenseModelId()); - currentLicenseAgreement.setVersion(licenseAgreement.getVersion()); - if (!(removedFeatureGroupIds == null)) { - currentLicenseAgreement.getFeatureGroupIds().removeAll(removedFeatureGroupIds); - } + @Override + public void deleteAll(LicenseAgreementEntity entity) { + //not supported + } - if (!(addedFeatureGroupIds == null)) { - currentLicenseAgreement.getFeatureGroupIds().addAll(addedFeatureGroupIds); - } - licenseAgreementElement.setRelations(currentLicenseAgreement.getFeatureGroupIds().stream() - .map(relation -> VlmZusammenUtil - .createRelation(RelationType.LicenseAgreementToFeatureGroup, relation)) - .collect(Collectors.toList())); - zusammenAdaptor.saveElement(context, elementContext, licenseAgreementElement, - "update license agreement"); + @Override + public void removeFeatureGroup(LicenseAgreementEntity licenseAgreement, String featureGroupId) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().getId()); + Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseAgreement.getId())); + if (elementInfo.isPresent()) { + ZusammenElement zusammenElement = VlmZusammenUtil.getZusammenElement(elementInfo.get()); + zusammenElement.setAction(Action.UPDATE); + zusammenElement.setRelations( + elementInfo.get().getRelations().stream().filter(relation -> !featureGroupId.equals(relation.getEdge2().getElementId().getValue())) + .collect(Collectors.toList())); + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "remove feature group"); + } } - } - private ZusammenElement buildLicenseAgreementElement(LicenseAgreementEntity licenseAgreement, - Action action) { - ZusammenElement licenseAgreementElement = - buildElement(licenseAgreement.getId() == null ? null : new Id(licenseAgreement.getId()), - action); - Info info = new Info(); - info.setName(licenseAgreement.getName()); - info.setDescription(licenseAgreement.getDescription()); - info.addProperty(ElementPropertyName.elementType.name(), ElementType.LicenseAgreement); - info.addProperty("licenseTerm", licenseAgreement.getLicenseTerm()); - info.addProperty("requirementsAndConstrains", licenseAgreement.getRequirementsAndConstrains()); - licenseAgreementElement.setInfo(info); + @Override + public void updateColumnsAndDeltaFeatureGroupIds(LicenseAgreementEntity licenseAgreement, Set<String> addedFeatureGroupIds, + Set<String> removedFeatureGroupIds) { + ZusammenElement licenseAgreementElement = buildLicenseAgreementElement(licenseAgreement, Action.UPDATE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().getId()); + ElementToLicenseAgreementConvertor convertor = new ElementToLicenseAgreementConvertor(); + Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseAgreement.getId())); + if (elementInfo.isPresent()) { + LicenseAgreementEntity currentLicenseAgreement = convertor.convert(elementInfo.get()); + currentLicenseAgreement.setVendorLicenseModelId(licenseAgreement.getVendorLicenseModelId()); + currentLicenseAgreement.setVersion(licenseAgreement.getVersion()); + if (!(removedFeatureGroupIds == null)) { + currentLicenseAgreement.getFeatureGroupIds().removeAll(removedFeatureGroupIds); + } + if (!(addedFeatureGroupIds == null)) { + currentLicenseAgreement.getFeatureGroupIds().addAll(addedFeatureGroupIds); + } + licenseAgreementElement.setRelations(currentLicenseAgreement.getFeatureGroupIds().stream() + .map(relation -> VlmZusammenUtil.createRelation(RelationType.LicenseAgreementToFeatureGroup, relation)).collect(Collectors.toList())); + zusammenAdaptor.saveElement(context, elementContext, licenseAgreementElement, "update license agreement"); + } + } - if (licenseAgreement.getFeatureGroupIds() != null && - !licenseAgreement.getFeatureGroupIds().isEmpty()) { - licenseAgreementElement.setRelations(licenseAgreement.getFeatureGroupIds().stream() - .map(rel -> VlmZusammenUtil - .createRelation(RelationType.LicenseAgreementToFeatureGroup, rel)) - .collect(Collectors.toList())); + private ZusammenElement buildLicenseAgreementElement(LicenseAgreementEntity licenseAgreement, Action action) { + ZusammenElement licenseAgreementElement = buildElement(licenseAgreement.getId() == null ? null : new Id(licenseAgreement.getId()), action); + Info info = new Info(); + info.setName(licenseAgreement.getName()); + info.setDescription(licenseAgreement.getDescription()); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.LicenseAgreement); + info.addProperty("licenseTerm", licenseAgreement.getLicenseTerm()); + info.addProperty("requirementsAndConstrains", licenseAgreement.getRequirementsAndConstrains()); + licenseAgreementElement.setInfo(info); + if (licenseAgreement.getFeatureGroupIds() != null && !licenseAgreement.getFeatureGroupIds().isEmpty()) { + licenseAgreementElement.setRelations(licenseAgreement.getFeatureGroupIds().stream() + .map(rel -> VlmZusammenUtil.createRelation(RelationType.LicenseAgreementToFeatureGroup, rel)).collect(Collectors.toList())); + } + return licenseAgreementElement; } - return licenseAgreementElement; - } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseKeyGroupZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseKeyGroupZusammenDaoImpl.java index e5a08ae93a..6d44d1a66a 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseKeyGroupZusammenDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseKeyGroupZusammenDaoImpl.java @@ -19,6 +19,10 @@ */ package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; +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 +31,10 @@ 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.util.ArrayList; +import java.util.Collection; +import java.util.Optional; +import java.util.stream.Collectors; import lombok.AllArgsConstructor; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.datatypes.model.ElementType; @@ -35,206 +43,145 @@ import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToLice import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity; import org.openecomp.types.ElementPropertyName; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Optional; -import java.util.stream.Collectors; - -import static org.openecomp.core.zusammen.api.ZusammenUtil.*; - @AllArgsConstructor public class LicenseKeyGroupZusammenDaoImpl implements LicenseKeyGroupDao { - private ZusammenAdaptor zusammenAdaptor; - - @Override - public void registerVersioning(String versionableEntityType) { - //no need - } - - @Override - public void create(LicenseKeyGroupEntity licenseKeyGroup) { - ZusammenElement licenseKeyGroupElement = - buildLicenseKeyGroupElement(licenseKeyGroup, Action.CREATE); - - ZusammenElement limitsElement = buildStructuralElement(ElementType.Limits, Action.CREATE); - licenseKeyGroupElement.addSubElement(limitsElement); - - ZusammenElement lkgsElement = - buildStructuralElement(ElementType.LicenseKeyGroups, Action.IGNORE); - lkgsElement.addSubElement(licenseKeyGroupElement); - - SessionContext context = createSessionContext(); - Element lkgsSavedElement = zusammenAdaptor.saveElement(context, - new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), - licenseKeyGroup.getVersion().getId()), lkgsElement, "Create license Key Group"); - - licenseKeyGroup - .setId(lkgsSavedElement.getSubElements().iterator().next().getElementId().getValue()); - } - - @Override - public void update(LicenseKeyGroupEntity licenseKeyGroup) { - ZusammenElement licenseKeyGroupElement = - buildLicenseKeyGroupElement(licenseKeyGroup, Action.UPDATE); - - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), - licenseKeyGroup.getVersion().getId()); - Optional<ElementInfo> lkgFromDb = zusammenAdaptor.getElementInfo(context, elementContext, - new Id(licenseKeyGroup.getId())); + private ZusammenAdaptor zusammenAdaptor; - if (lkgFromDb.isPresent()) { - - if (licenseKeyGroupElement.getRelations() == null) { - licenseKeyGroupElement.setRelations(new ArrayList<>()); - } - - if (lkgFromDb.get().getRelations() != null && !lkgFromDb.get().getRelations().isEmpty()) { - licenseKeyGroupElement.getRelations().addAll(lkgFromDb.get().getRelations()); - } + @Override + public void registerVersioning(String versionableEntityType) { + //no need } - zusammenAdaptor.saveElement(context, elementContext, licenseKeyGroupElement, - String.format("Update license key group with id %s", licenseKeyGroup.getId())); - } - - @Override - public LicenseKeyGroupEntity get(LicenseKeyGroupEntity licenseKeyGroup) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), - licenseKeyGroup.getVersion().getId()); - ElementToLicenseKeyGroupConvertor convertor = new ElementToLicenseKeyGroupConvertor(); - return zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseKeyGroup.getId())) - .map(elementInfo -> { - LicenseKeyGroupEntity entity = convertor.convert(elementInfo); - entity.setVendorLicenseModelId(licenseKeyGroup.getVendorLicenseModelId()); - entity.setVersion(licenseKeyGroup.getVersion()); - return entity; - }) - .orElse(null); - } - - @Override - public void delete(LicenseKeyGroupEntity licenseKeyGroup) { - ZusammenElement zusammenElement = buildElement(new Id(licenseKeyGroup.getId()), Action.DELETE); - - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), - licenseKeyGroup.getVersion().getId()); - - zusammenAdaptor.saveElement(context, elementContext, zusammenElement, - "delete license key group. id:" + licenseKeyGroup.getId() + "."); - } - - @Override - public Collection<LicenseKeyGroupEntity> list(LicenseKeyGroupEntity licenseKeyGroup) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), - licenseKeyGroup.getVersion().getId()); - ElementToLicenseKeyGroupConvertor convertor = new ElementToLicenseKeyGroupConvertor(); - return zusammenAdaptor - .listElementsByName(context, elementContext, null, ElementType.LicenseKeyGroups.name()) - .stream().map(elementInfo -> { - LicenseKeyGroupEntity entity = convertor.convert(elementInfo); - entity.setVendorLicenseModelId(licenseKeyGroup.getVendorLicenseModelId()); - entity.setVersion(licenseKeyGroup.getVersion()); - return entity; - }) - .collect(Collectors.toList()); - } - - @Override - public long count(LicenseKeyGroupEntity licenseKeyGroup) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), - licenseKeyGroup.getVersion().getId()); - - return zusammenAdaptor - .listElementsByName(context, elementContext, null, ElementType.LicenseKeyGroups.name()) - .size(); - } - @Override - public void deleteAll(LicenseKeyGroupEntity licenseKeyGroup) { - //not supported - } - - @Override - public void removeReferencingFeatureGroup(LicenseKeyGroupEntity licenseKeyGroup, - String featureGroupId) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), - licenseKeyGroup.getVersion().getId()); - - Optional<ElementInfo> elementInfo = - zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseKeyGroup.getId())); + @Override + public void create(LicenseKeyGroupEntity licenseKeyGroup) { + ZusammenElement licenseKeyGroupElement = buildLicenseKeyGroupElement(licenseKeyGroup, Action.CREATE); + ZusammenElement limitsElement = buildStructuralElement(ElementType.Limits, Action.CREATE); + licenseKeyGroupElement.addSubElement(limitsElement); + ZusammenElement lkgsElement = buildStructuralElement(ElementType.LicenseKeyGroups, Action.IGNORE); + lkgsElement.addSubElement(licenseKeyGroupElement); + SessionContext context = createSessionContext(); + Element lkgsSavedElement = zusammenAdaptor + .saveElement(context, new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().getId()), lkgsElement, + "Create license Key Group"); + licenseKeyGroup.setId(lkgsSavedElement.getSubElements().iterator().next().getElementId().getValue()); + } - if (elementInfo.isPresent()) { - ZusammenElement zusammenElement = VlmZusammenUtil.getZusammenElement(elementInfo.get()); - zusammenElement.setAction(Action.UPDATE); - zusammenElement.setRelations(elementInfo.get().getRelations().stream() - .filter(relation -> !featureGroupId - .equals(relation.getEdge2().getElementId().getValue())) - .collect(Collectors.toList())); + @Override + public void update(LicenseKeyGroupEntity licenseKeyGroup) { + ZusammenElement licenseKeyGroupElement = buildLicenseKeyGroupElement(licenseKeyGroup, Action.UPDATE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().getId()); + Optional<ElementInfo> lkgFromDb = zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseKeyGroup.getId())); + if (lkgFromDb.isPresent()) { + if (licenseKeyGroupElement.getRelations() == null) { + licenseKeyGroupElement.setRelations(new ArrayList<>()); + } + if (lkgFromDb.get().getRelations() != null && !lkgFromDb.get().getRelations().isEmpty()) { + licenseKeyGroupElement.getRelations().addAll(lkgFromDb.get().getRelations()); + } + } + zusammenAdaptor.saveElement(context, elementContext, licenseKeyGroupElement, + String.format("Update license key group with id %s", licenseKeyGroup.getId())); + } - zusammenAdaptor.saveElement(context, elementContext, zusammenElement, - "remove referencing feature group"); + @Override + public LicenseKeyGroupEntity get(LicenseKeyGroupEntity licenseKeyGroup) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().getId()); + ElementToLicenseKeyGroupConvertor convertor = new ElementToLicenseKeyGroupConvertor(); + return zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseKeyGroup.getId())).map(elementInfo -> { + LicenseKeyGroupEntity entity = convertor.convert(elementInfo); + entity.setVendorLicenseModelId(licenseKeyGroup.getVendorLicenseModelId()); + entity.setVersion(licenseKeyGroup.getVersion()); + return entity; + }).orElse(null); } - } - @Override - public void addReferencingFeatureGroup(LicenseKeyGroupEntity licenseKeyGroup, - String featureGroupId) { - SessionContext context = createSessionContext(); - ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), - licenseKeyGroup.getVersion().getId()); + @Override + public void delete(LicenseKeyGroupEntity licenseKeyGroup) { + ZusammenElement zusammenElement = buildElement(new Id(licenseKeyGroup.getId()), Action.DELETE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "delete license key group. id:" + licenseKeyGroup.getId() + "."); + } - Optional<ElementInfo> elementInfo = - zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseKeyGroup.getId())); + @Override + public Collection<LicenseKeyGroupEntity> list(LicenseKeyGroupEntity licenseKeyGroup) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().getId()); + ElementToLicenseKeyGroupConvertor convertor = new ElementToLicenseKeyGroupConvertor(); + return zusammenAdaptor.listElementsByName(context, elementContext, null, ElementType.LicenseKeyGroups.name()).stream().map(elementInfo -> { + LicenseKeyGroupEntity entity = convertor.convert(elementInfo); + entity.setVendorLicenseModelId(licenseKeyGroup.getVendorLicenseModelId()); + entity.setVersion(licenseKeyGroup.getVersion()); + return entity; + }).collect(Collectors.toList()); + } - if (elementInfo.isPresent()) { - ZusammenElement zusammenElement = VlmZusammenUtil.getZusammenElement(elementInfo.get()); - zusammenElement.setAction(Action.UPDATE); - if (zusammenElement.getRelations() == null) { - zusammenElement.setRelations(new ArrayList<>()); - } - zusammenElement.getRelations().add(VlmZusammenUtil - .createRelation(RelationType.LicenseKeyGroupToReferencingFeatureGroup, - featureGroupId)); - zusammenAdaptor - .saveElement(context, elementContext, zusammenElement, "add referencing feature group"); + @Override + public long count(LicenseKeyGroupEntity licenseKeyGroup) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().getId()); + return zusammenAdaptor.listElementsByName(context, elementContext, null, ElementType.LicenseKeyGroups.name()).size(); } - } - private ZusammenElement buildLicenseKeyGroupElement(LicenseKeyGroupEntity licenseKeyGroup, - Action action) { - ZusammenElement lkgElement = - buildElement(licenseKeyGroup.getId() == null ? null : new Id(licenseKeyGroup.getId()), - action); - Info info = new Info(); - info.setName(licenseKeyGroup.getName()); - info.setDescription(licenseKeyGroup.getDescription()); - info.addProperty(ElementPropertyName.elementType.name(), ElementType.LicenseKeyGroup); - info.addProperty("version_uuid", licenseKeyGroup.getVersionUuId()); - info.addProperty("LicenseKeyType", licenseKeyGroup.getType()); - info.addProperty("operational_scope", licenseKeyGroup.getOperationalScope()); - info.addProperty("startDate", licenseKeyGroup.getStartDate()); - info.addProperty("expiryDate", licenseKeyGroup.getExpiryDate()); - info.addProperty("thresholdValue", licenseKeyGroup.getThresholdValue()); - info.addProperty("thresholdUnits", licenseKeyGroup.getThresholdUnits()); - info.addProperty("increments", licenseKeyGroup.getIncrements()); - info.addProperty("manufacturerReferenceNumber", licenseKeyGroup.getManufacturerReferenceNumber()); - lkgElement.setInfo(info); + @Override + public void deleteAll(LicenseKeyGroupEntity licenseKeyGroup) { + //not supported + } - if (licenseKeyGroup.getReferencingFeatureGroups() != null - && !licenseKeyGroup.getReferencingFeatureGroups().isEmpty()) { - lkgElement.setRelations(licenseKeyGroup.getReferencingFeatureGroups().stream() - .map(rel -> VlmZusammenUtil - .createRelation(RelationType.LicenseKeyGroupToReferencingFeatureGroup, rel)) - .collect(Collectors.toList())); + @Override + public void removeReferencingFeatureGroup(LicenseKeyGroupEntity licenseKeyGroup, String featureGroupId) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().getId()); + Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseKeyGroup.getId())); + if (elementInfo.isPresent()) { + ZusammenElement zusammenElement = VlmZusammenUtil.getZusammenElement(elementInfo.get()); + zusammenElement.setAction(Action.UPDATE); + zusammenElement.setRelations( + elementInfo.get().getRelations().stream().filter(relation -> !featureGroupId.equals(relation.getEdge2().getElementId().getValue())) + .collect(Collectors.toList())); + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "remove referencing feature group"); + } } - return lkgElement; - } + @Override + public void addReferencingFeatureGroup(LicenseKeyGroupEntity licenseKeyGroup, String featureGroupId) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().getId()); + Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseKeyGroup.getId())); + if (elementInfo.isPresent()) { + ZusammenElement zusammenElement = VlmZusammenUtil.getZusammenElement(elementInfo.get()); + zusammenElement.setAction(Action.UPDATE); + if (zusammenElement.getRelations() == null) { + zusammenElement.setRelations(new ArrayList<>()); + } + zusammenElement.getRelations().add(VlmZusammenUtil.createRelation(RelationType.LicenseKeyGroupToReferencingFeatureGroup, featureGroupId)); + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "add referencing feature group"); + } + } + private ZusammenElement buildLicenseKeyGroupElement(LicenseKeyGroupEntity licenseKeyGroup, Action action) { + ZusammenElement lkgElement = buildElement(licenseKeyGroup.getId() == null ? null : new Id(licenseKeyGroup.getId()), action); + Info info = new Info(); + info.setName(licenseKeyGroup.getName()); + info.setDescription(licenseKeyGroup.getDescription()); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.LicenseKeyGroup); + info.addProperty("version_uuid", licenseKeyGroup.getVersionUuId()); + info.addProperty("LicenseKeyType", licenseKeyGroup.getType()); + info.addProperty("operational_scope", licenseKeyGroup.getOperationalScope()); + info.addProperty("startDate", licenseKeyGroup.getStartDate()); + info.addProperty("expiryDate", licenseKeyGroup.getExpiryDate()); + info.addProperty("thresholdValue", licenseKeyGroup.getThresholdValue()); + info.addProperty("thresholdUnits", licenseKeyGroup.getThresholdUnits()); + info.addProperty("increments", licenseKeyGroup.getIncrements()); + info.addProperty("manufacturerReferenceNumber", licenseKeyGroup.getManufacturerReferenceNumber()); + lkgElement.setInfo(info); + if (licenseKeyGroup.getReferencingFeatureGroups() != null && !licenseKeyGroup.getReferencingFeatureGroups().isEmpty()) { + lkgElement.setRelations(licenseKeyGroup.getReferencingFeatureGroups().stream() + .map(rel -> VlmZusammenUtil.createRelation(RelationType.LicenseKeyGroupToReferencingFeatureGroup, rel)).collect(Collectors.toList())); + } + return lkgElement; + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LimitZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LimitZusammenDaoImpl.java index 9fe3b38565..7b90a270bf 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LimitZusammenDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LimitZusammenDaoImpl.java @@ -19,6 +19,10 @@ */ package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; +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 +31,9 @@ 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.util.Collection; +import java.util.Collections; +import java.util.stream.Collectors; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.sdc.datatypes.model.ElementType; import org.openecomp.sdc.vendorlicense.dao.LimitDao; @@ -36,163 +43,120 @@ import org.openecomp.sdc.vendorlicense.dao.types.LimitType; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.types.ElementPropertyName; -import java.util.Collection; -import java.util.Collections; -import java.util.stream.Collectors; - -import static org.openecomp.core.zusammen.api.ZusammenUtil.*; - public class LimitZusammenDaoImpl implements LimitDao { - private static final String LIMT_TYPE = "type"; - private static final String METRIC = "metric"; - private static final String AGGREGATIONFUNCTION = "aggregationfunction"; - private static final String TIME = "time"; - private static final String UNIT = "unit"; - private static final String VALUE = "value"; - private ZusammenAdaptor zusammenAdaptor; - - public LimitZusammenDaoImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } - - @Override - public void create(LimitEntity limitEntity) { - ZusammenElement limitElement = limitToZusammen(limitEntity, Action.CREATE); - - ZusammenElement limitsElement = buildStructuralElement(ElementType.Limits, null); - limitsElement.setSubElements(Collections.singletonList(limitElement)); - - ZusammenElement epLkgElement = buildElement(new Id(limitEntity.getEpLkgId()), Action.IGNORE); - epLkgElement.setSubElements(Collections.singletonList(limitsElement)); - - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); - - Element savedElement = - zusammenAdaptor.saveElement(context, elementContext, epLkgElement, "Create limit"); - limitEntity.setId(savedElement.getSubElements().iterator().next() - .getSubElements().iterator().next().getElementId().getValue()); - } - - @Override - public boolean isLimitPresent(LimitEntity limitEntity) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); - - Collection<ElementInfo> elementInfos = zusammenAdaptor.listElementsByName(context, - elementContext, new Id(limitEntity.getEpLkgId()), ElementType.Limits.name()); + private static final String LIMT_TYPE = "type"; + private static final String METRIC = "metric"; + private static final String AGGREGATIONFUNCTION = "aggregationfunction"; + private static final String TIME = "time"; + private static final String UNIT = "unit"; + private static final String VALUE = "value"; + private ZusammenAdaptor zusammenAdaptor; - for (ElementInfo elementInfo : elementInfos) { - if (elementInfo.getId().getValue().equals(limitEntity.getId())) { - return true; - } + public LimitZusammenDaoImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; } - return false; - } - - @Override - public Collection<LimitEntity> list(LimitEntity limitEntity) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); - - return listLimits(context, elementContext, limitEntity); - } - - private Collection<LimitEntity> listLimits(SessionContext context, ElementContext elementContext, - LimitEntity limitEntity) { - return zusammenAdaptor - .listElementsByName(context, elementContext, new Id(limitEntity.getEpLkgId()), - ElementType.Limits.name()) - .stream().map(elementInfo -> mapElementInfoToLimit( - limitEntity.getVendorLicenseModelId(), limitEntity.getVersion(), - limitEntity.getEpLkgId(), elementInfo)) - .collect(Collectors.toList()); - } - - private LimitEntity mapElementInfoToLimit(String vlmId, Version version, - String epLkgId, ElementInfo elementInfo) { - LimitEntity limitEntity = - new LimitEntity(vlmId, version, epLkgId, elementInfo.getId().getValue()); - - limitEntity.setName(elementInfo.getInfo().getName()); - limitEntity.setDescription(elementInfo.getInfo().getDescription()); - limitEntity.setType(elementInfo.getInfo().getProperties().get(LIMT_TYPE) != null ? - LimitType.valueOf((String) elementInfo.getInfo().getProperties().get(LIMT_TYPE)) : - null); - limitEntity.setTime((String) elementInfo.getInfo().getProperties().get(TIME)); - limitEntity.setMetric((String) elementInfo.getInfo().getProperties().get(METRIC)); - limitEntity.setAggregationFunction(elementInfo.getInfo().getProperties().get - (AGGREGATIONFUNCTION) != null ? - AggregationFunction.valueOf((String) elementInfo.getInfo().getProperties() - .get(AGGREGATIONFUNCTION)) : null); - Object unit = elementInfo.getInfo().getProperties().get(UNIT); - limitEntity.setUnit((String) unit); - Object value = elementInfo.getInfo().getProperties().get(VALUE); - limitEntity.setValue((String) value); - - return limitEntity; - } + @Override + public void create(LimitEntity limitEntity) { + ZusammenElement limitElement = limitToZusammen(limitEntity, Action.CREATE); + ZusammenElement limitsElement = buildStructuralElement(ElementType.Limits, null); + limitsElement.setSubElements(Collections.singletonList(limitElement)); + ZusammenElement epLkgElement = buildElement(new Id(limitEntity.getEpLkgId()), Action.IGNORE); + epLkgElement.setSubElements(Collections.singletonList(limitsElement)); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); + Element savedElement = zusammenAdaptor.saveElement(context, elementContext, epLkgElement, "Create limit"); + limitEntity.setId(savedElement.getSubElements().iterator().next().getSubElements().iterator().next().getElementId().getValue()); + } - @Override - public void update(LimitEntity limitEntity) { - ZusammenElement limitElement = limitToZusammen(limitEntity, Action.UPDATE); + @Override + public boolean isLimitPresent(LimitEntity limitEntity) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); + Collection<ElementInfo> elementInfos = zusammenAdaptor + .listElementsByName(context, elementContext, new Id(limitEntity.getEpLkgId()), ElementType.Limits.name()); + for (ElementInfo elementInfo : elementInfos) { + if (elementInfo.getId().getValue().equals(limitEntity.getId())) { + return true; + } + } + return false; + } - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); + @Override + public Collection<LimitEntity> list(LimitEntity limitEntity) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); + return listLimits(context, elementContext, limitEntity); + } - zusammenAdaptor.saveElement(context, elementContext, limitElement, - String.format("Update limit with id %s", limitEntity.getId())); - } + private Collection<LimitEntity> listLimits(SessionContext context, ElementContext elementContext, LimitEntity limitEntity) { + return zusammenAdaptor.listElementsByName(context, elementContext, new Id(limitEntity.getEpLkgId()), ElementType.Limits.name()).stream().map( + elementInfo -> mapElementInfoToLimit(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion(), limitEntity.getEpLkgId(), + elementInfo)).collect(Collectors.toList()); + } - @Override - public LimitEntity get(LimitEntity limitEntity) { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); + private LimitEntity mapElementInfoToLimit(String vlmId, Version version, String epLkgId, ElementInfo elementInfo) { + LimitEntity limitEntity = new LimitEntity(vlmId, version, epLkgId, elementInfo.getId().getValue()); + limitEntity.setName(elementInfo.getInfo().getName()); + limitEntity.setDescription(elementInfo.getInfo().getDescription()); + limitEntity.setType(elementInfo.getInfo().getProperties().get(LIMT_TYPE) != null ? LimitType + .valueOf((String) elementInfo.getInfo().getProperties().get(LIMT_TYPE)) : null); + limitEntity.setTime((String) elementInfo.getInfo().getProperties().get(TIME)); + limitEntity.setMetric((String) elementInfo.getInfo().getProperties().get(METRIC)); + limitEntity.setAggregationFunction(elementInfo.getInfo().getProperties().get(AGGREGATIONFUNCTION) != null ? AggregationFunction + .valueOf((String) elementInfo.getInfo().getProperties().get(AGGREGATIONFUNCTION)) : null); + Object unit = elementInfo.getInfo().getProperties().get(UNIT); + limitEntity.setUnit((String) unit); + Object value = elementInfo.getInfo().getProperties().get(VALUE); + limitEntity.setValue((String) value); + return limitEntity; + } - return zusammenAdaptor.getElementInfo(context, elementContext, new Id(limitEntity.getId())) - .map(elementInfo -> mapElementInfoToLimit( - limitEntity.getVendorLicenseModelId(), limitEntity.getVersion(), limitEntity - .getEpLkgId(), elementInfo)) - .orElse(null); - } + @Override + public void update(LimitEntity limitEntity) { + ZusammenElement limitElement = limitToZusammen(limitEntity, Action.UPDATE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, limitElement, String.format("Update limit with id %s", limitEntity.getId())); + } - @Override - public void delete(LimitEntity limitEntity) { - ZusammenElement zusammenElement = buildElement(new Id(limitEntity.getId()), Action.DELETE); + @Override + public LimitEntity get(LimitEntity limitEntity) { + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); + return zusammenAdaptor.getElementInfo(context, elementContext, new Id(limitEntity.getId())).map( + elementInfo -> mapElementInfoToLimit(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion(), limitEntity.getEpLkgId(), + elementInfo)).orElse(null); + } - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); - zusammenAdaptor.saveElement(context, elementContext, zusammenElement, - "delete limit Id:" + limitEntity.getId() + "."); - } + @Override + public void delete(LimitEntity limitEntity) { + ZusammenElement zusammenElement = buildElement(new Id(limitEntity.getId()), Action.DELETE); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "delete limit Id:" + limitEntity.getId() + "."); + } - @Override - public void registerVersioning(String versionableEntityType) { - //registerVersioning not implemented for LimitZusammenDaoImpl - } + @Override + public void registerVersioning(String versionableEntityType) { + //registerVersioning not implemented for LimitZusammenDaoImpl + } - private ZusammenElement limitToZusammen(LimitEntity limit, Action action) { - ZusammenElement limitElement = - buildElement(limit.getId() == null ? null : new Id(limit.getId()), action); - Info info = new Info(); - info.setName(limit.getName()); - info.setDescription(limit.getDescription()); - info.addProperty(ElementPropertyName.elementType.name(), ElementType.Limit); - info.addProperty(LIMT_TYPE, limit.getType()); - info.addProperty(METRIC, limit.getMetric()); - info.addProperty(AGGREGATIONFUNCTION, limit.getAggregationFunction()); - info.addProperty(TIME, limit.getTime()); - info.addProperty(VALUE, limit.getValue()); - info.addProperty(UNIT, limit.getUnit()); - limitElement.setInfo(info); - return limitElement; - } + private ZusammenElement limitToZusammen(LimitEntity limit, Action action) { + ZusammenElement limitElement = buildElement(limit.getId() == null ? null : new Id(limit.getId()), action); + Info info = new Info(); + info.setName(limit.getName()); + info.setDescription(limit.getDescription()); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.Limit); + info.addProperty(LIMT_TYPE, limit.getType()); + info.addProperty(METRIC, limit.getMetric()); + info.addProperty(AGGREGATIONFUNCTION, limit.getAggregationFunction()); + info.addProperty(TIME, limit.getTime()); + info.addProperty(VALUE, limit.getValue()); + info.addProperty(UNIT, limit.getUnit()); + limitElement.setInfo(info); + return limitElement; + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VendorLicenseModelDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VendorLicenseModelDaoZusammenImpl.java index 031d415127..2c4702aec1 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VendorLicenseModelDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VendorLicenseModelDaoZusammenImpl.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; @@ -21,6 +20,8 @@ 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.util.Collection; +import java.util.stream.Collectors; import org.openecomp.core.zusammen.api.ZusammenAdaptor; import org.openecomp.core.zusammen.api.ZusammenUtil; import org.openecomp.sdc.datatypes.model.ElementType; @@ -31,130 +32,85 @@ import org.openecomp.sdc.versioning.ActionVersioningManagerFactory; import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; import org.openecomp.sdc.versioning.types.VersionableEntityStoreType; -import java.util.Collection; -import java.util.stream.Collectors; - public class VendorLicenseModelDaoZusammenImpl implements VendorLicenseModelDao { - private ZusammenAdaptor zusammenAdaptor; - - public VendorLicenseModelDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } - - @Override - public void registerVersioning(String versionableEntityType) { - VersionableEntityMetadata metadata = - new VersionableEntityMetadata(VersionableEntityStoreType.Zusammen, "VendorLicenseModel", - null, null); - - ActionVersioningManagerFactory.getInstance().createInterface() - .register(versionableEntityType, metadata); - } - - @Override - public Collection<VendorLicenseModelEntity> list( - VendorLicenseModelEntity vendorLicenseModelEntity) { - - ElementToVLMGeneralConvertor convertor = new ElementToVLMGeneralConvertor(); - return zusammenAdaptor.listItems(ZusammenUtil.createSessionContext()).stream() - .filter(item -> "VendorLicenseModel".equals(item.getInfo().getProperty("item_type"))) - .map(item -> { - VendorLicenseModelEntity entity = convertor.convert(item); - entity.setId(item.getId().getValue()); - entity.setVersion(null); - return entity; - }) - .collect(Collectors.toList()); - } - - @Override - public void create(VendorLicenseModelEntity vendorLicenseModel) { - - SessionContext context = ZusammenUtil.createSessionContext(); - - ElementContext elementContext = new ElementContext(vendorLicenseModel.getId(), - vendorLicenseModel.getVersion().getId()); - - ZusammenElement generalElement = mapVlmToZusammenElement(vendorLicenseModel, Action.CREATE); - - zusammenAdaptor.saveElement(context, elementContext, generalElement, - "Create VLM General Info Element"); - - ZusammenElement licenseAgreementsElement = - ZusammenUtil.buildStructuralElement(ElementType.LicenseAgreements, Action.CREATE); - - zusammenAdaptor.saveElement(context, elementContext, licenseAgreementsElement, - "Create VLM licenseAgreementsElement"); - - ZusammenElement featureGroupsElement = - ZusammenUtil.buildStructuralElement(ElementType.FeatureGroups, Action.CREATE); - - zusammenAdaptor.saveElement(context, elementContext, featureGroupsElement, - "Create VLM featureGroupsElement"); - - ZusammenElement lkgsElement = - ZusammenUtil.buildStructuralElement(ElementType.LicenseKeyGroups, Action.CREATE); - - zusammenAdaptor.saveElement(context, elementContext, lkgsElement, - "Create VLM lkgsElement"); - - ZusammenElement entitlementPoolsElement = - ZusammenUtil.buildStructuralElement(ElementType.EntitlementPools, Action.CREATE); - - zusammenAdaptor.saveElement(context, elementContext, entitlementPoolsElement, - "Create VLM entitlementPoolsElement"); - } - - @Override - public void update(VendorLicenseModelEntity vendorLicenseModel) { - ZusammenElement generalElement = mapVlmToZusammenElement(vendorLicenseModel, Action.UPDATE); - - SessionContext context = ZusammenUtil.createSessionContext(); - zusammenAdaptor.saveElement(context, - new ElementContext(vendorLicenseModel.getId(), vendorLicenseModel.getVersion().getId()), - generalElement, "Update VSP General Info Element"); - } - - @Override - public VendorLicenseModelEntity get(VendorLicenseModelEntity vendorLicenseModel) { - SessionContext context = ZusammenUtil.createSessionContext(); - ElementContext elementContext = - new ElementContext(vendorLicenseModel.getId(), vendorLicenseModel.getVersion().getId()); - ElementToVLMGeneralConvertor convertor = new ElementToVLMGeneralConvertor(); - return zusammenAdaptor - .getElementInfoByName(context, elementContext, null, ElementType.VendorLicenseModel.name()) - .map(generalElementInfo -> { - VendorLicenseModelEntity entity = convertor.convert(generalElementInfo); - entity.setId(vendorLicenseModel.getId()); - entity.setVersion(vendorLicenseModel.getVersion()); - return entity; - }) - .orElse(null); - } - - @Override - public void delete(VendorLicenseModelEntity entity) { - throw new UnsupportedOperationException("Delete vlm version is done using versioning manager"); - } - - private ZusammenElement mapVlmToZusammenElement(VendorLicenseModelEntity vendorLicenseModel, - Action action) { - ZusammenElement generalElement = - ZusammenUtil.buildStructuralElement(ElementType.VendorLicenseModel, action); - addVlmToInfo(generalElement.getInfo(), vendorLicenseModel); - return generalElement; - } - - private void addVlmToInfo(Info info, VendorLicenseModelEntity vendorLicenseModel) { - info.addProperty(InfoPropertyName.name.name(), vendorLicenseModel.getVendorName()); - info.addProperty(InfoPropertyName.description.name(), vendorLicenseModel.getDescription()); - info.addProperty(InfoPropertyName.iconRef.name(), vendorLicenseModel.getIconRef()); - } - - public enum InfoPropertyName { - name, - description, - iconRef, - } + private ZusammenAdaptor zusammenAdaptor; + + public VendorLicenseModelDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public void registerVersioning(String versionableEntityType) { + VersionableEntityMetadata metadata = new VersionableEntityMetadata(VersionableEntityStoreType.Zusammen, "VendorLicenseModel", null, null); + ActionVersioningManagerFactory.getInstance().createInterface().register(versionableEntityType, metadata); + } + + @Override + public Collection<VendorLicenseModelEntity> list(VendorLicenseModelEntity vendorLicenseModelEntity) { + ElementToVLMGeneralConvertor convertor = new ElementToVLMGeneralConvertor(); + return zusammenAdaptor.listItems(ZusammenUtil.createSessionContext()).stream() + .filter(item -> "VendorLicenseModel".equals(item.getInfo().getProperty("item_type"))).map(item -> { + VendorLicenseModelEntity entity = convertor.convert(item); + entity.setId(item.getId().getValue()); + entity.setVersion(null); + return entity; + }).collect(Collectors.toList()); + } + + @Override + public void create(VendorLicenseModelEntity vendorLicenseModel) { + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(vendorLicenseModel.getId(), vendorLicenseModel.getVersion().getId()); + ZusammenElement generalElement = mapVlmToZusammenElement(vendorLicenseModel, Action.CREATE); + zusammenAdaptor.saveElement(context, elementContext, generalElement, "Create VLM General Info Element"); + ZusammenElement licenseAgreementsElement = ZusammenUtil.buildStructuralElement(ElementType.LicenseAgreements, Action.CREATE); + zusammenAdaptor.saveElement(context, elementContext, licenseAgreementsElement, "Create VLM licenseAgreementsElement"); + ZusammenElement featureGroupsElement = ZusammenUtil.buildStructuralElement(ElementType.FeatureGroups, Action.CREATE); + zusammenAdaptor.saveElement(context, elementContext, featureGroupsElement, "Create VLM featureGroupsElement"); + ZusammenElement lkgsElement = ZusammenUtil.buildStructuralElement(ElementType.LicenseKeyGroups, Action.CREATE); + zusammenAdaptor.saveElement(context, elementContext, lkgsElement, "Create VLM lkgsElement"); + ZusammenElement entitlementPoolsElement = ZusammenUtil.buildStructuralElement(ElementType.EntitlementPools, Action.CREATE); + zusammenAdaptor.saveElement(context, elementContext, entitlementPoolsElement, "Create VLM entitlementPoolsElement"); + } + + @Override + public void update(VendorLicenseModelEntity vendorLicenseModel) { + ZusammenElement generalElement = mapVlmToZusammenElement(vendorLicenseModel, Action.UPDATE); + SessionContext context = ZusammenUtil.createSessionContext(); + zusammenAdaptor.saveElement(context, new ElementContext(vendorLicenseModel.getId(), vendorLicenseModel.getVersion().getId()), generalElement, + "Update VSP General Info Element"); + } + + @Override + public VendorLicenseModelEntity get(VendorLicenseModelEntity vendorLicenseModel) { + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(vendorLicenseModel.getId(), vendorLicenseModel.getVersion().getId()); + ElementToVLMGeneralConvertor convertor = new ElementToVLMGeneralConvertor(); + return zusammenAdaptor.getElementInfoByName(context, elementContext, null, ElementType.VendorLicenseModel.name()).map(generalElementInfo -> { + VendorLicenseModelEntity entity = convertor.convert(generalElementInfo); + entity.setId(vendorLicenseModel.getId()); + entity.setVersion(vendorLicenseModel.getVersion()); + return entity; + }).orElse(null); + } + + @Override + public void delete(VendorLicenseModelEntity entity) { + throw new UnsupportedOperationException("Delete vlm version is done using versioning manager"); + } + + private ZusammenElement mapVlmToZusammenElement(VendorLicenseModelEntity vendorLicenseModel, Action action) { + ZusammenElement generalElement = ZusammenUtil.buildStructuralElement(ElementType.VendorLicenseModel, action); + addVlmToInfo(generalElement.getInfo(), vendorLicenseModel); + return generalElement; + } + + private void addVlmToInfo(Info info, VendorLicenseModelEntity vendorLicenseModel) { + info.addProperty(InfoPropertyName.name.name(), vendorLicenseModel.getVendorName()); + info.addProperty(InfoPropertyName.description.name(), vendorLicenseModel.getDescription()); + info.addProperty(InfoPropertyName.iconRef.name(), vendorLicenseModel.getIconRef()); + } + + public enum InfoPropertyName {name, description, iconRef,} } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VlmZusammenUtil.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VlmZusammenUtil.java index 01a15304a9..96c9e2ff83 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VlmZusammenUtil.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VlmZusammenUtil.java @@ -24,42 +24,39 @@ import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; import com.amdocs.zusammen.datatypes.Id; import com.amdocs.zusammen.datatypes.item.Relation; import com.amdocs.zusammen.datatypes.item.RelationEdge; - import java.util.stream.Collectors; public class VlmZusammenUtil { - static ZusammenElement getZusammenElement(ElementInfo elementInfo) { - ZusammenElement zusammenElement = new ZusammenElement(); - zusammenElement.setElementId(elementInfo.getId()); - zusammenElement.setInfo(elementInfo.getInfo()); - zusammenElement.setRelations(elementInfo.getRelations()); - zusammenElement.setSubElements(elementInfo.getSubElements().stream() - .map(VlmZusammenUtil::getZusammenElement) - .collect(Collectors.toList())); - return zusammenElement; - } - - public static Relation createRelation(RelationType type, String to) { - Relation relation = new Relation(); - relation.setType(type.name()); - RelationEdge edge2 = new RelationEdge(); - edge2.setElementId(new Id(to)); - relation.setEdge2(edge2); - return relation; - } + static ZusammenElement getZusammenElement(ElementInfo elementInfo) { + ZusammenElement zusammenElement = new ZusammenElement(); + zusammenElement.setElementId(elementInfo.getId()); + zusammenElement.setInfo(elementInfo.getInfo()); + zusammenElement.setRelations(elementInfo.getRelations()); + zusammenElement.setSubElements(elementInfo.getSubElements().stream().map(VlmZusammenUtil::getZusammenElement).collect(Collectors.toList())); + return zusammenElement; + } - public static Integer toInteger(Object val) { - if (val == null) { - return null; + public static Relation createRelation(RelationType type, String to) { + Relation relation = new Relation(); + relation.setType(type.name()); + RelationEdge edge2 = new RelationEdge(); + edge2.setElementId(new Id(to)); + relation.setEdge2(edge2); + return relation; } - if (val instanceof Double) { - return ((Double) val).intValue(); - } else if (val instanceof String) { - return new Integer((String) val); - } else if (val instanceof Integer) { - return (Integer) val; + + public static Integer toInteger(Object val) { + if (val == null) { + return null; + } + if (val instanceof Double) { + return ((Double) val).intValue(); + } else if (val instanceof String) { + return new Integer((String) val); + } else if (val instanceof Integer) { + return (Integer) val; + } + throw new RuntimeException("invalid value for integer:" + val.getClass()); } - throw new RuntimeException("invalid value for integer:" + val.getClass()); - } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToEntitlementPoolConvertor.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToEntitlementPoolConvertor.java index 2f06b9b0d0..202e0eac68 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToEntitlementPoolConvertor.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToEntitlementPoolConvertor.java @@ -19,99 +19,88 @@ */ package org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor; +import static org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VlmZusammenUtil.toInteger; + import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; import com.amdocs.zusammen.datatypes.item.Info; import com.amdocs.zusammen.datatypes.item.Relation; -import org.openecomp.convertor.ElementConvertor; -import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; -import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolType; -import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther; -import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope; -import org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit; - import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; - -import static org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VlmZusammenUtil.toInteger; - +import org.openecomp.convertor.ElementConvertor; +import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; +import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolType; +import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther; +import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope; +import org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit; public class ElementToEntitlementPoolConvertor extends ElementConvertor { - @Override - public EntitlementPoolEntity convert(Element element) { - if (element == null) { - return null; - } - return mapElementToEntitlementPoolEntity(element); - } - @Override - public EntitlementPoolEntity convert(ElementInfo elementInfo) { - if (elementInfo == null) { - return null; + @Override + public EntitlementPoolEntity convert(Element element) { + if (element == null) { + return null; + } + return mapElementToEntitlementPoolEntity(element); } - return mapElementInfoToEntitlementPoolEntity(elementInfo); - } - - private EntitlementPoolEntity mapElementToEntitlementPoolEntity(Element element) { - EntitlementPoolEntity entitlementPool = - new EntitlementPoolEntity(); - entitlementPool.setId(element.getElementId().getValue()); - mapInfoToEntitlementPoolEntity(entitlementPool, element.getInfo()); - mapRelationsToEntitlementPoolEntity(entitlementPool, element.getRelations()); - return entitlementPool; - } - private EntitlementPoolEntity mapElementInfoToEntitlementPoolEntity(ElementInfo elementInfo) { - EntitlementPoolEntity entitlementPool = - new EntitlementPoolEntity(); - entitlementPool.setId(elementInfo.getId().getValue()); - mapInfoToEntitlementPoolEntity(entitlementPool, elementInfo.getInfo()); - mapRelationsToEntitlementPoolEntity(entitlementPool, elementInfo.getRelations()); - return entitlementPool; - } + @Override + public EntitlementPoolEntity convert(ElementInfo elementInfo) { + if (elementInfo == null) { + return null; + } + return mapElementInfoToEntitlementPoolEntity(elementInfo); + } - private void mapInfoToEntitlementPoolEntity(EntitlementPoolEntity entitlementPool, Info info) { - entitlementPool.setName(info.getName()); - entitlementPool.setDescription(info.getDescription()); - entitlementPool.setVersionUuId(info.getProperty("version_uuid")); - entitlementPool.setType(EntitlementPoolType.permissiveValueOf(info.getProperty("EntitlementPoolType"))); - entitlementPool.setThresholdValue(toInteger(info.getProperty("thresholdValue"))); - String thresholdUnit = info.getProperty("threshold_unit"); - entitlementPool - .setThresholdUnit(thresholdUnit == null ? null : ThresholdUnit.valueOf(thresholdUnit)); - entitlementPool.setIncrements(info.getProperty("increments")); - entitlementPool.setOperationalScope( - getOperationalScopeMultiChoiceOrOther(info.getProperty("operational_scope"))); - entitlementPool.setStartDate(info.getProperty("startDate")); - entitlementPool.setExpiryDate(info.getProperty("expiryDate")); - entitlementPool.setManufacturerReferenceNumber(info.getProperty("manufacturerReferenceNumber")); - } + private EntitlementPoolEntity mapElementToEntitlementPoolEntity(Element element) { + EntitlementPoolEntity entitlementPool = new EntitlementPoolEntity(); + entitlementPool.setId(element.getElementId().getValue()); + mapInfoToEntitlementPoolEntity(entitlementPool, element.getInfo()); + mapRelationsToEntitlementPoolEntity(entitlementPool, element.getRelations()); + return entitlementPool; + } - private void mapRelationsToEntitlementPoolEntity(EntitlementPoolEntity entitlementPool, - Collection<Relation> relations) { - if (relations != null && relations.size() > 0) { - entitlementPool - .setReferencingFeatureGroups(relations.stream().map(relation -> relation - .getEdge2().getElementId().getValue()).collect(Collectors.toSet())); + private EntitlementPoolEntity mapElementInfoToEntitlementPoolEntity(ElementInfo elementInfo) { + EntitlementPoolEntity entitlementPool = new EntitlementPoolEntity(); + entitlementPool.setId(elementInfo.getId().getValue()); + mapInfoToEntitlementPoolEntity(entitlementPool, elementInfo.getInfo()); + mapRelationsToEntitlementPoolEntity(entitlementPool, elementInfo.getRelations()); + return entitlementPool; } - } - private MultiChoiceOrOther<OperationalScope> getOperationalScopeMultiChoiceOrOther( - Map<String, Object> operationalScope) { - if (operationalScope == null || operationalScope.isEmpty()) { - return null; + private void mapInfoToEntitlementPoolEntity(EntitlementPoolEntity entitlementPool, Info info) { + entitlementPool.setName(info.getName()); + entitlementPool.setDescription(info.getDescription()); + entitlementPool.setVersionUuId(info.getProperty("version_uuid")); + entitlementPool.setType(EntitlementPoolType.permissiveValueOf(info.getProperty("EntitlementPoolType"))); + entitlementPool.setThresholdValue(toInteger(info.getProperty("thresholdValue"))); + String thresholdUnit = info.getProperty("threshold_unit"); + entitlementPool.setThresholdUnit(thresholdUnit == null ? null : ThresholdUnit.valueOf(thresholdUnit)); + entitlementPool.setIncrements(info.getProperty("increments")); + entitlementPool.setOperationalScope(getOperationalScopeMultiChoiceOrOther(info.getProperty("operational_scope"))); + entitlementPool.setStartDate(info.getProperty("startDate")); + entitlementPool.setExpiryDate(info.getProperty("expiryDate")); + entitlementPool.setManufacturerReferenceNumber(info.getProperty("manufacturerReferenceNumber")); } - Set<OperationalScope> choices = new HashSet<>(); - ((List<String>) operationalScope.get("choices")). - forEach(choice -> choices.add(OperationalScope.valueOf(choice))); + private void mapRelationsToEntitlementPoolEntity(EntitlementPoolEntity entitlementPool, Collection<Relation> relations) { + if (relations != null && relations.size() > 0) { + entitlementPool.setReferencingFeatureGroups( + relations.stream().map(relation -> relation.getEdge2().getElementId().getValue()).collect(Collectors.toSet())); + } + } - Object other = operationalScope.get("other"); - return new MultiChoiceOrOther<>(choices, other == null ? null : (String) other); - } + private MultiChoiceOrOther<OperationalScope> getOperationalScopeMultiChoiceOrOther(Map<String, Object> operationalScope) { + if (operationalScope == null || operationalScope.isEmpty()) { + return null; + } + Set<OperationalScope> choices = new HashSet<>(); + ((List<String>) operationalScope.get("choices")).forEach(choice -> choices.add(OperationalScope.valueOf(choice))); + Object other = operationalScope.get("other"); + return new MultiChoiceOrOther<>(choices, other == null ? null : (String) other); + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToFeatureGroupConvertor.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToFeatureGroupConvertor.java index 95eee9704c..d12cf3d8ea 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToFeatureGroupConvertor.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToFeatureGroupConvertor.java @@ -23,80 +23,71 @@ import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; import com.amdocs.zusammen.datatypes.item.Info; import com.amdocs.zusammen.datatypes.item.Relation; -import org.openecomp.convertor.ElementConvertor; -import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.RelationType; -import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; - import java.util.Collection; import java.util.HashSet; import java.util.Set; - +import org.openecomp.convertor.ElementConvertor; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.RelationType; +import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; public class ElementToFeatureGroupConvertor extends ElementConvertor { - @Override - public FeatureGroupEntity convert(Element element) { - if (element == null) { - return null; - } - return mapElementToFeatureGroupEntity(element); - - } - @Override - public FeatureGroupEntity convert(ElementInfo elementInfo) { - if (elementInfo == null) { - return null; + @Override + public FeatureGroupEntity convert(Element element) { + if (element == null) { + return null; + } + return mapElementToFeatureGroupEntity(element); } - return mapElementInfoToFeatureGroupEntity(elementInfo); - - } - - - private FeatureGroupEntity mapElementToFeatureGroupEntity(Element element) { - FeatureGroupEntity featureGroup = - new FeatureGroupEntity(); - featureGroup.setId(element.getElementId().getValue()); - mapInfoToFeatureGroup(featureGroup, element.getInfo()); - mapRelationsToFeatureGroup(featureGroup, element.getRelations()); - return featureGroup; - } + @Override + public FeatureGroupEntity convert(ElementInfo elementInfo) { + if (elementInfo == null) { + return null; + } + return mapElementInfoToFeatureGroupEntity(elementInfo); + } - private FeatureGroupEntity mapElementInfoToFeatureGroupEntity(ElementInfo elementInfo) { - FeatureGroupEntity featureGroup = new FeatureGroupEntity(); - featureGroup.setId(elementInfo.getId().getValue()); - mapInfoToFeatureGroup(featureGroup, elementInfo.getInfo()); - mapRelationsToFeatureGroup(featureGroup, elementInfo.getRelations()); - return featureGroup; - } + private FeatureGroupEntity mapElementToFeatureGroupEntity(Element element) { + FeatureGroupEntity featureGroup = new FeatureGroupEntity(); + featureGroup.setId(element.getElementId().getValue()); + mapInfoToFeatureGroup(featureGroup, element.getInfo()); + mapRelationsToFeatureGroup(featureGroup, element.getRelations()); + return featureGroup; + } - private void mapInfoToFeatureGroup(FeatureGroupEntity featureGroup, Info info) { - featureGroup.setName(info.getName()); - featureGroup.setDescription(info.getDescription()); - featureGroup.setPartNumber(info.getProperty("partNumber")); - featureGroup.setManufacturerReferenceNumber(info.getProperty("manufacturerReferenceNumber")); - } + private FeatureGroupEntity mapElementInfoToFeatureGroupEntity(ElementInfo elementInfo) { + FeatureGroupEntity featureGroup = new FeatureGroupEntity(); + featureGroup.setId(elementInfo.getId().getValue()); + mapInfoToFeatureGroup(featureGroup, elementInfo.getInfo()); + mapRelationsToFeatureGroup(featureGroup, elementInfo.getRelations()); + return featureGroup; + } - private void mapRelationsToFeatureGroup(FeatureGroupEntity featureGroup, - Collection<Relation> relations) { - Set<String> entitlementPoolIds = new HashSet<>(); - Set<String> licenseAgreements = new HashSet<>(); - Set<String> licenseKeyGroupIds = new HashSet<>(); + private void mapInfoToFeatureGroup(FeatureGroupEntity featureGroup, Info info) { + featureGroup.setName(info.getName()); + featureGroup.setDescription(info.getDescription()); + featureGroup.setPartNumber(info.getProperty("partNumber")); + featureGroup.setManufacturerReferenceNumber(info.getProperty("manufacturerReferenceNumber")); + } - if (relations != null) { - for (Relation relation : relations) { - if (RelationType.FeatureGroupToEntitlmentPool.name().equals(relation.getType())) { - entitlementPoolIds.add(relation.getEdge2().getElementId().getValue()); - } else if (RelationType.FeatureGroupToLicenseKeyGroup.name().equals(relation.getType())) { - licenseKeyGroupIds.add(relation.getEdge2().getElementId().getValue()); - } else if (RelationType.FeatureGroupToReferencingLicenseAgreement.name() - .equals(relation.getType())) { - licenseAgreements.add(relation.getEdge2().getElementId().getValue()); + private void mapRelationsToFeatureGroup(FeatureGroupEntity featureGroup, Collection<Relation> relations) { + Set<String> entitlementPoolIds = new HashSet<>(); + Set<String> licenseAgreements = new HashSet<>(); + Set<String> licenseKeyGroupIds = new HashSet<>(); + if (relations != null) { + for (Relation relation : relations) { + if (RelationType.FeatureGroupToEntitlmentPool.name().equals(relation.getType())) { + entitlementPoolIds.add(relation.getEdge2().getElementId().getValue()); + } else if (RelationType.FeatureGroupToLicenseKeyGroup.name().equals(relation.getType())) { + licenseKeyGroupIds.add(relation.getEdge2().getElementId().getValue()); + } else if (RelationType.FeatureGroupToReferencingLicenseAgreement.name().equals(relation.getType())) { + licenseAgreements.add(relation.getEdge2().getElementId().getValue()); + } + } } - } + featureGroup.setEntitlementPoolIds(entitlementPoolIds); + featureGroup.setLicenseKeyGroupIds(licenseKeyGroupIds); + featureGroup.setReferencingLicenseAgreements(licenseAgreements); } - featureGroup.setEntitlementPoolIds(entitlementPoolIds); - featureGroup.setLicenseKeyGroupIds(licenseKeyGroupIds); - featureGroup.setReferencingLicenseAgreements(licenseAgreements); - } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLicenseAgreementConvertor.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLicenseAgreementConvertor.java index 0623b10b04..f217c7c4c2 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLicenseAgreementConvertor.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLicenseAgreementConvertor.java @@ -23,83 +23,63 @@ import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; import com.amdocs.zusammen.datatypes.item.Info; import com.amdocs.zusammen.datatypes.item.Relation; +import java.util.Collection; +import java.util.Map; +import java.util.stream.Collectors; import org.openecomp.convertor.ElementConvertor; import org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther; import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity; import org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm; -import java.util.Collection; -import java.util.Map; -import java.util.stream.Collectors; - - public class ElementToLicenseAgreementConvertor extends ElementConvertor { - @Override - public LicenseAgreementEntity convert(Element element) { - if (element == null) { - return null; - } - return mapElementToLicenseAgreementEntity(element); - - } - - @Override - public LicenseAgreementEntity convert(ElementInfo elementInfo) { - if (elementInfo == null) { - return null; + @Override + public LicenseAgreementEntity convert(Element element) { + if (element == null) { + return null; + } + return mapElementToLicenseAgreementEntity(element); } - return mapElementInfoToLicenseAgreementEntity(elementInfo); - - } - - private LicenseAgreementEntity mapElementToLicenseAgreementEntity(Element element) { - LicenseAgreementEntity licenseAgreement = - new LicenseAgreementEntity(); - licenseAgreement.setId(element.getElementId().getValue()); - mapInfoToLicenseAgreementEntity(licenseAgreement, element.getInfo()); - mapRelationsToLicenseAgreementEntity(licenseAgreement, element.getRelations()); - return licenseAgreement; - } - - - private LicenseAgreementEntity mapElementInfoToLicenseAgreementEntity(ElementInfo elementInfo) { - LicenseAgreementEntity licenseAgreement = - new LicenseAgreementEntity(); - licenseAgreement.setId( elementInfo.getId().getValue()); - mapInfoToLicenseAgreementEntity(licenseAgreement, elementInfo.getInfo()); - mapRelationsToLicenseAgreementEntity(licenseAgreement, elementInfo.getRelations()); - return licenseAgreement; - } - - private void mapRelationsToLicenseAgreementEntity(LicenseAgreementEntity licenseAgreementEntity, - Collection<Relation> relations) { - if (relations != null && relations.size() > 0) { - licenseAgreementEntity.setFeatureGroupIds(relations.stream() - .map(relation -> relation.getEdge2().getElementId().getValue()) - .collect(Collectors.toSet())); + @Override + public LicenseAgreementEntity convert(ElementInfo elementInfo) { + if (elementInfo == null) { + return null; + } + return mapElementInfoToLicenseAgreementEntity(elementInfo); } - } - - private void mapInfoToLicenseAgreementEntity(LicenseAgreementEntity licenseAgreement, Info info) { - - - licenseAgreement.setName(info.getName()); - licenseAgreement.setDescription(info.getDescription()); - - licenseAgreement - .setLicenseTerm(getCoiceOrOther(info.getProperty("licenseTerm"))); - licenseAgreement.setRequirementsAndConstrains( - info.getProperty("requirementsAndConstrains")); + private LicenseAgreementEntity mapElementToLicenseAgreementEntity(Element element) { + LicenseAgreementEntity licenseAgreement = new LicenseAgreementEntity(); + licenseAgreement.setId(element.getElementId().getValue()); + mapInfoToLicenseAgreementEntity(licenseAgreement, element.getInfo()); + mapRelationsToLicenseAgreementEntity(licenseAgreement, element.getRelations()); + return licenseAgreement; + } - } + private LicenseAgreementEntity mapElementInfoToLicenseAgreementEntity(ElementInfo elementInfo) { + LicenseAgreementEntity licenseAgreement = new LicenseAgreementEntity(); + licenseAgreement.setId(elementInfo.getId().getValue()); + mapInfoToLicenseAgreementEntity(licenseAgreement, elementInfo.getInfo()); + mapRelationsToLicenseAgreementEntity(licenseAgreement, elementInfo.getRelations()); + return licenseAgreement; + } - private ChoiceOrOther<LicenseTerm> getCoiceOrOther(Map licenseTerm) { - return new ChoiceOrOther<>(LicenseTerm.valueOf((String) licenseTerm.get("choice")), - (String) licenseTerm.get("other")); - } + private void mapRelationsToLicenseAgreementEntity(LicenseAgreementEntity licenseAgreementEntity, Collection<Relation> relations) { + if (relations != null && relations.size() > 0) { + licenseAgreementEntity + .setFeatureGroupIds(relations.stream().map(relation -> relation.getEdge2().getElementId().getValue()).collect(Collectors.toSet())); + } + } + private void mapInfoToLicenseAgreementEntity(LicenseAgreementEntity licenseAgreement, Info info) { + licenseAgreement.setName(info.getName()); + licenseAgreement.setDescription(info.getDescription()); + licenseAgreement.setLicenseTerm(getCoiceOrOther(info.getProperty("licenseTerm"))); + licenseAgreement.setRequirementsAndConstrains(info.getProperty("requirementsAndConstrains")); + } + private ChoiceOrOther<LicenseTerm> getCoiceOrOther(Map licenseTerm) { + return new ChoiceOrOther<>(LicenseTerm.valueOf((String) licenseTerm.get("choice")), (String) licenseTerm.get("other")); + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLicenseKeyGroupConvertor.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLicenseKeyGroupConvertor.java index c22fcf8935..601a5ec35a 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLicenseKeyGroupConvertor.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLicenseKeyGroupConvertor.java @@ -19,103 +19,88 @@ */ package org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor; +import static org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VlmZusammenUtil.toInteger; + import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; import com.amdocs.zusammen.datatypes.item.Info; import com.amdocs.zusammen.datatypes.item.Relation; -import org.openecomp.convertor.ElementConvertor; -import org.openecomp.sdc.vendorlicense.dao.types.*; - -import java.util.stream.Collectors; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; - - -import static org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VlmZusammenUtil.toInteger; - +import java.util.stream.Collectors; +import org.openecomp.convertor.ElementConvertor; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType; +import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther; +import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope; +import org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit; public class ElementToLicenseKeyGroupConvertor extends ElementConvertor { - @Override - public LicenseKeyGroupEntity convert(Element element) { - if (element == null) { - return null; - } - return mapElementToLicenseKeyGroupEntity(element); - } - - @Override - public LicenseKeyGroupEntity convert(ElementInfo elementInfo) { - if (elementInfo == null) { - return null; + @Override + public LicenseKeyGroupEntity convert(Element element) { + if (element == null) { + return null; + } + return mapElementToLicenseKeyGroupEntity(element); } - return mapElementInfoToLicenseKeyGroupEntity(elementInfo); - - } - - private LicenseKeyGroupEntity mapElementToLicenseKeyGroupEntity( - Element element) { - LicenseKeyGroupEntity licenseKeyGroup = - new LicenseKeyGroupEntity(); - licenseKeyGroup.setId(element.getElementId().getValue()); - mapInfoToLicenseKeyGroup(licenseKeyGroup, element.getInfo()); - mapRelationsToLicenseKeyGroup(licenseKeyGroup, element.getRelations()); - return licenseKeyGroup; - } - - - private LicenseKeyGroupEntity mapElementInfoToLicenseKeyGroupEntity(ElementInfo elementInfo) { - LicenseKeyGroupEntity licenseKeyGroup = - new LicenseKeyGroupEntity(); - licenseKeyGroup.setId(elementInfo.getId().getValue()); - - mapInfoToLicenseKeyGroup(licenseKeyGroup, elementInfo.getInfo()); - mapRelationsToLicenseKeyGroup(licenseKeyGroup, elementInfo.getRelations()); - return licenseKeyGroup; - } - private void mapInfoToLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, Info info) { - licenseKeyGroup.setName(info.getName()); - licenseKeyGroup.setDescription(info.getDescription()); - licenseKeyGroup.setVersionUuId(info.getProperty("version_uuid")); - licenseKeyGroup.setType(LicenseKeyType.valueOf(info.getProperty("LicenseKeyType"))); - licenseKeyGroup.setOperationalScope( - getOperationalScopeMultiChoiceOrOther(info.getProperty("operational_scope"))); - licenseKeyGroup.setStartDate(info.getProperty("startDate")); - licenseKeyGroup.setExpiryDate(info.getProperty("expiryDate")); - - String thresholdUnit = info.getProperty("thresholdUnits"); - licenseKeyGroup - .setThresholdUnits(thresholdUnit == null ? null : ThresholdUnit.valueOf(thresholdUnit)); + @Override + public LicenseKeyGroupEntity convert(ElementInfo elementInfo) { + if (elementInfo == null) { + return null; + } + return mapElementInfoToLicenseKeyGroupEntity(elementInfo); + } - licenseKeyGroup.setThresholdValue(toInteger(info.getProperty("thresholdValue"))); - licenseKeyGroup.setIncrements(info.getProperty("increments")); - licenseKeyGroup.setManufacturerReferenceNumber(info.getProperty("manufacturerReferenceNumber")); - } + private LicenseKeyGroupEntity mapElementToLicenseKeyGroupEntity(Element element) { + LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity(); + licenseKeyGroup.setId(element.getElementId().getValue()); + mapInfoToLicenseKeyGroup(licenseKeyGroup, element.getInfo()); + mapRelationsToLicenseKeyGroup(licenseKeyGroup, element.getRelations()); + return licenseKeyGroup; + } - private void mapRelationsToLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, - Collection<Relation> relations) { - if (relations != null && relations.size() > 0) { - licenseKeyGroup - .setReferencingFeatureGroups((relations.stream().map(relation -> relation - .getEdge2().getElementId().getValue()).collect(Collectors.toSet()))); + private LicenseKeyGroupEntity mapElementInfoToLicenseKeyGroupEntity(ElementInfo elementInfo) { + LicenseKeyGroupEntity licenseKeyGroup = new LicenseKeyGroupEntity(); + licenseKeyGroup.setId(elementInfo.getId().getValue()); + mapInfoToLicenseKeyGroup(licenseKeyGroup, elementInfo.getInfo()); + mapRelationsToLicenseKeyGroup(licenseKeyGroup, elementInfo.getRelations()); + return licenseKeyGroup; } - } - private MultiChoiceOrOther<OperationalScope> getOperationalScopeMultiChoiceOrOther( - Map<String, Object> operationalScope) { - if (operationalScope == null || operationalScope.isEmpty()) { - return null; + private void mapInfoToLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, Info info) { + licenseKeyGroup.setName(info.getName()); + licenseKeyGroup.setDescription(info.getDescription()); + licenseKeyGroup.setVersionUuId(info.getProperty("version_uuid")); + licenseKeyGroup.setType(LicenseKeyType.valueOf(info.getProperty("LicenseKeyType"))); + licenseKeyGroup.setOperationalScope(getOperationalScopeMultiChoiceOrOther(info.getProperty("operational_scope"))); + licenseKeyGroup.setStartDate(info.getProperty("startDate")); + licenseKeyGroup.setExpiryDate(info.getProperty("expiryDate")); + String thresholdUnit = info.getProperty("thresholdUnits"); + licenseKeyGroup.setThresholdUnits(thresholdUnit == null ? null : ThresholdUnit.valueOf(thresholdUnit)); + licenseKeyGroup.setThresholdValue(toInteger(info.getProperty("thresholdValue"))); + licenseKeyGroup.setIncrements(info.getProperty("increments")); + licenseKeyGroup.setManufacturerReferenceNumber(info.getProperty("manufacturerReferenceNumber")); } - Set<OperationalScope> choices = new HashSet<>(); - ((List<String>) operationalScope.get("choices")). - forEach(choice -> choices.add(OperationalScope.valueOf(choice))); + private void mapRelationsToLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, Collection<Relation> relations) { + if (relations != null && relations.size() > 0) { + licenseKeyGroup.setReferencingFeatureGroups( + (relations.stream().map(relation -> relation.getEdge2().getElementId().getValue()).collect(Collectors.toSet()))); + } + } - Object other = operationalScope.get("other"); - return new MultiChoiceOrOther<>(choices, other == null ? null : (String) other); - } + private MultiChoiceOrOther<OperationalScope> getOperationalScopeMultiChoiceOrOther(Map<String, Object> operationalScope) { + if (operationalScope == null || operationalScope.isEmpty()) { + return null; + } + Set<OperationalScope> choices = new HashSet<>(); + ((List<String>) operationalScope.get("choices")).forEach(choice -> choices.add(OperationalScope.valueOf(choice))); + Object other = operationalScope.get("other"); + return new MultiChoiceOrOther<>(choices, other == null ? null : (String) other); + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLimitConvertor.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLimitConvertor.java index 20674c669a..ace15af3bf 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLimitConvertor.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLimitConvertor.java @@ -24,36 +24,36 @@ import org.openecomp.sdc.vendorlicense.dao.types.LimitType; * Created by ayalaben on 9/26/2017 */ public class ElementToLimitConvertor extends ElementConvertor<LimitEntity> { - @Override - public LimitEntity convert(Element element) { - if (element == null) { - return null; - } - return mapElementToLimitEntity(element); - } - private LimitEntity mapElementToLimitEntity(Element element) { - LimitEntity limit = new LimitEntity(); - limit.setId(element.getElementId().getValue()); - limit.setName(element.getInfo().getName()); - limit.setDescription(element.getInfo().getDescription()); - limit.setUnit(element.getInfo().getProperty("unit")); - limit.setMetric(element.getInfo().getProperty("metric")); - limit.setValue(element.getInfo().getProperty("value")); - limit.setTime(element.getInfo().getProperty("time")); - limit.setAggregationFunction(element.getInfo().getProperty("aggregationFunction")); - setLimitType(limit,element.getInfo().getProperty("type")); + @Override + public LimitEntity convert(Element element) { + if (element == null) { + return null; + } + return mapElementToLimitEntity(element); + } - return limit; - } + private LimitEntity mapElementToLimitEntity(Element element) { + LimitEntity limit = new LimitEntity(); + limit.setId(element.getElementId().getValue()); + limit.setName(element.getInfo().getName()); + limit.setDescription(element.getInfo().getDescription()); + limit.setUnit(element.getInfo().getProperty("unit")); + limit.setMetric(element.getInfo().getProperty("metric")); + limit.setValue(element.getInfo().getProperty("value")); + limit.setTime(element.getInfo().getProperty("time")); + limit.setAggregationFunction(element.getInfo().getProperty("aggregationFunction")); + setLimitType(limit, element.getInfo().getProperty("type")); + return limit; + } - private void setLimitType(LimitEntity limit, String type) { - switch (LimitType.valueOf(type)) { - case ServiceProvider: - limit.setType(LimitType.ServiceProvider); - break; - case Vendor: - limit.setType(LimitType.Vendor); + private void setLimitType(LimitEntity limit, String type) { + switch (LimitType.valueOf(type)) { + case ServiceProvider: + limit.setType(LimitType.ServiceProvider); + break; + case Vendor: + limit.setType(LimitType.Vendor); + } } - } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToVLMGeneralConvertor.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToVLMGeneralConvertor.java index 5dc3b592c0..e274e264c0 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToVLMGeneralConvertor.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToVLMGeneralConvertor.java @@ -27,39 +27,37 @@ import org.openecomp.convertor.ElementConvertor; import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VendorLicenseModelDaoZusammenImpl; import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity; - public class ElementToVLMGeneralConvertor extends ElementConvertor { - @Override - public VendorLicenseModelEntity convert(Element element) { - if(element == null) return null; - return mapInfoToVendorLicenseModelEntity( element.getInfo()); - - } - - @Override - public VendorLicenseModelEntity convert(Item item) { - if(item == null) return null; - return mapInfoToVendorLicenseModelEntity( item.getInfo()); - } - - @Override - public VendorLicenseModelEntity convert(ElementInfo elementInfo) { - if(elementInfo == null) return null; - return mapInfoToVendorLicenseModelEntity( elementInfo.getInfo()); - - } - - private VendorLicenseModelEntity mapInfoToVendorLicenseModelEntity(Info info) { - - VendorLicenseModelEntity vendorLicenseModelEntity = new VendorLicenseModelEntity(); - - vendorLicenseModelEntity.setVendorName(info.getProperty( - VendorLicenseModelDaoZusammenImpl.InfoPropertyName.name.name())); - vendorLicenseModelEntity.setDescription(info.getProperty( - VendorLicenseModelDaoZusammenImpl.InfoPropertyName.description.name())); - vendorLicenseModelEntity.setIconRef(info.getProperty( - VendorLicenseModelDaoZusammenImpl.InfoPropertyName.iconRef.name())); - return vendorLicenseModelEntity; - } + @Override + public VendorLicenseModelEntity convert(Element element) { + if (element == null) { + return null; + } + return mapInfoToVendorLicenseModelEntity(element.getInfo()); + } + + @Override + public VendorLicenseModelEntity convert(Item item) { + if (item == null) { + return null; + } + return mapInfoToVendorLicenseModelEntity(item.getInfo()); + } + + @Override + public VendorLicenseModelEntity convert(ElementInfo elementInfo) { + if (elementInfo == null) { + return null; + } + return mapInfoToVendorLicenseModelEntity(elementInfo.getInfo()); + } + + private VendorLicenseModelEntity mapInfoToVendorLicenseModelEntity(Info info) { + VendorLicenseModelEntity vendorLicenseModelEntity = new VendorLicenseModelEntity(); + vendorLicenseModelEntity.setVendorName(info.getProperty(VendorLicenseModelDaoZusammenImpl.InfoPropertyName.name.name())); + vendorLicenseModelEntity.setDescription(info.getProperty(VendorLicenseModelDaoZusammenImpl.InfoPropertyName.description.name())); + vendorLicenseModelEntity.setIconRef(info.getProperty(VendorLicenseModelDaoZusammenImpl.InfoPropertyName.iconRef.name())); + return vendorLicenseModelEntity; + } } |