From 8a312e6cf2bc0a0c539712b03e75ca3fcfe909ff Mon Sep 17 00:00:00 2001 From: KrupaNagabhushan Date: Fri, 25 Jun 2021 16:01:25 +0100 Subject: Support for associating policy and group types to models Issue-ID: SDC-3641 Signed-off-by: KrupaNagabhushan Change-Id: I68f5d13dd41b577cf76555b11d9c90d7a5cc4832 --- .../be/components/impl/CommonImportManager.java | 6 +- .../be/components/impl/GroupTypeImportManager.java | 18 +++-- .../components/impl/PolicyTypeImportManager.java | 18 +++-- .../sdc/be/servlets/TypesUploadServlet.java | 20 +++--- .../impl/GroupTypeImportManagerTest.java | 4 +- .../impl/RelationshipTypeImportManagerTest.java | 2 +- .../sdc/be/model/GroupTypeDefinition.java | 33 +++------- .../sdc/be/model/PolicyTypeDefinition.java | 26 +++----- .../model/operations/impl/GroupTypeOperation.java | 76 +++++++++++++++++----- .../model/operations/impl/PolicyTypeOperation.java | 54 ++++++++++++++- .../be/model/operations/impl/UniqueIdBuilder.java | 15 +++-- .../operations/impl/GroupTypeOperationTest.java | 29 ++++++++- .../operations/impl/PolicyTypeOperationTest.java | 56 ++++++++++------ 13 files changed, 244 insertions(+), 113 deletions(-) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java index 326022d806..8c309bd835 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java @@ -380,9 +380,9 @@ public class CommonImportManager { } public Either>, ResponseFormat> createElementTypes( - ToscaTypeImportData toscaTypeImportData, Function, ActionStatus>> elementTypeFromYmlCreater, - Function, Either>, ResponseFormat>> elementTypeDaoCreater) { - Either, ActionStatus> elementTypes = elementTypeFromYmlCreater.apply(toscaTypeImportData.getToscaTypesYml()); + ToscaTypeImportData toscaTypeImportData, BiFunction, ActionStatus>> elementTypeFromYmlCreater, + Function, Either>, ResponseFormat>> elementTypeDaoCreater, String modelName) { + Either, ActionStatus> elementTypes = elementTypeFromYmlCreater.apply(toscaTypeImportData.getToscaTypesYml(), modelName); return elementTypes .right() .map(err -> componentsUtils.getResponseFormat(err, "")) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java index d3640a71a7..8015685403 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java @@ -24,11 +24,13 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.components.impl.CommonImportManager.ElementTypeEnum; import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.CapabilityDefinition; import org.openecomp.sdc.be.model.ComponentInstanceProperty; @@ -37,6 +39,7 @@ import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation; +import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.be.model.utils.TypeCompareUtils; import org.openecomp.sdc.be.utils.TypeUtils; import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum; @@ -61,18 +64,23 @@ public class GroupTypeImportManager { this.commonImportManager = commonImportManager; } - public Either>, ResponseFormat> createGroupTypes(ToscaTypeImportData toscaTypeImportData) { - return commonImportManager.createElementTypes(toscaTypeImportData, this::createGroupTypesFromYml, this::upsertGroupTypesByDao); + public Either>, ResponseFormat> createGroupTypes(ToscaTypeImportData toscaTypeImportData, String modelName) { + return commonImportManager.createElementTypes(toscaTypeImportData, this::createGroupTypesFromYml, this::upsertGroupTypesByDao, modelName); } - private Either, ActionStatus> createGroupTypesFromYml(String groupTypesYml) { - return commonImportManager.createElementTypesFromYml(groupTypesYml, this::createGroupType); + private Either, ActionStatus> createGroupTypesFromYml(String groupTypesYml, String modelName) { + Either, ActionStatus> groupTypes = commonImportManager.createElementTypesFromYml(groupTypesYml, this::createGroupType); + if (groupTypes.isLeft() && StringUtils.isNotEmpty(modelName)){ + groupTypes.left().value().forEach(groupType -> groupType.setModel(modelName)); + } + return groupTypes; } private Either>, ResponseFormat> upsertGroupTypesByDao( List groupTypesToCreate) { return commonImportManager.createElementTypesByDao(groupTypesToCreate, this::validateGroupType, - groupType -> new ImmutablePair<>(ElementTypeEnum.GROUP_TYPE, groupType.getType()), groupTypeOperation::getLatestGroupTypeByType, + groupType -> new ImmutablePair<>(ElementTypeEnum.GROUP_TYPE, UniqueIdBuilder.buildGroupTypeUid(groupType.getModel(), + groupType.getType(), groupType.getVersion(), NodeTypeEnum.GroupType.getName()).toLowerCase()), groupTypeOperation::getLatestGroupTypeByType, groupTypeOperation::addGroupType, this::updateGroupType); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java index 2b9f58ce51..48519d9abe 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java @@ -23,11 +23,13 @@ import fj.data.Either; import java.util.List; import java.util.Map; import java.util.function.Consumer; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.components.impl.CommonImportManager.ElementTypeEnum; import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData; import org.openecomp.sdc.be.components.impl.utils.PolicyTypeImportUtils; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.GroupTypeDefinition; import org.openecomp.sdc.be.model.PolicyTypeDefinition; @@ -36,6 +38,7 @@ import org.openecomp.sdc.be.model.operations.api.IPolicyTypeOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.GroupOperation; import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation; +import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.be.utils.TypeUtils; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.stereotype.Component; @@ -61,18 +64,23 @@ public class PolicyTypeImportManager { this.groupTypeOperation = groupTypeOperation; } - public Either>, ResponseFormat> createPolicyTypes(ToscaTypeImportData toscaTypeImportData) { - return commonImportManager.createElementTypes(toscaTypeImportData, this::createPolicyTypesFromYml, this::upsertPolicyTypesByDao); + public Either>, ResponseFormat> createPolicyTypes(ToscaTypeImportData toscaTypeImportData, String modelName) { + return commonImportManager.createElementTypes(toscaTypeImportData, this::createPolicyTypesFromYml, this::upsertPolicyTypesByDao, modelName); } - private Either, ActionStatus> createPolicyTypesFromYml(String policyTypesYml) { - return commonImportManager.createElementTypesFromYml(policyTypesYml, this::createPolicyType); + private Either, ActionStatus> createPolicyTypesFromYml(String policyTypesYml, String modelName) { + Either, ActionStatus> policyTypes = commonImportManager.createElementTypesFromYml(policyTypesYml, this::createPolicyType); + if (policyTypes.isLeft() && StringUtils.isNotEmpty(modelName)){ + policyTypes.left().value().forEach(policyType -> policyType.setModel(modelName)); + } + return policyTypes; } private Either>, ResponseFormat> upsertPolicyTypesByDao( List policyTypesToCreate) { return commonImportManager.createElementTypesByDao(policyTypesToCreate, this::validatePolicyType, - policyType -> new ImmutablePair<>(ElementTypeEnum.POLICY_TYPE, policyType.getType()), policyTypeOperation::getLatestPolicyTypeByType, + policyType -> new ImmutablePair<>(ElementTypeEnum.POLICY_TYPE, UniqueIdBuilder.buildPolicyTypeUid(policyType.getModel(), + policyType.getType(), policyType.getVersion(), NodeTypeEnum.PolicyType.getName()).toLowerCase()), policyTypeOperation::getLatestPolicyTypeByType, policyTypeOperation::addPolicyType, this::updatePolicyType); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java index 9656550f95..396cb42d47 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java @@ -209,10 +209,11 @@ public class TypesUploadServlet extends AbstractValidationsServlet { @ApiResponse(responseCode = "409", description = "group types already exist")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public Response uploadGroupTypes(@Parameter(description = "toscaTypeMetadata") @FormDataParam("toscaTypeMetadata") String toscaTypesMetaData, + @Parameter(description = "model") @FormDataParam("model") String modelName, @Parameter(description = "FileInputStream") @FormDataParam("groupTypesZip") File file, @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) { Map typesMetadata = getTypesMetadata(toscaTypesMetaData); - return uploadTypesWithMetaData(this::createGroupTypes, typesMetadata, file, request, creator, NodeTypeEnum.GroupType.getName()); + return uploadTypesWithMetaData(this::createGroupTypes, typesMetadata, file, request, creator, NodeTypeEnum.GroupType.getName(), modelName); } @POST @@ -225,10 +226,11 @@ public class TypesUploadServlet extends AbstractValidationsServlet { @ApiResponse(responseCode = "409", description = "policy types already exist")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public Response uploadPolicyTypes(@Parameter(description = "toscaTypeMetadata") @FormDataParam("toscaTypeMetadata") String toscaTypesMetaData, + @Parameter(description = "model") @FormDataParam("model") String modelName, @Parameter(description = "FileInputStream") @FormDataParam("policyTypesZip") File file, @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) { Map typesMetadata = getTypesMetadata(toscaTypesMetaData); - return uploadTypesWithMetaData(this::createPolicyTypes, typesMetadata, file, request, creator, NodeTypeEnum.PolicyType.getName()); + return uploadTypesWithMetaData(this::createPolicyTypes, typesMetadata, file, request, creator, NodeTypeEnum.PolicyType.getName(), modelName); } private Map getTypesMetadata(String toscaTypesMetaData) { @@ -297,9 +299,9 @@ public class TypesUploadServlet extends AbstractValidationsServlet { return responseWrapper; } - private Response uploadTypesWithMetaData(ConsumerTwoParam, ToscaTypeImportData> createElementsMethod, + private Response uploadTypesWithMetaData(ConsumerThreeParam, ToscaTypeImportData, String> createElementsMethod, Map typesMetaData, File file, final HttpServletRequest request, - String creator, String elementTypeName) { + String creator, String elementTypeName, String modelName) { init(); String userId = initHeaderParam(creator, request, Constants.USER_ID_HEADER); Wrapper yamlStringWrapper = new Wrapper<>(); @@ -310,7 +312,7 @@ public class TypesUploadServlet extends AbstractValidationsServlet { } if (responseWrapper.isEmpty()) { ToscaTypeImportData toscaTypeImportData = new ToscaTypeImportData(yamlStringWrapper.getInnerElement(), typesMetaData); - createElementsMethod.accept(responseWrapper, toscaTypeImportData); + createElementsMethod.accept(responseWrapper, toscaTypeImportData, modelName); } return responseWrapper.getInnerElement(); } catch (Exception e) { @@ -347,17 +349,17 @@ public class TypesUploadServlet extends AbstractValidationsServlet { } // group types - private void createGroupTypes(Wrapper responseWrapper, ToscaTypeImportData toscaTypeImportData) { + private void createGroupTypes(Wrapper responseWrapper, ToscaTypeImportData toscaTypeImportData, String modelName) { final Supplier>, ResponseFormat>> generateElementTypeFromYml = () -> groupTypeImportManager - .createGroupTypes(toscaTypeImportData); + .createGroupTypes(toscaTypeImportData, modelName); buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml, ActionStatus.GROUP_TYPE_ALREADY_EXIST, NodeTypeEnum.GroupType.name()); } // policy types - private void createPolicyTypes(Wrapper responseWrapper, ToscaTypeImportData toscaTypeImportData) { + private void createPolicyTypes(Wrapper responseWrapper, ToscaTypeImportData toscaTypeImportData, String modelName) { final Supplier>, ResponseFormat>> generateElementTypeFromYml = () -> policyTypeImportManager - .createPolicyTypes(toscaTypeImportData); + .createPolicyTypes(toscaTypeImportData, modelName); buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml, ActionStatus.POLICY_TYPE_ALREADY_EXIST, NodeTypeEnum.PolicyType.name()); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java index 5de1f23181..33cd971c14 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java @@ -47,7 +47,7 @@ public class GroupTypeImportManagerTest { public void shouldInvokeCreateElementTypes() { GroupTypeImportManager groupTypeImportManager = new GroupTypeImportManager(groupTypeOperation, componentsUtils, toscaOperationFacade, commonImportManager); - groupTypeImportManager.createGroupTypes(data); - Mockito.verify(commonImportManager).createElementTypes(Mockito.any(ToscaTypeImportData.class), Mockito.any(), Mockito.any()); + groupTypeImportManager.createGroupTypes(data, null); + Mockito.verify(commonImportManager).createElementTypes(Mockito.any(ToscaTypeImportData.class), Mockito.any(), Mockito.any(), Mockito.any()); } } \ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java index a4ee779052..3495159153 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java @@ -42,7 +42,7 @@ public class RelationshipTypeImportManagerTest { RelationshipTypeImportManager relationshipTypeImportManager = new RelationshipTypeImportManager(relationshipTypeOperation, commonImportManager, componentsUtils); relationshipTypeImportManager.createRelationshipTypes("anyYaml", "anyModel"); - Mockito.verify(commonImportManager).createElementTypes(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); + Mockito.verify(commonImportManager).createElementTypes((String) Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); } } \ No newline at end of file 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 properties; private Map capabilities; - - public GroupTypeDefinition() { - super(); - } + private String model; public GroupTypeDefinition(GroupTypeDataDefinition p) { super(p); } - public List getProperties() { - return properties; - } - - public void setProperties(List properties) { - this.properties = properties; - } - - public Map getCapabilities() { - return capabilities; - } - - public void setCapabilities(Map 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 properties; - - public PolicyTypeDefinition() { - super(); - } + private String model; public PolicyTypeDefinition(PolicyTypeDataDefinition p) { super(p); } - - public List getProperties() { - return properties; - } - - public void setProperties(List 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 addGroupType(GroupTypeDefinition groupTypeDefinition, boolean inTransaction) { Either result = null; try { - Either eitherStatus = addGroupTypeToGraph(groupTypeDefinition); + Either 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, 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, JanusGraphOperationStatus> getAllGroupTypePropertiesFromAllDerivedFrom(String firstParentType) { - return janusGraphGenericDao.getNode(GraphPropertiesDictionary.TYPE.getProperty(), firstParentType, GroupTypeData.class).left().bind( + private Either, 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 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; + } + public Either getGroupTypeByCriteria(String type, Map properties, boolean inTransaction) { Either result = null; @@ -433,43 +459,59 @@ public class GroupTypeOperation implements IGroupTypeOperation { * @param groupTypeDefinition * @return */ - private Either addGroupTypeToGraph(GroupTypeDefinition groupTypeDefinition) { + private Either 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 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 properties = groupTypeDefinition.getProperties(); - Either, JanusGraphOperationStatus> addPropertiesToCapablityType = propertyOperation + Either, 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 createRelation = connectToDerivedFrom(ctUniqueId, derivedFrom); + Either createRelation = connectToDerivedFrom(gtUniqueId, derivedFrom); if (createRelation.isRight()) { - return Either.right(createRelation.right().value()); + return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createRelation.right().value())); } } Map 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 modelRelationship = addGroupTypeToModel(groupTypeDefinition); + if (modelRelationship.isRight()) { + return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(modelRelationship.right().value())); + } return Either.left(createGTResult.left().value()); } + private Either 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 connectToDerivedFrom(String ctUniqueId, String derivedFrom) { log.debug("Before creating relation between Group Type with id {} to its parent {}", ctUniqueId, derivedFrom); Either derivedFromGroupTypeResult = janusGraphGenericDao @@ -598,14 +640,14 @@ public class GroupTypeOperation implements IGroupTypeOperation { t -> t.getGroupTypeDataDefinition().getType()); } - private Either addDerivedFromRelation(GroupTypeDataDefinition groupTypeDef, String gtUniqueId) { + private Either 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 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); + } + final Either, 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 addPolicyType(PolicyTypeDefinition policyTypeDef) { Either result; @@ -107,7 +138,7 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp private Either 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 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 modelRelationship = addPolicyTypeToModel(policyTypeDef); + if (modelRelationship.isRight()) { + return Either.right(modelRelationship.right().value()); + } + return addDerivedFromRelation(policyTypeDef, ptUniqueId).left().map(updatedDerivedFrom -> eitherPolicyTypeData.left().value()); } + private Either 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 getPolicyTypeByCriteria(String type, Map properties) { Either result; if (type == null || type.isEmpty()) { @@ -253,14 +301,14 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp return addDerivedFromRelation(updatedPolicyType, policyTypeId); } - private Either addDerivedFromRelation(PolicyTypeDataDefinition policyTypeDef, String ptUniqueId) { + private Either 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 addGroupType = groupTypeOperation.addGroupType(groupTypeDefinition); + assertTrue(addGroupType.isLeft()); + Either eitherGroupTypeFetched = + groupTypeOperation.getLatestGroupTypeByType(groupTypeDefinition.getType(), groupTypeDefinition.getModel()); + assertTrue(eitherGroupTypeFetched.isLeft()); + assertEquals(groupTypeDefinition.getModel(), eitherGroupTypeFetched.left().value().getModel()); + } + private GroupTypeData getOrCreateRootGroupTypeNode() { Either 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 @@ -110,6 +113,21 @@ public class PolicyTypeOperationTest extends ModelTestBase { assertEquals(policyTypeFetched.toString(), policyTypeCreated.toString()); } + @Test + public void testAddPolicyTypeWithModel() { + PolicyTypeDefinition policyTypeDefinition = createPolicyTypeDef(); + policyTypeDefinition.setModel("testModel"); + Model model = new Model("testModel"); + modelOperation.createModel(model , true); + + Either addPolicyType = policyTypeOperation.addPolicyType(policyTypeDefinition); + assertTrue(addPolicyType.isLeft()); + Either 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(); @@ -130,8 +148,8 @@ public class PolicyTypeOperationTest extends ModelTestBase { Either 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 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 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 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, 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, 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 -- cgit 1.2.3-korg