diff --git a/dbrepo-identifier-service/pom.xml b/dbrepo-identifier-service/pom.xml index 31c7b376851c0fc7fa113c67f8399f078bf2c2a5..3fcb6af1822b9c682753c3fc7affbd0c35ecd7b3 100644 --- a/dbrepo-identifier-service/pom.xml +++ b/dbrepo-identifier-service/pom.xml @@ -26,7 +26,6 @@ <java.version>17</java.version> <spring-cloud.version>4.0.2</spring-cloud.version> <mapstruct.version>1.5.5.Final</mapstruct.version> - <docker.version>3.3.0</docker.version> <jacoco.version>0.8.10</jacoco.version> <jwt.version>4.3.0</jwt.version> <hibernate-c3po.version>5.6.3.Final</hibernate-c3po.version> @@ -35,6 +34,7 @@ <super-csv.version>2.4.0</super-csv.version> <jsql.version>4.6</jsql.version> <springdoc-openapi.version>2.1.0</springdoc-openapi.version> + <hsqldb.version>2.7.2</hsqldb.version> <opensearch-client.version>1.1.0</opensearch-client.version> </properties> @@ -108,19 +108,6 @@ <artifactId>spring-data-opensearch-starter</artifactId> <version>${opensearch-client.version}</version> </dependency> - <!-- Docker --> - <dependency> - <groupId>com.github.docker-java</groupId> - <artifactId>docker-java</artifactId> - <version>${docker.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.github.docker-java</groupId> - <artifactId>docker-java-transport-httpclient5</artifactId> - <version>${docker.version}</version> - <scope>test</scope> - </dependency> <!-- Swagger --> <dependency> <groupId>org.springdoc</groupId> @@ -164,8 +151,9 @@ </exclusions> </dependency> <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> + <groupId>org.hsqldb</groupId> + <artifactId>hsqldb</artifactId> + <version>${hsqldb.version}</version> <scope>test</scope> </dependency> <dependency> diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/IdentifierEndpointUnitTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/IdentifierEndpointUnitTest.java index c98c045e69b9d2e6be6f8a7c855659b7674b039f..4166b8deb01197d3d61b88976ccccbd0b01d9dce 100644 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/IdentifierEndpointUnitTest.java +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/IdentifierEndpointUnitTest.java @@ -152,7 +152,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { final ResponseEntity<?> response = generic_find(null, null); assertEquals(HttpStatus.MOVED_PERMANENTLY, response.getStatusCode()); assertNotNull(response.getHeaders().get("Location")); - assertEquals(endpointConfig.getWebsiteUrl() + "/container/" + IDENTIFIER_1_CONTAINER_ID + "/database/" + assertEquals(endpointConfig.getWebsiteUrl() + "/database/" + IDENTIFIER_1_DATABASE_ID, response.getHeaders().getFirst("Location")); } @@ -162,7 +162,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(AccessDeniedException.class, () -> { - generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, IDENTIFIER_1_DTO_REQUEST, null, null, null, null, null); + generic_create(DATABASE_1_ID, DATABASE_1, null, IDENTIFIER_1_DTO_REQUEST, null, null, null, null, null); }); } @@ -177,7 +177,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { .thenReturn(Optional.of(DATABASE_1_USER_1_READ_ACCESS)); /* test */ - generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_1_READ_ACCESS, IDENTIFIER_1_DTO_REQUEST, IDENTIFIER_1, USER_1_PRINCIPAL, USER_1_ID, USER_1_USERNAME, USER_1); + generic_create(DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_1_READ_ACCESS, IDENTIFIER_1_DTO_REQUEST, IDENTIFIER_1, USER_1_PRINCIPAL, USER_1_ID, USER_1_USERNAME, USER_1); } @Test @@ -186,7 +186,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, IDENTIFIER_1_DTO_REQUEST, IDENTIFIER_1, USER_1_PRINCIPAL, USER_1_ID, USER_1_USERNAME, USER_1); + generic_create(DATABASE_1_ID, DATABASE_1, null, IDENTIFIER_1_DTO_REQUEST, IDENTIFIER_1, USER_1_PRINCIPAL, USER_1_ID, USER_1_USERNAME, USER_1); }); } @@ -196,7 +196,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(AccessDeniedException.class, () -> { - generic_create(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, null, IDENTIFIER_2_DTO_REQUEST, IDENTIFIER_2, null, null, null, null); + generic_create(DATABASE_2_ID, DATABASE_2, null, IDENTIFIER_2_DTO_REQUEST, IDENTIFIER_2, null, null, null, null); }); } @@ -208,7 +208,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { at.tuwien.exception.AccessDeniedException { /* test */ - generic_create(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, DATABASE_2_USER_1_READ_ACCESS, IDENTIFIER_2_DTO_REQUEST, IDENTIFIER_2, USER_2_PRINCIPAL, USER_2_ID, USER_2_USERNAME, USER_2); + generic_create(DATABASE_2_ID, DATABASE_2, DATABASE_2_USER_1_READ_ACCESS, IDENTIFIER_2_DTO_REQUEST, IDENTIFIER_2, USER_2_PRINCIPAL, USER_2_ID, USER_2_USERNAME, USER_2); } @Test @@ -216,7 +216,6 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { public void create_invalidSubset_fails() { final IdentifierCreateDto request = IdentifierCreateDto.builder() .qid(null) // <-- - .cid(IDENTIFIER_1_CONTAINER_ID) .dbid(IDENTIFIER_1_DATABASE_ID) .description(IDENTIFIER_1_DESCRIPTION) .title(IDENTIFIER_1_TITLE) @@ -230,7 +229,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(IdentifierRequestException.class, () -> { - generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_1_READ_ACCESS, request, null, USER_1_PRINCIPAL, USER_1_ID, USER_1_USERNAME, USER_1); + generic_create(DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_1_READ_ACCESS, request, null, USER_1_PRINCIPAL, USER_1_ID, USER_1_USERNAME, USER_1); }); } @@ -239,7 +238,6 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { public void create_invalidDatabase_fails() { final IdentifierCreateDto request = IdentifierCreateDto.builder() .qid(IDENTIFIER_1_QUERY_ID) // <-- - .cid(IDENTIFIER_1_CONTAINER_ID) .dbid(IDENTIFIER_1_DATABASE_ID) .description(IDENTIFIER_1_DESCRIPTION) .title(IDENTIFIER_1_TITLE) @@ -254,7 +252,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(IdentifierRequestException.class, () -> { - generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_1_READ_ACCESS, request, null, USER_1_PRINCIPAL, USER_1_ID, USER_1_USERNAME, USER_1); + generic_create(DATABASE_1_ID, DATABASE_1, DATABASE_1_USER_1_READ_ACCESS, request, null, USER_1_PRINCIPAL, USER_1_ID, USER_1_USERNAME, USER_1); }); } @@ -264,7 +262,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_create(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, null, IDENTIFIER_2_DTO_REQUEST, IDENTIFIER_2, USER_1_PRINCIPAL, USER_1_ID, USER_1_USERNAME, USER_1); + generic_create(DATABASE_2_ID, DATABASE_2, null, IDENTIFIER_2_DTO_REQUEST, IDENTIFIER_2, USER_1_PRINCIPAL, USER_1_ID, USER_1_USERNAME, USER_1); }); } @@ -272,7 +270,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { /* ## GENERIC TEST CASES ## */ /* ################################################################################################### */ - protected void generic_create(Long containerId, Long databaseId, Database database, DatabaseAccess access, + protected void generic_create(Long databaseId, Database database, DatabaseAccess access, IdentifierCreateDto data, Identifier identifier, Principal principal, UUID userId, String username, User user) throws QueryNotFoundException, RemoteUnavailableException, IdentifierAlreadyExistsException, UserNotFoundException, DatabaseNotFoundException, @@ -297,7 +295,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { .when(accessService) .find(databaseId, userId); } - when(queryServiceGateway.find(containerId, databaseId, data, "ABC")) + when(queryServiceGateway.find(databaseId, data, "ABC")) .thenReturn(QUERY_1_DTO); when(identifierService.create(data, principal, "ABC")) .thenReturn(identifier); diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/PersistenceEndpointUnitTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/PersistenceEndpointUnitTest.java index 2f74995d16a86cc042eb909ae75360338adfb287..c67ef9f1bd38ad11f2f2b3ad9791fa534c9525a9 100644 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/PersistenceEndpointUnitTest.java +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/PersistenceEndpointUnitTest.java @@ -105,7 +105,6 @@ public class PersistenceEndpointUnitTest extends BaseUnitTest { assertEquals(compare.getId(), body.getId()); assertEquals(compare.getTitle(), body.getTitle()); assertEquals(compare.getDescription(), body.getDescription()); - assertEquals(compare.getContainerId(), body.getContainerId()); assertEquals(compare.getDatabaseId(), body.getDatabaseId()); assertEquals(compare.getCreated(), body.getCreated()); assertEquals(compare.getLastModified(), body.getLastModified()); @@ -137,7 +136,6 @@ public class PersistenceEndpointUnitTest extends BaseUnitTest { assertEquals(compare.getId(), body.getId()); assertEquals(compare.getTitle(), body.getTitle()); assertEquals(compare.getDescription(), body.getDescription()); - assertEquals(compare.getContainerId(), body.getContainerId()); assertEquals(compare.getDatabaseId(), body.getDatabaseId()); assertEquals(compare.getCreated(), body.getCreated()); assertEquals(compare.getLastModified(), body.getLastModified()); diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/gateway/QueryServiceGatewayUnitTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/gateway/QueryServiceGatewayUnitTest.java index 055cc56e07a32c23bd95a6928c56da046d646dbe..89e45559f89d5889e1405e80bfb1517e64247b15 100644 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/gateway/QueryServiceGatewayUnitTest.java +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/gateway/QueryServiceGatewayUnitTest.java @@ -65,7 +65,7 @@ public class QueryServiceGatewayUnitTest extends BaseUnitTest { .thenReturn(mock); /* test */ - final QueryDto response = queryServiceGateway.find(CONTAINER_1_ID, DATABASE_1_ID, IDENTIFIER_1_DTO_REQUEST, null); + final QueryDto response = queryServiceGateway.find(DATABASE_1_ID, IDENTIFIER_1_DTO_REQUEST, null); assertNotNull(response); assertEquals(QUERY_1_ID, response.getId()); } @@ -81,7 +81,7 @@ public class QueryServiceGatewayUnitTest extends BaseUnitTest { /* test */ assertThrows(QueryNotFoundException.class, () -> { - queryServiceGateway.find(CONTAINER_1_ID, DATABASE_1_ID, IDENTIFIER_1_DTO_REQUEST, null); + queryServiceGateway.find(DATABASE_1_ID, IDENTIFIER_1_DTO_REQUEST, null); }); } @@ -97,7 +97,7 @@ public class QueryServiceGatewayUnitTest extends BaseUnitTest { /* test */ assertThrows(RemoteUnavailableException.class, () -> { - queryServiceGateway.find(CONTAINER_1_ID, DATABASE_1_ID, IDENTIFIER_1_DTO_REQUEST, null); + queryServiceGateway.find(DATABASE_1_ID, IDENTIFIER_1_DTO_REQUEST, null); }); } @@ -112,7 +112,7 @@ public class QueryServiceGatewayUnitTest extends BaseUnitTest { /* test */ assertThrows(RemoteUnavailableException.class, () -> { - queryServiceGateway.find(CONTAINER_1_ID, DATABASE_1_ID, IDENTIFIER_1_DTO_REQUEST, null); + queryServiceGateway.find(DATABASE_1_ID, IDENTIFIER_1_DTO_REQUEST, null); }); } @@ -127,7 +127,7 @@ public class QueryServiceGatewayUnitTest extends BaseUnitTest { .thenReturn(mock); /* test */ - final byte[] response = queryServiceGateway.export(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID); + final byte[] response = queryServiceGateway.export(DATABASE_1_ID, QUERY_1_ID); assertNotNull(response); assertEquals(bytes, response); } @@ -143,7 +143,7 @@ public class QueryServiceGatewayUnitTest extends BaseUnitTest { /* test */ assertThrows(QueryNotFoundException.class, () -> { - queryServiceGateway.export(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID); + queryServiceGateway.export(DATABASE_1_ID, QUERY_1_ID); }); } @@ -158,7 +158,7 @@ public class QueryServiceGatewayUnitTest extends BaseUnitTest { /* test */ assertThrows(RemoteUnavailableException.class, () -> { - queryServiceGateway.export(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID); + queryServiceGateway.export(DATABASE_1_ID, QUERY_1_ID); }); } @@ -172,7 +172,7 @@ public class QueryServiceGatewayUnitTest extends BaseUnitTest { /* test */ assertThrows(RemoteUnavailableException.class, () -> { - queryServiceGateway.export(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID); + queryServiceGateway.export(DATABASE_1_ID, QUERY_1_ID); }); } diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java index 96de2e004f9f9d8810f2fc2dcc6154bdcd7a5a24..c1c1b5fdb657d34687df224d455fbe49c0d1e572 100644 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java @@ -95,7 +95,7 @@ public class IdentifierServiceIntegrationTest extends BaseUnitTest { /* mock */ when(restTemplate.exchange(anyString(), any(HttpMethod.class), any(HttpEntity.class), eq(QueryDto.class))) .thenReturn(ResponseEntity.ok(QUERY_2_DTO)); - when(queryServiceGateway.find(CONTAINER_2_ID, DATABASE_2_ID, IDENTIFIER_2_DTO_REQUEST, bearer)) + when(queryServiceGateway.find(DATABASE_2_ID, IDENTIFIER_2_DTO_REQUEST, bearer)) .thenReturn(QUERY_2_DTO); when(identifierIdxRepository.save(any(IdentifierDto.class))) .thenReturn(IDENTIFIER_2_DTO); @@ -107,7 +107,6 @@ public class IdentifierServiceIntegrationTest extends BaseUnitTest { assertEquals(IDENTIFIER_2_DESCRIPTION, response.getDescription()); assertEquals(IDENTIFIER_2_DOI, response.getDoi()); assertEquals(IDENTIFIER_2_PUBLISHER, response.getPublisher()); - assertEquals(IDENTIFIER_2_CONTAINER_ID, response.getContainerId()); assertEquals(IDENTIFIER_2_DATABASE_ID, response.getDatabaseId()); assertNull(response.getLanguage()); assertEquals(IDENTIFIER_2_PUBLICATION_YEAR, response.getPublicationYear()); diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/application.properties b/dbrepo-identifier-service/rest-service/src/test/resources/application.properties index 938bc30b0f3491387d1455bcba0a733f9487d57d..0338865e530e40e75cbc3adba41ed0973e1ed0a9 100644 --- a/dbrepo-identifier-service/rest-service/src/test/resources/application.properties +++ b/dbrepo-identifier-service/rest-service/src/test/resources/application.properties @@ -8,15 +8,15 @@ spring.cloud.discovery.enabled = false spring.cloud.config.discovery.enabled = false spring.cloud.config.enabled = false -# disable datasource -# spring 6 fix https://github.com/h2database/h2database/issues/3363 -spring.datasource.url=jdbc:h2:mem:testdb;NON_KEYWORDS=VALUE,KEY;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS FDA -spring.datasource.driverClassName=org.h2.Driver -spring.datasource.username=sa -spring.datasource.password=password -spring.jpa.database-platform=org.hibernate.dialect.H2Dialect -spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.show-sql=false +# internal datasource +spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver +spring.datasource.url=jdbc:hsqldb:mem:testdb;db_close_delay=-1;sql.syntax_mys=true +spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect +spring.datasource.username=root +spring.datasource.password=dbrepo +spring.sql.init.mode=always +spring.sql.init.schema-locations=classpath*:init/schema.sql +spring.jpa.hibernate.ddl-auto=create # datacite fda.datacite.url: https://api.test.datacite.org/ diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/init/schema.sql b/dbrepo-identifier-service/rest-service/src/test/resources/init/schema.sql new file mode 100644 index 0000000000000000000000000000000000000000..f8482e47d5b0827e87537d940b54900a8f2d8f3b --- /dev/null +++ b/dbrepo-identifier-service/rest-service/src/test/resources/init/schema.sql @@ -0,0 +1 @@ +CREATE SCHEMA IF NOT EXISTS fda; \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/json/metadata0.json b/dbrepo-identifier-service/rest-service/src/test/resources/json/metadata0.json index d7bb152193d38d9a50d4ab162bbca8a2b23456df..939159fbb9262bf287f8c1b454e4b8ebac7bd974 100644 --- a/dbrepo-identifier-service/rest-service/src/test/resources/json/metadata0.json +++ b/dbrepo-identifier-service/rest-service/src/test/resources/json/metadata0.json @@ -1,6 +1,5 @@ { "id": 4, - "container_id": 4, "database_id": 4, "type": "database", "title": "Sweden weather data", diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/json/metadata1.json b/dbrepo-identifier-service/rest-service/src/test/resources/json/metadata1.json index 347b13ed828b33c4926c680489df7082711746d7..b57274c1566201cd0a81693a50686ba5e08cf812 100644 --- a/dbrepo-identifier-service/rest-service/src/test/resources/json/metadata1.json +++ b/dbrepo-identifier-service/rest-service/src/test/resources/json/metadata1.json @@ -1,6 +1,5 @@ { "id": 1, - "container_id": 1, "database_id": 1, "query_id": 1, "type": "subset", diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/gateway/QueryServiceGateway.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/gateway/QueryServiceGateway.java index a3fb59350f54486837f06509a5483a0b19653019..784b160e236d73036f489c364637c5883e17c964 100644 --- a/dbrepo-identifier-service/services/src/main/java/at/tuwien/gateway/QueryServiceGateway.java +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/gateway/QueryServiceGateway.java @@ -12,7 +12,6 @@ public interface QueryServiceGateway { /** * Finds a query by given id from the query service that internally looks in the query store of a container. * - * @param containerId The container id. * @param databaseId The database id. * @param identifier The identifier containing the query id and database id. * @param authorization The authorization token. @@ -20,19 +19,18 @@ public interface QueryServiceGateway { * @throws QueryNotFoundException The query was not found. * @throws RemoteUnavailableException The remote service is not available. */ - QueryDto find(Long containerId, Long databaseId, IdentifierCreateDto identifier, String authorization) + QueryDto find(Long databaseId, IdentifierCreateDto identifier, String authorization) throws QueryNotFoundException, RemoteUnavailableException; /** * Exports a query by given id. * - * @param containerId The container id. * @param databaseId The database id. * @param queryId The query id. * @return The exported resource as bytes. * @throws RemoteUnavailableException The remote service is not available. * @throws QueryNotFoundException The query was not found. */ - byte[] export(Long containerId, Long databaseId, Long queryId) throws RemoteUnavailableException, + byte[] export(Long databaseId, Long queryId) throws RemoteUnavailableException, QueryNotFoundException; } diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/gateway/impl/QueryServiceGatewayImpl.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/gateway/impl/QueryServiceGatewayImpl.java index 494e6db27d720d46636a08ae868d8fc7cf257d34..73ed7e6c5809b04259bdb72ef8a50a6683d0bb89 100644 --- a/dbrepo-identifier-service/services/src/main/java/at/tuwien/gateway/impl/QueryServiceGatewayImpl.java +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/gateway/impl/QueryServiceGatewayImpl.java @@ -25,29 +25,29 @@ public class QueryServiceGatewayImpl implements QueryServiceGateway { } @Override - public QueryDto find(Long containerId, Long databaseId, IdentifierCreateDto identifier, String authorization) throws QueryNotFoundException, + public QueryDto find(Long databaseId, IdentifierCreateDto identifier, String authorization) throws QueryNotFoundException, RemoteUnavailableException { final HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", authorization); final String url = - "/api/container/" + containerId + "/database/" + databaseId + "/query/" + identifier.getQid(); + "/api/database/" + databaseId + "/query/" + identifier.getQid(); final ResponseEntity<QueryDto> response; try { log.trace("call gateway path {}", url); response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(null, headers), QueryDto.class); } catch (ResourceAccessException | HttpServerErrorException.ServiceUnavailable e) { - log.error("Query service not available for container with id {} and database with id {} for query with id {}, reason {}", - containerId, databaseId, identifier.getQid(), e.getMessage()); + log.error("Query service not available for database with id {} for query with id {}, reason {}", + databaseId, identifier.getQid(), e.getMessage()); throw new RemoteUnavailableException("Query service not available", e); } if (response.getStatusCode().equals(HttpStatus.NOT_FOUND)) { - log.error("Query not found for container with id {} and database with id {} for query with id {}", - containerId, databaseId, identifier.getQid()); + log.error("Query not found for and database with id {} for query with id {}", + databaseId, identifier.getQid()); throw new QueryNotFoundException("Query not found"); } if (response.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) { - log.error("Query not authorized for container with id {} and database with id {} for query with id {}", - containerId, databaseId, identifier.getQid()); + log.error("Query not authorized for and database with id {} for query with id {}", + databaseId, identifier.getQid()); throw new RemoteUnavailableException("Query not authorized"); } log.debug("found query {}", response.getBody()); @@ -55,9 +55,9 @@ public class QueryServiceGatewayImpl implements QueryServiceGateway { } @Override - public byte[] export(Long containerId, Long databaseId, Long queryId) + public byte[] export(Long databaseId, Long queryId) throws RemoteUnavailableException, QueryNotFoundException { - final String url = "/api/container/" + containerId + "/database/" + databaseId + "/query/" + queryId + "/export"; + final String url = "/database/" + databaseId + "/query/" + queryId + "/export"; final HttpHeaders headers = new HttpHeaders(); headers.add("Accept", "text/csv"); final ResponseEntity<byte[]> response; @@ -69,13 +69,13 @@ public class QueryServiceGatewayImpl implements QueryServiceGateway { throw new RemoteUnavailableException("Query service not available", e); } if (response.getStatusCode().equals(HttpStatus.NOT_FOUND)) { - log.error("Query not found for container with id {} and database with id {} for query with id {}", - containerId, databaseId, queryId); + log.error("Query not found for and database with id {} for query with id {}", + databaseId, queryId); throw new QueryNotFoundException("Query not found"); } if (response.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) { - log.error("Query not authorized for container with id {} and database with id {} for query with id {}", - containerId, databaseId, queryId); + log.error("Query not authorized for and database with id {} for query with id {}", + databaseId, queryId); throw new RemoteUnavailableException("Query not authorized"); } log.debug("found query {}", response.getBody()); diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/mapper/IdentifierMapper.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/mapper/IdentifierMapper.java index 74c61a567618e4c4dd1d55e4ab861b7c5d5f5cfa..98a4dd88c4172126837aa4746b4acd1b8b19e145 100644 --- a/dbrepo-identifier-service/services/src/main/java/at/tuwien/mapper/IdentifierMapper.java +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/mapper/IdentifierMapper.java @@ -15,14 +15,12 @@ public interface IdentifierMapper { IdentifierDto identifierToIdentifierDto(Identifier data); @Mappings({ - @Mapping(target = "containerId", source = "cid"), @Mapping(target = "databaseId", source = "dbid"), @Mapping(target = "queryId", source = "qid"), }) Identifier identifierCreateDtoToIdentifier(IdentifierCreateDto data); @Mappings({ - @Mapping(target = "containerId", source = "cid"), @Mapping(target = "databaseId", source = "dbid"), @Mapping(target = "queryId", source = "qid"), }) @@ -44,9 +42,9 @@ public interface IdentifierMapper { default String identifierToLocationUrl(String baseUrl, Identifier data) { if (data.getType().equals(IdentifierType.SUBSET)) { - return baseUrl + "/container/" + data.getContainerId() + "/database/" + data.getDatabaseId() + "/query/" + data.getQueryId(); + return baseUrl + "/database/" + data.getDatabaseId() + "/query/" + data.getQueryId(); } else if (data.getType().equals(IdentifierType.DATABASE)) { - return baseUrl + "/container/" + data.getContainerId() + "/database/" + data.getDatabaseId(); + return baseUrl + "/database/" + data.getDatabaseId(); } else { return null; } diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/repository/mdb/DatabaseRepository.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/repository/mdb/DatabaseRepository.java index dd31029441061583637573fdb016bfd81a111a7f..c11a773abc70ade28fdf7aa45845043fafcdd314 100644 --- a/dbrepo-identifier-service/services/src/main/java/at/tuwien/repository/mdb/DatabaseRepository.java +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/repository/mdb/DatabaseRepository.java @@ -2,17 +2,9 @@ package at.tuwien.repository.mdb; import at.tuwien.entities.database.Database; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; -import java.util.Optional; - @Repository public interface DatabaseRepository extends JpaRepository<Database, Long> { - @Query(value = "select d from Database d where d.container.id = :containerId and d.id = :databaseId") - Optional<Database> findByContainerAndDatabaseId(@Param("containerId") Long containerId, - @Param("databaseId") Long databaseId); - } diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java index 8be744283483a10a2950098a130073f26cc5654c..5311673630efce83027bef6cfe87a4d84c037184 100644 --- a/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java @@ -1,7 +1,10 @@ package at.tuwien.service.impl; import at.tuwien.api.database.query.QueryDto; -import at.tuwien.api.identifier.*; +import at.tuwien.api.identifier.BibliographyTypeDto; +import at.tuwien.api.identifier.IdentifierCreateDto; +import at.tuwien.api.identifier.IdentifierTypeDto; +import at.tuwien.api.identifier.IdentifierUpdateDto; import at.tuwien.config.EndpointConfig; import at.tuwien.entities.database.Database; import at.tuwien.entities.identifier.Creator; @@ -117,7 +120,7 @@ public class IdentifierServiceImpl implements IdentifierService { tmp.setCreators(List.of()); if (data.getType().equals(IdentifierTypeDto.SUBSET)) { log.debug("identifier describes a subset"); - final QueryDto query = queryServiceGateway.find(data.getCid(), data.getDbid(), data, authorization); + final QueryDto query = queryServiceGateway.find(data.getDbid(), data, authorization); tmp.setQuery(query.getQuery()); tmp.setQueryId(query.getId()); tmp.setQueryNormalized(query.getQueryNormalized()); @@ -241,8 +244,7 @@ public class IdentifierServiceImpl implements IdentifierService { throw new IdentifierRequestException("Failed to find identifier"); } /* subset */ - final byte[] file = queryServiceGateway.export(identifier.getContainerId(), - identifier.getDatabaseId(), identifier.getQueryId()); + final byte[] file = queryServiceGateway.export(identifier.getDatabaseId(), identifier.getQueryId()); final InputStreamResource resource = new InputStreamResource(new ByteArrayInputStream(file)); log.trace("found resource {}", resource); return resource;