diff options
author | davsad <david.sadlier@est.tech> | 2021-06-16 10:36:24 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2021-07-21 14:12:28 +0000 |
commit | a3da4a7625f75f719a0ef1ffe1c2bef87828d2f3 (patch) | |
tree | 2673985092a7ae9e2fb2acccdfa48afff6b2c4f1 /catalog-model/src/main | |
parent | 8a312e6cf2bc0a0c539712b03e75ca3fcfe909ff (diff) |
Support for associating interface types to models
Issue-ID: SDC-3639
Change-Id: I5eaa9ffbe3c88416bf17ff9a94e76faad79fe888
Signed-off-by: davsad <david.sadlier@est.tech>
Diffstat (limited to 'catalog-model/src/main')
3 files changed, 54 insertions, 10 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceDefinition.java index f4b0e8e522..13d80df4ea 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceDefinition.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/InterfaceDefinition.java @@ -19,23 +19,30 @@ */ package org.openecomp.sdc.be.model; -import com.fasterxml.jackson.annotation.JsonIgnore; import java.util.Map; import java.util.stream.Collectors; + import org.apache.commons.collections.MapUtils; import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; +import com.fasterxml.jackson.annotation.JsonIgnore; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + /** * Definition of the operations that can be performed on (instances of) a Node Type. * * @author esofer */ +@NoArgsConstructor public class InterfaceDefinition extends InterfaceDataDefinition implements IOperationParameter { - public InterfaceDefinition() { - super(); - } + @Getter + @Setter + private String model; public InterfaceDefinition(String type, String description, Map<String, Operation> operations) { super(type, description); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java index a4d8ac9152..3fa1f8933d 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperation.java @@ -19,7 +19,6 @@ */ package org.openecomp.sdc.be.model.operations.impl; -import fj.data.Either; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -28,8 +27,10 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.stream.Collectors; + import org.apache.commons.lang3.tuple.ImmutablePair; 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; @@ -45,11 +46,15 @@ import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.resources.data.ArtifactData; import org.openecomp.sdc.be.resources.data.InterfaceData; +import org.openecomp.sdc.be.resources.data.ModelData; import org.openecomp.sdc.be.resources.data.OperationData; import org.openecomp.sdc.be.resources.data.ResourceMetadataData; +import org.openecomp.sdc.be.resources.data.UniqueIdData; import org.openecomp.sdc.common.log.wrappers.Logger; import org.springframework.stereotype.Component; +import fj.data.Either; + @Component("interface-operation") public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation { @@ -96,7 +101,9 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation private InterfaceDefinition convertInterfaceDataToInterfaceDefinition(InterfaceData interfaceData) { log.debug("The object returned after create interface is {}", interfaceData); - return new InterfaceDefinition(interfaceData.getInterfaceDataDefinition()); + final InterfaceDefinition interfaceDefinition = new InterfaceDefinition(interfaceData.getInterfaceDataDefinition()); + interfaceDefinition.setModel(getModelAssociatedToInterface(interfaceData.getUniqueId())); + return interfaceDefinition; } private Operation convertOperationDataToOperation(OperationData operationData) { @@ -743,8 +750,8 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation public Either<InterfaceDefinition, StorageOperationStatus> createInterfaceType(InterfaceDefinition interf, boolean inTransaction) { Either<InterfaceDefinition, StorageOperationStatus> result = null; try { + interf.setUniqueId(UniqueIdBuilder.buildInterfaceTypeUid(interf.getModel(), interf.getType())); InterfaceData interfaceData = new InterfaceData(interf); - interf.setUniqueId(interf.getType().toLowerCase()); Either<InterfaceData, JanusGraphOperationStatus> existInterface = janusGraphGenericDao .getNode(interfaceData.getUniqueIdKey(), interfaceData.getUniqueId(), InterfaceData.class); if (existInterface.isLeft()) { @@ -753,7 +760,6 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation result = Either.right(StorageOperationStatus.ENTITY_ALREADY_EXISTS); return result; } - log.debug("Before adding interface type to graph {}", interfaceData); Either<InterfaceData, JanusGraphOperationStatus> createNodeResult = janusGraphGenericDao.createNode(interfaceData, InterfaceData.class); log.debug("After adding property type to graph {}", interfaceData); if (createNodeResult.isRight()) { @@ -782,6 +788,11 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation } interfaceDefResult.setOperationsMap(newOperations); } + final Either<GraphRelation, StorageOperationStatus> modelRelationship = addInterfaceTypeToModel(interf); + if (modelRelationship.isRight()) { + return Either.right(modelRelationship.right().value()); + } + result = Either.left(interfaceDefResult); return result; } finally { @@ -797,6 +808,17 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation } } + private Either<GraphRelation, StorageOperationStatus> addInterfaceTypeToModel(final InterfaceDefinition interfaceDefinition) { + final String model = interfaceDefinition.getModel(); + if (model == null) { + return Either.left(null); + } + final GraphNode from = new UniqueIdData(NodeTypeEnum.Model, UniqueIdBuilder.buildModelUid(model)); + final GraphNode to = new UniqueIdData(NodeTypeEnum.Interface, interfaceDefinition.getUniqueId()); + log.info("Connecting model {} to type {}", from, to); + return janusGraphGenericDao.createRelation(from , to, GraphEdgeLabels.MODEL_ELEMENT, Collections.emptyMap()).right().map(DaoStatusConverter::convertJanusGraphStatusToStorageStatus); + } + @Override public Either<InterfaceDefinition, StorageOperationStatus> getInterface(String interfaceId) { Either<InterfaceData, JanusGraphOperationStatus> getResult = janusGraphGenericDao @@ -837,8 +859,9 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation Map<String, InterfaceDefinition> interfaceTypes = new HashMap<>(); List<InterfaceData> interfaceDataList = allInterfaceLifecycleTypes.left().value(); List<InterfaceDefinition> interfaceDefinitions = interfaceDataList.stream().map(this::convertInterfaceDataToInterfaceDefinition) - .filter(interfaceDefinition -> interfaceDefinition.getUniqueId().equalsIgnoreCase((interfaceDefinition.getType()))) - .collect(Collectors.toList()); + .filter(interfaceDefinition -> interfaceDefinition.getUniqueId() + .equalsIgnoreCase(UniqueIdBuilder.buildInterfaceTypeUid(interfaceDefinition.getModel(), interfaceDefinition.getType())) + ).collect(Collectors.toList()); for (InterfaceDefinition interfaceDefinition : interfaceDefinitions) { Either<List<ImmutablePair<OperationData, GraphEdge>>, JanusGraphOperationStatus> childrenNodes = janusGraphGenericDao .getChildrenNodes(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), interfaceDefinition.getUniqueId(), @@ -855,4 +878,14 @@ public class InterfaceLifecycleOperation implements IInterfaceLifecycleOperation } return Either.left(interfaceTypes); } + + private String getModelAssociatedToInterface(String uid) { + final Either<ImmutablePair<ModelData, GraphEdge>, JanusGraphOperationStatus> model = janusGraphGenericDao.getParentNode( + UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Interface), uid, GraphEdgeLabels.MODEL_ELEMENT, + NodeTypeEnum.Model, ModelData.class); + if (model.isLeft()) { + return model.left().value().getLeft().getName(); + } + return null; + } } 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 a433698ce5..8f1cbae1bb 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 @@ -97,6 +97,10 @@ public class UniqueIdBuilder { return StringUtils.isEmpty(modelName) ? type : modelName + DOT + type; } + public static String buildInterfaceTypeUid(final String modelName, String type) { + return StringUtils.isEmpty(modelName) ? type : modelName + DOT + type; + } + public static String buildAttributeUid(String resourceId, String attName) { return buildTypeUid(NodeTypeEnum.Attribute.getName(), resourceId, attName); } |