From a5e32b3d20bc078482cb08645c38ffb685c0f145 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Fri, 20 Aug 2021 15:40:35 +0100 Subject: Support querying of model by type Signed-off-by: MichaelMorris Issue-ID: SDC-3678 Change-Id: I5fd19eefe475113df501901628b2ee8669004399 --- .../java/org/openecomp/sdc/be/model/Model.java | 7 +++++++ .../operations/ToscaOperationFacade.java | 24 ++++++++++++---------- .../exception/ModelOperationExceptionSupplier.java | 4 ++++ .../be/model/operations/impl/ModelOperation.java | 20 +++++++++++++----- .../sdc/be/ui/model/ModelCreateRequest.java | 4 ++++ 5 files changed, 43 insertions(+), 16 deletions(-) (limited to 'catalog-model/src/main/java') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Model.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Model.java index 9c07c0565c..f551f252c7 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Model.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Model.java @@ -18,6 +18,7 @@ */ package org.openecomp.sdc.be.model; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import com.googlecode.jmapper.annotations.JGlobalMap; import lombok.AllArgsConstructor; import lombok.Data; @@ -31,9 +32,15 @@ public class Model { private String name; private String derivedFrom; + private ModelTypeEnum modelType; public Model(final String name) { this.name = name; } + + public Model(final String name, final ModelTypeEnum modelType) { + this.name = name; + this.modelType = modelType; + } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java index bd61f61a49..b2ccb6d0ac 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java @@ -1935,17 +1935,18 @@ public class ToscaOperationFacade { return fetchServicesByCriteria(services, hasProps, hasNotProps, modelName); } - private Either, StorageOperationStatus> getLatestVersionNotAbstractToscaElementsMetadataOnly(boolean isAbstract, - ComponentTypeEnum componentTypeEnum, - String internalComponentType, - VertexTypeEnum vertexType, - String modelName) { + private Either, StorageOperationStatus> getLatestVersionNotAbstractToscaElementsMetadataOnly(final boolean isAbstract, + final ComponentTypeEnum componentTypeEnum, + final String internalComponentType, + final VertexTypeEnum vertexType, + final String modelName, + final boolean includeNormativeExtensionModels) { List services = null; Map hasProps = new EnumMap<>(GraphPropertyEnum.class); Map hasNotProps = new EnumMap<>(GraphPropertyEnum.class); fillPropsMap(hasProps, hasNotProps, internalComponentType, componentTypeEnum, isAbstract, vertexType, modelName); Either, JanusGraphOperationStatus> getRes = janusGraphDao - .getByCriteria(vertexType, hasProps, hasNotProps, JsonParseFlagEnum.ParseMetadata, modelName); + .getByCriteria(vertexType, hasProps, hasNotProps, JsonParseFlagEnum.ParseMetadata, modelName, includeNormativeExtensionModels); if (getRes.isRight() && !JanusGraphOperationStatus.NOT_FOUND.equals(getRes.right().value())) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value())); } @@ -2070,7 +2071,7 @@ public class ToscaOperationFacade { private Either, StorageOperationStatus> getComponentUids(boolean isAbstract, ComponentTypeEnum componentTypeEnum, String internalComponentType) { Either, StorageOperationStatus> getToscaElementsRes = getLatestVersionNotAbstractMetadataOnly(isAbstract, componentTypeEnum, - internalComponentType, null); + internalComponentType, null, false); if (getToscaElementsRes.isRight()) { return Either.right(getToscaElementsRes.right().value()); } @@ -2214,14 +2215,15 @@ public class ToscaOperationFacade { } public Either, StorageOperationStatus> getLatestVersionNotAbstractMetadataOnly(boolean isAbstract, - ComponentTypeEnum componentTypeEnum, - String internalComponentType, - String modelName) { + final ComponentTypeEnum componentTypeEnum, + final String internalComponentType, + final String modelName, + final boolean includeNormativeExtensionModels) { List internalVertexTypes = getInternalVertexTypes(componentTypeEnum, internalComponentType); List result = new ArrayList<>(); for (VertexTypeEnum vertexType : internalVertexTypes) { Either, StorageOperationStatus> listByVertexType = getLatestVersionNotAbstractToscaElementsMetadataOnly(isAbstract, - componentTypeEnum, internalComponentType, vertexType, modelName); + componentTypeEnum, internalComponentType, vertexType, modelName, includeNormativeExtensionModels); if (listByVertexType.isRight()) { return listByVertexType; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ModelOperationExceptionSupplier.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ModelOperationExceptionSupplier.java index 6622bf5bd8..68e098bd69 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ModelOperationExceptionSupplier.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/exception/ModelOperationExceptionSupplier.java @@ -52,5 +52,9 @@ public class ModelOperationExceptionSupplier { var errorMsg = String.format("Failed to retrieve models. Status '%s'", janusGraphOperationStatus); return () -> new OperationException(ActionStatus.GENERAL_ERROR, errorMsg); } + + public static Supplier unknownModelType(final String modelType) { + return () -> new OperationException(ActionStatus.UNKNOWN_MODEL_TYPE, modelType); + } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java index ce1f574e93..d522e10d7c 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java @@ -46,6 +46,7 @@ import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; import org.openecomp.sdc.be.data.model.ToscaImportByModel; import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.model.Model; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ModelOperationExceptionSupplier; @@ -83,7 +84,7 @@ public class ModelOperation { public Model createModel(final Model model, final boolean inTransaction) { Model result = null; - final var modelData = new ModelData(model.getName(), UniqueIdBuilder.buildModelUid(model.getName())); + final var modelData = new ModelData(model.getName(), UniqueIdBuilder.buildModelUid(model.getName()), model.getModelType()); try { final Either createNode = janusGraphGenericDao.createNode(modelData, ModelData.class); if (createNode.isRight()) { @@ -97,7 +98,7 @@ public class ModelOperation { String.format("Failed to create model %s on JanusGraph with %s error", model, janusGraphOperationStatus)); } addDerivedFromRelation(model); - result = new Model(createNode.left().value().getName(), model.getDerivedFrom()); + result = new Model(createNode.left().value().getName(), model.getDerivedFrom(), model.getModelType()); return result; } finally { if (!inTransaction) { @@ -183,6 +184,13 @@ public class ModelOperation { public List findAllModels() { return findModelsByCriteria(Collections.emptyMap()); } + + public List findModels(final ModelTypeEnum modelType) { + final Map propertyCriteria = new EnumMap<>(GraphPropertyEnum.class); + propertyCriteria.put(GraphPropertyEnum.MODEL_TYPE, modelType.getValue()); + + return findModelsByCriteria(propertyCriteria); + } private List findModelsByCriteria(final Map propertyCriteria) { final List modelVerticesByCriteria = findModelVerticesByCriteria(propertyCriteria); @@ -209,7 +217,9 @@ public class ModelOperation { private Model convertToModel(final GraphVertex modelGraphVertex) { final String modelName = (String) modelGraphVertex.getMetadataProperty(GraphPropertyEnum.NAME); - + final String modelTypeProperty = (String) modelGraphVertex.getMetadataProperty(GraphPropertyEnum.MODEL_TYPE); + final ModelTypeEnum modelType = StringUtils.isEmpty(modelTypeProperty) ? ModelTypeEnum.NORMATIVE : ModelTypeEnum.findByValue(modelTypeProperty).get(); + final Either, JanusGraphOperationStatus> parentNode = janusGraphGenericDao.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Model), UniqueIdBuilder.buildModelUid(modelName), GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.Model, ModelData.class); @@ -221,10 +231,10 @@ public class ModelOperation { log.error(EcompLoggerErrorCode.DATA_ERROR, this.getClass().getName(), operationException.getMessage()); throw operationException; } - return new Model((String) modelGraphVertex.getMetadataProperty(GraphPropertyEnum.NAME)); + return new Model((String) modelGraphVertex.getMetadataProperty(GraphPropertyEnum.NAME), modelType); } else { final ModelData parentModel = parentNode.left().value().getKey(); - return new Model((String) modelGraphVertex.getMetadataProperty(GraphPropertyEnum.NAME), parentModel.getName()); + return new Model((String) modelGraphVertex.getMetadataProperty(GraphPropertyEnum.NAME), parentModel.getName(), modelType); } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/ModelCreateRequest.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/ModelCreateRequest.java index 685d95e4ab..8c2ee302f7 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/ModelCreateRequest.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/ModelCreateRequest.java @@ -20,6 +20,7 @@ package org.openecomp.sdc.be.ui.model; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -36,4 +37,7 @@ public class ModelCreateRequest { private String name; private String derivedFrom; + + private ModelTypeEnum modelType; + } -- cgit 1.2.3-korg