diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/AccessEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/AccessEndpoint.java index 1c9ade9d90a6ad7d7cb4a809fc64a33f23b2905b..054bc7cfa9e29eb819ec0329d6c4ba23aa559470 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/AccessEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/AccessEndpoint.java @@ -59,6 +59,11 @@ public class AccessEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Failed giving access", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "404", description = "Database or user not found", content = {@Content( @@ -75,7 +80,7 @@ public class AccessEndpoint { @Valid @RequestBody DatabaseGiveAccessDto accessDto, @NotNull Principal principal) throws DatabaseNotFoundException, UserNotFoundException, NotAllowedException, QueryMalformedException, - DatabaseMalformedException, KeycloakRemoteException, AccessDeniedException { + DatabaseMalformedException { log.debug("endpoint give access to database, databaseId={}, userId={}, accessDto={}, {}", databaseId, userId, accessDto, PrincipalUtil.formatForDebug(principal)); try { accessService.find(databaseId, userId); @@ -119,7 +124,7 @@ public class AccessEndpoint { @Valid @RequestBody DatabaseModifyAccessDto accessDto, @NotNull Principal principal) throws DatabaseNotFoundException, UserNotFoundException, NotAllowedException, QueryMalformedException, - DatabaseMalformedException, AccessDeniedException, KeycloakRemoteException { + DatabaseMalformedException, AccessDeniedException { log.debug("endpoint modify access to database, databaseId={}, userId={}, accessDto={}, {}", databaseId, userId, accessDto, PrincipalUtil.formatForDebug(principal)); accessService.find(databaseId, userId); accessService.update(databaseId, userId, accessDto); @@ -143,8 +148,8 @@ public class AccessEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", - description = "Check access is not permitted", + @ApiResponse(responseCode = "404", + description = "Database not found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), @@ -173,18 +178,13 @@ public class AccessEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "404", - description = "User with access was not found", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", - description = "Revoke of access not permitted", + @ApiResponse(responseCode = "403", + description = "Revoke of access not permitted as no access was found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "403", - description = "Revoke of access not permitted as no access was found", + @ApiResponse(responseCode = "404", + description = "User, database with access was not found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/ContainerEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/ContainerEndpoint.java index 04f49f65b80f1361bef8689f62306e60521b9fba..c0e01632f35a48bda6b0be6534d84b0a054b6416 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/ContainerEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/ContainerEndpoint.java @@ -84,16 +84,6 @@ public class ContainerEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ContainerBriefDto.class))}), - @ApiResponse(responseCode = "502", - description = "Failed to connect", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "404", - description = "Container image or user could not be found", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "404", description = "Container image or user could not be found", content = {@Content( @@ -126,24 +116,14 @@ public class ContainerEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ContainerDto.class))}), - @ApiResponse(responseCode = "502", - description = "Failed to connect", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "404", description = "Container image could not be found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "502", - description = "Connection to the container failed", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), }) public ResponseEntity<ContainerDto> findById(@NotNull @PathVariable("id") Long containerId) - throws ContainerNotFoundException { + throws ContainerNotFoundException { log.debug("endpoint find container, id={}", containerId); final Container container = containerService.find(containerId); final ContainerDto dto = containerMapper.containerToContainerDto(container); @@ -159,15 +139,9 @@ public class ContainerEndpoint { @Operation(summary = "Delete some container", security = @SecurityRequirement(name = "bearerAuth")) @ApiResponses(value = { @ApiResponse(responseCode = "202", - description = "Deleted container successfully", - content = {@Content}), - @ApiResponse(responseCode = "409", - description = "Container is still running", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "410", - description = "Container is already removed", + description = "Deleted container successfully"), + @ApiResponse(responseCode = "404", + description = "Container not found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/DatabaseEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/DatabaseEndpoint.java index 57b62ef6699fc6443f72709392a3ab67d671dac2..beec5ad35112142480210e50c394df248cff2f29 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/DatabaseEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/DatabaseEndpoint.java @@ -72,6 +72,11 @@ public class DatabaseEndpoint { content = {@Content( mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = DatabaseBriefDto.class)))}), + @ApiResponse(responseCode = "404", + description = "User not found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), }) public ResponseEntity<List<DatabaseDto>> list(@NotNull Principal principal, @RequestParam(required = false) String filter) @@ -100,8 +105,12 @@ public class DatabaseEndpoint { @Operation(summary = "Count databases") @ApiResponses(value = { @ApiResponse(responseCode = "200", - description = "Count databases", - content = {@Content()}), + description = "Count databases"), + @ApiResponse(responseCode = "404", + description = "User not found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), }) public ResponseEntity<List<DatabaseDto>> count(@NotNull Principal principal, @RequestParam(required = false) String filter) @@ -140,37 +149,22 @@ public class DatabaseEndpoint { mediaType = "application/json", schema = @Schema(implementation = DatabaseBriefDto.class))}), @ApiResponse(responseCode = "400", - description = "Database create query is malformed", + description = "Database create query is malformed or image is not supported", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "404", - description = "Container, user or database could not be found", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", + @ApiResponse(responseCode = "403", description = "Database create permission is missing or grant permissions at broker service failed", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "406", - description = "Failed to create user at broker service or virtual host could not be reached at broker service", + @ApiResponse(responseCode = "404", + description = "Container, user or database could not be found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "409", - description = "Database name already exist or query store could not be created", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "501", - description = "Container image is not supported", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "502", - description = "Connection to the container failed", + description = "Query store could not be created", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), @@ -182,11 +176,9 @@ public class DatabaseEndpoint { }) public ResponseEntity<DatabaseBriefDto> create(@Valid @RequestBody DatabaseCreateDto createDto, @NotNull Principal principal) - throws ImageNotSupportedException, ContainerNotFoundException, DatabaseMalformedException, - AmqpException, ContainerConnectionException, UserNotFoundException, - DatabaseNotFoundException, DatabaseNameExistsException, DatabaseConnectionException, - QueryMalformedException, NotAllowedException, BrokerVirtualHostModificationException, QueryStoreException, - BrokerVirtualHostGrantException, KeycloakRemoteException, AccessDeniedException, BrokerRemoteException { + throws ContainerNotFoundException, DatabaseMalformedException, UserNotFoundException, + DatabaseNotFoundException, DatabaseConnectionException, QueryMalformedException, NotAllowedException, + QueryStoreException { log.debug("endpoint create database, createDto={}, {}", createDto, PrincipalUtil.formatForDebug(principal)); final User user = userService.findByUsername(principal.getName()); final Database database = databaseService.create(createDto, principal); @@ -212,11 +204,11 @@ public class DatabaseEndpoint { mediaType = "application/json", schema = @Schema(implementation = DatabaseDto.class))}), @ApiResponse(responseCode = "404", - description = "Database or user could not be found", + description = "Database could not be found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", + @ApiResponse(responseCode = "403", description = "Visibility modification is not permitted", content = {@Content( mediaType = "application/json", @@ -225,10 +217,9 @@ public class DatabaseEndpoint { public ResponseEntity<DatabaseDto> visibility(@NotNull @PathVariable Long id, @Valid @RequestBody DatabaseModifyVisibilityDto data, @NotNull Principal principal) throws DatabaseNotFoundException, - UserNotFoundException, NotAllowedException { + NotAllowedException { log.debug("endpoint update database, id={}, data={}, {}", id, data, PrincipalUtil.formatForDebug(principal)); final Database database = databaseService.findById(id); - final User user = userService.findByUsername(principal.getName()); if (!database.getOwnedBy().equals(UserUtil.getId(principal))) { log.error("Failed to create database: not owner"); throw new NotAllowedException(("Failed to create database: not owner")); @@ -255,7 +246,7 @@ public class DatabaseEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", + @ApiResponse(responseCode = "403", description = "Transfer of ownership is not permitted", content = {@Content( mediaType = "application/json", @@ -264,7 +255,7 @@ public class DatabaseEndpoint { public ResponseEntity<DatabaseDto> transfer(@NotNull @PathVariable Long id, @Valid @RequestBody DatabaseTransferDto transferDto, @NotNull Principal principal) throws DatabaseNotFoundException, - UserNotFoundException, NotAllowedException, KeycloakRemoteException, AccessDeniedException { + UserNotFoundException, NotAllowedException { log.debug("endpoint update database, id={}, transferDto={}, {}", id, transferDto, PrincipalUtil.formatForDebug(principal)); final Database database = databaseService.findById(id); final User user = userService.findByUsername(principal.getName()); @@ -289,7 +280,12 @@ public class DatabaseEndpoint { mediaType = "application/json", schema = @Schema(implementation = DatabaseDto.class))}), @ApiResponse(responseCode = "404", - description = "Database could not be found", + description = "Database or exchange could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "503", + description = "Connection to the broker service could not be established", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/IdentifierEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/IdentifierEndpoint.java index d5bcd75118ae9d07aa007f0703062300fd5a0708..aac1e1c4ef266fed4be72521518fb5821acb084e 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/IdentifierEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/IdentifierEndpoint.java @@ -111,6 +111,11 @@ public class IdentifierEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = IdentifierDto.class))}), + @ApiResponse(responseCode = "204", + description = "Identifier could not be created", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "400", description = "Identifier form contains invalid request data", content = {@Content( @@ -146,14 +151,17 @@ public class IdentifierEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "503", + description = "DataCite system did not respond", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), }) public ResponseEntity<IdentifierDto> create(@NotNull @Valid @RequestBody IdentifierSaveDto data, - @NotNull Principal principal) - throws IdentifierAlreadyExistsException, QueryNotFoundException, IdentifierPublishingNotAllowedException, - RemoteUnavailableException, UserNotFoundException, DatabaseNotFoundException, IdentifierRequestException, - NotAllowedException, ViewNotFoundException, QueryStoreException, DatabaseConnectionException, - ImageNotSupportedException, IdentifierNotFoundException, TableNotFoundException, TableMalformedException, - QueryMalformedException, FileStorageException, DataDbSidecarException { + @NotNull Principal principal) throws DatabaseNotFoundException, + NotAllowedException, IdentifierRequestException, ViewNotFoundException, TableNotFoundException, + QueryStoreException, QueryNotFoundException, ImageNotSupportedException, UserNotFoundException, + DatabaseConnectionException, RemoteUnavailableException { log.debug("endpoint create identifier, data={}, {}", data, PrincipalUtil.formatForDebug(principal)); DatabaseAccess access = null; try { diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/ImageEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/ImageEndpoint.java index e1290d84fc071a042adc47e5f50ff5d863e91100..1ac1988a2aca03557e63d19c884001bd8da06476 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/ImageEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/ImageEndpoint.java @@ -87,16 +87,6 @@ public class ImageEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "404", - description = "User could not be found", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "502", - description = "Failed to connect", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "409", description = "Image already exists", content = {@Content( @@ -104,8 +94,8 @@ public class ImageEndpoint { schema = @Schema(implementation = ApiErrorDto.class))}), }) public ResponseEntity<ImageDto> create(@Valid @RequestBody ImageCreateDto data, - @NotNull Principal principal) throws ImageNotFoundException, - ImageAlreadyExistsException, UserNotFoundException, ImageInvalidException { + @NotNull Principal principal) throws ImageAlreadyExistsException, + ImageInvalidException { log.debug("endpoint create image, data={}, {}", data, PrincipalUtil.formatForDebug(principal)); if (data.getDefaultPort() == null) { log.error("Failed to create image, default port is null"); diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/MaintenanceEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/MaintenanceEndpoint.java index b71109d62ba5cd75e113a9f3f6d89677f5bd3ae8..e0702cd8a5eeed8bb94102db3f46aed1f7ff5b7f 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/MaintenanceEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/MaintenanceEndpoint.java @@ -1,5 +1,6 @@ package at.tuwien.endpoints; +import at.tuwien.api.error.ApiErrorDto; import at.tuwien.api.maintenance.BannerMessageBriefDto; import at.tuwien.api.maintenance.BannerMessageCreateDto; import at.tuwien.api.maintenance.BannerMessageDto; @@ -69,6 +70,11 @@ public class MaintenanceEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = BannerMessageDto.class))}), + @ApiResponse(responseCode = "404", + description = "Could not find message", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), }) public ResponseEntity<BannerMessageDto> find(@NotNull @PathVariable("id") Long messageId) throws BannerMessageNotFoundException { @@ -131,7 +137,7 @@ public class MaintenanceEndpoint { description = "Could not find message", content = {@Content( mediaType = "application/json", - schema = @Schema(implementation = BannerMessageNotFoundException.class))}), + schema = @Schema(implementation = ApiErrorDto.class))}), }) public ResponseEntity<BannerMessageDto> update(@NotNull @PathVariable("id") Long messageId, @Valid @RequestBody BannerMessageUpdateDto data) @@ -155,7 +161,7 @@ public class MaintenanceEndpoint { description = "Could not find message", content = {@Content( mediaType = "application/json", - schema = @Schema(implementation = BannerMessageNotFoundException.class))}), + schema = @Schema(implementation = ApiErrorDto.class))}), }) public ResponseEntity<?> delete(@NotNull @PathVariable("id") Long messageId) throws BannerMessageNotFoundException { diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/OntologyEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/OntologyEndpoint.java index 649c51dfe11c924bc24ea8108892022be2b80fb5..b03d183707f2767c8e9b2c7929424e4198aa3f4f 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/OntologyEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/OntologyEndpoint.java @@ -96,16 +96,10 @@ public class OntologyEndpoint { description = "Registered ontology successfully", content = {@Content( mediaType = "application/json", - schema = @Schema(implementation = OntologyDto.class))}), - @ApiResponse(responseCode = "201", - description = "Could not find user", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), + schema = @Schema(implementation = OntologyDto.class))}) }) public ResponseEntity<OntologyDto> create(@NotNull @Valid @RequestBody OntologyCreateDto data, - @NotNull Principal principal) throws UserNotFoundException, - KeycloakRemoteException, AccessDeniedException { + @NotNull Principal principal) { log.debug("endpoint create ontology, data={}, {}", data, PrincipalUtil.formatForDebug(principal)); final OntologyDto dto = ontologyMapper.ontologyToOntologyDto(ontologyService.create(data, principal)); log.trace("create ontology resulted in dto {}", dto); diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/PersistenceEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/PersistenceEndpoint.java index dda30b78d036ffe4ad6b7334de795410135d172a..a8d46160496c2144e3a92544ffcfed95af0eb7dc 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/PersistenceEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/PersistenceEndpoint.java @@ -72,11 +72,26 @@ public class PersistenceEndpoint { mediaType = "text/bibliography", schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "404", - description = "Identifier could not be exported from database as the resource was not found", + description = "Identifier could not be found", content = {@Content( mediaType = "text/csv", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "502", + @ApiResponse(responseCode = "409", + description = "Exported resource was not found", + content = {@Content( + mediaType = "text/csv", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "410", + description = "Failed to retrieve from S3 endpoint", + content = {@Content( + mediaType = "text/csv", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "422", + description = "Failed to retrieve from database sidecar", + content = {@Content( + mediaType = "text/csv", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "503", description = "Identifier could not exported from database as it is not reachable", content = {@Content( mediaType = "text/csv", @@ -85,9 +100,9 @@ public class PersistenceEndpoint { public ResponseEntity<?> find(@Valid @PathVariable("pid") Long pid, @RequestHeader(HttpHeaders.ACCEPT) String accept, @NotNull Principal principal) throws IdentifierNotFoundException, - QueryNotFoundException, RemoteUnavailableException, IdentifierRequestException, UserNotFoundException, - QueryStoreException, TableMalformedException, DatabaseConnectionException, QueryMalformedException, - DatabaseNotFoundException, ImageNotSupportedException, FileStorageException, DataDbSidecarException { + QueryNotFoundException, IdentifierRequestException, UserNotFoundException, QueryStoreException, + TableMalformedException, DatabaseConnectionException, QueryMalformedException, DatabaseNotFoundException, + ImageNotSupportedException, FileStorageException, DataDbSidecarException { log.debug("endpoint find identifier, pid={}, accept={}", pid, accept); final Identifier identifier = identifierService.find(pid); log.info("Found persistent identifier with id {}", identifier.getId()); @@ -151,15 +166,14 @@ public class PersistenceEndpoint { @Operation(summary = "Delete some identifier", security = @SecurityRequirement(name = "bearerAuth")) @ApiResponses(value = { @ApiResponse(responseCode = "202", - description = "Deleted identifier", - content = {@Content}), - @ApiResponse(responseCode = "404", - description = "Identifier or database could not be found", + description = "Deleted identifier"), + @ApiResponse(responseCode = "403", + description = "Deleting identifier not permitted", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", - description = "Deleting identifier not permitted", + @ApiResponse(responseCode = "404", + description = "Identifier or database could not be found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}) diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/QueryEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/QueryEndpoint.java index 612ad08e75e619937e2bac2383caaf46cb7f1abb..0b1c053865683fc0a2ed78cf896c792ea6d2530f 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/QueryEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/QueryEndpoint.java @@ -4,6 +4,7 @@ import at.tuwien.ExportResource; import at.tuwien.SortType; import at.tuwien.api.database.query.ExecuteStatementDto; import at.tuwien.api.database.query.QueryResultDto; +import at.tuwien.api.error.ApiErrorDto; import at.tuwien.entities.database.Database; import at.tuwien.exception.*; import at.tuwien.querystore.Query; @@ -15,6 +16,10 @@ import at.tuwien.utils.UserUtil; import at.tuwien.validation.EndpointValidator; import io.micrometer.observation.annotation.Observed; import io.swagger.v3.oas.annotations.Operation; +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.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; @@ -53,6 +58,38 @@ public class QueryEndpoint { @Observed(name = "dbr_query_execute") @PreAuthorize("hasAuthority('execute-query')") @Operation(summary = "Execute query", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Executed query", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = QueryResultDto.class))}), + @ApiResponse(responseCode = "400", + description = "Image is not supported", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Execute query not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database, query or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "409", + description = "Could not store query in query store", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "417", + description = "Could not parse columns", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}) + }) public ResponseEntity<QueryResultDto> execute(@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @Valid @RequestBody ExecuteStatementDto data, @RequestParam(value = "page", required = false) Long page, @@ -61,8 +98,8 @@ public class QueryEndpoint { @RequestParam(required = false) SortType sortDirection, @RequestParam(required = false) String sortColumn) throws DatabaseNotFoundException, ImageNotSupportedException, QueryStoreException, QueryMalformedException, - ColumnParseException, UserNotFoundException, TableMalformedException, DatabaseConnectionException, - SortException, PaginationException, NotAllowedException, KeycloakRemoteException, AccessDeniedException, QueryNotFoundException { + ColumnParseException, UserNotFoundException, TableMalformedException, SortException, PaginationException, + NotAllowedException, AccessDeniedException, QueryNotFoundException { log.debug("endpoint execute query, databaseId={}, data={}, page={}, size={}, sortDirection={}, sortColumn={}, {}", databaseId, data, page, size, sortDirection, sortColumn, PrincipalUtil.formatForDebug(principal)); /* check */ @@ -85,6 +122,38 @@ public class QueryEndpoint { @Transactional(readOnly = true) @Observed(name = "dbr_query_reexecute") @Operation(summary = "Re-execute some query", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Executed query", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = QueryResultDto.class))}), + @ApiResponse(responseCode = "400", + description = "Image is not supported", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Execute query not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database or query could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "409", + description = "Could not store query in query store", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "417", + description = "Could not parse columns", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}) + }) public ResponseEntity<QueryResultDto> reExecute(@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("queryId") Long queryId, Principal principal, @@ -92,9 +161,9 @@ public class QueryEndpoint { @RequestParam(value = "size", required = false) Long size, @RequestParam(required = false) SortType sortDirection, @RequestParam(required = false) String sortColumn) - throws QueryStoreException, QueryNotFoundException, DatabaseNotFoundException, ImageNotSupportedException, - QueryMalformedException, TableMalformedException, ColumnParseException, DatabaseConnectionException, - SortException, PaginationException, UserNotFoundException, NotAllowedException, AccessDeniedException { + throws DatabaseNotFoundException, ImageNotSupportedException, QueryStoreException, QueryMalformedException, + ColumnParseException, TableMalformedException, SortException, PaginationException, NotAllowedException, + AccessDeniedException, QueryNotFoundException { log.debug("endpoint re-execute query, databaseId={}, queryId={}, page={}, size={}, sortDirection={}, sortColumn={}, {}", databaseId, queryId, page, size, sortDirection, sortColumn, PrincipalUtil.formatForDebug(principal)); endpointValidator.validateDataParams(page, size, sortDirection, sortColumn); @@ -113,12 +182,39 @@ public class QueryEndpoint { @Transactional(readOnly = true) @Observed(name = "dbr_query_reexecute_count") @Operation(summary = "Re-execute some query", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Executed query", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = QueryResultDto.class))}), + @ApiResponse(responseCode = "400", + description = "Image is not supported", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Execute query not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database or query could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "417", + description = "Could not parse columns", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}) + }) public ResponseEntity<Long> reExecuteCount(@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("queryId") Long queryId, Principal principal) throws QueryStoreException, QueryNotFoundException, DatabaseNotFoundException, ImageNotSupportedException, QueryMalformedException, TableMalformedException, ColumnParseException, NotAllowedException, - DatabaseConnectionException, UserNotFoundException, AccessDeniedException { + AccessDeniedException { log.debug("endpoint re-execute query count, databaseId={}, queryId={}, {}", databaseId, queryId, PrincipalUtil.formatForDebug(principal)); endpointValidator.validateOnlyAccessOrPublic(databaseId, principal); /* execute */ @@ -133,13 +229,46 @@ public class QueryEndpoint { @Transactional(readOnly = true) @Observed(name = "dbr_query_export") @Operation(summary = "Exports some query", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "Executed query"), + @ApiResponse(responseCode = "400", + description = "Image is not supported", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Execute query not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database or query could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "409", + description = "Export of query failed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "410", + description = "Could not find in S3 storage", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "422", + description = "Sidecar failed to export", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}) + }) public ResponseEntity<?> export(@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("queryId") Long queryId, @RequestHeader(HttpHeaders.ACCEPT) String accept, Principal principal) throws QueryStoreException, QueryNotFoundException, DatabaseNotFoundException, ImageNotSupportedException, - TableMalformedException, FileStorageException, QueryMalformedException, DatabaseConnectionException, - UserNotFoundException, NotAllowedException, DataDbSidecarException { + FileStorageException, QueryMalformedException, NotAllowedException, DataDbSidecarException { log.debug("endpoint export query, databaseId={}, queryId={}, accept={}, {}", databaseId, queryId, accept, PrincipalUtil.formatForDebug(principal)); final Database database = databaseService.find(databaseId); if (!database.getIsPublic()) { diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/StoreEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/StoreEndpoint.java index 63ff9ed1b6302c9356288edc4a6902330798e483..1ff758a309f0b54c2f5f48005dc525d6571b698e 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/StoreEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/StoreEndpoint.java @@ -219,39 +219,38 @@ public class StoreEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = QueryDto.class))}), - @ApiResponse(responseCode = "404", - description = "Database, query or user could not be found", + @ApiResponse(responseCode = "400", + description = "Image not supported", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", - description = "Persist query is not permitted", + @ApiResponse(responseCode = "403", + description = "Not allowed to persist query", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "409", - description = "Query is already persisted", + @ApiResponse(responseCode = "404", + description = "Database, query or user could not be found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "501", - description = "Image is not supported", + @ApiResponse(responseCode = "405", + description = "Persist query is not permitted", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "504", - description = "Query store failed to persist query", + @ApiResponse(responseCode = "412", + description = "Query is already persisted", content = {@Content( mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), + schema = @Schema(implementation = ApiErrorDto.class))}) }) public ResponseEntity<QueryDto> persist(@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("queryId") Long queryId, @NotNull @Valid @RequestBody QueryPersistDto data, @NotNull Principal principal) - throws QueryStoreException, DatabaseNotFoundException, ImageNotSupportedException, - DatabaseConnectionException, UserNotFoundException, NotAllowedException, AccessDeniedException, - IdentifierAlreadyPublishedException { + throws QueryStoreException, DatabaseNotFoundException, ImageNotSupportedException, UserNotFoundException, + NotAllowedException, AccessDeniedException, IdentifierAlreadyPublishedException { log.debug("endpoint persist query, container, databaseId={}, queryId={}, data.persist={}, {}", databaseId, queryId, data.getPersist(), PrincipalUtil.formatForDebug(principal)); /* check */ endpointValidator.validateOnlyAccessOrPublic(databaseId, principal); diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/TableColumnEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/TableColumnEndpoint.java index 3cc440c088ba49caee6d7b5888193c65274125fd..999a66bb70f150e7fa1459724f782eca4744636c 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/TableColumnEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/TableColumnEndpoint.java @@ -67,15 +67,10 @@ public class TableColumnEndpoint { mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "404", - description = "Table, database, semantic concept, unit of measurement or container could not be found", + description = "Table or database could not be found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", - description = "Update column semantics not permitted", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ColumnDto.class))}), }) public ResponseEntity<ColumnDto> update(@NotNull @PathVariable("id") Long id, @NotNull @PathVariable("tableId") Long tableId, @@ -83,9 +78,8 @@ public class TableColumnEndpoint { @NotNull @Valid @RequestBody ColumnSemanticsUpdateDto updateDto, @NotNull Principal principal, @NotNull @RequestHeader("Authorization") String authorization) - throws TableNotFoundException, TableMalformedException, DatabaseNotFoundException, - ContainerNotFoundException, NotAllowedException, SemanticEntityPersistException, - SemanticEntityNotFoundException, QueryMalformedException, AccessDeniedException { + throws TableNotFoundException, TableMalformedException, DatabaseNotFoundException, NotAllowedException, + AccessDeniedException { log.debug("endpoint update table, id={}, tableId={}, columnId={}, {}", id, tableId, columnId, PrincipalUtil.formatForDebug(principal)); if (principal != null && !UserUtil.hasRole(principal, "modify-foreign-table-column-semantics")) { endpointValidator.validateOnlyAccess(id, principal, true); diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/TableDataEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/TableDataEndpoint.java index f2e1fb567c74bf3648ea95773c64a0c4cd0410d0..0b1f25f0fe4dc5e105a4e3626dd186471a507cb6 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/TableDataEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/TableDataEndpoint.java @@ -5,6 +5,8 @@ import at.tuwien.api.database.query.ImportDto; import at.tuwien.api.database.query.QueryResultDto; import at.tuwien.api.database.table.TableCsvDeleteDto; import at.tuwien.api.database.table.TableCsvDto; +import at.tuwien.api.database.table.columns.ColumnDto; +import at.tuwien.api.error.ApiErrorDto; import at.tuwien.entities.database.Database; import at.tuwien.exception.*; import at.tuwien.service.DatabaseService; @@ -14,6 +16,10 @@ import at.tuwien.utils.UserUtil; import at.tuwien.validation.EndpointValidator; import io.micrometer.observation.annotation.Observed; import io.swagger.v3.oas.annotations.Operation; +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.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; @@ -50,13 +56,31 @@ public class TableDataEndpoint { @Observed(name = "dbr_table_data_insert") @PreAuthorize("hasAuthority('insert-table-data')") @Operation(summary = "Insert data", security = @SecurityRequirement(name = "bearerAuth")) - public ResponseEntity<Void> insert(@NotNull @PathVariable("databaseId") Long databaseId, - @NotNull @PathVariable("tableId") Long tableId, - @NotNull @Valid @RequestBody TableCsvDto data, - @NotNull Principal principal) - throws TableNotFoundException, DatabaseNotFoundException, TableMalformedException, - ImageNotSupportedException, ContainerNotFoundException, DatabaseConnectionException, UserNotFoundException, - NotAllowedException, AccessDeniedException { + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Inserted data successfully"), + @ApiResponse(responseCode = "400", + description = "Insert table data is malformed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Access to the database is forbidden", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Table or database could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) + public ResponseEntity<?> insert(@NotNull @PathVariable("databaseId") Long databaseId, + @NotNull @PathVariable("tableId") Long tableId, + @NotNull @Valid @RequestBody TableCsvDto data, + @NotNull Principal principal) + throws TableNotFoundException, DatabaseNotFoundException, TableMalformedException, NotAllowedException, + AccessDeniedException { log.debug("endpoint insert data, databaseId={}, tableId={}, data={}, {}", databaseId, tableId, data, PrincipalUtil.formatForDebug(principal)); /* check */ endpointValidator.validateOnlyWriteOwnOrWriteAllAccess(databaseId, tableId, principal); @@ -71,13 +95,31 @@ public class TableDataEndpoint { @PreAuthorize("hasAuthority('delete-table-data')") @Observed(name = "dbr_table_data_delete") @Operation(summary = "Delete data", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Deleted table data successfully"), + @ApiResponse(responseCode = "400", + description = "Table data or query is malformed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Access to the database is forbidden", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Table or database could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<Void> delete(@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("tableId") Long tableId, @NotNull @Valid @RequestBody TableCsvDeleteDto data, @NotNull Principal principal) throws TableNotFoundException, DatabaseNotFoundException, TableMalformedException, - ImageNotSupportedException, DatabaseConnectionException, QueryMalformedException, UserNotFoundException, - NotAllowedException, AccessDeniedException { + ImageNotSupportedException, QueryMalformedException, NotAllowedException, AccessDeniedException { log.debug("endpoint delete data, databaseId={}, tableId={}, data={}, {}", databaseId, tableId, data, PrincipalUtil.formatForDebug(principal)); /* check */ endpointValidator.validateOnlyWriteOwnOrWriteAllAccess(databaseId, tableId, principal); @@ -92,12 +134,35 @@ public class TableDataEndpoint { @PreAuthorize("hasAuthority('insert-table-data')") @Observed(name = "dbr_table_data_import") @Operation(summary = "Insert data from csv", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Import table data successfully"), + @ApiResponse(responseCode = "400", + description = "Table data is malformed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Access to the database is forbidden", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Table or database could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "422", + description = "Could not import csv via sidecar", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<Void> importCsv(@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("tableId") Long tableId, @NotNull @Valid @RequestBody ImportDto data, @NotNull Principal principal) throws TableNotFoundException, DatabaseNotFoundException, TableMalformedException, - ImageNotSupportedException, DatabaseConnectionException, QueryMalformedException, UserNotFoundException, NotAllowedException, AccessDeniedException, DataDbSidecarException { log.debug("endpoint insert data from csv, databaseId={}, tableId={}, data={}, {}", databaseId, tableId, data, PrincipalUtil.formatForDebug(principal)); /* check */ @@ -112,6 +177,30 @@ public class TableDataEndpoint { @Transactional(readOnly = true) @Observed(name = "dbr_table_data_findall") @Operation(summary = "Find data", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Get table data successfully"), + @ApiResponse(responseCode = "400", + description = "Table data is malformed or image is not supported", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Access to the database is forbidden", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Table or database could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "422", + description = "Could not import csv via sidecar", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<QueryResultDto> getAll(@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("tableId") Long tableId, @NotNull Principal principal, @@ -120,9 +209,9 @@ public class TableDataEndpoint { @RequestParam(required = false) Long size, @RequestParam(required = false) SortType sortDirection, @RequestParam(required = false) String sortColumn) - throws TableNotFoundException, DatabaseNotFoundException, DatabaseConnectionException, - ImageNotSupportedException, TableMalformedException, PaginationException, QueryMalformedException, - UserNotFoundException, SortException, NotAllowedException, AccessDeniedException { + throws TableNotFoundException, DatabaseNotFoundException, ImageNotSupportedException, + TableMalformedException, PaginationException, QueryMalformedException, SortException, NotAllowedException, + AccessDeniedException { log.debug("endpoint find table data, databaseId={}, tableId={}, timestamp={}, page={}, size={}, sortDirection={}, sortColumn={}, {}", databaseId, tableId, timestamp, page, size, sortDirection, sortColumn, PrincipalUtil.formatForDebug(principal)); /* check */ @@ -144,13 +233,37 @@ public class TableDataEndpoint { @Transactional(readOnly = true) @Observed(name = "dbr_table_data_countall") @Operation(summary = "Find data", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Get table data count successfully"), + @ApiResponse(responseCode = "400", + description = "Table data is malformed or image is not supported", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Access to the database is forbidden", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Table or database could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "422", + description = "Could not import csv via sidecar", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<Long> getCount(@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("tableId") Long tableId, @NotNull Principal principal, @RequestParam(required = false) Instant timestamp) - throws TableNotFoundException, DatabaseNotFoundException, DatabaseConnectionException, - ImageNotSupportedException, TableMalformedException, QueryStoreException, QueryMalformedException, - UserNotFoundException, NotAllowedException, AccessDeniedException { + throws TableNotFoundException, DatabaseNotFoundException, ImageNotSupportedException, + TableMalformedException, QueryStoreException, QueryMalformedException, NotAllowedException, + AccessDeniedException { log.debug("endpoint find table data, databaseId={}, tableId={}, timestamp={}, {}", databaseId, tableId, timestamp, PrincipalUtil.formatForDebug(principal)); /* check */ endpointValidator.validateOnlyAccessOrPublic(databaseId, principal); diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/TableEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/TableEndpoint.java index f3a8601a8dab6aba00606da01f2160e6582a6982..e3be34e34746452667def2da8ef63d937d6fdf62 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/TableEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/TableEndpoint.java @@ -68,13 +68,13 @@ public class TableEndpoint { content = {@Content( mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = TableBriefDto.class)))}), - @ApiResponse(responseCode = "404", - description = "Database could not be found", + @ApiResponse(responseCode = "403", + description = "List tables not permitted", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", - description = "List tables not permitted", + @ApiResponse(responseCode = "404", + description = "Database could not be found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), @@ -109,13 +109,13 @@ public class TableEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "404", - description = "Database, container or user could not be found", + @ApiResponse(responseCode = "403", + description = "Create table not permitted", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", - description = "Create table not permitted", + @ApiResponse(responseCode = "404", + description = "Database, container or user could not be found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), @@ -124,23 +124,13 @@ public class TableEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "501", - description = "Image is not supported", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "504", - description = "Broker service failed to create queue", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), }) public ResponseEntity<TableBriefDto> create(@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @Valid @RequestBody TableCreateDto createDto, @NotNull Principal principal) - throws ImageNotSupportedException, DatabaseNotFoundException, TableMalformedException, AmqpException, - TableNameExistsException, ContainerNotFoundException, UserNotFoundException, QueryMalformedException, - NotAllowedException, AccessDeniedException, TableNotFoundException { + throws ImageNotSupportedException, DatabaseNotFoundException, TableMalformedException, + TableNameExistsException, QueryMalformedException, NotAllowedException, AccessDeniedException, + TableNotFoundException { log.debug("endpoint create table, databaseId={}, createDto={}, {}", databaseId, createDto, PrincipalUtil.formatForDebug(principal)); /* checks */ if (createDto.getName().isBlank()) { @@ -177,8 +167,8 @@ public class TableEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", - description = "Find table not permitted", + @ApiResponse(responseCode = "503", + description = "Could not communicate with the broker service", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), @@ -207,9 +197,7 @@ public class TableEndpoint { @ApiResponses(value = { @ApiResponse(responseCode = "202", description = "Delete table successfully", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = TableDto.class))}), + content = {@Content}), @ApiResponse(responseCode = "400", description = "Delete table query resulted in an invalid query statement", content = {@Content( @@ -224,29 +212,13 @@ public class TableEndpoint { description = "Table, database or container could not be found", content = {@Content( mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", - description = "Delete table not permitted", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "423", - description = "Delete table resulted in an invalid state", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "501", - description = "Image is not supported", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), + schema = @Schema(implementation = ApiErrorDto.class))}) }) - public ResponseEntity<Void> delete(@NotNull @PathVariable("databaseId") Long databaseId, + public ResponseEntity<?> delete(@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("tableId") Long tableId, @NotNull Principal principal) throws TableNotFoundException, DatabaseNotFoundException, ImageNotSupportedException, - DataProcessingException, ContainerNotFoundException, TableMalformedException, QueryMalformedException, - NotAllowedException { + TableMalformedException, QueryMalformedException, NotAllowedException { log.debug("endpoint delete table, databaseId={}, tableId={}, {}", databaseId, tableId, PrincipalUtil.formatForDebug(principal)); final Table table = tableService.find(databaseId, tableId); /* roles */ diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/TableHistoryEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/TableHistoryEndpoint.java index f3f893fe355f8e78d4e1af28d4a5062bd22ec2c0..727b3f69c3c27d8e1a652445dcbd753bc9f37ddd 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/TableHistoryEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/TableHistoryEndpoint.java @@ -51,22 +51,17 @@ public class TableHistoryEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "404", - description = "Table, database or user could not be found", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", + @ApiResponse(responseCode = "403", description = "Find table history is not permitted", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "503", - description = "Connection to the database failed", + @ApiResponse(responseCode = "404", + description = "Table, database or user could not be found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "504", + @ApiResponse(responseCode = "409", description = "Query store failed to query table history", content = {@Content( mediaType = "application/json", @@ -75,8 +70,7 @@ public class TableHistoryEndpoint { public ResponseEntity<List<TableHistoryDto>> getAll(@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("tableId") Long tableId, @NotNull Principal principal) - throws TableNotFoundException, QueryMalformedException, DatabaseNotFoundException, - QueryStoreException, DatabaseConnectionException, UserNotFoundException { + throws TableNotFoundException, QueryMalformedException, DatabaseNotFoundException, QueryStoreException { log.debug("endpoint find all history, databaseId={}, tableId={}, {}", databaseId, tableId, PrincipalUtil.formatForDebug(principal)); final List<TableHistoryDto> history = tableService.findHistory(databaseId, tableId, principal); log.trace("find all history resulted in history {}", history); diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/UserEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/UserEndpoint.java index 2d0b400e691058f7385063b7b2da3823335c825e..4b9418005bfd9df475992e37fbff6c1978c371d7 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/UserEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/UserEndpoint.java @@ -154,20 +154,20 @@ public class UserEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = UserDto.class))}), - @ApiResponse(responseCode = "404", - description = "User was not found", + @ApiResponse(responseCode = "403", + description = "Find user is not permitted", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", - description = "Find user is not permitted", + @ApiResponse(responseCode = "404", + description = "User was not found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), }) public ResponseEntity<UserDto> find(@NotNull @PathVariable("id") UUID id, - @NotNull Principal principal) throws UserNotFoundException, NotAllowedException, - KeycloakRemoteException, AccessDeniedException { + @NotNull Principal principal) throws UserNotFoundException, + NotAllowedException { log.debug("endpoint find a user, id={}, {}", id, PrincipalUtil.formatForDebug(principal)); /* check */ final User user = userService.find(id); @@ -196,13 +196,23 @@ public class UserEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = UserDto.class))}), + @ApiResponse(responseCode = "400", + description = "Modify user query is malformed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Modify user is not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "404", description = "User attribute was not found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "405", - description = "Modify user is not permitted", + description = "Foreign user modification", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), @@ -210,8 +220,7 @@ public class UserEndpoint { public ResponseEntity<UserDto> modify(@NotNull @PathVariable("id") UUID id, @NotNull @Valid @RequestBody UserUpdateDto data, @NotNull Principal principal) throws UserNotFoundException, - ForeignUserException, UserAttributeNotFoundException, KeycloakRemoteException, AccessDeniedException, - QueryMalformedException, DatabaseMalformedException { + ForeignUserException, QueryMalformedException { log.debug("endpoint modify a user, id={}, data={}, {}", id, data, PrincipalUtil.formatForDebug(principal)); /* check */ if (!id.equals(UserUtil.getId(principal))) { @@ -238,13 +247,18 @@ public class UserEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = UserDto.class))}), + @ApiResponse(responseCode = "403", + description = "Modify user is not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "404", description = "User or user attribute was not found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "405", - description = "Modify user is not permitted", + description = "Foreign user modification", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), @@ -278,13 +292,23 @@ public class UserEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = UserDto.class))}), + @ApiResponse(responseCode = "403", + description = "Modify is not allowed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "404", description = "User was not found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "405", - description = "Modify user is not permitted", + description = "Foreign user modification", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "503", + description = "Authentication service does not respond", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), @@ -292,8 +316,7 @@ public class UserEndpoint { public ResponseEntity<?> password(@NotNull @PathVariable("id") UUID id, @NotNull @Valid @RequestBody UserPasswordDto data, @NotNull Principal principal) - throws UserNotFoundException, ForeignUserException, KeycloakRemoteException, AccessDeniedException, - QueryMalformedException, DatabaseMalformedException { + throws UserNotFoundException, ForeignUserException, KeycloakRemoteException, AccessDeniedException { log.debug("endpoint modify a user password, id={}, data={}, {}", id, data, PrincipalUtil.formatForDebug(principal)); /* check */ if (!id.equals(UserUtil.getId(principal))) { diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/ViewEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/ViewEndpoint.java index cf9ae3a146f444cf0dd29cf2d3925834fcfbabe1..fd379d6afd4468a6cd0fda52b8f349425335c3a6 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/ViewEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/ViewEndpoint.java @@ -74,11 +74,6 @@ public class ViewEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", - description = "Find views is not permitted", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), }) public ResponseEntity<List<ViewBriefDto>> findAll(@NotNull @PathVariable("databaseId") Long databaseId, Principal principal) throws DatabaseNotFoundException, @@ -172,21 +167,21 @@ public class ViewEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ViewDto.class))}), - @ApiResponse(responseCode = "404", - description = "Database, view or user could not be found", + @ApiResponse(responseCode = "403", + description = "Find view is not permitted", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", - description = "Find view is not permitted", + @ApiResponse(responseCode = "404", + description = "Database, view or user could not be found", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), }) public ResponseEntity<ViewDto> find(@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("viewId") Long viewId, - Principal principal) throws DatabaseNotFoundException, - NotAllowedException, ViewNotFoundException, UserNotFoundException { + Principal principal) throws DatabaseNotFoundException, ViewNotFoundException, + UserNotFoundException { log.debug("endpoint find view, databaseId={}, viewId={}, {}", databaseId, viewId, PrincipalUtil.formatForDebug(principal)); final Database database = databaseService.find(databaseId); log.trace("find view for database {}", database); @@ -209,13 +204,8 @@ public class ViewEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "401", - description = "Credentials missing", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "403", - description = "Credentials missing", + description = "Deletion not allowed", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), @@ -243,8 +233,8 @@ public class ViewEndpoint { public ResponseEntity<?> delete(@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("viewId") Long viewId, @NotNull Principal principal) throws DatabaseNotFoundException, - ViewNotFoundException, UserNotFoundException, DatabaseConnectionException, - ViewMalformedException, QueryMalformedException, NotAllowedException { + ViewNotFoundException, UserNotFoundException, DatabaseConnectionException, ViewMalformedException, + QueryMalformedException, NotAllowedException { log.debug("endpoint delete view, databaseId={}, viewId={}, {}", databaseId, viewId, PrincipalUtil.formatForDebug(principal)); /* check */ final Database database = databaseService.find(databaseId); @@ -272,13 +262,8 @@ public class ViewEndpoint { content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "401", - description = "Credentials missing", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), @ApiResponse(responseCode = "403", - description = "Credentials missing", + description = "View data not allowed", content = {@Content( mediaType = "application/json", schema = @Schema(implementation = ApiErrorDto.class))}), @@ -286,37 +271,7 @@ public class ViewEndpoint { description = "Database, view, container or user could not be found", content = {@Content( mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "405", - description = "Find data is not permitted", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "417", - description = "Parsing of resulting columns failed", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "423", - description = "Find data resulted in an invalid query statement", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "501", - description = "Image is not supported", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "503", - description = "Connection to the database failed", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), - @ApiResponse(responseCode = "504", - description = "Query store failed to query view data", - content = {@Content( - mediaType = "application/json", - schema = @Schema(implementation = ApiErrorDto.class))}), + schema = @Schema(implementation = ApiErrorDto.class))}) }) public ResponseEntity<QueryResultDto> data(@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("viewId") Long viewId, @@ -324,8 +279,7 @@ public class ViewEndpoint { @RequestParam(required = false) Long page, @RequestParam(required = false) Long size) throws DatabaseNotFoundException, NotAllowedException, ViewNotFoundException, PaginationException, - QueryStoreException, DatabaseConnectionException, TableMalformedException, QueryMalformedException, - ImageNotSupportedException, ColumnParseException, UserNotFoundException, ContainerNotFoundException, ViewMalformedException { + TableMalformedException, QueryMalformedException, UserNotFoundException { log.debug("endpoint find view data, databaseId={}, viewId={}, page={}, size={}, {}", databaseId, viewId, page, size, PrincipalUtil.formatForDebug(principal)); /* check */ endpointValidator.validateDataParams(page, size); @@ -354,12 +308,38 @@ public class ViewEndpoint { @Transactional(readOnly = true) @Observed(name = "dbr_view_data_count") @Operation(summary = "Find view data count", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "Count data successfully", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = Long.class))}), + @ApiResponse(responseCode = "400", + description = "Pagination not in valid range or find data query is malformed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Count data not allowed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database, view, container or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "409", + description = "Could not count query data", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}) + }) public ResponseEntity<Long> count(@NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("viewId") Long viewId, Principal principal) - throws DatabaseNotFoundException, ViewNotFoundException, QueryStoreException, DatabaseConnectionException, - TableMalformedException, QueryMalformedException, ImageNotSupportedException, UserNotFoundException, - ContainerNotFoundException { + throws DatabaseNotFoundException, ViewNotFoundException, QueryStoreException, TableMalformedException, + QueryMalformedException, ImageNotSupportedException, UserNotFoundException { log.debug("endpoint find view data count, databaseId={}, viewId={}, {}", databaseId, viewId, PrincipalUtil.formatForDebug(principal)); /* find */ databaseService.find(databaseId); diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/amqp/RabbitMqConsumer.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/amqp/RabbitMqConsumer.java deleted file mode 100644 index 0f32e23535458cb25e2e2fc78e21c55f10c74986..0000000000000000000000000000000000000000 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/amqp/RabbitMqConsumer.java +++ /dev/null @@ -1,101 +0,0 @@ -package at.tuwien.amqp; - -import at.tuwien.api.database.table.TableCsvDto; -import at.tuwien.exception.*; -import at.tuwien.service.QueryService; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.rabbitmq.client.AMQP; -import com.rabbitmq.client.Consumer; -import com.rabbitmq.client.Envelope; -import com.rabbitmq.client.ShutdownSignalException; -import lombok.extern.log4j.Log4j2; -import org.apache.http.auth.BasicUserPrincipal; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.client.HttpClientErrorException; - -import java.io.IOException; -import java.util.HashMap; - -@Log4j2 -public class RabbitMqConsumer implements Consumer { - - private final Long databaseId; - private final Long tableId; - private final ObjectMapper objectMapper; - private final QueryService queryService; - - public RabbitMqConsumer(Long databaseId, Long tableId, ObjectMapper objectMapper, QueryService queryService) { - this.databaseId = databaseId; - this.tableId = tableId; - this.objectMapper = objectMapper; - this.queryService = queryService; - } - - @Override - public void handleConsumeOk(String consumerTag) { - // - } - - @Override - public void handleCancelOk(String consumerTag) { - // - } - - @Override - public void handleCancel(String consumerTag) { - // - } - - @Override - public void handleShutdownSignal(String consumerTag, ShutdownSignalException sig) { - // - } - - @Override - public void handleRecoverOk(String consumerTag) { - // - } - - @Override - @Transactional(readOnly = true) - public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) - throws IOException { - log.trace("handle delivery of tuple, consumerTag={}, envelope={}, properties={}, body=(bytes)", - consumerTag, envelope, properties); - final TypeReference<HashMap<String, Object>> payloadReference = new TypeReference<>() { - }; - final TableCsvDto data = TableCsvDto.builder() - .data(objectMapper.readValue(body, payloadReference)) - .build(); - log.trace("received tuple data {}", data); - try { - queryService.insert(databaseId, tableId, data, new BasicUserPrincipal(properties.getUserId())); - } catch (HttpClientErrorException.Unauthorized e) { - log.error("Failed to authenticate for table with id {}, reason: {}", tableId, e.getMessage()); - throw new IOException("Failed to authenticate for table", e); - } catch (HttpClientErrorException.BadRequest e) { - log.error("Failed to insert for table with id {}, reason: {}", tableId, e.getMessage()); - throw new IOException("Failed to insert for table", e); - } catch (TableNotFoundException e) { - log.error("Failed to find table with id {}, reason: {}", tableId, e.getMessage()); - throw new IOException("Failed to find table", e); - } catch (TableMalformedException e) { - log.error("Tuple columns do not match table columns with table id {}, reason: {}", tableId, e.getMessage()); - throw new IOException("Tuple columns do not match table columns", e); - } catch (DatabaseNotFoundException e) { - log.error("Failed to find database with id {}, reason: {}", databaseId, e.getMessage()); - throw new IOException("Failed to find database", e); - } catch (ImageNotSupportedException e) { - log.error("Image is not supported"); - throw new IOException("Image is not supported", e); - } catch (DatabaseConnectionException e) { - log.error("Failed to connect to database, reason: {}", e.getMessage()); - throw new IOException("Failed to connect to container", e); - } catch (UserNotFoundException e) { - log.error("Failed to find user with id {}", properties.getUserId()); - throw new IOException("Failed to find user", e); - } - } - -} diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/AccessService.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/AccessService.java index 380bf8330940f3dc8f765389c61712b56763eee2..86df08020442982606ef7f1f2b5fa349f1cabb2e 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/AccessService.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/AccessService.java @@ -15,6 +15,7 @@ public interface AccessService { * * @param databaseId The database id. * @return The list of database access definitions. + * @throws DatabaseNotFoundException The database was not found in the metadata database. */ List<DatabaseAccess> list(Long databaseId) throws DatabaseNotFoundException; @@ -24,7 +25,8 @@ public interface AccessService { * @param databaseId The database id. * @param userId The user id. * @return The database access. - * @throws AccessDeniedException The access does not exist. + * @throws AccessDeniedException The access does not exist. + * @throws DatabaseNotFoundException The database was not found in the metadata database. */ DatabaseAccess find(Long databaseId, UUID userId) throws AccessDeniedException, DatabaseNotFoundException; @@ -56,8 +58,7 @@ public interface AccessService { * @throws DatabaseMalformedException The database has an invalid state. */ void update(Long databaseId, UUID userId, DatabaseModifyAccessDto accessDto) throws DatabaseNotFoundException, - UserNotFoundException, QueryMalformedException, DatabaseMalformedException, - NotAllowedException; + UserNotFoundException, QueryMalformedException, DatabaseMalformedException, NotAllowedException; /** * Revokes access to a database of container. @@ -69,6 +70,7 @@ public interface AccessService { * @throws NotAllowedException The access is not allowed. * @throws QueryMalformedException The mapped access query is malformed. * @throws DatabaseMalformedException The database has an invalid state. + * @throws AccessDeniedException The access to the database was denied. */ void delete(Long databaseId, UUID userId) throws DatabaseNotFoundException, UserNotFoundException, NotAllowedException, QueryMalformedException, DatabaseMalformedException, AccessDeniedException; diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/AuthenticationService.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/AuthenticationService.java index a39e0d66c20348a35d5d2fcafbbd7ab1a364fd85..d98869850fde3a2f7921ab6d4db0851572c1d8b7 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/AuthenticationService.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/AuthenticationService.java @@ -43,5 +43,13 @@ public interface AuthenticationService { UserDto findByUsername(String username) throws UserNotFoundException, KeycloakRemoteException, AccessDeniedException; + /** + * Updates the password of a user with given id. + * + * @param id The user id. + * @param data The new password. + * @throws KeycloakRemoteException The Authentication Service was not able to respond within the 3s timeout. + * @throws AccessDeniedException The admin token could not be obtained. + */ void updatePassword(UUID id, UserPasswordDto data) throws KeycloakRemoteException, AccessDeniedException; } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/DatabaseService.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/DatabaseService.java index 430f4b62504bfc0d834eb841e7d91bbfc028ecd6..e013d982743af03509b703609d59298fe94d269b 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/DatabaseService.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/DatabaseService.java @@ -63,20 +63,13 @@ public interface DatabaseService { * * @param createDto The metadata. * @return The database, if successful. - * @throws ImageNotSupportedException The image is not supported. - * @throws ContainerNotFoundException The container was not found in the metadata database. - * @throws DatabaseMalformedException The query string is malformed. - * @throws AmqpException The exchange could not be created. - * @throws ContainerConnectionException The connection to the container could not be established. - * @throws UserNotFoundException The current user could not be loaded in the metadata database. - * @throws DatabaseNameExistsException A database with this name already exists in the container. - * @throws DatabaseConnectionException The connection to the database could not be established by the database connector. - * @throws QueryMalformedException The mapped creation query resulted in an invalid query statement and thus was rejected by the database engine. + * @throws ContainerNotFoundException The container was not found in the metadata database. + * @throws DatabaseMalformedException The query string is malformed. + * @throws UserNotFoundException The current user could not be loaded in the metadata database. + * @throws QueryMalformedException The mapped creation query resulted in an invalid query statement and thus was rejected by the database engine. */ - Database create(DatabaseCreateDto createDto, Principal principal) throws ImageNotSupportedException, - ContainerNotFoundException, DatabaseMalformedException, AmqpException, ContainerConnectionException, - UserNotFoundException, DatabaseNameExistsException, DatabaseConnectionException, QueryMalformedException, - KeycloakRemoteException, AccessDeniedException; + Database create(DatabaseCreateDto createDto, Principal principal) throws ContainerNotFoundException, + DatabaseMalformedException, UserNotFoundException, QueryMalformedException; /** * Updates the user's password. diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/EntityService.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/EntityService.java index d8f4e2f306dfee9568186ae2ea6b1466b68e29e2..947b9660312c6a202adf967890b7c65e9477452b 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/EntityService.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/EntityService.java @@ -9,18 +9,81 @@ import java.util.List; public interface EntityService { + /** + * Finds entities in the ontology whose label match the given label. + * + * @param ontology The ontology. + * @param label The label. + * @return The list of entities that match. + * @throws QueryMalformedException The SPARQL query is malformed. + * @throws OntologyInvalidException The given ontology is invalid. + */ List<EntityDto> findByLabel(Ontology ontology, String label) throws QueryMalformedException, OntologyInvalidException; + /** + * Finds entities in the ontology whose label match the given label with maximum number of entities. + * + * @param ontology The ontology. + * @param label The label. + * @param limit The maximum number of entities to return. + * @return The list of entities that match. + * @throws QueryMalformedException The SPARQL query is malformed. + * @throws OntologyInvalidException The given ontology is invalid. + */ List<EntityDto> findByLabel(Ontology ontology, String label, Integer limit) throws QueryMalformedException, OntologyInvalidException; + /** + * Finds entities in the ontology whose uri match the given uri. + * + * @param ontology The ontology. + * @param uri The uri. + * @return The list of entities that match. + * @throws QueryMalformedException The SPARQL query is malformed. + * @throws OntologyInvalidException The given ontology is invalid. + */ List<EntityDto> findByUri(Ontology ontology, String uri) throws QueryMalformedException, OntologyInvalidException; + /** + * Finds an entity in the ontology whose uri match the given uri. + * + * @param ontology The ontology. + * @param uri The uri. + * @return The entity, if successful. + * @throws QueryMalformedException The SPARQL query is malformed. + * @throws OntologyInvalidException The given ontology is invalid. + * @throws SemanticEntityNotFoundException The entity was not found. + */ EntityDto findOneByUri(Ontology ontology, String uri) throws QueryMalformedException, SemanticEntityNotFoundException, OntologyInvalidException; + /** + * Attempts to suggest table semantics for a table with given id in database with given id. + * + * @param databaseId The database id. + * @param tableId The table id. + * @return The list of entities that were suggested. + * @throws TableNotFoundException The table with id was not found in the metadata database. + * @throws QueryMalformedException The SPARQL query is malformed. + * @throws DatabaseNotFoundException The database with id was not found in the metadata database. + * @throws OntologyInvalidException The given ontology is invalid. + */ List<EntityDto> suggestTableSemantics(Long databaseId, Long tableId) throws TableNotFoundException, QueryMalformedException, DatabaseNotFoundException, OntologyInvalidException; + /** + * Attempts to suggest table column semantics for a table column in table with given id in database with given id. + * + * @param databaseId The database id. + * @param tableId The table id. + * @param columnId The table column id. + * @return The list of entities that were suggested. + * @throws TableNotFoundException The table with id was not found in the metadata database. + * @throws QueryMalformedException The SPARQL query is malformed. + * @throws DatabaseNotFoundException The database with id was not found in the metadata database. + * @throws OntologyInvalidException The given ontology is invalid. + * @throws TableColumnNotFoundException The table column was not found. + */ List<TableColumnEntityDto> suggestTableColumnSemantics(Long databaseId, Long tableId, Long columnId) - throws QueryMalformedException, TableColumnNotFoundException, TableNotFoundException, DatabaseNotFoundException, OntologyInvalidException; + throws QueryMalformedException, TableColumnNotFoundException, TableNotFoundException, + DatabaseNotFoundException, OntologyInvalidException; } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/IdentifierService.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/IdentifierService.java index e4f823c44e7cb86596c9b6aec6117268b6bbb0a8..4a3032281a1de86dcc165450b474c3d89dadd066 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/IdentifierService.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/IdentifierService.java @@ -33,11 +33,18 @@ public interface IdentifierService { * Finds an identifier by given id. * * @param id The identifier id. - * @return The identifier. + * @return The identifier, if successful. * @throws IdentifierNotFoundException The identifier does not exist. */ Identifier find(Long id) throws IdentifierNotFoundException; + /** + * Finds an identifier by given doi. + * + * @param doi The identifier doi. + * @return The identifier, if successful. + * @throws IdentifierNotFoundException The identifier does not exist. + */ Identifier findByDoi(String doi) throws IdentifierNotFoundException; /** @@ -45,12 +52,22 @@ public interface IdentifierService { * * @param databaseId The database id. * @param queryId The query id. - * @return The identifiers, if found. + * @return The list of identifiers. */ List<Identifier> findByDatabaseIdAndQueryId(Long databaseId, Long queryId); + /** + * Finds all identifiers in the metadata database which are identifying databases. + * + * @return The list of identifiers. + */ List<Identifier> findAllDatabaseIdentifiers(); + /** + * Finds all identifiers in the metadata database which are identifying subsets. + * + * @return The list of identifiers. + */ List<Identifier> findAllSubsetIdentifiers(); /** @@ -62,7 +79,7 @@ public interface IdentifierService { * @param queryId Optional. The query id. * @param viewId Optional. The view id. * @param tableId Optional. The table id. - * @return List of identifiers + * @return The list of identifiers. */ List<Identifier> findAll(IdentifierTypeDto type, Long databaseId, Long queryId, Long viewId, Long tableId); @@ -72,19 +89,19 @@ public interface IdentifierService { * @param data The identifier. * @param principal The authorization principal. * @return The created identifier from the metadata database if successful. - * @throws IdentifierPublishingNotAllowedException The identifier with this visibility could not be created. - * @throws QueryNotFoundException The query was not found in the data database. - * @throws RemoteUnavailableException The connection to the Query Store could not be established by - * the database connector. - * @throws IdentifierAlreadyExistsException The identifier for this query/database already exists. - * @throws UserNotFoundException The user was not found in the metadata database. - * @throws DatabaseNotFoundException The database was not found in the metadata database. - * @throws IdentifierNotFoundException The identifier was not found in the metadata database. + * @throws QueryNotFoundException The query was not found in the data database. + * @throws IdentifierRequestException The identifier requested could not be created. + * @throws RemoteUnavailableException The connection to the Query Store could not be established by + * the database connector. + * @throws UserNotFoundException The user was not found in the metadata database. + * @throws DatabaseNotFoundException The database was not found in the metadata database. + * @throws ViewNotFoundException The view with id was not found. + * @throws QueryStoreException The query store failed to retrieve. + * @throws ImageNotSupportedException The image is not supported. */ - Identifier create(IdentifierSaveDto data, Principal principal) throws IdentifierPublishingNotAllowedException, - QueryNotFoundException, RemoteUnavailableException, IdentifierAlreadyExistsException, UserNotFoundException, - DatabaseNotFoundException, IdentifierRequestException, ViewNotFoundException, QueryStoreException, - DatabaseConnectionException, ImageNotSupportedException, IdentifierNotFoundException; + Identifier create(IdentifierSaveDto data, Principal principal) throws QueryNotFoundException, + IdentifierRequestException, RemoteUnavailableException, UserNotFoundException, DatabaseNotFoundException, + ViewNotFoundException, QueryStoreException, ImageNotSupportedException; /** * Export metadata for a identifier @@ -104,7 +121,8 @@ public interface IdentifierService { * @throws IdentifierNotFoundException The identifier was not found in the metadata database or was deleted. * @throws IdentifierRequestException The identifier style was not found. */ - String exportBibliography(Long id, BibliographyTypeDto style) throws IdentifierNotFoundException, IdentifierRequestException; + String exportBibliography(Long id, BibliographyTypeDto style) throws IdentifierNotFoundException, + IdentifierRequestException; /** * Exports an identifier to XML @@ -114,8 +132,16 @@ public interface IdentifierService { * @throws IdentifierNotFoundException The identifier was not found in the metadata database or was deleted. * @throws QueryNotFoundException The query was not found in the metadata database or was deleted. * @throws IdentifierRequestException The identifier does not allow for exporting. + * @throws QueryStoreException The query store failed to retrieve. + * @throws QueryMalformedException The export query is malformed. + * @throws DatabaseNotFoundException The database was not found in the metadata database. + * @throws ImageNotSupportedException The image is not supported. + * @throws FileStorageException The S3 storage failed to produce an export resource. + * @throws DataDbSidecarException The sidecar failed to upload the export to the S3 storage. */ - InputStreamResource exportResource(Long identifierId, Principal principal) throws IdentifierNotFoundException, QueryNotFoundException, FileStorageException, IdentifierRequestException, UserNotFoundException, QueryStoreException, TableMalformedException, DatabaseConnectionException, QueryMalformedException, DatabaseNotFoundException, ImageNotSupportedException, DataDbSidecarException; + InputStreamResource exportResource(Long identifierId, Principal principal) throws IdentifierNotFoundException, + QueryNotFoundException, IdentifierRequestException, QueryStoreException, QueryMalformedException, + DatabaseNotFoundException, ImageNotSupportedException, FileStorageException, DataDbSidecarException; /** * Soft-deletes an identifier for a given id in the metadata database. Does not actually remove the entity from the @@ -123,6 +149,7 @@ public interface IdentifierService { * * @param identifierId The identifier id. * @throws IdentifierNotFoundException The identifier was not found in the metadata database or was deleted. + * @throws DatabaseNotFoundException The database was not found in the metadata database. */ void delete(Long identifierId) throws IdentifierNotFoundException, DatabaseNotFoundException; } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/MessageQueueService.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/MessageQueueService.java index 61d731316d90adc951289eee8e218bb325efc013..b58294feb204b3ae839c9ee563593040f7e7c575 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/MessageQueueService.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/MessageQueueService.java @@ -12,7 +12,7 @@ public interface MessageQueueService { * * @param username The username. * @param password The password. - * @throws BrokerRemoteException The user could not be created. + * @throws BrokerRemoteException The broker service did not answer. * @throws BrokerVirtualHostModificationException The Broker Service did not respond within the 3s timeout. */ void createUser(String username, String password) throws BrokerRemoteException, BrokerVirtualHostModificationException; @@ -21,7 +21,7 @@ public interface MessageQueueService { * Delete a user on the broker service with given username. * * @param username The username. - * @throws BrokerRemoteException The user could not be deleted. + * @throws BrokerRemoteException The broker service did not answer. * @throws BrokerVirtualHostModificationException The Broker Service did not respond within the 3s timeout. */ void deleteUser(String username) throws BrokerRemoteException, BrokerVirtualHostModificationException; @@ -31,13 +31,37 @@ public interface MessageQueueService { * * @param username The username. * @throws BrokerVirtualHostGrantException The Broker Service refused to grant the permissions. + * @throws BrokerRemoteException The broker service did not answer. */ void setVirtualHostPermissions(String username) throws BrokerVirtualHostGrantException, BrokerRemoteException; + /** + * Sets topic exchange permissions for a user. + * + * @param user The user. + * @throws BrokerVirtualHostGrantException The Broker Service refused to grant the permissions. + * @throws BrokerRemoteException The broker service did not answer. + */ void setTopicExchangePermissions(User user) throws BrokerVirtualHostGrantException, BrokerRemoteException; + /** + * Finds a queue with a given name. + * + * @param name The queue name. + * @return The queue. + * @throws QueueNotFoundException The queue could not be found in the broker service. + * @throws BrokerRemoteException The broker service did not answer. + */ QueueDto findQueue(String name) throws QueueNotFoundException, BrokerRemoteException; + /** + * Finds an exchange with given name. + * + * @param name The name. + * @return The exchange. + * @throws ExchangeNotFoundException The exchange could not be found in the broker service. + * @throws BrokerRemoteException The broker service did not answer. + */ ExchangeDto findExchange(String name) throws ExchangeNotFoundException, BrokerRemoteException; } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/MetadataService.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/MetadataService.java index 79d618730cb57699d5dc2a31c5bf41787f606177..b7b2d1de20ed6a8b76ee79d3238728152e242b52 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/MetadataService.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/MetadataService.java @@ -55,6 +55,8 @@ public interface MetadataService { * @throws OrcidNotFoundException The provided identifier is of ORCID type and does not exist. * @throws RorNotFoundException The provided identifier is of ROR type and does not exist. * @throws RemoteUnavailableException The remote service is not supported. + * @throws DoiNotFoundException The doi was not found. */ - ExternalMetadataDto findByUrl(String url) throws OrcidNotFoundException, RorNotFoundException, RemoteUnavailableException, DoiNotFoundException; + ExternalMetadataDto findByUrl(String url) throws OrcidNotFoundException, RorNotFoundException, + RemoteUnavailableException, DoiNotFoundException; } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/OntologyService.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/OntologyService.java index 0f91626406f47dc290a7bc4ef5e3d3603c369ce8..6d94249c285fc9eb383343ecc2240e03c5415cc3 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/OntologyService.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/OntologyService.java @@ -12,15 +12,54 @@ import java.security.Principal; import java.util.List; public interface OntologyService { + + /** + * Finds all ontologies in the metadata database. + * + * @return The list of ontologies. + */ List<Ontology> findAll(); + /** + * Finds all processable ontologies. + * + * @return The list of ontologies. + */ List<Ontology> findAllProcessable(); + /** + * Finds an ontology in the metadata database with given id. + * + * @param id The ontology id. + * @return The ontology, if successful. + * @throws OntologyNotFoundException The ontology was not found in the metadata database. + */ Ontology find(Long id) throws OntologyNotFoundException; - Ontology create(OntologyCreateDto data, Principal principal) throws UserNotFoundException, KeycloakRemoteException, AccessDeniedException; + /** + * Registers an ontology in the metadata database. + * + * @param data The ontology data. + * @param principal The user principal. + * @return The created ontology, if successful. + */ + Ontology create(OntologyCreateDto data, Principal principal); + /** + * Updates an ontology in the metadata database with given id. + * + * @param id The ontology id. + * @param data The ontology data. + * @return The updated ontology, if successful. + * @throws OntologyNotFoundException The ontology was not found in the metadata database. + */ Ontology update(Long id, OntologyModifyDto data) throws OntologyNotFoundException; + /** + * Unregisters an ontology in the metadata database with given id. + * + * @param id The ontology id. + * @throws OntologyNotFoundException The ontology was not found in the metadata database. + */ void delete(Long id) throws OntologyNotFoundException; } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/QueryService.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/QueryService.java index 4ed19c2742196248f9c8f530cdcacebb3316cb3f..738eddb4a6d110341d364ec3da8c93f896d0aff3 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/QueryService.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/QueryService.java @@ -31,16 +31,18 @@ public interface QueryService { * @param sortColumn The sorting column. * @return The result. * @throws QueryStoreException The query store is not reachable. - * @throws QueryMalformedException The query is malformed. - * @throws DatabaseNotFoundException The database was not found in the metdata database. + * @throws DatabaseNotFoundException The database was not found in the metadata database. * @throws ImageNotSupportedException The image is not supported. * @throws QueryMalformedException The query is malformed. + * @throws ColumnParseException The column could not be parsed. + * @throws UserNotFoundException The user could not be found. + * @throws TableMalformedException The table is malformed. + * @throws QueryNotFoundException The query was not found in the query store. */ QueryResultDto execute(Long databaseId, ExecuteStatementDto statement, Principal principal, Long page, Long size, SortType sortDirection, String sortColumn) throws DatabaseNotFoundException, ImageNotSupportedException, QueryMalformedException, QueryStoreException, ColumnParseException, - UserNotFoundException, TableMalformedException, DatabaseConnectionException, KeycloakRemoteException, - AccessDeniedException, QueryNotFoundException; + UserNotFoundException, TableMalformedException, QueryNotFoundException; /** * Re-Executes an arbitrary query on the database. We allow the user to only view the data, therefore the @@ -54,7 +56,6 @@ public interface QueryService { * @param sortColumn The sorting column. * @param principal The user principal. * @return The result. - * @throws QueryStoreException The query store is not reachable. * @throws QueryMalformedException The query is malformed. * @throws DatabaseNotFoundException The database was not found in the metdata database. * @throws ImageNotSupportedException The image is not supported. @@ -64,8 +65,7 @@ public interface QueryService { */ QueryResultDto reExecute(Long databaseId, Query query, Long page, Long size, SortType sortDirection, String sortColumn, Principal principal) throws QueryMalformedException, - DatabaseNotFoundException, ImageNotSupportedException, ColumnParseException, DatabaseConnectionException, - TableMalformedException, QueryStoreException, UserNotFoundException; + DatabaseNotFoundException, ImageNotSupportedException, ColumnParseException, TableMalformedException; /** * Re-Executes the count-statement of an arbitrary query on the database. We allow the user to only view @@ -105,8 +105,7 @@ public interface QueryService { */ QueryResultDto tableFindAll(Long databaseId, Long tableId, Instant timestamp, Long page, Long size, Principal principal) throws TableNotFoundException, DatabaseNotFoundException, - ImageNotSupportedException, DatabaseConnectionException, TableMalformedException, PaginationException, - QueryMalformedException, UserNotFoundException; + TableMalformedException, QueryMalformedException, ImageNotSupportedException; /** * Select all data known in the database-table id tuple at a given time and return a downloadable input stream @@ -118,18 +117,15 @@ public interface QueryService { * @param timestamp The given time. * @param principal The user principal. * @return The select all data result in the form of a downloadable .csv file. - * @throws TableNotFoundException The table was not found in the metadata database. - * @throws TableMalformedException The table columns are messed up what we got from the metadata database. - * @throws DatabaseNotFoundException The database was not found in the remote database. - * @throws ImageNotSupportedException The image is not supported. - * @throws DatabaseConnectionException The connection to the remote database was unsuccessful. - * @throws FileStorageException The file could not be exported. - * @throws QueryMalformedException The query is malformed. + * @throws TableNotFoundException The table was not found in the metadata database. + * @throws DatabaseNotFoundException The database was not found in the remote database. + * @throws FileStorageException The file could not be exported. + * @throws QueryMalformedException The query is malformed. + * @throws DataDbSidecarException The data database sidecar failed to produce the export resource. */ ExportResource tableFindAll(Long databaseId, Long tableId, Instant timestamp, Principal principal) - throws TableNotFoundException, DatabaseNotFoundException, ImageNotSupportedException, - DatabaseConnectionException, TableMalformedException, PaginationException, - FileStorageException, QueryMalformedException, UserNotFoundException, DataDbSidecarException; + throws TableNotFoundException, DatabaseNotFoundException, FileStorageException, QueryMalformedException, + DataDbSidecarException; /** * Select all data known in the view id tuple and return a page of specific size. @@ -141,16 +137,12 @@ public interface QueryService { * @param size The page size. * @param principal The user principal. * @return The select all data result - * @throws ViewNotFoundException The view was not found in the metadata database. - * @throws DatabaseNotFoundException The database was not found in the metdata database. - * @throws ImageNotSupportedException The image is not supported. - * @throws ViewMalformedException The table is malformed. - * @throws QueryMalformedException The query is malformed. + * @throws DatabaseNotFoundException The database was not found in the metadata database. + * @throws QueryMalformedException The query is malformed. + * @throws TableMalformedException The table is malformed. */ QueryResultDto viewFindAll(Long databaseId, View view, Long page, Long size, Principal principal) - throws ViewNotFoundException, DatabaseNotFoundException, ImageNotSupportedException, - DatabaseConnectionException, ViewMalformedException, PaginationException, QueryMalformedException, - UserNotFoundException, TableMalformedException; + throws DatabaseNotFoundException, QueryMalformedException, TableMalformedException; /** * Finds one query by database id and query id. @@ -161,16 +153,15 @@ public interface QueryService { * @return The query result in the form of a downloadable .csv file. * @throws DatabaseNotFoundException The database was not found in the remote database. * @throws ImageNotSupportedException The image is not supported. - * @throws TableMalformedException The table columns are messed up what we got from the metadata database. * @throws FileStorageException The file could not be exported. * @throws QueryStoreException The query store is not reachable. * @throws QueryNotFoundException THe query was not found in the query store. * @throws QueryMalformedException The query is malformed. + * @throws DataDbSidecarException The data database sidecar failed to produce the export resource. */ ExportResource findOne(Long databaseId, Long queryId, Principal principal) throws DatabaseNotFoundException, - ImageNotSupportedException, TableMalformedException, FileStorageException, QueryStoreException, - QueryNotFoundException, QueryMalformedException, DatabaseConnectionException, UserNotFoundException, - DataDbSidecarException; + ImageNotSupportedException, FileStorageException, QueryStoreException, QueryNotFoundException, + QueryMalformedException, DataDbSidecarException; /** * Count the total tuples for a given table id within a database id at a given time. @@ -184,11 +175,12 @@ public interface QueryService { * @throws TableNotFoundException The table was not found in the metadata database. * @throws TableMalformedException The table columns are messed up what we got from the metadata database. * @throws ImageNotSupportedException The image is not supported. + * @throws QueryMalformedException The query is malformed. + * @throws QueryStoreException The query store could not retrieve. */ Long tableCount(Long databaseId, Long tableId, Instant timestamp, Principal principal) - throws DatabaseNotFoundException, TableNotFoundException, TableMalformedException, - ImageNotSupportedException, DatabaseConnectionException, QueryMalformedException, QueryStoreException, - UserNotFoundException; + throws DatabaseNotFoundException, TableNotFoundException, ImageNotSupportedException, + QueryMalformedException, QueryStoreException, TableMalformedException; /** * Count the total tuples for a given table id within a database id at a given time. @@ -202,8 +194,7 @@ public interface QueryService { * @throws ImageNotSupportedException The image is not supported. */ Long viewCount(Long databaseId, View view, Principal principal) throws DatabaseNotFoundException, - TableMalformedException, ImageNotSupportedException, DatabaseConnectionException, QueryMalformedException, - QueryStoreException, UserNotFoundException; + ImageNotSupportedException, QueryMalformedException, QueryStoreException, TableMalformedException; /** * Insert data from AMQP client into a table of a table-database id tuple, we need the "root" role for this as the @@ -213,14 +204,12 @@ public interface QueryService { * @param tableId The table id. * @param data The data. * @param principal The user principal. - * @throws ImageNotSupportedException The image is not supported. - * @throws TableMalformedException The table does not exist in the metadata database. - * @throws DatabaseNotFoundException The database is not found in the metadata database. - * @throws TableNotFoundException The table is not found in the metadata database. + * @throws TableMalformedException The table does not exist in the metadata database. + * @throws DatabaseNotFoundException The database is not found in the metadata database. + * @throws TableNotFoundException The table is not found in the metadata database. */ - void insert(Long databaseId, Long tableId, TableCsvDto data, Principal principal) throws ImageNotSupportedException, - TableMalformedException, DatabaseNotFoundException, TableNotFoundException, DatabaseConnectionException, - UserNotFoundException; + void insert(Long databaseId, Long tableId, TableCsvDto data, Principal principal) throws TableMalformedException, + DatabaseNotFoundException, TableNotFoundException; /** * Deletes a tuple by given constraint set @@ -237,7 +226,7 @@ public interface QueryService { */ void delete(Long databaseId, Long tableId, TableCsvDeleteDto data, Principal principal) throws ImageNotSupportedException, TableMalformedException, DatabaseNotFoundException, - TableNotFoundException, DatabaseConnectionException, QueryMalformedException, UserNotFoundException; + TableNotFoundException, QueryMalformedException; /** * Insert data from a csv into a table of a table-database id tuple, we need the "root" role for this as the @@ -247,13 +236,11 @@ public interface QueryService { * @param tableId The table id. * @param data The data path. * @param principal The user principal. - * @throws ImageNotSupportedException The image is not supported. - * @throws TableMalformedException The table does not exist in the metadata database. - * @throws DatabaseNotFoundException The database is not found in the metadata database. - * @throws TableNotFoundException The table is not found in the metadata database. - * @throws QueryMalformedException The query is malformed. + * @throws TableMalformedException The table does not exist in the metadata database. + * @throws DatabaseNotFoundException The database is not found in the metadata database. + * @throws TableNotFoundException The table is not found in the metadata database. + * @throws DataDbSidecarException The data database sidecar failed to import the dataset. */ - void insert(Long databaseId, Long tableId, ImportDto data, Principal principal) throws ImageNotSupportedException, - TableMalformedException, DatabaseNotFoundException, TableNotFoundException, DatabaseConnectionException, - QueryMalformedException, UserNotFoundException, DataDbSidecarException; + void insert(Long databaseId, Long tableId, ImportDto data, Principal principal) throws TableMalformedException, + DatabaseNotFoundException, TableNotFoundException, DataDbSidecarException; } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/QueryStoreService.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/QueryStoreService.java index 680f8322db35e2663c164d3306ede6d33ed6c1a0..7fe8d91b6af4037ecb54f5a80cb459eceabe3df9 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/QueryStoreService.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/QueryStoreService.java @@ -9,13 +9,13 @@ public interface QueryStoreService { /** * Creates the query store in the database. * - * @param databaseId The database id. - * @param principal The principal of the user. - * @throws DatabaseNotFoundException - * @throws DatabaseConnectionException - * @throws DatabaseMalformedException - * @throws UserNotFoundException - * @throws QueryStoreException + * @param databaseId The database id. + * @param principal The principal of the user. + * @throws DatabaseNotFoundException The database is not found in the metadata database. + * @throws DatabaseMalformedException The database is malformed. + * @throws UserNotFoundException The user was not found in the metadata database. + * @throws QueryStoreException The query store failed to retrieve. */ - void create(Long databaseId, Principal principal) throws DatabaseNotFoundException, DatabaseConnectionException, DatabaseMalformedException, UserNotFoundException, QueryStoreException; + void create(Long databaseId, Principal principal) throws DatabaseNotFoundException, DatabaseMalformedException, + UserNotFoundException, QueryStoreException; } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/SemanticService.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/SemanticService.java index bfa1928ec02048594e36c4f6a9ed1e2ba5483efa..8a0c44dc081e2cbebe54e187ec8bfb8c862fe1a1 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/SemanticService.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/SemanticService.java @@ -9,11 +9,35 @@ import java.util.List; public interface SemanticService { + /** + * Finds all table column concepts in the metadata database. + * + * @return The list of table column concepts. + */ List<TableColumnConcept> findAllConcepts(); + /** + * Finds all table column units in the metadata database. + * + * @return The list of table column units. + */ List<TableColumnUnit> findAllUnits(); + /** + * Finds a table column unit by given uri in the metadata database. + * + * @param uri The uri. + * @return The table column unit, if successful. + * @throws UnitNotFoundException The unit was not found. + */ TableColumnUnit findUnit(String uri) throws UnitNotFoundException; + /** + * Finds a table column concept by given uri in the metadata database. + * + * @param uri The uri. + * @return The table column concept, if successful. + * @throws ConceptNotFoundException The concept was not found. + */ TableColumnConcept findConcept(String uri) throws ConceptNotFoundException; } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/StoreService.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/StoreService.java index 5d3c007802c67fdafac7abe9f0111236cf82766d..ab48966bd002915ad2e619c5849a8a7c54445d2b 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/StoreService.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/StoreService.java @@ -24,8 +24,7 @@ public interface StoreService { * @throws QueryStoreException The query store produced an invalid result */ List<Query> findAll(Long databaseId, Boolean persisted, Principal principal) throws DatabaseNotFoundException, - ImageNotSupportedException, QueryStoreException, ContainerNotFoundException, DatabaseConnectionException, - TableMalformedException, UserNotFoundException; + ImageNotSupportedException, QueryStoreException; /** * Finds a query in the query store of the given database id and query id. @@ -40,7 +39,7 @@ public interface StoreService { * @throws QueryNotFoundException The query store did not return a query */ Query findOne(Long databaseId, Long queryId, Principal principal) throws DatabaseNotFoundException, - ImageNotSupportedException, DatabaseConnectionException, QueryNotFoundException, QueryStoreException, UserNotFoundException; + ImageNotSupportedException, QueryNotFoundException, QueryStoreException; /** * Inserts a query and metadata to the query store of a given database id. @@ -49,14 +48,15 @@ public interface StoreService { * @param metadata The statement. * @param principal The user principal. * @return The stored query on success - * @throws QueryStoreException The query store raised some error - * @throws DatabaseNotFoundException The database id was not found in the metadata database - * @throws ImageNotSupportedException The image is not supported - * @throws UserNotFoundException The user was not found in the metadata database. - * @throws DatabaseConnectionException The database connection to the remote container failed. + * @throws QueryStoreException The query store raised some error + * @throws DatabaseNotFoundException The database id was not found in the metadata database + * @throws ImageNotSupportedException The image is not supported + * @throws UserNotFoundException The user was not found in the metadata database. + * @throws QueryNotFoundException The query was not found in the query store. */ Query insert(Long databaseId, ExecuteStatementDto metadata, Principal principal) throws QueryStoreException, - DatabaseNotFoundException, ImageNotSupportedException, UserNotFoundException, DatabaseConnectionException, KeycloakRemoteException, AccessDeniedException, QueryNotFoundException; + DatabaseNotFoundException, ImageNotSupportedException, UserNotFoundException, + QueryNotFoundException; /** * Persists a query to be displayed in the frontend. @@ -65,16 +65,16 @@ public interface StoreService { * @param queryId The query id. * @param data The desired persist state. * @return The stored query on success. - * @throws DatabaseNotFoundException The database id was not found in the metadata database - * @throws ImageNotSupportedException The image is not supported. - * @throws DatabaseConnectionException The database connection to the remote container failed. - * @throws QueryStoreException The query store raised some error. + * @throws DatabaseNotFoundException The database id was not found in the metadata database + * @throws ImageNotSupportedException The image is not supported. + * @throws QueryStoreException The query store raised some error. + * @throws IdentifierAlreadyPublishedException The query is already persisted. */ Query persist(Long databaseId, Long queryId, QueryPersistDto data) throws DatabaseNotFoundException, - ImageNotSupportedException, DatabaseConnectionException, QueryStoreException, UserNotFoundException, IdentifierAlreadyPublishedException; + ImageNotSupportedException, QueryStoreException, IdentifierAlreadyPublishedException; /** - * Deletes the stale queries that have not been persisted within 24 hozrs. + * Deletes the stale queries that have not been persisted within 24 hours. * * @throws ImageNotSupportedException The image is not supported. * @throws QueryStoreException The query store raised some error. diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/TableService.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/TableService.java index 9c09b94cc1e5a7883790bdad936c0b99e0d71e6e..e1e57273a72923e0455635dd4cb53b525dcff08e 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/TableService.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/TableService.java @@ -14,17 +14,25 @@ import java.util.List; public interface TableService { /** - * Find a table in the metadata database by database-table id tuple + * Find a table in the metadata database by database and table id. * * @param databaseId The database id. * @param tableId The table id. - * @return The database. - * @throws DatabaseNotFoundException The database is not found. - * @throws TableNotFoundException The table is not found. + * @return The table, if successful. + * @throws DatabaseNotFoundException The database was not found in the metadata database. + * @throws TableNotFoundException The table was not found in the metadata database. */ Table find(Long databaseId, Long tableId) throws DatabaseNotFoundException, TableNotFoundException; - @Transactional(readOnly = true) + /** + * Find a table in the metadata database by database id and table name. + * + * @param databaseId The database id. + * @param internalName The table name. + * @return The table, if successful. + * @throws DatabaseNotFoundException The database was not found in the metadata database. + * @throws TableNotFoundException The table was not found in the metadata database. + */ Table find(Long databaseId, String internalName) throws DatabaseNotFoundException, TableNotFoundException; /** @@ -44,16 +52,17 @@ public interface TableService { * @throws QueryMalformedException The query is malformed. * @throws DatabaseNotFoundException The database is not found. * @throws TableNotFoundException The table is not found. + * @throws QueryStoreException The query store failed. */ List<TableHistoryDto> findHistory(Long databaseId, Long tableId, Principal principal) - throws DatabaseNotFoundException, QueryMalformedException, TableNotFoundException, - DatabaseConnectionException, QueryStoreException, UserNotFoundException; + throws DatabaseNotFoundException, TableNotFoundException, QueryStoreException, QueryMalformedException; /** * Select all tables from the metadata database. * * @param databaseId The database id. * @return The list of tables. + * @throws DatabaseNotFoundException The database was not found in the metadata database. */ List<Table> findAll(Long databaseId) throws DatabaseNotFoundException; @@ -68,14 +77,12 @@ public interface TableService { * @throws ImageNotSupportedException The image is not supported. * @throws DatabaseNotFoundException The database was not found in the metadata database. * @throws TableNameExistsException The table name exists already in this database. - * @throws ContainerNotFoundException The container was not found. * @throws TableMalformedException The table seems malformed by the mapper. * @throws QueryMalformedException The query to create the table is malformed. */ Table createTable(Long databaseId, TableCreateDto createDto, Principal principal) throws ImageNotSupportedException, DatabaseNotFoundException, TableMalformedException, - TableNameExistsException, ContainerNotFoundException, UserNotFoundException, QueryMalformedException, - TableNotFoundException; + TableNameExistsException, QueryMalformedException, TableNotFoundException; /** @@ -86,16 +93,14 @@ public interface TableService { * @param columnId The column id. * @param updateDto The update data containing unit and concept uris. * @return The updated table column, if successful. - * @throws TableNotFoundException The table was not found in the metadata database. - * @throws DatabaseNotFoundException The database was not found in the metadata database. - * @throws ContainerNotFoundException The container was not found. - * @throws TableMalformedException The table seems malformed by the mapper. - * @throws QueryMalformedException The query to update the table is malformed. + * @throws TableNotFoundException The table was not found in the metadata database. + * @throws DatabaseNotFoundException The database was not found in the metadata database. + * @throws TableMalformedException The table seems malformed by the mapper. + * @throws TableNotFoundException The table is not found. */ TableColumn update(Long databaseId, Long tableId, Long columnId, ColumnSemanticsUpdateDto updateDto, String authorization) throws TableNotFoundException, DatabaseNotFoundException, - ContainerNotFoundException, TableMalformedException, SemanticEntityPersistException, - SemanticEntityNotFoundException, QueryMalformedException; + TableMalformedException; /** * Deletes a table from the database in the metadata database and data database. diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/UserService.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/UserService.java index a5edcc519c9643afc2915217eaebd14df20550ac..9dd6554774c5503c64a1f473d9a7102c9f5ac19c 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/UserService.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/UserService.java @@ -11,14 +11,14 @@ import java.util.UUID; public interface UserService { /** - * Finds all users in the metadata database + * Finds all users in the metadata database. * * @return The list of users. */ List<User> findAll(); /** - * Finds a user by username. + * Finds a user by username in the metadata database. * * @param username The username. * @return The user, if successfully. @@ -30,7 +30,7 @@ public interface UserService { * Finds a specific user in the metadata database by given id. * * @param id The user id. - * @return The user if successful. False otherwise. + * @return The user, if successful. * @throws UserNotFoundException The user was not found. */ User find(UUID id) throws UserNotFoundException; @@ -39,11 +39,10 @@ public interface UserService { * Creates a user in the metadata database managed by Keycloak in the given realm. * * @param data The user data. - * @return The user, if successful. False otherwise. - * @throws UserAlreadyExistsException The user already exists in the metadata database. + * @param id The user id. + * @return The user, if successful. */ - User create(SignupRequestDto data, UUID id) throws UserAlreadyExistsException, AccessDeniedException, - KeycloakRemoteException, UserNotFoundException, UserEmailAlreadyExistsException; + User create(SignupRequestDto data, UUID id); /** * Updates the user information for a user with given id in the metadata database. @@ -51,12 +50,12 @@ public interface UserService { * @param id The user id. * @param data The user information. * @return The user if successful. False otherwise. - * @throws UserNotFoundException The user was not found. + * @throws UserNotFoundException The user was not found. */ User modify(UUID id, UserUpdateDto data) throws UserNotFoundException; /** - * Updates the user password for a user with given id. + * Updates the user password for a user with given id in the metadata database. * * @param id The user id. * @param data The new password. @@ -64,12 +63,12 @@ public interface UserService { void updatePassword(UUID id, UserPasswordDto data) throws UserNotFoundException; /** - * Updates the user theme for a user with given id. + * Updates the user theme for a user with given id in the metadata database. * * @param id The user id. * @param data The user theme. * @return The user if successful. False otherwise. - * @throws UserNotFoundException The user was not found. + * @throws UserNotFoundException The user was not found. */ User toggleTheme(UUID id, UserThemeSetDto data) throws UserNotFoundException; diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/ViewService.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/ViewService.java index 208f55fe45dc9acf7c09831bc00bed2725bfad0b..48803195a6589bd956a95df2287901e9527ceab0 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/ViewService.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/ViewService.java @@ -17,7 +17,8 @@ public interface ViewService { * @param databaseId The database id. * @param principal The user. * @return A list of views. - * @throws UserNotFoundException The user with authorization principal was not found. + * @throws UserNotFoundException The user with authorization principal was not found. + * @throws DatabaseNotFoundException The database was not found in the metadata database. */ List<View> findAll(Long databaseId, Principal principal) throws UserNotFoundException, DatabaseNotFoundException; @@ -28,8 +29,9 @@ public interface ViewService { * @param id The view id. * @param principal The user. * @return The view, if successful. - * @throws ViewNotFoundException The view was not found in the metadata database. - * @throws UserNotFoundException The user with authorization principal was not found. + * @throws ViewNotFoundException The view was not found in the metadata database. + * @throws UserNotFoundException The user with authorization principal was not found. + * @throws DatabaseNotFoundException The database was not found in the metadata database. */ View findById(Long databaseId, Long id, Principal principal) throws ViewNotFoundException, UserNotFoundException, DatabaseNotFoundException; @@ -37,9 +39,9 @@ public interface ViewService { /** * Delete view in the container with the given id and database with id and the given view id. * - * @param databaseId The database id. - * @param id The view id. - * @param principal The authorization principal. + * @param databaseId The database id. + * @param id The view id. + * @param principal The authorization principal. * @throws ViewNotFoundException The view was not found in the metadata database. * @throws UserNotFoundException The user with authorization principal was not found. * @throws DatabaseNotFoundException The database was not found. @@ -48,14 +50,15 @@ public interface ViewService { * @throws ViewMalformedException The view is malformed and could not be deleted. */ void delete(Long databaseId, Long id, Principal principal) throws ViewNotFoundException, - UserNotFoundException, DatabaseNotFoundException, DatabaseConnectionException, QueryMalformedException, ViewMalformedException; + UserNotFoundException, DatabaseNotFoundException, DatabaseConnectionException, QueryMalformedException, + ViewMalformedException; /** * Creates a view in the container with given id and database with id with the given query. * - * @param databaseId The database id. - * @param data The given query. - * @param principal The authorization principal. + * @param databaseId The database id. + * @param data The given query. + * @param principal The authorization principal. * @return The view that was created. * @throws DatabaseNotFoundException The database was not found. * @throws DatabaseConnectionException The connection to the database could not be established. diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/AccessServiceImpl.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/AccessServiceImpl.java index 60dbcc40f98f496b1b4aef267d83e02712691f45..77c8420eefcecf04c3b5b569e17809573f978364 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/AccessServiceImpl.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/AccessServiceImpl.java @@ -149,8 +149,8 @@ public class AccessServiceImpl extends HibernateConnector implements AccessServi final PreparedStatement preparedStatement4 = databaseMapper.rawFlushPrivileges(connection); preparedStatement4.executeUpdate(); } catch (SQLException e) { - log.error("Failed to modify database access {}, reason {}", accessDto, e.getMessage()); - throw new DatabaseMalformedException("Failed to execute query", e); + log.error("Failed to modify database access: {}", e.getMessage()); + throw new DatabaseMalformedException("Failed to modify database access: " + e.getMessage(), e); } finally { dataSource.close(); } @@ -176,8 +176,8 @@ public class AccessServiceImpl extends HibernateConnector implements AccessServi @Override @Transactional - public void delete(Long databaseId, UUID userId) throws DatabaseNotFoundException, UserNotFoundException, - NotAllowedException, QueryMalformedException, DatabaseMalformedException, AccessDeniedException { + public void delete(Long databaseId, UUID userId) throws DatabaseNotFoundException, NotAllowedException, + QueryMalformedException, DatabaseMalformedException, AccessDeniedException { /* check */ final Database database = databaseService.findById(databaseId); final Container container = database.getContainer(); @@ -195,8 +195,8 @@ public class AccessServiceImpl extends HibernateConnector implements AccessServi final PreparedStatement preparedStatement2 = databaseMapper.userToRawDropUserQuery(connection, access.getUser().getUsername()); preparedStatement2.executeUpdate(); } catch (SQLException e) { - log.error("Failed to revoke database access, reason {}", e.getMessage()); - throw new DatabaseMalformedException("Failed to execute query", e); + log.error("Failed to revoke database access: {}", e.getMessage()); + throw new DatabaseMalformedException("Failed to execute query: " + e.getMessage(), e); } finally { dataSource.close(); } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/ContainerServiceImpl.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/ContainerServiceImpl.java index 29db821a09850b4078ea48f785efcf9a7cb558b0..5f2a5f0a5dc0b8d70c6d9e5e4c7801224bbf09c6 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/ContainerServiceImpl.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/ContainerServiceImpl.java @@ -45,13 +45,13 @@ public class ContainerServiceImpl implements ContainerService { final Optional<Container> optional = containerRepository.findByInternalName( containerMapper.containerToInternalContainerName(data.getName())); if (optional.isPresent()) { - log.error("Failed to create container with name {}: already exists in metadata database", data.getName()); - throw new ContainerAlreadyExistsException("Failed to create container with name " + data.getName() + ": already exists in metadata database"); + log.error("Failed to create container with name {}: already exists", data.getName()); + throw new ContainerAlreadyExistsException("Failed to create container with name " + data.getName() + ": already exists"); } final Optional<ContainerImage> optional2 = imageRepository.findById(data.getImageId()); if (optional2.isEmpty()) { - log.error("Failed to find image with id {} in metadata database", data.getImageId()); - throw new ImageNotFoundException("Failed to find image with id " + data.getImageId() + " in metadata database"); + log.error("Failed to find image with id {}", data.getImageId()); + throw new ImageNotFoundException("Failed to find image with id " + data.getImageId()); } /* entity */ final Container container = Container.builder() diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/DataCiteIdentifierServiceImpl.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/DataCiteIdentifierServiceImpl.java index 6a9ed0de7f90e32be4b4948a490df9df1b681aaf..3dfa60dc757343d49bd197c747e9831faa4c0d44 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/DataCiteIdentifierServiceImpl.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/DataCiteIdentifierServiceImpl.java @@ -82,11 +82,9 @@ public class DataCiteIdentifierServiceImpl implements IdentifierService { @Override @Transactional(rollbackFor = {Exception.class}) - public Identifier create(IdentifierSaveDto data, Principal principal) - throws IdentifierPublishingNotAllowedException, QueryNotFoundException, RemoteUnavailableException, - IdentifierAlreadyExistsException, UserNotFoundException, DatabaseNotFoundException, - IdentifierRequestException, ViewNotFoundException, QueryStoreException, DatabaseConnectionException, - ImageNotSupportedException, IdentifierNotFoundException { + public Identifier create(IdentifierSaveDto data, Principal principal) throws QueryNotFoundException, + IdentifierRequestException, RemoteUnavailableException, UserNotFoundException, DatabaseNotFoundException, + ViewNotFoundException, QueryStoreException, ImageNotSupportedException { final Identifier identifier = identifierService.create(data, principal); /* https://stackoverflow.com/questions/55090541/spring-data-jpa-lombok-unsupportedoperationexception-during-saving */ if (identifier.getCreators() != null) { @@ -190,9 +188,8 @@ public class DataCiteIdentifierServiceImpl implements IdentifierService { @Transactional(readOnly = true) public InputStreamResource exportResource(Long identifierId, Principal principal) throws IdentifierNotFoundException, QueryNotFoundException, FileStorageException, - IdentifierRequestException, UserNotFoundException, QueryStoreException, TableMalformedException, - DatabaseConnectionException, QueryMalformedException, DatabaseNotFoundException, ImageNotSupportedException, - DataDbSidecarException { + IdentifierRequestException, QueryStoreException, QueryMalformedException, DatabaseNotFoundException, + ImageNotSupportedException, DataDbSidecarException { return identifierService.exportResource(identifierId, principal); } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/EntityServiceImpl.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/EntityServiceImpl.java index 1c0ca06c39e8cde9f2d4c0a0e066beefb41324b3..7e983019e7f7955cee1c462e40a3b96912e82917 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/EntityServiceImpl.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/EntityServiceImpl.java @@ -126,7 +126,7 @@ public class EntityServiceImpl implements EntityService { return results; } catch (QueryParseException | IllegalArgumentException | RiotException e) { log.error("Failed to parse query: {}", e.getMessage()); - throw new QueryMalformedException("Failed to parse query", e); + throw new QueryMalformedException("Failed to parse query: " + e.getMessage(), e); } } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java index 5e57b6c0f5f4ad2e9c46bb0569a0af1654a73de1..4b2724a9aa55006abe48e3c033d86b68dd7bce91 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java @@ -84,8 +84,8 @@ public class IdentifierServiceImpl implements IdentifierService { public Identifier find(Long identifierId) throws IdentifierNotFoundException { final Optional<Identifier> optional = identifierRepository.findById(identifierId); if (optional.isEmpty()) { - log.error("Identifier with id {} not existing", identifierId); - throw new IdentifierNotFoundException("Unable to find identifier with pid: " + identifierId); + log.error("Failed to find identifier with id: {}", identifierId); + throw new IdentifierNotFoundException("Failed to find identifier with id: " + identifierId); } return optional.get(); } @@ -95,8 +95,8 @@ public class IdentifierServiceImpl implements IdentifierService { public Identifier findByDoi(String doi) throws IdentifierNotFoundException { final Optional<Identifier> optional = identifierRepository.findByDoi(doi); if (optional.isEmpty()) { - log.error("Identifier with doi {} not existing", doi); - throw new IdentifierNotFoundException("Unable to find identifier with doi: " + doi); + log.error("Failed to find identifier with doi {}: not existing", doi); + throw new IdentifierNotFoundException("Failed to find identifier with doi " + doi + ": not existing"); } return optional.get(); } @@ -153,11 +153,9 @@ public class IdentifierServiceImpl implements IdentifierService { @Override @Transactional - public Identifier create(IdentifierSaveDto data, Principal principal) - throws QueryNotFoundException, RemoteUnavailableException, IdentifierAlreadyExistsException, - UserNotFoundException, DatabaseNotFoundException, IdentifierPublishingNotAllowedException, - IdentifierRequestException, ViewNotFoundException, QueryStoreException, DatabaseConnectionException, - ImageNotSupportedException, IdentifierNotFoundException { + public Identifier create(IdentifierSaveDto data, Principal principal) throws QueryNotFoundException, + IdentifierRequestException, RemoteUnavailableException, UserNotFoundException, DatabaseNotFoundException, + ViewNotFoundException, QueryStoreException, ImageNotSupportedException { /* create identifier */ final Identifier entity = identifierMapper.identifierCreateDtoToIdentifier(data); entity.setCreatedBy(UserUtil.getId(principal)); @@ -218,8 +216,8 @@ public class IdentifierServiceImpl implements IdentifierService { @Override @Transactional(readOnly = true) - public String exportBibliography(Long id, BibliographyTypeDto style) - throws IdentifierNotFoundException, IdentifierRequestException { + public String exportBibliography(Long id, BibliographyTypeDto style) throws IdentifierNotFoundException, + IdentifierRequestException { /* check */ final Identifier identifier = find(id); /* context */ @@ -237,7 +235,7 @@ public class IdentifierServiceImpl implements IdentifierService { body = templateEngine.process(template, context); } catch (TemplateInputException e) { log.error("Failed to load template: {}", e.getMessage()); - throw new IdentifierRequestException("Failed to load template", e); + throw new IdentifierRequestException("Failed to load template: " + e.getMessage(), e); } log.trace("mapped bibliography {}", body); return body; @@ -246,8 +244,7 @@ public class IdentifierServiceImpl implements IdentifierService { @Override @Transactional(readOnly = true) public InputStreamResource exportResource(Long identifierId, Principal principal) throws IdentifierNotFoundException, - QueryNotFoundException, IdentifierRequestException, UserNotFoundException, QueryStoreException, - TableMalformedException, DatabaseConnectionException, QueryMalformedException, + QueryNotFoundException, IdentifierRequestException, QueryStoreException, QueryMalformedException, DatabaseNotFoundException, ImageNotSupportedException, FileStorageException, DataDbSidecarException { /* check */ final Identifier identifier = find(identifierId); diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/ImageServiceImpl.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/ImageServiceImpl.java index 28ada413a74d01b6d363ebc8d30353c7e9c2c321..35e3e87b3b387895f9eacee4adab83dc77f81bca 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/ImageServiceImpl.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/ImageServiceImpl.java @@ -45,8 +45,8 @@ public class ImageServiceImpl implements ImageService { public ContainerImage find(Long imageId) throws ImageNotFoundException { final Optional<ContainerImage> image = imageRepository.findById(imageId); if (image.isEmpty()) { - log.error("Failed to find image with id {} in metadata database", imageId); - throw new ImageNotFoundException("Failed to find image with id " + imageId + " in metadata database"); + log.error("Failed to find image with id {}", imageId); + throw new ImageNotFoundException("Failed to find image with id " + imageId); } return image.get(); } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/LicenseServiceImpl.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/LicenseServiceImpl.java index 3f558d93edc76cde93fd9f64ed279fba925d0625..4d387a3b76a66be4a317905032e32c8cc0269d74 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/LicenseServiceImpl.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/LicenseServiceImpl.java @@ -29,8 +29,8 @@ public class LicenseServiceImpl implements LicenseService { public License find(String identifier) throws LicenseNotFoundException { final Optional<License> license = licenseRepository.findByIdentifier(identifier); if (license.isEmpty()) { - log.error("Failed to find license with identifier {} in metadata database", identifier); - throw new LicenseNotFoundException("Failed to find license with identifier " + identifier + " in metadata database"); + log.error("Failed to find license with identifier {}", identifier); + throw new LicenseNotFoundException("Failed to find license with identifier " + identifier); } return license.get(); } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/MariaDbServiceImpl.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/MariaDbServiceImpl.java index edae7bfa0e7f8199da7575aad41e9d7a28de3fcc..07df2b4ca5950d5f3dbbb60c8e68746044b919f6 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/MariaDbServiceImpl.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/MariaDbServiceImpl.java @@ -118,10 +118,8 @@ public class MariaDbServiceImpl extends HibernateConnector implements DatabaseSe @Override @Transactional - public Database create(DatabaseCreateDto createDto, Principal principal) - throws ImageNotSupportedException, ContainerNotFoundException, DatabaseMalformedException, AmqpException, - ContainerConnectionException, UserNotFoundException, DatabaseNameExistsException, - DatabaseConnectionException, QueryMalformedException, KeycloakRemoteException, AccessDeniedException { + public Database create(DatabaseCreateDto createDto, Principal principal) throws ContainerNotFoundException, + DatabaseMalformedException, UserNotFoundException, QueryMalformedException { /* start the object */ final Database database = databaseMapper.databaseCreateDtoToDatabase(createDto); final Container container = containerService.find(database.getCid()); @@ -145,7 +143,7 @@ public class MariaDbServiceImpl extends HibernateConnector implements DatabaseSe preparedStatement3.executeUpdate(); } catch (SQLException e) { log.error("Failed to create database/-user: {}", e.getMessage()); - throw new DatabaseMalformedException("Failed to create database/-user", e); + throw new DatabaseMalformedException("Failed to create database/-user: " + e.getMessage(), e); } finally { dataSource.close(); } @@ -268,7 +266,7 @@ public class MariaDbServiceImpl extends HibernateConnector implements DatabaseSe log.info("Enabled system-versioning for table with name {}", table.getInternalName()); } final PreparedStatement preparedStatement2 = queryMapper.databaseToDatabaseConstraintMetadata(connection, table.getDatabase().getInternalName(), table.getInternalName()); - table.setConstraints(resultSetTableToObtainedConstraintsMetadata(preparedStatement2.executeQuery(), table)); + table.setConstraints(resultSetTableToObtainedConstraintsMetadata(preparedStatement2.executeQuery())); final PreparedStatement preparedStatement3 = tableMapper.tableToCreateHistoryViewRawQuery(connection, table); preparedStatement3.executeUpdate(); database.getTables().add(table); @@ -300,8 +298,7 @@ public class MariaDbServiceImpl extends HibernateConnector implements DatabaseSe } @Transactional - public Constraints resultSetTableToObtainedConstraintsMetadata(ResultSet resultSet, Table table) - throws SQLException { + public Constraints resultSetTableToObtainedConstraintsMetadata(ResultSet resultSet) throws SQLException { final Set<String> checks = new LinkedHashSet<>(); final List<Unique> uniques = new LinkedList<>(); final List<ForeignKey> foreignKeys = new LinkedList<>(); diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/OntologyServiceImpl.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/OntologyServiceImpl.java index a629754c4fb24358723557b3152538fd6043fbf6..8818e51b724bf59884df8ad0016557b950dc4618 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/OntologyServiceImpl.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/OntologyServiceImpl.java @@ -52,8 +52,7 @@ public class OntologyServiceImpl implements OntologyService { } @Override - public Ontology create(OntologyCreateDto data, Principal principal) throws UserNotFoundException, - KeycloakRemoteException, AccessDeniedException { + public Ontology create(OntologyCreateDto data, Principal principal) { final Ontology entity = ontologyMapper.ontologyCreateDtoToOntology(data); final Ontology ontology = ontologyRepository.save(entity); log.info("Created ontology with id {} in metadata database", ontology.getId()); diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/QueryServiceImpl.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/QueryServiceImpl.java index 70a1e6cc2b5b74e7af2116d298aa0c11d467b396..b78715ee47068b3c4956e92a8ca562c792fe3ab1 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/QueryServiceImpl.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/QueryServiceImpl.java @@ -79,8 +79,7 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService public QueryResultDto execute(Long databaseId, ExecuteStatementDto statement, Principal principal, Long page, Long size, SortType sortDirection, String sortColumn) throws DatabaseNotFoundException, ImageNotSupportedException, QueryMalformedException, QueryStoreException, - ColumnParseException, UserNotFoundException, DatabaseConnectionException, TableMalformedException, - KeycloakRemoteException, AccessDeniedException, QueryNotFoundException { + ColumnParseException, UserNotFoundException, TableMalformedException, QueryNotFoundException { if (statement.getStatement().contains(";")) { log.error("Failed to execute query: contains ';'"); throw new QueryMalformedException("Failed to execute query: contains ';'"); @@ -232,9 +231,8 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService @Override @Transactional - public Long viewCount(Long databaseId, View view, Principal principal) - throws DatabaseNotFoundException, ImageNotSupportedException, - QueryMalformedException, QueryStoreException, TableMalformedException { + public Long viewCount(Long databaseId, View view, Principal principal) throws DatabaseNotFoundException, + ImageNotSupportedException, QueryMalformedException, QueryStoreException, TableMalformedException { /* find */ final String statement = queryMapper.viewToRawCountAllQuery(view); return executeCountNonPersistent(databaseId, statement); @@ -265,7 +263,8 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService return retrieveBlobAsResource(database.getContainer(), filename); } - private ExportResource retrieveBlobAsResource(Container container, String filename) throws DataDbSidecarException, FileStorageException { + private ExportResource retrieveBlobAsResource(Container container, String filename) throws DataDbSidecarException, + FileStorageException { /* upload from sidecar into blob storage */ dataDbSidecarGateway.exportFile(container.getSidecarHost(), container.getSidecarPort(), filename); /* export file from blob storage */ @@ -279,8 +278,8 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService } catch (ServerException | InsufficientDataException | ErrorResponseException | IOException | NoSuchAlgorithmException | InvalidKeyException | InvalidResponseException | XmlParserException | InternalException e) { - log.error("Failed to find object {} in bucket {}", filename, s3Config.getS3ExportBucket()); - throw new FileStorageException("Failed to find object " + filename + " in bucket " + s3Config.getS3ExportBucket()); + log.error("Failed to find object {} in bucket {}: {}", filename, s3Config.getS3ExportBucket(), e.getMessage()); + throw new FileStorageException("Failed to find object " + filename + " in bucket " + s3Config.getS3ExportBucket() + ": " + e.getMessage()); } } @@ -288,14 +287,14 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService @Transactional(readOnly = true) public ExportResource findOne(Long databaseId, Long queryId, Principal principal) throws DatabaseNotFoundException, ImageNotSupportedException, FileStorageException, QueryStoreException, - QueryNotFoundException, QueryMalformedException, DatabaseConnectionException, UserNotFoundException, DataDbSidecarException { + QueryNotFoundException, QueryMalformedException, DataDbSidecarException { return findOne(databaseId, queryId, principal, RandomStringUtils.randomAlphabetic(40) + ".csv"); } @Transactional(readOnly = true) public ExportResource findOne(Long databaseId, Long queryId, Principal principal, String filename) throws DatabaseNotFoundException, ImageNotSupportedException, FileStorageException, QueryStoreException, - QueryNotFoundException, QueryMalformedException, DatabaseConnectionException, UserNotFoundException, DataDbSidecarException { + QueryNotFoundException, QueryMalformedException, DataDbSidecarException { /* find */ final Database database = databaseService.find(databaseId); final Query query = storeService.findOne(databaseId, queryId, principal); @@ -308,7 +307,7 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService preparedStatement.executeUpdate(); } catch (SQLException e) { log.error("Failed to execute query: {}", e.getMessage()); - throw new QueryStoreException("Failed to execute query", e); + throw new QueryStoreException("Failed to execute query: " + e.getMessage(), e); } finally { dataSource.close(); } @@ -333,13 +332,13 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService preparedStatement.executeUpdate(); } catch (DateTimeParseException e) { log.error("Failed to parse date: {}", e.getMessage()); - throw new TableMalformedException("Failed to parse date", e); + throw new TableMalformedException("Failed to parse date: " + e.getMessage(), e); } catch (NumberFormatException e) { log.error("Failed to parse number: {}", e.getMessage()); - throw new TableMalformedException("Failed to parse number", e); + throw new TableMalformedException("Failed to parse number: " + e.getMessage(), e); } catch (Exception e) { log.error("Database failed to accept tuple: {}", e.getMessage()); - throw new TableMalformedException("Database failed to accept tuple", e); + throw new TableMalformedException("Database failed to accept tuple: " + e.getMessage(), e); } finally { dataSource.close(); } @@ -349,7 +348,7 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService @Transactional public void delete(Long databaseId, Long tableId, TableCsvDeleteDto data, Principal principal) throws ImageNotSupportedException, TableMalformedException, DatabaseNotFoundException, - TableNotFoundException, DatabaseConnectionException, QueryMalformedException, UserNotFoundException { + TableNotFoundException, QueryMalformedException { /* find */ final Database database = databaseService.find(databaseId); final Table table = tableService.find(databaseId, tableId); @@ -364,7 +363,7 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService preparedStatement.executeUpdate(); } catch (SQLException e) { log.error("Failed to delete tuples: {}", e.getMessage()); - throw new TableMalformedException("Failed to delete tuples", e); + throw new TableMalformedException("Failed to delete tuples: " + e.getMessage(), e); } finally { dataSource.close(); } @@ -373,8 +372,7 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService @Override @Transactional public void insert(Long databaseId, Long tableId, ImportDto data, Principal principal) - throws TableMalformedException, DatabaseNotFoundException, TableNotFoundException, QueryMalformedException, - DataDbSidecarException { + throws TableMalformedException, DatabaseNotFoundException, TableNotFoundException, DataDbSidecarException { /* find */ final Database database = databaseService.find(databaseId); final Table table = tableService.find(databaseId, tableId); @@ -387,8 +385,8 @@ public class QueryServiceImpl extends HibernateConnector implements QueryService final Connection connection = dataSource.getConnection(); queryMapper.importCsvQuery(connection, table, data); } catch (SQLException e) { - log.error("Failed to import .csv: {}", e.getMessage()); - throw new TableMalformedException("Failed to import .csv", e); + log.error("Failed to import csv: {}", e.getMessage()); + throw new TableMalformedException("Failed to import csv: " + e.getMessage(), e); } finally { dataSource.close(); } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/QueryStoreServiceImpl.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/QueryStoreServiceImpl.java index 411e6cc1fa3f933f667983463e41817d0b39a236..d3078999fd77103143d8abc49cb51fa2582fd8b9 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/QueryStoreServiceImpl.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/QueryStoreServiceImpl.java @@ -31,7 +31,7 @@ public class QueryStoreServiceImpl extends HibernateConnector implements QuerySt @Override @Transactional(rollbackFor = DatabaseMalformedException.class) public void create(Long databaseId, Principal principal) throws DatabaseNotFoundException, - DatabaseConnectionException, DatabaseMalformedException, UserNotFoundException, QueryStoreException { + DatabaseMalformedException, UserNotFoundException, QueryStoreException { final Database database = databaseService.findById(databaseId); /* create */ final ComboPooledDataSource dataSource = getPrivilegedDataSource(database.getContainer().getImage(), database.getContainer(), database); diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/SemanticServiceImpl.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/SemanticServiceImpl.java index cd3871cb482dd8596fd0bf5064fe3999ddccfc50..5ca35a87374177b473d2e1e8de00e3d07b88486a 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/SemanticServiceImpl.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/SemanticServiceImpl.java @@ -74,7 +74,7 @@ public class SemanticServiceImpl implements SemanticService { .findFirst(); if (optional.isEmpty()) { log.error("Failed to find unit with uri {} in metadata database", uri); - throw new UnitNotFoundException("Failed to find unit with uri " + uri + " in metadata database"); + throw new UnitNotFoundException("Failed to find unit with uri " + uri); } return optional.get(); } @@ -94,7 +94,7 @@ public class SemanticServiceImpl implements SemanticService { .findFirst(); if (optional.isEmpty()) { log.error("Failed to find concept with uri {} in metadata database", uri); - throw new ConceptNotFoundException("Failed to find concept with uri " + uri + " in metadata database"); + throw new ConceptNotFoundException("Failed to find concept with uri " + uri); } return optional.get(); } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/StoreServiceImpl.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/StoreServiceImpl.java index af6d6ee60aa20966006c24a8e0675657c3f25dfd..df8df65792718d259b73b91ca75901ff2f20502d 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/StoreServiceImpl.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/StoreServiceImpl.java @@ -3,7 +3,6 @@ package at.tuwien.service.impl; import at.tuwien.api.database.query.ExecuteStatementDto; import at.tuwien.api.database.query.QueryPersistDto; import at.tuwien.entities.database.Database; -import at.tuwien.entities.identifier.Identifier; import at.tuwien.entities.user.User; import at.tuwien.exception.*; import at.tuwien.mapper.StoreMapper; @@ -44,8 +43,7 @@ public class StoreServiceImpl extends HibernateConnector implements StoreService @Override @Transactional(readOnly = true) public List<Query> findAll(Long databaseId, Boolean persisted, Principal principal) - throws DatabaseNotFoundException, ImageNotSupportedException, QueryStoreException, - ContainerNotFoundException, DatabaseConnectionException, TableMalformedException, UserNotFoundException { + throws DatabaseNotFoundException, ImageNotSupportedException, QueryStoreException { /* find */ final Database database = databaseService.find(databaseId); if (!database.getContainer().getImage().getName().equals("mariadb")) { @@ -67,7 +65,7 @@ public class StoreServiceImpl extends HibernateConnector implements StoreService return queries; } catch (SQLException e) { log.error("Failed to find queries in database with id {}: {}", databaseId, e.getMessage()); - throw new QueryStoreException("Failed to find queries in database with id " + database); + throw new QueryStoreException("Failed to find queries in database with id " + databaseId + ": " + e.getMessage()); } finally { dataSource.close(); } @@ -92,12 +90,12 @@ public class StoreServiceImpl extends HibernateConnector implements StoreService final ResultSet resultSet = preparedStatement.executeQuery(); if (!resultSet.next()) { log.error("Query not found with id {} in database with id {}", queryId, databaseId); - throw new QueryNotFoundException("Query not found with id " + queryId + " in database with id " + databaseId); + throw new QueryNotFoundException("Query not found with id " + queryId + " in database with id " + databaseId); } return storeMapper.resultSetToQuery(resultSet); } catch (SQLException e) { log.error("Failed to retrieve first row for query with id {}: {}", queryId, e.getMessage()); - throw new QueryStoreException("Failed to retrieve first row for query with id " + queryId); + throw new QueryStoreException("Failed to retrieve first row for query with id " + queryId + ": " + e.getMessage()); } finally { dataSource.close(); } @@ -106,8 +104,7 @@ public class StoreServiceImpl extends HibernateConnector implements StoreService @Override @Transactional(readOnly = true) public Query insert(Long databaseId, ExecuteStatementDto metadata, Principal principal) - throws QueryStoreException, DatabaseNotFoundException, ImageNotSupportedException, - UserNotFoundException, DatabaseConnectionException, KeycloakRemoteException, AccessDeniedException, + throws QueryStoreException, DatabaseNotFoundException, ImageNotSupportedException, UserNotFoundException, QueryNotFoundException { /* find */ final Database database = databaseService.find(databaseId); @@ -142,7 +139,7 @@ public class StoreServiceImpl extends HibernateConnector implements StoreService return query; } catch (SQLException e) { log.error("Failed to execute query: {}", e.getMessage()); - throw new QueryStoreException("Failed to execute query", e); + throw new QueryStoreException("Failed to execute query: " + e.getMessage(), e); } finally { dataSource.close(); } @@ -208,7 +205,7 @@ public class StoreServiceImpl extends HibernateConnector implements StoreService log.debug("delete stale queries affected {} rows", affected); } catch (SQLException e) { log.error("Failed to delete stale queries in database with id {}: {}", database.getId(), e.getMessage()); - throw new QueryStoreException("Failed to delete stale queries in database with id " + database.getId(), e); + throw new QueryStoreException("Failed to delete stale queries in database with id " + database.getId() + ": " + e.getMessage(), e); } finally { dataSource.close(); } diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/TableServiceImpl.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/TableServiceImpl.java index 5e5e25b874fd45813c1723a8ea74558ca8728b2b..3201ad9ea0e7b8ea839da97ed6a0b67352309e4d 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/TableServiceImpl.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/TableServiceImpl.java @@ -116,7 +116,7 @@ public class TableServiceImpl extends HibernateConnector implements TableService return queryMapper.resultListToTableHistoryDto(resultSet); } catch (SQLException e) { log.error("Failed to map table history: {}", e.getMessage()); - throw new QueryStoreException("Failed to map table history", e); + throw new QueryStoreException("Failed to map table history: " + e.getMessage(), e); } finally { dataSource.close(); } @@ -209,10 +209,9 @@ public class TableServiceImpl extends HibernateConnector implements TableService @Override @Transactional - public TableColumn update(Long databaseId, Long tableId, Long columnId, - ColumnSemanticsUpdateDto updateDto, String authorization) - throws TableNotFoundException, DatabaseNotFoundException, TableMalformedException, - SemanticEntityNotFoundException, QueryMalformedException { + public TableColumn update(Long databaseId, Long tableId, Long columnId, ColumnSemanticsUpdateDto updateDto, + String authorization) throws TableNotFoundException, DatabaseNotFoundException, + TableMalformedException { final Table table = find(databaseId, tableId); final TableColumn column = findColumn(table, columnId); /* assign */ diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/UserServiceImpl.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/UserServiceImpl.java index d7c40db36f7fc4a09090d76eae9f8c125289c740..581239b2950acebee4ed7f2476f17b5d0ae5782b 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/UserServiceImpl.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/service/impl/UserServiceImpl.java @@ -53,8 +53,7 @@ public class UserServiceImpl implements UserService { } @Override - public User create(SignupRequestDto data, UUID id) throws UserAlreadyExistsException, AccessDeniedException, - KeycloakRemoteException, UserNotFoundException, UserEmailAlreadyExistsException { + public User create(SignupRequestDto data, UUID id) { /* create at authentication service */ final User entity = User.builder() .id(id)