From 280f8015d06af1f41a3ef12e8300801c7a5e0d54 Mon Sep 17 00:00:00 2001 From: AviZi Date: Fri, 9 Jun 2017 02:39:56 +0300 Subject: [SDC-29] Amdocs OnBoard 1707 initial commit. Change-Id: Ie4d12a3f574008b792899b368a0902a8b46b5370 Signed-off-by: AviZi --- .../openecomp-sdc-vendor-license-core/pom.xml | 24 +- .../pom.xml.versionsBackup | 53 ++++ .../dao/impl/EntitlementPoolCassandraDaoImpl.java | 2 +- .../dao/impl/EntitlementPoolDaoFactoryImpl.java | 5 +- .../dao/impl/FeatureGroupCassandraDaoImpl.java | 43 +-- .../dao/impl/FeatureGroupDaoFactoryImpl.java | 5 +- .../dao/impl/LicenseAgreementCassandraDaoImpl.java | 1 + .../dao/impl/LicenseAgreementDaoFactoryImpl.java | 5 +- .../dao/impl/LicenseKeyGroupCassandraDaoImpl.java | 9 +- .../dao/impl/LicenseKeyGroupDaoFactoryImpl.java | 4 +- .../impl/VendorLicenseModelCassandraDaoImpl.java | 13 +- .../dao/impl/VendorLicenseModelDaoFactoryImpl.java | 5 +- .../dao/impl/zusammen/ElementPropertyName.java | 6 + .../dao/impl/zusammen/ElementType.java | 6 + .../zusammen/EntitlementPoolZusammenDaoImpl.java | 291 ++++++++++++++++++ .../impl/zusammen/FeatureGroupDaoZusammenImpl.java | 326 +++++++++++++++++++++ .../zusammen/LicenseAgreementDaoZusammenImpl.java | 249 ++++++++++++++++ .../zusammen/LicenseKeyGroupZusammenDaoImpl.java | 243 +++++++++++++++ .../dao/impl/zusammen/RelationType.java | 10 + .../dao/impl/zusammen/StructureElement.java | 9 + .../VendorLicenseModelDaoZusammenImpl.java | 138 +++++++++ .../dao/impl/zusammen/VlmZusammenUtil.java | 68 +++++ .../facade/impl/VendorLicenseFacadeImpl.java | 291 +++++++++--------- .../healing/impl/SimpleHealingServiceImpl.java | 28 +- .../impl/VendorLicenseArtifactsServiceImpl.java | 174 ++++------- .../impl/types/VnfLicenseArtifact.java | 4 +- .../licenseartifacts/impl/types/XmlArtifact.java | 13 +- ...itlementPoolEntityForVendorLicenseArtifact.java | 20 +- .../MixinEntitlementPoolEntityForVnfArtifact.java | 3 + .../impl/types/mixins/MixinFeatureGroupModel.java | 2 +- ...enseKeyGroupEntityForVendorLicenseArtifact.java | 6 +- .../MixinLicenseKeyGroupEntityForVnfArtifact.java | 5 +- .../util/VendorLicenseArtifactsServiceUtils.java | 132 +++++++++ .../VersionableEntitySortByVlmMajorVersion.java | 38 +++ 34 files changed, 1912 insertions(+), 319 deletions(-) create mode 100644 openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/pom.xml.versionsBackup create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/RelationType.java create mode 100644 openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/StructureElement.java create mode 100644 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 create mode 100644 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 create mode 100644 openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/util/VendorLicenseArtifactsServiceUtils.java create mode 100644 openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/util/VersionableEntitySortByVlmMajorVersion.java (limited to 'openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core') diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/pom.xml b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/pom.xml index 94d2bdc45a..7ac5aef2f7 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/pom.xml +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/pom.xml @@ -5,6 +5,7 @@ openecomp-sdc-vendor-license-core openecomp-sdc-vendor-license-core + org.openecomp.sdc openecomp-sdc-lib @@ -18,12 +19,22 @@ openecomp-sdc-vendor-license-api ${project.version} - + + org.openecomp.core + openecomp-zusammen-api + ${project.version} + + + org.openecomp.core + openecomp-zusammen-core + ${project.version} + runtime + org.mockito mockito-all test - 1.10.19 + ${mockito.all.version} org.testng @@ -41,8 +52,13 @@ junit junit test - RELEASE + 4.11 + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + ${jackson.dataformat.version} - \ No newline at end of file + diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/pom.xml.versionsBackup b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/pom.xml.versionsBackup new file mode 100644 index 0000000000..b1141fc5cd --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/pom.xml.versionsBackup @@ -0,0 +1,53 @@ + + 4.0.0 + + openecomp-sdc-vendor-license-core + openecomp-sdc-vendor-license-core + + + + org.openecomp.sdc + openecomp-sdc-lib + 1.0-SNAPSHOT + ../.. + + + + org.openecomp.sdc + openecomp-sdc-vendor-license-api + ${project.version} + + + + org.mockito + mockito-all + test + 1.10.19 + + + org.testng + testng + test + 6.8.5 + + + snakeyaml + org.yaml + + + + + junit + junit + test + 4.11 + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + 2.7.4 + + + + \ No newline at end of file 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/EntitlementPoolCassandraDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/EntitlementPoolCassandraDaoImpl.java index 1722f8f8de..496e653ef0 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/EntitlementPoolCassandraDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/EntitlementPoolCassandraDaoImpl.java @@ -133,7 +133,7 @@ public class EntitlementPoolCassandraDaoImpl extends CassandraBaseDao referencingFeatureGroups, String vendorLicenseModelId, UDTValue vendorLicenseModelVersion, String id); 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 c1046f79cd..dba631a6ed 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 @@ -20,11 +20,14 @@ package org.openecomp.sdc.vendorlicense.dao.impl; +import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; 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 EntitlementPoolCassandraDaoImpl(); + private static EntitlementPoolDao INSTANCE = new EntitlementPoolZusammenDaoImpl(ZusammenAdaptorFactory.getInstance().createInterface()); @Override public EntitlementPoolDao createInterface() { 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/FeatureGroupCassandraDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/FeatureGroupCassandraDaoImpl.java index 86957a02c7..2568d719e2 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/FeatureGroupCassandraDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/FeatureGroupCassandraDaoImpl.java @@ -20,6 +20,8 @@ package org.openecomp.sdc.vendorlicense.dao.impl; +import static org.openecomp.core.utilities.CommonMethods.toSingleElementSet; + import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.UDTValue; import com.datastax.driver.mapping.Mapper; @@ -45,7 +47,6 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; - public class FeatureGroupCassandraDaoImpl extends CassandraBaseDao implements FeatureGroupDao { @@ -94,6 +95,12 @@ public class FeatureGroupCassandraDaoImpl extends CassandraBaseDao addedEntitlementPools, @@ -114,18 +121,6 @@ public class FeatureGroupCassandraDaoImpl extends CassandraBaseDao list(FeatureGroupEntity entity) { - return accessor.listByVlmVersion(entity.getVendorLicenseModelId(), - versionMapper.toUDT(entity.getVersion())).all(); - } - - @Override - public void deleteAll(FeatureGroupEntity entity) { - accessor.deleteByVlmVersion(entity.getVendorLicenseModelId(), - versionMapper.toUDT(entity.getVersion())).all(); - } - @Override public void addReferencingLicenseAgreement(FeatureGroupEntity entity, String licenseAgreementId) { accessor.addReferencingLicenseAgreements(CommonMethods.toSingleElementSet(licenseAgreementId), @@ -143,16 +138,22 @@ public class FeatureGroupCassandraDaoImpl extends CassandraBaseDao list(FeatureGroupEntity entity) { + return accessor.listByVlmVersion(entity.getVendorLicenseModelId(), + versionMapper.toUDT(entity.getVersion())).all(); + } + @Accessor interface FeatureGroupAccessor { @@ -167,8 +168,8 @@ public class FeatureGroupCassandraDaoImpl extends CassandraBaseDao addedEntitlementPools, @@ -179,15 +180,15 @@ public class FeatureGroupCassandraDaoImpl extends CassandraBaseDao licenseAgreementIds, String vendorLicenseModelId, UDTValue version, String id); @Query( - "UPDATE feature_group SET ref_la_ids = ref_la_ids - ? " - + "WHERE vlm_id=? AND version=? AND fg_id=?") + "UPDATE feature_group SET ref_la_ids = ref_la_ids - ? WHERE vlm_id=? AND version=? AND " + + "fg_id=?") ResultSet removeReferencingLicenseAgreements(Set licenseAgreementIds, String vendorLicenseModelId, UDTValue version, String id); 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 941b2b5ecc..830ca4c6c4 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 @@ -20,11 +20,14 @@ package org.openecomp.sdc.vendorlicense.dao.impl; +import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; 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 FeatureGroupCassandraDaoImpl(); + private static FeatureGroupDao INSTANCE = new FeatureGroupDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface()); @Override public FeatureGroupDao createInterface() { 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/LicenseAgreementCassandraDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LicenseAgreementCassandraDaoImpl.java index 6a7cc2aa60..3b5a3b3bb4 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LicenseAgreementCassandraDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LicenseAgreementCassandraDaoImpl.java @@ -46,6 +46,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; + public class LicenseAgreementCassandraDaoImpl extends CassandraBaseDao implements LicenseAgreementDao { private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); 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 d92e2562e9..2c1b915200 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 @@ -20,11 +20,14 @@ package org.openecomp.sdc.vendorlicense.dao.impl; +import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao; import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDaoFactory; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.LicenseAgreementDaoZusammenImpl; public class LicenseAgreementDaoFactoryImpl extends LicenseAgreementDaoFactory { - private static LicenseAgreementDao INSTANCE = new LicenseAgreementCassandraDaoImpl(); + private static LicenseAgreementDao INSTANCE = new LicenseAgreementDaoZusammenImpl( + ZusammenAdaptorFactory.getInstance().createInterface()); @Override public LicenseAgreementDao createInterface() { 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/LicenseKeyGroupCassandraDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LicenseKeyGroupCassandraDaoImpl.java index c6952c8d03..96eecc9747 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LicenseKeyGroupCassandraDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/LicenseKeyGroupCassandraDaoImpl.java @@ -88,6 +88,11 @@ public class LicenseKeyGroupCassandraDaoImpl extends CassandraBaseDao deleteByVlmVersion(String vendorLicenseModelId, UDTValue version); @Query( - "UPDATE license_key_group SET ref_fg_ids = ref_fg_ids + ? WHERE vlm_id=? AND version=?" - + " AND lkg_id=?") + "UPDATE license_key_group SET ref_fg_ids = ref_fg_ids + ? WHERE vlm_id=? AND version=? " + + "AND lkg_id=?") ResultSet addReferencingFeatureGroups(Set referencingFeatureGroups, String vendorLicenseModelId, UDTValue version, String id); 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 16d1fd2a3e..407e24d906 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 @@ -20,11 +20,13 @@ package org.openecomp.sdc.vendorlicense.dao.impl; +import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao; import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDaoFactory; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.LicenseKeyGroupZusammenDaoImpl; public class LicenseKeyGroupDaoFactoryImpl extends LicenseKeyGroupDaoFactory { - private static LicenseKeyGroupDao INSTANCE = new LicenseKeyGroupCassandraDaoImpl(); + private static LicenseKeyGroupDao INSTANCE = new LicenseKeyGroupZusammenDaoImpl(ZusammenAdaptorFactory.getInstance().createInterface()); @Override public LicenseKeyGroupDao createInterface() { 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/VendorLicenseModelCassandraDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/VendorLicenseModelCassandraDaoImpl.java index 4d08d98bd7..b52f4ba9dd 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/VendorLicenseModelCassandraDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/VendorLicenseModelCassandraDaoImpl.java @@ -37,7 +37,8 @@ import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; import java.util.Collection; public class VendorLicenseModelCassandraDaoImpl extends CassandraBaseDao - implements VendorLicenseModelDao { + implements + VendorLicenseModelDao { private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); private static Mapper mapper = @@ -71,21 +72,11 @@ public class VendorLicenseModelCassandraDaoImpl extends CassandraBaseDao getAll(); - // @Query("UPDATE vendor_license_model set last_modification_time - // = ? where vlm_id = ? and version = ?") - // ResultSet updateLastModificationTime(Date lastModificationTime, - // String vlmId, UDTValue version); } } 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 d218ca4907..79d0677da7 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 @@ -20,12 +20,15 @@ package org.openecomp.sdc.vendorlicense.dao.impl; +import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao; import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDaoFactory; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VendorLicenseModelDaoZusammenImpl; public class VendorLicenseModelDaoFactoryImpl extends VendorLicenseModelDaoFactory { - private static VendorLicenseModelDao INSTANCE = new VendorLicenseModelCassandraDaoImpl(); + private static VendorLicenseModelDao INSTANCE = new VendorLicenseModelDaoZusammenImpl( + ZusammenAdaptorFactory.getInstance().createInterface()); @Override public VendorLicenseModelDao createInterface() { 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 new file mode 100644 index 0000000000..560402abf2 --- /dev/null +++ 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 @@ -0,0 +1,6 @@ +package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; + +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 new file mode 100644 index 0000000000..4d9c0fa98c --- /dev/null +++ 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 @@ -0,0 +1,6 @@ +package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; + +public enum ElementType { + + +} 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 new file mode 100644 index 0000000000..f133aaad9a --- /dev/null +++ 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 @@ -0,0 +1,291 @@ +package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; + +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; +import com.amdocs.zusammen.datatypes.Id; +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 org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenUtil; +import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao; +import org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction; +import org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther; +import org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric; +import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; +import org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime; +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 org.openecomp.sdc.versioning.dao.types.Version; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Created by ayalaben on 3/28/2017. + */ +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 = + VlmZusammenUtil.buildStructuralElement(StructureElement.EntitlementPools, null); + + entitlementPoolsElement.addSubElement(entitlementPoolElement); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(entitlementPool.getVendorLicenseModelId()); + Optional savedElement = zusammenAdaptor.saveElement(context, new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), + entitlementPoolsElement, "Create entitlement pool"); + + savedElement.ifPresent(element -> entitlementPool + .setId(element.getSubElements().iterator().next().getElementId().getValue())); + } + + @Override + public void update(EntitlementPoolEntity entitlementPool) { + ZusammenElement entitlmentpoolElement = + buildEntitlementPoolElement(entitlementPool, Action.UPDATE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(entitlementPool.getVendorLicenseModelId()); + zusammenAdaptor.saveElement(context, new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), entitlmentpoolElement, + String.format("Update entitlement pool with id %s", entitlementPool.getId())); + } + + @Override + public EntitlementPoolEntity get(EntitlementPoolEntity entitlementPool) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(entitlementPool.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VlmZusammenUtil.getVersionTag(entitlementPool.getVersion())); + + return zusammenAdaptor.getElementInfo(context, elementContext, new Id(entitlementPool.getId())) + .map(elementInfo -> mapElementInfoToEntitlementPool( + entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion(), elementInfo)) + .orElse(null); + } + + @Override + public void delete(EntitlementPoolEntity entitlementPool) { + SessionContext context = ZusammenUtil.createSessionContext(); + ZusammenElement zusammenElement = new ZusammenElement(); + zusammenElement.setAction(Action.DELETE); + zusammenElement.setElementId(new Id(entitlementPool.getId())); + + Id itemId = new Id(entitlementPool.getVendorLicenseModelId()); + ElementContext elementContext = + new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, + "delete entitlement pool. id:" + entitlementPool.getId() + "."); + } + + @Override + public Collection list(EntitlementPoolEntity entitlementPool) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(entitlementPool.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VlmZusammenUtil.getVersionTag(entitlementPool.getVersion())); + + return zusammenAdaptor + .listElementsByName(context, elementContext, null, StructureElement.EntitlementPools.name()) + .stream().map(elementInfo -> mapElementInfoToEntitlementPool( + entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion(), elementInfo)) + .collect(Collectors.toList()); + } + + @Override + public long count(EntitlementPoolEntity entitlementPool) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(entitlementPool.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VlmZusammenUtil.getVersionTag(entitlementPool.getVersion())); + + return zusammenAdaptor + .listElementsByName(context, elementContext, null, StructureElement.EntitlementPools.name()) + .size(); + } + + @Override + public void removeReferencingFeatureGroup(EntitlementPoolEntity entitlementPool, + String referencingFeatureGroupId) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(entitlementPool.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + Optional 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(); + Id itemId = new Id(entitlementPool.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + Optional 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 + } + + private ZusammenElement buildEntitlementPoolElement(EntitlementPoolEntity entitlementPool, + Action action) { + ZusammenElement entitlementPoolElement = new ZusammenElement(); + entitlementPoolElement.setAction(action); + if (entitlementPool.getId() != null) { + entitlementPoolElement.setElementId(new Id(entitlementPool.getId())); + } + Info info = new Info(); + info.setName(entitlementPool.getName()); + info.setDescription(entitlementPool.getDescription()); + info.addProperty("thresholdValue", entitlementPool.getThresholdValue()); + info.addProperty("threshold_unit", entitlementPool.getThresholdUnit()); + info.addProperty("entitlement_metric", entitlementPool.getEntitlementMetric()); + info.addProperty("increments", entitlementPool.getIncrements()); + info.addProperty("aggregation_func", entitlementPool.getAggregationFunction()); + info.addProperty("operational_scope", entitlementPool.getOperationalScope()); + info.addProperty("EntitlementTime", entitlementPool.getTime()); + info.addProperty("manufacturerReferenceNumber", + entitlementPool.getManufacturerReferenceNumber()); + entitlementPoolElement.setInfo(info); + + if (entitlementPool.getReferencingFeatureGroups() != null && + entitlementPool.getReferencingFeatureGroups().size() > 0) { + entitlementPoolElement.setRelations(entitlementPool.getReferencingFeatureGroups().stream() + .map(rel -> VlmZusammenUtil + .createRelation(RelationType.EntitlmentPoolToReferencingFeatureGroup, rel)) + .collect(Collectors.toList())); + } + return entitlementPoolElement; + } + + private EntitlementPoolEntity mapElementInfoToEntitlementPool(String vlmId, Version version, + ElementInfo elementInfo) { + EntitlementPoolEntity entitlmentPool = + new EntitlementPoolEntity(vlmId, version, elementInfo.getId().getValue()); + entitlmentPool.setName(elementInfo.getInfo().getName()); + entitlmentPool.setDescription(elementInfo.getInfo().getDescription()); + entitlmentPool + .setThresholdValue(toInteger(elementInfo.getInfo().getProperty("thresholdValue"))); + entitlmentPool.setThresholdUnit( + ThresholdUnit.valueOf(elementInfo.getInfo().getProperty("threshold_unit"))); + entitlmentPool.setEntitlementMetric( + getEntitlementMetricCoiceOrOther(elementInfo.getInfo().getProperty("entitlement_metric"))); + entitlmentPool.setIncrements(elementInfo.getInfo().getProperty("increments")); + entitlmentPool.setAggregationFunction( + getAggregationFuncCoiceOrOther(elementInfo.getInfo().getProperty("aggregation_func"))); + entitlmentPool.setOperationalScope(getOperationalScopeMultiChoiceOrOther( + elementInfo.getInfo().getProperty("operational_scope"))); + entitlmentPool.setTime( + getEntitlementTimeCoiceOrOther(elementInfo.getInfo().getProperty("EntitlementTime"))); + entitlmentPool.setManufacturerReferenceNumber( + elementInfo.getInfo().getProperty("manufacturerReferenceNumber")); + + if (elementInfo.getRelations() != null && elementInfo.getRelations().size() > 0) { + entitlmentPool + .setReferencingFeatureGroups(elementInfo.getRelations().stream().map(relation -> relation + .getEdge2().getElementId().getValue()).collect(Collectors.toSet())); + } + return entitlmentPool; + } + + private ChoiceOrOther getAggregationFuncCoiceOrOther( + Map aggregationFunction) { + return new ChoiceOrOther<> + (AggregationFunction.valueOf((String) aggregationFunction.get("choice")), + (String) aggregationFunction.get("other")); + } + + private ChoiceOrOther getEntitlementMetricCoiceOrOther(Map entitlementMetric) { + return new ChoiceOrOther<>(EntitlementMetric.valueOf((String) entitlementMetric.get("choice") + ), (String) entitlementMetric.get("other")); + } + + private ChoiceOrOther getEntitlementTimeCoiceOrOther(Map entitlementTime) { + return new ChoiceOrOther<>(EntitlementTime.valueOf((String) entitlementTime.get("choice")), + (String) entitlementTime.get("other")); + } + + private MultiChoiceOrOther getOperationalScopeMultiChoiceOrOther + (Map + operationalScope) { + Set choices = new HashSet<>(); + ((List) operationalScope.get("choices")). + forEach(choice -> choices.add(OperationalScope.valueOf(choice))); + + return new MultiChoiceOrOther<>(choices, (String) operationalScope.get("other")); + } + + private Integer toInteger(Object val) { + 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()); + } + +} 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 new file mode 100644 index 0000000000..ee6ffbfca2 --- /dev/null +++ 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 @@ -0,0 +1,326 @@ +package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; + +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; +import com.amdocs.zusammen.datatypes.Id; +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 com.amdocs.zusammen.datatypes.item.Relation; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenUtil; +import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao; +import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Created by ayalaben on 3/27/2017. + */ +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 = + VlmZusammenUtil.buildStructuralElement(StructureElement.FeatureGroups, null); + + featureGroupsElement.addSubElement(featureGroupElement); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(featureGroup.getVendorLicenseModelId()); + Optional savedElement = zusammenAdaptor.saveElement(context, new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), + featureGroupsElement, "Create feature group"); + + savedElement.ifPresent(element -> featureGroup + .setId(element.getSubElements().iterator().next().getElementId().getValue())); + } + + @Override + public void update(FeatureGroupEntity featureGroup) { + ZusammenElement featureGroupElement = buildFeatureGroupElement(featureGroup, Action.UPDATE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(featureGroup.getVendorLicenseModelId()); + zusammenAdaptor.saveElement(context, new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), featureGroupElement, + String.format("Update feature group with id %s", featureGroup.getId())); + } + + @Override + public FeatureGroupEntity get(FeatureGroupEntity featureGroup) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(featureGroup.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VlmZusammenUtil.getVersionTag(featureGroup.getVersion())); + + return zusammenAdaptor.getElementInfo(context, elementContext, new Id(featureGroup.getId())) + .map(elementInfo -> mapElementInfoToFeatureGroup( + featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(), elementInfo)) + .orElse(null); + } + + @Override + public void delete(FeatureGroupEntity featureGroup) { + SessionContext context = ZusammenUtil.createSessionContext(); + ZusammenElement zusammenElement = new ZusammenElement(); + zusammenElement.setAction(Action.DELETE); + zusammenElement.setElementId(new Id(featureGroup.getId())); + + Id itemId = new Id(featureGroup.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, + "delete feature group. id:" + featureGroup.getId() + "."); + } + + @Override + public Collection list(FeatureGroupEntity featureGroup) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(featureGroup.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VlmZusammenUtil.getVersionTag(featureGroup.getVersion())); + + return zusammenAdaptor + .listElementsByName(context, elementContext, null, StructureElement.FeatureGroups.name()) + .stream().map(elementInfo -> mapElementInfoToFeatureGroup( + featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(), elementInfo)) + .collect(Collectors.toList()); + } + + @Override + public long count(FeatureGroupEntity featureGroup) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(featureGroup.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VlmZusammenUtil.getVersionTag(featureGroup.getVersion())); + + return zusammenAdaptor + .listElementsByName(context, elementContext, null, StructureElement.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 = ZusammenUtil.createSessionContext(); + Id itemId = new Id(featureGroup.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + Optional 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)); + } + } + + @Override + public void updateFeatureGroup(FeatureGroupEntity + featureGroup, Set addedEntitlementPools, + Set removedEntitlementPools, + Set addedLicenseKeyGroups, + Set removedLicenseKeyGroups) { + ZusammenElement featureGroupElement = buildFeatureGroupElement(featureGroup, Action.UPDATE); + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(featureGroup.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + Optional elementInfo = zusammenAdaptor.getElementInfo(context, + elementContext, new Id(featureGroup.getId())); + if (elementInfo.isPresent()) { + FeatureGroupEntity currentFeatureGroup = + mapElementInfoToFeatureGroup(featureGroup.getId(), featureGroup.getVersion(), + elementInfo.get()); + + currentFeatureGroup.getEntitlementPoolIds().removeAll(removedEntitlementPools); + 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())); + + currentFeatureGroup.getLicenseKeyGroupIds().removeAll(removedLicenseKeyGroups); + currentFeatureGroup.getLicenseKeyGroupIds().addAll(addedLicenseKeyGroups); + featureGroupElement.getRelations() + .addAll(currentFeatureGroup.getLicenseKeyGroupIds().stream() + .map(relation -> VlmZusammenUtil + .createRelation(RelationType.FeatureGroupToLicenseKeyGroup, relation)) + .collect(Collectors.toList())); + + zusammenAdaptor + .saveElement(context, elementContext, featureGroupElement, "update feature group"); + } + } + + @Override + public void deleteAll(FeatureGroupEntity featureGroup) { + //not supported + } + + + @Override + public void addReferencingLicenseAgreement(FeatureGroupEntity featureGroup, + String licenseAgreementId) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(featureGroup.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + Optional 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 void removeReferencingLicenseAgreement(FeatureGroupEntity featureGroup, + String licenseAgreementId) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(featureGroup.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + Optional 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"); + } + } + + private ZusammenElement buildFeatureGroupElement(FeatureGroupEntity featureGroup, Action action) { + ZusammenElement featureGroupElement = new ZusammenElement(); + featureGroupElement.setAction(action); + if (featureGroup.getId() != null) { + featureGroupElement.setElementId(new Id(featureGroup.getId())); + } + Info info = new Info(); + info.setName(featureGroup.getName()); + info.setDescription(featureGroup.getDescription()); + info.addProperty("partNumber", featureGroup.getPartNumber()); + featureGroupElement.setInfo(info); + + featureGroupElement.setRelations(new ArrayList<>()); + + if (featureGroup.getEntitlementPoolIds() != null && + featureGroup.getEntitlementPoolIds().size() > 0) { + featureGroupElement.getRelations().addAll(featureGroup.getEntitlementPoolIds().stream() + .map(rel -> VlmZusammenUtil + .createRelation(RelationType.FeatureGroupToEntitlmentPool, rel)) + .collect(Collectors.toList())); + } + + if (featureGroup.getLicenseKeyGroupIds() != null && + featureGroup.getLicenseKeyGroupIds().size() > 0) { + featureGroupElement.getRelations() + .addAll(featureGroup.getLicenseKeyGroupIds().stream() + .map(rel -> VlmZusammenUtil + .createRelation(RelationType.FeatureGroupToLicenseKeyGroup, rel)) + .collect(Collectors.toList())); + } + + if (featureGroup.getReferencingLicenseAgreements() != null && + featureGroup.getReferencingLicenseAgreements().size() > 0) { + featureGroupElement.getRelations() + .addAll(featureGroup.getReferencingLicenseAgreements().stream() + .map(rel -> VlmZusammenUtil + .createRelation(RelationType.FeatureGroupToReferencingLicenseAgreement, + rel)) + .collect(Collectors.toList())); + } + return featureGroupElement; + } + + private FeatureGroupEntity mapElementInfoToFeatureGroup(String vlmId, Version version, + ElementInfo elementInfo) { + FeatureGroupEntity featureGroup = + new FeatureGroupEntity(vlmId, version, elementInfo.getId().getValue()); + featureGroup.setName(elementInfo.getInfo().getName()); + featureGroup.setDescription(elementInfo.getInfo().getDescription()); + featureGroup.setPartNumber(elementInfo.getInfo().getProperty("partNumber")); + + Set entitlementPoolIds = new HashSet<>(); + Set licenseAgreements = new HashSet<>(); + Set licenseKeyGroupIds = new HashSet<>(); + + if (elementInfo.getRelations() != null) { + for (Relation relation : elementInfo.getRelations()) { + 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); + + return featureGroup; + } +} 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 new file mode 100644 index 0000000000..55bbae9b33 --- /dev/null +++ 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 @@ -0,0 +1,249 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; + +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; +import com.amdocs.zusammen.datatypes.Id; +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 org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenUtil; +import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao; +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 org.openecomp.sdc.versioning.dao.types.Version; + +import java.util.Collection; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + + +public class LicenseAgreementDaoZusammenImpl implements LicenseAgreementDao { + + private ZusammenAdaptor zusammenAdaptor; + + public LicenseAgreementDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public void registerVersioning(String versionableEntityType) { + //no need + } + + @Override + public void create(LicenseAgreementEntity licenseAgreement) { + ZusammenElement licenseAgreementElement = + buildLicenseAgreementElement(licenseAgreement, Action.CREATE); + ZusammenElement licenseAgreementsElement = + VlmZusammenUtil.buildStructuralElement(StructureElement.LicenseAgreements, null); + licenseAgreementsElement.addSubElement(licenseAgreementElement); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(licenseAgreement.getVendorLicenseModelId()); + Optional savedElement = zusammenAdaptor.saveElement(context, new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), + licenseAgreementsElement, "Create license agreement"); + savedElement.ifPresent(element -> licenseAgreement + .setId(element.getSubElements().iterator().next().getElementId().getValue())); + } + + @Override + public void update(LicenseAgreementEntity licenseAgreement) { + ZusammenElement licenseAgreementElement = + buildLicenseAgreementElement(licenseAgreement, Action.UPDATE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(licenseAgreement.getVendorLicenseModelId()); + zusammenAdaptor.saveElement(context, new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), + licenseAgreementElement, + String.format("Update license agreement with id %s", licenseAgreement.getId())); + } + + @Override + public LicenseAgreementEntity get(LicenseAgreementEntity licenseAgreement) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(licenseAgreement.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VlmZusammenUtil.getVersionTag(licenseAgreement.getVersion())); + + return zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseAgreement.getId())) + .map(elementInfo -> mapElementInfoToLicenseAgreement( + licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion(), elementInfo)) + .orElse(null); + } + + @Override + public void delete(LicenseAgreementEntity licenseAgreement) { + SessionContext context = ZusammenUtil.createSessionContext(); + ZusammenElement zusammenElement = new ZusammenElement(); + zusammenElement.setAction(Action.DELETE); + zusammenElement.setElementId(new Id(licenseAgreement.getId())); + + Id itemId = new Id(licenseAgreement.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, + "delete license agreement. id:" + licenseAgreement.getId() + "."); + } + + + @Override + public Collection list(LicenseAgreementEntity licenseAgreement) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(licenseAgreement.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VlmZusammenUtil.getVersionTag(licenseAgreement.getVersion())); + + return zusammenAdaptor + .listElementsByName(context, elementContext, null, + StructureElement.LicenseAgreements.name()) + .stream().map(elementInfo -> mapElementInfoToLicenseAgreement( + licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion(), elementInfo)) + .collect(Collectors.toList()); + } + + @Override + public long count(LicenseAgreementEntity licenseAgreement) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(licenseAgreement.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VlmZusammenUtil.getVersionTag(licenseAgreement.getVersion())); + + return zusammenAdaptor.listElementsByName(context, elementContext, null, + StructureElement.LicenseAgreements.name()) + .size(); + } + + @Override + public void deleteAll(LicenseAgreementEntity entity) { + //not supported + } + + @Override + public void removeFeatureGroup(LicenseAgreementEntity licenseAgreement, String featureGroupId) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(licenseAgreement.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + Optional 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 void updateColumnsAndDeltaFeatureGroupIds(LicenseAgreementEntity licenseAgreement, + Set addedFeatureGroupIds, + Set removedFeatureGroupIds) { + ZusammenElement licenseAgreementElement = + buildLicenseAgreementElement(licenseAgreement, Action.UPDATE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(licenseAgreement.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + Optional elementInfo = + zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseAgreement.getId())); + if (elementInfo.isPresent()) { + LicenseAgreementEntity currentLicenseAgreement = + mapElementInfoToLicenseAgreement(licenseAgreement.getId(), licenseAgreement.getVersion(), + elementInfo.get()); + + currentLicenseAgreement.getFeatureGroupIds().removeAll(removedFeatureGroupIds); + 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"); + } + } + + private LicenseAgreementEntity mapElementInfoToLicenseAgreement(String vlmId, Version version, + ElementInfo elementInfo) { + LicenseAgreementEntity licenseAgreement = + new LicenseAgreementEntity(vlmId, version, elementInfo.getId().getValue()); + licenseAgreement.setName(elementInfo.getInfo().getName()); + licenseAgreement.setDescription(elementInfo.getInfo().getDescription()); + + licenseAgreement + .setLicenseTerm(getCoiceOrOther(elementInfo.getInfo().getProperty("licenseTerm"))); + licenseAgreement.setRequirementsAndConstrains( + elementInfo.getInfo().getProperty("requirementsAndConstrains")); + if (elementInfo.getRelations() != null && elementInfo.getRelations().size() > 0) { + licenseAgreement.setFeatureGroupIds(elementInfo.getRelations().stream() + .map(relation -> relation.getEdge2().getElementId().getValue()) + .collect(Collectors.toSet())); + } + return licenseAgreement; + } + + private ChoiceOrOther getCoiceOrOther(Map licenseTerm) { + return new ChoiceOrOther(LicenseTerm.valueOf((String) licenseTerm.get("choice")), + (String) licenseTerm.get("other")); + } + + + private ZusammenElement buildLicenseAgreementElement(LicenseAgreementEntity licenseAgreement, + Action action) { + ZusammenElement licenseAgreementElement = new ZusammenElement(); + licenseAgreementElement.setAction(action); + if (licenseAgreement.getId() != null) { + licenseAgreementElement.setElementId(new Id(licenseAgreement.getId())); + } + Info info = new Info(); + info.setName(licenseAgreement.getName()); + info.setDescription(licenseAgreement.getDescription()); + info.addProperty("licenseTerm", licenseAgreement.getLicenseTerm()); + info.addProperty("requirementsAndConstrains", licenseAgreement.getRequirementsAndConstrains()); + licenseAgreementElement.setInfo(info); + + if (licenseAgreement.getFeatureGroupIds() != null && + licenseAgreement.getFeatureGroupIds().size() > 0) { + licenseAgreementElement.setRelations(licenseAgreement.getFeatureGroupIds().stream() + .map(rel -> VlmZusammenUtil + .createRelation(RelationType.LicenseAgreementToFeatureGroup, rel)) + .collect(Collectors.toList())); + } + 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 new file mode 100644 index 0000000000..bf1899cb04 --- /dev/null +++ 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 @@ -0,0 +1,243 @@ +package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; + +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; +import com.amdocs.zusammen.datatypes.Id; +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 org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenUtil; +import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao; +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.versioning.dao.types.Version; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Created by ayalaben on 3/30/2017. + */ +public class LicenseKeyGroupZusammenDaoImpl implements LicenseKeyGroupDao { + private ZusammenAdaptor zusammenAdaptor; + + public LicenseKeyGroupZusammenDaoImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public void registerVersioning(String versionableEntityType) { + //no need + } + + @Override + public void create(LicenseKeyGroupEntity licenseKeyGroup) { + ZusammenElement licenseKeyGroupElement = + buildLicenseKeyGroupElement(licenseKeyGroup, Action.CREATE); + + ZusammenElement lkgsElement = + VlmZusammenUtil.buildStructuralElement(StructureElement.LicenseKeyGroups, null); + lkgsElement.addSubElement(licenseKeyGroupElement); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(licenseKeyGroup.getVendorLicenseModelId()); + Optional savedElement = zusammenAdaptor.saveElement(context, new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), + lkgsElement, "Create license Key Group"); + + savedElement.ifPresent(element -> licenseKeyGroup + .setId(element.getSubElements().iterator().next().getElementId().getValue())); + } + + @Override + public void update(LicenseKeyGroupEntity licenseKeyGroup) { + ZusammenElement locenseKeyGroupElement = + buildLicenseKeyGroupElement(licenseKeyGroup, Action.UPDATE); + + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(licenseKeyGroup.getVendorLicenseModelId()); + zusammenAdaptor.saveElement(context, new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), + locenseKeyGroupElement, + String.format("Update license key group with id %s", licenseKeyGroup.getId())); + } + + @Override + public LicenseKeyGroupEntity get(LicenseKeyGroupEntity licenseKeyGroup) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(licenseKeyGroup.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VlmZusammenUtil.getVersionTag(licenseKeyGroup.getVersion())); + + return zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseKeyGroup.getId())) + .map(elementInfo -> mapElementInfoToLicenseKeyGroup( + licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion(), elementInfo)) + .orElse(null); + } + + @Override + public void delete(LicenseKeyGroupEntity licenseKeyGroup) { + SessionContext context = ZusammenUtil.createSessionContext(); + ZusammenElement zusammenElement = new ZusammenElement(); + zusammenElement.setAction(Action.DELETE); + zusammenElement.setElementId(new Id(licenseKeyGroup.getId())); + + Id itemId = new Id(licenseKeyGroup.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + zusammenAdaptor.saveElement(context, elementContext, zusammenElement, + "delete license key group. id:" + licenseKeyGroup.getId() + "."); + } + + @Override + public Collection list(LicenseKeyGroupEntity licenseKeyGroup) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(licenseKeyGroup.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VlmZusammenUtil.getVersionTag(licenseKeyGroup.getVersion())); + + return zusammenAdaptor + .listElementsByName(context, elementContext, null, StructureElement.LicenseKeyGroups.name()) + .stream().map(elementInfo -> mapElementInfoToLicenseKeyGroup( + licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion(), elementInfo)) + .collect(Collectors.toList()); + } + + @Override + public long count(LicenseKeyGroupEntity licenseKeyGroup) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(licenseKeyGroup.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), + VlmZusammenUtil.getVersionTag(licenseKeyGroup.getVersion())); + + return zusammenAdaptor + .listElementsByName(context, elementContext, null, StructureElement.LicenseKeyGroups.name()) + .size(); + } + + @Override + public void deleteAll(LicenseKeyGroupEntity licenseKeyGroup) { + //not supported + } + + @Override + public void removeReferencingFeatureGroup(LicenseKeyGroupEntity licenseKeyGroup, + String featureGroupId) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(licenseKeyGroup.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + Optional 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"); + } + } + + @Override + public void addReferencingFeatureGroup(LicenseKeyGroupEntity licenseKeyGroup, + String featureGroupId) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(licenseKeyGroup.getVendorLicenseModelId()); + ElementContext elementContext = new ElementContext(itemId, + VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + + Optional 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 = new ZusammenElement(); + lkgElement.setAction(action); + if (licenseKeyGroup.getId() != null) { + lkgElement.setElementId(new Id(licenseKeyGroup.getId())); + } + Info info = new Info(); + info.setName(licenseKeyGroup.getName()); + info.setDescription(licenseKeyGroup.getDescription()); + info.addProperty("LicenseKeyType", licenseKeyGroup.getType()); + info.addProperty("operational_scope", licenseKeyGroup.getOperationalScope()); + lkgElement.setInfo(info); + + if (licenseKeyGroup.getReferencingFeatureGroups() != null && + licenseKeyGroup.getReferencingFeatureGroups().size() > 0) { + lkgElement.setRelations(licenseKeyGroup.getReferencingFeatureGroups().stream() + .map(rel -> VlmZusammenUtil + .createRelation(RelationType.LicenseKeyGroupToReferencingFeatureGroup, rel)) + .collect(Collectors.toList())); + } + return lkgElement; + } + + private LicenseKeyGroupEntity mapElementInfoToLicenseKeyGroup(String vlmId, Version version, + ElementInfo elementInfo) { + LicenseKeyGroupEntity licenseKeyGroup = + new LicenseKeyGroupEntity(vlmId, version, elementInfo.getId().getValue()); + licenseKeyGroup.setName(elementInfo.getInfo().getName()); + licenseKeyGroup.setDescription(elementInfo.getInfo().getDescription()); + + licenseKeyGroup + .setType(LicenseKeyType.valueOf(elementInfo.getInfo().getProperty("LicenseKeyType"))); + licenseKeyGroup.setOperationalScope(getOperationalScopeMultiChoiceOrOther( + elementInfo.getInfo().getProperty("operational_scope"))); + + if (elementInfo.getRelations() != null && elementInfo.getRelations().size() > 0) { + licenseKeyGroup + .setReferencingFeatureGroups(elementInfo.getRelations().stream().map(relation -> relation + .getEdge2().getElementId().getValue()).collect(Collectors.toSet())); + } + return licenseKeyGroup; + } + + private MultiChoiceOrOther getOperationalScopeMultiChoiceOrOther + (Map + operationalScope) { + + Set choices = new HashSet<>(); + ((List) operationalScope.get("choices")). + forEach(choice -> choices.add(OperationalScope.valueOf(choice))); + + return new MultiChoiceOrOther<>(choices, (String) operationalScope.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/RelationType.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/RelationType.java new file mode 100644 index 0000000000..5ce0433f50 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/RelationType.java @@ -0,0 +1,10 @@ +package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; + +public enum RelationType { + LicenseAgreementToFeatureGroup, + FeatureGroupToEntitlmentPool, + FeatureGroupToLicenseKeyGroup, + FeatureGroupToReferencingLicenseAgreement, + EntitlmentPoolToReferencingFeatureGroup, + LicenseKeyGroupToReferencingFeatureGroup +} 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/StructureElement.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/StructureElement.java new file mode 100644 index 0000000000..767fa52d44 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/StructureElement.java @@ -0,0 +1,9 @@ +package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; + +public enum StructureElement { + General, + LicenseAgreements, + FeatureGroups, + EntitlementPools, + LicenseKeyGroups +} 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 new file mode 100644 index 0000000000..cd1ef0fbcf --- /dev/null +++ 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 @@ -0,0 +1,138 @@ +package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; +import com.amdocs.zusammen.datatypes.Id; +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 com.amdocs.zusammen.datatypes.item.ItemVersion; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenUtil; +import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao; +import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity; +import org.openecomp.sdc.versioning.VersioningManagerFactory; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; +import org.openecomp.sdc.versioning.types.VersionableEntityStoreType; + +import java.util.Collection; +import java.util.Date; +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, "vlm", null, null); + + VersioningManagerFactory.getInstance().createInterface() + .register(versionableEntityType, metadata); + } + + @Override + public Collection list(VendorLicenseModelEntity entity) { + return zusammenAdaptor.listItems(ZusammenUtil.createSessionContext()).stream() + .map(item -> mapInfoToVlm( + item.getId().getValue(), null, item.getInfo(), + item.getModificationTime(), item.getCreationTime())) + .collect(Collectors.toList()); + } + + @Override + public void create(VendorLicenseModelEntity vendorLicenseModel) { + SessionContext context = ZusammenUtil.createSessionContext(); + + Id itemId = zusammenAdaptor.createItem(context, mapVlmToZusammenItemInfo(vendorLicenseModel)); + Id versionId = + zusammenAdaptor.createVersion(context, itemId, null, ZusammenUtil.createFirstVersionData()); + + ZusammenElement generalElement = mapVlmToZusammenElement(vendorLicenseModel, Action.CREATE); + zusammenAdaptor.saveElement(context, new ElementContext(itemId, versionId), + generalElement, "Create VSP General Info Element"); + + vendorLicenseModel.setId(itemId.getValue());//set id for caller + } + + @Override + public void update(VendorLicenseModelEntity vendorLicenseModel) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vendorLicenseModel.getId()); + Id versionId = VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor); + + zusammenAdaptor.updateItem(context, itemId, mapVlmToZusammenItemInfo(vendorLicenseModel)); + + ZusammenElement generalElement = mapVlmToZusammenElement(vendorLicenseModel, Action.UPDATE); + zusammenAdaptor.saveElement(context, new ElementContext(itemId, versionId), + generalElement, "Update VSP General Info Element"); + } + + @Override + public VendorLicenseModelEntity get(VendorLicenseModelEntity vendorLicenseModel) { + SessionContext context = ZusammenUtil.createSessionContext(); + Id itemId = new Id(vendorLicenseModel.getId()); + ItemVersion itemVersion = VlmZusammenUtil.getFirstVersion(context, itemId, zusammenAdaptor); + ElementContext elementContext = new ElementContext(itemId, itemVersion.getId(), + VlmZusammenUtil.getVersionTag(vendorLicenseModel.getVersion())); + + return zusammenAdaptor + .getElementInfoByName(context, elementContext, null, StructureElement.General.name()) + .map(generalElementInfo -> mapInfoToVlm( + vendorLicenseModel.getId(), vendorLicenseModel.getVersion(), + generalElementInfo.getInfo(), + itemVersion.getModificationTime(), itemVersion.getCreationTime())) + .orElse(null); + } + + @Override + public void delete(VendorLicenseModelEntity entity) { + + } + + private Info mapVlmToZusammenItemInfo(VendorLicenseModelEntity vendorLicenseModel) { + Info info = new Info(); + info.setName(vendorLicenseModel.getVendorName()); + info.setDescription(vendorLicenseModel.getDescription()); + info.addProperty("type", "vlm"); + addVlmToInfo(info, vendorLicenseModel); + return info; + } + + private ZusammenElement mapVlmToZusammenElement(VendorLicenseModelEntity vendorLicenseModel, + Action action) { + ZusammenElement generalElement = + VlmZusammenUtil.buildStructuralElement(StructureElement.General, 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()); + } + + private VendorLicenseModelEntity mapInfoToVlm(String vlmId, Version version, Info info, + Date modificationTime, Date creationTime) { + VendorLicenseModelEntity vendorLicenseModel = new VendorLicenseModelEntity(vlmId, version); + vendorLicenseModel.setVendorName(info.getProperty(InfoPropertyName.name.name())); + vendorLicenseModel.setDescription(info.getProperty(InfoPropertyName.description.name())); + vendorLicenseModel.setIconRef(info.getProperty(InfoPropertyName.iconRef.name())); + vendorLicenseModel.setWritetimeMicroSeconds( + modificationTime == null ? creationTime.getTime() : modificationTime.getTime()); + return vendorLicenseModel; + } + + private 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 new file mode 100644 index 0000000000..b2802bee66 --- /dev/null +++ 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 @@ -0,0 +1,68 @@ +package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.item.Action; +import com.amdocs.zusammen.datatypes.item.ItemVersion; +import com.amdocs.zusammen.datatypes.item.Relation; +import com.amdocs.zusammen.datatypes.item.RelationEdge; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.core.zusammen.api.ZusammenUtil; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.vendorlicense.errors.VendorLicenseModelNotFoundErrorBuilder; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.dao.types.VersionStatus; + +import java.util.Optional; +import java.util.stream.Collectors; + +public class VlmZusammenUtil { + + static ItemVersion getFirstVersion(SessionContext context, Id itemId, + ZusammenAdaptor zusammenAdaptor) { + Optional itemVersion = zusammenAdaptor.getFirstVersion(context, itemId); + + if (!itemVersion.isPresent()) { + throw new CoreException( + new VendorLicenseModelNotFoundErrorBuilder(itemId.getValue()).build()); + } + return itemVersion.get(); + } + + static Id getFirstVersionId(SessionContext context, Id itemId, ZusammenAdaptor zusammenAdaptor) { + return getFirstVersion(context, itemId, zusammenAdaptor).getId(); + } + + // TODO: 4/25/2017 remove upon working with more than one single version + static String getVersionTag(Version version) { + return version.getStatus() == VersionStatus.Locked + ? null + : version.toString(); + } + + static ZusammenElement buildStructuralElement(StructureElement structureElement, Action action) { + return ZusammenUtil.buildStructuralElement(structureElement.name(), action); + } + + 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; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/facade/impl/VendorLicenseFacadeImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/facade/impl/VendorLicenseFacadeImpl.java index 678a53583c..6f3573981c 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/facade/impl/VendorLicenseFacadeImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/facade/impl/VendorLicenseFacadeImpl.java @@ -24,6 +24,13 @@ import org.openecomp.core.util.UniqueValueUtil; import org.openecomp.core.utilities.CommonMethods; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCode; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage; +import org.openecomp.sdc.logging.types.LoggerConstants; +import org.openecomp.sdc.logging.types.LoggerErrorCode; +import org.openecomp.sdc.logging.types.LoggerErrorDescription; +import org.openecomp.sdc.logging.types.LoggerTragetServiceName; import org.openecomp.sdc.vendorlicense.VendorLicenseConstants; import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao; import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDaoFactory; @@ -60,64 +67,61 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import static org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE; +import static org.openecomp.sdc.vendorlicense.errors.UncompletedVendorLicenseModelErrorType.SUBMIT_UNCOMPLETED_VLM_MSG_FG_MISSING_EP; +import static org.openecomp.sdc.vendorlicense.errors.UncompletedVendorLicenseModelErrorType.SUBMIT_UNCOMPLETED_VLM_MSG_LA_MISSING_FG; +import static org.openecomp.sdc.vendorlicense.errors.UncompletedVendorLicenseModelErrorType.SUBMIT_UNCOMPLETED_VLM_MSG_MISSING_LA; -public class VendorLicenseFacadeImpl - implements VendorLicenseFacade { - +public class VendorLicenseFacadeImpl implements VendorLicenseFacade { private static final VersioningManager versioningManager = VersioningManagerFactory.getInstance().createInterface(); - private static final VendorLicenseModelDao vendorLicenseModelDao = - VendorLicenseModelDaoFactory.getInstance().createInterface(); - private static final LicenseAgreementDao licenseAgreementDao = - LicenseAgreementDaoFactory.getInstance().createInterface(); + private static final VendorLicenseModelDao + vendorLicenseModelDao = VendorLicenseModelDaoFactory.getInstance().createInterface(); + private static final LicenseAgreementDao + licenseAgreementDao = LicenseAgreementDaoFactory.getInstance().createInterface(); private static final FeatureGroupDao featureGroupDao = FeatureGroupDaoFactory.getInstance().createInterface(); - private static final EntitlementPoolDao entitlementPoolDao = - EntitlementPoolDaoFactory.getInstance().createInterface(); - private static final LicenseKeyGroupDao licenseKeyGroupDao = - LicenseKeyGroupDaoFactory.getInstance().createInterface(); + private static final EntitlementPoolDao + entitlementPoolDao = EntitlementPoolDaoFactory.getInstance().createInterface(); + private static final LicenseKeyGroupDao + licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface(); + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); /** * Instantiates a new Vendor license facade. */ public VendorLicenseFacadeImpl() { - vendorLicenseModelDao - .registerVersioning(VendorLicenseConstants.VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); - licenseAgreementDao - .registerVersioning(VendorLicenseConstants.VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); - featureGroupDao - .registerVersioning(VendorLicenseConstants.VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); - entitlementPoolDao - .registerVersioning(VendorLicenseConstants.VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); - licenseKeyGroupDao - .registerVersioning(VendorLicenseConstants.VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); + vendorLicenseModelDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); + licenseAgreementDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); + featureGroupDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); + entitlementPoolDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); + licenseKeyGroupDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE); } @Override - public void checkin(String vendorLicenseModelId, String user) { + public Version checkin(String vendorLicenseModelId, String user) { Version newVersion = versioningManager - .checkin(VendorLicenseConstants - .VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, - vendorLicenseModelId, user, null); + .checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user, null); updateVlmLastModificationTime(vendorLicenseModelId, newVersion); + return newVersion; } @Override - public void submit(String vendorLicenseModelId, String user) { + public Version submit(String vendorLicenseModelId, String user) { validateCompletedVendorLicenseModel(vendorLicenseModelId, user); Version newVersion = versioningManager - .submit(VendorLicenseConstants - .VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, - vendorLicenseModelId, user, null); + .submit(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user, null); updateVlmLastModificationTime(vendorLicenseModelId, newVersion); + return newVersion; } @Override public FeatureGroupEntity getFeatureGroup(FeatureGroupEntity featureGroup, String user) { Version version = VersioningUtil.resolveVersion(featureGroup.getVersion(), - getVersionInfo(featureGroup.getVendorLicenseModelId(), VersionableEntityAction.Read, user)); + getVersionInfo(featureGroup.getVendorLicenseModelId(), VersionableEntityAction.Read, + user), user); featureGroup.setVersion(version); return getFeatureGroup(featureGroup); } @@ -150,21 +154,6 @@ public class VendorLicenseFacadeImpl return featureGroupModel; } - @Override - public LicenseAgreementEntity getLicenseAgreement(String vlmId, Version version, - String licenseAgreementId, String user) { - return getLicenseAgreement(vlmId, licenseAgreementId, VersioningUtil - .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user))); - } - - private LicenseAgreementEntity getLicenseAgreement(String vlmId, String licenseAgreementId, - Version version) { - LicenseAgreementEntity input = new LicenseAgreementEntity(vlmId, version, licenseAgreementId); - LicenseAgreementEntity retrieved = licenseAgreementDao.get(input); - VersioningUtil.validateEntityExistence(retrieved, input, VendorLicenseModelEntity.ENTITY_TYPE); - return retrieved; - } - @Override public LicenseAgreementModel getLicenseAgreementModel(String vlmId, Version version, String licenseAgreementId, String user) { @@ -185,10 +174,10 @@ public class VendorLicenseFacadeImpl @Override public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool, String user) { - entitlementPool.setVersion( + entitlementPool.setVersion(VersioningUtil.resolveVersion(entitlementPool.getVersion(), getVersionInfo(entitlementPool.getVendorLicenseModelId(), VersionableEntityAction.Write, - user).getActiveVersion()); - entitlementPool.setId(CommonMethods.nextUuId()); + user), user)); + //entitlementPool.setId(CommonMethods.nextUuId()); entitlementPool.setVersionUuId(CommonMethods.nextUuId()); UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME, entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().toString(), @@ -199,28 +188,11 @@ public class VendorLicenseFacadeImpl return entitlementPool; } - @Override - public LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, - String user) { - licenseKeyGroup.setVersion( - getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Write, - user).getActiveVersion()); - licenseKeyGroup.setId(CommonMethods.nextUuId()); - licenseKeyGroup.setVersionUuId(CommonMethods.nextUuId()); - UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME, - licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().toString(), - licenseKeyGroup.getName()); - licenseKeyGroupDao.create(licenseKeyGroup); - updateVlmLastModificationTime(licenseKeyGroup.getVendorLicenseModelId(), - licenseKeyGroup.getVersion()); - return licenseKeyGroup; - } - @Override public void updateEntitlementPool(EntitlementPoolEntity entitlementPool, String user) { - entitlementPool.setVersion( + entitlementPool.setVersion(VersioningUtil.resolveVersion(entitlementPool.getVersion(), getVersionInfo(entitlementPool.getVendorLicenseModelId(), VersionableEntityAction.Write, - user).getActiveVersion()); + user), user)); EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool); VersioningUtil .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE); @@ -240,21 +212,23 @@ public class VendorLicenseFacadeImpl public Collection listLicenseKeyGroups(String vlmId, Version version, String user) { return licenseKeyGroupDao.list(new LicenseKeyGroupEntity(vlmId, VersioningUtil - .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user)), null)); + .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user), + null)); } @Override public Collection listEntitlementPools(String vlmId, Version version, String user) { return entitlementPoolDao.list(new EntitlementPoolEntity(vlmId, VersioningUtil - .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user)), null)); + .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user), + null)); } @Override public void updateLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, String user) { - licenseKeyGroup.setVersion( + licenseKeyGroup.setVersion(VersioningUtil.resolveVersion(licenseKeyGroup.getVersion(), getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Write, - user).getActiveVersion()); + user), user)); LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup); licenseKeyGroup.setVersionUuId((CommonMethods.nextUuId())); VersioningUtil @@ -268,81 +242,93 @@ public class VendorLicenseFacadeImpl licenseKeyGroup.getVersion()); } - @Override - public VersionInfo getVersionInfo(String vendorLicenseModelId, VersionableEntityAction action, - String user) { - return versioningManager - .getEntityVersionInfo(VendorLicenseConstants - .VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, - vendorLicenseModelId, user, - action); + public LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, + String user) { + licenseKeyGroup.setVersion(VersioningUtil.resolveVersion(licenseKeyGroup.getVersion(), + getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Write, + user), user)); + //licenseKeyGroup.setId(CommonMethods.nextUuId()); + licenseKeyGroup.setVersionUuId(CommonMethods.nextUuId()); + UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME, + licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().toString(), + licenseKeyGroup.getName()); + licenseKeyGroupDao.create(licenseKeyGroup); + updateVlmLastModificationTime(licenseKeyGroup.getVendorLicenseModelId(), + licenseKeyGroup.getVersion()); + return licenseKeyGroup; } @Override public VersionedVendorLicenseModel getVendorLicenseModel(String vlmId, Version version, String user) { + mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId); + VersionInfo versionInfo = getVersionInfo(vlmId, VersionableEntityAction.Read, user); VendorLicenseModelEntity vendorLicenseModel = vendorLicenseModelDao.get( - new VendorLicenseModelEntity(vlmId, VersioningUtil.resolveVersion(version, versionInfo))); + new VendorLicenseModelEntity(vlmId, + VersioningUtil.resolveVersion(version, versionInfo, user))); if (vendorLicenseModel == null) { + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, + LoggerTragetServiceName.GET_VLM, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.ENTITY_NOT_FOUND); throw new CoreException(new VendorLicenseModelNotFoundErrorBuilder(vlmId).build()); } + mdcDataDebugMessage.debugExitMessage("VLM id", vlmId); return new VersionedVendorLicenseModel(vendorLicenseModel, versionInfo); } @Override public VendorLicenseModelEntity createVendorLicenseModel( VendorLicenseModelEntity vendorLicenseModelEntity, String user) { - UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, - vendorLicenseModelEntity.getVendorName()); - vendorLicenseModelEntity.setId(CommonMethods.nextUuId()); - Version version = versioningManager - .create(VendorLicenseConstants - .VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, - vendorLicenseModelEntity.getId(), user); - vendorLicenseModelEntity.setVersion(version); + mdcDataDebugMessage.debugEntryMessage(null, null); - // vendorLicenseModelEntity.setLastModificationTime(new Date()); + UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, + vendorLicenseModelEntity.getVendorName()); + //vendorLicenseModelEntity.setId(CommonMethods.nextUuId()); vendorLicenseModelDao.create(vendorLicenseModelEntity); UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, vendorLicenseModelEntity.getVendorName()); + Version version = versioningManager + .create(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelEntity.getId(), user); + vendorLicenseModelEntity.setVersion(version); + + mdcDataDebugMessage.debugExitMessage(null, null); return vendorLicenseModelEntity; } @Override public LicenseAgreementEntity createLicenseAgreement(LicenseAgreementEntity licenseAgreement, String user) { - Version activeVersion = + Version version = VersioningUtil.resolveVersion(licenseAgreement.getVersion(), getVersionInfo(licenseAgreement.getVendorLicenseModelId(), VersionableEntityAction.Write, - user).getActiveVersion(); - licenseAgreement.setVersion(activeVersion); - licenseAgreement.setId(CommonMethods.nextUuId()); + user), user); + licenseAgreement.setVersion(version); + //licenseAgreement.setId(CommonMethods.nextUuId()); VersioningUtil.validateEntitiesExistence(licenseAgreement.getFeatureGroupIds(), - new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), activeVersion, null), + new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), version, null), featureGroupDao, VendorLicenseModelEntity.ENTITY_TYPE); + UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME, licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().toString(), licenseAgreement.getName()); + licenseAgreementDao.create(licenseAgreement); + UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME, + licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().toString(), + licenseAgreement.getName()); if (licenseAgreement.getFeatureGroupIds() != null) { for (String addedFgId : licenseAgreement.getFeatureGroupIds()) { featureGroupDao.addReferencingLicenseAgreement( - new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), activeVersion, + new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), version, addedFgId), licenseAgreement.getId()); } } - - licenseAgreementDao.create(licenseAgreement); - UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME, - licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().toString(), - licenseAgreement.getName()); - updateVlmLastModificationTime(licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion()); @@ -351,49 +337,48 @@ public class VendorLicenseFacadeImpl @Override public FeatureGroupEntity createFeatureGroup(FeatureGroupEntity featureGroup, String user) { - Version activeVersion = - getVersionInfo(featureGroup.getVendorLicenseModelId(), VersionableEntityAction.Write, user) - .getActiveVersion(); - featureGroup.setId(CommonMethods.nextUuId()); - featureGroup.setVersion(activeVersion); + Version version = VersioningUtil.resolveVersion(featureGroup.getVersion(), + getVersionInfo(featureGroup.getVendorLicenseModelId(), VersionableEntityAction.Write, + user), user); + //featureGroup.setId(CommonMethods.nextUuId()); + featureGroup.setVersion(version); VersioningUtil.validateEntitiesExistence(featureGroup.getLicenseKeyGroupIds(), - new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), activeVersion, null), + new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), version, null), licenseKeyGroupDao, VendorLicenseModelEntity.ENTITY_TYPE); VersioningUtil.validateEntitiesExistence(featureGroup.getEntitlementPoolIds(), - new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), activeVersion, null), + new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), version, null), entitlementPoolDao, VendorLicenseModelEntity.ENTITY_TYPE); UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME, featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().toString(), featureGroup.getName()); + featureGroupDao.create(featureGroup); + UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME, + featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().toString(), + featureGroup.getName()); + if (featureGroup.getLicenseKeyGroupIds() != null) { for (String addedLkgId : featureGroup.getLicenseKeyGroupIds()) { licenseKeyGroupDao.addReferencingFeatureGroup( - new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), activeVersion, - addedLkgId), featureGroup.getId()); + new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), version, addedLkgId), + featureGroup.getId()); } } if (featureGroup.getEntitlementPoolIds() != null) { for (String addedEpId : featureGroup.getEntitlementPoolIds()) { entitlementPoolDao.addReferencingFeatureGroup( - new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), activeVersion, - addedEpId), featureGroup.getId()); + new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), version, addedEpId), + featureGroup.getId()); } } - featureGroupDao.create(featureGroup); - UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME, - featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().toString(), - featureGroup.getName()); - updateVlmLastModificationTime(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion()); return featureGroup; } - @Override public Collection validateLicensingData(String vlmId, Version version, String licenseAgreementId, @@ -404,16 +389,16 @@ public class VendorLicenseFacadeImpl || !versionInfo.getViewableVersions().contains(version)) { return Collections.singletonList(new RequestedVersionInvalidErrorBuilder().build()); } - } catch (CoreException coreException) { - return Collections.singletonList(coreException.code()); + } catch (CoreException exception) { + return Collections.singletonList(exception.code()); } List errorMessages = new ArrayList<>(); try { getLicenseAgreement(vlmId, licenseAgreementId, version); - } catch (CoreException coreException) { - errorMessages.add(coreException.code()); + } catch (CoreException exception) { + errorMessages.add(exception.code()); } for (String featureGroupId : featureGroupIds) { @@ -428,51 +413,79 @@ public class VendorLicenseFacadeImpl licenseAgreementId, version).build()); } - } catch (CoreException coreException) { - errorMessages.add(coreException.code()); + } catch (CoreException exception) { + errorMessages.add(exception.code()); } } return errorMessages; } + @Override + public VersionInfo getVersionInfo(String vendorLicenseModelId, VersionableEntityAction action, + String user) { + return versioningManager + .getEntityVersionInfo(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user, + action); + } + @Override public void updateVlmLastModificationTime(String vendorLicenseModelId, Version version) { VendorLicenseModelEntity retrieved = vendorLicenseModelDao.get(new VendorLicenseModelEntity(vendorLicenseModelId, version)); vendorLicenseModelDao.update(retrieved); - // entity.setLastModificationTime(new Date()); - // - // vendorLicenseModelDao.updateLastModificationTime(entity); + } + + @Override + public LicenseAgreementEntity getLicenseAgreement(String vlmId, Version version, + String licenseAgreementId, String user) { + return getLicenseAgreement(vlmId, licenseAgreementId, VersioningUtil + .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user)); + } + + private LicenseAgreementEntity getLicenseAgreement(String vlmId, String licenseAgreementId, + Version version) { + LicenseAgreementEntity input = new LicenseAgreementEntity(vlmId, version, licenseAgreementId); + LicenseAgreementEntity retrieved = licenseAgreementDao.get(input); + VersioningUtil.validateEntityExistence(retrieved, input, VendorLicenseModelEntity.ENTITY_TYPE); + return retrieved; } private void validateCompletedVendorLicenseModel(String vendorLicenseModelId, String user) { - Version activeVersion = - getVersionInfo(vendorLicenseModelId, VersionableEntityAction.Read, user).getActiveVersion(); + Version version = VersioningUtil.resolveVersion(null, + getVersionInfo(vendorLicenseModelId, VersionableEntityAction.Read, user), user); Collection licenseAgreements = licenseAgreementDao - .list(new LicenseAgreementEntity(vendorLicenseModelId, activeVersion, null)); + .list(new LicenseAgreementEntity(vendorLicenseModelId, version, null)); if (licenseAgreements == null || licenseAgreements.isEmpty()) { + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, + LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.SUBMIT_ENTITY); throw new CoreException( - new SubmitUncompletedLicenseModelErrorBuilder(vendorLicenseModelId).build()); + new SubmitUncompletedLicenseModelErrorBuilder(SUBMIT_UNCOMPLETED_VLM_MSG_MISSING_LA).build()); } for (LicenseAgreementEntity licenseAgreement : licenseAgreements) { - if (licenseAgreement.getFeatureGroupIds() == null - || licenseAgreement.getFeatureGroupIds().isEmpty()) { + if (licenseAgreement.getFeatureGroupIds() == null || licenseAgreement.getFeatureGroupIds().isEmpty()) { + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, + LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.SUBMIT_ENTITY); throw new CoreException( - new SubmitUncompletedLicenseModelErrorBuilder(vendorLicenseModelId).build()); + new SubmitUncompletedLicenseModelErrorBuilder(SUBMIT_UNCOMPLETED_VLM_MSG_LA_MISSING_FG).build()); } } - Collection featureGroupEntities = featureGroupDao - .list(new FeatureGroupEntity(vendorLicenseModelId, activeVersion, null)); + Collection featureGroupEntities = + featureGroupDao.list(new FeatureGroupEntity(vendorLicenseModelId, version, null)); for (FeatureGroupEntity featureGroupEntity : featureGroupEntities) { - if (featureGroupEntity.getEntitlementPoolIds() == null - || featureGroupEntity.getEntitlementPoolIds().isEmpty()) { + if (featureGroupEntity.getEntitlementPoolIds() == null || featureGroupEntity.getEntitlementPoolIds().isEmpty()) { + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, + LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.SUBMIT_ENTITY); throw new CoreException( - new SubmitUncompletedLicenseModelErrorBuilder(vendorLicenseModelId).build()); + new SubmitUncompletedLicenseModelErrorBuilder(SUBMIT_UNCOMPLETED_VLM_MSG_FG_MISSING_EP).build()); } } + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/healing/impl/SimpleHealingServiceImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/healing/impl/SimpleHealingServiceImpl.java index 8f8f34e471..eeed3b069d 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/healing/impl/SimpleHealingServiceImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/healing/impl/SimpleHealingServiceImpl.java @@ -20,6 +20,14 @@ package org.openecomp.sdc.vendorlicense.healing.impl; +import org.openecomp.sdc.common.utils.CommonUtil; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage; +import org.openecomp.sdc.logging.types.LoggerConstants; +import org.openecomp.sdc.logging.types.LoggerErrorCode; +import org.openecomp.sdc.logging.types.LoggerErrorDescription; +import org.openecomp.sdc.logging.types.LoggerTragetServiceName; import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao; import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDaoFactory; import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao; @@ -29,11 +37,14 @@ import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity; import org.openecomp.sdc.vendorlicense.healing.HealingService; import org.openecomp.sdc.versioning.dao.types.VersionableEntity; +import java.util.UUID; + public class SimpleHealingServiceImpl implements HealingService { private static final EntitlementPoolDao entitlementPoolDao = EntitlementPoolDaoFactory.getInstance().createInterface(); private static final LicenseKeyGroupDao licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface(); + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); @Override public VersionableEntity heal(VersionableEntity toHeal, String user) { @@ -41,23 +52,30 @@ public class SimpleHealingServiceImpl implements HealingService { } private VersionableEntity handleMissingVersionId(VersionableEntity toHeal, String user) { - if (toHeal.getVersionUuId() != null) { + + + mdcDataDebugMessage.debugEntryMessage(null, null); + + if (toHeal != null && toHeal.getVersionUuId() != null) { return toHeal; } - if (toHeal instanceof EntitlementPoolEntity) { - toHeal.setVersionUuId(toHeal.getId()); + toHeal.setVersionUuId(UUID.randomUUID().toString()); entitlementPoolDao.update((EntitlementPoolEntity) toHeal); } else if (toHeal instanceof LicenseKeyGroupEntity) { - toHeal.setVersionUuId(toHeal.getId()); + toHeal.setVersionUuId(UUID.randomUUID().toString()); licenseKeyGroupDao.update((LicenseKeyGroupEntity) toHeal); } else { + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, + LoggerTragetServiceName.SELF_HEALING, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.UNSUPPORTED_OPERATION); throw new UnsupportedOperationException( "Unsupported operation for 1610 release/1607->1610 migration."); //todo maybe errorbuilder? } + + mdcDataDebugMessage.debugExitMessage(null, null); return toHeal; } - } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/VendorLicenseArtifactsServiceImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/VendorLicenseArtifactsServiceImpl.java index 2f11b75a98..580fc6c0e5 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/VendorLicenseArtifactsServiceImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/VendorLicenseArtifactsServiceImpl.java @@ -20,11 +20,10 @@ package org.openecomp.sdc.vendorlicense.licenseartifacts.impl; -import org.apache.commons.collections4.MultiValuedMap; -import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.sdc.common.utils.CommonUtil; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; import org.openecomp.sdc.vendorlicense.HealingServiceFactory; -import org.openecomp.sdc.vendorlicense.VendorLicenseConstants; import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel; @@ -35,166 +34,115 @@ import org.openecomp.sdc.vendorlicense.healing.HealingService; import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService; import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.VendorLicenseArtifact; import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.VnfLicenseArtifact; +import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util.VendorLicenseArtifactsServiceUtils; import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdc.versioning.dao.types.VersionableEntity; -import org.openecomp.sdc.versioning.types.VersionInfo; -import org.openecomp.sdc.versioning.types.VersionableEntityAction; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; 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.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH; +import static org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH; + public class VendorLicenseArtifactsServiceImpl implements VendorLicenseArtifactsService { - private static final VendorLicenseFacade vendorLicenseFacade = VendorLicenseFacadeFactory - .getInstance().createInterface(); - private static final HealingService healingService = HealingServiceFactory - .getInstance().createInterface(); + public static final VendorLicenseFacade vendorLicenseFacade = + VendorLicenseFacadeFactory.getInstance().createInterface(); + public static final HealingService healingService = + HealingServiceFactory.getInstance().createInterface(); + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); - /** - * Create License Artifacts. - * - * @param vspId the vsp id - * @param vlmId the vlm id - * @param vlmVersion the vlm version - * @param featureGroups the feature groups - * @param user the user - * @return FileContentHandler - */ - public FileContentHandler createLicenseArtifacts(String vspId, String vlmId, - Version vlmVersion, - List featureGroups, String user) { - FileContentHandler artifacts = new FileContentHandler(); - String vendorName = getVendorName(vlmId, user); - artifacts.addFile(VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH, - createVnfArtifact(vspId, vlmId, vlmVersion, vendorName, featureGroups, user)); - artifacts.addFile(VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH, - createVendorLicenseArtifact(vlmId, vendorName, user)); + static byte[] createVnfArtifact(String vspId, String vlmId, Version vlmVersion, String vendorName, + List featureGroups, String user) { - return artifacts; - } - static byte[] createVnfArtifact( - String vspId, String vlmId, Version vlmVersion, - String vendorName, List featureGroups, - String user) { + mdcDataDebugMessage.debugEntryMessage("VLM name", vendorName); + VnfLicenseArtifact artifact = new VnfLicenseArtifact(); artifact.setVspId(vspId); artifact.setVendorName(vendorName); for (String featureGroupId : featureGroups) { - FeatureGroupModel featureGroupModel = - vendorLicenseFacade.getFeatureGroupModel(new FeatureGroupEntity( - vlmId, vlmVersion, featureGroupId), user); + FeatureGroupModel featureGroupModel = vendorLicenseFacade + .getFeatureGroupModel(new FeatureGroupEntity(vlmId, vlmVersion, featureGroupId), user); Set entitlementPoolEntities = featureGroupModel.getEntitlementPools(); Set licenseKeyGroupEntities = featureGroupModel.getLicenseKeyGroups(); - featureGroupModel.setEntitlementPools( - entitlementPoolEntities.stream() - .map(entitlementPoolEntity -> (EntitlementPoolEntity) healingService - .heal(entitlementPoolEntity, user)) - .collect(Collectors.toSet())); - featureGroupModel.setLicenseKeyGroups( - licenseKeyGroupEntities.stream() - .map(licenseKeyGroupEntity -> (LicenseKeyGroupEntity) healingService - .heal(licenseKeyGroupEntity, user)) - .collect(Collectors.toSet())); + featureGroupModel.setEntitlementPools(entitlementPoolEntities.stream().map( + entitlementPoolEntity -> (EntitlementPoolEntity) healingService + .heal(entitlementPoolEntity, user)).collect(Collectors.toSet())); + featureGroupModel.setLicenseKeyGroups(licenseKeyGroupEntities.stream().map( + licenseKeyGroupEntity -> (LicenseKeyGroupEntity) healingService + .heal(licenseKeyGroupEntity, user)).collect(Collectors.toSet())); artifact.getFeatureGroups().add(featureGroupModel); } + mdcDataDebugMessage.debugExitMessage("VLM name", vendorName); return artifact.toXml().getBytes(); } - static byte[] createVendorLicenseArtifact(String vlmId, String vendorName, String user) { + + + mdcDataDebugMessage.debugEntryMessage("VLM name", vendorName); + VendorLicenseArtifact vendorLicenseArtifact = new VendorLicenseArtifact(); vendorLicenseArtifact.setVendorName(vendorName); Set entitlementPoolEntities = new HashSet<>(); Set licenseKeyGroupEntities = new HashSet<>(); - List finalVersions = getFinalVersionsForVlm(vlmId); + List finalVersions = VendorLicenseArtifactsServiceUtils.getFinalVersionsForVlm(vlmId); for (Version finalVersion : finalVersions) { - entitlementPoolEntities.addAll( - vendorLicenseFacade.listEntitlementPools(vlmId, finalVersion, user)); - licenseKeyGroupEntities.addAll( - vendorLicenseFacade.listLicenseKeyGroups(vlmId, finalVersion, user)); + entitlementPoolEntities + .addAll(vendorLicenseFacade.listEntitlementPools(vlmId, finalVersion, user)); + licenseKeyGroupEntities + .addAll(vendorLicenseFacade.listLicenseKeyGroups(vlmId, finalVersion, user)); } - entitlementPoolEntities = healEPs(user, filterChangedEntities(entitlementPoolEntities)); - licenseKeyGroupEntities = healLkgs(user, filterChangedEntities(licenseKeyGroupEntities)); + entitlementPoolEntities = VendorLicenseArtifactsServiceUtils + .healEPs(user, + VendorLicenseArtifactsServiceUtils.filterChangedEntities(entitlementPoolEntities)); + licenseKeyGroupEntities = VendorLicenseArtifactsServiceUtils + .healLkgs(user, + VendorLicenseArtifactsServiceUtils.filterChangedEntities(licenseKeyGroupEntities)); vendorLicenseArtifact.setEntitlementPoolEntities(entitlementPoolEntities); vendorLicenseArtifact.setLicenseKeyGroupEntities(licenseKeyGroupEntities); - return vendorLicenseArtifact.toXml().getBytes(); - } - - private static List filterChangedEntities( - Collection versionableEntities) { - MultiValuedMap entitiesById = mapById(versionableEntities); - Map entitiesByVersionUuId = new HashMap<>(); - List changedOnly = new ArrayList<>(); - - for (String epId : entitiesById.keySet()) { - Collection versionableEntitiesForId = entitiesById.get(epId); - for (VersionableEntity ep : versionableEntitiesForId) { - entitiesByVersionUuId.put(ep.getVersionUuId(), ep); - } - } - changedOnly.addAll(entitiesByVersionUuId.values()); - - return changedOnly; - } - - private static MultiValuedMap mapById( - Collection versionableEntities) { - MultiValuedMap mappedById = new ArrayListValuedHashMap<>(); - for (VersionableEntity ve : versionableEntities) { - mappedById.put(ve.getId(), ve); - } - return mappedById; + mdcDataDebugMessage.debugExitMessage("VLM name", vendorName); + return vendorLicenseArtifact.toXml().getBytes(); } - private static Set healLkgs( - String user, Collection licenseKeyGroupEntities) { - Set healed = new HashSet<>(); - for (VersionableEntity licenseKeyGroupEntity : licenseKeyGroupEntities) { - healed.add((LicenseKeyGroupEntity) healingService.heal(licenseKeyGroupEntity, user)); - } - - return healed; - } + /** + * Create License Artifacts. + * @param vspId vspId + * @param vlmId vlmId + * @param vlmVersion vlmVersion + * @param featureGroups featureGroups + * @param user user + * @return FileContentHandler + */ + public FileContentHandler createLicenseArtifacts(String vspId, String vlmId, Version vlmVersion, + List featureGroups, String user) { - private static Set healEPs( - String user, Collection entitlementPoolEntities) { - Set healed = new HashSet<>(); - for (VersionableEntity entitlementPoolEntity : entitlementPoolEntities) { - healed.add((EntitlementPoolEntity) healingService.heal(entitlementPoolEntity, user)); - } - return healed; - } + mdcDataDebugMessage.debugEntryMessage("VSP Id", vspId); - private static List getFinalVersionsForVlm(String vlmId) { - VersionInfo versionInfo = vendorLicenseFacade - .getVersionInfo(vlmId, VersionableEntityAction.Read, ""); - return versionInfo.getFinalVersions(); + FileContentHandler artifacts = new FileContentHandler(); + String vendorName = VendorLicenseArtifactsServiceUtils.getVendorName(vlmId, user); - } + artifacts.addFile(VNF_ARTIFACT_NAME_WITH_PATH, + createVnfArtifact(vspId, vlmId, vlmVersion, vendorName, featureGroups, user)); + artifacts.addFile(VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH, + createVendorLicenseArtifact(vlmId, vendorName, user)); + mdcDataDebugMessage.debugExitMessage("VSP Id", vspId); - private static String getVendorName(String vendorLicenseModelId, String user) { - return vendorLicenseFacade - .getVendorLicenseModel(vendorLicenseModelId, null, user) - .getVendorLicenseModel().getVendorName(); + return artifacts; } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/VnfLicenseArtifact.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/VnfLicenseArtifact.java index 1f8607765a..f1da629960 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/VnfLicenseArtifact.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/VnfLicenseArtifact.java @@ -36,11 +36,11 @@ import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins.MixinE import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins.MixinFeatureGroupModel; import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins.MixinLicenseKeyGroupEntityForVnfArtifact; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; import java.io.Writer; import java.util.ArrayList; import java.util.List; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; @JacksonXmlRootElement(localName = "vf-license-model", namespace = "http://xmlns.openecomp.org/asdc/license-model/1.0") diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/XmlArtifact.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/XmlArtifact.java index 78d5e22412..3a3fbd16a3 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/XmlArtifact.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/XmlArtifact.java @@ -22,6 +22,12 @@ package org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage; +import org.openecomp.sdc.logging.types.LoggerConstants; +import org.openecomp.sdc.logging.types.LoggerErrorCode; +import org.openecomp.sdc.logging.types.LoggerErrorDescription; +import org.openecomp.sdc.logging.types.LoggerTragetServiceName; import org.openecomp.sdc.vendorlicense.VendorLicenseConstants; import org.openecomp.sdc.vendorlicense.errors.JsonErrorBuilder; @@ -42,8 +48,11 @@ public abstract class XmlArtifact { try { xml = xmlMapper.writeValueAsString(this); - } catch (com.fasterxml.jackson.core.JsonProcessingException jsonProcessingException) { - throw new CoreException(new JsonErrorBuilder(jsonProcessingException.getMessage()).build()); + } catch (com.fasterxml.jackson.core.JsonProcessingException exception) { + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, + LoggerTragetServiceName.WRITE_ARTIFACT_XML, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_JSON); + throw new CoreException(new JsonErrorBuilder(exception.getMessage()).build()); } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinEntitlementPoolEntityForVendorLicenseArtifact.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinEntitlementPoolEntityForVendorLicenseArtifact.java index 1458fa80a7..020316f019 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinEntitlementPoolEntityForVendorLicenseArtifact.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinEntitlementPoolEntityForVendorLicenseArtifact.java @@ -22,13 +22,14 @@ package org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction; import org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther; import org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric; import org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime; import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope; +import org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction; import org.openecomp.sdc.vendorlicense.dao.types.xml.AggregationFunctionForXml; import org.openecomp.sdc.vendorlicense.dao.types.xml.EntitlementMetricForXml; import org.openecomp.sdc.vendorlicense.dao.types.xml.EntitlementTimeForXml; @@ -36,6 +37,7 @@ import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml; import java.util.Set; +@JsonPropertyOrder({ "entitlement-pool-invariant-uuid", "entitlement-pool-uuid" }) public abstract class MixinEntitlementPoolEntityForVendorLicenseArtifact { @JsonProperty(value = "threshold-value") abstract ThresholdForXml getThresholdForArtifact(); @@ -43,24 +45,26 @@ public abstract class MixinEntitlementPoolEntityForVendorLicenseArtifact { @JsonProperty(value = "entitlement-pool-uuid") abstract String getVersionUuId(); - @JsonProperty(value = "manufacturer-reference-number") - abstract String getManufacturerReferenceNumber(); - @JsonIgnore abstract Set getReferencingFeatureGroups(); @JsonIgnore abstract String getFirstClassCitizenId(); - @JsonIgnore + @JsonProperty(value = "entitlement-pool-invariant-uuid") abstract String getId(); - @JsonIgnore - abstract String getVersion(); + @JsonProperty(value = "manufacturer-reference-number") + abstract String getManufacturerReferenceNumber(); + + @JsonProperty(value = "version") + abstract String getVersionForArtifact(); @JsonIgnore abstract String getVendorLicenseModelId(); + + @JsonIgnore abstract String getThresholdUnit(); @@ -79,7 +83,7 @@ public abstract class MixinEntitlementPoolEntityForVendorLicenseArtifact { @JsonIgnore abstract String getEntityType(); - @JacksonXmlProperty(isAttribute = false, localName = "value") + @JacksonXmlProperty(localName = "value") @JacksonXmlElementWrapper(localName = "operational-scope") abstract String getOperationalScopeForArtifact(); diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinEntitlementPoolEntityForVnfArtifact.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinEntitlementPoolEntityForVnfArtifact.java index c4f2b4d4bd..064d17b8fa 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinEntitlementPoolEntityForVnfArtifact.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinEntitlementPoolEntityForVnfArtifact.java @@ -58,6 +58,9 @@ public abstract class MixinEntitlementPoolEntityForVnfArtifact { @JsonIgnore abstract String getVersion(); + @JsonIgnore + abstract String getVersionForArtifact(); + @JsonIgnore abstract String getVendorLicenseModelId(); diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinFeatureGroupModel.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinFeatureGroupModel.java index 1e76a74f4c..f5eb5f0bad 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinFeatureGroupModel.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinFeatureGroupModel.java @@ -38,7 +38,7 @@ public abstract class MixinFeatureGroupModel { @JacksonXmlElementWrapper(localName = "license-key-group-list") abstract Set getLicenseKeyGroups(); - @JacksonXmlProperty(isAttribute = false, localName = "internal-part-number") + @JacksonXmlProperty(isAttribute = false, localName = "part-number") abstract String getEntityPartNumber(); @JacksonXmlProperty(isAttribute = false, localName = "feature-group-uuid") diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinLicenseKeyGroupEntityForVendorLicenseArtifact.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinLicenseKeyGroupEntityForVendorLicenseArtifact.java index ed3083afe3..b5fb2f4549 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinLicenseKeyGroupEntityForVendorLicenseArtifact.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinLicenseKeyGroupEntityForVendorLicenseArtifact.java @@ -37,8 +37,8 @@ public abstract class MixinLicenseKeyGroupEntityForVendorLicenseArtifact { @JsonIgnore abstract Set getReferencingFeatureGroups(); - @JsonIgnore - abstract String getVersion(); + @JsonProperty(value = "version") + abstract String getVersionForArtifact(); @JsonIgnore abstract String getVendorLicenseModelId(); @@ -50,7 +50,7 @@ public abstract class MixinLicenseKeyGroupEntityForVendorLicenseArtifact { @JsonIgnore abstract String getFirstClassCitizenId(); - @JsonIgnore + @JsonProperty(value = "license-key-group-invariant-uuid") abstract String getId(); diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinLicenseKeyGroupEntityForVnfArtifact.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinLicenseKeyGroupEntityForVnfArtifact.java index 6281c44830..ed171c6a4b 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinLicenseKeyGroupEntityForVnfArtifact.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/types/mixins/MixinLicenseKeyGroupEntityForVnfArtifact.java @@ -40,6 +40,9 @@ public abstract class MixinLicenseKeyGroupEntityForVnfArtifact { @JsonIgnore abstract String getVersion(); + @JsonIgnore + abstract String getVersionForArtifact(); + @JsonIgnore abstract String getVendorLicenseModelId(); @@ -54,7 +57,6 @@ public abstract class MixinLicenseKeyGroupEntityForVnfArtifact { abstract String getFirstClassCitizenId(); - @JsonIgnore abstract ChoiceOrOther getOperationalScope(); @@ -71,4 +73,3 @@ public abstract class MixinLicenseKeyGroupEntityForVnfArtifact { } - diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/util/VendorLicenseArtifactsServiceUtils.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/util/VendorLicenseArtifactsServiceUtils.java new file mode 100644 index 0000000000..f3e09766db --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/util/VendorLicenseArtifactsServiceUtils.java @@ -0,0 +1,132 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util; + +import org.apache.commons.collections4.MultiValuedMap; +import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; +import org.openecomp.sdc.vendorlicense.HealingServiceFactory; +import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity; +import org.openecomp.sdc.vendorlicense.healing.HealingService; +import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.VendorLicenseArtifactsServiceImpl; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.dao.types.VersionableEntity; +import org.openecomp.sdc.versioning.types.VersionInfo; +import org.openecomp.sdc.versioning.types.VersionableEntityAction; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * @author katyr + * @since January 10, 2017 + */ + +public class VendorLicenseArtifactsServiceUtils { + private static final HealingService healingService = + HealingServiceFactory.getInstance().createInterface(); + + /** + * maps the entities by id + * + * @return a Map of id -> list of versionable entities with that id + */ + static MultiValuedMap mapById( + Collection versionableEntities) { + MultiValuedMap mappedById = new ArrayListValuedHashMap<>(); + for (VersionableEntity ve : versionableEntities) { + mappedById.put(ve.getId(), ve); + } + return mappedById; + } + + /** + * For all entities with same id, only entities that differ from one another will be returned. + * If no change has occured, the entity with the earlier VLM version will be returned. + * If only one version of said entitity exists it will be returned + * @param versionableEntities + * @return a list of entities that has been changed + */ + public static List filterChangedEntities( + Collection versionableEntities) { + MultiValuedMap entitiesById = mapById( + versionableEntities); + MultiValuedMap entitiesByVersionUuId = + new ArrayListValuedHashMap<>(); + List changedOnly = new ArrayList<>(); + + for (String epId : entitiesById.keySet()) { + Collection versionableEntitiesForId = entitiesById.get(epId); + for (VersionableEntity ep : versionableEntitiesForId) { + entitiesByVersionUuId.put(ep.getVersionUuId(), ep); + } + } + + //for every list of eps which have the same uuid, get the one with the earliest vlm version. + for (String versionUid : entitiesByVersionUuId.keySet()) { + List versionableEntitiesForUuid = + (List) entitiesByVersionUuId.get(versionUid); + versionableEntitiesForUuid.sort(new VersionableEntitySortByVlmMajorVersion()); + changedOnly.add(versionableEntitiesForUuid.get(0)); + } + + return changedOnly; + } + + public static Set healLkgs(String user, + Collection licenseKeyGroupEntities) { + Set healed = new HashSet<>(); + for (VersionableEntity licenseKeyGroupEntity : licenseKeyGroupEntities) { + healed.add((LicenseKeyGroupEntity) VendorLicenseArtifactsServiceImpl.healingService + .heal(licenseKeyGroupEntity, user)); + } + + return healed; + } + + public static Set healEPs(String user, + Collection entitlementPoolEntities) { + Set healed = new HashSet<>(); + for (VersionableEntity entitlementPoolEntity : entitlementPoolEntities) { + healed.add((EntitlementPoolEntity) VendorLicenseArtifactsServiceImpl.healingService + .heal(entitlementPoolEntity, user)); + } + + return healed; + } + + public static List getFinalVersionsForVlm(String vlmId) { + VersionInfo versionInfo = + VendorLicenseArtifactsServiceImpl.vendorLicenseFacade + .getVersionInfo(vlmId, VersionableEntityAction.Read, ""); + return versionInfo.getFinalVersions(); + + } + + public static String getVendorName(String vendorLicenseModelId, String user) { + return VendorLicenseArtifactsServiceImpl.vendorLicenseFacade + .getVendorLicenseModel(vendorLicenseModelId, null, user) + .getVendorLicenseModel().getVendorName(); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/util/VersionableEntitySortByVlmMajorVersion.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/util/VersionableEntitySortByVlmMajorVersion.java new file mode 100644 index 0000000000..1aee2dd97e --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts/impl/util/VersionableEntitySortByVlmMajorVersion.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util; + +import org.openecomp.sdc.versioning.dao.types.VersionableEntity; + +import java.util.Comparator; + +/** + * @author katyr + * @since January 10, 2017 + */ + +public class VersionableEntitySortByVlmMajorVersion implements Comparator { + @Override + public int compare(VersionableEntity o1, VersionableEntity o2) { + return Integer.compare(o1.getVersion().getMajor(), o2.getVersion().getMajor()); + + } +} -- cgit 1.2.3-korg