diff options
author | MichaelMorris <michael.morris@est.tech> | 2021-08-20 15:40:35 +0100 |
---|---|---|
committer | Andr� Schmid <andre.schmid@est.tech> | 2021-08-27 10:33:32 +0000 |
commit | a5e32b3d20bc078482cb08645c38ffb685c0f145 (patch) | |
tree | 133fe88578f3a3c3db3ec73315b65f45caba625a | |
parent | 4701612ba26c4b8c7c7e9fbfa38f582a4b74669f (diff) |
Support querying of model by type
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-3678
Change-Id: I5fd19eefe475113df501901628b2ee8669004399
32 files changed, 229 insertions, 67 deletions
diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml index 563594a728..b161c4a006 100644 --- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml +++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml @@ -2546,6 +2546,14 @@ errors: message: "Error: Could not fetch data types from data base with model %1", messageId: "SVC4153" } + + #-----------SVC4154--------------------------- + # %1 - "Model name" + UNKNOWN_MODEL_TYPE: { + code: 400, + message: "Error: Model type %1 not known in the system", + messageId: "SVC4154" + } #-----------SVC4154--------------------------- CSAR_TOSCA_IMPORTS_ERROR: { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java index 7d4ba3bf77..8d202092b5 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java @@ -423,16 +423,17 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { } } - public Either<List<Component>, ResponseFormat> getLatestVersionNotAbstractComponentsMetadata(boolean isAbstractAbstract, - HighestFilterEnum highestFilter, - ComponentTypeEnum componentTypeEnum, - String internalComponentType, String userId, - String modelName) { + public Either<List<Component>, ResponseFormat> getLatestVersionNotAbstractComponentsMetadata(final boolean isAbstractAbstract, + final HighestFilterEnum highestFilter, + final ComponentTypeEnum componentTypeEnum, + final String internalComponentType, String userId, + final String modelName, + final boolean includeNormativeExtensionModels) { Either<List<Component>, StorageOperationStatus> nonCheckoutCompResponse = null; try { validateUserExists(userId); nonCheckoutCompResponse = toscaOperationFacade - .getLatestVersionNotAbstractMetadataOnly(isAbstractAbstract, componentTypeEnum, internalComponentType, modelName); + .getLatestVersionNotAbstractMetadataOnly(isAbstractAbstract, componentTypeEnum, internalComponentType, modelName, includeNormativeExtensionModels); if (nonCheckoutCompResponse.isLeft()) { log.debug("Retrieved Resource successfully."); return Either.left(nonCheckoutCompResponse.left().value()); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java index 1d34f39b74..3951be2d58 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import org.apache.commons.lang3.StringUtils; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import org.openecomp.sdc.be.model.Model; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ModelOperationExceptionSupplier; import org.openecomp.sdc.be.model.operations.impl.ModelOperation; @@ -77,6 +78,10 @@ public class ModelBusinessLogic { public List<Model> listModels() { return modelOperation.findAllModels(); } + + public List<Model> listModels(final ModelTypeEnum modelType) { + return modelOperation.findModels(modelType); + } public void createModelImports(final String modelName, final InputStream modelImportsZip) { if (StringUtils.isEmpty(modelName)) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index 9bb4f62f01..49cd95831c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -98,6 +98,7 @@ import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.CreatedFrom; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; @@ -1040,7 +1041,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } if (MapUtils.isNotEmpty(dataTypesToCreate)) { final String nameForGeneratedModel = resource.getModel() + "_" + csarInfo.getVfResourceName() + resource.getCsarVersion(); - final Model model = new Model(nameForGeneratedModel, resource.getModel()); + final Model model = new Model(nameForGeneratedModel, resource.getModel(), ModelTypeEnum.NORMATIVE_EXTENSION); modelBusinessLogic.createModel(model, new Yaml().dump(dataTypesToCreate)); resource.setModel(nameForGeneratedModel); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java index 7fd667d147..e60d7d53ba 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java @@ -250,6 +250,7 @@ public class ComponentServlet extends BeGenericServlet { @Context final HttpServletRequest request, @QueryParam("internalComponentType") String internalComponentType, @QueryParam("componentModel") String internalComponentModel, + @QueryParam("includeNormativeExtensionModels") boolean includeNormativeExtensionModels, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Parameter(description = "uid list", required = true) String data) throws IOException { @@ -263,7 +264,7 @@ public class ComponentServlet extends BeGenericServlet { } Either<List<Component>, ResponseFormat> actionResponse = businessLogic .getLatestVersionNotAbstractComponentsMetadata(false, HighestFilterEnum.HIGHEST_ONLY, componentTypeEnum, - internalComponentType, userId, internalComponentModel); + internalComponentType, userId, internalComponentModel, includeNormativeExtensionModels); if (actionResponse.isRight()) { log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, componentType); return buildErrorResponse(actionResponse.right().value()); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ModelServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ModelServlet.java index 337c641b33..6449a91112 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ModelServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ModelServlet.java @@ -41,9 +41,11 @@ import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; +import org.apache.commons.lang3.StringUtils; import org.glassfish.jersey.media.multipart.FormDataParam; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.ModelBusinessLogic; @@ -53,10 +55,12 @@ import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import org.openecomp.sdc.be.exception.BusinessException; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.model.Model; +import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ModelOperationExceptionSupplier; import org.openecomp.sdc.be.ui.model.ModelCreateRequest; import org.openecomp.sdc.be.user.Role; import org.openecomp.sdc.be.user.UserBusinessLogic; @@ -108,6 +112,9 @@ public class ModelServlet extends AbstractValidationsServlet { validateUser(ValidationUtils.sanitizeInputString(userId)); final var modelName = ValidationUtils.sanitizeInputString(modelCreateRequest.getName().trim()); try { + if (modelCreateRequest.getModelType() == null){ + modelCreateRequest.setModelType(ModelTypeEnum.NORMATIVE); + } final Model createdModel = modelBusinessLogic .createModel(new JMapper<>(Model.class, ModelCreateRequest.class).getDestination(modelCreateRequest)); modelBusinessLogic.createModelImports(modelName, modelImportsZip); @@ -134,10 +141,10 @@ public class ModelServlet extends AbstractValidationsServlet { @ApiResponse(responseCode = "403", description = "Restricted operation") } ) - public Response listModels(@HeaderParam(value = Constants.USER_ID_HEADER) final String userId) { + public Response listModels(@HeaderParam(value = Constants.USER_ID_HEADER) final String userId, @QueryParam("modelType") final String modelType) { validateUser(ValidationUtils.sanitizeInputString(userId)); try { - final List<Model> modelList = modelBusinessLogic.listModels(); + final List<Model> modelList = StringUtils.isEmpty(modelType)? modelBusinessLogic.listModels() : modelBusinessLogic.listModels(getModelTypeEnum(modelType)); return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), RepresentationUtils.toRepresentation(modelList)); } catch (final BusinessException e) { throw e; @@ -148,6 +155,14 @@ public class ModelServlet extends AbstractValidationsServlet { return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); } } + + private ModelTypeEnum getModelTypeEnum(final String modelType) { + final ModelTypeEnum modelTypeEnum = ModelTypeEnum.valueOf(modelType.toUpperCase()); + if (modelTypeEnum == null) { + throw ModelOperationExceptionSupplier.unknownModelType(modelType).get(); + } + return modelTypeEnum; + } @PUT @Path("/model/imports") diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java index 1c7fe2d470..097398455f 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java @@ -318,7 +318,7 @@ public class TypesFetchServlet extends AbstractValidationsServlet { List<Component> componentList; actionResponse = resourceBL .getLatestVersionNotAbstractComponentsMetadata(isAbstract, HighestFilterEnum.HIGHEST_ONLY, ComponentTypeEnum.RESOURCE, null, userId, - null); + null, false); if (actionResponse.isRight()) { log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, ComponentTypeEnum.RESOURCE.getValue()); return Either.right(buildErrorResponse(actionResponse.right().value())); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java index fda7c0807e..2f4239f9cf 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java @@ -1499,7 +1499,6 @@ public class ResourceBusinessLogicTest { vduCp.getProperties().add(roleProp); when(toscaOperationFacade.getLatestByToscaResourceNameAndModel("tosca.nodes.nfv.VduCp", "testModel_myVnf1.0")).thenReturn(Either.left(vduCp)); - when(yamlTemplateParsingHandler.parseResourceInfoFromYAML(any(), any(), any(), any(), any(), any())).thenReturn(parsedToscaYamlInfo); UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java index 66399a49f7..4465997c4a 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java @@ -54,6 +54,7 @@ public enum ActionStatus { // Model related MODEL_ALREADY_EXISTS, INVALID_MODEL, MODEL_IMPORTS_IS_EMPTY, COULD_NOT_READ_MODEL_IMPORTS, MODEL_NOT_FOUND, MODEL_NAME_CANNOT_BE_EMPTY, COMPONENT_WITH_MODEL_ALREADY_EXIST, COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS, COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS_IN_MODEL, + UNKNOWN_MODEL_TYPE, // Service API URL INVALID_SERVICE_API_URL, // Property related diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphDao.java index 5d0c4cffb6..449a4968e8 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphDao.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphDao.java @@ -58,6 +58,7 @@ import org.openecomp.sdc.be.dao.jsongraph.utils.JsonParserUtils; import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; import org.openecomp.sdc.common.jsongraph.util.CommonUtility; import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum; @@ -442,12 +443,29 @@ public class JanusGraphDao { return Either.right(graph.right().value()); } } + + public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(final VertexTypeEnum type, final Map<GraphPropertyEnum, Object> props, + final Map<GraphPropertyEnum, Object> hasNotProps, + final JsonParseFlagEnum parseFlag, + final String model) { + return getByCriteria(type, props, hasNotProps, null, parseFlag, model, false); + } - public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(VertexTypeEnum type, Map<GraphPropertyEnum, Object> props, - Map<GraphPropertyEnum, Object> hasNotProps, - JsonParseFlagEnum parseFlag, - String model) { - return getByCriteria(type, props, hasNotProps, null, parseFlag, model); + public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(final VertexTypeEnum type, final Map<GraphPropertyEnum, Object> props, + final Map<GraphPropertyEnum, Object> hasNotProps, + final JsonParseFlagEnum parseFlag, + final String model, + final boolean includeNormativeExtensionModels) { + return getByCriteria(type, props, hasNotProps, null, parseFlag, model, includeNormativeExtensionModels); + } + + public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(final VertexTypeEnum type, + final Map<GraphPropertyEnum, Object> hasProps, + final Map<GraphPropertyEnum, Object> hasNotProps, + final Map<String, Entry<JanusGraphPredicate, Object>> predicates, + final JsonParseFlagEnum parseFlag, + final String model) { + return getByCriteria(type, hasProps, hasNotProps, predicates, parseFlag, model, false); } public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(final VertexTypeEnum type, @@ -455,7 +473,8 @@ public class JanusGraphDao { final Map<GraphPropertyEnum, Object> hasNotProps, final Map<String, Entry<JanusGraphPredicate, Object>> predicates, final JsonParseFlagEnum parseFlag, - final String model) { + final String model, + final boolean includeNormativeExtensionModels) { Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph(); if (graph.isLeft()) { try { @@ -492,7 +511,7 @@ public class JanusGraphDao { } List<GraphVertex> result = new ArrayList<>(); - final Predicate<? super JanusGraphVertex> filterPredicate = StringUtils.isEmpty(model) ? this::vertexNotConnectedToAnyModel : vertex -> vertexValidForModel(vertex, model); + final Predicate<? super JanusGraphVertex> filterPredicate = StringUtils.isEmpty(model) ? this::vertexNotConnectedToAnyModel : vertex -> vertexValidForModel(vertex, model, includeNormativeExtensionModels); final List<JanusGraphVertex> verticesForModel = StreamSupport.stream(vertices.spliterator(), false).filter(filterPredicate).collect(Collectors.toList()); if (verticesForModel == null || verticesForModel.size() == 0) { return Either.right(JanusGraphOperationStatus.NOT_FOUND); @@ -585,22 +604,35 @@ public class JanusGraphDao { } } - private boolean vertexValidForModel(final JanusGraphVertex vertex, final String model) { + private boolean vertexValidForModel(final JanusGraphVertex vertex, final String model, final boolean includeNormativeExtensions) { final String vertexLabel = (String)vertex.property(GraphPropertyEnum.LABEL.getProperty()).value(); final VertexTypeEnum vertexType = VertexTypeEnum.getByName(vertexLabel); final GraphEdgeLabels edgeLabel = vertexType.equals(VertexTypeEnum.TOPOLOGY_TEMPLATE) ? GraphEdgeLabels.MODEL : GraphEdgeLabels.MODEL_ELEMENT; final Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> modelVertices = getParentVerticies(vertex, edgeLabel); - return modelVertices.isLeft() && modelVertices.left().value().stream().anyMatch(vertexPair -> modelVertexMatchesModel(vertexPair.getLeft(), model)); + return modelVertices.isLeft() && modelVertices.left().value().stream().anyMatch(vertexPair -> modelVertexMatchesModel(vertexPair.getLeft(), model, includeNormativeExtensions)); } - private boolean modelVertexMatchesModel(final JanusGraphVertex modelVertex, final String model) { + private boolean modelVertexMatchesModel(final JanusGraphVertex modelVertex, final String model, final boolean includeNormativeExtensions) { if (model.equals((String)modelVertex.property("name").value())) { return true; } final Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> derivedModels = getParentVerticies(modelVertex, GraphEdgeLabels.DERIVED_FROM); - return derivedModels.isLeft() && derivedModels.left().value().stream().anyMatch(derivedModel ->modelVertexMatchesModel(derivedModel.left, model)); + if (derivedModels.isLeft() && derivedModels.left().value().stream().anyMatch(derivedModel ->modelVertexMatchesModel(derivedModel.left, model, includeNormativeExtensions))) { + return true; + } + + if (includeNormativeExtensions && isANormativeExtension(modelVertex)) { + final Either<List<Vertex>,JanusGraphOperationStatus> derivedFromModels = + getChildrenVertices(modelVertex, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.ParseAll); + return derivedFromModels.isLeft() && derivedFromModels.left().value().stream().anyMatch(derivedFromModel -> model.equals((String)derivedFromModel.property("name").value())); + } + return false; + } + + private boolean isANormativeExtension(final JanusGraphVertex modelVertex) { + return ModelTypeEnum.NORMATIVE_EXTENSION.getValue().equals((String)modelVertex.property(GraphPropertyEnum.MODEL_TYPE.getProperty()).value()); } private Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> getParentVerticies( diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java index cbfee5e799..03016f793f 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java @@ -50,7 +50,8 @@ public enum GraphPropertiesDictionary { CONTACT_ID ("contactId", String.class, false, false), VENDOR_NAME ("vendorName", String.class, false, false), VENDOR_RELEASE ("vendorRelease", String.class, false, false), - MODEL ("model", String.class, false, false), + MODEL ("model", String.class, false, false), + MODEL_TYPE ("modelType", String.class, false, false), CONFORMANCE_LEVEL ("conformanceLevel", String.class, false, false), ICON ("icon", String.class, false, false), TAGS ("tags", String.class, false, false), diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ModelData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ModelData.java index 026b1d7998..5f7b15e043 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ModelData.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ModelData.java @@ -23,6 +23,7 @@ import java.util.Map; import lombok.Getter; import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; @Getter @@ -30,17 +31,20 @@ public class ModelData extends GraphNode { private final String name; private final String uniqueId; + private final String modelType; - public ModelData(final String name, final String uniqueId) { + public ModelData(final String name, final String uniqueId, final ModelTypeEnum modelType) { super(NodeTypeEnum.Model); this.name = name; this.uniqueId = uniqueId; + this.modelType = modelType.getValue(); } public ModelData(final Map<String, Object> properties) { super(NodeTypeEnum.Model); name = (String) properties.get(GraphPropertiesDictionary.NAME.getProperty()); uniqueId = (String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()); + modelType = (String) properties.get(GraphPropertiesDictionary.MODEL_TYPE.getProperty()); } @Override @@ -48,6 +52,7 @@ public class ModelData extends GraphNode { final Map<String, Object> map = new HashMap<>(); addIfExists(map, GraphPropertiesDictionary.NAME, name); addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, uniqueId); + addIfExists(map, GraphPropertiesDictionary.MODEL_TYPE, modelType); return map; } diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/ModelDataTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/ModelDataTest.java index 1fb34dd5e6..f011e36509 100644 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/ModelDataTest.java +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/ModelDataTest.java @@ -27,17 +27,19 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance.Lifecycle; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; @TestInstance(Lifecycle.PER_CLASS) class ModelDataTest { private final String modelName = "ETSI-SDC-MODEL-TEST"; private final String modelId = UUID.randomUUID().toString(); + private final ModelTypeEnum modelType = ModelTypeEnum.NORMATIVE; ModelData modelData; @BeforeAll void initTestData() { - modelData = new ModelData(modelName, modelId); + modelData = new ModelData(modelName, modelId, modelType); } @Test @@ -45,17 +47,20 @@ class ModelDataTest { assertThat(modelData).isNotNull(); assertThat(modelData.getUniqueId()).isEqualTo(modelId); assertThat(modelData.getName()).isEqualTo(modelName); + assertThat(modelData.getModelType()).isEqualTo(modelType.getValue()); } @Test void modelDataFromPropertiesMapTest() { - final Map<String, Object> properties = new HashMap(); + final Map<String, Object> properties = new HashMap<>(); properties.put("name", modelData.getName()); properties.put("uid", modelData.getUniqueId()); + properties.put("modelType", modelData.getModelType()); final ModelData modelDataFromPropertiesMap = new ModelData(properties); assertThat(modelDataFromPropertiesMap).isNotNull(); assertThat(modelDataFromPropertiesMap.getUniqueId()).isEqualTo(modelId); assertThat(modelDataFromPropertiesMap.getName()).isEqualTo(modelName); + assertThat(modelDataFromPropertiesMap.getModelType()).isEqualTo(modelType.getValue()); } @Test @@ -65,6 +70,7 @@ class ModelDataTest { assertThat(result).isNotEmpty(); assertThat(result.values()).contains(modelId); assertThat(result.values()).contains(modelName); + assertThat(result.values()).contains(modelType.getValue()); } } 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<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractToscaElementsMetadataOnly(boolean isAbstract, - ComponentTypeEnum componentTypeEnum, - String internalComponentType, - VertexTypeEnum vertexType, - String modelName) { + private Either<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractToscaElementsMetadataOnly(final boolean isAbstract, + final ComponentTypeEnum componentTypeEnum, + final String internalComponentType, + final VertexTypeEnum vertexType, + final String modelName, + final boolean includeNormativeExtensionModels) { List<Service> services = null; Map<GraphPropertyEnum, Object> hasProps = new EnumMap<>(GraphPropertyEnum.class); Map<GraphPropertyEnum, Object> hasNotProps = new EnumMap<>(GraphPropertyEnum.class); fillPropsMap(hasProps, hasNotProps, internalComponentType, componentTypeEnum, isAbstract, vertexType, modelName); Either<List<GraphVertex>, 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<List<String>, StorageOperationStatus> getComponentUids(boolean isAbstract, ComponentTypeEnum componentTypeEnum, String internalComponentType) { Either<List<Component>, 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<List<Component>, StorageOperationStatus> getLatestVersionNotAbstractMetadataOnly(boolean isAbstract, - ComponentTypeEnum componentTypeEnum, - String internalComponentType, - String modelName) { + final ComponentTypeEnum componentTypeEnum, + final String internalComponentType, + final String modelName, + final boolean includeNormativeExtensionModels) { List<VertexTypeEnum> internalVertexTypes = getInternalVertexTypes(componentTypeEnum, internalComponentType); List<Component> result = new ArrayList<>(); for (VertexTypeEnum vertexType : internalVertexTypes) { Either<List<Component>, 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<OperationException> 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<ModelData, JanusGraphOperationStatus> 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<Model> findAllModels() { return findModelsByCriteria(Collections.emptyMap()); } + + public List<Model> findModels(final ModelTypeEnum modelType) { + final Map<GraphPropertyEnum, Object> propertyCriteria = new EnumMap<>(GraphPropertyEnum.class); + propertyCriteria.put(GraphPropertyEnum.MODEL_TYPE, modelType.getValue()); + + return findModelsByCriteria(propertyCriteria); + } private List<Model> findModelsByCriteria(final Map<GraphPropertyEnum, Object> propertyCriteria) { final List<GraphVertex> 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<ImmutablePair<ModelData, GraphEdge>, 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; + } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperationTest.java index af4715fd62..6ed482f948 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperationTest.java @@ -47,6 +47,7 @@ import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge; import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao; import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.model.CapabilityTypeDefinition; import org.openecomp.sdc.be.model.Model; @@ -136,7 +137,7 @@ public class CapabilityTypeOperationTest extends ModelTestBase { capabilityTypeDefinition.setType("tosca.capabilities.Container1"); capabilityTypeDefinition.setModel("testModel"); - Model model = new Model("testModel"); + Model model = new Model("testModel", ModelTypeEnum.NORMATIVE); modelOperation.createModel(model , true); Either<CapabilityTypeDefinition, StorageOperationStatus> addCapabilityType1 = capabilityTypeOperation.addCapabilityType(capabilityTypeDefinition, true); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java index 015aedc6a3..c8a2b03fb3 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperationTest.java @@ -34,6 +34,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.Model; @@ -122,7 +123,7 @@ class DataTypeOperationTest { private void initTestData() { - model = new Model(modelName); + model = new Model(modelName, ModelTypeEnum.NORMATIVE); final String TEST_DATA_TYPE_001 = "test.data.type001"; final String TEST_DATA_TYPE_002 = "test.data.type002"; final String TEST_DATA_TYPE_003 = "test.data.type003"; 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 48202c3ec5..19812e6d61 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 @@ -48,6 +48,7 @@ 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.GroupTypeDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.model.CapabilityDefinition; import org.openecomp.sdc.be.model.CapabilityTypeDefinition; @@ -544,7 +545,7 @@ public class GroupTypeOperationTest extends ModelTestBase { public void testAddGroupTypeWithModel() { GroupTypeDefinition groupTypeDefinition = createGroupTypeDef(); groupTypeDefinition.setModel("testModel"); - Model model = new Model("testModel"); + Model model = new Model("testModel", ModelTypeEnum.NORMATIVE); modelOperation.createModel(model , true); Either<GroupTypeDefinition, StorageOperationStatus> addGroupType = groupTypeOperation.addGroupType(groupTypeDefinition); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java index 4e0d68f7e2..1a7f1c8ba3 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java @@ -48,6 +48,7 @@ import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.ModelTestBase; @@ -188,7 +189,7 @@ public class InterfaceLifecycleOperationTest { @Test public void testGetAllInterfaceLifecycleTypesWithModel() { final var uid = UniqueIdBuilder.buildInterfaceTypeUid(MODEL_NAME, INTERFACE_TYPE); - final var modelData = new ModelData(MODEL_NAME, uid); + final var modelData = new ModelData(MODEL_NAME, uid, ModelTypeEnum.NORMATIVE); final ImmutablePair<GraphNode, GraphEdge> modelNode = new ImmutablePair<>(modelData, Mockito.mock(GraphEdge.class)); final InterfaceData interfaceData = new InterfaceData(); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java index 44a9a7df42..6071b4d59d 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ModelOperationTest.java @@ -58,6 +58,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.ModelTestBase; @@ -95,9 +96,9 @@ class ModelOperationTest extends ModelTestBase { @Test void createModelSuccessTest() { - final ModelData modelData = new ModelData(modelName, UniqueIdBuilder.buildModelUid(modelName)); + final ModelData modelData = new ModelData(modelName, UniqueIdBuilder.buildModelUid(modelName), ModelTypeEnum.NORMATIVE); when(janusGraphGenericDao.createNode(any(),any())).thenReturn(Either.left(modelData)); - final Model createdModel = modelOperation.createModel(new Model(modelName), false); + final Model createdModel = modelOperation.createModel(new Model(modelName, ModelTypeEnum.NORMATIVE), false); assertThat(createdModel).isNotNull(); assertThat(createdModel.getName()).isEqualTo(modelName); } @@ -105,16 +106,17 @@ class ModelOperationTest extends ModelTestBase { @Test void createDerivedModelSuccessTest() { final String derivedModelName = "derivedModel"; - final ModelData modelData = new ModelData(derivedModelName, UniqueIdBuilder.buildModelUid(derivedModelName)); + final ModelData modelData = new ModelData(derivedModelName, UniqueIdBuilder.buildModelUid(derivedModelName), ModelTypeEnum.NORMATIVE); when(janusGraphGenericDao.createNode(any(),any())).thenReturn(Either.left(modelData)); final GraphVertex modelVertex = new GraphVertex(); modelVertex.addMetadataProperty(GraphPropertyEnum.NAME, "baseModel"); + modelVertex.addMetadataProperty(GraphPropertyEnum.MODEL_TYPE, ModelTypeEnum.NORMATIVE.getValue()); when(janusGraphDao.getByCriteria(eq(VertexTypeEnum.MODEL), anyMap())).thenReturn(Either.left(Collections.singletonList(modelVertex))); when(janusGraphGenericDao.getChild(eq("uid"), anyString(), eq(GraphEdgeLabels.DERIVED_FROM), eq(NodeTypeEnum.Model), eq(ModelData.class))).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); when(derivedFromOperation.addDerivedFromRelation("model.derivedModel", "model.baseModel", NodeTypeEnum.Model)).thenReturn(Either.left(new GraphRelation())); - final Model createdModel = modelOperation.createModel(new Model(derivedModelName, modelName), false); + final Model createdModel = modelOperation.createModel(new Model(derivedModelName, modelName, ModelTypeEnum.NORMATIVE), false); assertThat(createdModel).isNotNull(); assertThat(createdModel.getName()).isEqualTo(derivedModelName); } @@ -122,14 +124,14 @@ class ModelOperationTest extends ModelTestBase { @Test void createModelFailWithModelAlreadyExistTest() { when(janusGraphGenericDao.createNode(any(),any())).thenReturn(Either.right(JanusGraphOperationStatus.JANUSGRAPH_SCHEMA_VIOLATION)); - final var model = new Model(modelName); + final var model = new Model(modelName, ModelTypeEnum.NORMATIVE); assertThrows(OperationException.class, () -> modelOperation.createModel(model, false)); } @Test void createModelFailTest() { when(janusGraphGenericDao.createNode(any(),any())).thenReturn(Either.right(JanusGraphOperationStatus.GRAPH_IS_NOT_AVAILABLE)); - final var model = new Model(modelName); + final var model = new Model(modelName, ModelTypeEnum.NORMATIVE); assertThrows(OperationException.class, () -> modelOperation.createModel(model, false)); } @@ -224,6 +226,7 @@ class ModelOperationTest extends ModelTestBase { var modelName = "modelName"; final GraphVertex expectedVertex = mock(GraphVertex.class); when(expectedVertex.getMetadataProperty(GraphPropertyEnum.NAME)).thenReturn(modelName); + when(expectedVertex.getMetadataProperty(GraphPropertyEnum.MODEL_TYPE)).thenReturn(ModelTypeEnum.NORMATIVE.getValue()); when(janusGraphDao.getByCriteria(eq(VertexTypeEnum.MODEL), mapArgumentCaptor.capture())).thenReturn(Either.left(List.of(expectedVertex))); when(janusGraphGenericDao.getChild("uid", UniqueIdBuilder.buildModelUid(modelName), GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.Model, ModelData.class)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); @@ -233,7 +236,7 @@ class ModelOperationTest extends ModelTestBase { assertEquals(modelName, value.get(GraphPropertyEnum.NAME)); assertEquals(UniqueIdBuilder.buildModelUid(modelName), value.get(GraphPropertyEnum.UNIQUE_ID)); - final Model expectedModel = new Model(modelName); + final Model expectedModel = new Model(modelName, ModelTypeEnum.NORMATIVE); assertTrue(modelByNameOpt.isPresent()); assertEquals(expectedModel, modelByNameOpt.get()); } @@ -258,6 +261,7 @@ class ModelOperationTest extends ModelTestBase { void findAllModelsSuccessTest() { final GraphVertex expectedVertex = mock(GraphVertex.class); when(expectedVertex.getMetadataProperty(GraphPropertyEnum.NAME)).thenReturn(modelName); + when(expectedVertex.getMetadataProperty(GraphPropertyEnum.MODEL_TYPE)).thenReturn(ModelTypeEnum.NORMATIVE.getValue()); when(janusGraphDao.getByCriteria(VertexTypeEnum.MODEL, Collections.emptyMap())).thenReturn(Either.left(List.of(expectedVertex))); when(janusGraphGenericDao.getChild("uid", UniqueIdBuilder.buildModelUid(modelName), GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.Model, ModelData.class)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); 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 d849ec647d..a6b2aa687a 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 @@ -25,8 +25,6 @@ import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; - -import fj.data.Either; import java.util.Iterator; import java.util.List; import java.util.stream.Stream; @@ -44,6 +42,7 @@ import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; 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.ModelTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.model.Model; import org.openecomp.sdc.be.model.ModelTestBase; @@ -54,6 +53,7 @@ import org.openecomp.sdc.be.resources.data.PolicyTypeData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import fj.data.Either; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:application-context-test.xml") @@ -117,7 +117,7 @@ public class PolicyTypeOperationTest extends ModelTestBase { public void testAddPolicyTypeWithModel() { PolicyTypeDefinition policyTypeDefinition = createPolicyTypeDef(); policyTypeDefinition.setModel("testModel"); - Model model = new Model("testModel"); + Model model = new Model("testModel", ModelTypeEnum.NORMATIVE); modelOperation.createModel(model , true); Either<PolicyTypeDefinition, StorageOperationStatus> addPolicyType = policyTypeOperation.addPolicyType(policyTypeDefinition); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java index 6551a13981..371c3edfe5 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java @@ -50,6 +50,7 @@ import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; import org.openecomp.sdc.be.datatypes.elements.RelationshipInstDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.model.ModelTestBase; import org.openecomp.sdc.be.model.PropertyConstraint; @@ -396,7 +397,7 @@ public class RelationshipTypeOperationTest extends ModelTestBase { .when(janusGraphGenericDao).getNode(Mockito.anyString(), Mockito.any(), Mockito.eq(RelationshipTypeData.class), Mockito.any()); - ModelData modelData = new ModelData("modelA", "modelA"); + ModelData modelData = new ModelData("modelA", "modelA", ModelTypeEnum.NORMATIVE); ImmutablePair<ModelData, GraphEdge> pair = new ImmutablePair<>(modelData, new GraphEdge()); Mockito.doReturn(Either.left(pair)) .when(janusGraphGenericDao).getParentNode("uid", relationshipInstDataDefinition1.getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, NodeTypeEnum.Model, ModelData.class); @@ -464,7 +465,7 @@ public class RelationshipTypeOperationTest extends ModelTestBase { Mockito.doReturn(Either.left(new GraphRelation())).when(derivedFromOperation) .addDerivedFromRelation(relationshipTypeDefinition.getUniqueId(), derivedFromRelationshipTypeData.getUniqueId(), NodeTypeEnum.RelationshipType); - ModelData modelData = new ModelData("modelA", "modelA"); + ModelData modelData = new ModelData("modelA", "modelA", ModelTypeEnum.NORMATIVE); ImmutablePair<ModelData, GraphEdge> pair = new ImmutablePair<>(modelData, new GraphEdge()); Mockito.doReturn(Either.left(pair)) .when(janusGraphGenericDao).getParentNode("uid", dervideFromRelationshipInstDataDefinition.getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, NodeTypeEnum.Model, ModelData.class); @@ -544,7 +545,7 @@ public class RelationshipTypeOperationTest extends ModelTestBase { Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(janusGraphGenericDao) .getChild(Mockito.any(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.eq(RelationshipTypeData.class)); - ModelData modelData = new ModelData("modelA", "modelA"); + ModelData modelData = new ModelData("modelA", "modelA", ModelTypeEnum.NORMATIVE); ImmutablePair<ModelData, GraphEdge> pair = new ImmutablePair<>(modelData, new GraphEdge()); Mockito.doReturn(Either.left(pair)) .when(janusGraphGenericDao).getParentNode("uid", newRelationshipTypeDefinition.getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, NodeTypeEnum.Model, ModelData.class); @@ -574,7 +575,7 @@ public class RelationshipTypeOperationTest extends ModelTestBase { .getChild(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.eq(RelationshipTypeData.class)); - ModelData modelData = new ModelData("modelA", "modelA"); + ModelData modelData = new ModelData("modelA", "modelA", ModelTypeEnum.NORMATIVE); ImmutablePair<ModelData, GraphEdge> pair = new ImmutablePair<>(modelData, new GraphEdge()); Mockito.doReturn(Either.left(pair)) .when(janusGraphGenericDao).getParentNode("uid", relationshipTypeDefinition.getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, NodeTypeEnum.Model, ModelData.class); diff --git a/catalog-ui/src/app/ng2/pages/composition/palette/services/palette.service.ts b/catalog-ui/src/app/ng2/pages/composition/palette/services/palette.service.ts index ed61dce192..d5528c5197 100644 --- a/catalog-ui/src/app/ng2/pages/composition/palette/services/palette.service.ts +++ b/catalog-ui/src/app/ng2/pages/composition/palette/services/palette.service.ts @@ -32,6 +32,9 @@ export class CompositionPaletteService { let model = this.workspaceService.metadata.model if (model) { params = params.append('componentModel', model); + if (this.workspaceService.getMetadataType() === 'SERVICE'){ + params = params.append('includeNormativeExtensionModels', 'true'); + } } const loadInstances = this.http.get(this.facadeUrl, {params}); const loadGroups = this.http.get(this.baseUrl + 'groupTypes', {params}); diff --git a/catalog-ui/src/app/ng2/services/model.service.ts b/catalog-ui/src/app/ng2/services/model.service.ts index 10ad4142de..83e16b12c7 100644 --- a/catalog-ui/src/app/ng2/services/model.service.ts +++ b/catalog-ui/src/app/ng2/services/model.service.ts @@ -35,4 +35,8 @@ export class ModelService { return this.http.get<Model[]>(this.baseUrl + "/v1/catalog/model"); } + getModelsOfType(type: string):Observable<Model[]> { + return this.http.get<Model[]>(this.baseUrl + "/v1/catalog/model?modelType=" + type); + } + } diff --git a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts index c319b806c0..dd1fa464bf 100644 --- a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts +++ b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts @@ -485,9 +485,15 @@ export class GeneralViewModel { return; } - this.modelService.getModels().subscribe((modelsFound: Model[]) => { - modelsFound.forEach(model => {this.$scope.models.push({id: model.name, name: model.name})}); - }); + if (!this.$scope.isCreateMode() && this.$scope.isVspImport()){ + this.modelService.getModels().subscribe((modelsFound: Model[]) => { + modelsFound.forEach(model => {this.$scope.models.push({id: model.name, name: model.name})}); + }); + } else { + this.modelService.getModelsOfType("normative").subscribe((modelsFound: Model[]) => { + modelsFound.forEach(model => {this.$scope.models.push({id: model.name, name: model.name})}); + }); + } this.$scope.models.sort(function (model1, model2) { if (model1.id > model2.id) { diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/GraphPropertyEnum.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/GraphPropertyEnum.java index 8f547cf7d2..1d65d1d70a 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/GraphPropertyEnum.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/GraphPropertyEnum.java @@ -64,7 +64,8 @@ public enum GraphPropertyEnum { CURRENT_CATALOG_UPDATE_TIME("currentUpdateTime", Long.class, false, true), //Healing HEALING_VERSION("healVersion", Integer.class, false, true), - MODEL("model", String.class, false, false); + MODEL("model", String.class, false, false), + MODEL_TYPE("modelType", String.class, false, false); // @formatter:on private final String property; diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ModelTypeEnum.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ModelTypeEnum.java new file mode 100644 index 0000000000..11ef3552d7 --- /dev/null +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ModelTypeEnum.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.openecomp.sdc.be.datatypes.enums; + +import java.util.Arrays; +import java.util.Optional; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ModelTypeEnum { + NORMATIVE("normative"), + NORMATIVE_EXTENSION("normative-extension"); + + private final String value; + + public static Optional<ModelTypeEnum> findByValue(String value) { + return Arrays.stream(ModelTypeEnum.values()).filter(modelTypeEnum -> modelTypeEnum.getValue().equals(value)).findAny(); + } +} diff --git a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js index 29e278f928..5c82c70830 100644 --- a/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js +++ b/openecomp-ui/src/sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js @@ -109,7 +109,7 @@ function softwareProductCategoriesUrl() { function getModelUrl() { const restCatalogPrefix = Configuration.get('restCatalogPrefix'); - return `${restCatalogPrefix}/v1/catalog/model/`; + return `${restCatalogPrefix}/v1/catalog/model?modelType=normative`; } function uploadFile(vspId, formData, version) { diff --git a/openecomp-ui/test/softwareProduct/details/test.js b/openecomp-ui/test/softwareProduct/details/test.js index 0e0c9ecafd..8b5f68c469 100644 --- a/openecomp-ui/test/softwareProduct/details/test.js +++ b/openecomp-ui/test/softwareProduct/details/test.js @@ -218,7 +218,7 @@ describe('Software Product Details Module Tests', function () { }); mockRest.addHandler('fetch', ({options, data, baseUrl}) => { - expect(baseUrl).toEqual('/sdc1/feProxy/rest/v1/catalog/model/'); + expect(baseUrl).toEqual('/sdc1/feProxy/rest/v1/catalog/model?modelType=normative'); expect(data).toEqual(undefined); expect(options).toEqual(undefined); return []; |