diff options
author | KrupaNagabhushan <krupa.nagabhushan@est.tech> | 2021-06-25 16:01:25 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2021-07-21 14:02:01 +0000 |
commit | 8a312e6cf2bc0a0c539712b03e75ca3fcfe909ff (patch) | |
tree | 9ad9f03d0937bb716fbd7f9cf68ac9008975b6bb /catalog-model/src | |
parent | 8278b79c92f5149813f0161670a0eb76c33db322 (diff) |
Support for associating policy and group types to models
Issue-ID: SDC-3641
Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech>
Change-Id: I68f5d13dd41b577cf76555b11d9c90d7a5cc4832
Diffstat (limited to 'catalog-model/src')
7 files changed, 201 insertions, 88 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupTypeDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupTypeDefinition.java index f3fb9f7829..343a5094b2 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupTypeDefinition.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupTypeDefinition.java @@ -21,42 +21,27 @@ package org.openecomp.sdc.be.model; import java.util.List; import java.util.Map; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; import org.openecomp.sdc.be.datatypes.elements.GroupTypeDataDefinition; /** * Specifies the group type that the Node Type exposes. */ +@Getter +@Setter +@NoArgsConstructor +@ToString(callSuper = true) public class GroupTypeDefinition extends GroupTypeDataDefinition { private List<PropertyDefinition> properties; private Map<String, CapabilityDefinition> capabilities; - - public GroupTypeDefinition() { - super(); - } + private String model; public GroupTypeDefinition(GroupTypeDataDefinition p) { super(p); } - public List<PropertyDefinition> getProperties() { - return properties; - } - - public void setProperties(List<PropertyDefinition> properties) { - this.properties = properties; - } - - public Map<String, CapabilityDefinition> getCapabilities() { - return capabilities; - } - - public void setCapabilities(Map<String, CapabilityDefinition> capabilies) { - this.capabilities = capabilies; - } - - @Override - public String toString() { - return super.toString() + " [properties=" + properties + ", capabilities=" + capabilities + "]"; - } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTypeDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTypeDefinition.java index 3f3577664e..657da786de 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTypeDefinition.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTypeDefinition.java @@ -20,33 +20,25 @@ package org.openecomp.sdc.be.model; import java.util.List; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; import org.openecomp.sdc.be.datatypes.elements.PolicyTypeDataDefinition; /** * Specifies the policy type that the Node Type exposes. */ +@Getter +@Setter +@NoArgsConstructor +@ToString(callSuper = true) public class PolicyTypeDefinition extends PolicyTypeDataDefinition { private List<PropertyDefinition> properties; - - public PolicyTypeDefinition() { - super(); - } + private String model; public PolicyTypeDefinition(PolicyTypeDataDefinition p) { super(p); } - - public List<PropertyDefinition> getProperties() { - return properties; - } - - public void setProperties(List<PropertyDefinition> properties) { - this.properties = properties; - } - - @Override - public String toString() { - return super.toString() + " [ properties=" + properties + " ]"; - } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java index 488ab78cab..7cf0d29a13 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java @@ -20,6 +20,7 @@ package org.openecomp.sdc.be.model.operations.impl; import static org.openecomp.sdc.be.dao.janusgraph.JanusGraphUtils.buildNotInPredicate; +import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR; import com.google.common.base.Strings; import fj.data.Either; @@ -39,6 +40,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.janusgraph.graphdb.query.JanusGraphPredicate; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge; +import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; @@ -59,6 +61,7 @@ import org.openecomp.sdc.be.model.utils.TypeCompareUtils; import org.openecomp.sdc.be.resources.data.CapabilityData; import org.openecomp.sdc.be.resources.data.CapabilityTypeData; import org.openecomp.sdc.be.resources.data.GroupTypeData; +import org.openecomp.sdc.be.resources.data.ModelData; import org.openecomp.sdc.be.resources.data.PropertyData; import org.openecomp.sdc.be.resources.data.UniqueIdData; import org.openecomp.sdc.common.log.wrappers.Logger; @@ -100,11 +103,11 @@ public class GroupTypeOperation implements IGroupTypeOperation { public Either<GroupTypeDefinition, StorageOperationStatus> addGroupType(GroupTypeDefinition groupTypeDefinition, boolean inTransaction) { Either<GroupTypeDefinition, StorageOperationStatus> result = null; try { - Either<GroupTypeData, JanusGraphOperationStatus> eitherStatus = addGroupTypeToGraph(groupTypeDefinition); + Either<GroupTypeData, StorageOperationStatus> eitherStatus = addGroupTypeToGraph(groupTypeDefinition); if (eitherStatus.isRight()) { BeEcompErrorManager.getInstance() .logBeFailedCreateNodeError(CREATE_FLOW_CONTEXT, groupTypeDefinition.getType(), eitherStatus.right().value().name()); - result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(eitherStatus.right().value())); + result = Either.right(eitherStatus.right().value()); } else { result = getGroupType(eitherStatus.left().value().getUniqueId(), inTransaction); } @@ -124,7 +127,7 @@ public class GroupTypeOperation implements IGroupTypeOperation { JanusGraphOperationStatus error = null; if (CollectionUtils.isNotEmpty(groupTypeDefinition.getProperties()) && !Strings.isNullOrEmpty(groupTypeDefinition.getDerivedFrom())) { Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> allPropertiesRes = getAllGroupTypePropertiesFromAllDerivedFrom( - groupTypeDefinition.getDerivedFrom()); + groupTypeDefinition.getDerivedFrom(), groupTypeDefinition.getModel()); if (allPropertiesRes.isRight() && !allPropertiesRes.right().value().equals(JanusGraphOperationStatus.NOT_FOUND)) { error = allPropertiesRes.right().value(); log.debug("Couldn't fetch derived from property nodes for group type {}, error: {}", groupTypeDefinition.getType(), error); @@ -143,8 +146,8 @@ public class GroupTypeOperation implements IGroupTypeOperation { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(error)); } - private Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> getAllGroupTypePropertiesFromAllDerivedFrom(String firstParentType) { - return janusGraphGenericDao.getNode(GraphPropertiesDictionary.TYPE.getProperty(), firstParentType, GroupTypeData.class).left().bind( + private Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> getAllGroupTypePropertiesFromAllDerivedFrom(String firstParentType, String modelName) { + return janusGraphGenericDao.getNode(GraphPropertiesDictionary.TYPE.getProperty(), firstParentType, GroupTypeData.class, modelName).left().bind( parentGroup -> propertyOperation .getAllTypePropertiesFromAllDerivedFrom(parentGroup.getUniqueId(), NodeTypeEnum.GroupType, GroupTypeData.class)); } @@ -320,6 +323,29 @@ public class GroupTypeOperation implements IGroupTypeOperation { return getGroupTypeByCriteria(type, mapCriteria, inTransaction); } + public Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(final String groupType, final String model) { + final Either<GroupTypeData, JanusGraphOperationStatus> groupTypeRes = janusGraphGenericDao + .getNode(GraphPropertiesDictionary.TYPE.getProperty(), groupType, GroupTypeData.class, model); + if (groupTypeRes.isRight()) { + final JanusGraphOperationStatus status = groupTypeRes.right().value(); + log.error("GroupTypeData cannot be found in graph. status is {}", status); + return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); + } + Either<GroupTypeDefinition, StorageOperationStatus> groupTypeDefinition = getGroupTypeByUid(groupTypeRes.left().value().getUniqueId()); + if (groupTypeDefinition.isRight()) { + final StorageOperationStatus status = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(groupTypeRes.right().value()); + log.error("GroupTypeDefinition cannot be found in graph. status is {}", status); + return Either.right(status); + } + final Either<ImmutablePair<ModelData, GraphEdge>, JanusGraphOperationStatus> modelName = janusGraphGenericDao.getParentNode( + UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), groupTypeRes.left().value().getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, + NodeTypeEnum.Model, ModelData.class); + if (modelName.isLeft()) { + groupTypeDefinition.left().value().setModel(modelName.left().value().getLeft().getName()); + } + return groupTypeDefinition; + } + public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByCriteria(String type, Map<String, Object> properties, boolean inTransaction) { Either<GroupTypeDefinition, StorageOperationStatus> result = null; @@ -433,43 +459,59 @@ public class GroupTypeOperation implements IGroupTypeOperation { * @param groupTypeDefinition * @return */ - private Either<GroupTypeData, JanusGraphOperationStatus> addGroupTypeToGraph(GroupTypeDefinition groupTypeDefinition) { + private Either<GroupTypeData, StorageOperationStatus> addGroupTypeToGraph(GroupTypeDefinition groupTypeDefinition) { log.debug("Got group type {}", groupTypeDefinition); - String ctUniqueId = UniqueIdBuilder.buildGroupTypeUid(groupTypeDefinition.getType(), groupTypeDefinition.getVersion(), "grouptype"); - GroupTypeData groupTypeData = buildGroupTypeData(groupTypeDefinition, ctUniqueId); + String gtUniqueId = UniqueIdBuilder.buildGroupTypeUid(groupTypeDefinition.getModel(), groupTypeDefinition.getType(), + groupTypeDefinition.getVersion(), "grouptype"); + GroupTypeData groupTypeData = buildGroupTypeData(groupTypeDefinition, gtUniqueId); log.debug("Before adding group type to graph. groupTypeData = {}", groupTypeData); Either<GroupTypeData, JanusGraphOperationStatus> createGTResult = janusGraphGenericDao.createNode(groupTypeData, GroupTypeData.class); log.debug("After adding group type to graph. status is = {}", createGTResult); if (createGTResult.isRight()) { JanusGraphOperationStatus operationStatus = createGTResult.right().value(); log.error("Failed to add group type {} to graph. status is {}", groupTypeDefinition.getType(), operationStatus); - return Either.right(operationStatus); + return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(operationStatus)); } GroupTypeData resultCTD = createGTResult.left().value(); List<PropertyDefinition> properties = groupTypeDefinition.getProperties(); - Either<Map<String, PropertyData>, JanusGraphOperationStatus> addPropertiesToCapablityType = propertyOperation + Either<Map<String, PropertyData>, JanusGraphOperationStatus> addPropertiesToGroupType = propertyOperation .addPropertiesToElementType(resultCTD.getUniqueId(), NodeTypeEnum.GroupType, properties); - if (addPropertiesToCapablityType.isRight()) { + if (addPropertiesToGroupType.isRight()) { log.error("Failed add properties {} to capability {}", properties, groupTypeDefinition.getType()); - return Either.right(addPropertiesToCapablityType.right().value()); + return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(addPropertiesToGroupType.right().value())); } String derivedFrom = groupTypeDefinition.getDerivedFrom(); if (derivedFrom != null) { - Either<GraphRelation, JanusGraphOperationStatus> createRelation = connectToDerivedFrom(ctUniqueId, derivedFrom); + Either<GraphRelation, JanusGraphOperationStatus> createRelation = connectToDerivedFrom(gtUniqueId, derivedFrom); if (createRelation.isRight()) { - return Either.right(createRelation.right().value()); + return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createRelation.right().value())); } } Map<String, CapabilityDefinition> groupCapTypes = groupTypeDefinition.getCapabilities(); if (!MapUtils.isEmpty(groupCapTypes)) { JanusGraphOperationStatus status = createCapabilities(groupTypeData, groupCapTypes); if (status != JanusGraphOperationStatus.OK) { - return Either.right(status); + return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } } + final Either<GraphRelation, JanusGraphOperationStatus> modelRelationship = addGroupTypeToModel(groupTypeDefinition); + if (modelRelationship.isRight()) { + return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(modelRelationship.right().value())); + } return Either.left(createGTResult.left().value()); } + private Either<GraphRelation, JanusGraphOperationStatus> addGroupTypeToModel(final GroupTypeDefinition groupTypeDefinition) { + final String model = groupTypeDefinition.getModel(); + if (model == null) { + return Either.left(null); + } + final GraphNode from = new UniqueIdData(NodeTypeEnum.Model, UniqueIdBuilder.buildModelUid(model)); + final GraphNode to = new UniqueIdData(NodeTypeEnum.GroupType, groupTypeDefinition.getUniqueId()); + log.info("Connecting model {} to type {}", from, to); + return janusGraphGenericDao.createRelation(from , to, GraphEdgeLabels.MODEL_ELEMENT, Collections.emptyMap()); + } + private Either<GraphRelation, JanusGraphOperationStatus> connectToDerivedFrom(String ctUniqueId, String derivedFrom) { log.debug("Before creating relation between Group Type with id {} to its parent {}", ctUniqueId, derivedFrom); Either<GroupTypeData, JanusGraphOperationStatus> derivedFromGroupTypeResult = janusGraphGenericDao @@ -598,14 +640,14 @@ public class GroupTypeOperation implements IGroupTypeOperation { t -> t.getGroupTypeDataDefinition().getType()); } - private Either<GraphRelation, StorageOperationStatus> addDerivedFromRelation(GroupTypeDataDefinition groupTypeDef, String gtUniqueId) { + private Either<GraphRelation, StorageOperationStatus> addDerivedFromRelation(GroupTypeDefinition groupTypeDef, String gtUniqueId) { String derivedFrom = groupTypeDef.getDerivedFrom(); if (derivedFrom == null) { return Either.left(null); } log.debug("#addDerivedFromRelationBefore - adding derived from relation between group type {} to its parent {}", groupTypeDef.getType(), derivedFrom); - return this.getLatestGroupTypeByType(derivedFrom, true).left().bind( + return this.getLatestGroupTypeByType(derivedFrom, groupTypeDef.getModel()).left().bind( derivedFromGroup -> derivedFromOperation.addDerivedFromRelation(gtUniqueId, derivedFromGroup.getUniqueId(), NodeTypeEnum.GroupType)); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java index 03b531b3b1..9bc4cfc4b8 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java @@ -19,18 +19,24 @@ */ package org.openecomp.sdc.be.model.operations.impl; import static org.openecomp.sdc.be.dao.janusgraph.JanusGraphUtils.buildNotInPredicate; +import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR; import fj.data.Either; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import org.apache.commons.lang3.tuple.ImmutablePair; import org.janusgraph.graphdb.query.JanusGraphPredicate; import org.openecomp.sdc.be.config.BeEcompErrorManager; +import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge; +import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; +import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; import org.openecomp.sdc.be.datatypes.elements.PolicyTypeDataDefinition; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; @@ -39,8 +45,10 @@ import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.operations.api.DerivedFromOperation; import org.openecomp.sdc.be.model.operations.api.IPolicyTypeOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.be.resources.data.ModelData; import org.openecomp.sdc.be.resources.data.PolicyTypeData; import org.openecomp.sdc.be.resources.data.PropertyData; +import org.openecomp.sdc.be.resources.data.UniqueIdData; import org.openecomp.sdc.common.log.wrappers.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -66,6 +74,29 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp return getPolicyTypeByCriteria(type, mapCriteria); } + public Either<PolicyTypeDefinition, StorageOperationStatus> getLatestPolicyTypeByType(String type, String model) { + final Either<PolicyTypeData, JanusGraphOperationStatus> policyTypesRes = janusGraphGenericDao + .getNode(GraphPropertiesDictionary.TYPE.getProperty(), type, PolicyTypeData.class, model); + if (policyTypesRes.isRight()) { + final StorageOperationStatus status = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(policyTypesRes.right().value()); + log.error("PolicyTypeData cannot be found in graph. status is {}", status); + return Either.right(status); + } + Either<PolicyTypeDefinition, StorageOperationStatus> policyTypeDefinition = getPolicyTypeByUid(policyTypesRes.left().value().getUniqueId()); + if (policyTypeDefinition.isRight()) { + final StorageOperationStatus status = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(policyTypesRes.right().value()); + log.error("PolicyTypeDefinition cannot be found in graph. status is {}", status); + return Either.right(status); + } + final Either<ImmutablePair<ModelData, GraphEdge>, JanusGraphOperationStatus> modelName = janusGraphGenericDao.getParentNode( + UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), policyTypesRes.left().value().getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, + NodeTypeEnum.Model, ModelData.class); + if (modelName.isLeft()) { + policyTypeDefinition.left().value().setModel(modelName.left().value().getLeft().getName()); + } + return policyTypeDefinition; + } + @Override public Either<PolicyTypeDefinition, StorageOperationStatus> addPolicyType(PolicyTypeDefinition policyTypeDef) { Either<PolicyTypeDefinition, StorageOperationStatus> result; @@ -107,7 +138,7 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp private Either<PolicyTypeData, StorageOperationStatus> addPolicyTypeToGraph(PolicyTypeDefinition policyTypeDef) { log.debug("Got policy type {}", policyTypeDef); - String ptUniqueId = UniqueIdBuilder.buildPolicyTypeUid(policyTypeDef.getType(), policyTypeDef.getVersion(), "policytype"); + String ptUniqueId = UniqueIdBuilder.buildPolicyTypeUid(policyTypeDef.getModel(), policyTypeDef.getType(), policyTypeDef.getVersion(), "policytype"); PolicyTypeData policyTypeData = buildPolicyTypeData(policyTypeDef, ptUniqueId); log.debug("Before adding policy type to graph. policyTypeData = {}", policyTypeData); Either<PolicyTypeData, JanusGraphOperationStatus> eitherPolicyTypeData = janusGraphGenericDao @@ -125,9 +156,26 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp log.error("Failed add properties {} to policy {}", properties, policyTypeDef.getType()); return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(addPropertiesToPolicyType.right().value())); } + + final Either<GraphRelation, StorageOperationStatus> modelRelationship = addPolicyTypeToModel(policyTypeDef); + if (modelRelationship.isRight()) { + return Either.right(modelRelationship.right().value()); + } + return addDerivedFromRelation(policyTypeDef, ptUniqueId).left().map(updatedDerivedFrom -> eitherPolicyTypeData.left().value()); } + private Either<GraphRelation, StorageOperationStatus> addPolicyTypeToModel(final PolicyTypeDefinition policyTypeDefinition) { + final String model = policyTypeDefinition.getModel(); + if (model == null) { + return Either.left(null); + } + final GraphNode from = new UniqueIdData(NodeTypeEnum.Model, UniqueIdBuilder.buildModelUid(model)); + final GraphNode to = new UniqueIdData(NodeTypeEnum.PolicyType, policyTypeDefinition.getUniqueId()); + log.info("Connecting model {} to type {}", from, to); + return janusGraphGenericDao.createRelation(from , to, GraphEdgeLabels.MODEL_ELEMENT, Collections.emptyMap()).right().map(DaoStatusConverter::convertJanusGraphStatusToStorageStatus); + } + private Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeByCriteria(String type, Map<String, Object> properties) { Either<PolicyTypeDefinition, StorageOperationStatus> result; if (type == null || type.isEmpty()) { @@ -253,14 +301,14 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp return addDerivedFromRelation(updatedPolicyType, policyTypeId); } - private Either<GraphRelation, StorageOperationStatus> addDerivedFromRelation(PolicyTypeDataDefinition policyTypeDef, String ptUniqueId) { + private Either<GraphRelation, StorageOperationStatus> addDerivedFromRelation(PolicyTypeDefinition policyTypeDef, String ptUniqueId) { String derivedFrom = policyTypeDef.getDerivedFrom(); if (derivedFrom == null) { return Either.left(null); } log.debug("#addDerivedFromRelationBefore - adding derived from relation between policy type {} to its parent {}", policyTypeDef.getType(), derivedFrom); - return this.getLatestPolicyTypeByType(derivedFrom).left().bind( + return this.getLatestPolicyTypeByType(derivedFrom, policyTypeDef.getModel()).left().bind( derivedFromPolicy -> derivedFromOperation.addDerivedFromRelation(ptUniqueId, derivedFromPolicy.getUniqueId(), NodeTypeEnum.PolicyType)); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java index 72fdffab14..a433698ce5 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java @@ -184,12 +184,19 @@ public class UniqueIdBuilder { return generateUUID(); } - static String buildGroupTypeUid(String type, String version, String resourceName) { - return buildTypeUid(type, version, resourceName); + public static String buildGroupTypeUid(String modelName, String type, String version, String resourceName) { + return buildTypeUidWithModel(modelName, type, version, resourceName); } - static String buildPolicyTypeUid(String type, String version, String resourceName) { - return buildTypeUid(type, version, resourceName); + public static String buildPolicyTypeUid(String modelName, String type, String version, String resourceName) { + return buildTypeUidWithModel(modelName, type, version, resourceName); + } + + static String buildTypeUidWithModel(String modelName, String type, String version, String resourceName) { + if (StringUtils.isEmpty(modelName)){ + return buildTypeUid(type, version, resourceName); + } + return modelName + DOT + buildTypeUid(type, version, resourceName); } static String buildTypeUid(String type, String version, String resourceName) { diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java index 062f668b05..4e4a95d2cc 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java @@ -53,6 +53,7 @@ import org.openecomp.sdc.be.model.CapabilityDefinition; import org.openecomp.sdc.be.model.CapabilityTypeDefinition; import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.GroupTypeDefinition; +import org.openecomp.sdc.be.model.Model; import org.openecomp.sdc.be.model.ModelTestBase; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; @@ -77,7 +78,10 @@ public class GroupTypeOperationTest extends ModelTestBase { @Resource(name = "group-type-operation") private GroupTypeOperation groupTypeOperation; - + + @Resource(name = "model-operation") + private ModelOperation modelOperation; + @BeforeClass public static void setupBeforeClass() { ModelTestBase.init(); @@ -534,7 +538,27 @@ public class GroupTypeOperationTest extends ModelTestBase { assertTrue(upgradeResult.isLeft()); assertThat(groupTypeDefinition).isEqualToIgnoringGivenFields(upgradeResult.left().value(), "properties", "capabilities"); } - + + @Test + public void testAddGroupTypeWithModel() { + createRootGroupTypeNode(); + + GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition(); + groupTypeDefinition.setDescription("groups l2-networks in network collection"); + groupTypeDefinition.setType("org.openecomp.groups.PrivateCollection"); + groupTypeDefinition.setVersion("1.0"); + groupTypeDefinition.setModel("testModel"); + Model model = new Model("testModel"); + modelOperation.createModel(model , true); + + Either<GroupTypeDefinition, StorageOperationStatus> addGroupType = groupTypeOperation.addGroupType(groupTypeDefinition); + assertTrue(addGroupType.isLeft()); + Either<GroupTypeDefinition, StorageOperationStatus> eitherGroupTypeFetched = + groupTypeOperation.getLatestGroupTypeByType(groupTypeDefinition.getType(), groupTypeDefinition.getModel()); + assertTrue(eitherGroupTypeFetched.isLeft()); + assertEquals(groupTypeDefinition.getModel(), eitherGroupTypeFetched.left().value().getModel()); + } + private GroupTypeData getOrCreateRootGroupTypeNode() { Either<GroupTypeData, JanusGraphOperationStatus> groupTypeResult = janusGraphDao @@ -850,5 +874,4 @@ public class GroupTypeOperationTest extends ModelTestBase { } return groupTypeDefinition; } - } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java index 47bc484193..e25344f8bb 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -45,6 +45,7 @@ import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; import org.openecomp.sdc.be.datatypes.elements.PolicyTypeDataDefinition; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; +import org.openecomp.sdc.be.model.Model; import org.openecomp.sdc.be.model.ModelTestBase; import org.openecomp.sdc.be.model.PolicyTypeDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; @@ -61,6 +62,8 @@ public class PolicyTypeOperationTest extends ModelTestBase { private static final String NULL_STRING = null; @Autowired private PolicyTypeOperation policyTypeOperation; + @Autowired + private ModelOperation modelOperation; @Autowired private HealingJanusGraphGenericDao janusGraphGenericDao; @@ -98,7 +101,7 @@ public class PolicyTypeOperationTest extends ModelTestBase { PolicyTypeDefinition policyTypePostCreate = addPolicyType.left().value(); assertThat(policyTypePostCreate.getUniqueId()).isNotEmpty(); assertThat(policyTypePostCreate) - .isEqualToComparingOnlyGivenFields(policyTypePreCreate, "name", "icon", "description", "type"); + .isEqualToComparingOnlyGivenFields(policyTypePreCreate, "name", "icon", "description", "type"); } @Test @@ -111,6 +114,21 @@ public class PolicyTypeOperationTest extends ModelTestBase { } @Test + public void testAddPolicyTypeWithModel() { + PolicyTypeDefinition policyTypeDefinition = createPolicyTypeDef(); + policyTypeDefinition.setModel("testModel"); + Model model = new Model("testModel"); + modelOperation.createModel(model , true); + + Either<PolicyTypeDefinition, StorageOperationStatus> addPolicyType = policyTypeOperation.addPolicyType(policyTypeDefinition); + assertTrue(addPolicyType.isLeft()); + Either<PolicyTypeDefinition, StorageOperationStatus> eitherPolicyTypeFetched = + policyTypeOperation.getLatestPolicyTypeByType(policyTypeDefinition.getType(), policyTypeDefinition.getModel()); + assertTrue(eitherPolicyTypeFetched.isLeft()); + assertEquals(policyTypeDefinition.getModel(), eitherPolicyTypeFetched.left().value().getModel()); + } + + @Test public void testGetLatestPolicyTypeByType_derivedFromFetchedCorrectly() { PolicyTypeDefinition rootPolicyType = createRootPolicyTypeOnGraph(); String derivedFromRootType = rootPolicyType.getType(); @@ -130,8 +148,8 @@ public class PolicyTypeOperationTest extends ModelTestBase { Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType2 = policyTypeOperation.getLatestPolicyTypeByType(policyType2.getType()); assertThat(latestPolicyType2.isLeft()).isTrue(); assertThat(latestPolicyType2.left().value().getProperties()) - .usingElementComparatorOnFields("defaultValue", "name", "type") - .containsExactlyInAnyOrder(prop1, prop2); + .usingElementComparatorOnFields("defaultValue", "name", "type") + .containsExactlyInAnyOrder(prop1, prop2); } @Test @@ -151,8 +169,8 @@ public class PolicyTypeOperationTest extends ModelTestBase { Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType3 = policyTypeOperation.getLatestPolicyTypeByType(policyType4.getType()); assertThat(latestPolicyType3.isLeft()).isTrue(); assertThat(latestPolicyType3.left().value().getProperties()) - .usingElementComparatorOnFields("defaultValue", "name", "type") - .containsExactlyInAnyOrder(prop1, prop2, prop3); + .usingElementComparatorOnFields("defaultValue", "name", "type") + .containsExactlyInAnyOrder(prop1, prop2, prop3); } @Test @@ -169,7 +187,7 @@ public class PolicyTypeOperationTest extends ModelTestBase { List<PolicyTypeDefinition> allPolicyTypesWithNoExcluded = policyTypeOperation.getAllPolicyTypes(null, null); assertThat(allPolicyTypesWithNoExcluded).hasSize(2); assertThat(allPolicyTypesWithNoExcluded).usingElementComparatorOnFields("uniqueId", "description", "version", "type") - .containsExactlyInAnyOrder(policyType1, policyType2); + .containsExactlyInAnyOrder(policyType1, policyType2); } @Test @@ -184,7 +202,7 @@ public class PolicyTypeOperationTest extends ModelTestBase { null); assertThat(allPolicyTypes).hasSize(1); assertThat(allPolicyTypes).usingElementComparatorOnFields("type") - .containsExactly(policyType1); + .containsExactly(policyType1); } @Test @@ -231,7 +249,7 @@ public class PolicyTypeOperationTest extends ModelTestBase { PolicyTypeDefinition fetchedPolicyType = fetchedUpdatedType.left().value(); assertThat(fetchedPolicyType.getProperties()).isEmpty(); assertThat(fetchedPolicyType) - .isEqualToIgnoringGivenFields(updatedType, "properties"); + .isEqualToIgnoringGivenFields(updatedType, "properties"); } @@ -250,8 +268,8 @@ public class PolicyTypeOperationTest extends ModelTestBase { Either<PolicyTypeDefinition, StorageOperationStatus> fetchedUpdatedType = policyTypeOperation.getLatestPolicyTypeByType(policyType.getType()); assertThat(fetchedUpdatedType.left().value().getProperties()) - .usingElementComparatorOnFields("name", "defaultValue", "type") - .containsExactlyInAnyOrder(updatedProp1, prop3); + .usingElementComparatorOnFields("name", "defaultValue", "type") + .containsExactlyInAnyOrder(updatedProp1, prop3); } @@ -312,16 +330,16 @@ public class PolicyTypeOperationTest extends ModelTestBase { private void verifyDerivedFromNodeEqualsToRootPolicyType(PolicyTypeDefinition rootPolicyType, String parentPolicyId) { Either<ImmutablePair<PolicyTypeData, GraphEdge>, JanusGraphOperationStatus> derivedFromRelation = janusGraphGenericDao.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), parentPolicyId, GraphEdgeLabels.DERIVED_FROM, - NodeTypeEnum.PolicyType, PolicyTypeData.class); + NodeTypeEnum.PolicyType, PolicyTypeData.class); assertThat(derivedFromRelation.left().value().getLeft().getPolicyTypeDataDefinition()) - .isEqualToComparingFieldByField(rootPolicyType); + .isEqualToComparingFieldByField(rootPolicyType); } private void verifyDerivedFromRelationDoesntExist(String parentPolicyId) { Either<ImmutablePair<PolicyTypeData, GraphEdge>, JanusGraphOperationStatus> derivedFromRelation = janusGraphGenericDao.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), parentPolicyId, GraphEdgeLabels.DERIVED_FROM, - NodeTypeEnum.PolicyType, PolicyTypeData.class); + NodeTypeEnum.PolicyType, PolicyTypeData.class); assertThat(derivedFromRelation.right().value()) - .isEqualTo(JanusGraphOperationStatus.NOT_FOUND); + .isEqualTo(JanusGraphOperationStatus.NOT_FOUND); } private PolicyTypeDefinition createRootPolicyTypeOnGraph() { @@ -349,7 +367,7 @@ public class PolicyTypeOperationTest extends ModelTestBase { return createPolicyTypeDef(type, description, derivedFrom, null); } - private PolicyTypeDefinition createPolicyTypeDef(String type, String description, String derivedFrom, PropertyDefinition ... props) { + private PolicyTypeDefinition createPolicyTypeDef(String type, String description, String derivedFrom, PropertyDefinition ... props) { PolicyTypeDataDefinition policyTypeDataDefinition = new PolicyTypeDataDefinition(); policyTypeDataDefinition.setDescription(description); policyTypeDataDefinition.setType(type); @@ -368,6 +386,4 @@ public class PolicyTypeOperationTest extends ModelTestBase { private void addPolicyTypesToDB(PolicyTypeDefinition ... policyTypeDefinitions) { Stream.of(policyTypeDefinitions).forEach(policyTypeOperation::addPolicyType); } - - -} +}
\ No newline at end of file |