diff options
author | KrupaNagabhushan <krupa.nagabhushan@est.tech> | 2022-09-23 10:17:29 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2022-11-30 16:40:22 +0000 |
commit | 4a754a8c898fb397e19876de2d19141d047a9e58 (patch) | |
tree | 164634a57dc675cd45d84fbc40dc843cac57ca77 /catalog-be | |
parent | 1ed328d96144bc626f664e2a5c45894393e8308e (diff) |
View data types in UI catalog
Issue-ID: SDC-4220
Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech>
Change-Id: I880c7fedb58eafc7524fc6833b9b5d02f3b7d523
Diffstat (limited to 'catalog-be')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java | 45 | ||||
-rw-r--r-- | catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesFetchServletTest.java | 6 |
2 files changed, 50 insertions, 1 deletions
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 7709721e61..fe08b5cd74 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 @@ -29,6 +29,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.servers.Server; import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -68,8 +69,10 @@ import org.openecomp.sdc.be.model.CapabilityTypeDefinition; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; +import org.openecomp.sdc.be.model.Model; import org.openecomp.sdc.be.model.RelationshipTypeDefinition; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.operations.impl.ModelOperation; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode; @@ -93,6 +96,7 @@ public class TypesFetchServlet extends AbstractValidationsServlet { private final InterfaceOperationBusinessLogic interfaceOperationBusinessLogic; private final ResourceBusinessLogic resourceBusinessLogic; private final ArtifactTypeBusinessLogic artifactTypeBusinessLogic; + private final ModelOperation modelOperation; @Inject public TypesFetchServlet( @@ -104,7 +108,8 @@ public class TypesFetchServlet extends AbstractValidationsServlet { CapabilitiesBusinessLogic capabilitiesBusinessLogic, InterfaceOperationBusinessLogic interfaceOperationBusinessLogic, ResourceBusinessLogic resourceBusinessLogic, - ArtifactTypeBusinessLogic artifactTypeBusinessLogic + ArtifactTypeBusinessLogic artifactTypeBusinessLogic, + ModelOperation modelOperation ) { super( componentInstanceBL, @@ -117,6 +122,7 @@ public class TypesFetchServlet extends AbstractValidationsServlet { this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic; this.resourceBusinessLogic = resourceBusinessLogic; this.artifactTypeBusinessLogic = artifactTypeBusinessLogic; + this.modelOperation = modelOperation; } @GET @@ -149,6 +155,43 @@ public class TypesFetchServlet extends AbstractValidationsServlet { } @GET + @Path("allDataTypes") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Operation(description = "Get data types", method = "GET", summary = "Returns all data types from all models", responses = { + @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))), + @ApiResponse(responseCode = "200", description = "allDataTypes"), @ApiResponse(responseCode = "403", description = "Restricted operation"), + @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"), + @ApiResponse(responseCode = "404", description = "Data types not found")}) + @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) + public Response getAllDataTypesFromAllModels(@Context final HttpServletRequest request, + @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { + Wrapper<Response> responseWrapper = new Wrapper<>(); + Wrapper<User> userWrapper = new Wrapper<>(); + init(); + validateUserExist(responseWrapper, userWrapper, userId); + if (responseWrapper.isEmpty()) { + String url = request.getMethod() + " " + request.getRequestURI(); + log.debug("Start handle request of {} - modifier id is {}", url, userId); + resourceBusinessLogic.getApplicationDataTypeCache().refreshDataTypesCacheIfStale(); + final List<Map<String, DataTypeDefinition>> dataTypesList = new ArrayList<>(); + List<Model> models = modelOperation.findAllModels(); + Model defaultModel = new Model(); + defaultModel.setName(null); + models.add(defaultModel); + models.forEach(model -> { + final Map<String, DataTypeDefinition> dataTypes = resourceBusinessLogic.getComponentsUtils() + .getAllDataTypes(resourceBusinessLogic.getApplicationDataTypeCache(), model.getName()); + dataTypesList.add(dataTypes); + }); + String dataTypeJson = gson.toJson(dataTypesList); + Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypeJson); + responseWrapper.setInnerElement(okResponse); + } + return responseWrapper.getInnerElement(); + } + + @GET @Path("interfaceLifecycleTypes") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesFetchServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesFetchServletTest.java index 031377f2e9..d7f23f1b21 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesFetchServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesFetchServletTest.java @@ -63,6 +63,7 @@ import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.operations.impl.ModelOperation; import org.openecomp.sdc.be.servlets.builder.ServletResponseBuilder; import org.openecomp.sdc.be.servlets.exception.OperationExceptionMapper; import org.openecomp.sdc.be.user.Role; @@ -116,6 +117,8 @@ class TypesFetchServletTest extends JerseyTest { private ArtifactTypeBusinessLogic artifactTypeBusinessLogic; @Mock private ResponseFormatManager responseFormatManager; + @Mock + private ModelOperation modelOperation; private final Path rootPath = Path.of("/v1/catalog"); private final Path nodeTypesPath = rootPath.resolve("nodeTypes"); @@ -214,6 +217,7 @@ class TypesFetchServletTest extends JerseyTest { bind(capabilitiesBusinessLogic).to(CapabilitiesBusinessLogic.class); bind(interfaceOperationBusinessLogic).to(InterfaceOperationBusinessLogic.class); bind(artifactTypeBusinessLogic).to(ArtifactTypeBusinessLogic.class); + bind(modelOperation).to(ModelOperation.class); } }) .register(new OperationExceptionMapper( @@ -258,6 +262,8 @@ class TypesFetchServletTest extends JerseyTest { .thenReturn(resourceBusinessLogic); when(webApplicationContext.getBean(ArtifactTypeBusinessLogic.class)) .thenReturn(artifactTypeBusinessLogic); + when(webApplicationContext.getBean(ModelOperation.class)) + .thenReturn(modelOperation); } void initConfig() { |