summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrupaNagabhushan <krupa.nagabhushan@est.tech>2021-06-25 16:01:25 +0100
committerMichael Morris <michael.morris@est.tech>2021-07-21 14:02:01 +0000
commit8a312e6cf2bc0a0c539712b03e75ca3fcfe909ff (patch)
tree9ad9f03d0937bb716fbd7f9cf68ac9008975b6bb
parent8278b79c92f5149813f0161670a0eb76c33db322 (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
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java18
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java18
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java20
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManagerTest.java4
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManagerTest.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupTypeDefinition.java33
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTypeDefinition.java26
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java76
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java54
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java15
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java29
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java56
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 <T extends ToscaTypeDataDefinition> Either<List<ImmutablePair<T, Boolean>>, ResponseFormat> createElementTypes(
- ToscaTypeImportData toscaTypeImportData, Function<String, Either<List<T>, ActionStatus>> elementTypeFromYmlCreater,
- Function<List<T>, Either<List<ImmutablePair<T, Boolean>>, ResponseFormat>> elementTypeDaoCreater) {
- Either<List<T>, ActionStatus> elementTypes = elementTypeFromYmlCreater.apply(toscaTypeImportData.getToscaTypesYml());
+ ToscaTypeImportData toscaTypeImportData, BiFunction<String, String, Either<List<T>, ActionStatus>> elementTypeFromYmlCreater,
+ Function<List<T>, Either<List<ImmutablePair<T, Boolean>>, ResponseFormat>> elementTypeDaoCreater, String modelName) {
+ Either<List<T>, 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<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> createGroupTypes(ToscaTypeImportData toscaTypeImportData) {
- return commonImportManager.createElementTypes(toscaTypeImportData, this::createGroupTypesFromYml, this::upsertGroupTypesByDao);
+ public Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> createGroupTypes(ToscaTypeImportData toscaTypeImportData, String modelName) {
+ return commonImportManager.createElementTypes(toscaTypeImportData, this::createGroupTypesFromYml, this::upsertGroupTypesByDao, modelName);
}
- private Either<List<GroupTypeDefinition>, ActionStatus> createGroupTypesFromYml(String groupTypesYml) {
- return commonImportManager.createElementTypesFromYml(groupTypesYml, this::createGroupType);
+ private Either<List<GroupTypeDefinition>, ActionStatus> createGroupTypesFromYml(String groupTypesYml, String modelName) {
+ Either<List<GroupTypeDefinition>, 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<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> upsertGroupTypesByDao(
List<GroupTypeDefinition> 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<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> createPolicyTypes(ToscaTypeImportData toscaTypeImportData) {
- return commonImportManager.createElementTypes(toscaTypeImportData, this::createPolicyTypesFromYml, this::upsertPolicyTypesByDao);
+ public Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> createPolicyTypes(ToscaTypeImportData toscaTypeImportData, String modelName) {
+ return commonImportManager.createElementTypes(toscaTypeImportData, this::createPolicyTypesFromYml, this::upsertPolicyTypesByDao, modelName);
}
- private Either<List<PolicyTypeDefinition>, ActionStatus> createPolicyTypesFromYml(String policyTypesYml) {
- return commonImportManager.createElementTypesFromYml(policyTypesYml, this::createPolicyType);
+ private Either<List<PolicyTypeDefinition>, ActionStatus> createPolicyTypesFromYml(String policyTypesYml, String modelName) {
+ Either<List<PolicyTypeDefinition>, 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<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> upsertPolicyTypesByDao(
List<PolicyTypeDefinition> 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<String, ToscaTypeMetadata> 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<String, ToscaTypeMetadata> 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<String, ToscaTypeMetadata> getTypesMetadata(String toscaTypesMetaData) {
@@ -297,9 +299,9 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
return responseWrapper;
}
- private Response uploadTypesWithMetaData(ConsumerTwoParam<Wrapper<Response>, ToscaTypeImportData> createElementsMethod,
+ private Response uploadTypesWithMetaData(ConsumerThreeParam<Wrapper<Response>, ToscaTypeImportData, String> createElementsMethod,
Map<String, ToscaTypeMetadata> 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<String> 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<Response> responseWrapper, ToscaTypeImportData toscaTypeImportData) {
+ private void createGroupTypes(Wrapper<Response> responseWrapper, ToscaTypeImportData toscaTypeImportData, String modelName) {
final Supplier<Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, 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<Response> responseWrapper, ToscaTypeImportData toscaTypeImportData) {
+ private void createPolicyTypes(Wrapper<Response> responseWrapper, ToscaTypeImportData toscaTypeImportData, String modelName) {
final Supplier<Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, 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<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