diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/licenseartifacts')
13 files changed, 596 insertions, 692 deletions
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 f0f8a6cb7c..7b5902e08f 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 @@ -13,9 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorlicense.licenseartifacts.impl; +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; +import static org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util.VendorLicenseArtifactsServiceUtils.filterChangedEntities; +import static org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util.VendorLicenseArtifactsServiceUtils.getFinalVersionsForVlm; +import static org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util.VendorLicenseArtifactsServiceUtils.getVendorName; +import static org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util.VendorLicenseArtifactsServiceUtils.healEPs; +import static org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util.VendorLicenseArtifactsServiceUtils.healLkgs; +import static org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util.VendorLicenseArtifactsServiceUtils.prepareForFiltering; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.openecomp.core.utilities.file.FileContentHandler; @@ -32,155 +47,105 @@ import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.VendorLicense import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.VnfLicenseArtifact; import org.openecomp.sdc.versioning.dao.types.Version; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -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; -import static org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util.VendorLicenseArtifactsServiceUtils.filterChangedEntities; -import static org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util.VendorLicenseArtifactsServiceUtils.getFinalVersionsForVlm; -import static org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util.VendorLicenseArtifactsServiceUtils.getVendorName; -import static org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util.VendorLicenseArtifactsServiceUtils.healEPs; -import static org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util.VendorLicenseArtifactsServiceUtils.healLkgs; -import static org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util.VendorLicenseArtifactsServiceUtils.prepareForFiltering; - public class VendorLicenseArtifactsServiceImpl implements VendorLicenseArtifactsService { - public static final VendorLicenseFacade vendorLicenseFacade = - VendorLicenseFacadeFactory.getInstance().createInterface(); - public static final HealingService healingService = - HealingServiceFactory.getInstance().createInterface(); - private static byte[] createVnfArtifact(String vspId, String vlmId, Version vlmVersion, String vendorName, - List<String> featureGroups) { - VnfLicenseArtifact artifact = new VnfLicenseArtifact(); - - artifact.setVspId(vspId); - artifact.setVendorName(vendorName); - if (featureGroups != null) { - for (String featureGroupId : featureGroups) { - FeatureGroupModel featureGroupModel = vendorLicenseFacade - .getFeatureGroupModel(new FeatureGroupEntity(vlmId, vlmVersion, featureGroupId)); - Set<EntitlementPoolEntity> entitlementPoolEntities = - featureGroupModel.getEntitlementPools(); - String manufacturerReferenceNumber = featureGroupModel.getEntityManufacturerReferenceNumber(); - for (EntitlementPoolEntity entitlementPoolEntity : entitlementPoolEntities) { - entitlementPoolEntity.setLimits(vendorLicenseFacade.listLimits(vlmId, vlmVersion, - entitlementPoolEntity.getId())); - if (Objects.nonNull(manufacturerReferenceNumber) && !manufacturerReferenceNumber.trim().isEmpty()) { - entitlementPoolEntity.setManufacturerReferenceNumber(manufacturerReferenceNumber); - } + public static final VendorLicenseFacade vendorLicenseFacade = VendorLicenseFacadeFactory.getInstance().createInterface(); + public static final HealingService healingService = HealingServiceFactory.getInstance().createInterface(); + + private static byte[] createVnfArtifact(String vspId, String vlmId, Version vlmVersion, String vendorName, List<String> featureGroups) { + VnfLicenseArtifact artifact = new VnfLicenseArtifact(); + artifact.setVspId(vspId); + artifact.setVendorName(vendorName); + if (featureGroups != null) { + for (String featureGroupId : featureGroups) { + FeatureGroupModel featureGroupModel = vendorLicenseFacade + .getFeatureGroupModel(new FeatureGroupEntity(vlmId, vlmVersion, featureGroupId)); + Set<EntitlementPoolEntity> entitlementPoolEntities = featureGroupModel.getEntitlementPools(); + String manufacturerReferenceNumber = featureGroupModel.getEntityManufacturerReferenceNumber(); + for (EntitlementPoolEntity entitlementPoolEntity : entitlementPoolEntities) { + entitlementPoolEntity.setLimits(vendorLicenseFacade.listLimits(vlmId, vlmVersion, entitlementPoolEntity.getId())); + if (Objects.nonNull(manufacturerReferenceNumber) && !manufacturerReferenceNumber.trim().isEmpty()) { + entitlementPoolEntity.setManufacturerReferenceNumber(manufacturerReferenceNumber); + } + } + Set<LicenseKeyGroupEntity> licenseKeyGroupEntities = featureGroupModel.getLicenseKeyGroups(); + for (LicenseKeyGroupEntity licenseKeyGroupEntity : licenseKeyGroupEntities) { + licenseKeyGroupEntity.setLimits(vendorLicenseFacade.listLimits(vlmId, vlmVersion, licenseKeyGroupEntity.getId())); + if (Objects.nonNull(manufacturerReferenceNumber) && !manufacturerReferenceNumber.trim().isEmpty()) { + licenseKeyGroupEntity.setManufacturerReferenceNumber(manufacturerReferenceNumber); + } + } + featureGroupModel.setEntitlementPools( + entitlementPoolEntities.stream().map(entitlementPoolEntity -> (EntitlementPoolEntity) healingService.heal(entitlementPoolEntity)) + .collect(Collectors.toSet())); + featureGroupModel.setLicenseKeyGroups( + licenseKeyGroupEntities.stream().map(licenseKeyGroupEntity -> (LicenseKeyGroupEntity) healingService.heal(licenseKeyGroupEntity)) + .collect(Collectors.toSet())); + artifact.getFeatureGroups().add(featureGroupModel); + } } + return artifact.toXml().getBytes(); + } - Set<LicenseKeyGroupEntity> licenseKeyGroupEntities = - featureGroupModel.getLicenseKeyGroups(); - for (LicenseKeyGroupEntity licenseKeyGroupEntity : licenseKeyGroupEntities) { - licenseKeyGroupEntity.setLimits(vendorLicenseFacade.listLimits(vlmId, vlmVersion, - licenseKeyGroupEntity.getId())); - if (Objects.nonNull(manufacturerReferenceNumber) && !manufacturerReferenceNumber.trim().isEmpty()) { - licenseKeyGroupEntity.setManufacturerReferenceNumber(manufacturerReferenceNumber); - } + private static byte[] createVendorLicenseArtifact(String vlmId, String vendorName) { + VendorLicenseArtifact vendorLicenseArtifact = new VendorLicenseArtifact(); + vendorLicenseArtifact.setVendorName(vendorName); + Set<EntitlementPoolEntity> entitlementPoolEntities = new HashSet<>(); + Set<LicenseKeyGroupEntity> licenseKeyGroupEntities = new HashSet<>(); + List<Version> finalVersions = getFinalVersionsForVlm(vlmId); + for (Version finalVersion : finalVersions) { + Collection<EntitlementPoolEntity> eps = vendorLicenseFacade.listEntitlementPools(vlmId, finalVersion); + eps.forEach(entitlementPoolEntity -> { + entitlementPoolEntity.setLimits(vendorLicenseFacade.listLimits(vlmId, finalVersion, entitlementPoolEntity.getId())); + Optional<String> manufacturerReferenceNumber = getFeatureGroupManufactureRefNumber( + entitlementPoolEntity.getReferencingFeatureGroups(), vlmId, finalVersion); + manufacturerReferenceNumber.ifPresent(entitlementPoolEntity::setManufacturerReferenceNumber); + }); + entitlementPoolEntities.addAll(eps); + Collection<LicenseKeyGroupEntity> lkgs = vendorLicenseFacade.listLicenseKeyGroups(vlmId, finalVersion); + lkgs.forEach(licenseKeyGroupEntity -> { + licenseKeyGroupEntity.setLimits(vendorLicenseFacade.listLimits(vlmId, finalVersion, licenseKeyGroupEntity.getId())); + Optional<String> manufacturerReferenceNumber = getFeatureGroupManufactureRefNumber( + licenseKeyGroupEntity.getReferencingFeatureGroups(), vlmId, finalVersion); + manufacturerReferenceNumber.ifPresent(licenseKeyGroupEntity::setManufacturerReferenceNumber); + }); + licenseKeyGroupEntities.addAll(lkgs); } - - featureGroupModel.setEntitlementPools(entitlementPoolEntities.stream().map( - entitlementPoolEntity -> (EntitlementPoolEntity) healingService - .heal(entitlementPoolEntity)).collect(Collectors.toSet())); - featureGroupModel.setLicenseKeyGroups(licenseKeyGroupEntities.stream().map( - licenseKeyGroupEntity -> (LicenseKeyGroupEntity) healingService - .heal(licenseKeyGroupEntity)).collect(Collectors.toSet())); - artifact.getFeatureGroups().add(featureGroupModel); - } + entitlementPoolEntities = healEPs(filterChangedEntities(prepareForFiltering(entitlementPoolEntities, true))); + licenseKeyGroupEntities = healLkgs(filterChangedEntities(prepareForFiltering(licenseKeyGroupEntities, false))); + vendorLicenseArtifact.setEntitlementPoolEntities(entitlementPoolEntities); + vendorLicenseArtifact.setLicenseKeyGroupEntities(licenseKeyGroupEntities); + return vendorLicenseArtifact.toXml().getBytes(); } - return artifact.toXml().getBytes(); - } - - private static byte[] createVendorLicenseArtifact(String vlmId, String vendorName) { - VendorLicenseArtifact vendorLicenseArtifact = new VendorLicenseArtifact(); - vendorLicenseArtifact.setVendorName(vendorName); - Set<EntitlementPoolEntity> entitlementPoolEntities = new HashSet<>(); - Set<LicenseKeyGroupEntity> licenseKeyGroupEntities = new HashSet<>(); - - List<Version> finalVersions = getFinalVersionsForVlm(vlmId); - for (Version finalVersion : finalVersions) { - Collection<EntitlementPoolEntity> eps = - vendorLicenseFacade.listEntitlementPools(vlmId, finalVersion); - eps.forEach(entitlementPoolEntity -> { - entitlementPoolEntity.setLimits(vendorLicenseFacade.listLimits(vlmId, finalVersion, - entitlementPoolEntity.getId())); - Optional<String> manufacturerReferenceNumber = getFeatureGroupManufactureRefNumber - (entitlementPoolEntity.getReferencingFeatureGroups(), vlmId, finalVersion); - manufacturerReferenceNumber - .ifPresent(entitlementPoolEntity::setManufacturerReferenceNumber); - }); - entitlementPoolEntities.addAll(eps); - Collection<LicenseKeyGroupEntity> lkgs = - vendorLicenseFacade.listLicenseKeyGroups(vlmId, finalVersion); - - lkgs.forEach(licenseKeyGroupEntity -> { - licenseKeyGroupEntity.setLimits(vendorLicenseFacade.listLimits(vlmId, finalVersion, - licenseKeyGroupEntity.getId())); - Optional<String> manufacturerReferenceNumber = getFeatureGroupManufactureRefNumber - (licenseKeyGroupEntity.getReferencingFeatureGroups(), vlmId, finalVersion); - manufacturerReferenceNumber - .ifPresent(licenseKeyGroupEntity::setManufacturerReferenceNumber); - }); - licenseKeyGroupEntities.addAll(lkgs); + private static Optional<String> getFeatureGroupManufactureRefNumber(Set<String> featureGroupIds, String vlmId, Version finalVersion) { + String manufactureReferenceNumber = null; + if (CollectionUtils.isNotEmpty(featureGroupIds)) { + Object[] featureGroupIdsList = featureGroupIds.toArray(); + if (featureGroupIdsList.length > 0) { + FeatureGroupEntity featureGroup = vendorLicenseFacade + .getFeatureGroup(new FeatureGroupEntity(vlmId, finalVersion, featureGroupIdsList[0].toString())); + manufactureReferenceNumber = featureGroup != null ? featureGroup.getManufacturerReferenceNumber() : null; + } + } + return StringUtils.isNotEmpty(manufactureReferenceNumber) ? Optional.of(manufactureReferenceNumber) : Optional.empty(); } - - entitlementPoolEntities = - healEPs(filterChangedEntities(prepareForFiltering(entitlementPoolEntities, true))); - licenseKeyGroupEntities = - healLkgs(filterChangedEntities(prepareForFiltering(licenseKeyGroupEntities, false))); - vendorLicenseArtifact.setEntitlementPoolEntities(entitlementPoolEntities); - vendorLicenseArtifact.setLicenseKeyGroupEntities(licenseKeyGroupEntities); - return vendorLicenseArtifact.toXml().getBytes(); - } - - private static Optional<String> getFeatureGroupManufactureRefNumber(Set<String> featureGroupIds, - String vlmId, - Version finalVersion) { - String manufactureReferenceNumber = null; - if (CollectionUtils.isNotEmpty(featureGroupIds)) { - Object[] featureGroupIdsList = featureGroupIds.toArray(); - if (featureGroupIdsList.length > 0) { - FeatureGroupEntity featureGroup = - vendorLicenseFacade.getFeatureGroup(new FeatureGroupEntity(vlmId, finalVersion, - featureGroupIdsList[0].toString())); - manufactureReferenceNumber = featureGroup != null ? featureGroup - .getManufacturerReferenceNumber() : null; - } + /** + * Create License Artifacts. + * + * @param vspId vspId + * @param vlmId vlmId + * @param vlmVersion vlmVersion + * @param featureGroups featureGroups + * @return FileContentHandler + */ + @Override + public FileContentHandler createLicenseArtifacts(String vspId, String vlmId, Version vlmVersion, List<String> featureGroups) { + FileContentHandler artifacts = new FileContentHandler(); + String vendorName = getVendorName(vlmId); + artifacts.addFile(VNF_ARTIFACT_NAME_WITH_PATH, createVnfArtifact(vspId, vlmId, vlmVersion, vendorName, featureGroups)); + artifacts.addFile(VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH, createVendorLicenseArtifact(vlmId, vendorName)); + return artifacts; } - return StringUtils.isNotEmpty(manufactureReferenceNumber) ? Optional.of(manufactureReferenceNumber) : - Optional.empty(); - } - - - /** - * Create License Artifacts. - * - * @param vspId vspId - * @param vlmId vlmId - * @param vlmVersion vlmVersion - * @param featureGroups featureGroups - * @return FileContentHandler - */ - @Override - public FileContentHandler createLicenseArtifacts(String vspId, String vlmId, Version vlmVersion, - List<String> featureGroups) { - FileContentHandler artifacts = new FileContentHandler(); - String vendorName = getVendorName(vlmId); - - artifacts.addFile(VNF_ARTIFACT_NAME_WITH_PATH, - createVnfArtifact(vspId, vlmId, vlmVersion, vendorName, featureGroups)); - artifacts.addFile(VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH, - createVendorLicenseArtifact(vlmId, vendorName)); - 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/VendorLicenseArtifact.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/VendorLicenseArtifact.java index afc1d3151b..a805b75587 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/VendorLicenseArtifact.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/VendorLicenseArtifact.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,13 +17,13 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import java.util.Collection; import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity; import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitXml; @@ -31,53 +31,47 @@ import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins.MixinE import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins.MixinLicenseKeyGroupEntityForVendorLicenseArtifact; import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins.MixinLimitArtifact; -import java.util.Collection; - @JacksonXmlRootElement(localName = "vendor-license-model", namespace = "http://xmlns.openecomp.org/asdc/license-model/1.0") public class VendorLicenseArtifact extends XmlArtifact { - @JsonProperty(value = "vendor-name") - String vendorName; - Collection<EntitlementPoolEntity> entitlementPoolEntities; - Collection<LicenseKeyGroupEntity> licenseKeyGroupEntities; + @JsonProperty(value = "vendor-name") + String vendorName; + Collection<EntitlementPoolEntity> entitlementPoolEntities; + Collection<LicenseKeyGroupEntity> licenseKeyGroupEntities; - public String getVendorName() { - return vendorName; - } + public String getVendorName() { + return vendorName; + } - public void setVendorName(String vendorName) { - this.vendorName = vendorName; - } + public void setVendorName(String vendorName) { + this.vendorName = vendorName; + } - @JacksonXmlProperty(isAttribute = false, localName = "entitlement-pool") - @JacksonXmlElementWrapper(localName = "entitlement-pool-list") - public Collection<EntitlementPoolEntity> getEntitlementPoolEntities() { - return entitlementPoolEntities; - } + @JacksonXmlProperty(isAttribute = false, localName = "entitlement-pool") + @JacksonXmlElementWrapper(localName = "entitlement-pool-list") + public Collection<EntitlementPoolEntity> getEntitlementPoolEntities() { + return entitlementPoolEntities; + } - public void setEntitlementPoolEntities( - Collection<EntitlementPoolEntity> entitlementPoolEntities) { - this.entitlementPoolEntities = entitlementPoolEntities; - } + public void setEntitlementPoolEntities(Collection<EntitlementPoolEntity> entitlementPoolEntities) { + this.entitlementPoolEntities = entitlementPoolEntities; + } - @JacksonXmlProperty(isAttribute = false, localName = "license-key-group") - @JacksonXmlElementWrapper(localName = "license-key-group-list") - public Collection<LicenseKeyGroupEntity> getLicenseKeyGroupEntities() { - return licenseKeyGroupEntities; - } + @JacksonXmlProperty(isAttribute = false, localName = "license-key-group") + @JacksonXmlElementWrapper(localName = "license-key-group-list") + public Collection<LicenseKeyGroupEntity> getLicenseKeyGroupEntities() { + return licenseKeyGroupEntities; + } - public void setLicenseKeyGroupEntities( - Collection<LicenseKeyGroupEntity> licenseKeyGroupEntities) { - this.licenseKeyGroupEntities = licenseKeyGroupEntities; - } + public void setLicenseKeyGroupEntities(Collection<LicenseKeyGroupEntity> licenseKeyGroupEntities) { + this.licenseKeyGroupEntities = licenseKeyGroupEntities; + } - @Override - void initMapper() { - xmlMapper.addMixIn(EntitlementPoolEntity.class, - MixinEntitlementPoolEntityForVendorLicenseArtifact.class); - xmlMapper.addMixIn(LicenseKeyGroupEntity.class, - MixinLicenseKeyGroupEntityForVendorLicenseArtifact.class); - xmlMapper.addMixIn(LimitXml.class, MixinLimitArtifact.class); - } + @Override + void initMapper() { + xmlMapper.addMixIn(EntitlementPoolEntity.class, MixinEntitlementPoolEntityForVendorLicenseArtifact.class); + xmlMapper.addMixIn(LicenseKeyGroupEntity.class, MixinLicenseKeyGroupEntityForVendorLicenseArtifact.class); + xmlMapper.addMixIn(LimitXml.class, MixinLimitArtifact.class); + } } 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 91a73b6377..1686b9631d 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types; import com.ctc.wstx.api.WstxInputProperties; @@ -29,6 +28,11 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel; import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity; @@ -38,63 +42,55 @@ import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins.MixinF import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins.MixinLicenseKeyGroupEntityForVnfArtifact; import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins.MixinLimitArtifact; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.List; - @JacksonXmlRootElement(localName = "vf-license-model", namespace = "http://xmlns.openecomp.org/asdc/license-model/1.0") public class VnfLicenseArtifact extends XmlArtifact { - @JsonProperty(value = "vendor-name") - String vendorName; - @JsonProperty(value = "vf-id") - String vspId; - List<FeatureGroupModel> featureGroups = new ArrayList<>(); - - public String getVspId() { - return vspId; - } - - public void setVspId(String vspId) { - this.vspId = vspId; - } - public String getVendorName() { - return vendorName; - } + @JsonProperty(value = "vendor-name") + String vendorName; + @JsonProperty(value = "vf-id") + String vspId; + List<FeatureGroupModel> featureGroups = new ArrayList<>(); - public void setVendorName(String vendorName) { - this.vendorName = vendorName; - } + public String getVspId() { + return vspId; + } - @JacksonXmlProperty(isAttribute = false, localName = "feature-group") - @JacksonXmlElementWrapper(localName = "feature-group-list") - public List<FeatureGroupModel> getFeatureGroups() { - return featureGroups; - } + public void setVspId(String vspId) { + this.vspId = vspId; + } - public void setFeatureGroups(List<FeatureGroupModel> featureGroups) { - this.featureGroups = featureGroups; - } + public String getVendorName() { + return vendorName; + } - void initMapper() { - WstxOutputFactory wstxOutputFactory = new WstxOutputFactory() { - @Override - public XMLStreamWriter createXMLStreamWriter(Writer writer) throws XMLStreamException { - mConfig.setProperty(WstxInputProperties.P_RETURN_NULL_FOR_DEFAULT_NAMESPACE, true); - return super.createXMLStreamWriter(writer); - } - }; - XmlFactory factory = new XmlFactory(new WstxInputFactory(), wstxOutputFactory); + public void setVendorName(String vendorName) { + this.vendorName = vendorName; + } - xmlMapper = new XmlMapper(factory); + @JacksonXmlProperty(isAttribute = false, localName = "feature-group") + @JacksonXmlElementWrapper(localName = "feature-group-list") + public List<FeatureGroupModel> getFeatureGroups() { + return featureGroups; + } + public void setFeatureGroups(List<FeatureGroupModel> featureGroups) { + this.featureGroups = featureGroups; + } - xmlMapper.addMixIn(EntitlementPoolEntity.class, MixinEntitlementPoolEntityForVnfArtifact.class); - xmlMapper.addMixIn(LicenseKeyGroupEntity.class, MixinLicenseKeyGroupEntityForVnfArtifact.class); - xmlMapper.addMixIn(FeatureGroupModel.class, MixinFeatureGroupModel.class); - xmlMapper.addMixIn(LimitXml.class, MixinLimitArtifact.class); - } + void initMapper() { + WstxOutputFactory wstxOutputFactory = new WstxOutputFactory() { + @Override + public XMLStreamWriter createXMLStreamWriter(Writer writer) throws XMLStreamException { + mConfig.setProperty(WstxInputProperties.P_RETURN_NULL_FOR_DEFAULT_NAMESPACE, true); + return super.createXMLStreamWriter(writer); + } + }; + XmlFactory factory = new XmlFactory(new WstxInputFactory(), wstxOutputFactory); + xmlMapper = new XmlMapper(factory); + xmlMapper.addMixIn(EntitlementPoolEntity.class, MixinEntitlementPoolEntityForVnfArtifact.class); + xmlMapper.addMixIn(LicenseKeyGroupEntity.class, MixinLicenseKeyGroupEntityForVnfArtifact.class); + xmlMapper.addMixIn(FeatureGroupModel.class, MixinFeatureGroupModel.class); + xmlMapper.addMixIn(LimitXml.class, MixinLimitArtifact.class); + } } 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 7052d6afb6..dc5089f57a 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 @@ -12,8 +12,7 @@ * 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. -*/ - + */ package org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types; import com.fasterxml.jackson.dataformat.xml.XmlMapper; @@ -23,28 +22,23 @@ import org.openecomp.sdc.vendorlicense.errors.JsonErrorBuilder; public abstract class XmlArtifact { - XmlMapper xmlMapper = new XmlMapper(); - - abstract void initMapper(); - - /** - * To xml string. - * - * @return the string - */ - public String toXml() { - initMapper(); - String xml; - - try { - xml = xmlMapper.writeValueAsString(this); - } catch (com.fasterxml.jackson.core.JsonProcessingException exception) { - throw new CoreException(new JsonErrorBuilder("Failed to write xml value as string ") - .build(), exception); + XmlMapper xmlMapper = new XmlMapper(); + + abstract void initMapper(); + + /** + * To xml string. + * + * @return the string + */ + public String toXml() { + initMapper(); + String xml; + try { + xml = xmlMapper.writeValueAsString(this); + } catch (com.fasterxml.jackson.core.JsonProcessingException exception) { + throw new CoreException(new JsonErrorBuilder("Failed to write xml value as string ").build(), exception); + } + return xml.replaceAll(VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_REGEX_REMOVE, ""); } - - return xml.replaceAll(VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_REGEX_REMOVE, ""); - } - - } 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 5afd0a9ab1..55301c9b7f 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,98 +17,104 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - 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 org.openecomp.sdc.vendorlicense.dao.types.*; -import org.openecomp.sdc.vendorlicense.dao.types.xml.*; - import java.util.Collection; import java.util.Set; - -@JsonPropertyOrder({ "entitlement-pool-invariant-uuid", "entitlement-pool-uuid" }) +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.LimitEntity; +import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope; +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; +import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml; +import org.openecomp.sdc.vendorlicense.dao.types.xml.OperationalScopeForXml; +import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml; + +@JsonPropertyOrder({"entitlement-pool-invariant-uuid", "entitlement-pool-uuid"}) public abstract class MixinEntitlementPoolEntityForVendorLicenseArtifact { - @JsonProperty(value = "threshold-value") - abstract ThresholdForXml getThresholdForArtifact(); - - @JsonProperty(value = "entitlement-pool-uuid") - abstract String getVersionUuId(); - - @JsonIgnore - abstract Set<String> getReferencingFeatureGroups(); - @JsonIgnore - abstract String getFirstClassCitizenId(); + @JsonProperty(value = "threshold-value") + abstract ThresholdForXml getThresholdForArtifact(); - @JsonProperty(value = "entitlement-pool-invariant-uuid") - abstract String getId(); + @JsonProperty(value = "entitlement-pool-uuid") + abstract String getVersionUuId(); - @JsonProperty(value = "manufacturer-reference-number") - abstract String getManufacturerReferenceNumber(); + @JsonIgnore + abstract Set<String> getReferencingFeatureGroups(); - @JsonProperty(value = "version") - abstract String getVersionForArtifact(); + @JsonIgnore + abstract String getFirstClassCitizenId(); - @JsonIgnore - abstract String getStartDate(); + @JsonProperty(value = "entitlement-pool-invariant-uuid") + abstract String getId(); - @JsonIgnore - abstract String getExpiryDate(); + @JsonProperty(value = "manufacturer-reference-number") + abstract String getManufacturerReferenceNumber(); - @JsonProperty(value = "start-date") - abstract String getIsoFormatStartDate(); + @JsonProperty(value = "version") + abstract String getVersionForArtifact(); - @JsonProperty(value = "expiry-date") - abstract String getIsoFormatExpiryDate(); + @JsonIgnore + abstract String getStartDate(); - @JsonIgnore - abstract String getVendorLicenseModelId(); + @JsonIgnore + abstract String getExpiryDate(); + @JsonProperty(value = "start-date") + abstract String getIsoFormatStartDate(); + @JsonProperty(value = "expiry-date") + abstract String getIsoFormatExpiryDate(); - @JsonIgnore - abstract String getThresholdUnit(); + @JsonIgnore + abstract String getVendorLicenseModelId(); - @JsonIgnore - abstract float getThresholdValue(); + @JsonIgnore + abstract String getThresholdUnit(); - @JsonIgnore - abstract ChoiceOrOther<EntitlementMetric> getEntitlementMetric(); + @JsonIgnore + abstract float getThresholdValue(); - @JsonIgnore - abstract ChoiceOrOther<EntitlementTime> getTime(); + @JsonIgnore + abstract ChoiceOrOther<EntitlementMetric> getEntitlementMetric(); - @JsonIgnore - abstract ChoiceOrOther<AggregationFunction> getAggregationFunction(); + @JsonIgnore + abstract ChoiceOrOther<EntitlementTime> getTime(); - @JsonIgnore - abstract String getEntityType(); + @JsonIgnore + abstract ChoiceOrOther<AggregationFunction> getAggregationFunction(); - @JsonProperty(value = "operational-scope") - abstract OperationalScopeForXml getOperationalScopeForArtifact(); + @JsonIgnore + abstract String getEntityType(); - @JsonIgnore - abstract ChoiceOrOther<OperationalScope> getOperationalScope(); + @JsonProperty(value = "operational-scope") + abstract OperationalScopeForXml getOperationalScopeForArtifact(); - @JsonProperty(value = "entitlement-metric") - abstract EntitlementMetricForXml getEntitlementMetricForArtifact(); + @JsonIgnore + abstract ChoiceOrOther<OperationalScope> getOperationalScope(); - @JsonProperty(value = "time") - abstract EntitlementTimeForXml getTimeForArtifact(); + @JsonProperty(value = "entitlement-metric") + abstract EntitlementMetricForXml getEntitlementMetricForArtifact(); + @JsonProperty(value = "time") + abstract EntitlementTimeForXml getTimeForArtifact(); - @JsonProperty(value = "aggregation-function") - abstract AggregationFunctionForXml getAggregationFunctionForArtifact(); + @JsonProperty(value = "aggregation-function") + abstract AggregationFunctionForXml getAggregationFunctionForArtifact(); - @JsonProperty(value = "sp-limits") - abstract LimitForXml getSPLimits(); + @JsonProperty(value = "sp-limits") + abstract LimitForXml getSPLimits(); - @JsonProperty(value = "vendor-limits") - abstract LimitForXml getVendorLimits(); + @JsonProperty(value = "vendor-limits") + abstract LimitForXml getVendorLimits(); - @JsonIgnore - abstract Collection<LimitEntity> getLimits(); + @JsonIgnore + abstract Collection<LimitEntity> getLimits(); } 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 32ac6fb532..95dd28ada2 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,99 +17,105 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import org.openecomp.sdc.vendorlicense.dao.types.*; -import org.openecomp.sdc.vendorlicense.dao.types.xml.*; - import java.util.Collection; import java.util.Set; +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.LimitEntity; +import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope; +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; +import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml; +import org.openecomp.sdc.vendorlicense.dao.types.xml.OperationalScopeForXml; +import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml; public abstract class MixinEntitlementPoolEntityForVnfArtifact { - @JsonProperty(value = "threshold-value") - abstract ThresholdForXml getThresholdForArtifact(); - - @JsonProperty(value = "entitlement-pool-invariant-uuid") - abstract String getId(); - - @JsonProperty(value = "manufacturer-reference-number") - abstract String getManufacturerReferenceNumber(); - @JsonIgnore - abstract Set<String> getReferencingFeatureGroups(); + @JsonProperty(value = "threshold-value") + abstract ThresholdForXml getThresholdForArtifact(); - @JsonIgnore - abstract String getFirstClassCitizenId(); + @JsonProperty(value = "entitlement-pool-invariant-uuid") + abstract String getId(); - @JsonProperty(value = "entitlement-pool-uuid") - abstract String getVersionUuId(); + @JsonProperty(value = "manufacturer-reference-number") + abstract String getManufacturerReferenceNumber(); - @JsonIgnore - abstract String getVersion(); + @JsonIgnore + abstract Set<String> getReferencingFeatureGroups(); - @JsonProperty(value = "version") - abstract String getVersionForArtifact(); + @JsonIgnore + abstract String getFirstClassCitizenId(); - @JsonIgnore - abstract String getVendorLicenseModelId(); + @JsonProperty(value = "entitlement-pool-uuid") + abstract String getVersionUuId(); - @JsonIgnore - abstract String getThresholdUnit(); + @JsonIgnore + abstract String getVersion(); - @JsonIgnore - abstract float getThresholdValue(); + @JsonProperty(value = "version") + abstract String getVersionForArtifact(); - @JsonIgnore - abstract String getStartDate(); + @JsonIgnore + abstract String getVendorLicenseModelId(); - @JsonIgnore - abstract String getExpiryDate(); + @JsonIgnore + abstract String getThresholdUnit(); - @JsonProperty(value = "start-date") - abstract String getIsoFormatStartDate(); + @JsonIgnore + abstract float getThresholdValue(); - @JsonProperty(value = "expiry-date") - abstract String getIsoFormatExpiryDate(); + @JsonIgnore + abstract String getStartDate(); - @JsonIgnore - abstract ChoiceOrOther<EntitlementMetric> getEntitlementMetric(); + @JsonIgnore + abstract String getExpiryDate(); - @JsonIgnore - abstract ChoiceOrOther<EntitlementTime> getTime(); + @JsonProperty(value = "start-date") + abstract String getIsoFormatStartDate(); - @JsonIgnore - abstract ChoiceOrOther<AggregationFunction> getAggregationFunction(); + @JsonProperty(value = "expiry-date") + abstract String getIsoFormatExpiryDate(); - @JsonIgnore - abstract String getEntityType(); + @JsonIgnore + abstract ChoiceOrOther<EntitlementMetric> getEntitlementMetric(); - @JsonProperty(value = "operational-scope") - abstract OperationalScopeForXml getOperationalScopeForArtifact(); + @JsonIgnore + abstract ChoiceOrOther<EntitlementTime> getTime(); - @JsonIgnore - abstract ChoiceOrOther<OperationalScope> getOperationalScope(); + @JsonIgnore + abstract ChoiceOrOther<AggregationFunction> getAggregationFunction(); + @JsonIgnore + abstract String getEntityType(); - @JsonProperty(value = "entitlement-metric") - abstract EntitlementMetricForXml getEntitlementMetricForArtifact(); + @JsonProperty(value = "operational-scope") + abstract OperationalScopeForXml getOperationalScopeForArtifact(); - @JsonProperty(value = "time") - abstract EntitlementTimeForXml getTimeForArtifact(); + @JsonIgnore + abstract ChoiceOrOther<OperationalScope> getOperationalScope(); + @JsonProperty(value = "entitlement-metric") + abstract EntitlementMetricForXml getEntitlementMetricForArtifact(); - @JsonProperty(value = "aggregation-function") - abstract AggregationFunctionForXml getAggregationFunctionForArtifact(); + @JsonProperty(value = "time") + abstract EntitlementTimeForXml getTimeForArtifact(); - @JsonProperty(value = "sp-limits") - abstract LimitForXml getSPLimits(); + @JsonProperty(value = "aggregation-function") + abstract AggregationFunctionForXml getAggregationFunctionForArtifact(); - @JsonProperty(value = "vendor-limits") - abstract LimitForXml getVendorLimits(); + @JsonProperty(value = "sp-limits") + abstract LimitForXml getSPLimits(); - @JsonIgnore - abstract Collection<LimitEntity> getLimits(); + @JsonProperty(value = "vendor-limits") + abstract LimitForXml getVendorLimits(); + @JsonIgnore + abstract Collection<LimitEntity> getLimits(); } 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/MixinFeatureGroupEntity.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/MixinFeatureGroupEntity.java index 61751b111b..970290b25a 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/MixinFeatureGroupEntity.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/MixinFeatureGroupEntity.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,49 +17,44 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins; import com.fasterxml.jackson.annotation.JsonIgnore; -import org.openecomp.sdc.versioning.dao.types.Version; - import java.util.Set; +import org.openecomp.sdc.versioning.dao.types.Version; public abstract class MixinFeatureGroupEntity { - @JsonIgnore - abstract String getVendorLicenseModelId(); - - @JsonIgnore - abstract String getEntityType(); - - - @JsonIgnore - abstract Version getVersion(); + @JsonIgnore + abstract String getVendorLicenseModelId(); - @JsonIgnore - abstract String getId(); + @JsonIgnore + abstract String getEntityType(); - @JsonIgnore - abstract String getName(); + @JsonIgnore + abstract Version getVersion(); - @JsonIgnore - abstract String getDescription(); + @JsonIgnore + abstract String getId(); - @JsonIgnore - abstract String getPartNumber(); + @JsonIgnore + abstract String getName(); - @JsonIgnore - abstract String getManufacturerReferenceNumber(); + @JsonIgnore + abstract String getDescription(); - @JsonIgnore - abstract Set<String> getLicenseKeyGroupIds(); + @JsonIgnore + abstract String getPartNumber(); - @JsonIgnore - abstract Set<String> getEntitlementPoolIds(); + @JsonIgnore + abstract String getManufacturerReferenceNumber(); + @JsonIgnore + abstract Set<String> getLicenseKeyGroupIds(); - @JsonIgnore - abstract Set<String> getReferencingLicenseAgreements(); + @JsonIgnore + abstract Set<String> getEntitlementPoolIds(); + @JsonIgnore + abstract Set<String> getReferencingLicenseAgreements(); } 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 b8c45ba4c6..45feb365e5 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,48 +17,44 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import java.util.Set; import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity; -import java.util.Set; - public abstract class MixinFeatureGroupModel { - @JacksonXmlProperty(isAttribute = false, localName = "entitlement-pool") - @JacksonXmlElementWrapper(localName = "entitlement-pool-list") - abstract Set<EntitlementPoolEntity> getEntitlementPools(); - - @JacksonXmlProperty(isAttribute = false, localName = "license-key-group") - @JacksonXmlElementWrapper(localName = "license-key-group-list") - abstract Set<LicenseKeyGroupEntity> getLicenseKeyGroups(); - - @JacksonXmlProperty(isAttribute = false, localName = "part-number") - abstract String getEntityPartNumber(); - @JacksonXmlProperty(isAttribute = false, localName = "feature-group-uuid") - abstract String getEntityId(); + @JacksonXmlProperty(isAttribute = false, localName = "entitlement-pool") + @JacksonXmlElementWrapper(localName = "entitlement-pool-list") + abstract Set<EntitlementPoolEntity> getEntitlementPools(); - @JacksonXmlProperty(isAttribute = false, localName = "description") - abstract String getEntityDesc(); + @JacksonXmlProperty(isAttribute = false, localName = "license-key-group") + @JacksonXmlElementWrapper(localName = "license-key-group-list") + abstract Set<LicenseKeyGroupEntity> getLicenseKeyGroups(); - @JacksonXmlProperty(isAttribute = false, localName = "name") - abstract String getEntityName(); + @JacksonXmlProperty(isAttribute = false, localName = "part-number") + abstract String getEntityPartNumber(); + @JacksonXmlProperty(isAttribute = false, localName = "feature-group-uuid") + abstract String getEntityId(); - @JsonIgnore - abstract FeatureGroupEntity getFeatureGroup(); + @JacksonXmlProperty(isAttribute = false, localName = "description") + abstract String getEntityDesc(); - @JsonIgnore - abstract String getEntityType(); + @JacksonXmlProperty(isAttribute = false, localName = "name") + abstract String getEntityName(); - @JsonIgnore - abstract String getEntityManufacturerReferenceNumber(); + @JsonIgnore + abstract FeatureGroupEntity getFeatureGroup(); + @JsonIgnore + abstract String getEntityType(); + @JsonIgnore + abstract String getEntityManufacturerReferenceNumber(); } 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 eeaa7c0a3a..03bc6c83ad 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,11 +17,12 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Collection; +import java.util.Set; import org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther; import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity; import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope; @@ -30,74 +31,68 @@ import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml; import org.openecomp.sdc.vendorlicense.dao.types.xml.OperationalScopeForXml; import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml; -import java.util.Collection; -import java.util.Set; - public abstract class MixinLicenseKeyGroupEntityForVendorLicenseArtifact { - @JsonProperty(value = "license-key-group-uuid") - abstract String getVersionUuId(); - - @JsonIgnore - abstract Set<String> getReferencingFeatureGroups(); - - @JsonProperty(value = "version") - abstract String getVersionForArtifact(); - - @JsonIgnore - abstract String getVendorLicenseModelId(); + @JsonProperty(value = "license-key-group-uuid") + abstract String getVersionUuId(); - @JsonIgnore - abstract String getEntityType(); + @JsonIgnore + abstract Set<String> getReferencingFeatureGroups(); - @JsonIgnore - abstract String getFirstClassCitizenId(); + @JsonProperty(value = "version") + abstract String getVersionForArtifact(); - @JsonProperty(value = "license-key-group-invariant-uuid") - abstract String getId(); + @JsonIgnore + abstract String getVendorLicenseModelId(); + @JsonIgnore + abstract String getEntityType(); - @JsonIgnore - abstract ChoiceOrOther<OperationalScope> getOperationalScope(); + @JsonIgnore + abstract String getFirstClassCitizenId(); - @JsonProperty(value = "operational-scope") - abstract OperationalScopeForXml getOperationalScopeForArtifact(); + @JsonProperty(value = "license-key-group-invariant-uuid") + abstract String getId(); + @JsonIgnore + abstract ChoiceOrOther<OperationalScope> getOperationalScope(); - @JsonIgnore - abstract LicenseKeyTypeForXml getTypeForArtifact(); + @JsonProperty(value = "operational-scope") + abstract OperationalScopeForXml getOperationalScopeForArtifact(); - @JsonIgnore - abstract String getVersionableId(); + @JsonIgnore + abstract LicenseKeyTypeForXml getTypeForArtifact(); - @JsonProperty(value = "sp-limits") - abstract LimitForXml getSPLimits(); + @JsonIgnore + abstract String getVersionableId(); - @JsonProperty(value = "vendor-limits") - abstract LimitForXml getVendorLimits(); + @JsonProperty(value = "sp-limits") + abstract LimitForXml getSPLimits(); - @JsonIgnore - abstract Collection<LimitEntity> getLimits(); + @JsonProperty(value = "vendor-limits") + abstract LimitForXml getVendorLimits(); - @JsonIgnore - abstract String getStartDate(); + @JsonIgnore + abstract Collection<LimitEntity> getLimits(); - @JsonIgnore - abstract String getExpiryDate(); + @JsonIgnore + abstract String getStartDate(); - @JsonProperty(value = "start-date") - abstract String getIsoFormatStartDate(); + @JsonIgnore + abstract String getExpiryDate(); - @JsonProperty(value = "expiry-date") - abstract String getIsoFormatExpiryDate(); + @JsonProperty(value = "start-date") + abstract String getIsoFormatStartDate(); - @JsonProperty(value = "threshold-value") - abstract ThresholdForXml getThresholdForArtifact(); + @JsonProperty(value = "expiry-date") + abstract String getIsoFormatExpiryDate(); - @JsonIgnore - abstract String getThresholdUnits(); + @JsonProperty(value = "threshold-value") + abstract ThresholdForXml getThresholdForArtifact(); - @JsonIgnore - abstract float getThresholdValue(); + @JsonIgnore + abstract String getThresholdUnits(); + @JsonIgnore + abstract float getThresholdValue(); } 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 f560f363a1..c9e21806ce 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,11 +17,12 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Collection; +import java.util.Set; import org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther; import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity; import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope; @@ -30,78 +31,74 @@ import org.openecomp.sdc.vendorlicense.dao.types.xml.LimitForXml; import org.openecomp.sdc.vendorlicense.dao.types.xml.OperationalScopeForXml; import org.openecomp.sdc.vendorlicense.dao.types.xml.ThresholdForXml; -import java.util.Collection; -import java.util.Set; - public abstract class MixinLicenseKeyGroupEntityForVnfArtifact { - @JsonProperty(value = "license-key-group-invariant-uuid") - abstract String getId(); - - @JsonProperty(value = "manufacturer-reference-number") - abstract String getManufacturerReferenceNumber(); - @JsonIgnore - abstract Set<String> getReferencingFeatureGroups(); + @JsonProperty(value = "license-key-group-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 Set<String> getReferencingFeatureGroups(); - @JsonIgnore - abstract String getVendorLicenseModelId(); + @JsonIgnore + abstract String getVersion(); + @JsonProperty(value = "version") + abstract String getVersionForArtifact(); - @JsonIgnore - abstract String getEntityType(); + @JsonIgnore + abstract String getVendorLicenseModelId(); - @JsonProperty(value = "license-key-group-uuid") - abstract String getVersionUuId(); + @JsonIgnore + abstract String getEntityType(); - @JsonIgnore - abstract String getFirstClassCitizenId(); + @JsonProperty(value = "license-key-group-uuid") + abstract String getVersionUuId(); + @JsonIgnore + abstract String getFirstClassCitizenId(); - @JsonIgnore - abstract ChoiceOrOther<OperationalScope> getOperationalScope(); + @JsonIgnore + abstract ChoiceOrOther<OperationalScope> getOperationalScope(); - @JsonProperty(value = "operational-scope") - abstract OperationalScopeForXml getOperationalScopeForArtifact(); + @JsonProperty(value = "operational-scope") + abstract OperationalScopeForXml getOperationalScopeForArtifact(); + @JsonIgnore + abstract LicenseKeyTypeForXml getTypeForArtifact(); - @JsonIgnore - abstract LicenseKeyTypeForXml getTypeForArtifact(); + @JsonIgnore + abstract String getVersionableId(); - @JsonIgnore - abstract String getVersionableId(); + @JsonProperty(value = "threshold-value") + abstract ThresholdForXml getThresholdForArtifact(); - @JsonProperty(value = "threshold-value") - abstract ThresholdForXml getThresholdForArtifact(); - @JsonProperty(value = "sp-limits") - abstract LimitForXml getSPLimits(); + @JsonProperty(value = "sp-limits") + abstract LimitForXml getSPLimits(); - @JsonProperty(value = "vendor-limits") - abstract LimitForXml getVendorLimits(); + @JsonProperty(value = "vendor-limits") + abstract LimitForXml getVendorLimits(); - @JsonIgnore - abstract Collection<LimitEntity> getLimits(); + @JsonIgnore + abstract Collection<LimitEntity> getLimits(); - @JsonIgnore - abstract String getStartDate(); + @JsonIgnore + abstract String getStartDate(); - @JsonIgnore - abstract String getExpiryDate(); + @JsonIgnore + abstract String getExpiryDate(); - @JsonProperty(value = "start-date") - abstract String getIsoFormatStartDate(); + @JsonProperty(value = "start-date") + abstract String getIsoFormatStartDate(); - @JsonProperty(value = "expiry-date") - abstract String getIsoFormatExpiryDate(); + @JsonProperty(value = "expiry-date") + abstract String getIsoFormatExpiryDate(); - @JsonIgnore - abstract String getThresholdUnits(); + @JsonIgnore + abstract String getThresholdUnits(); - @JsonIgnore - abstract float getThresholdValue(); + @JsonIgnore + abstract float getThresholdValue(); } 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/MixinLimitArtifact.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/MixinLimitArtifact.java index 1a15a6e557..7627d5f243 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/MixinLimitArtifact.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/MixinLimitArtifact.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.mixins; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -27,16 +26,15 @@ import org.openecomp.sdc.vendorlicense.dao.types.xml.EntitlementTimeForXml; public abstract class MixinLimitArtifact { - @JsonIgnore - abstract String getTime(); - - @JsonIgnore - abstract String getAggregationFunction(); + @JsonIgnore + abstract String getTime(); - @JsonProperty(value = "aggregation-function") - abstract AggregationFunctionForXml getAggregationFunctionForArtifact(); + @JsonIgnore + abstract String getAggregationFunction(); - @JsonProperty(value = "time") - abstract EntitlementTimeForXml getTimeForArtifact(); + @JsonProperty(value = "aggregation-function") + abstract AggregationFunctionForXml getAggregationFunctionForArtifact(); + @JsonProperty(value = "time") + abstract EntitlementTimeForXml getTimeForArtifact(); } 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 index 7153f45d2f..7dbbad7b44 100644 --- 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 @@ -13,17 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util; - import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; - import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; import org.openecomp.sdc.vendorlicense.HealingServiceFactory; @@ -38,148 +35,116 @@ import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.openecomp.sdc.versioning.dao.types.VersionableEntity; - - /** * @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 - */ - private static MultiValuedMap<String, VersionableEntity> mapById( - Collection<? extends VersionableEntity> versionableEntities) { - MultiValuedMap<String, VersionableEntity> mappedById = new ArrayListValuedHashMap<>(); - for (VersionableEntity ve : versionableEntities) { - mappedById.put(ve.getId(), ve); + 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 + */ + private static MultiValuedMap<String, VersionableEntity> mapById(Collection<? extends VersionableEntity> versionableEntities) { + MultiValuedMap<String, VersionableEntity> mappedById = new ArrayListValuedHashMap<>(); + for (VersionableEntity ve : versionableEntities) { + mappedById.put(ve.getId(), ve); + } + return mappedById; } - 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 entities exists it will be returned - * - * @return a list of entities that has been changed - */ - public static List<VersionableEntity> filterChangedEntities( - Collection<? extends VersionableEntity> versionableEntities) { - MultiValuedMap<String, VersionableEntity> entitiesById = mapById( - versionableEntities); - MultiValuedMap<String, VersionableEntity> entitiesByVersionUuId = - new ArrayListValuedHashMap<>(); - List<VersionableEntity> changedOnly = new ArrayList<>(); - for (String epId : entitiesById.keySet()) { - Collection<VersionableEntity> versionableEntitiesForId = entitiesById.get(epId); - for (VersionableEntity ep : versionableEntitiesForId) { - entitiesByVersionUuId.put(ep.getVersionUuId(), ep); - } + /** + * 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 entities exists it will be returned + * + * @return a list of entities that has been changed + */ + public static List<VersionableEntity> filterChangedEntities(Collection<? extends VersionableEntity> versionableEntities) { + MultiValuedMap<String, VersionableEntity> entitiesById = mapById(versionableEntities); + MultiValuedMap<String, VersionableEntity> entitiesByVersionUuId = new ArrayListValuedHashMap<>(); + List<VersionableEntity> changedOnly = new ArrayList<>(); + for (String epId : entitiesById.keySet()) { + Collection<VersionableEntity> 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<VersionableEntity> versionableEntitiesForUuid = (List<VersionableEntity>) entitiesByVersionUuId.get(versionUid); + versionableEntitiesForUuid.sort(new VersionableEntitySortByVlmMajorVersion()); + changedOnly.add(versionableEntitiesForUuid.get(0)); + } + return changedOnly; } - //for every list of eps which have the same uuid, get the one with the earliest vlm version. - for (String versionUid : entitiesByVersionUuId.keySet()) { - List<VersionableEntity> versionableEntitiesForUuid = - (List<VersionableEntity>) entitiesByVersionUuId.get(versionUid); - versionableEntitiesForUuid.sort(new VersionableEntitySortByVlmMajorVersion()); - changedOnly.add(versionableEntitiesForUuid.get(0)); + public static Set<LicenseKeyGroupEntity> healLkgs(Collection<? extends VersionableEntity> licenseKeyGroupEntities) { + Set<LicenseKeyGroupEntity> healed = new HashSet<>(); + for (VersionableEntity licenseKeyGroupEntity : licenseKeyGroupEntities) { + healed.add((LicenseKeyGroupEntity) VendorLicenseArtifactsServiceImpl.healingService.heal(licenseKeyGroupEntity)); + } + return healed; } - return changedOnly; - } - - public static Set<LicenseKeyGroupEntity> healLkgs( - Collection<? extends VersionableEntity> licenseKeyGroupEntities) { - Set<LicenseKeyGroupEntity> healed = new HashSet<>(); - for (VersionableEntity licenseKeyGroupEntity : licenseKeyGroupEntities) { - healed.add((LicenseKeyGroupEntity) VendorLicenseArtifactsServiceImpl.healingService - .heal(licenseKeyGroupEntity)); + public static Set<EntitlementPoolEntity> healEPs(Collection<? extends VersionableEntity> entitlementPoolEntities) { + Set<EntitlementPoolEntity> healed = new HashSet<>(); + for (VersionableEntity entitlementPoolEntity : entitlementPoolEntities) { + healed.add((EntitlementPoolEntity) VendorLicenseArtifactsServiceImpl.healingService.heal(entitlementPoolEntity)); + } + return healed; } - return healed; - } - - public static Set<EntitlementPoolEntity> healEPs( - Collection<? extends VersionableEntity> entitlementPoolEntities) { - Set<EntitlementPoolEntity> healed = new HashSet<>(); - for (VersionableEntity entitlementPoolEntity : entitlementPoolEntities) { - healed.add((EntitlementPoolEntity) VendorLicenseArtifactsServiceImpl.healingService - .heal(entitlementPoolEntity)); + public static List<Version> getFinalVersionsForVlm(String vlmId) { + VersioningManager versioningManager = VersioningManagerFactory.getInstance().createInterface(); + return versioningManager.list(vlmId).stream().filter(version -> VersionStatus.Certified == version.getStatus()) + .map(certifiedVersion -> versioningManager.get(vlmId, certifiedVersion)) //sync to private + .collect(Collectors.toList()); } - return healed; - } - - public static List<Version> getFinalVersionsForVlm(String vlmId) { - VersioningManager versioningManager = VersioningManagerFactory.getInstance().createInterface(); - return versioningManager.list(vlmId).stream() - .filter(version -> VersionStatus.Certified == version.getStatus()) - .map(certifiedVersion -> versioningManager.get(vlmId, certifiedVersion)) //sync to private - .collect(Collectors.toList()); - } - - public static String getVendorName(String vendorLicenseModelId) { - return AsdcItemManagerFactory.getInstance().createInterface().get(vendorLicenseModelId) - .getName(); - } - - - /** - * Written to handle the consequences of ATTASDC-4780 where version_uuid was not saved or - * retrieved correctly by DAO for EPs and LKGs. Performs a healing of sorts according to the - * following : 1. all versions of a specific entity (EP or LKG that have the same invariant_uuid) - * are ordered by their VLM version 2. first element is sent to healing (which will set a - * versionUUID for it IF it doesnt exist) 3. each subsequent element is compared to previous . If - * same, UUID is copied from the previous element , if they differ - the current element is sent - * to healing as before. For VLMs created post-bugfix this code should not update any element - */ - public static Collection<? extends VersionableEntity> prepareForFiltering(Collection<? extends - VersionableEntity> versionableEntities, boolean isEP) { - MultiValuedMap<String, VersionableEntity> entitiesById = mapById( - versionableEntities); - - for (String epId : entitiesById.keySet()) { - List<VersionableEntity> versionableEntitiesForId = new ArrayList<>(); - versionableEntitiesForId.addAll(entitiesById.get(epId)); - versionableEntitiesForId.sort(new VersionableEntitySortByVlmMajorVersion()); - healingService.heal(versionableEntitiesForId.get(0)); - for (int i = 1; i < versionableEntitiesForId.size(); i++) { - if (isEP) { - EntitlementPoolEntity current = (EntitlementPoolEntity) versionableEntitiesForId.get(i); - EntitlementPoolEntity previous = (EntitlementPoolEntity) versionableEntitiesForId - .get(i - 1); - if (current.equals(previous) && current.getVersionUuId() == null) { - current.setVersionUuId(previous.getVersionUuId()); - healingService.persistNoHealing(current); - } else { - versionableEntitiesForId.set(i, healingService.heal(versionableEntitiesForId.get(i))); - } - - } else { - LicenseKeyGroupEntity current = (LicenseKeyGroupEntity) versionableEntitiesForId.get(i); - LicenseKeyGroupEntity previous = (LicenseKeyGroupEntity) versionableEntitiesForId - .get(i - 1); - if (current.equals(previous) && current.getVersionUuId() == null) { - current.setVersionUuId(previous.getVersionUuId()); - healingService.persistNoHealing(current); - } else { - versionableEntitiesForId.set(i, healingService.heal(versionableEntitiesForId.get(i))); - } - + public static String getVendorName(String vendorLicenseModelId) { + return AsdcItemManagerFactory.getInstance().createInterface().get(vendorLicenseModelId).getName(); + } + /** + * Written to handle the consequences of ATTASDC-4780 where version_uuid was not saved or retrieved correctly by DAO for EPs and LKGs. Performs a + * healing of sorts according to the following : 1. all versions of a specific entity (EP or LKG that have the same invariant_uuid) are ordered by + * their VLM version 2. first element is sent to healing (which will set a versionUUID for it IF it doesnt exist) 3. each subsequent element is + * compared to previous . If same, UUID is copied from the previous element , if they differ - the current element is sent to healing as before. + * For VLMs created post-bugfix this code should not update any element + */ + public static Collection<? extends VersionableEntity> prepareForFiltering(Collection<? extends VersionableEntity> versionableEntities, + boolean isEP) { + MultiValuedMap<String, VersionableEntity> entitiesById = mapById(versionableEntities); + for (String epId : entitiesById.keySet()) { + List<VersionableEntity> versionableEntitiesForId = new ArrayList<>(); + versionableEntitiesForId.addAll(entitiesById.get(epId)); + versionableEntitiesForId.sort(new VersionableEntitySortByVlmMajorVersion()); + healingService.heal(versionableEntitiesForId.get(0)); + for (int i = 1; i < versionableEntitiesForId.size(); i++) { + if (isEP) { + EntitlementPoolEntity current = (EntitlementPoolEntity) versionableEntitiesForId.get(i); + EntitlementPoolEntity previous = (EntitlementPoolEntity) versionableEntitiesForId.get(i - 1); + if (current.equals(previous) && current.getVersionUuId() == null) { + current.setVersionUuId(previous.getVersionUuId()); + healingService.persistNoHealing(current); + } else { + versionableEntitiesForId.set(i, healingService.heal(versionableEntitiesForId.get(i))); + } + } else { + LicenseKeyGroupEntity current = (LicenseKeyGroupEntity) versionableEntitiesForId.get(i); + LicenseKeyGroupEntity previous = (LicenseKeyGroupEntity) versionableEntitiesForId.get(i - 1); + if (current.equals(previous) && current.getVersionUuId() == null) { + current.setVersionUuId(previous.getVersionUuId()); + healingService.persistNoHealing(current); + } else { + versionableEntitiesForId.set(i, healingService.heal(versionableEntitiesForId.get(i))); + } + } + } } - } + return versionableEntities; } - return versionableEntities; - } - - } 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 index 1aee2dd97e..2626382479 100644 --- 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,22 +17,19 @@ * 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; +import org.openecomp.sdc.versioning.dao.types.VersionableEntity; /** * @author katyr * @since January 10, 2017 */ - public class VersionableEntitySortByVlmMajorVersion implements Comparator<VersionableEntity> { - @Override - public int compare(VersionableEntity o1, VersionableEntity o2) { - return Integer.compare(o1.getVersion().getMajor(), o2.getVersion().getMajor()); - } + @Override + public int compare(VersionableEntity o1, VersionableEntity o2) { + return Integer.compare(o1.getVersion().getMajor(), o2.getVersion().getMajor()); + } } |