aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2021-06-21 22:25:28 +0100
committerChristophe Closset <christophe.closset@intl.att.com>2021-07-05 09:21:57 +0000
commitb835031b83230c36649c6e77787867a465e0ac47 (patch)
treec988e23a137da1f2a757693f56ab1a457394444f /catalog-be/src/main
parent70975c212b58b793d3893e131a3d23d8144f5df9 (diff)
Create REST endpoint to retrieve models
Change-Id: Ifca0095d84d5da4ab4b055942d893e9c6a259eb7 Issue-ID: SDC-3622 Signed-off-by: André Schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ModelBusinessLogic.java10
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ModelServlet.java28
2 files changed, 38 insertions, 0 deletions
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 7f68a00a8b..a048af4ac8 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
@@ -21,6 +21,7 @@ package org.openecomp.sdc.be.components.impl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
@@ -56,6 +57,15 @@ public class ModelBusinessLogic {
return modelOperation.findModelByName(modelName);
}
+ /**
+ * Loads the list of models.
+ *
+ * @return the list of models
+ */
+ public List<Model> listModels() {
+ return modelOperation.findAllModels();
+ }
+
public void createModelImports(final String modelName, final InputStream modelImportsZip) {
if (StringUtils.isEmpty(modelName)) {
throw ModelOperationExceptionSupplier.invalidModel(modelName).get();
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 0c5e4aebd6..337c641b33 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
@@ -30,10 +30,12 @@ import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.io.InputStream;
import java.util.Arrays;
+import java.util.List;
import javax.inject.Inject;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
@@ -121,6 +123,32 @@ public class ModelServlet extends AbstractValidationsServlet {
}
}
+ @GET
+ @Path("/model")
+ @Produces(MediaType.APPLICATION_JSON)
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ @Operation(method = "GET", summary = "List TOSCA models", description = "List all the existing TOSCA models",
+ responses = {
+ @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Model.class)))),
+ @ApiResponse(responseCode = "200", description = "Listing successful"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation")
+ }
+ )
+ public Response listModels(@HeaderParam(value = Constants.USER_ID_HEADER) final String userId) {
+ validateUser(ValidationUtils.sanitizeInputString(userId));
+ try {
+ final List<Model> modelList = modelBusinessLogic.listModels();
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), RepresentationUtils.toRepresentation(modelList));
+ } catch (final BusinessException e) {
+ throw e;
+ } catch (final Exception e) {
+ var errorMsg = "Unexpected error while listing the models";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(errorMsg);
+ log.error(errorMsg, e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
@PUT
@Path("/model/imports")
@Consumes(MediaType.MULTIPART_FORM_DATA)