From 3df5332403d04bffdaa3025fada8ced0f158ac79 Mon Sep 17 00:00:00 2001 From: Martin Weise <martin.weise@tuwien.ac.at> Date: Tue, 29 Nov 2022 12:20:50 +0100 Subject: [PATCH] Added not allowed exception, mistook the sequence name --- .../IdentifierServiceIntegrationTest.java | 2 -- .../at/tuwien/entities/database/Database.java | 4 +-- .../tuwien/entities/identifier/Creator.java | 2 +- fda-metadata-db/setup-schema.sql | 26 +++++++++---------- .../at/tuwien/endpoints/TableEndpoint.java | 14 +++++----- .../tuwien/exception/NotAllowedException.java | 21 +++++++++++++++ 6 files changed, 44 insertions(+), 25 deletions(-) create mode 100644 fda-table-service/services/src/main/java/at/tuwien/exception/NotAllowedException.java diff --git a/fda-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java b/fda-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java index 9230ab56f1..0209823173 100644 --- a/fda-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java +++ b/fda-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java @@ -61,7 +61,6 @@ public class IdentifierServiceIntegrationTest extends BaseUnitTest { private ImageRepository imageRepository; @BeforeEach - @Transactional public void beforeEach() { userRepository.save(USER_1); imageRepository.save(IMAGE_1); @@ -77,7 +76,6 @@ public class IdentifierServiceIntegrationTest extends BaseUnitTest { } @Test - @Transactional public void findAll_succeeds() { /* mock */ diff --git a/fda-metadata-db/entities/src/main/java/at/tuwien/entities/database/Database.java b/fda-metadata-db/entities/src/main/java/at/tuwien/entities/database/Database.java index 67cb65cc91..8b3d935c86 100644 --- a/fda-metadata-db/entities/src/main/java/at/tuwien/entities/database/Database.java +++ b/fda-metadata-db/entities/src/main/java/at/tuwien/entities/database/Database.java @@ -39,7 +39,7 @@ public class Database { @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumns({ - @JoinColumn(name = "Creator", referencedColumnName = "UserID") + @JoinColumn(name = "created_by", referencedColumnName = "UserID") }) private User creator; @@ -65,7 +65,7 @@ public class Database { @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumns({ - @JoinColumn(name = "Contactperson", referencedColumnName = "UserID") + @JoinColumn(name = "contact_person", referencedColumnName = "UserID") }) private User contact; diff --git a/fda-metadata-db/entities/src/main/java/at/tuwien/entities/identifier/Creator.java b/fda-metadata-db/entities/src/main/java/at/tuwien/entities/identifier/Creator.java index 95430bcc39..646af21a5c 100644 --- a/fda-metadata-db/entities/src/main/java/at/tuwien/entities/identifier/Creator.java +++ b/fda-metadata-db/entities/src/main/java/at/tuwien/entities/identifier/Creator.java @@ -24,7 +24,7 @@ public class Creator { @Id @EqualsAndHashCode.Include @GeneratedValue(generator = "creators-sequence") - @GenericGenerator(name = "creatos-sequence", strategy = "increment") + @GenericGenerator(name = "creators-sequence", strategy = "increment") @Column(updatable = false, nullable = false) private Long id; diff --git a/fda-metadata-db/setup-schema.sql b/fda-metadata-db/setup-schema.sql index fd90720928..b58d7cde3d 100644 --- a/fda-metadata-db/setup-schema.sql +++ b/fda-metadata-db/setup-schema.sql @@ -143,20 +143,20 @@ CREATE TABLE IF NOT EXISTS mdb_licenses CREATE TABLE IF NOT EXISTS mdb_databases ( - id bigint NOT NULL AUTO_INCREMENT, - name character varying(255) NOT NULL, - internal_name character varying(255) NOT NULL, - exchange character varying(255) NOT NULL, - Description TEXT, - Engine VARCHAR(20), - is_public BOOLEAN NOT NULL DEFAULT TRUE, - Creator BIGINT, - Contactperson BIGINT, - created timestamp NOT NULL DEFAULT NOW(), - last_modified timestamp, + id bigint NOT NULL AUTO_INCREMENT, + name character varying(255) NOT NULL, + internal_name character varying(255) NOT NULL, + exchange character varying(255) NOT NULL, + description TEXT, + engine character varying(20), + is_public BOOLEAN NOT NULL DEFAULT TRUE, + created_by bigint, + contact_person bigint, + created timestamp NOT NULL DEFAULT NOW(), + last_modified timestamp, PRIMARY KEY (id), - FOREIGN KEY (Creator) REFERENCES mdb_users (UserID), - FOREIGN KEY (Contactperson) REFERENCES mdb_users (UserID), + FOREIGN KEY (created_by) REFERENCES mdb_users (UserID), + FOREIGN KEY (contact_person) REFERENCES mdb_users (UserID), FOREIGN KEY (id) REFERENCES mdb_containers (id) /* currently we only support one-to-one */ ); 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 0c4978329a..6b857e1208 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 @@ -11,7 +11,6 @@ import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.extern.log4j.Log4j2; -import org.jacoco.core.internal.flow.IProbeIdGenerator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -20,7 +19,6 @@ import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import javax.validation.constraints.NotNull; -import javax.ws.rs.NotAllowedException; import java.security.Principal; import java.util.List; import java.util.stream.Collectors; @@ -51,7 +49,7 @@ public class TableEndpoint extends AbstractEndpoint { public ResponseEntity<List<TableBriefDto>> list(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable("databaseId") Long databaseId, Principal principal) - throws DatabaseNotFoundException { + throws DatabaseNotFoundException, NotAllowedException { log.debug("endpoint list tables, containerId={}, databaseId={}, principal={}", containerId, databaseId, principal); if (!hasDatabasePermission(containerId, databaseId, "TABLES_VIEW", principal)) { @@ -75,7 +73,8 @@ public class TableEndpoint extends AbstractEndpoint { @NotNull @Valid @RequestBody TableCreateDto createDto, @NotNull Principal principal) throws ImageNotSupportedException, DatabaseNotFoundException, TableMalformedException, AmqpException, - TableNameExistsException, ContainerNotFoundException, UserNotFoundException, QueryMalformedException { + TableNameExistsException, ContainerNotFoundException, UserNotFoundException, QueryMalformedException, + NotAllowedException { log.debug("endpoint create table, containerId={}, databaseId={}, createDto={}, principal={}", containerId, databaseId, createDto, principal); if (!hasDatabasePermission(containerId, databaseId, "TABLE_CREATE", principal)) { @@ -99,7 +98,7 @@ public class TableEndpoint extends AbstractEndpoint { @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("tableId") Long tableId, Principal principal) - throws TableNotFoundException, DatabaseNotFoundException, ContainerNotFoundException { + throws TableNotFoundException, DatabaseNotFoundException, ContainerNotFoundException, NotAllowedException { log.debug("endpoint find table, containerId={}, databaseId={}, tableId={}, principal={}", containerId, databaseId, tableId, principal); if (!hasTablePermission(containerId, databaseId, tableId, "TABLE_INFO", principal)) { @@ -119,7 +118,7 @@ public class TableEndpoint extends AbstractEndpoint { public ResponseEntity<TableBriefDto> update(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("tableId") Long tableId, - @NotNull Principal principal) { + @NotNull Principal principal) throws NotAllowedException { log.debug("endpoint update table, containerId={}, databaseId={}, tableId={}, principal={}", containerId, databaseId, tableId, principal); if (!hasTablePermission(containerId, databaseId, tableId, "TABLE_UPDATE", principal)) { @@ -141,7 +140,8 @@ public class TableEndpoint extends AbstractEndpoint { @NotNull @PathVariable("tableId") Long tableId, @NotNull Principal principal) throws TableNotFoundException, DatabaseNotFoundException, ImageNotSupportedException, - DataProcessingException, ContainerNotFoundException, TableMalformedException, QueryMalformedException { + DataProcessingException, ContainerNotFoundException, TableMalformedException, QueryMalformedException, + NotAllowedException { log.debug("endpoint delete table, containerId={}, databaseId={}, tableId={}, principal={}", containerId, databaseId, tableId, principal); if (!hasTablePermission(containerId, databaseId, tableId, "TABLE_DELETE", principal)) { diff --git a/fda-table-service/services/src/main/java/at/tuwien/exception/NotAllowedException.java b/fda-table-service/services/src/main/java/at/tuwien/exception/NotAllowedException.java new file mode 100644 index 0000000000..44c3d430f9 --- /dev/null +++ b/fda-table-service/services/src/main/java/at/tuwien/exception/NotAllowedException.java @@ -0,0 +1,21 @@ +package at.tuwien.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(code = HttpStatus.METHOD_NOT_ALLOWED) +public class NotAllowedException extends Exception { + + public NotAllowedException(String msg) { + super(msg); + } + + public NotAllowedException(String msg, Throwable thr) { + super(msg, thr); + } + + public NotAllowedException(Throwable thr) { + super(thr); + } + +} -- GitLab