diff --git a/dbrepo-data-service/rest-service/src/main/java/at/tuwien/endpoints/SubsetEndpoint.java b/dbrepo-data-service/rest-service/src/main/java/at/tuwien/endpoints/SubsetEndpoint.java index eb9971869f51a0291eec0b69a494656cc308b984..9ef410b0b681776fa53f51969b652cb0ca816308 100644 --- a/dbrepo-data-service/rest-service/src/main/java/at/tuwien/endpoints/SubsetEndpoint.java +++ b/dbrepo-data-service/rest-service/src/main/java/at/tuwien/endpoints/SubsetEndpoint.java @@ -205,6 +205,11 @@ public class SubsetEndpoint extends RestEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "406", + description = "Failed to format data", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "417", description = "Failed to insert query into query store of data database", content = {@Content( @@ -300,6 +305,11 @@ public class SubsetEndpoint extends RestEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "406", + description = "Failed to format data", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "503", description = "Failed to communicate with database", content = {@Content( diff --git a/dbrepo-data-service/rest-service/src/main/java/at/tuwien/endpoints/TableEndpoint.java b/dbrepo-data-service/rest-service/src/main/java/at/tuwien/endpoints/TableEndpoint.java index 00dc146332f4eb0daf3f2a8cacde65c1d2535fec..8e1fef5bac3d5451b0938f337e623d7e0e39ab56 100644 --- a/dbrepo-data-service/rest-service/src/main/java/at/tuwien/endpoints/TableEndpoint.java +++ b/dbrepo-data-service/rest-service/src/main/java/at/tuwien/endpoints/TableEndpoint.java @@ -244,6 +244,11 @@ public class TableEndpoint extends RestEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "406", + description = "Failed to format data", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "503", description = "Failed to establish connection with the metadata service", content = {@Content( diff --git a/dbrepo-data-service/rest-service/src/main/java/at/tuwien/endpoints/ViewEndpoint.java b/dbrepo-data-service/rest-service/src/main/java/at/tuwien/endpoints/ViewEndpoint.java index 3a06b2fe7c4148ef4a53dcb9626de125aaf619e1..b4c7fa715f667d7edf2727e7248af696266bf5e5 100644 --- a/dbrepo-data-service/rest-service/src/main/java/at/tuwien/endpoints/ViewEndpoint.java +++ b/dbrepo-data-service/rest-service/src/main/java/at/tuwien/endpoints/ViewEndpoint.java @@ -241,6 +241,11 @@ public class ViewEndpoint extends RestEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "406", + description = "Failed to format data", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "409", description = "View schema could not be mapped", content = {@Content( diff --git a/dbrepo-data-service/rest-service/src/test/java/at/tuwien/endpoint/SubsetEndpointUnitTest.java b/dbrepo-data-service/rest-service/src/test/java/at/tuwien/endpoint/SubsetEndpointUnitTest.java index ca97569f3c00b54b466af97cd99d44aea4f31d0e..b034b791242dd92c640b0b721afa86a8197a7afd 100644 --- a/dbrepo-data-service/rest-service/src/test/java/at/tuwien/endpoint/SubsetEndpointUnitTest.java +++ b/dbrepo-data-service/rest-service/src/test/java/at/tuwien/endpoint/SubsetEndpointUnitTest.java @@ -196,23 +196,6 @@ public class SubsetEndpointUnitTest extends AbstractUnitTest { generic_findById(DATABASE_3_ID, QUERY_5_ID, null, USER_3_PRINCIPAL); } - @Test - @WithAnonymousUser - public void findById_format_fails() throws DatabaseNotFoundException, RemoteUnavailableException, SQLException, - UserNotFoundException, QueryNotFoundException, MetadataServiceException { - - /* mock */ - when(credentialService.getDatabase(DATABASE_4_ID)) - .thenReturn(DATABASE_4_PRIVILEGED_DTO); - when(subsetService.findById(DATABASE_4_PRIVILEGED_DTO, QUERY_7_ID)) - .thenReturn(QUERY_7_DTO); - - /* test */ - assertThrows(FormatNotAvailableException.class, () -> { - generic_findById(DATABASE_4_ID, QUERY_7_ID, null, null); - }); - } - @Test @WithMockUser(username = USER_1_USERNAME) public void findById_privateDataPrivateSchemaAcceptCsv_succeeds() throws DatabaseNotFoundException, @@ -495,7 +478,7 @@ public class SubsetEndpointUnitTest extends AbstractUnitTest { /* test */ final ResponseEntity<?> response = subsetEndpoint.getData(DATABASE_3_ID, QUERY_5_ID, - null, "GET", httpServletRequest, null, null, null); + null, "application/json", httpServletRequest, null, null, null); assertEquals(HttpStatus.OK, response.getStatusCode()); assertNotNull(response.getBody()); } @@ -518,7 +501,7 @@ public class SubsetEndpointUnitTest extends AbstractUnitTest { /* test */ final ResponseEntity<?> response = subsetEndpoint.getData(DATABASE_3_ID, QUERY_5_ID, - null, "GET", httpServletRequest, null, null, null); + null, "application/json", httpServletRequest, null, null, null); assertEquals(HttpStatus.OK, response.getStatusCode()); assertNotNull(response.getHeaders().get("X-Count")); assertEquals(1, response.getHeaders().get("X-Count").size()); @@ -552,7 +535,7 @@ public class SubsetEndpointUnitTest extends AbstractUnitTest { /* test */ final ResponseEntity<?> response = subsetEndpoint.getData(DATABASE_1_ID, QUERY_1_ID, - USER_1_PRINCIPAL, "GET", httpServletRequest, null, null, null); + USER_1_PRINCIPAL, "application/json", httpServletRequest, null, null, null); assertEquals(HttpStatus.OK, response.getStatusCode()); assertNotNull(response.getBody()); } @@ -568,7 +551,7 @@ public class SubsetEndpointUnitTest extends AbstractUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - subsetEndpoint.getData(DATABASE_1_ID, QUERY_1_ID, null, "GET", httpServletRequest, null, null, null); + subsetEndpoint.getData(DATABASE_1_ID, QUERY_1_ID, null, "application/json", httpServletRequest, null, null, null); }); } @@ -586,7 +569,7 @@ public class SubsetEndpointUnitTest extends AbstractUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - subsetEndpoint.getData(DATABASE_1_ID, QUERY_1_ID, USER_1_PRINCIPAL, "GET", httpServletRequest, null, null, null); + subsetEndpoint.getData(DATABASE_1_ID, QUERY_1_ID, USER_1_PRINCIPAL, "application/json", httpServletRequest, null, null, null); }); } diff --git a/dbrepo-data-service/rest-service/src/test/java/at/tuwien/mvc/PrometheusEndpointMvcTest.java b/dbrepo-data-service/rest-service/src/test/java/at/tuwien/mvc/PrometheusEndpointMvcTest.java index 33f77b7cce1f3fc29f70073bc9bbc6e5acd5869e..de1c875e0aef96a54f283e31a8ef90d9e8468de0 100644 --- a/dbrepo-data-service/rest-service/src/test/java/at/tuwien/mvc/PrometheusEndpointMvcTest.java +++ b/dbrepo-data-service/rest-service/src/test/java/at/tuwien/mvc/PrometheusEndpointMvcTest.java @@ -175,8 +175,7 @@ public class PrometheusEndpointMvcTest extends AbstractUnitTest { /* test */ for (String metric : List.of("dbrepo_table_data_list", "dbrepo_table_data_create", "dbrepo_table_data_update", - "dbrepo_table_data_delete", "dbrepo_table_data_history", "dbrepo_table_data_export", - "dbrepo_table_data_import")) { + "dbrepo_table_data_delete", "dbrepo_table_data_history", "dbrepo_table_data_import")) { assertThat(registry) .hasObservationWithNameEqualTo(metric); } diff --git a/dbrepo-data-service/rest-service/src/test/java/at/tuwien/mvc/SubsetEndpointMvcTest.java b/dbrepo-data-service/rest-service/src/test/java/at/tuwien/mvc/SubsetEndpointMvcTest.java index 158c6743a4e7bac049cae0211fe764030ab4a3f0..37f6d367dc125a155dcdb7ae85c9bdf30cc8c6a2 100644 --- a/dbrepo-data-service/rest-service/src/test/java/at/tuwien/mvc/SubsetEndpointMvcTest.java +++ b/dbrepo-data-service/rest-service/src/test/java/at/tuwien/mvc/SubsetEndpointMvcTest.java @@ -36,21 +36,6 @@ public class SubsetEndpointMvcTest extends AbstractUnitTest { @Autowired private MockMvc mockMvc; - @Test - public void findById_noAcceptHeader_fails() throws Exception { - - /* mock */ - when(metadataServiceGateway.getDatabaseById(DATABASE_3_ID)) - .thenReturn(DATABASE_3_PRIVILEGED_DTO); - when(subsetService.findById(DATABASE_3_PRIVILEGED_DTO, QUERY_5_ID)) - .thenReturn(QUERY_5_DTO); - - /* test */ - this.mockMvc.perform(get("/api/database/" + DATABASE_3_ID + "/subset/" + QUERY_5_ID)) - .andDo(print()) - .andExpect(status().isBadRequest()); - } - @Test public void findById_privateDataPublicSchema_jsonAcceptHeader_fails() throws Exception { diff --git a/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/endpoints/IdentifierEndpointUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/endpoints/IdentifierEndpointUnitTest.java index 4f6bd37fd41dabb1bdb73eadc15fddf06aa2f93c..59aca6a405cf0086fb1cc39e033d4865a33df082 100644 --- a/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/endpoints/IdentifierEndpointUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/endpoints/IdentifierEndpointUnitTest.java @@ -365,20 +365,6 @@ public class IdentifierEndpointUnitTest extends AbstractUnitTest { assertEquals(1, identifiers.size()); } - @Test - @WithAnonymousUser - public void find_textCsvDatabase_fails() throws IdentifierNotFoundException { - - /* mock */ - when(identifierService.find(IDENTIFIER_1_ID)) - .thenReturn(IDENTIFIER_1); - - /* test */ - assertThrows(FormatNotAvailableException.class, () -> { - identifierEndpoint.find(IDENTIFIER_1_ID, "text/csv", null); - }); - } - @Test @WithAnonymousUser public void find_draft_fails() throws IdentifierNotFoundException { @@ -1505,10 +1491,6 @@ public class IdentifierEndpointUnitTest extends AbstractUnitTest { return identifierEndpoint.find(IDENTIFIER_1_ID, accept, null); } - protected static String inputStreamToString(InputStream inputStream) throws IOException { - return IOUtils.toString(inputStream, StandardCharsets.UTF_8); - } - protected void generic_delete() throws NotAllowedException, DataServiceException, DataServiceConnectionException, DatabaseNotFoundException, IdentifierNotFoundException, SearchServiceException, SearchServiceConnectionException { diff --git a/dbrepo-metadata-service/test/src/main/java/at/tuwien/test/BaseTest.java b/dbrepo-metadata-service/test/src/main/java/at/tuwien/test/BaseTest.java index 1f4cc4e6691c5108f2fb61e806dc9e488b926f68..490c902295d9c50977caa0ab2b66a462ba6d514b 100644 --- a/dbrepo-metadata-service/test/src/main/java/at/tuwien/test/BaseTest.java +++ b/dbrepo-metadata-service/test/src/main/java/at/tuwien/test/BaseTest.java @@ -6201,6 +6201,10 @@ public abstract class BaseTest { public static final IdentifierDto IDENTIFIER_1_DTO = IdentifierDto.builder() .id(IDENTIFIER_1_ID) .databaseId(DATABASE_1_ID) + .links(LinksDto.builder() + .self("/api/identifier/" + IDENTIFIER_1_ID) + .selfHtml("/pid/" + IDENTIFIER_1_ID) + .build()) .queryId(QUERY_1_ID) .descriptions(new LinkedList<>(List.of(IDENTIFIER_1_DESCRIPTION_1_DTO))) .titles(new LinkedList<>(List.of(IDENTIFIER_1_TITLE_1_DTO, IDENTIFIER_1_TITLE_2_DTO))) @@ -6488,6 +6492,11 @@ public abstract class BaseTest { .id(IDENTIFIER_5_ID) .databaseId(DATABASE_2_ID) .queryId(QUERY_2_ID) + .links(LinksDto.builder() + .self("/api/identifier/" + IDENTIFIER_5_ID) + .selfHtml("/pid/" + IDENTIFIER_5_ID) + .data("/api/database/" + DATABASE_2_ID + "/subset/" + QUERY_2_ID + "/data") + .build()) .descriptions(new LinkedList<>(List.of(IDENTIFIER_5_DESCRIPTION_1_DTO))) .titles(new LinkedList<>(List.of(IDENTIFIER_5_TITLE_1_DTO))) .doi(IDENTIFIER_5_DOI) @@ -6769,6 +6778,11 @@ public abstract class BaseTest { .id(IDENTIFIER_6_ID) .databaseId(DATABASE_3_ID) .queryId(QUERY_3_ID) + .links(LinksDto.builder() + .self("/api/identifier/" + IDENTIFIER_6_ID) + .selfHtml("/pid/" + IDENTIFIER_6_ID) + .data("/api/database/" + DATABASE_3_ID + "/subset/" + QUERY_3_ID + "/data") + .build()) .descriptions(new LinkedList<>(List.of(IDENTIFIER_6_DESCRIPTION_1_DTO))) .titles(new LinkedList<>(List.of(IDENTIFIER_6_TITLE_1_DTO))) .doi(IDENTIFIER_6_DOI) @@ -6878,6 +6892,10 @@ public abstract class BaseTest { public static final IdentifierDto IDENTIFIER_7_DTO = IdentifierDto.builder() .id(IDENTIFIER_7_ID) .databaseId(DATABASE_4_ID) + .links(LinksDto.builder() + .self("/api/identifier/" + IDENTIFIER_7_ID) + .selfHtml("/pid/" + IDENTIFIER_7_ID) + .build()) .descriptions(new LinkedList<>()) .titles(new LinkedList<>()) .doi(IDENTIFIER_7_DOI) @@ -6986,6 +7004,11 @@ public abstract class BaseTest { .id(IDENTIFIER_2_ID) .queryId(QUERY_1_ID) .databaseId(DATABASE_1_ID) + .links(LinksDto.builder() + .self("/api/identifier/" + IDENTIFIER_2_ID) + .selfHtml("/pid/" + IDENTIFIER_2_ID) + .data("/api/database/" + DATABASE_1_ID + "/subset/" + QUERY_1_ID + "/data") + .build()) .descriptions(new LinkedList<>()) .titles(new LinkedList<>()) .doi(IDENTIFIER_2_DOI) @@ -7085,6 +7108,11 @@ public abstract class BaseTest { .id(IDENTIFIER_3_ID) .databaseId(DATABASE_1_ID) .viewId(VIEW_1_ID) + .links(LinksDto.builder() + .self("/api/identifier/" + IDENTIFIER_3_ID) + .selfHtml("/pid/" + IDENTIFIER_3_ID) + .data("/api/database/" + DATABASE_1_ID + "/view/" + VIEW_1_ID + "/data") + .build()) .descriptions(new LinkedList<>()) .titles(new LinkedList<>()) .doi(IDENTIFIER_3_DOI) @@ -7185,6 +7213,11 @@ public abstract class BaseTest { .id(IDENTIFIER_4_ID) .databaseId(DATABASE_1_ID) .tableId(TABLE_1_ID) + .links(LinksDto.builder() + .self("/api/identifier/" + IDENTIFIER_4_ID) + .selfHtml("/pid/" + IDENTIFIER_4_ID) + .data("/api/database/" + DATABASE_1_ID + "/table/" + TABLE_1_ID + "/data") + .build()) .descriptions(new LinkedList<>()) .titles(new LinkedList<>()) .doi(IDENTIFIER_4_DOI)