aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java45
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/TypesFetchServletTest.java6
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() {