diff --git a/fda-query-service/services/src/main/java/at/tuwien/config/WebSecurityConfig.java b/fda-query-service/services/src/main/java/at/tuwien/config/WebSecurityConfig.java index 20cb1215a930de2d386633cef30c07ed11ef5602..37af892694fd5feef0af131a03939655268da3cb 100644 --- a/fda-query-service/services/src/main/java/at/tuwien/config/WebSecurityConfig.java +++ b/fda-query-service/services/src/main/java/at/tuwien/config/WebSecurityConfig.java @@ -62,16 +62,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.GET, "/api/container/**/database/**/table/**/export/**").permitAll() .antMatchers(HttpMethod.GET, "/api/container/**/database/query/**").permitAll() .antMatchers(HttpMethod.GET, "/api/container/**/database/**/query/**").permitAll() - .antMatchers("/v2/api-docs", - "/configuration/ui", - "/swagger-resources", - "/configuration/security", - "/swagger-ui.html", - "/webjars/**", - "/swagger-resources/configuration/ui", - "/swagger-ui.html", - "/v3/api-docs/**", - "/swagger-ui/**").permitAll() + .antMatchers("/v3/api-docs/**", + "/swagger-ui/**", + "/swagger-ui.html").permitAll() /* insert endpoint */ .antMatchers(HttpMethod.POST, "/api/container/**/database/**/table/**/data").permitAll() /* our private endpoints */ diff --git a/fda-table-service/pom.xml b/fda-table-service/pom.xml index c438df0222d945aae4bd61ded57b955ce033aecf..0acf9a647dfab83423f7d3b3f8c98221eb9c919c 100644 --- a/fda-table-service/pom.xml +++ b/fda-table-service/pom.xml @@ -193,17 +193,6 @@ <artifactId>mapstruct</artifactId> <version>${mapstruct.version}</version> </dependency> - <!-- Swagger --> - <dependency> - <groupId>io.springfox</groupId> - <artifactId>springfox-boot-starter</artifactId> - <version>${springfox.version}</version> - </dependency> - <dependency> - <groupId>io.swagger</groupId> - <artifactId>swagger-codegen-maven-plugin</artifactId> - <version>2.4.21</version> - </dependency> </dependencies> <build> diff --git a/fda-table-service/rest-service/src/main/java/at/tuwien/FdaTableServiceApplication.java b/fda-table-service/rest-service/src/main/java/at/tuwien/FdaTableServiceApplication.java index 90bb253a4c549241394f0696b4b094faa9b46ab4..0185480e36d3c3ad08194970e73f060494b8c440 100644 --- a/fda-table-service/rest-service/src/main/java/at/tuwien/FdaTableServiceApplication.java +++ b/fda-table-service/rest-service/src/main/java/at/tuwien/FdaTableServiceApplication.java @@ -7,12 +7,10 @@ import org.springframework.data.elasticsearch.repository.config.EnableElasticsea import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.transaction.annotation.EnableTransactionManagement; -import springfox.documentation.oas.annotations.EnableOpenApi; @SpringBootApplication @EnableJpaAuditing -@EnableOpenApi @EnableTransactionManagement @EnableElasticsearchRepositories(basePackages = {"at.tuwien.repository.elastic"}) @EnableJpaRepositories(basePackages = {"at.tuwien.repository.jpa"}) diff --git a/fda-table-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java b/fda-table-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java index dad2860b67931dfb268b7500d25ecc11a791a284..1e076eeb1eb2dafb35bea09b8cd60502b8248791 100644 --- a/fda-table-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java +++ b/fda-table-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java @@ -1,40 +1,41 @@ package at.tuwien.config; +import io.swagger.v3.oas.models.ExternalDocumentation; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import org.springdoc.core.GroupedOpenApi; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.oas.annotations.EnableOpenApi; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.service.Contact; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; - -import java.util.Collections; @Configuration -@EnableOpenApi public class SwaggerConfig { @Bean - public Docket tableApi() { - return new Docket(DocumentationType.SWAGGER_2) - .apiInfo(apiInfo()) - .select() - .paths(PathSelectors.ant("/api/**")) - .build(); + public OpenAPI springShopOpenAPI() { + return new OpenAPI() + .info(new Info() + .title("Database Repository Table Service API") + .contact(new Contact() + .name("Prof. Andreas Rauber") + .email("andreas.rauber@tuwien.ac.at")) + .description("Service that manages the tables") + .version("v1.1.0-alpha") + .license(new License() + .name("Apache 2.0") + .url("https://www.apache.org/licenses/LICENSE-2.0"))) + .externalDocs(new ExternalDocumentation() + .description("Wiki Documentation") + .url("https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services/-/wikis")); } - private ApiInfo apiInfo() { - return new ApiInfo("FDA-Table-Service API", - "Service API for table service", - "1.0", - null, - new Contact("Ao.Univ.Prof. Andreas Rauber", "http://www.ifs.tuwien.ac.at/~andi/", "rauber@ifs.tuwien.ac.at"), - "API license", - null, - Collections.emptyList()); - - + @Bean + public GroupedOpenApi publicApi() { + return GroupedOpenApi.builder() + .group("table-service") + .pathsToMatch("/api/**") + .build(); } } diff --git a/fda-table-service/rest-service/src/main/java/at/tuwien/endpoints/TableEndpoint.java b/fda-table-service/rest-service/src/main/java/at/tuwien/endpoints/TableEndpoint.java index dcb900773aef75d00d9ed4fa5055bed2c2bd83d7..7304114bcff18b5d303820bae65139a2f71dc87f 100644 --- a/fda-table-service/rest-service/src/main/java/at/tuwien/endpoints/TableEndpoint.java +++ b/fda-table-service/rest-service/src/main/java/at/tuwien/endpoints/TableEndpoint.java @@ -6,11 +6,8 @@ import at.tuwien.exception.*; import at.tuwien.mapper.TableMapper; import at.tuwien.service.MessageQueueService; import at.tuwien.service.TableService; -import at.tuwien.service.impl.RabbitMqService; -import at.tuwien.service.impl.TableServiceImpl; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -43,11 +40,7 @@ public class TableEndpoint { @GetMapping @Transactional(readOnly = true) - @ApiOperation(value = "List all tables", notes = "Lists the tables in the metadata database for this database.") - @ApiResponses({ - @ApiResponse(code = 200, message = "All tables are listed."), - @ApiResponse(code = 401, message = "Not authorized to list all tables."), - }) + @Operation(summary = "List tables") public ResponseEntity<List<TableBriefDto>> findAll(@NotNull @PathVariable("id") Long id, @NotNull @PathVariable("databaseId") Long databaseId) throws DatabaseNotFoundException { @@ -60,15 +53,7 @@ public class TableEndpoint { @PostMapping @Transactional @PreAuthorize("hasRole('ROLE_RESEARCHER')") - @ApiOperation(value = "Create a table", notes = "Creates a new table for a database, requires a running container.") - @ApiResponses({ - @ApiResponse(code = 201, message = "The table was created."), - @ApiResponse(code = 400, message = "The creation form contains invalid data."), - @ApiResponse(code = 401, message = "Not authorized to create a tables."), - @ApiResponse(code = 404, message = "The database does not exist."), - @ApiResponse(code = 405, message = "The container is not running."), - @ApiResponse(code = 409, message = "The table name already exists."), - }) + @Operation(summary = "Create table", security = @SecurityRequirement(name = "bearerAuth")) public ResponseEntity<TableBriefDto> create(@NotNull @PathVariable("id") Long id, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @Valid @RequestBody TableCreateDto createDto) @@ -84,12 +69,7 @@ public class TableEndpoint { @GetMapping("/{tableId}") @Transactional(readOnly = true) - @ApiOperation(value = "Get information about table", notes = "Lists the information of a table from the metadata database for this database.") - @ApiResponses({ - @ApiResponse(code = 200, message = "All tables are listed."), - @ApiResponse(code = 401, message = "Not authorized to list all tables."), - @ApiResponse(code = 404, message = "Table not found in metadata database."), - }) + @Operation(summary = "Find some table") public ResponseEntity<TableDto> findById(@NotNull @PathVariable("id") Long id, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("tableId") Long tableId) @@ -101,29 +81,17 @@ public class TableEndpoint { @PutMapping("/{tableId}") @Transactional @PreAuthorize("hasRole('ROLE_RESEARCHER')") - @ApiOperation(value = "Update a table", notes = "Update a table in the database.") - @ApiResponses({ - @ApiResponse(code = 200, message = "Updated the table."), - @ApiResponse(code = 400, message = "The update form contains invalid data."), - @ApiResponse(code = 401, message = "Not authorized to update tables."), - @ApiResponse(code = 404, message = "The table is not found in database."), - }) + @Operation(summary = "Update some table", security = @SecurityRequirement(name = "bearerAuth")) public ResponseEntity<TableBriefDto> update(@NotNull @PathVariable("id") Long id, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("tableId") Long tableId) { - // TODO return ResponseEntity.unprocessableEntity().body(new TableBriefDto()); } @DeleteMapping("/{tableId}") @Transactional @PreAuthorize("hasRole('ROLE_DEVELOPER') or hasRole('ROLE_DATA_STEWARD')") - @ApiOperation(value = "Delete a table", notes = "Delete a table in the database.") - @ApiResponses({ - @ApiResponse(code = 200, message = "Deleted the table."), - @ApiResponse(code = 401, message = "Not authorized to delete tables."), - @ApiResponse(code = 404, message = "The table is not found in database."), - }) + @Operation(summary = "Delete some table", security = @SecurityRequirement(name = "bearerAuth")) @ResponseStatus(HttpStatus.OK) public void delete(@NotNull @PathVariable("id") Long id, @NotNull @PathVariable("databaseId") Long databaseId, diff --git a/fda-table-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java b/fda-table-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java index d6c2edbdc25d173db2909ed3a6e556c2dff8525a..7c2e2c1996255a9cfb0edafb62ff1fa4f2d88b66 100644 --- a/fda-table-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java +++ b/fda-table-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java @@ -7,24 +7,27 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; @ControllerAdvice public class ApiExceptionHandler extends ResponseEntityExceptionHandler { - @ExceptionHandler({AmqpException.class}) - public ResponseEntity<Object> handle(AmqpException e, WebRequest request) { + @ResponseStatus(HttpStatus.NOT_ACCEPTABLE) + @ExceptionHandler(AmqpException.class) + public ResponseEntity<ApiErrorDto> handle(AmqpException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.BAD_REQUEST) + .status(HttpStatus.NOT_ACCEPTABLE) .message(e.getLocalizedMessage()) .code("error.database.queue") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ExceptionHandler({ArbitraryPrimaryKeysException.class}) - public ResponseEntity<Object> handle(ArbitraryPrimaryKeysException e, WebRequest request) { + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(ArbitraryPrimaryKeysException.class) + public ResponseEntity<ApiErrorDto> handle(ArbitraryPrimaryKeysException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() .status(HttpStatus.BAD_REQUEST) .message(e.getLocalizedMessage()) @@ -33,8 +36,9 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ExceptionHandler({ContainerNotFoundException.class}) - public ResponseEntity<Object> handle(ContainerNotFoundException e, WebRequest request) { + @ResponseStatus(HttpStatus.NOT_FOUND) + @ExceptionHandler(ContainerNotFoundException.class) + public ResponseEntity<ApiErrorDto> handle(ContainerNotFoundException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() .status(HttpStatus.NOT_FOUND) .message(e.getLocalizedMessage()) @@ -43,8 +47,9 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ExceptionHandler({DatabaseConnectionException.class}) - public ResponseEntity<Object> handle(DatabaseConnectionException e, WebRequest request) { + @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) + @ExceptionHandler(DatabaseConnectionException.class) + public ResponseEntity<ApiErrorDto> handle(DatabaseConnectionException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() .status(HttpStatus.METHOD_NOT_ALLOWED) .message(e.getLocalizedMessage()) @@ -53,8 +58,9 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ExceptionHandler({DatabaseNotFoundException.class}) - public ResponseEntity<Object> handle(DatabaseNotFoundException e, WebRequest request) { + @ResponseStatus(HttpStatus.NOT_FOUND) + @ExceptionHandler(DatabaseNotFoundException.class) + public ResponseEntity<ApiErrorDto> handle(DatabaseNotFoundException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() .status(HttpStatus.NOT_FOUND) .message(e.getLocalizedMessage()) @@ -63,8 +69,9 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ExceptionHandler({DataProcessingException.class}) - public ResponseEntity<Object> handle(DataProcessingException e, WebRequest request) { + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(DataProcessingException.class) + public ResponseEntity<ApiErrorDto> handle(DataProcessingException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() .status(HttpStatus.BAD_REQUEST) .message(e.getLocalizedMessage()) @@ -73,8 +80,9 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ExceptionHandler({FileStorageException.class}) - public ResponseEntity<Object> handle(FileStorageException e, WebRequest request) { + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(FileStorageException.class) + public ResponseEntity<ApiErrorDto> handle(FileStorageException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() .status(HttpStatus.BAD_REQUEST) .message(e.getLocalizedMessage()) @@ -83,8 +91,9 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ExceptionHandler({ImageNotSupportedException.class}) - public ResponseEntity<Object> handle(ImageNotSupportedException e, WebRequest request) { + @ResponseStatus(HttpStatus.CONFLICT) + @ExceptionHandler(ImageNotSupportedException.class) + public ResponseEntity<ApiErrorDto> handle(ImageNotSupportedException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() .status(HttpStatus.CONFLICT) .message(e.getLocalizedMessage()) @@ -93,18 +102,20 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ExceptionHandler({PaginationException.class}) - public ResponseEntity<Object> handle(PaginationException e, WebRequest request) { + @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) + @ExceptionHandler(PaginationException.class) + public ResponseEntity<ApiErrorDto> handle(PaginationException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.CONFLICT) + .status(HttpStatus.METHOD_NOT_ALLOWED) .message(e.getLocalizedMessage()) .code("error.database.pagination") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ExceptionHandler({TableMalformedException.class}) - public ResponseEntity<Object> handle(TableMalformedException e, WebRequest request) { + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(TableMalformedException.class) + public ResponseEntity<ApiErrorDto> handle(TableMalformedException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() .status(HttpStatus.BAD_REQUEST) .message(e.getLocalizedMessage()) @@ -113,8 +124,9 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ExceptionHandler({TableNameExistsException.class}) - public ResponseEntity<Object> handle(TableNameExistsException e, WebRequest request) { + @ResponseStatus(HttpStatus.CONFLICT) + @ExceptionHandler(TableNameExistsException.class) + public ResponseEntity<ApiErrorDto> handle(TableNameExistsException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() .status(HttpStatus.CONFLICT) .message(e.getLocalizedMessage()) @@ -123,8 +135,9 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ExceptionHandler({TableNotFoundException.class}) - public ResponseEntity<Object> handle(TableNotFoundException e, WebRequest request) { + @ResponseStatus(HttpStatus.NOT_FOUND) + @ExceptionHandler(TableNotFoundException.class) + public ResponseEntity<ApiErrorDto> handle(TableNotFoundException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() .status(HttpStatus.NOT_FOUND) .message(e.getLocalizedMessage()) diff --git a/fda-table-service/rest-service/src/main/resources/application.yml b/fda-table-service/rest-service/src/main/resources/application.yml index 4f4107471553d4f5a162b19f314a233ff6395be5..5cee4931537f6ea302a0378a4af164550362b076 100644 --- a/fda-table-service/rest-service/src/main/resources/application.yml +++ b/fda-table-service/rest-service/src/main/resources/application.yml @@ -30,6 +30,6 @@ eureka: instance.hostname: fda-table-service client.serviceUrl.defaultZone: http://localhost:9090/eureka/ fda: - ready.path: ./readyalhost:9090/eureka/ + ready.path: ./ready gateway.endpoint: http://localhost:9095 - elastic.endpoint: fda-search-service:9200 \ No newline at end of file + elastic.endpoint: localhost:9200 \ No newline at end of file diff --git a/fda-table-service/services/src/main/java/at/tuwien/config/WebSecurityConfig.java b/fda-table-service/services/src/main/java/at/tuwien/config/WebSecurityConfig.java index 58a1d637f3926c247c369ee0378412bf1713f2a7..4a0189575d9871cccf0e4d3f129bc2112987e446 100644 --- a/fda-table-service/services/src/main/java/at/tuwien/config/WebSecurityConfig.java +++ b/fda-table-service/services/src/main/java/at/tuwien/config/WebSecurityConfig.java @@ -58,16 +58,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { http.authorizeRequests() /* our public endpoints */ .antMatchers(HttpMethod.GET, "/api/container/**/database/**/table/**").permitAll() - .antMatchers("/v2/api-docs", - "/configuration/ui", - "/swagger-resources", - "/configuration/security", - "/swagger-ui.html", - "/webjars/**", - "/swagger-resources/configuration/ui", - "/swagger-ui.html", - "/v3/api-docs/**", - "/swagger-ui/**").permitAll() + .antMatchers("/v3/api-docs/**", + "/swagger-ui/**", + "/swagger-ui.html").permitAll() /* our private endpoints */ .anyRequest().authenticated(); /* add JWT token filter */ diff --git a/fda-table-service/services/src/main/java/at/tuwien/exception/PaginationException.java b/fda-table-service/services/src/main/java/at/tuwien/exception/PaginationException.java index 9d56aec9c2752c2c37e7b31f227950ad94c95ef3..11a0f198979fc53f9098bc782e839ee8ac8f5fd0 100644 --- a/fda-table-service/services/src/main/java/at/tuwien/exception/PaginationException.java +++ b/fda-table-service/services/src/main/java/at/tuwien/exception/PaginationException.java @@ -3,7 +3,7 @@ package at.tuwien.exception; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; -@ResponseStatus(code = HttpStatus.BAD_REQUEST) +@ResponseStatus(code = HttpStatus.METHOD_NOT_ALLOWED) public class PaginationException extends Exception { public PaginationException(String msg) {