summaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-10-04 20:29:28 +0100
committerMichael Morris <michael.morris@est.tech>2022-10-17 14:42:22 +0000
commitaa72781388f3e6408bb43f1b024d88ec1c9d2c10 (patch)
tree15002a934486557f1d62eec49e57af1e2e59b443 /catalog-be/src
parentb75fe3c7ce231c86cd4c6d052da453d02809c8f9 (diff)
Add data type properties workspace
Implements the properties workspace for a data type, with the list and filter feature. Change-Id: I2ec337a0481bddd5fe32e45644abdc88e197fa49 Issue-ID: SDC-4214 Signed-off-by: André Schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java20
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/DataTypeServletTest.java27
3 files changed, 48 insertions, 1 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 47e2851b8e..532ee3ecac 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
@@ -2826,4 +2826,4 @@ errors:
DATA_TYPE_NOT_FOUND:
code: 404
message: "Data type '%1' was not found."
- messageId: "SVC4011"
+ messageId: "SVC4011" \ No newline at end of file
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java
index d9846a7fb1..e39e0d2c0d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java
@@ -22,16 +22,19 @@ package org.openecomp.sdc.be.servlets;
import com.jcabi.aspects.Loggable;
import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
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.List;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
@@ -45,6 +48,8 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
import org.openecomp.sdc.be.exception.BusinessException;
import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.dto.PropertyDefinitionDto;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
import org.openecomp.sdc.be.model.operations.impl.DataTypeOperation;
import org.openecomp.sdc.common.api.Constants;
@@ -99,4 +104,19 @@ public class DataTypeServlet extends BeGenericServlet {
return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataType);
}
+ @GET
+ @Path("{id}/properties")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get a data type properties", method = "GET", summary = "Returns the data type properties", responses = {
+ @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = PropertyDefinition.class)))),
+ @ApiResponse(responseCode = "200", description = "Data type found, properties may be empty"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Data type not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response fetchProperties(@PathParam("id") final String id) {
+ final List<PropertyDefinition> allProperties = dataTypeOperation.findAllProperties(id);
+ return buildOkResponse(allProperties);
+ }
+
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/DataTypeServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/DataTypeServletTest.java
index d916fffc12..d2380fa96e 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/DataTypeServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/DataTypeServletTest.java
@@ -25,6 +25,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import java.util.List;
+import java.util.Map;
import java.util.Optional;
import javax.servlet.ServletContext;
import javax.ws.rs.core.MediaType;
@@ -44,6 +46,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
import org.openecomp.sdc.be.model.operations.impl.DataTypeOperation;
import org.openecomp.sdc.common.api.Constants;
@@ -56,6 +59,7 @@ class DataTypeServletTest extends JerseySpringBaseTest {
private static final String USER_ID = "cs0008";
private static final String DATA_TYPE_UID = "ETSI SOL001 v2.5.1.tosca.datatypes.nfv.L3AddressData.datatype";
private static final String PATH = "/v1/catalog/data-types/" + DATA_TYPE_UID;
+ private static final String DATA_TYPE_PROPERTIES_PATH = "/v1/catalog/data-types/%s/properties";
@InjectMocks
private DataTypeServlet dataTypeServlet;
@@ -153,4 +157,27 @@ class DataTypeServletTest extends JerseySpringBaseTest {
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus());
}
+ @Test
+ void fetchDataTypePropertiesTest_Success() {
+ final DataTypeDataDefinition expectedDataType = new DataTypeDataDefinition();
+ final PropertyDefinition expectedProperty1 = new PropertyDefinition();
+ expectedProperty1.setName("property1");
+ final PropertyDefinition expectedProperty2 = new PropertyDefinition();
+ expectedProperty2.setName("property2");
+ expectedDataType.setUniqueId(DATA_TYPE_UID);
+ when(dataTypeOperation.findAllProperties(DATA_TYPE_UID)).thenReturn(List.of(expectedProperty1, expectedProperty2));
+
+ final Response response = target()
+ .path(String.format(DATA_TYPE_PROPERTIES_PATH, DATA_TYPE_UID))
+ .request(MediaType.APPLICATION_JSON)
+ .header("USER_ID", USER_ID)
+ .get(Response.class);
+ assertNotNull(response);
+ assertEquals(HttpStatus.SC_OK, response.getStatus());
+ final List<Map<String, Object>> actualResponse = response.readEntity(List.class);
+ assertEquals(2, actualResponse.size());
+ assertEquals(expectedProperty1.getName(), actualResponse.get(0).get("name"));
+ assertEquals(expectedProperty2.getName(), actualResponse.get(1).get("name"));
+ }
+
}