summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org
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 /catalog-model/src/main/java/org
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
Diffstat (limited to 'catalog-model/src/main/java/org')
-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
5 files changed, 139 insertions, 65 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupTypeDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupTypeDefinition.java
index f3fb9f7829..343a5094b2 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupTypeDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/GroupTypeDefinition.java
@@ -21,42 +21,27 @@ package org.openecomp.sdc.be.model;
import java.util.List;
import java.util.Map;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.ToString;
import org.openecomp.sdc.be.datatypes.elements.GroupTypeDataDefinition;
/**
* Specifies the group type that the Node Type exposes.
*/
+@Getter
+@Setter
+@NoArgsConstructor
+@ToString(callSuper = true)
public class GroupTypeDefinition extends GroupTypeDataDefinition {
private List<PropertyDefinition> properties;
private Map<String, CapabilityDefinition> capabilities;
-
- public GroupTypeDefinition() {
- super();
- }
+ private String model;
public GroupTypeDefinition(GroupTypeDataDefinition p) {
super(p);
}
- public List<PropertyDefinition> getProperties() {
- return properties;
- }
-
- public void setProperties(List<PropertyDefinition> properties) {
- this.properties = properties;
- }
-
- public Map<String, CapabilityDefinition> getCapabilities() {
- return capabilities;
- }
-
- public void setCapabilities(Map<String, CapabilityDefinition> capabilies) {
- this.capabilities = capabilies;
- }
-
- @Override
- public String toString() {
- return super.toString() + " [properties=" + properties + ", capabilities=" + capabilities + "]";
- }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTypeDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTypeDefinition.java
index 3f3577664e..657da786de 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTypeDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/PolicyTypeDefinition.java
@@ -20,33 +20,25 @@
package org.openecomp.sdc.be.model;
import java.util.List;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.ToString;
import org.openecomp.sdc.be.datatypes.elements.PolicyTypeDataDefinition;
/**
* Specifies the policy type that the Node Type exposes.
*/
+@Getter
+@Setter
+@NoArgsConstructor
+@ToString(callSuper = true)
public class PolicyTypeDefinition extends PolicyTypeDataDefinition {
private List<PropertyDefinition> properties;
-
- public PolicyTypeDefinition() {
- super();
- }
+ private String model;
public PolicyTypeDefinition(PolicyTypeDataDefinition p) {
super(p);
}
-
- public List<PropertyDefinition> getProperties() {
- return properties;
- }
-
- public void setProperties(List<PropertyDefinition> properties) {
- this.properties = properties;
- }
-
- @Override
- public String toString() {
- return super.toString() + " [ properties=" + properties + " ]";
- }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
index 488ab78cab..7cf0d29a13 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
@@ -20,6 +20,7 @@
package org.openecomp.sdc.be.model.operations.impl;
import static org.openecomp.sdc.be.dao.janusgraph.JanusGraphUtils.buildNotInPredicate;
+import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR;
import com.google.common.base.Strings;
import fj.data.Either;
@@ -39,6 +40,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import org.janusgraph.graphdb.query.JanusGraphPredicate;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
+import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
@@ -59,6 +61,7 @@ import org.openecomp.sdc.be.model.utils.TypeCompareUtils;
import org.openecomp.sdc.be.resources.data.CapabilityData;
import org.openecomp.sdc.be.resources.data.CapabilityTypeData;
import org.openecomp.sdc.be.resources.data.GroupTypeData;
+import org.openecomp.sdc.be.resources.data.ModelData;
import org.openecomp.sdc.be.resources.data.PropertyData;
import org.openecomp.sdc.be.resources.data.UniqueIdData;
import org.openecomp.sdc.common.log.wrappers.Logger;
@@ -100,11 +103,11 @@ public class GroupTypeOperation implements IGroupTypeOperation {
public Either<GroupTypeDefinition, StorageOperationStatus> addGroupType(GroupTypeDefinition groupTypeDefinition, boolean inTransaction) {
Either<GroupTypeDefinition, StorageOperationStatus> result = null;
try {
- Either<GroupTypeData, JanusGraphOperationStatus> eitherStatus = addGroupTypeToGraph(groupTypeDefinition);
+ Either<GroupTypeData, StorageOperationStatus> eitherStatus = addGroupTypeToGraph(groupTypeDefinition);
if (eitherStatus.isRight()) {
BeEcompErrorManager.getInstance()
.logBeFailedCreateNodeError(CREATE_FLOW_CONTEXT, groupTypeDefinition.getType(), eitherStatus.right().value().name());
- result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(eitherStatus.right().value()));
+ result = Either.right(eitherStatus.right().value());
} else {
result = getGroupType(eitherStatus.left().value().getUniqueId(), inTransaction);
}
@@ -124,7 +127,7 @@ public class GroupTypeOperation implements IGroupTypeOperation {
JanusGraphOperationStatus error = null;
if (CollectionUtils.isNotEmpty(groupTypeDefinition.getProperties()) && !Strings.isNullOrEmpty(groupTypeDefinition.getDerivedFrom())) {
Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> allPropertiesRes = getAllGroupTypePropertiesFromAllDerivedFrom(
- groupTypeDefinition.getDerivedFrom());
+ groupTypeDefinition.getDerivedFrom(), groupTypeDefinition.getModel());
if (allPropertiesRes.isRight() && !allPropertiesRes.right().value().equals(JanusGraphOperationStatus.NOT_FOUND)) {
error = allPropertiesRes.right().value();
log.debug("Couldn't fetch derived from property nodes for group type {}, error: {}", groupTypeDefinition.getType(), error);
@@ -143,8 +146,8 @@ public class GroupTypeOperation implements IGroupTypeOperation {
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(error));
}
- private Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> getAllGroupTypePropertiesFromAllDerivedFrom(String firstParentType) {
- return janusGraphGenericDao.getNode(GraphPropertiesDictionary.TYPE.getProperty(), firstParentType, GroupTypeData.class).left().bind(
+ private Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> getAllGroupTypePropertiesFromAllDerivedFrom(String firstParentType, String modelName) {
+ return janusGraphGenericDao.getNode(GraphPropertiesDictionary.TYPE.getProperty(), firstParentType, GroupTypeData.class, modelName).left().bind(
parentGroup -> propertyOperation
.getAllTypePropertiesFromAllDerivedFrom(parentGroup.getUniqueId(), NodeTypeEnum.GroupType, GroupTypeData.class));
}
@@ -320,6 +323,29 @@ public class GroupTypeOperation implements IGroupTypeOperation {
return getGroupTypeByCriteria(type, mapCriteria, inTransaction);
}
+ public Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(final String groupType, final String model) {
+ final Either<GroupTypeData, JanusGraphOperationStatus> groupTypeRes = janusGraphGenericDao
+ .getNode(GraphPropertiesDictionary.TYPE.getProperty(), groupType, GroupTypeData.class, model);
+ if (groupTypeRes.isRight()) {
+ final JanusGraphOperationStatus status = groupTypeRes.right().value();
+ log.error("GroupTypeData cannot be found in graph. status is {}", status);
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
+ }
+ Either<GroupTypeDefinition, StorageOperationStatus> groupTypeDefinition = getGroupTypeByUid(groupTypeRes.left().value().getUniqueId());
+ if (groupTypeDefinition.isRight()) {
+ final StorageOperationStatus status = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(groupTypeRes.right().value());
+ log.error("GroupTypeDefinition cannot be found in graph. status is {}", status);
+ return Either.right(status);
+ }
+ final Either<ImmutablePair<ModelData, GraphEdge>, JanusGraphOperationStatus> modelName = janusGraphGenericDao.getParentNode(
+ UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), groupTypeRes.left().value().getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT,
+ NodeTypeEnum.Model, ModelData.class);
+ if (modelName.isLeft()) {
+ groupTypeDefinition.left().value().setModel(modelName.left().value().getLeft().getName());
+ }
+ return groupTypeDefinition;
+ }
+
public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByCriteria(String type, Map<String, Object> properties,
boolean inTransaction) {
Either<GroupTypeDefinition, StorageOperationStatus> result = null;
@@ -433,43 +459,59 @@ public class GroupTypeOperation implements IGroupTypeOperation {
* @param groupTypeDefinition
* @return
*/
- private Either<GroupTypeData, JanusGraphOperationStatus> addGroupTypeToGraph(GroupTypeDefinition groupTypeDefinition) {
+ private Either<GroupTypeData, StorageOperationStatus> addGroupTypeToGraph(GroupTypeDefinition groupTypeDefinition) {
log.debug("Got group type {}", groupTypeDefinition);
- String ctUniqueId = UniqueIdBuilder.buildGroupTypeUid(groupTypeDefinition.getType(), groupTypeDefinition.getVersion(), "grouptype");
- GroupTypeData groupTypeData = buildGroupTypeData(groupTypeDefinition, ctUniqueId);
+ String gtUniqueId = UniqueIdBuilder.buildGroupTypeUid(groupTypeDefinition.getModel(), groupTypeDefinition.getType(),
+ groupTypeDefinition.getVersion(), "grouptype");
+ GroupTypeData groupTypeData = buildGroupTypeData(groupTypeDefinition, gtUniqueId);
log.debug("Before adding group type to graph. groupTypeData = {}", groupTypeData);
Either<GroupTypeData, JanusGraphOperationStatus> createGTResult = janusGraphGenericDao.createNode(groupTypeData, GroupTypeData.class);
log.debug("After adding group type to graph. status is = {}", createGTResult);
if (createGTResult.isRight()) {
JanusGraphOperationStatus operationStatus = createGTResult.right().value();
log.error("Failed to add group type {} to graph. status is {}", groupTypeDefinition.getType(), operationStatus);
- return Either.right(operationStatus);
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(operationStatus));
}
GroupTypeData resultCTD = createGTResult.left().value();
List<PropertyDefinition> properties = groupTypeDefinition.getProperties();
- Either<Map<String, PropertyData>, JanusGraphOperationStatus> addPropertiesToCapablityType = propertyOperation
+ Either<Map<String, PropertyData>, JanusGraphOperationStatus> addPropertiesToGroupType = propertyOperation
.addPropertiesToElementType(resultCTD.getUniqueId(), NodeTypeEnum.GroupType, properties);
- if (addPropertiesToCapablityType.isRight()) {
+ if (addPropertiesToGroupType.isRight()) {
log.error("Failed add properties {} to capability {}", properties, groupTypeDefinition.getType());
- return Either.right(addPropertiesToCapablityType.right().value());
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(addPropertiesToGroupType.right().value()));
}
String derivedFrom = groupTypeDefinition.getDerivedFrom();
if (derivedFrom != null) {
- Either<GraphRelation, JanusGraphOperationStatus> createRelation = connectToDerivedFrom(ctUniqueId, derivedFrom);
+ Either<GraphRelation, JanusGraphOperationStatus> createRelation = connectToDerivedFrom(gtUniqueId, derivedFrom);
if (createRelation.isRight()) {
- return Either.right(createRelation.right().value());
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(createRelation.right().value()));
}
}
Map<String, CapabilityDefinition> groupCapTypes = groupTypeDefinition.getCapabilities();
if (!MapUtils.isEmpty(groupCapTypes)) {
JanusGraphOperationStatus status = createCapabilities(groupTypeData, groupCapTypes);
if (status != JanusGraphOperationStatus.OK) {
- return Either.right(status);
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
}
}
+ final Either<GraphRelation, JanusGraphOperationStatus> modelRelationship = addGroupTypeToModel(groupTypeDefinition);
+ if (modelRelationship.isRight()) {
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(modelRelationship.right().value()));
+ }
return Either.left(createGTResult.left().value());
}
+ private Either<GraphRelation, JanusGraphOperationStatus> addGroupTypeToModel(final GroupTypeDefinition groupTypeDefinition) {
+ final String model = groupTypeDefinition.getModel();
+ if (model == null) {
+ return Either.left(null);
+ }
+ final GraphNode from = new UniqueIdData(NodeTypeEnum.Model, UniqueIdBuilder.buildModelUid(model));
+ final GraphNode to = new UniqueIdData(NodeTypeEnum.GroupType, groupTypeDefinition.getUniqueId());
+ log.info("Connecting model {} to type {}", from, to);
+ return janusGraphGenericDao.createRelation(from , to, GraphEdgeLabels.MODEL_ELEMENT, Collections.emptyMap());
+ }
+
private Either<GraphRelation, JanusGraphOperationStatus> connectToDerivedFrom(String ctUniqueId, String derivedFrom) {
log.debug("Before creating relation between Group Type with id {} to its parent {}", ctUniqueId, derivedFrom);
Either<GroupTypeData, JanusGraphOperationStatus> derivedFromGroupTypeResult = janusGraphGenericDao
@@ -598,14 +640,14 @@ public class GroupTypeOperation implements IGroupTypeOperation {
t -> t.getGroupTypeDataDefinition().getType());
}
- private Either<GraphRelation, StorageOperationStatus> addDerivedFromRelation(GroupTypeDataDefinition groupTypeDef, String gtUniqueId) {
+ private Either<GraphRelation, StorageOperationStatus> addDerivedFromRelation(GroupTypeDefinition groupTypeDef, String gtUniqueId) {
String derivedFrom = groupTypeDef.getDerivedFrom();
if (derivedFrom == null) {
return Either.left(null);
}
log.debug("#addDerivedFromRelationBefore - adding derived from relation between group type {} to its parent {}", groupTypeDef.getType(),
derivedFrom);
- return this.getLatestGroupTypeByType(derivedFrom, true).left().bind(
+ return this.getLatestGroupTypeByType(derivedFrom, groupTypeDef.getModel()).left().bind(
derivedFromGroup -> derivedFromOperation.addDerivedFromRelation(gtUniqueId, derivedFromGroup.getUniqueId(), NodeTypeEnum.GroupType));
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
index 03b531b3b1..9bc4cfc4b8 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
@@ -19,18 +19,24 @@
*/
package org.openecomp.sdc.be.model.operations.impl;
import static org.openecomp.sdc.be.dao.janusgraph.JanusGraphUtils.buildNotInPredicate;
+import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR;
import fj.data.Either;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
+import org.apache.commons.lang3.tuple.ImmutablePair;
import org.janusgraph.graphdb.query.JanusGraphPredicate;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
+import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.datatypes.elements.PolicyTypeDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -39,8 +45,10 @@ import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.operations.api.DerivedFromOperation;
import org.openecomp.sdc.be.model.operations.api.IPolicyTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.ModelData;
import org.openecomp.sdc.be.resources.data.PolicyTypeData;
import org.openecomp.sdc.be.resources.data.PropertyData;
+import org.openecomp.sdc.be.resources.data.UniqueIdData;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -66,6 +74,29 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp
return getPolicyTypeByCriteria(type, mapCriteria);
}
+ public Either<PolicyTypeDefinition, StorageOperationStatus> getLatestPolicyTypeByType(String type, String model) {
+ final Either<PolicyTypeData, JanusGraphOperationStatus> policyTypesRes = janusGraphGenericDao
+ .getNode(GraphPropertiesDictionary.TYPE.getProperty(), type, PolicyTypeData.class, model);
+ if (policyTypesRes.isRight()) {
+ final StorageOperationStatus status = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(policyTypesRes.right().value());
+ log.error("PolicyTypeData cannot be found in graph. status is {}", status);
+ return Either.right(status);
+ }
+ Either<PolicyTypeDefinition, StorageOperationStatus> policyTypeDefinition = getPolicyTypeByUid(policyTypesRes.left().value().getUniqueId());
+ if (policyTypeDefinition.isRight()) {
+ final StorageOperationStatus status = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(policyTypesRes.right().value());
+ log.error("PolicyTypeDefinition cannot be found in graph. status is {}", status);
+ return Either.right(status);
+ }
+ final Either<ImmutablePair<ModelData, GraphEdge>, JanusGraphOperationStatus> modelName = janusGraphGenericDao.getParentNode(
+ UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), policyTypesRes.left().value().getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT,
+ NodeTypeEnum.Model, ModelData.class);
+ if (modelName.isLeft()) {
+ policyTypeDefinition.left().value().setModel(modelName.left().value().getLeft().getName());
+ }
+ return policyTypeDefinition;
+ }
+
@Override
public Either<PolicyTypeDefinition, StorageOperationStatus> addPolicyType(PolicyTypeDefinition policyTypeDef) {
Either<PolicyTypeDefinition, StorageOperationStatus> result;
@@ -107,7 +138,7 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp
private Either<PolicyTypeData, StorageOperationStatus> addPolicyTypeToGraph(PolicyTypeDefinition policyTypeDef) {
log.debug("Got policy type {}", policyTypeDef);
- String ptUniqueId = UniqueIdBuilder.buildPolicyTypeUid(policyTypeDef.getType(), policyTypeDef.getVersion(), "policytype");
+ String ptUniqueId = UniqueIdBuilder.buildPolicyTypeUid(policyTypeDef.getModel(), policyTypeDef.getType(), policyTypeDef.getVersion(), "policytype");
PolicyTypeData policyTypeData = buildPolicyTypeData(policyTypeDef, ptUniqueId);
log.debug("Before adding policy type to graph. policyTypeData = {}", policyTypeData);
Either<PolicyTypeData, JanusGraphOperationStatus> eitherPolicyTypeData = janusGraphGenericDao
@@ -125,9 +156,26 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp
log.error("Failed add properties {} to policy {}", properties, policyTypeDef.getType());
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(addPropertiesToPolicyType.right().value()));
}
+
+ final Either<GraphRelation, StorageOperationStatus> modelRelationship = addPolicyTypeToModel(policyTypeDef);
+ if (modelRelationship.isRight()) {
+ return Either.right(modelRelationship.right().value());
+ }
+
return addDerivedFromRelation(policyTypeDef, ptUniqueId).left().map(updatedDerivedFrom -> eitherPolicyTypeData.left().value());
}
+ private Either<GraphRelation, StorageOperationStatus> addPolicyTypeToModel(final PolicyTypeDefinition policyTypeDefinition) {
+ final String model = policyTypeDefinition.getModel();
+ if (model == null) {
+ return Either.left(null);
+ }
+ final GraphNode from = new UniqueIdData(NodeTypeEnum.Model, UniqueIdBuilder.buildModelUid(model));
+ final GraphNode to = new UniqueIdData(NodeTypeEnum.PolicyType, policyTypeDefinition.getUniqueId());
+ log.info("Connecting model {} to type {}", from, to);
+ return janusGraphGenericDao.createRelation(from , to, GraphEdgeLabels.MODEL_ELEMENT, Collections.emptyMap()).right().map(DaoStatusConverter::convertJanusGraphStatusToStorageStatus);
+ }
+
private Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeByCriteria(String type, Map<String, Object> properties) {
Either<PolicyTypeDefinition, StorageOperationStatus> result;
if (type == null || type.isEmpty()) {
@@ -253,14 +301,14 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp
return addDerivedFromRelation(updatedPolicyType, policyTypeId);
}
- private Either<GraphRelation, StorageOperationStatus> addDerivedFromRelation(PolicyTypeDataDefinition policyTypeDef, String ptUniqueId) {
+ private Either<GraphRelation, StorageOperationStatus> addDerivedFromRelation(PolicyTypeDefinition policyTypeDef, String ptUniqueId) {
String derivedFrom = policyTypeDef.getDerivedFrom();
if (derivedFrom == null) {
return Either.left(null);
}
log.debug("#addDerivedFromRelationBefore - adding derived from relation between policy type {} to its parent {}", policyTypeDef.getType(),
derivedFrom);
- return this.getLatestPolicyTypeByType(derivedFrom).left().bind(
+ return this.getLatestPolicyTypeByType(derivedFrom, policyTypeDef.getModel()).left().bind(
derivedFromPolicy -> derivedFromOperation.addDerivedFromRelation(ptUniqueId, derivedFromPolicy.getUniqueId(), NodeTypeEnum.PolicyType));
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java
index 72fdffab14..a433698ce5 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java
@@ -184,12 +184,19 @@ public class UniqueIdBuilder {
return generateUUID();
}
- static String buildGroupTypeUid(String type, String version, String resourceName) {
- return buildTypeUid(type, version, resourceName);
+ public static String buildGroupTypeUid(String modelName, String type, String version, String resourceName) {
+ return buildTypeUidWithModel(modelName, type, version, resourceName);
}
- static String buildPolicyTypeUid(String type, String version, String resourceName) {
- return buildTypeUid(type, version, resourceName);
+ public static String buildPolicyTypeUid(String modelName, String type, String version, String resourceName) {
+ return buildTypeUidWithModel(modelName, type, version, resourceName);
+ }
+
+ static String buildTypeUidWithModel(String modelName, String type, String version, String resourceName) {
+ if (StringUtils.isEmpty(modelName)){
+ return buildTypeUid(type, version, resourceName);
+ }
+ return modelName + DOT + buildTypeUid(type, version, resourceName);
}
static String buildTypeUid(String type, String version, String resourceName) {