summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2021-08-20 15:40:35 +0100
committerAndr� Schmid <andre.schmid@est.tech>2021-08-27 10:33:32 +0000
commita5e32b3d20bc078482cb08645c38ffb685c0f145 (patch)
tree133fe88578f3a3c3db3ec73315b65f45caba625a /catalog-be/src/main/java
parent4701612ba26c4b8c7c7e9fbfa38f582a4b74669f (diff)
Support querying of model by type
Signed-off-by: MichaelMorris <michael.morris@est.tech> Issue-ID: SDC-3678 Change-Id: I5fd19eefe475113df501901628b2ee8669004399
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java13
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ModelServlet.java19
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java2
6 files changed, 34 insertions, 11 deletions
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()));