diff options
Diffstat (limited to 'catalog-model/src/main/java')
4 files changed, 53 insertions, 68 deletions
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<GroupTypeDefinition, StorageOperationStatus> getGroupType(String uniqueId, boolean inTransaction); - Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String name); + Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String name, String model); - Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String name, boolean inTransaction); + Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String name, String model, boolean inTransaction); - Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String name, String version); + Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String name, String version, String model); - Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String name, String version, boolean inTransaction); + Either<GroupTypeDefinition, StorageOperationStatus> 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<PolicyTypeDefinition, StorageOperationStatus> getLatestPolicyTypeByType(String policyTypeName); + Either<PolicyTypeDefinition, StorageOperationStatus> getLatestPolicyTypeByType(String policyTypeName, String modelName); Either<PolicyTypeDefinition, StorageOperationStatus> 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<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String type) { - return getLatestGroupTypeByType(type, true); + public Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String type, String model) { + return getLatestGroupTypeByType(type, model, true); } - public Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String type, boolean inTransaction) { + public Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String type, String model, boolean inTransaction) { Map<String, Object> mapCriteria = new HashMap<>(); mapCriteria.put(GraphPropertiesDictionary.TYPE.getProperty(), type); mapCriteria.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true); - 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; + return getGroupTypeByCriteria(type, mapCriteria, model, inTransaction); } public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByCriteria(String type, Map<String, Object> properties, + String model, boolean inTransaction) { Either<GroupTypeDefinition, StorageOperationStatus> result = null; try { @@ -355,8 +333,8 @@ public class GroupTypeOperation implements IGroupTypeOperation { result = Either.right(StorageOperationStatus.INVALID_ID); return result; } - Either<List<GroupTypeData>, StorageOperationStatus> groupTypeEither = janusGraphGenericDao - .getByCriteria(NodeTypeEnum.GroupType, properties, GroupTypeData.class).right() + Either<List<GroupTypeData>, 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<GroupTypeDefinition, StorageOperationStatus> buildGroupTypeDefinition(String uniqueId, GroupTypeData groupTypeNode) { GroupTypeDefinition groupType = new GroupTypeDefinition(groupTypeNode.getGroupTypeDataDefinition()); + Optional<String> 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<String> getAssociatedModelName(String uniqueId) { + final Either<ImmutablePair<ModelData, GraphEdge>, 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<GroupTypeDefinition, StorageOperationStatus> 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<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String type, String version) { - return getGroupTypeByTypeAndVersion(type, version, false); + public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String type, String version, String model) { + return getGroupTypeByTypeAndVersion(type, version, model, false); } - public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String type, String version, boolean inTransaction) { + public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String type, String version, String model, boolean inTransaction) { Map<String, Object> 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<PolicyTypeDefinition, StorageOperationStatus> getLatestPolicyTypeByType(String type) { + public Either<PolicyTypeDefinition, StorageOperationStatus> getLatestPolicyTypeByType(String type, String model) { Map<String, Object> 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<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); - } + public Optional<String> getAssociatedModelName(String uniqueId) { final Either<ImmutablePair<ModelData, GraphEdge>, 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<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeByCriteria(String type, Map<String, Object> properties) { + private Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeByCriteria(String type, Map<String, Object> properties, String model) { Either<PolicyTypeDefinition, StorageOperationStatus> 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<List<PolicyTypeData>, 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<PolicyTypeDefinition, StorageOperationStatus> createPolicyTypeDefinition(String uniqueId, PolicyTypeData policyTypeNode) { PolicyTypeDefinition policyType = new PolicyTypeDefinition(policyTypeNode.getPolicyTypeDataDefinition()); + Optional<String> 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); } |