From 4959218f8ced87d458151d14a38891b1fdc70c7d Mon Sep 17 00:00:00 2001 From: KrupaNagabhushan Date: Mon, 26 Jul 2021 12:50:21 +0100 Subject: Consider component model when retrieving group and policy types Issue-ID: SDC-3659 Signed-off-by: KrupaNagabhushan Change-Id: I6d58e51e70085adf114e6efd0c29b00b14358b39 --- .../model/operations/api/IGroupTypeOperation.java | 8 +-- .../model/operations/api/IPolicyTypeOperation.java | 2 +- .../model/operations/impl/GroupTypeOperation.java | 68 ++++++++++------------ .../model/operations/impl/PolicyTypeOperation.java | 43 ++++++-------- 4 files changed, 53 insertions(+), 68 deletions(-) (limited to 'catalog-model/src/main') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupTypeOperation.java index d601a2fd49..62f51210f4 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupTypeOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupTypeOperation.java @@ -32,11 +32,11 @@ public interface IGroupTypeOperation { Either getGroupType(String uniqueId, boolean inTransaction); - Either getLatestGroupTypeByType(String name); + Either getLatestGroupTypeByType(String name, String model); - Either getLatestGroupTypeByType(String name, boolean inTransaction); + Either getLatestGroupTypeByType(String name, String model, boolean inTransaction); - Either getGroupTypeByTypeAndVersion(String name, String version); + Either getGroupTypeByTypeAndVersion(String name, String version, String model); - Either getGroupTypeByTypeAndVersion(String name, String version, boolean inTransaction); + Either getGroupTypeByTypeAndVersion(String name, String version, String model, boolean inTransaction); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java index bba124ec0d..fce683e52f 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java @@ -26,7 +26,7 @@ import org.openecomp.sdc.be.model.PolicyTypeDefinition; public interface IPolicyTypeOperation { - Either getLatestPolicyTypeByType(String policyTypeName); + Either getLatestPolicyTypeByType(String policyTypeName, String modelName); Either addPolicyType(PolicyTypeDefinition policyType); 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 7cf0d29a13..621ba97cb3 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,7 +20,6 @@ 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; @@ -30,6 +29,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; @@ -312,41 +312,19 @@ public class GroupTypeOperation implements IGroupTypeOperation { } } - public Either getLatestGroupTypeByType(String type) { - return getLatestGroupTypeByType(type, true); + public Either getLatestGroupTypeByType(String type, String model) { + return getLatestGroupTypeByType(type, model, true); } - public Either getLatestGroupTypeByType(String type, boolean inTransaction) { + public Either getLatestGroupTypeByType(String type, String model, boolean inTransaction) { Map mapCriteria = new HashMap<>(); mapCriteria.put(GraphPropertiesDictionary.TYPE.getProperty(), type); mapCriteria.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true); - return getGroupTypeByCriteria(type, mapCriteria, inTransaction); - } - - public Either getLatestGroupTypeByType(final String groupType, final String model) { - final Either 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 = 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, 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; + return getGroupTypeByCriteria(type, mapCriteria, model, inTransaction); } public Either getGroupTypeByCriteria(String type, Map properties, + String model, boolean inTransaction) { Either result = null; try { @@ -355,8 +333,8 @@ public class GroupTypeOperation implements IGroupTypeOperation { result = Either.right(StorageOperationStatus.INVALID_ID); return result; } - Either, StorageOperationStatus> groupTypeEither = janusGraphGenericDao - .getByCriteria(NodeTypeEnum.GroupType, properties, GroupTypeData.class).right() + Either, StorageOperationStatus> groupTypeEither = janusGraphGenericDao + .getByCriteriaForModel(NodeTypeEnum.GroupType, properties, model, GroupTypeData.class).right() .map(DaoStatusConverter::convertJanusGraphStatusToStorageStatus); if (groupTypeEither.isRight()) { result = Either.right(groupTypeEither.right().value()); @@ -373,10 +351,24 @@ public class GroupTypeOperation implements IGroupTypeOperation { private Either buildGroupTypeDefinition(String uniqueId, GroupTypeData groupTypeNode) { GroupTypeDefinition groupType = new GroupTypeDefinition(groupTypeNode.getGroupTypeDataDefinition()); + Optional modelName = getAssociatedModelName(uniqueId); + if(modelName.isPresent()) { + groupType.setModel(modelName.get()); + } return fillDerivedFrom(uniqueId, groupType).left().map(derivedFrom -> fillProperties(uniqueId, groupType, derivedFrom)).left() .bind(props -> fillCapabilities(uniqueId, groupType)); } + public Optional getAssociatedModelName(String uniqueId) { + final Either, JanusGraphOperationStatus> modelName = janusGraphGenericDao.getParentNode( + UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.GroupType), uniqueId, GraphEdgeLabels.MODEL_ELEMENT, + NodeTypeEnum.Model, ModelData.class); + if(modelName.isRight()) { + return Optional.empty(); + } + return Optional.ofNullable(modelName.left().value().getLeft().getName()); + } + private Either fillCapabilities(String uniqueId, GroupTypeDefinition groupType) { return getCapablities(uniqueId).left().map(capabilities -> { groupType.setCapabilities(asCapabilitiesMap(capabilities)); @@ -436,15 +428,15 @@ public class GroupTypeOperation implements IGroupTypeOperation { return derivedFrom; } - public Either getGroupTypeByTypeAndVersion(String type, String version) { - return getGroupTypeByTypeAndVersion(type, version, false); + public Either getGroupTypeByTypeAndVersion(String type, String version, String model) { + return getGroupTypeByTypeAndVersion(type, version, model, false); } - public Either getGroupTypeByTypeAndVersion(String type, String version, boolean inTransaction) { + public Either getGroupTypeByTypeAndVersion(String type, String version, String model, boolean inTransaction) { Map mapCriteria = new HashMap<>(); mapCriteria.put(GraphPropertiesDictionary.TYPE.getProperty(), type); mapCriteria.put(GraphPropertiesDictionary.VERSION.getProperty(), version); - return getGroupTypeByCriteria(type, mapCriteria, inTransaction); + return getGroupTypeByCriteria(type, mapCriteria, model, inTransaction); } /** @@ -618,7 +610,7 @@ public class GroupTypeOperation implements IGroupTypeOperation { String groupTypeId = updatedGroupType.getUniqueId(); if (StringUtils.equals(updatedGroupType.getDerivedFrom(), currDerivedFromGroupType)) { return Strings.isNullOrEmpty(currDerivedFromGroupType) ? Either.right(StorageOperationStatus.OK) - : getLatestGroupTypeByType(currDerivedFromGroupType, true).left().map(def -> null); + : getLatestGroupTypeByType(currDerivedFromGroupType, updatedGroupType.getModel()).left().map(def -> null); } StorageOperationStatus status = isLegalToReplaceParent(currDerivedFromGroupType, updatedGroupType.getDerivedFrom(), updatedGroupType.getType()); @@ -628,7 +620,7 @@ public class GroupTypeOperation implements IGroupTypeOperation { log.debug( "#updateGroupDerivedFrom - updating group derived from relation for group type with id {}. old derived type {}. new derived type {}", groupTypeId, currDerivedFromGroupType, updatedGroupType.getDerivedFrom()); - StorageOperationStatus deleteDerivedRelationStatus = deleteDerivedFromGroupType(groupTypeId, currDerivedFromGroupType); + StorageOperationStatus deleteDerivedRelationStatus = deleteDerivedFromGroupType(groupTypeId, currDerivedFromGroupType, updatedGroupType.getModel()); if (deleteDerivedRelationStatus != StorageOperationStatus.OK) { return Either.right(deleteDerivedRelationStatus); } @@ -651,13 +643,13 @@ public class GroupTypeOperation implements IGroupTypeOperation { derivedFromGroup -> derivedFromOperation.addDerivedFromRelation(gtUniqueId, derivedFromGroup.getUniqueId(), NodeTypeEnum.GroupType)); } - private StorageOperationStatus deleteDerivedFromGroupType(String groupTypeId, String derivedFromType) { + private StorageOperationStatus deleteDerivedFromGroupType(String groupTypeId, String derivedFromType, String model) { if (derivedFromType == null) { return StorageOperationStatus.OK; } log.debug("#deleteDerivedFromGroupType - deleting derivedFrom relation for group type with id {} and its derived type {}", groupTypeId, derivedFromType); - return getLatestGroupTypeByType(derivedFromType, true).either( + return getLatestGroupTypeByType(derivedFromType, model).either( derivedFromNode -> derivedFromOperation.removeDerivedFromRelation(groupTypeId, derivedFromNode.getUniqueId(), NodeTypeEnum.GroupType), err -> err); } 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 9bc4cfc4b8..99a284168e 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 @@ -27,6 +27,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -66,35 +67,23 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp @Autowired private OperationUtils operationUtils; + @Override - public Either getLatestPolicyTypeByType(String type) { + public Either getLatestPolicyTypeByType(String type, String model) { Map mapCriteria = new HashMap<>(); mapCriteria.put(GraphPropertiesDictionary.TYPE.getProperty(), type); mapCriteria.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true); - return getPolicyTypeByCriteria(type, mapCriteria); + return getPolicyTypeByCriteria(type, mapCriteria, model); } - public Either getLatestPolicyTypeByType(String type, String model) { - final Either 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 = 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); - } + public Optional getAssociatedModelName(String uniqueId) { final Either, JanusGraphOperationStatus> modelName = janusGraphGenericDao.getParentNode( - UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), policyTypesRes.left().value().getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, + UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), uniqueId, GraphEdgeLabels.MODEL_ELEMENT, NodeTypeEnum.Model, ModelData.class); - if (modelName.isLeft()) { - policyTypeDefinition.left().value().setModel(modelName.left().value().getLeft().getName()); + if (modelName.isRight()) { + return Optional.empty(); } - return policyTypeDefinition; + return Optional.ofNullable(modelName.left().value().getLeft().getName()); } @Override @@ -176,7 +165,7 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp return janusGraphGenericDao.createRelation(from , to, GraphEdgeLabels.MODEL_ELEMENT, Collections.emptyMap()).right().map(DaoStatusConverter::convertJanusGraphStatusToStorageStatus); } - private Either getPolicyTypeByCriteria(String type, Map properties) { + private Either getPolicyTypeByCriteria(String type, Map properties, String model) { Either result; if (type == null || type.isEmpty()) { log.error("type is empty"); @@ -184,7 +173,7 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp return result; } Either, JanusGraphOperationStatus> eitherPolicyData = janusGraphGenericDao - .getByCriteria(NodeTypeEnum.PolicyType, properties, PolicyTypeData.class); + .getByCriteriaForModel(NodeTypeEnum.PolicyType, properties, model, PolicyTypeData.class); if (eitherPolicyData.isRight()) { result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(eitherPolicyData.right().value())); } else { @@ -204,6 +193,10 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp private Either createPolicyTypeDefinition(String uniqueId, PolicyTypeData policyTypeNode) { PolicyTypeDefinition policyType = new PolicyTypeDefinition(policyTypeNode.getPolicyTypeDataDefinition()); + Optional modelName = getAssociatedModelName(uniqueId); + if (modelName.isPresent()) { + policyType.setModel(modelName.get()); + } return fillDerivedFrom(uniqueId, policyType).left().map(derivedFrom -> fillProperties(uniqueId, policyType, derivedFrom)).left() .map(props -> policyType); } @@ -294,7 +287,7 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp log.debug( "#updatePolicyDerivedFrom - updating policy derived from relation for policy type with id {}. old derived type {}. new derived type {}", policyTypeId, currDerivedFromPolicyType, updatedPolicyType.getDerivedFrom()); - StorageOperationStatus deleteDerivedRelationStatus = deleteDerivedFromPolicyType(policyTypeId, currDerivedFromPolicyType); + StorageOperationStatus deleteDerivedRelationStatus = deleteDerivedFromPolicyType(policyTypeId, currDerivedFromPolicyType, updatedPolicyType.getModel()); if (deleteDerivedRelationStatus != StorageOperationStatus.OK) { return Either.right(deleteDerivedRelationStatus); } @@ -312,13 +305,13 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp derivedFromPolicy -> derivedFromOperation.addDerivedFromRelation(ptUniqueId, derivedFromPolicy.getUniqueId(), NodeTypeEnum.PolicyType)); } - private StorageOperationStatus deleteDerivedFromPolicyType(String policyTypeId, String derivedFromType) { + private StorageOperationStatus deleteDerivedFromPolicyType(String policyTypeId, String derivedFromType, String model) { if (derivedFromType == null) { return StorageOperationStatus.OK; } log.debug("#deleteDerivedFromPolicyType - deleting derivedFrom relation for policy type with id {} and its derived type {}", policyTypeId, derivedFromType); - return getLatestPolicyTypeByType(derivedFromType).either( + return getLatestPolicyTypeByType(derivedFromType, model).either( derivedFromNode -> derivedFromOperation.removeDerivedFromRelation(policyTypeId, derivedFromNode.getUniqueId(), NodeTypeEnum.PolicyType), err -> err); } -- cgit 1.2.3-korg