From 05ae07dd148587a241b0184b13838fe13fed8dd0 Mon Sep 17 00:00:00 2001 From: Martin Weise <martin.weise@tuwien.ac.at> Date: Mon, 28 Mar 2022 15:58:37 +0200 Subject: [PATCH] Reverted more changes --- .../src/test/java/at/tuwien/BaseUnitTest.java | 2 + .../java/at/tuwien/mapper/DatabaseMapper.java | 4 +- .../repository/jpa/ContainerRepository.java | 2 - .../repository/jpa/DatabaseRepository.java | 3 - .../tuwien/repository/jpa/UserRepository.java | 15 - .../at/tuwien/api/container/ContainerDto.java | 4 - .../at/tuwien/api/database/DatabaseDto.java | 4 - .../tuwien/api/database/query/QueryDto.java | 4 - .../tuwien/api/database/table/TableDto.java | 4 - .../api/database/table/columns/ColumnDto.java | 4 - .../tuwien/api/identifier/IdentifierDto.java | 4 - .../tuwien/exception/SortDataException.java | 21 - .../exception/UserNotFoundException.java | 21 - .../main/java/at/tuwien/querystore/Query.java | 6 +- .../tuwien/repository/jpa/UserRepository.java | 15 - fda-table-service/pom.xml | 20 +- .../at/tuwien/FdaTableServiceApplication.java | 2 + .../java/at/tuwien/config/SwaggerConfig.java | 57 +- .../at/tuwien/endpoints/TableEndpoint.java | 49 +- .../tuwien/handlers/ApiExceptionHandler.java | 83 ++- .../src/main/resources/application-docker.yml | 2 - .../src/main/resources/application.yml | 6 +- .../src/test/java/at/tuwien/BaseUnitTest.java | 3 + .../TableEndpointIntegrationTest.java | 2 +- .../endpoint/TableEndpointUnitTest.java | 4 +- .../service/TableServiceIntegrationTest.java | 20 +- .../java/at/tuwien/config/ReadyConfig.java | 16 - .../at/tuwien/config/WebSecurityConfig.java | 22 +- .../tuwien/exception/PaginationException.java | 2 +- .../exception/UserNotFoundException.java | 21 - .../main/java/at/tuwien/seeder/Seeder.java | 9 - .../at/tuwien/seeder/impl/AbstractSeeder.java | 498 ------------------ .../at/tuwien/seeder/impl/SeederImpl.java | 26 - .../tuwien/seeder/impl/TableSeederImpl.java | 50 -- 34 files changed, 145 insertions(+), 860 deletions(-) delete mode 100644 fda-database-service/services/src/main/java/at/tuwien/repository/jpa/UserRepository.java delete mode 100644 fda-query-service/services/src/main/java/at/tuwien/exception/SortDataException.java delete mode 100644 fda-query-service/services/src/main/java/at/tuwien/exception/UserNotFoundException.java delete mode 100644 fda-query-service/services/src/main/java/at/tuwien/repository/jpa/UserRepository.java delete mode 100644 fda-table-service/services/src/main/java/at/tuwien/exception/UserNotFoundException.java delete mode 100644 fda-table-service/services/src/main/java/at/tuwien/seeder/Seeder.java delete mode 100644 fda-table-service/services/src/main/java/at/tuwien/seeder/impl/AbstractSeeder.java delete mode 100644 fda-table-service/services/src/main/java/at/tuwien/seeder/impl/SeederImpl.java delete mode 100644 fda-table-service/services/src/main/java/at/tuwien/seeder/impl/TableSeederImpl.java diff --git a/fda-database-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java b/fda-database-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java index b169bccfda..8e782f7b27 100644 --- a/fda-database-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java +++ b/fda-database-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java @@ -132,6 +132,7 @@ public abstract class BaseUnitTest { .id(DATABASE_1_ID) .name(DATABASE_1_NAME) .internalName(DATABASE_1_INTERNALNAME) + .isPublic(DATABASE_1_PUBLIC) .container(CONTAINER_1) .created(DATABASE_1_CREATED) .tables(List.of()) @@ -158,6 +159,7 @@ public abstract class BaseUnitTest { .id(DATABASE_2_ID) .name(DATABASE_2_NAME) .internalName(DATABASE_2_INTERNALNAME) + .isPublic(DATABASE_2_PUBLIC) .container(CONTAINER_2) .created(DATABASE_2_CREATED) .tables(List.of()) diff --git a/fda-database-service/services/src/main/java/at/tuwien/mapper/DatabaseMapper.java b/fda-database-service/services/src/main/java/at/tuwien/mapper/DatabaseMapper.java index f2c6474089..f2985fb74d 100644 --- a/fda-database-service/services/src/main/java/at/tuwien/mapper/DatabaseMapper.java +++ b/fda-database-service/services/src/main/java/at/tuwien/mapper/DatabaseMapper.java @@ -45,7 +45,7 @@ public interface DatabaseMapper { DatabaseDto databaseToDatabaseDto(Database data); default String databaseToRawCreateDatabaseQuery(Database database) { - return "CREATE DATABASE `" + database.getInternalName() + "`;"; + return "CREATE DATABASE " + database.getInternalName() + ";"; } default String imageToRawGrantReadonlyAccessQuery() { @@ -53,7 +53,7 @@ public interface DatabaseMapper { } default String databaseToRawDeleteDatabaseQuery(Database database) { - return "DROP DATABASE `" + database.getInternalName() + "`;"; + return "DROP DATABASE " + database.getInternalName() + ";"; } } diff --git a/fda-database-service/services/src/main/java/at/tuwien/repository/jpa/ContainerRepository.java b/fda-database-service/services/src/main/java/at/tuwien/repository/jpa/ContainerRepository.java index f50db9945d..39566b1cc0 100644 --- a/fda-database-service/services/src/main/java/at/tuwien/repository/jpa/ContainerRepository.java +++ b/fda-database-service/services/src/main/java/at/tuwien/repository/jpa/ContainerRepository.java @@ -7,6 +7,4 @@ import org.springframework.stereotype.Repository; @Repository public interface ContainerRepository extends JpaRepository<Container, Long> { - /* keep */ - } diff --git a/fda-database-service/services/src/main/java/at/tuwien/repository/jpa/DatabaseRepository.java b/fda-database-service/services/src/main/java/at/tuwien/repository/jpa/DatabaseRepository.java index fd91a51a0e..2e64248f81 100644 --- a/fda-database-service/services/src/main/java/at/tuwien/repository/jpa/DatabaseRepository.java +++ b/fda-database-service/services/src/main/java/at/tuwien/repository/jpa/DatabaseRepository.java @@ -14,7 +14,4 @@ public interface DatabaseRepository extends JpaRepository<Database, Long> { @Query("select d from Database d where d.container.id = :containerId") List<Database> findAllByContainerId(@Param("containerId") Long containerId); - @Query("select d from Database d where d.container.id = :containerId and d.creator.username = :username") - List<Database> findAllMine(@Param("containerId") Long containerId, @Param("username") String username); - } diff --git a/fda-database-service/services/src/main/java/at/tuwien/repository/jpa/UserRepository.java b/fda-database-service/services/src/main/java/at/tuwien/repository/jpa/UserRepository.java deleted file mode 100644 index 8368703d88..0000000000 --- a/fda-database-service/services/src/main/java/at/tuwien/repository/jpa/UserRepository.java +++ /dev/null @@ -1,15 +0,0 @@ - -package at.tuwien.repository.jpa; - -import at.tuwien.entities.user.User; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.Optional; - -@Repository -public interface UserRepository extends JpaRepository<User, Long> { - - Optional<User> findByUsername(String username); - -} diff --git a/fda-metadata-db/api/src/main/java/at/tuwien/api/container/ContainerDto.java b/fda-metadata-db/api/src/main/java/at/tuwien/api/container/ContainerDto.java index c4f422f392..4532df2c72 100644 --- a/fda-metadata-db/api/src/main/java/at/tuwien/api/container/ContainerDto.java +++ b/fda-metadata-db/api/src/main/java/at/tuwien/api/container/ContainerDto.java @@ -32,10 +32,6 @@ public class ContainerDto { @Parameter(name = "container name", example = "Weather World") private String name; - @NotNull - @Parameter(name = "user") - private UserDto creator; - @NotBlank @JsonProperty("internal_name") @Parameter(name = "container internal name", example = "weather-world") diff --git a/fda-metadata-db/api/src/main/java/at/tuwien/api/database/DatabaseDto.java b/fda-metadata-db/api/src/main/java/at/tuwien/api/database/DatabaseDto.java index d9a3d19397..ac7c8fd0b6 100644 --- a/fda-metadata-db/api/src/main/java/at/tuwien/api/database/DatabaseDto.java +++ b/fda-metadata-db/api/src/main/java/at/tuwien/api/database/DatabaseDto.java @@ -35,10 +35,6 @@ public class DatabaseDto { @Parameter(name = "database internal name", example = "weather_australia") private String internalName; - @NotNull - @Parameter(name = "user") - private UserDto creator; - @NotBlank @Parameter(name = "database description", example = "Weather Australia 2009-2021") private String description; diff --git a/fda-metadata-db/api/src/main/java/at/tuwien/api/database/query/QueryDto.java b/fda-metadata-db/api/src/main/java/at/tuwien/api/database/query/QueryDto.java index bd0e9eb27e..0dc1f27d60 100644 --- a/fda-metadata-db/api/src/main/java/at/tuwien/api/database/query/QueryDto.java +++ b/fda-metadata-db/api/src/main/java/at/tuwien/api/database/query/QueryDto.java @@ -37,10 +37,6 @@ public class QueryDto { @Parameter(name = "creator id", example = "1") private Long createdBy; - @NotNull(message = "creator is required") - @Parameter(name = "creator") - private UserDto creator; - @Parameter(name = "execution time", example = "2022-01-01 08:00:00.000") private Instant execution; diff --git a/fda-metadata-db/api/src/main/java/at/tuwien/api/database/table/TableDto.java b/fda-metadata-db/api/src/main/java/at/tuwien/api/database/table/TableDto.java index aec863c220..835243dddd 100644 --- a/fda-metadata-db/api/src/main/java/at/tuwien/api/database/table/TableDto.java +++ b/fda-metadata-db/api/src/main/java/at/tuwien/api/database/table/TableDto.java @@ -31,10 +31,6 @@ public class TableDto { @Parameter(name = "table internal name", example = "weather_australia") private String internalName; - @NotNull - @Parameter(name = "user") - private UserDto creator; - @NotBlank @Parameter(name = "topic name", example = "fda.c1.d1.t1") private String topic; diff --git a/fda-metadata-db/api/src/main/java/at/tuwien/api/database/table/columns/ColumnDto.java b/fda-metadata-db/api/src/main/java/at/tuwien/api/database/table/columns/ColumnDto.java index c176f732ce..b966b1e60c 100644 --- a/fda-metadata-db/api/src/main/java/at/tuwien/api/database/table/columns/ColumnDto.java +++ b/fda-metadata-db/api/src/main/java/at/tuwien/api/database/table/columns/ColumnDto.java @@ -31,10 +31,6 @@ public class ColumnDto { @Parameter(name = "internal name", example = "mdb_date", required = true) private String internalName; - @NotNull - @Parameter(name = "user") - private UserDto creator; - @NotBlank @JsonProperty("date_format") @Parameter(name = "date format", example = "1") diff --git a/fda-metadata-db/api/src/main/java/at/tuwien/api/identifier/IdentifierDto.java b/fda-metadata-db/api/src/main/java/at/tuwien/api/identifier/IdentifierDto.java index 35579d7567..9132e878e7 100644 --- a/fda-metadata-db/api/src/main/java/at/tuwien/api/identifier/IdentifierDto.java +++ b/fda-metadata-db/api/src/main/java/at/tuwien/api/identifier/IdentifierDto.java @@ -33,10 +33,6 @@ public class IdentifierDto { @Parameter(name = "query id", example = "1") private Long qid; - @NotNull - @Parameter(name = "user") - private UserDto creator; - @NotBlank @Parameter(name = "query title", example = "Select all weather events for 2012") private String title; diff --git a/fda-query-service/services/src/main/java/at/tuwien/exception/SortDataException.java b/fda-query-service/services/src/main/java/at/tuwien/exception/SortDataException.java deleted file mode 100644 index aef5cfa078..0000000000 --- a/fda-query-service/services/src/main/java/at/tuwien/exception/SortDataException.java +++ /dev/null @@ -1,21 +0,0 @@ -package at.tuwien.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(code = HttpStatus.BAD_REQUEST) -public class SortDataException extends Exception { - - public SortDataException(String msg) { - super(msg); - } - - public SortDataException(String msg, Throwable thr) { - super(msg, thr); - } - - public SortDataException(Throwable thr) { - super(thr); - } - -} diff --git a/fda-query-service/services/src/main/java/at/tuwien/exception/UserNotFoundException.java b/fda-query-service/services/src/main/java/at/tuwien/exception/UserNotFoundException.java deleted file mode 100644 index 0abb87f609..0000000000 --- a/fda-query-service/services/src/main/java/at/tuwien/exception/UserNotFoundException.java +++ /dev/null @@ -1,21 +0,0 @@ -package at.tuwien.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(code = HttpStatus.NOT_FOUND, reason = "User not found") -public class UserNotFoundException extends Exception { - - public UserNotFoundException(String message) { - super(message); - } - - public UserNotFoundException(String message, Throwable thr) { - super(message, thr); - } - - public UserNotFoundException(Throwable thr) { - super(thr); - } - -} diff --git a/fda-query-service/services/src/main/java/at/tuwien/querystore/Query.java b/fda-query-service/services/src/main/java/at/tuwien/querystore/Query.java index 33e94cb7d1..de1d12f70f 100644 --- a/fda-query-service/services/src/main/java/at/tuwien/querystore/Query.java +++ b/fda-query-service/services/src/main/java/at/tuwien/querystore/Query.java @@ -38,9 +38,6 @@ public class Query implements Serializable { @javax.persistence.Column(nullable = false) private Long dbid; - @javax.persistence.Column(nullable = false) - private Long createdBy; - @javax.persistence.Column private Instant execution; @@ -63,6 +60,9 @@ public class Query implements Serializable { @CreatedDate private Instant created; + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.MERGE) + private List<Table> tables; + @javax.persistence.Column(name = "last_modified") @LastModifiedDate private Instant lastModified; diff --git a/fda-query-service/services/src/main/java/at/tuwien/repository/jpa/UserRepository.java b/fda-query-service/services/src/main/java/at/tuwien/repository/jpa/UserRepository.java deleted file mode 100644 index 8368703d88..0000000000 --- a/fda-query-service/services/src/main/java/at/tuwien/repository/jpa/UserRepository.java +++ /dev/null @@ -1,15 +0,0 @@ - -package at.tuwien.repository.jpa; - -import at.tuwien.entities.user.User; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.Optional; - -@Repository -public interface UserRepository extends JpaRepository<User, Long> { - - Optional<User> findByUsername(String username); - -} diff --git a/fda-table-service/pom.xml b/fda-table-service/pom.xml index d1d24592da..ca2be8d0b8 100644 --- a/fda-table-service/pom.xml +++ b/fda-table-service/pom.xml @@ -193,18 +193,20 @@ <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> - <resources> - <resource> - <directory>${basedir}/src/main/resources</directory> - <filtering>true</filtering> - <includes> - <include>**/application*.yml</include> - </includes> - </resource> - </resources> <plugins> <plugin> <groupId>org.jacoco</groupId> 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 0185480e36..90bb253a4c 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,10 +7,12 @@ 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 c841ecbd15..dad2860b67 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,45 +1,40 @@ 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.beans.factory.annotation.Value; 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 { - @Value("${app.version:unknown}") - private String version; - @Bean - 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(version) - .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")); + public Docket tableApi() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .select() + .paths(PathSelectors.ant("/api/**")) + .build(); } - @Bean - public GroupedOpenApi publicApi() { - return GroupedOpenApi.builder() - .group("table-service") - .pathsToMatch("/api/**") - .build(); + 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()); + + } } 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 7304114bcf..b1fd265188 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,8 +6,11 @@ import at.tuwien.exception.*; import at.tuwien.mapper.TableMapper; import at.tuwien.service.MessageQueueService; import at.tuwien.service.TableService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.security.SecurityRequirement; +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 lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -40,7 +43,11 @@ public class TableEndpoint { @GetMapping @Transactional(readOnly = true) - @Operation(summary = "List tables") + @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."), + }) public ResponseEntity<List<TableBriefDto>> findAll(@NotNull @PathVariable("id") Long id, @NotNull @PathVariable("databaseId") Long databaseId) throws DatabaseNotFoundException { @@ -53,13 +60,21 @@ public class TableEndpoint { @PostMapping @Transactional @PreAuthorize("hasRole('ROLE_RESEARCHER')") - @Operation(summary = "Create table", security = @SecurityRequirement(name = "bearerAuth")) + @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."), + }) public ResponseEntity<TableBriefDto> create(@NotNull @PathVariable("id") Long id, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @Valid @RequestBody TableCreateDto createDto) throws ImageNotSupportedException, DatabaseNotFoundException, DataProcessingException, ArbitraryPrimaryKeysException, TableMalformedException, AmqpException, TableNameExistsException, - ContainerNotFoundException, UserNotFoundException { + ContainerNotFoundException { final Table table = tableService.createTable(id, databaseId, createDto); amqpService.create(table); return ResponseEntity.status(HttpStatus.CREATED) @@ -69,7 +84,12 @@ public class TableEndpoint { @GetMapping("/{tableId}") @Transactional(readOnly = true) - @Operation(summary = "Find some table") + @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."), + }) public ResponseEntity<TableDto> findById(@NotNull @PathVariable("id") Long id, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("tableId") Long tableId) @@ -80,18 +100,29 @@ public class TableEndpoint { @PutMapping("/{tableId}") @Transactional - @PreAuthorize("hasRole('ROLE_RESEARCHER')") - @Operation(summary = "Update some table", security = @SecurityRequirement(name = "bearerAuth")) + @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."), + }) 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')") - @Operation(summary = "Delete some table", security = @SecurityRequirement(name = "bearerAuth")) + @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."), + }) @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 7c2e2c1996..e3e4b5fa11 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,49 +7,34 @@ 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 { - @ResponseStatus(HttpStatus.NOT_ACCEPTABLE) - @ExceptionHandler(AmqpException.class) - public ResponseEntity<ApiErrorDto> handle(AmqpException e, WebRequest request) { - final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.NOT_ACCEPTABLE) - .message(e.getLocalizedMessage()) - .code("error.database.queue") - .build(); - return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); - } - - @ResponseStatus(HttpStatus.BAD_REQUEST) - @ExceptionHandler(ArbitraryPrimaryKeysException.class) - public ResponseEntity<ApiErrorDto> handle(ArbitraryPrimaryKeysException e, WebRequest request) { + @ExceptionHandler({AmqpException.class}) + public ResponseEntity<Object> handle(AmqpException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() .status(HttpStatus.BAD_REQUEST) .message(e.getLocalizedMessage()) - .code("error.database.primary") + .code("error.amqp.queue") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.NOT_FOUND) - @ExceptionHandler(ContainerNotFoundException.class) - public ResponseEntity<ApiErrorDto> handle(ContainerNotFoundException e, WebRequest request) { + @ExceptionHandler({ArbitraryPrimaryKeysException.class}) + public ResponseEntity<Object> handle(ArbitraryPrimaryKeysException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.NOT_FOUND) + .status(HttpStatus.BAD_REQUEST) .message(e.getLocalizedMessage()) - .code("error.database.container") + .code("error.keys.primary") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) - @ExceptionHandler(DatabaseConnectionException.class) - public ResponseEntity<ApiErrorDto> handle(DatabaseConnectionException e, WebRequest request) { + @ExceptionHandler({DatabaseConnectionException.class}) + public ResponseEntity<Object> handle(DatabaseConnectionException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() .status(HttpStatus.METHOD_NOT_ALLOWED) .message(e.getLocalizedMessage()) @@ -58,9 +43,8 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.NOT_FOUND) - @ExceptionHandler(DatabaseNotFoundException.class) - public ResponseEntity<ApiErrorDto> handle(DatabaseNotFoundException e, WebRequest request) { + @ExceptionHandler({DatabaseNotFoundException.class}) + public ResponseEntity<Object> handle(DatabaseNotFoundException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() .status(HttpStatus.NOT_FOUND) .message(e.getLocalizedMessage()) @@ -69,9 +53,8 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.BAD_REQUEST) - @ExceptionHandler(DataProcessingException.class) - public ResponseEntity<ApiErrorDto> handle(DataProcessingException e, WebRequest request) { + @ExceptionHandler({DataProcessingException.class}) + public ResponseEntity<Object> handle(DataProcessingException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() .status(HttpStatus.BAD_REQUEST) .message(e.getLocalizedMessage()) @@ -80,9 +63,8 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.BAD_REQUEST) - @ExceptionHandler(FileStorageException.class) - public ResponseEntity<ApiErrorDto> handle(FileStorageException e, WebRequest request) { + @ExceptionHandler({FileStorageException.class}) + public ResponseEntity<Object> handle(FileStorageException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() .status(HttpStatus.BAD_REQUEST) .message(e.getLocalizedMessage()) @@ -91,9 +73,8 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.CONFLICT) - @ExceptionHandler(ImageNotSupportedException.class) - public ResponseEntity<ApiErrorDto> handle(ImageNotSupportedException e, WebRequest request) { + @ExceptionHandler({ImageNotSupportedException.class}) + public ResponseEntity<Object> handle(ImageNotSupportedException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() .status(HttpStatus.CONFLICT) .message(e.getLocalizedMessage()) @@ -102,42 +83,38 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) - @ExceptionHandler(PaginationException.class) - public ResponseEntity<ApiErrorDto> handle(PaginationException e, WebRequest request) { + @ExceptionHandler({PaginationException.class}) + public ResponseEntity<Object> handle(PaginationException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.METHOD_NOT_ALLOWED) + .status(HttpStatus.CONFLICT) .message(e.getLocalizedMessage()) .code("error.database.pagination") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.BAD_REQUEST) - @ExceptionHandler(TableMalformedException.class) - public ResponseEntity<ApiErrorDto> handle(TableMalformedException e, WebRequest request) { + @ExceptionHandler({TableNameExistsException.class}) + public ResponseEntity<Object> handle(TableNameExistsException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.BAD_REQUEST) + .status(HttpStatus.CONFLICT) .message(e.getLocalizedMessage()) - .code("error.database.table") + .code("error.database.name") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.CONFLICT) - @ExceptionHandler(TableNameExistsException.class) - public ResponseEntity<ApiErrorDto> handle(TableNameExistsException e, WebRequest request) { + @ExceptionHandler({TableMalformedException.class}) + public ResponseEntity<Object> handle(TableMalformedException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.CONFLICT) + .status(HttpStatus.BAD_REQUEST) .message(e.getLocalizedMessage()) - .code("error.database.name") + .code("error.database.table") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.NOT_FOUND) - @ExceptionHandler(TableNotFoundException.class) - public ResponseEntity<ApiErrorDto> handle(TableNotFoundException e, WebRequest request) { + @ExceptionHandler({TableNotFoundException.class}) + public ResponseEntity<Object> 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-docker.yml b/fda-table-service/rest-service/src/main/resources/application-docker.yml index e89a10d737..36ea0e7538 100644 --- a/fda-table-service/rest-service/src/main/resources/application-docker.yml +++ b/fda-table-service/rest-service/src/main/resources/application-docker.yml @@ -1,4 +1,3 @@ -app.version: '@project.version@' spring: main.banner-mode: off datasource: @@ -26,7 +25,6 @@ logging: level: root: warn at.tuwien.: debug - at.tuwien.mapper.: trace eureka: instance.hostname: fda-table-service client.serviceUrl.defaultZone: http://fda-discovery-service:9090/eureka/ 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 b17a9d896e..e921859975 100644 --- a/fda-table-service/rest-service/src/main/resources/application.yml +++ b/fda-table-service/rest-service/src/main/resources/application.yml @@ -1,4 +1,3 @@ -app.version: '@project.version@' spring: main.banner-mode: off datasource: @@ -26,11 +25,10 @@ logging: level: root: warn at.tuwien.: debug - at.tuwien.mapper.: trace eureka: instance.hostname: fda-table-service client.serviceUrl.defaultZone: http://localhost:9090/eureka/ fda: - ready.path: ./ready + ready.path: ./readyalhost:9090/eureka/ gateway.endpoint: http://localhost:9095 - elastic.endpoint: localhost:9200 \ No newline at end of file + elastic.endpoint: fda-search-service:9200 \ No newline at end of file diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java index 4515f147d6..91b82218bf 100644 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java +++ b/fda-table-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java @@ -381,6 +381,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { .id(DATABASE_1_ID) .created(Instant.now().minus(1, HOURS)) .lastModified(Instant.now()) + .isPublic(false) .name(DATABASE_1_NAME) .container(CONTAINER_1) .tables(List.of(TABLE_1)) @@ -392,6 +393,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { .id(DATABASE_2_ID) .created(Instant.now().minus(1, HOURS)) .lastModified(Instant.now()) + .isPublic(false) .name(DATABASE_2_NAME) .container(CONTAINER_2) .tables(List.of(TABLE_2)) @@ -403,6 +405,7 @@ public abstract class BaseUnitTest extends CsvUnitTest { .id(DATABASE_3_ID) .created(Instant.now().minus(1, HOURS)) .lastModified(Instant.now()) + .isPublic(false) .name(DATABASE_3_NAME) .container(CONTAINER_3) .tables(List.of(TABLE_3)) diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/TableEndpointIntegrationTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/TableEndpointIntegrationTest.java index 037f85c275..8f90d8e7b6 100644 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/TableEndpointIntegrationTest.java +++ b/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/TableEndpointIntegrationTest.java @@ -112,7 +112,7 @@ public class TableEndpointIntegrationTest extends BaseUnitTest { @Test public void create_succeeds() throws DatabaseNotFoundException, ImageNotSupportedException, DataProcessingException, ArbitraryPrimaryKeysException, TableMalformedException, - AmqpException, TableNameExistsException, InterruptedException, ContainerNotFoundException, UserNotFoundException { + AmqpException, TableNameExistsException, InterruptedException, ContainerNotFoundException { final TableCreateDto request = TableCreateDto.builder() .name(TABLE_3_NAME) .description(TABLE_3_DESCRIPTION) diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/TableEndpointUnitTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/TableEndpointUnitTest.java index 8ef1008985..8c2fbe556c 100644 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/TableEndpointUnitTest.java +++ b/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/TableEndpointUnitTest.java @@ -73,7 +73,7 @@ public class TableEndpointUnitTest extends BaseUnitTest { @Test public void create_succeeds() throws DatabaseNotFoundException, ImageNotSupportedException, TableNotFoundException, DataProcessingException, ArbitraryPrimaryKeysException, TableMalformedException, - AmqpException, IOException, TableNameExistsException, ContainerNotFoundException, UserNotFoundException { + AmqpException, IOException, TableNameExistsException, ContainerNotFoundException { final TableCreateDto request = TableCreateDto.builder() .name(TABLE_1_NAME) .description(TABLE_1_DESCRIPTION) @@ -96,7 +96,7 @@ public class TableEndpointUnitTest extends BaseUnitTest { @Test public void create_databaseNotFound_fails() throws DatabaseNotFoundException, ImageNotSupportedException, - TableMalformedException, TableNameExistsException, ContainerNotFoundException, UserNotFoundException { + TableMalformedException, TableNameExistsException, ContainerNotFoundException { final TableCreateDto request = TableCreateDto.builder() .name(TABLE_1_NAME) .description(TABLE_1_DESCRIPTION) diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java index 765d1c1dca..7aa4465915 100644 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java +++ b/fda-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java @@ -128,7 +128,7 @@ public class TableServiceIntegrationTest extends BaseUnitTest { @Test public void createTable_succeeds() throws ArbitraryPrimaryKeysException, DatabaseNotFoundException, ImageNotSupportedException, DataProcessingException, TableMalformedException, InterruptedException, - TableNameExistsException, ContainerNotFoundException, UserNotFoundException { + TableNameExistsException, ContainerNotFoundException { final TableCreateDto request = TableCreateDto.builder() .name(TABLE_2_NAME) .description(TABLE_2_DESCRIPTION) @@ -151,7 +151,7 @@ public class TableServiceIntegrationTest extends BaseUnitTest { @Test public void createTable_noPrimaryKeyAutoGenerate_succeeds() throws ArbitraryPrimaryKeysException, DatabaseNotFoundException, ImageNotSupportedException, DataProcessingException, TableMalformedException, - InterruptedException, TableNameExistsException, ContainerNotFoundException, UserNotFoundException { + InterruptedException, TableNameExistsException, ContainerNotFoundException { final ColumnCreateDto[] columns = new ColumnCreateDto[]{ ColumnCreateDto.builder() .name(COLUMN_1_2_NAME) @@ -186,7 +186,7 @@ public class TableServiceIntegrationTest extends BaseUnitTest { @Test public void createTable_noPrimaryKeyAutoGenerateEmpty_succeeds() throws ArbitraryPrimaryKeysException, DatabaseNotFoundException, ImageNotSupportedException, DataProcessingException, TableMalformedException, - InterruptedException, TableNameExistsException, ContainerNotFoundException, UserNotFoundException { + InterruptedException, TableNameExistsException, ContainerNotFoundException { final ColumnCreateDto[] columns = new ColumnCreateDto[0]; final TableCreateDto request = TableCreateDto.builder() .name(TABLE_2_NAME) @@ -249,7 +249,7 @@ public class TableServiceIntegrationTest extends BaseUnitTest { @Test public void createTable_groupPrimaryKey_succeeds() throws ArbitraryPrimaryKeysException, DatabaseNotFoundException, ImageNotSupportedException, DataProcessingException, TableMalformedException, InterruptedException, - TableNameExistsException, ContainerNotFoundException, UserNotFoundException { + TableNameExistsException, ContainerNotFoundException { final ColumnCreateDto[] columns = new ColumnCreateDto[]{ ColumnCreateDto.builder() .name(COLUMN_1_1_NAME) @@ -293,7 +293,7 @@ public class TableServiceIntegrationTest extends BaseUnitTest { @Test public void createTable_checkExpression_succeeds() throws ArbitraryPrimaryKeysException, DatabaseNotFoundException, ImageNotSupportedException, DataProcessingException, TableMalformedException, InterruptedException, - TableNameExistsException, ContainerNotFoundException, UserNotFoundException { + TableNameExistsException, ContainerNotFoundException { final ColumnCreateDto[] columns = new ColumnCreateDto[]{ ColumnCreateDto.builder() .name(COLUMN_1_1_NAME) @@ -327,7 +327,7 @@ public class TableServiceIntegrationTest extends BaseUnitTest { @Test public void createTable_withEnum_succeeds() throws ArbitraryPrimaryKeysException, DatabaseNotFoundException, ImageNotSupportedException, DataProcessingException, TableMalformedException, InterruptedException, - TableNameExistsException, ContainerNotFoundException, UserNotFoundException { + TableNameExistsException, ContainerNotFoundException { final ColumnCreateDto[] columns = new ColumnCreateDto[]{ ColumnCreateDto.builder() .name(COLUMN_1_1_NAME) @@ -372,7 +372,7 @@ public class TableServiceIntegrationTest extends BaseUnitTest { @Test public void createTable_withUniqueColumn_succeeds() throws ArbitraryPrimaryKeysException, DatabaseNotFoundException, ImageNotSupportedException, DataProcessingException, TableMalformedException, InterruptedException, - TableNameExistsException, ContainerNotFoundException, UserNotFoundException { + TableNameExistsException, ContainerNotFoundException { final ColumnCreateDto[] columns = new ColumnCreateDto[]{ ColumnCreateDto.builder() .name(COLUMN_1_1_NAME) @@ -435,7 +435,7 @@ public class TableServiceIntegrationTest extends BaseUnitTest { @Test public void createTable_textPrimaryKey_succeeds() throws InterruptedException, SQLException, TableMalformedException, ArbitraryPrimaryKeysException, DatabaseNotFoundException, ImageNotSupportedException, - DataProcessingException, TableNameExistsException, ContainerNotFoundException, UserNotFoundException { + DataProcessingException, TableNameExistsException, ContainerNotFoundException { final TableCreateDto request = TableCreateDto.builder() .name("Issue 99") .description("Related to issue 99") @@ -468,7 +468,7 @@ public class TableServiceIntegrationTest extends BaseUnitTest { @Test public void createTable_blobPrimaryKey_succeeds() throws InterruptedException, SQLException, TableMalformedException, ArbitraryPrimaryKeysException, DatabaseNotFoundException, ImageNotSupportedException, - DataProcessingException, TableNameExistsException, ContainerNotFoundException, UserNotFoundException { + DataProcessingException, TableNameExistsException, ContainerNotFoundException { final TableCreateDto request = TableCreateDto.builder() .name("Issue 99") .description("Related to issue 99") @@ -513,7 +513,7 @@ public class TableServiceIntegrationTest extends BaseUnitTest { @Test public void createTable_issue106_succeeds() throws InterruptedException, SQLException, TableMalformedException, ArbitraryPrimaryKeysException, DatabaseNotFoundException, ImageNotSupportedException, - DataProcessingException, TableNameExistsException, ContainerNotFoundException, UserNotFoundException { + DataProcessingException, TableNameExistsException, ContainerNotFoundException { final TableCreateDto request = TableCreateDto.builder() .name("Table") .description(TABLE_2_DESCRIPTION) diff --git a/fda-table-service/services/src/main/java/at/tuwien/config/ReadyConfig.java b/fda-table-service/services/src/main/java/at/tuwien/config/ReadyConfig.java index 1047426e49..0bee3b961e 100644 --- a/fda-table-service/services/src/main/java/at/tuwien/config/ReadyConfig.java +++ b/fda-table-service/services/src/main/java/at/tuwien/config/ReadyConfig.java @@ -1,17 +1,13 @@ package at.tuwien.config; -import at.tuwien.seeder.Seeder; import com.google.common.io.Files; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.annotation.Configuration; import org.springframework.context.event.EventListener; -import org.springframework.core.env.Environment; import java.io.File; import java.io.IOException; -import java.util.Arrays; @Configuration public class ReadyConfig { @@ -19,20 +15,8 @@ public class ReadyConfig { @Value("${fda.ready.path}") private String readyPath; - private final Environment environment; - private final Seeder seederImpl; - - @Autowired - public ReadyConfig(Environment environment, Seeder seederImpl) { - this.environment = environment; - this.seederImpl = seederImpl; - } - @EventListener(ApplicationReadyEvent.class) public void init() throws IOException { - if (Arrays.asList(environment.getActiveProfiles()).contains("seeder")) { - seederImpl.seed(); - } Files.touch(new File(readyPath)); } 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 cfbd29d78c..58a1d637f3 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 @@ -2,8 +2,6 @@ package at.tuwien.config; import at.tuwien.auth.AuthTokenFilter; import at.tuwien.gateway.AuthenticationServiceGateway; -import io.swagger.v3.oas.annotations.enums.SecuritySchemeType; -import io.swagger.v3.oas.annotations.security.SecurityScheme; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -23,12 +21,6 @@ import javax.servlet.http.HttpServletResponse; @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) -@SecurityScheme( - name = "bearerAuth", - type = SecuritySchemeType.HTTP, - bearerFormat = "JWT", - scheme = "bearer" -) public class WebSecurityConfig extends WebSecurityConfigurerAdapter { private final AuthenticationServiceGateway authenticationServiceGateway; @@ -66,10 +58,16 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { http.authorizeRequests() /* our public endpoints */ .antMatchers(HttpMethod.GET, "/api/container/**/database/**/table/**").permitAll() - .antMatchers("/v3/api-docs.yaml", - "/v3/api-docs/**", - "/swagger-ui/**", - "/swagger-ui.html").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() /* 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 11a0f19897..9d56aec9c2 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.METHOD_NOT_ALLOWED) +@ResponseStatus(code = HttpStatus.BAD_REQUEST) public class PaginationException extends Exception { public PaginationException(String msg) { diff --git a/fda-table-service/services/src/main/java/at/tuwien/exception/UserNotFoundException.java b/fda-table-service/services/src/main/java/at/tuwien/exception/UserNotFoundException.java deleted file mode 100644 index 0abb87f609..0000000000 --- a/fda-table-service/services/src/main/java/at/tuwien/exception/UserNotFoundException.java +++ /dev/null @@ -1,21 +0,0 @@ -package at.tuwien.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(code = HttpStatus.NOT_FOUND, reason = "User not found") -public class UserNotFoundException extends Exception { - - public UserNotFoundException(String message) { - super(message); - } - - public UserNotFoundException(String message, Throwable thr) { - super(message, thr); - } - - public UserNotFoundException(Throwable thr) { - super(thr); - } - -} diff --git a/fda-table-service/services/src/main/java/at/tuwien/seeder/Seeder.java b/fda-table-service/services/src/main/java/at/tuwien/seeder/Seeder.java deleted file mode 100644 index 128dcaf5a9..0000000000 --- a/fda-table-service/services/src/main/java/at/tuwien/seeder/Seeder.java +++ /dev/null @@ -1,9 +0,0 @@ -package at.tuwien.seeder; - -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.event.EventListener; - -public interface Seeder { - - void seed(); -} diff --git a/fda-table-service/services/src/main/java/at/tuwien/seeder/impl/AbstractSeeder.java b/fda-table-service/services/src/main/java/at/tuwien/seeder/impl/AbstractSeeder.java deleted file mode 100644 index 7d656b65fb..0000000000 --- a/fda-table-service/services/src/main/java/at/tuwien/seeder/impl/AbstractSeeder.java +++ /dev/null @@ -1,498 +0,0 @@ -package at.tuwien.seeder.impl; - -import at.tuwien.api.database.table.TableCreateDto; -import at.tuwien.api.database.table.columns.ColumnCreateDto; -import at.tuwien.api.database.table.columns.ColumnTypeDto; -import at.tuwien.entities.database.Database; - -public abstract class AbstractSeeder { - - public final static Long CONTAINER_1_ID = 1L; - - public final static Long CONTAINER_2_ID = 2L; - - public final static Long DATABASE_1_ID = 1L; - - public final static Long DATABASE_2_ID = 2L; - - public final static Database DATABASE_1 = Database.builder() - .id(DATABASE_1_ID) - .build(); - - public final static Database DATABASE_2 = Database.builder() - .id(DATABASE_2_ID) - .build(); - - public final static Long TABLE_1_ID = 1L; - public final static String TABLE_1_NAME = "Timetable Zürich"; - public final static String TABLE_1_FALSE_ELEMENT = null; - public final static String TABLE_1_TRUE_ELEMENT = null; - public final static String TABLE_1_NULL_ELEMENT = null; - public final static Character TABLE_1_SEPERATOR = ','; - public final static Long TABLE_1_SKIP_LINES = 1L; - public final static String TABLE_1_DESCRIPTION = "The data table is a variance analysis of the times certain trams and busses should have departed and when they actually departed."; - - public final static Long TABLE_2_ID = 2L; - public final static String TABLE_2_NAME = "Ethernet Temperature"; - public final static String TABLE_2_FALSE_ELEMENT = null; - public final static String TABLE_2_TRUE_ELEMENT = null; - public final static String TABLE_2_NULL_ELEMENT = null; - public final static Character TABLE_2_SEPERATOR = ','; - public final static Long TABLE_2_SKIP_LINES = 1L; - public final static String TABLE_2_DESCRIPTION = "Temperature of the server's Ethernet module in degree Celsius"; - - public final static Long TABLE_3_ID = 3L; - public final static String TABLE_3_NAME = "Vienna Public Transport Delays"; - public final static String TABLE_3_FALSE_ELEMENT = null; - public final static String TABLE_3_TRUE_ELEMENT = null; - public final static String TABLE_3_NULL_ELEMENT = null; - public final static Character TABLE_3_SEPERATOR = ','; - public final static Long TABLE_3_SKIP_LINES = 1L; - public final static String TABLE_3_DESCRIPTION = "Current delays from Vienna public transport gathered via live API"; - - public final static Long IMAGE_DATE_3_ID = 3L; - - public final static TableCreateDto TABLE_1_CREATE_DTO = TableCreateDto.builder() - .name(TABLE_1_NAME) - .description(TABLE_1_DESCRIPTION) - .falseElement(TABLE_1_FALSE_ELEMENT) - .trueElement(TABLE_1_TRUE_ELEMENT) - .nullElement(TABLE_1_NULL_ELEMENT) - .separator(TABLE_1_SEPERATOR) - .skipLines(TABLE_1_SKIP_LINES) - .columns(new ColumnCreateDto[]{ - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("linie") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("richtung") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.DATE) - .name("betriebsdatum") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(IMAGE_DATE_3_ID) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("fahrzeug") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("kurs") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("seq_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_diva_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_punkt_diva_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_kurz_von1") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.DATE) - .name("datum_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(IMAGE_DATE_3_ID) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("soll_an_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("ist_an_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("soll_ab_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("seq_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_diva_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_punkt_diva_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_kurz_nach1") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.DATE) - .name("datum_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(IMAGE_DATE_3_ID) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("soll_an_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("ist_an_nach1") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("soll_ab_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("ist_ab_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("fahrt_id") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("fahrweg_id") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("fw_no") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("fw_typ") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("fw_kurz") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.STRING) - .name("fw_lang") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("umlauf_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_id_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_id_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_punkt_id_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_punkt_id_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build()}) - .build(); - - public final static TableCreateDto TABLE_2_CREATE_DTO = TableCreateDto.builder() - .name(TABLE_2_NAME) - .description(TABLE_2_DESCRIPTION) - .falseElement(TABLE_2_FALSE_ELEMENT) - .trueElement(TABLE_2_TRUE_ELEMENT) - .nullElement(TABLE_2_NULL_ELEMENT) - .separator(TABLE_2_SEPERATOR) - .skipLines(TABLE_2_SKIP_LINES) - .columns(new ColumnCreateDto[]{ - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("temp") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build()}) - .build(); - - public final static TableCreateDto TABLE_3_CREATE_DTO = TableCreateDto.builder() - .name(TABLE_3_NAME) - .description(TABLE_3_DESCRIPTION) - .falseElement(TABLE_3_FALSE_ELEMENT) - .trueElement(TABLE_3_TRUE_ELEMENT) - .nullElement(TABLE_3_NULL_ELEMENT) - .separator(TABLE_3_SEPERATOR) - .skipLines(TABLE_3_SKIP_LINES) - .columns(new ColumnCreateDto[]{ - ColumnCreateDto.builder() - .type(ColumnTypeDto.STRING) - .name("name") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.STRING) - .name("priority") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.STRING) - .name("owner") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.STRING) - .name("title") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.TEXT) - .name("description") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.STRING) - .name("start_time") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.STRING) - .name("end_time") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build()}) - .build(); - -} diff --git a/fda-table-service/services/src/main/java/at/tuwien/seeder/impl/SeederImpl.java b/fda-table-service/services/src/main/java/at/tuwien/seeder/impl/SeederImpl.java deleted file mode 100644 index cc8aade07c..0000000000 --- a/fda-table-service/services/src/main/java/at/tuwien/seeder/impl/SeederImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -package at.tuwien.seeder.impl; - -import at.tuwien.seeder.Seeder; -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.annotation.Profile; -import org.springframework.context.event.EventListener; -import org.springframework.stereotype.Service; - - -@Slf4j -@Profile("seeder") -@Service -public class SeederImpl implements Seeder { - - private final Seeder databaseSeederImpl; - - public SeederImpl(Seeder databaseSeederImpl) { - this.databaseSeederImpl = databaseSeederImpl; - } - - @Override - public void seed() { - databaseSeederImpl.seed(); - } -} diff --git a/fda-table-service/services/src/main/java/at/tuwien/seeder/impl/TableSeederImpl.java b/fda-table-service/services/src/main/java/at/tuwien/seeder/impl/TableSeederImpl.java deleted file mode 100644 index 030168550c..0000000000 --- a/fda-table-service/services/src/main/java/at/tuwien/seeder/impl/TableSeederImpl.java +++ /dev/null @@ -1,50 +0,0 @@ -package at.tuwien.seeder.impl; - -import at.tuwien.entities.database.table.Table; -import at.tuwien.repository.jpa.TableRepository; -import at.tuwien.seeder.Seeder; -import at.tuwien.service.MessageQueueService; -import at.tuwien.service.TableService; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Slf4j -@Service -public class TableSeederImpl extends AbstractSeeder implements Seeder { - - private final TableService tableService; - private final TableRepository tableRepository; - private final MessageQueueService messageQueueService; - - @Autowired - public TableSeederImpl(TableService tableService, TableRepository tableRepository, - MessageQueueService messageQueueService) { - this.tableService = tableService; - this.tableRepository = tableRepository; - this.messageQueueService = messageQueueService; - } - - @SneakyThrows - @Override - public void seed() { - if (tableRepository.findByDatabaseAndId(DATABASE_1, TABLE_1_ID).isPresent()) { - log.warn("Already seeded. Skip."); - return; - } - final Table table1 = tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_CREATE_DTO); - log.info("Seeded table id {}", table1.getId()); - final Table table2 = tableService.createTable(CONTAINER_2_ID, DATABASE_2_ID, TABLE_2_CREATE_DTO); - log.info("Seeded table id {}", table2.getId()); - final Table table3 = tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, TABLE_3_CREATE_DTO); - log.info("Seeded table id {}", table3.getId()); - messageQueueService.create(table1); - log.info("Created message queue for table with id {}", table1.getId()); - messageQueueService.create(table2); - log.info("Created message queue for table with id {}", table2.getId()); - messageQueueService.create(table3); - log.info("Created message queue for table with id {}", table3.getId()); - } - -} -- GitLab