Skip to content
Snippets Groups Projects
Unverified Commit 4ff3d2ec authored by Martin Weise's avatar Martin Weise
Browse files

Updated the table service

parent 8c563039
Branches
Tags
2 merge requests!81New stable release,!47Resolve "Show error messages from response"
Showing
with 82 additions and 127 deletions
......@@ -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 */
......
......@@ -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>
......
......@@ -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"})
......
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();
}
}
......@@ -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,
......
......@@ -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())
......
......@@ -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
......@@ -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 */
......
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment