diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao')
14 files changed, 871 insertions, 628 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/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 2568d719e2..dd22397760 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,8 +20,6 @@ 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; @@ -47,6 +45,8 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; +import static org.openecomp.core.utilities.CommonMethods.toSingleElementSet; + public class FeatureGroupCassandraDaoImpl extends CassandraBaseDao<FeatureGroupEntity> implements FeatureGroupDao { diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/EntitlementPoolZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/EntitlementPoolZusammenDaoImpl.java index b880c67cbc..35182a3502 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/EntitlementPoolZusammenDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/EntitlementPoolZusammenDaoImpl.java @@ -10,25 +10,20 @@ 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.datatypes.model.ElementType; import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToEntitlementPoolConvertor; import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; -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 org.openecomp.types.ElementPropertyName; 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. - */ +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; + public class EntitlementPoolZusammenDaoImpl implements EntitlementPoolDao { private ZusammenAdaptor zusammenAdaptor; @@ -48,18 +43,22 @@ public class EntitlementPoolZusammenDaoImpl implements EntitlementPoolDao { buildEntitlementPoolElement(entitlementPool, Action.CREATE); ZusammenElement entitlementPoolsElement = - VlmZusammenUtil.buildStructuralElement(StructureElement.EntitlementPools, null); + ZusammenUtil.buildStructuralElement(ElementType.EntitlementPools, Action.IGNORE); + + ZusammenElement limitsElement = + ZusammenUtil.buildStructuralElement(ElementType.Limits, Action.CREATE); + entitlementPoolElement.addSubElement(limitsElement); entitlementPoolsElement.addSubElement(entitlementPoolElement); SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(entitlementPool.getVendorLicenseModelId()); - Optional<Element> savedElement = zusammenAdaptor.saveElement(context, new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), + Element epsSavedElement = zusammenAdaptor.saveElement(context, + new ElementContext(entitlementPool.getVendorLicenseModelId(), + entitlementPool.getVersion().getId()), entitlementPoolsElement, "Create entitlement pool"); - savedElement.ifPresent(element -> entitlementPool - .setId(element.getSubElements().iterator().next().getElementId().getValue())); + entitlementPool + .setId(epsSavedElement.getSubElements().iterator().next().getElementId().getValue()); } @Override @@ -68,9 +67,8 @@ public class EntitlementPoolZusammenDaoImpl implements EntitlementPoolDao { buildEntitlementPoolElement(entitlementPool, Action.UPDATE); SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(entitlementPool.getVendorLicenseModelId()); - ElementContext elementContext = new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), + entitlementPool.getVersion().getId()); Optional<ElementInfo> epFromDb = zusammenAdaptor.getElementInfo(context, elementContext, new Id(entitlementPool.getId())); @@ -84,35 +82,33 @@ public class EntitlementPoolZusammenDaoImpl implements EntitlementPoolDao { } } - zusammenAdaptor.saveElement(context,elementContext, entitlmentpoolElement, + zusammenAdaptor.saveElement(context, elementContext, 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())); - + ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), + entitlementPool.getVersion().getId()); + ElementToEntitlementPoolConvertor convertor = new ElementToEntitlementPoolConvertor(); return zusammenAdaptor.getElementInfo(context, elementContext, new Id(entitlementPool.getId())) - .map(elementInfo -> mapElementInfoToEntitlementPool( - entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion(), elementInfo)) + .map(elementInfo -> { + EntitlementPoolEntity entity = convertor.convert(elementInfo); + entity.setVendorLicenseModelId(entitlementPool.getVendorLicenseModelId()); + entity.setVersion(entitlementPool.getVersion()); + return entity; + }) .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())); + ZusammenElement zusammenElement = buildElement(new Id(entitlementPool.getId()), Action.DELETE); - Id itemId = new Id(entitlementPool.getVendorLicenseModelId()); - ElementContext elementContext = - new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), + entitlementPool.getVersion().getId()); zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "delete entitlement pool. id:" + entitlementPool.getId() + "."); } @@ -120,28 +116,27 @@ public class EntitlementPoolZusammenDaoImpl implements EntitlementPoolDao { @Override public Collection<EntitlementPoolEntity> 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())); - + ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), + entitlementPool.getVersion().getId()); + ElementToEntitlementPoolConvertor convertor = new ElementToEntitlementPoolConvertor(); return zusammenAdaptor - .listElementsByName(context, elementContext, null, StructureElement.EntitlementPools.name()) - .stream().map(elementInfo -> mapElementInfoToEntitlementPool( - entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion(), elementInfo)) - .collect(Collectors.toList()); + .listElementsByName(context, elementContext, null, ElementType.EntitlementPools.name()) + .stream().map(elementInfo -> { + EntitlementPoolEntity entity = convertor.convert(elementInfo); + entity.setVendorLicenseModelId(entitlementPool.getVendorLicenseModelId()); + entity.setVersion(entitlementPool.getVersion()); + return entity; + }).collect(Collectors.toList()); } @Override public long count(EntitlementPoolEntity entitlementPool) { SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(entitlementPool.getVendorLicenseModelId()); - ElementContext elementContext = new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), - VlmZusammenUtil.getVersionTag(entitlementPool.getVersion())); + ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), + entitlementPool.getVersion().getId()); return zusammenAdaptor - .listElementsByName(context, elementContext, null, StructureElement.EntitlementPools.name()) + .listElementsByName(context, elementContext, null, ElementType.EntitlementPools.name()) .size(); } @@ -149,9 +144,8 @@ public class EntitlementPoolZusammenDaoImpl implements EntitlementPoolDao { 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)); + ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), + entitlementPool.getVersion().getId()); Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(entitlementPool.getId())); @@ -173,9 +167,8 @@ public class EntitlementPoolZusammenDaoImpl implements EntitlementPoolDao { 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)); + ElementContext elementContext = new ElementContext(entitlementPool.getVendorLicenseModelId(), + entitlementPool.getVersion().getId()); Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(entitlementPool.getId())); @@ -199,17 +192,32 @@ public class EntitlementPoolZusammenDaoImpl implements EntitlementPoolDao { //not supported } - private ZusammenElement buildEntitlementPoolElement(EntitlementPoolEntity entitlementPool, - Action action) { + @Override + public String getManufacturerReferenceNumber(EntitlementPoolEntity entitlementPoolEntity) { + SessionContext context = ZusammenUtil.createSessionContext(); + ElementContext elementContext = + new ElementContext(entitlementPoolEntity.getVendorLicenseModelId(), + entitlementPoolEntity.getVersion().getId()); - ZusammenElement entitlementPoolElement = new ZusammenElement(); - entitlementPoolElement.setAction(action); - if (entitlementPool.getId() != null) { - entitlementPoolElement.setElementId(new Id(entitlementPool.getId())); + Optional<ElementInfo> elementInfo1 = zusammenAdaptor + .getElementInfo(context, elementContext, new Id(entitlementPoolEntity.getId())); + Map<String, Object> properties = elementInfo1.get().getInfo().getProperties(); + String manufacturerReferenceNumber = null; + if (properties != null && properties.containsKey("manufacturerReferenceNumber")) { + manufacturerReferenceNumber = (String) properties.get("manufacturerReferenceNumber"); } + return manufacturerReferenceNumber; + } + + private ZusammenElement buildEntitlementPoolElement(EntitlementPoolEntity entitlementPool, + Action action) { + ZusammenElement entitlementPoolElement = + buildElement(entitlementPool.getId() == null ? null : new Id(entitlementPool.getId()), + action); Info info = new Info(); info.setName(entitlementPool.getName()); info.setDescription(entitlementPool.getDescription()); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.EntitlementPool); info.addProperty("version_uuid", entitlementPool.getVersionUuId()); info.addProperty("thresholdValue", entitlementPool.getThresholdValue()); info.addProperty("threshold_unit", entitlementPool.getThresholdUnit()); @@ -219,8 +227,8 @@ public class EntitlementPoolZusammenDaoImpl implements EntitlementPoolDao { info.addProperty("expiryDate", entitlementPool.getExpiryDate()); entitlementPoolElement.setInfo(info); - if (entitlementPool.getReferencingFeatureGroups() != null - && entitlementPool.getReferencingFeatureGroups().size() > 0) { + if (entitlementPool.getReferencingFeatureGroups() != null + && entitlementPool.getReferencingFeatureGroups().size() > 0) { entitlementPoolElement.setRelations(entitlementPool.getReferencingFeatureGroups().stream() .map(rel -> VlmZusammenUtil .createRelation(RelationType.EntitlmentPoolToReferencingFeatureGroup, rel)) @@ -229,62 +237,5 @@ public class EntitlementPoolZusammenDaoImpl implements EntitlementPoolDao { 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.setVersionUuId(elementInfo.getInfo().getProperty("version_uuid")); - entitlmentPool - .setThresholdValue(elementInfo.getInfo().getProperty("thresholdValue") != null - ? VlmZusammenUtil.toInteger(elementInfo.getInfo().getProperty("thresholdValue")) : null); - - Object threshold_unit = elementInfo.getInfo().getProperty("threshold_unit"); - entitlmentPool.setThresholdUnit( threshold_unit != null ? - ThresholdUnit.valueOf(elementInfo.getInfo().getProperty("threshold_unit")) : null); - entitlmentPool.setIncrements(elementInfo.getInfo().getProperty("increments")); - entitlmentPool.setOperationalScope(getOperationalScopeMultiChoiceOrOther( - elementInfo.getInfo().getProperty("operational_scope"))); - entitlmentPool.setStartDate(elementInfo.getInfo().getProperty("startDate")); - entitlmentPool.setExpiryDate(elementInfo.getInfo().getProperty("expiryDate")); - - 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 MultiChoiceOrOther<OperationalScope> getOperationalScopeMultiChoiceOrOther - (Map<String, Object> - operationalScope) { - if(operationalScope != null && !operationalScope.isEmpty()) { - Set<OperationalScope> choices = new HashSet<>(); - ((List<String>) operationalScope.get("choices")). - forEach(choice -> choices.add(OperationalScope.valueOf(choice))); - - return new MultiChoiceOrOther<>(choices, operationalScope.get("other")==null?null: - (String) operationalScope.get("other")); - } - return null; - } - - @Override - public String getManufacturerReferenceNumber(EntitlementPoolEntity entitlementPoolEntity){ - SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(entitlementPoolEntity.getVendorLicenseModelId()); - ElementContext elementContext = new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), - VlmZusammenUtil.getVersionTag(entitlementPoolEntity.getVersion())); - Optional<ElementInfo> elementInfo1 = zusammenAdaptor.getElementInfo(context, elementContext, new Id(entitlementPoolEntity.getId())); - Map<String, Object> properties = elementInfo1.get().getInfo().getProperties(); - String manufacturerReferenceNumber = null; - if(properties != null && properties.containsKey("manufacturerReferenceNumber") ) { - manufacturerReferenceNumber = (String)properties.get("manufacturerReferenceNumber"); - } - return manufacturerReferenceNumber; - } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/FeatureGroupDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/FeatureGroupDaoZusammenImpl.java index aa9e6c7ae0..8dcc964e7d 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/FeatureGroupDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/FeatureGroupDaoZusammenImpl.java @@ -10,21 +10,22 @@ 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.datatypes.model.ElementType; import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToFeatureGroupConvertor; import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; -import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.types.ElementPropertyName; 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. - */ +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + public class FeatureGroupDaoZusammenImpl implements FeatureGroupDao { private ZusammenAdaptor zusammenAdaptor; @@ -40,88 +41,86 @@ public class FeatureGroupDaoZusammenImpl implements FeatureGroupDao { @Override public void create(FeatureGroupEntity featureGroup) { - ZusammenElement featureGroupElement = - buildFeatureGroupElement(featureGroup, Action.CREATE); + ZusammenElement featureGroupElement = buildFeatureGroupElement(featureGroup, Action.CREATE); ZusammenElement featureGroupsElement = - VlmZusammenUtil.buildStructuralElement(StructureElement.FeatureGroups, null); + buildStructuralElement(ElementType.FeatureGroups, Action.IGNORE); featureGroupsElement.addSubElement(featureGroupElement); - SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(featureGroup.getVendorLicenseModelId()); - Optional<Element> savedElement = zusammenAdaptor.saveElement(context, new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), - featureGroupsElement, "Create feature group"); + SessionContext context = createSessionContext(); + Element featureGroupsSavedElement = zusammenAdaptor.saveElement(context, + new ElementContext(featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion().getId()), featureGroupsElement, "Create feature group"); - savedElement.ifPresent(element -> featureGroup - .setId(element.getSubElements().iterator().next().getElementId().getValue())); + featureGroup.setId( + featureGroupsSavedElement.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, + SessionContext context = createSessionContext(); + zusammenAdaptor.saveElement(context, new ElementContext(featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion().getId()), featureGroupElement, String.format("Update feature group with id %s", featureGroup.getId())); } @Override public FeatureGroupEntity get(FeatureGroupEntity featureGroup) { - SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(featureGroup.getVendorLicenseModelId()); - ElementContext elementContext = new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), - VlmZusammenUtil.getVersionTag(featureGroup.getVersion())); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion().getId()); return zusammenAdaptor.getElementInfo(context, elementContext, new Id(featureGroup.getId())) - .map(elementInfo -> mapElementInfoToFeatureGroup( - featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(), elementInfo)) + .map(elementInfo -> { + FeatureGroupEntity entity = new ElementToFeatureGroupConvertor().convert(elementInfo); + entity.setVendorLicenseModelId(featureGroup.getVendorLicenseModelId()); + entity.setVersion(featureGroup.getVersion()); + return entity; + }) .orElse(null); } @Override public void delete(FeatureGroupEntity featureGroup) { - 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)); + ZusammenElement zusammenElement = buildElement(new Id(featureGroup.getId()), Action.DELETE); + + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion().getId()); zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "delete feature group. id:" + featureGroup.getId() + "."); } @Override public Collection<FeatureGroupEntity> list(FeatureGroupEntity featureGroup) { - SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(featureGroup.getVendorLicenseModelId()); - ElementContext elementContext = new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), - VlmZusammenUtil.getVersionTag(featureGroup.getVersion())); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion().getId()); + ElementToFeatureGroupConvertor convertor = new ElementToFeatureGroupConvertor(); return zusammenAdaptor - .listElementsByName(context, elementContext, null, StructureElement.FeatureGroups.name()) - .stream().map(elementInfo -> mapElementInfoToFeatureGroup( - featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(), elementInfo)) + .listElementsByName(context, elementContext, null, ElementType.FeatureGroups.name()) + .stream().map(elementInfo -> { + FeatureGroupEntity entity = convertor.convert( + elementInfo); + entity.setVendorLicenseModelId(featureGroup.getVendorLicenseModelId()); + entity.setVersion(featureGroup.getVersion()); + return entity; + }) .collect(Collectors.toList()); } @Override public long count(FeatureGroupEntity featureGroup) { - SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(featureGroup.getVendorLicenseModelId()); - ElementContext elementContext = new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), - VlmZusammenUtil.getVersionTag(featureGroup.getVersion())); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion().getId()); return zusammenAdaptor - .listElementsByName(context, elementContext, null, StructureElement.FeatureGroups.name()) + .listElementsByName(context, elementContext, null, ElementType.FeatureGroups.name()) .size(); } @@ -138,10 +137,9 @@ public class FeatureGroupDaoZusammenImpl implements FeatureGroupDao { 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)); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion().getId()); Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(featureGroup.getId())); @@ -158,25 +156,23 @@ public class FeatureGroupDaoZusammenImpl implements FeatureGroupDao { } @Override - public void updateFeatureGroup(FeatureGroupEntity - featureGroup, Set<String> addedEntitlementPools, + public void updateFeatureGroup(FeatureGroupEntity featureGroup, + Set<String> addedEntitlementPools, Set<String> removedEntitlementPools, Set<String> addedLicenseKeyGroups, Set<String> removedLicenseKeyGroups) { ZusammenElement featureGroupElement = buildFeatureGroupElement(featureGroup, Action.UPDATE); - SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(featureGroup.getVendorLicenseModelId()); - ElementContext elementContext = new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); - + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion().getId()); + ElementToFeatureGroupConvertor convertor = new ElementToFeatureGroupConvertor(); Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(featureGroup.getId())); if (elementInfo.isPresent()) { - FeatureGroupEntity currentFeatureGroup = - mapElementInfoToFeatureGroup(featureGroup.getId(), featureGroup.getVersion(), - elementInfo.get()); - - if (!(removedEntitlementPools == null )) { + FeatureGroupEntity currentFeatureGroup = convertor.convert(elementInfo.get()); + currentFeatureGroup.setVendorLicenseModelId(featureGroup.getVendorLicenseModelId()); + currentFeatureGroup.setVersion(featureGroup.getVersion()); + if (!(removedEntitlementPools == null)) { currentFeatureGroup.getEntitlementPoolIds().removeAll(removedEntitlementPools); } if (!(addedEntitlementPools == null)) { @@ -192,22 +188,24 @@ public class FeatureGroupDaoZusammenImpl implements FeatureGroupDao { .createRelation(RelationType.FeatureGroupToEntitlmentPool, relation)) .collect(Collectors.toList())); - if (! ( removedLicenseKeyGroups == null)) { + if (!(removedLicenseKeyGroups == null)) { currentFeatureGroup.getLicenseKeyGroupIds().removeAll(removedLicenseKeyGroups); } - if (! ( addedLicenseKeyGroups == null)) { + if (!(addedLicenseKeyGroups == null)) { currentFeatureGroup.getLicenseKeyGroupIds().addAll(addedLicenseKeyGroups); } + featureGroupElement.getRelations() .addAll(currentFeatureGroup.getLicenseKeyGroupIds().stream() .map(relation -> VlmZusammenUtil .createRelation(RelationType.FeatureGroupToLicenseKeyGroup, relation)) .collect(Collectors.toList())); - Collection<Relation> LaRelations = elementInfo.get().getRelations().stream().filter - (rel->rel.getType().equals(RelationType.FeatureGroupToReferencingLicenseAgreement.name())) - .map(rel ->VlmZusammenUtil.createRelation(RelationType - .FeatureGroupToReferencingLicenseAgreement,rel.getEdge2().getElementId().toString())) + Collection<Relation> LaRelations = elementInfo.get().getRelations().stream().filter + (rel -> rel.getType() + .equals(RelationType.FeatureGroupToReferencingLicenseAgreement.name())) + .map(rel -> VlmZusammenUtil.createRelation(RelationType + .FeatureGroupToReferencingLicenseAgreement, rel.getEdge2().getElementId().toString())) .collect(Collectors.toList()); featureGroupElement.getRelations().addAll(LaRelations); @@ -226,10 +224,9 @@ public class FeatureGroupDaoZusammenImpl implements FeatureGroupDao { @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)); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion().getId()); Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(featureGroup.getId())); @@ -247,10 +244,9 @@ public class FeatureGroupDaoZusammenImpl implements FeatureGroupDao { @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)); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion().getId()); Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(featureGroup.getId())); @@ -268,15 +264,12 @@ public class FeatureGroupDaoZusammenImpl implements FeatureGroupDao { } private ZusammenElement buildFeatureGroupElement(FeatureGroupEntity featureGroup, Action action) { - - ZusammenElement featureGroupElement = new ZusammenElement(); - featureGroupElement.setAction(action); - if (featureGroup.getId() != null) { - featureGroupElement.setElementId(new Id(featureGroup.getId())); - } + ZusammenElement featureGroupElement = + buildElement(featureGroup.getId() == null ? null : new Id(featureGroup.getId()), action); Info info = new Info(); info.setName(featureGroup.getName()); info.setDescription(featureGroup.getDescription()); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.FeatureGroup); info.addProperty("partNumber", featureGroup.getPartNumber()); info.addProperty("manufacturerReferenceNumber", featureGroup.getManufacturerReferenceNumber()); featureGroupElement.setInfo(info); @@ -310,39 +303,5 @@ public class FeatureGroupDaoZusammenImpl implements FeatureGroupDao { .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")); - featureGroup.setManufacturerReferenceNumber(elementInfo.getInfo() - .getProperty("manufacturerReferenceNumber")); - - Set<String> entitlementPoolIds = new HashSet<>(); - Set<String> licenseAgreements = new HashSet<>(); - Set<String> 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 index 45c831fbd7..0fbac66b58 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseAgreementDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseAgreementDaoZusammenImpl.java @@ -29,19 +29,21 @@ 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.datatypes.model.ElementType; import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao; -import org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToLicenseAgreementConvertor; 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 org.openecomp.types.ElementPropertyName; import java.util.Collection; -import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + public class LicenseAgreementDaoZusammenImpl implements LicenseAgreementDao { @@ -61,16 +63,17 @@ public class LicenseAgreementDaoZusammenImpl implements LicenseAgreementDao { ZusammenElement licenseAgreementElement = buildLicenseAgreementElement(licenseAgreement, Action.CREATE); ZusammenElement licenseAgreementsElement = - VlmZusammenUtil.buildStructuralElement(StructureElement.LicenseAgreements, null); + buildStructuralElement(ElementType.LicenseAgreements, Action.IGNORE); licenseAgreementsElement.addSubElement(licenseAgreementElement); - SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(licenseAgreement.getVendorLicenseModelId()); - Optional<Element> 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())); + SessionContext context = createSessionContext(); + Element licenseAgreementsSavedElement = zusammenAdaptor.saveElement(context, + new ElementContext(licenseAgreement.getVendorLicenseModelId(), + licenseAgreement.getVersion().getId()), licenseAgreementsElement, + "Create license agreement"); + licenseAgreement + .setId(licenseAgreementsSavedElement.getSubElements().iterator().next().getElementId() + .getValue()); } @Override @@ -78,38 +81,36 @@ public class LicenseAgreementDaoZusammenImpl implements LicenseAgreementDao { 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, + SessionContext context = createSessionContext(); + zusammenAdaptor.saveElement(context, + new ElementContext(licenseAgreement.getVendorLicenseModelId(), + licenseAgreement.getVersion().getId()), licenseAgreementElement, String.format("Update license agreement with id %s", licenseAgreement.getId())); } @Override public LicenseAgreementEntity get(LicenseAgreementEntity licenseAgreement) { - SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(licenseAgreement.getVendorLicenseModelId()); - ElementContext elementContext = new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), - VlmZusammenUtil.getVersionTag(licenseAgreement.getVersion())); - + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), + licenseAgreement.getVersion().getId()); + ElementToLicenseAgreementConvertor convertor = new ElementToLicenseAgreementConvertor(); return zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseAgreement.getId())) - .map(elementInfo -> mapElementInfoToLicenseAgreement( - licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion(), elementInfo)) + .map(elementInfo -> { + LicenseAgreementEntity entity = convertor.convert(elementInfo); + entity.setVendorLicenseModelId(licenseAgreement.getVendorLicenseModelId()); + entity.setVersion(licenseAgreement.getVersion()); + return entity; + }) .orElse(null); } @Override public void delete(LicenseAgreementEntity licenseAgreement) { - 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)); + ZusammenElement zusammenElement = buildElement(new Id(licenseAgreement.getId()), Action.DELETE); + + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), + licenseAgreement.getVersion().getId()); zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "delete license agreement. id:" + licenseAgreement.getId() + "."); } @@ -117,30 +118,30 @@ public class LicenseAgreementDaoZusammenImpl implements LicenseAgreementDao { @Override public Collection<LicenseAgreementEntity> 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())); - + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), + licenseAgreement.getVersion().getId()); + ElementToLicenseAgreementConvertor convertor = new ElementToLicenseAgreementConvertor(); return zusammenAdaptor .listElementsByName(context, elementContext, null, - StructureElement.LicenseAgreements.name()) - .stream().map(elementInfo -> mapElementInfoToLicenseAgreement( - licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion(), elementInfo)) + ElementType.LicenseAgreements.name()) + .stream().map(elementInfo -> { + LicenseAgreementEntity entity = convertor.convert(elementInfo); + entity.setVendorLicenseModelId(licenseAgreement.getVendorLicenseModelId()); + entity.setVersion(licenseAgreement.getVersion()); + return entity; + }) .collect(Collectors.toList()); } @Override public 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())); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), + licenseAgreement.getVersion().getId()); return zusammenAdaptor.listElementsByName(context, elementContext, null, - StructureElement.LicenseAgreements.name()) + ElementType.LicenseAgreements.name()) .size(); } @@ -151,10 +152,9 @@ public class LicenseAgreementDaoZusammenImpl implements LicenseAgreementDao { @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)); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), + licenseAgreement.getVersion().getId()); Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseAgreement.getId())); @@ -175,23 +175,22 @@ public class LicenseAgreementDaoZusammenImpl implements LicenseAgreementDao { 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)); - + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseAgreement.getVendorLicenseModelId(), + licenseAgreement.getVersion().getId()); + ElementToLicenseAgreementConvertor convertor = new ElementToLicenseAgreementConvertor(); Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseAgreement.getId())); if (elementInfo.isPresent()) { LicenseAgreementEntity currentLicenseAgreement = - mapElementInfoToLicenseAgreement(licenseAgreement.getId(), licenseAgreement.getVersion(), - elementInfo.get()); - - if (! (removedFeatureGroupIds == null) ) { + convertor.convert(elementInfo.get()); + currentLicenseAgreement.setVendorLicenseModelId(licenseAgreement.getVendorLicenseModelId()); + currentLicenseAgreement.setVersion(licenseAgreement.getVersion()); + if (!(removedFeatureGroupIds == null)) { currentLicenseAgreement.getFeatureGroupIds().removeAll(removedFeatureGroupIds); } - if (! (addedFeatureGroupIds == null)) { + if (!(addedFeatureGroupIds == null)) { currentLicenseAgreement.getFeatureGroupIds().addAll(addedFeatureGroupIds); } licenseAgreementElement.setRelations(currentLicenseAgreement.getFeatureGroupIds().stream() @@ -203,41 +202,15 @@ public class LicenseAgreementDaoZusammenImpl implements LicenseAgreementDao { } } - 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<LicenseTerm> 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())); - } + ZusammenElement licenseAgreementElement = + buildElement(licenseAgreement.getId() == null ? null : new Id(licenseAgreement.getId()), + action); Info info = new Info(); info.setName(licenseAgreement.getName()); info.setDescription(licenseAgreement.getDescription()); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.LicenseAgreement); info.addProperty("licenseTerm", licenseAgreement.getLicenseTerm()); info.addProperty("requirementsAndConstrains", licenseAgreement.getRequirementsAndConstrains()); licenseAgreementElement.setInfo(info); diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseKeyGroupZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseKeyGroupZusammenDaoImpl.java index 976db94f39..4e7aee377a 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseKeyGroupZusammenDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LicenseKeyGroupZusammenDaoImpl.java @@ -9,27 +9,22 @@ 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.datatypes.model.ElementType; import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToLicenseKeyGroupConvertor; import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity; -import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType; -import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther; -import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope; -import org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit; -import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.types.ElementPropertyName; 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. - */ +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + + public class LicenseKeyGroupZusammenDaoImpl implements LicenseKeyGroupDao { private ZusammenAdaptor zusammenAdaptor; @@ -47,18 +42,20 @@ public class LicenseKeyGroupZusammenDaoImpl implements LicenseKeyGroupDao { ZusammenElement licenseKeyGroupElement = buildLicenseKeyGroupElement(licenseKeyGroup, Action.CREATE); + ZusammenElement limitsElement = buildStructuralElement(ElementType.Limits, Action.CREATE); + licenseKeyGroupElement.addSubElement(limitsElement); + ZusammenElement lkgsElement = - VlmZusammenUtil.buildStructuralElement(StructureElement.LicenseKeyGroups, null); + buildStructuralElement(ElementType.LicenseKeyGroups, Action.IGNORE); lkgsElement.addSubElement(licenseKeyGroupElement); - SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(licenseKeyGroup.getVendorLicenseModelId()); - Optional<Element> savedElement = zusammenAdaptor.saveElement(context, new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)), - lkgsElement, "Create license Key Group"); + SessionContext context = createSessionContext(); + Element lkgsSavedElement = zusammenAdaptor.saveElement(context, + new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), + licenseKeyGroup.getVersion().getId()), lkgsElement, "Create license Key Group"); - savedElement.ifPresent(element -> licenseKeyGroup - .setId(element.getSubElements().iterator().next().getElementId().getValue())); + licenseKeyGroup + .setId(lkgsSavedElement.getSubElements().iterator().next().getElementId().getValue()); } @Override @@ -66,55 +63,50 @@ public class LicenseKeyGroupZusammenDaoImpl implements LicenseKeyGroupDao { ZusammenElement licenseKeyGroupElement = buildLicenseKeyGroupElement(licenseKeyGroup, Action.UPDATE); - SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(licenseKeyGroup.getVendorLicenseModelId()); - - ElementContext elementContext = new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), + licenseKeyGroup.getVersion().getId()); Optional<ElementInfo> lkgFromDb = zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseKeyGroup.getId())); - if(lkgFromDb.isPresent()) { + if (lkgFromDb.isPresent()) { - if( licenseKeyGroupElement.getRelations() == null) { - licenseKeyGroupElement.setRelations(new ArrayList<>()); + if (licenseKeyGroupElement.getRelations() == null) { + licenseKeyGroupElement.setRelations(new ArrayList<>()); } if (lkgFromDb.get().getRelations() != null && lkgFromDb.get().getRelations().size() > 0) { licenseKeyGroupElement.getRelations().addAll(lkgFromDb.get().getRelations()); } } - - zusammenAdaptor.saveElement(context, elementContext, - licenseKeyGroupElement, + zusammenAdaptor.saveElement(context, elementContext, licenseKeyGroupElement, 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())); - + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), + licenseKeyGroup.getVersion().getId()); + ElementToLicenseKeyGroupConvertor convertor = new ElementToLicenseKeyGroupConvertor(); return zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseKeyGroup.getId())) - .map(elementInfo -> mapElementInfoToLicenseKeyGroup( - licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion(), elementInfo)) + .map(elementInfo -> { + LicenseKeyGroupEntity entity = convertor.convert(elementInfo); + entity.setVendorLicenseModelId(licenseKeyGroup.getVendorLicenseModelId()); + entity.setVersion(licenseKeyGroup.getVersion()); + return entity; + }) .orElse(null); } @Override public void delete(LicenseKeyGroupEntity licenseKeyGroup) { - SessionContext context = ZusammenUtil.createSessionContext(); - ZusammenElement zusammenElement = new ZusammenElement(); - zusammenElement.setAction(Action.DELETE); - zusammenElement.setElementId(new Id(licenseKeyGroup.getId())); + ZusammenElement zusammenElement = buildElement(new Id(licenseKeyGroup.getId()), Action.DELETE); - Id itemId = new Id(licenseKeyGroup.getVendorLicenseModelId()); - ElementContext elementContext = new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), + licenseKeyGroup.getVersion().getId()); zusammenAdaptor.saveElement(context, elementContext, zusammenElement, "delete license key group. id:" + licenseKeyGroup.getId() + "."); @@ -122,29 +114,29 @@ public class LicenseKeyGroupZusammenDaoImpl implements LicenseKeyGroupDao { @Override public Collection<LicenseKeyGroupEntity> 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())); - + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), + licenseKeyGroup.getVersion().getId()); + ElementToLicenseKeyGroupConvertor convertor = new ElementToLicenseKeyGroupConvertor(); return zusammenAdaptor - .listElementsByName(context, elementContext, null, StructureElement.LicenseKeyGroups.name()) - .stream().map(elementInfo -> mapElementInfoToLicenseKeyGroup( - licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion(), elementInfo)) + .listElementsByName(context, elementContext, null, ElementType.LicenseKeyGroups.name()) + .stream().map(elementInfo -> { + LicenseKeyGroupEntity entity = convertor.convert(elementInfo); + entity.setVendorLicenseModelId(licenseKeyGroup.getVendorLicenseModelId()); + entity.setVersion(licenseKeyGroup.getVersion()); + return entity; + }) .collect(Collectors.toList()); } @Override public long count(LicenseKeyGroupEntity licenseKeyGroup) { - SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(licenseKeyGroup.getVendorLicenseModelId()); - ElementContext elementContext = new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), - VlmZusammenUtil.getVersionTag(licenseKeyGroup.getVersion())); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), + licenseKeyGroup.getVersion().getId()); return zusammenAdaptor - .listElementsByName(context, elementContext, null, StructureElement.LicenseKeyGroups.name()) + .listElementsByName(context, elementContext, null, ElementType.LicenseKeyGroups.name()) .size(); } @@ -156,10 +148,9 @@ public class LicenseKeyGroupZusammenDaoImpl implements LicenseKeyGroupDao { @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)); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), + licenseKeyGroup.getVersion().getId()); Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseKeyGroup.getId())); @@ -180,10 +171,9 @@ public class LicenseKeyGroupZusammenDaoImpl implements LicenseKeyGroupDao { @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)); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(licenseKeyGroup.getVendorLicenseModelId(), + licenseKeyGroup.getVersion().getId()); Optional<ElementInfo> elementInfo = zusammenAdaptor.getElementInfo(context, elementContext, new Id(licenseKeyGroup.getId())); @@ -204,18 +194,15 @@ public class LicenseKeyGroupZusammenDaoImpl implements LicenseKeyGroupDao { private ZusammenElement buildLicenseKeyGroupElement(LicenseKeyGroupEntity licenseKeyGroup, Action action) { - - ZusammenElement lkgElement = new ZusammenElement(); - lkgElement.setAction(action); - if (licenseKeyGroup.getId() != null) { - lkgElement.setElementId(new Id(licenseKeyGroup.getId())); - } + ZusammenElement lkgElement = + buildElement(licenseKeyGroup.getId() == null ? null : new Id(licenseKeyGroup.getId()), + action); Info info = new Info(); info.setName(licenseKeyGroup.getName()); info.setDescription(licenseKeyGroup.getDescription()); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.LicenseKeyGroup); info.addProperty("version_uuid", licenseKeyGroup.getVersionUuId()); info.addProperty("LicenseKeyType", licenseKeyGroup.getType()); - info.addProperty("version_uuid", licenseKeyGroup.getVersionUuId()); info.addProperty("operational_scope", licenseKeyGroup.getOperationalScope()); info.addProperty("startDate", licenseKeyGroup.getStartDate()); info.addProperty("expiryDate", licenseKeyGroup.getExpiryDate()); @@ -224,70 +211,15 @@ public class LicenseKeyGroupZusammenDaoImpl implements LicenseKeyGroupDao { info.addProperty("increments", licenseKeyGroup.getIncrements()); lkgElement.setInfo(info); - if (licenseKeyGroup.getReferencingFeatureGroups() != null - && licenseKeyGroup.getReferencingFeatureGroups().size() > 0) { + 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.setVersionUuId(elementInfo.getInfo().getProperty("version_uuid")); - licenseKeyGroup - .setType(LicenseKeyType.valueOf(elementInfo.getInfo().getProperty("LicenseKeyType"))); - licenseKeyGroup.setVersionUuId(elementInfo.getInfo().getProperty("version_uuid")); - licenseKeyGroup.setOperationalScope(getOperationalScopeMultiChoiceOrOther( - elementInfo.getInfo().getProperty("operational_scope"))); - licenseKeyGroup.setStartDate(elementInfo.getInfo().getProperty("startDate")); - licenseKeyGroup.setExpiryDate(elementInfo.getInfo().getProperty("expiryDate")); - if (elementInfo.getInfo().getProperty("thresholdUnits") != null ){ - licenseKeyGroup.setThresholdUnits(ThresholdUnit.valueOf(elementInfo - .getInfo().getProperty("thresholdUnits"))); - } - if (elementInfo.getInfo().getProperty("thresholdValue") != null ){ - licenseKeyGroup.setThresholdValue(toInteger(elementInfo.getInfo().getProperty - ("thresholdValue"))); - } - licenseKeyGroup.setIncrements(elementInfo.getInfo().getProperty("increments")); - - 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<OperationalScope> getOperationalScopeMultiChoiceOrOther - (Map<String, Object> - operationalScope) { - if(operationalScope != null && !operationalScope.isEmpty()) { - Set<OperationalScope> choices = new HashSet<>(); - ((List<String>) operationalScope.get("choices")) - .forEach(choice -> choices.add(OperationalScope.valueOf(choice))); - - return new MultiChoiceOrOther<>(choices, operationalScope.get("other")==null?null:(String) operationalScope.get("other")); - } - return null; - } - - 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/LimitZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LimitZusammenDaoImpl.java index 78c26c83d3..7b19236409 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LimitZusammenDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/LimitZusammenDaoImpl.java @@ -9,26 +9,30 @@ 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.datatypes.model.ElementType; import org.openecomp.sdc.vendorlicense.dao.LimitDao; import org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction; import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity; import org.openecomp.sdc.vendorlicense.dao.types.LimitType; import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.types.ElementPropertyName; import java.util.Collection; import java.util.Collections; -import java.util.Optional; import java.util.stream.Collectors; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + public class LimitZusammenDaoImpl implements LimitDao { - public static final String LIMT_TYPE = "type"; - public static final String METRIC = "metric"; - public static final String AGGREGATIONFUNCTION = "aggregationfunction"; - public static final String TIME = "time"; - public static final String UNIT = "unit"; - public static final String VALUE = "value"; + private static final String LIMT_TYPE = "type"; + private static final String METRIC = "metric"; + private static final String AGGREGATIONFUNCTION = "aggregationfunction"; + private static final String TIME = "time"; + private static final String UNIT = "unit"; + private static final String VALUE = "value"; private ZusammenAdaptor zusammenAdaptor; public LimitZusammenDaoImpl(ZusammenAdaptor zusammenAdaptor) { @@ -39,36 +43,30 @@ public class LimitZusammenDaoImpl implements LimitDao { public void create(LimitEntity limitEntity) { ZusammenElement limitElement = limitToZusammen(limitEntity, Action.CREATE); - ZusammenElement limitsElement = - VlmZusammenUtil.buildStructuralElement(StructureElement.Limits, null); + ZusammenElement limitsElement = buildStructuralElement(ElementType.Limits, null); limitsElement.setSubElements(Collections.singletonList(limitElement)); - ZusammenElement epLkgElement = - buildZusammenElement(new Id(limitEntity.getEpLkgId()), Action.IGNORE); + ZusammenElement epLkgElement = buildElement(new Id(limitEntity.getEpLkgId()), Action.IGNORE); epLkgElement.setSubElements(Collections.singletonList(limitsElement)); - SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(limitEntity.getVendorLicenseModelId()); - ElementContext elementContext = new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + SessionContext context = createSessionContext(); + ElementContext elementContext = + new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); - Optional<Element> savedElement = + Element savedElement = zusammenAdaptor.saveElement(context, elementContext, epLkgElement, "Create limit"); - savedElement.ifPresent(element -> - limitEntity.setId(element.getSubElements().iterator().next() - .getSubElements().iterator().next().getElementId().getValue())); + limitEntity.setId(savedElement.getSubElements().iterator().next() + .getSubElements().iterator().next().getElementId().getValue()); } @Override public boolean isLimitPresent(LimitEntity limitEntity) { - SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(limitEntity.getVendorLicenseModelId()); - ElementContext elementContext = new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), - VlmZusammenUtil.getVersionTag(limitEntity.getVersion())); + SessionContext context = createSessionContext(); + ElementContext elementContext = + new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); Collection<ElementInfo> elementInfos = zusammenAdaptor.listElementsByName(context, - elementContext, new Id(limitEntity.getEpLkgId()),StructureElement.Limits.name()); + elementContext, new Id(limitEntity.getEpLkgId()), ElementType.Limits.name()); for (ElementInfo elementInfo : elementInfos) { if (elementInfo.getId().getValue().equals(limitEntity.getId())) { @@ -81,20 +79,18 @@ public class LimitZusammenDaoImpl implements LimitDao { @Override public Collection<LimitEntity> list(LimitEntity limitEntity) { - SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(limitEntity.getVendorLicenseModelId()); - ElementContext elementContext = new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), - VlmZusammenUtil.getVersionTag(limitEntity.getVersion())); + SessionContext context = createSessionContext(); + ElementContext elementContext = + new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); return listLimits(context, elementContext, limitEntity); } private Collection<LimitEntity> listLimits(SessionContext context, ElementContext elementContext, - LimitEntity limitEntity) { + LimitEntity limitEntity) { return zusammenAdaptor .listElementsByName(context, elementContext, new Id(limitEntity.getEpLkgId()), - StructureElement.Limits.name()) + ElementType.Limits.name()) .stream().map(elementInfo -> mapElementInfoToLimit( limitEntity.getVendorLicenseModelId(), limitEntity.getVersion(), limitEntity.getEpLkgId(), elementInfo)) @@ -102,18 +98,18 @@ public class LimitZusammenDaoImpl implements LimitDao { } private LimitEntity mapElementInfoToLimit(String vlmId, Version version, - String epLkgId, ElementInfo elementInfo) { + String epLkgId, ElementInfo elementInfo) { LimitEntity limitEntity = new LimitEntity(vlmId, version, epLkgId, elementInfo.getId().getValue()); limitEntity.setName(elementInfo.getInfo().getName()); limitEntity.setDescription(elementInfo.getInfo().getDescription()); - limitEntity.setType( elementInfo.getInfo().getProperties().get(LIMT_TYPE) != null ? + limitEntity.setType(elementInfo.getInfo().getProperties().get(LIMT_TYPE) != null ? LimitType.valueOf((String) elementInfo.getInfo().getProperties().get(LIMT_TYPE)) : null); - limitEntity.setTime((String) elementInfo.getInfo().getProperties().get(TIME) ); - limitEntity.setMetric( (String) elementInfo.getInfo().getProperties().get(METRIC)); - limitEntity.setAggregationFunction( elementInfo.getInfo().getProperties().get + limitEntity.setTime((String) elementInfo.getInfo().getProperties().get(TIME)); + limitEntity.setMetric((String) elementInfo.getInfo().getProperties().get(METRIC)); + limitEntity.setAggregationFunction(elementInfo.getInfo().getProperties().get (AGGREGATIONFUNCTION) != null ? AggregationFunction.valueOf((String) elementInfo.getInfo().getProperties() .get(AGGREGATIONFUNCTION)) : null); @@ -126,25 +122,22 @@ public class LimitZusammenDaoImpl implements LimitDao { } @Override - public void update(LimitEntity entity) { - ZusammenElement limitElement = limitToZusammen(entity, Action.UPDATE); + public void update(LimitEntity limitEntity) { + ZusammenElement limitElement = limitToZusammen(limitEntity, Action.UPDATE); - SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(entity.getVendorLicenseModelId()); - ElementContext elementContext = new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + SessionContext context = createSessionContext(); + ElementContext elementContext = + new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); - zusammenAdaptor.saveElement(context,elementContext, limitElement, - String.format("Update limit with id %s", entity.getId())); + zusammenAdaptor.saveElement(context, elementContext, limitElement, + String.format("Update limit with id %s", limitEntity.getId())); } @Override public LimitEntity get(LimitEntity limitEntity) { - SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(limitEntity.getVendorLicenseModelId()); - ElementContext elementContext = new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor), - VlmZusammenUtil.getVersionTag(limitEntity.getVersion())); + SessionContext context = createSessionContext(); + ElementContext elementContext = + new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); return zusammenAdaptor.getElementInfo(context, elementContext, new Id(limitEntity.getId())) .map(elementInfo -> mapElementInfoToLimit( @@ -154,18 +147,14 @@ public class LimitZusammenDaoImpl implements LimitDao { } @Override - public void delete(LimitEntity entity) { - SessionContext context = ZusammenUtil.createSessionContext(); - ZusammenElement zusammenElement = new ZusammenElement(); - zusammenElement.setAction(Action.DELETE); - zusammenElement.setElementId(new Id(entity.getId())); + public void delete(LimitEntity limitEntity) { + ZusammenElement zusammenElement = buildElement(new Id(limitEntity.getId()), Action.DELETE); - Id itemId = new Id(entity.getVendorLicenseModelId()); + SessionContext context = createSessionContext(); ElementContext elementContext = - new ElementContext(itemId, - VlmZusammenUtil.getFirstVersionId(context, itemId, zusammenAdaptor)); + new ElementContext(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion().getId()); zusammenAdaptor.saveElement(context, elementContext, zusammenElement, - "delete limit Id:" + entity.getId() + "."); + "delete limit Id:" + limitEntity.getId() + "."); } @Override @@ -173,23 +162,13 @@ public class LimitZusammenDaoImpl implements LimitDao { } - private ZusammenElement limitToZusammen(LimitEntity limit, - Action action) { - ZusammenElement limitElement = buildLimitElement(limit, action); - return limitElement; - } - - private ZusammenElement buildLimitElement(LimitEntity limit, - Action action) { - ZusammenElement limitElement = new ZusammenElement(); - limitElement.setAction(action); - if (limit.getId() != null) { - limitElement.setElementId(new Id(limit.getId())); - } - + private ZusammenElement limitToZusammen(LimitEntity limit, Action action) { + ZusammenElement limitElement = + buildElement(limit.getId() == null ? null : new Id(limit.getId()), action); Info info = new Info(); info.setName(limit.getName()); info.setDescription(limit.getDescription()); + info.addProperty(ElementPropertyName.elementType.name(), ElementType.Limit); info.addProperty(LIMT_TYPE, limit.getType()); info.addProperty(METRIC, limit.getMetric()); info.addProperty(AGGREGATIONFUNCTION, limit.getAggregationFunction()); @@ -199,11 +178,4 @@ public class LimitZusammenDaoImpl implements LimitDao { limitElement.setInfo(info); return limitElement; } - - private ZusammenElement buildZusammenElement(Id elementId, Action action) { - ZusammenElement element = new ZusammenElement(); - element.setElementId(elementId); - element.setAction(action); - return element; - } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VendorLicenseModelDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VendorLicenseModelDaoZusammenImpl.java index cd1ef0fbcf..13065515d8 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VendorLicenseModelDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VendorLicenseModelDaoZusammenImpl.java @@ -1,23 +1,21 @@ 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.datatypes.model.ElementType; import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor.ElementToVLMGeneralConvertor; 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 { @@ -31,63 +29,91 @@ public class VendorLicenseModelDaoZusammenImpl implements VendorLicenseModelDao @Override public void registerVersioning(String versionableEntityType) { VersionableEntityMetadata metadata = - new VersionableEntityMetadata(VersionableEntityStoreType.Zusammen, "vlm", null, null); + new VersionableEntityMetadata(VersionableEntityStoreType.Zusammen, "VendorLicenseModel", + null, null); VersioningManagerFactory.getInstance().createInterface() .register(versionableEntityType, metadata); } @Override - public Collection<VendorLicenseModelEntity> list(VendorLicenseModelEntity entity) { + public Collection<VendorLicenseModelEntity> list( + VendorLicenseModelEntity vendorLicenseModelEntity) { + + ElementToVLMGeneralConvertor convertor = new ElementToVLMGeneralConvertor(); return zusammenAdaptor.listItems(ZusammenUtil.createSessionContext()).stream() - .map(item -> mapInfoToVlm( - item.getId().getValue(), null, item.getInfo(), - item.getModificationTime(), item.getCreationTime())) + .filter(item -> "VendorLicenseModel".equals(item.getInfo().getProperty("item_type"))) + .map(item -> { + VendorLicenseModelEntity entity = convertor.convert(item); + entity.setId(item.getId().getValue()); + entity.setVersion(null); + return entity; + }) .collect(Collectors.toList()); } @Override public void create(VendorLicenseModelEntity vendorLicenseModel) { + SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = zusammenAdaptor.createItem(context, mapVlmToZusammenItemInfo(vendorLicenseModel)); - Id versionId = - zusammenAdaptor.createVersion(context, itemId, null, ZusammenUtil.createFirstVersionData()); + ElementContext elementContext = new ElementContext(vendorLicenseModel.getId(), + vendorLicenseModel.getVersion().getId()); 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 + zusammenAdaptor.saveElement(context, elementContext, generalElement, + "Create VLM General Info Element"); + + ZusammenElement licenseAgreementsElement = + ZusammenUtil.buildStructuralElement(ElementType.LicenseAgreements, Action.CREATE); + + zusammenAdaptor.saveElement(context, elementContext, licenseAgreementsElement, + "Create VLM licenseAgreementsElement"); + + ZusammenElement featureGroupsElement = + ZusammenUtil.buildStructuralElement(ElementType.FeatureGroups, Action.CREATE); + + zusammenAdaptor.saveElement(context, elementContext, featureGroupsElement, + "Create VLM featureGroupsElement"); + + ZusammenElement lkgsElement = + ZusammenUtil.buildStructuralElement(ElementType.LicenseKeyGroups, Action.CREATE); + + zusammenAdaptor.saveElement(context, elementContext, lkgsElement, + "Create VLM lkgsElement"); + + ZusammenElement entitlementPoolsElement = + ZusammenUtil.buildStructuralElement(ElementType.EntitlementPools, Action.CREATE); + + zusammenAdaptor.saveElement(context, elementContext, entitlementPoolsElement, + "Create VLM entitlementPoolsElement"); } @Override public void update(VendorLicenseModelEntity vendorLicenseModel) { - 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), + + SessionContext context = ZusammenUtil.createSessionContext(); + zusammenAdaptor.saveElement(context, + new ElementContext(vendorLicenseModel.getId(), vendorLicenseModel.getVersion().getId()), generalElement, "Update VSP General Info Element"); } @Override public VendorLicenseModelEntity get(VendorLicenseModelEntity vendorLicenseModel) { SessionContext context = ZusammenUtil.createSessionContext(); - Id itemId = new Id(vendorLicenseModel.getId()); - ItemVersion itemVersion = VlmZusammenUtil.getFirstVersion(context, itemId, zusammenAdaptor); - ElementContext elementContext = new ElementContext(itemId, itemVersion.getId(), - VlmZusammenUtil.getVersionTag(vendorLicenseModel.getVersion())); - + ElementContext elementContext = + new ElementContext(vendorLicenseModel.getId(), vendorLicenseModel.getVersion().getId()); + ElementToVLMGeneralConvertor convertor = new ElementToVLMGeneralConvertor(); return zusammenAdaptor - .getElementInfoByName(context, elementContext, null, StructureElement.General.name()) - .map(generalElementInfo -> mapInfoToVlm( - vendorLicenseModel.getId(), vendorLicenseModel.getVersion(), - generalElementInfo.getInfo(), - itemVersion.getModificationTime(), itemVersion.getCreationTime())) + .getElementInfoByName(context, elementContext, null, ElementType.VendorLicenseModel.name()) + .map(generalElementInfo -> { + VendorLicenseModelEntity entity = convertor.convert(generalElementInfo); + entity.setId(vendorLicenseModel.getId()); + entity.setVersion(vendorLicenseModel.getVersion()); + return entity; + }) .orElse(null); } @@ -96,19 +122,19 @@ public class VendorLicenseModelDaoZusammenImpl implements VendorLicenseModelDao } - private Info mapVlmToZusammenItemInfo(VendorLicenseModelEntity vendorLicenseModel) { + /* private Info mapVlmToZusammenItemInfo(VendorLicenseModelEntity vendorLicenseModel) { Info info = new Info(); info.setName(vendorLicenseModel.getVendorName()); info.setDescription(vendorLicenseModel.getDescription()); - info.addProperty("type", "vlm"); + info.addProperty("type", "VendorLicenseModel"); addVlmToInfo(info, vendorLicenseModel); return info; - } + }*/ private ZusammenElement mapVlmToZusammenElement(VendorLicenseModelEntity vendorLicenseModel, Action action) { ZusammenElement generalElement = - VlmZusammenUtil.buildStructuralElement(StructureElement.General, action); + ZusammenUtil.buildStructuralElement(ElementType.VendorLicenseModel, action); addVlmToInfo(generalElement.getInfo(), vendorLicenseModel); return generalElement; } @@ -117,22 +143,21 @@ public class VendorLicenseModelDaoZusammenImpl implements VendorLicenseModelDao info.addProperty(InfoPropertyName.name.name(), vendorLicenseModel.getVendorName()); info.addProperty(InfoPropertyName.description.name(), vendorLicenseModel.getDescription()); info.addProperty(InfoPropertyName.iconRef.name(), vendorLicenseModel.getIconRef()); + info.addProperty(InfoPropertyName.oldVersion.name(), vendorLicenseModel.getOldVersion()); } - private VendorLicenseModelEntity mapInfoToVlm(String vlmId, Version version, Info info, - Date modificationTime, Date creationTime) { + /*private VendorLicenseModelEntity mapInfoToVlm(String vlmId, Version version, Info info) { 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 { + public enum InfoPropertyName { name, description, - iconRef + iconRef, + oldVersion } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VlmZusammenUtil.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VlmZusammenUtil.java index f16d0fae67..07a4f87e67 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VlmZusammenUtil.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VlmZusammenUtil.java @@ -3,49 +3,13 @@ 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> 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()); @@ -67,6 +31,9 @@ public class VlmZusammenUtil { } public static Integer toInteger(Object val) { + if (val == null) { + return null; + } if (val instanceof Double) { return ((Double) val).intValue(); } else if (val instanceof String) { diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToEntitlementPoolConvertor.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToEntitlementPoolConvertor.java new file mode 100644 index 0000000000..75fc6f2605 --- /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/convertor/ElementToEntitlementPoolConvertor.java @@ -0,0 +1,95 @@ +package org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; +import com.amdocs.zusammen.datatypes.item.Info; +import com.amdocs.zusammen.datatypes.item.Relation; +import org.openecomp.convertor.ElementConvertor; +import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; +import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther; +import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope; +import org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VlmZusammenUtil.toInteger; + + +public class ElementToEntitlementPoolConvertor extends ElementConvertor { + @Override + public EntitlementPoolEntity convert(Element element) { + if (element == null) { + return null; + } + return mapElementToEntitlementPoolEntity(element); + } + + @Override + public EntitlementPoolEntity convert(ElementInfo elementInfo) { + if (elementInfo == null) { + return null; + } + return mapElementInfoToEntitlementPoolEntity(elementInfo); + } + + private EntitlementPoolEntity mapElementToEntitlementPoolEntity(Element element) { + EntitlementPoolEntity entitlementPool = + new EntitlementPoolEntity(); + entitlementPool.setId(element.getElementId().getValue()); + mapInfoToEntitlementPoolEntity(entitlementPool, element.getInfo()); + mapRelationsToEntitlementPoolEntity(entitlementPool, element.getRelations()); + return entitlementPool; + } + + private EntitlementPoolEntity mapElementInfoToEntitlementPoolEntity(ElementInfo elementInfo) { + EntitlementPoolEntity entitlementPool = + new EntitlementPoolEntity(); + entitlementPool.setId(elementInfo.getId().getValue()); + mapInfoToEntitlementPoolEntity(entitlementPool, elementInfo.getInfo()); + mapRelationsToEntitlementPoolEntity(entitlementPool, elementInfo.getRelations()); + return entitlementPool; + } + + private void mapInfoToEntitlementPoolEntity(EntitlementPoolEntity entitlementPool, Info info) { + entitlementPool.setName(info.getName()); + entitlementPool.setDescription(info.getDescription()); + entitlementPool.setVersionUuId(info.getProperty("version_uuid")); + entitlementPool.setThresholdValue(toInteger(info.getProperty("thresholdValue"))); + String thresholdUnit = info.getProperty("threshold_unit"); + entitlementPool + .setThresholdUnit(thresholdUnit == null ? null : ThresholdUnit.valueOf(thresholdUnit)); + entitlementPool.setIncrements(info.getProperty("increments")); + entitlementPool.setOperationalScope( + getOperationalScopeMultiChoiceOrOther(info.getProperty("operational_scope"))); + entitlementPool.setStartDate(info.getProperty("startDate")); + entitlementPool.setExpiryDate(info.getProperty("expiryDate")); + } + + private void mapRelationsToEntitlementPoolEntity(EntitlementPoolEntity entitlementPool, + Collection<Relation> relations) { + if (relations != null && relations.size() > 0) { + entitlementPool + .setReferencingFeatureGroups(relations.stream().map(relation -> relation + .getEdge2().getElementId().getValue()).collect(Collectors.toSet())); + } + } + + private MultiChoiceOrOther<OperationalScope> getOperationalScopeMultiChoiceOrOther( + Map<String, Object> operationalScope) { + if (operationalScope == null || operationalScope.isEmpty()) { + return null; + } + + Set<OperationalScope> choices = new HashSet<>(); + ((List<String>) operationalScope.get("choices")). + forEach(choice -> choices.add(OperationalScope.valueOf(choice))); + + Object other = operationalScope.get("other"); + return new MultiChoiceOrOther<>(choices, other == null ? null : (String) other); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToFeatureGroupConvertor.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToFeatureGroupConvertor.java new file mode 100644 index 0000000000..e39c22e569 --- /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/convertor/ElementToFeatureGroupConvertor.java @@ -0,0 +1,83 @@ +package org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; +import com.amdocs.zusammen.datatypes.item.Info; +import com.amdocs.zusammen.datatypes.item.Relation; +import org.openecomp.convertor.ElementConvertor; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.RelationType; +import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + + +public class ElementToFeatureGroupConvertor extends ElementConvertor { + @Override + public FeatureGroupEntity convert(Element element) { + if (element == null) { + return null; + } + return mapElementToFeatureGroupEntity(element); + + } + + @Override + public FeatureGroupEntity convert(ElementInfo elementInfo) { + if (elementInfo == null) { + return null; + } + return mapElementInfoToFeatureGroupEntity(elementInfo); + + } + + + private FeatureGroupEntity mapElementToFeatureGroupEntity(Element element) { + FeatureGroupEntity featureGroup = + new FeatureGroupEntity(); + featureGroup.setId(element.getElementId().getValue()); + mapInfoToFeatureGroup(featureGroup, element.getInfo()); + mapRelationsToFeatureGroup(featureGroup, element.getRelations()); + return featureGroup; + } + + + private FeatureGroupEntity mapElementInfoToFeatureGroupEntity(ElementInfo elementInfo) { + FeatureGroupEntity featureGroup = new FeatureGroupEntity(); + featureGroup.setId(elementInfo.getId().getValue()); + mapInfoToFeatureGroup(featureGroup, elementInfo.getInfo()); + mapRelationsToFeatureGroup(featureGroup, elementInfo.getRelations()); + return featureGroup; + } + + private void mapInfoToFeatureGroup(FeatureGroupEntity featureGroup, Info info) { + featureGroup.setName(info.getName()); + featureGroup.setDescription(info.getDescription()); + featureGroup.setPartNumber(info.getProperty("partNumber")); + featureGroup.setManufacturerReferenceNumber(info.getProperty("manufacturerReferenceNumber")); + } + + private void mapRelationsToFeatureGroup(FeatureGroupEntity featureGroup, + Collection<Relation> relations) { + Set<String> entitlementPoolIds = new HashSet<>(); + Set<String> licenseAgreements = new HashSet<>(); + Set<String> licenseKeyGroupIds = new HashSet<>(); + + if (relations != null) { + for (Relation relation : relations) { + if (RelationType.FeatureGroupToEntitlmentPool.name().equals(relation.getType())) { + entitlementPoolIds.add(relation.getEdge2().getElementId().getValue()); + } else if (RelationType.FeatureGroupToLicenseKeyGroup.name().equals(relation.getType())) { + licenseKeyGroupIds.add(relation.getEdge2().getElementId().getValue()); + } else if (RelationType.FeatureGroupToReferencingLicenseAgreement.name() + .equals(relation.getType())) { + licenseAgreements.add(relation.getEdge2().getElementId().getValue()); + } + } + } + featureGroup.setEntitlementPoolIds(entitlementPoolIds); + featureGroup.setLicenseKeyGroupIds(licenseKeyGroupIds); + featureGroup.setReferencingLicenseAgreements(licenseAgreements); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLicenseAgreementConvertor.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLicenseAgreementConvertor.java new file mode 100644 index 0000000000..a0caa0cf5b --- /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/convertor/ElementToLicenseAgreementConvertor.java @@ -0,0 +1,86 @@ +package org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; +import com.amdocs.zusammen.datatypes.item.Info; +import com.amdocs.zusammen.datatypes.item.Relation; +import org.openecomp.convertor.ElementConvertor; +import org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm; + +import java.util.Collection; +import java.util.Map; +import java.util.stream.Collectors; + + +public class ElementToLicenseAgreementConvertor extends ElementConvertor { + @Override + public LicenseAgreementEntity convert(Element element) { + if (element == null) { + return null; + } + return mapElementToLicenseAgreementEntity(element); + + } + + + @Override + public LicenseAgreementEntity convert(ElementInfo elementInfo) { + if (elementInfo == null) { + return null; + } + return mapElementInfoToLicenseAgreementEntity(elementInfo); + + } + + + private LicenseAgreementEntity mapElementToLicenseAgreementEntity(Element element) { + LicenseAgreementEntity licenseAgreement = + new LicenseAgreementEntity(); + licenseAgreement.setId(element.getElementId().getValue()); + mapInfoToLicenseAgreementEntity(licenseAgreement, element.getInfo()); + mapRelationsToLicenseAgreementEntity(licenseAgreement, element.getRelations()); + return licenseAgreement; + } + + + private LicenseAgreementEntity mapElementInfoToLicenseAgreementEntity(ElementInfo elementInfo) { + LicenseAgreementEntity licenseAgreement = + new LicenseAgreementEntity(); + licenseAgreement.setId( elementInfo.getId().getValue()); + mapInfoToLicenseAgreementEntity(licenseAgreement, elementInfo.getInfo()); + mapRelationsToLicenseAgreementEntity(licenseAgreement, elementInfo.getRelations()); + return licenseAgreement; + } + + private void mapRelationsToLicenseAgreementEntity(LicenseAgreementEntity licenseAgreementEntity, + Collection<Relation> relations) { + if (relations != null && relations.size() > 0) { + licenseAgreementEntity.setFeatureGroupIds(relations.stream() + .map(relation -> relation.getEdge2().getElementId().getValue()) + .collect(Collectors.toSet())); + } + + } + + private void mapInfoToLicenseAgreementEntity(LicenseAgreementEntity licenseAgreement, Info info) { + + + licenseAgreement.setName(info.getName()); + licenseAgreement.setDescription(info.getDescription()); + + licenseAgreement + .setLicenseTerm(getCoiceOrOther(info.getProperty("licenseTerm"))); + licenseAgreement.setRequirementsAndConstrains( + info.getProperty("requirementsAndConstrains")); + + } + + private ChoiceOrOther<LicenseTerm> getCoiceOrOther(Map licenseTerm) { + return new ChoiceOrOther<>(LicenseTerm.valueOf((String) licenseTerm.get("choice")), + (String) licenseTerm.get("other")); + } + + +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLicenseKeyGroupConvertor.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLicenseKeyGroupConvertor.java new file mode 100644 index 0000000000..5956c3e6f1 --- /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/convertor/ElementToLicenseKeyGroupConvertor.java @@ -0,0 +1,104 @@ +package org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; +import com.amdocs.zusammen.datatypes.item.Info; +import com.amdocs.zusammen.datatypes.item.Relation; +import org.openecomp.convertor.ElementConvertor; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType; +import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther; +import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope; +import org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VlmZusammenUtil.toInteger; + + +public class ElementToLicenseKeyGroupConvertor extends ElementConvertor { + @Override + public LicenseKeyGroupEntity convert(Element element) { + if (element == null) { + return null; + } + return mapElementToLicenseKeyGroupEntity(element); + + } + + @Override + public LicenseKeyGroupEntity convert(ElementInfo elementInfo) { + if (elementInfo == null) { + return null; + } + return mapElementInfoToLicenseKeyGroupEntity(elementInfo); + + } + + private LicenseKeyGroupEntity mapElementToLicenseKeyGroupEntity( + Element element) { + LicenseKeyGroupEntity licenseKeyGroup = + new LicenseKeyGroupEntity(); + licenseKeyGroup.setId(element.getElementId().getValue()); + mapInfoToLicenseKeyGroup(licenseKeyGroup, element.getInfo()); + mapRelationsToLicenseKeyGroup(licenseKeyGroup, element.getRelations()); + return licenseKeyGroup; + } + + + private LicenseKeyGroupEntity mapElementInfoToLicenseKeyGroupEntity(ElementInfo elementInfo) { + LicenseKeyGroupEntity licenseKeyGroup = + new LicenseKeyGroupEntity(); + licenseKeyGroup.setId(elementInfo.getId().getValue()); + + mapInfoToLicenseKeyGroup(licenseKeyGroup, elementInfo.getInfo()); + mapRelationsToLicenseKeyGroup(licenseKeyGroup, elementInfo.getRelations()); + return licenseKeyGroup; + } + + private void mapInfoToLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, Info info) { + licenseKeyGroup.setName(info.getName()); + licenseKeyGroup.setDescription(info.getDescription()); + licenseKeyGroup.setVersionUuId(info.getProperty("version_uuid")); + licenseKeyGroup.setType(LicenseKeyType.valueOf(info.getProperty("LicenseKeyType"))); + licenseKeyGroup.setOperationalScope( + getOperationalScopeMultiChoiceOrOther(info.getProperty("operational_scope"))); + licenseKeyGroup.setStartDate(info.getProperty("startDate")); + licenseKeyGroup.setExpiryDate(info.getProperty("expiryDate")); + + String thresholdUnit = info.getProperty("thresholdUnits"); + licenseKeyGroup + .setThresholdUnits(thresholdUnit == null ? null : ThresholdUnit.valueOf(thresholdUnit)); + + licenseKeyGroup.setThresholdValue(toInteger(info.getProperty("thresholdValue"))); + licenseKeyGroup.setIncrements(info.getProperty("increments")); + } + + private void mapRelationsToLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, + Collection<Relation> relations) { + if (relations != null && relations.size() > 0) { + licenseKeyGroup + .setReferencingFeatureGroups((relations.stream().map(relation -> relation + .getEdge2().getElementId().getValue()).collect(Collectors.toSet()))); + } + } + + private MultiChoiceOrOther<OperationalScope> getOperationalScopeMultiChoiceOrOther( + Map<String, Object> operationalScope) { + if (operationalScope == null || operationalScope.isEmpty()) { + return null; + } + + Set<OperationalScope> choices = new HashSet<>(); + ((List<String>) operationalScope.get("choices")). + forEach(choice -> choices.add(OperationalScope.valueOf(choice))); + + Object other = operationalScope.get("other"); + return new MultiChoiceOrOther<>(choices, other == null ? null : (String) other); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLimitConvertor.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToLimitConvertor.java new file mode 100644 index 0000000000..4b2370aea1 --- /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/convertor/ElementToLimitConvertor.java @@ -0,0 +1,44 @@ +package org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; +import org.openecomp.convertor.ElementConvertor; +import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity; +import org.openecomp.sdc.vendorlicense.dao.types.LimitType; + +/** + * Created by ayalaben on 9/26/2017 + */ +public class ElementToLimitConvertor extends ElementConvertor { + @Override + public Object convert(Element element) { + if (element == null) { + return null; + } + return mapElementToLimitEntity(element); + } + + private LimitEntity mapElementToLimitEntity(Element element) { + LimitEntity limit = new LimitEntity(); + limit.setId(element.getElementId().getValue()); + limit.setName(element.getInfo().getName()); + limit.setDescription(element.getInfo().getDescription()); + limit.setUnit(element.getInfo().getProperty("unit")); + limit.setMetric(element.getInfo().getProperty("metric")); + limit.setValue(element.getInfo().getProperty("value")); + limit.setTime(element.getInfo().getProperty("time")); + limit.setAggregationFunction(element.getInfo().getProperty("aggregationFunction")); + setLimitType(limit,element.getInfo().getProperty("type")); + + return limit; + } + + private void setLimitType(LimitEntity limit, String type) { + switch (LimitType.valueOf(type)) { + case ServiceProvider: + limit.setType(LimitType.ServiceProvider); + break; + case Vendor: + limit.setType(LimitType.Vendor); + } + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToVLMGeneralConvertor.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToVLMGeneralConvertor.java new file mode 100644 index 0000000000..c2ef5a6c41 --- /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/convertor/ElementToVLMGeneralConvertor.java @@ -0,0 +1,52 @@ +package org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; +import com.amdocs.zusammen.datatypes.item.Info; +import com.amdocs.zusammen.datatypes.item.Item; +import org.openecomp.convertor.ElementConvertor; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VendorLicenseModelDaoZusammenImpl; +import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity; + + +public class ElementToVLMGeneralConvertor extends ElementConvertor { + @Override + public VendorLicenseModelEntity convert(Element element) { + if(element == null) return null; + return mapInfoToVendorLicenseModelEntity( element.getInfo()); + + } + + @Override + public VendorLicenseModelEntity convert(Item item) { + if(item == null) return null; + return mapInfoToVendorLicenseModelEntity( item.getInfo()); + } + + @Override + public VendorLicenseModelEntity convert(ElementInfo elementInfo) { + if(elementInfo == null) return null; + return mapInfoToVendorLicenseModelEntity( elementInfo.getInfo()); + + } + + + private VendorLicenseModelEntity mapInfoToVendorLicenseModelEntity(Info info) { + + VendorLicenseModelEntity vendorLicenseModelEntity = new VendorLicenseModelEntity(); + + vendorLicenseModelEntity.setVendorName(info.getProperty( + VendorLicenseModelDaoZusammenImpl.InfoPropertyName.name.name())); + vendorLicenseModelEntity.setDescription(info.getProperty( + VendorLicenseModelDaoZusammenImpl.InfoPropertyName.description.name())); + vendorLicenseModelEntity.setIconRef(info.getProperty( + VendorLicenseModelDaoZusammenImpl.InfoPropertyName.iconRef.name())); + vendorLicenseModelEntity.setOldVersion(info.getProperty( + VendorLicenseModelDaoZusammenImpl.InfoPropertyName.oldVersion.name())); + + + return vendorLicenseModelEntity; + } + + +} |