diff --git a/fda-container-service/rest-service/src/main/resources/MDB/createMDB.sql b/fda-container-service/rest-service/src/main/resources/MDB/createMDB.sql index c9deb3d498a7ae7ca2a64f2e2fd69227e27e2908..2b9b714507e6bb243927a38d0cb4283967218194 100644 --- a/fda-container-service/rest-service/src/main/resources/MDB/createMDB.sql +++ b/fda-container-service/rest-service/src/main/resources/MDB/createMDB.sql @@ -3,7 +3,7 @@ CREATE SEQUENCE seq_user; CREATE TYPE gender AS ENUM ('F', 'M', 'T'); CREATE TYPE accesstype AS ENUM ('R', 'W'); -CREATE TABLE md_DATA ( +CREATE TABLE DATA ( ID INTEGER PRIMARY KEY DEFAULT nextval('seq_data'), PROVENANCE TEXT, FileEncoding TEXT, @@ -24,12 +24,12 @@ CREATE TABLE md_USERS ( Main_Email TEXT ); -CREATE TABLE md_CONTACTPERSON ( - cUserID INTEGER PRIMARY KEY REFERENCES md_USERS(UserID), +CREATE TABLE CONTACTPERSON ( + cUserID INTEGER PRIMARY KEY REFERENCES USERS(UserID), Email TEXT ); -CREATE TABLE md_DATABASES ( +CREATE TABLE DATABASES ( DBID TEXT PRIMARY KEY, -- (= DockerContainer ID) Title VARCHAR(50), ResourceType TEXT, @@ -38,11 +38,11 @@ CREATE TABLE md_DATABASES ( Publisher VARCHAR(50), Year DATE DEFAULT CURRENT_DATE, Open BOOLEAN DEFAULT TRUE, - Contact INTEGER REFERENCES md_CONTACTPERSON(cUserID) + Contact INTEGER REFERENCES CONTACTPERSON(cUserID) ); -CREATE TABLE md_TABLES ( - tDBID TEXT REFERENCES md_DATABASES(DBID), +CREATE TABLE TABLES ( + tDBID TEXT REFERENCES DATABASES(DBID), tName VARCHAR(50), NumCols INTEGER, NumRows INTEGER, @@ -50,7 +50,7 @@ CREATE TABLE md_TABLES ( PRIMARY KEY(tDBID,tName) ); -CREATE TABLE md_COLUMNS ( +CREATE TABLE COLUMNS ( cDBID TEXT NOT NULL, tName VARCHAR(50) NOT NULL, cName VARCHAR(50), @@ -105,24 +105,24 @@ CREATE TABLE md_VIEW ( PRIMARY KEY (vDBID,vName) ); -CREATE TABLE md_feed ( +CREATE TABLE feed ( fDBID TEXT, fName VARCHAR(50), - fUserId INTEGER REFERENCES md_USERS(UserID), - fDataID INTEGER REFERENCES md_DATA(ID), - FOREIGN KEY (fDBID,fName) REFERENCES md_TABLES(tDBID,tNAME), + fUserId INTEGER REFERENCES USERS(UserID), + fDataID INTEGER REFERENCES DATA(ID), + FOREIGN KEY (fDBID,fName) REFERENCES TABLES(tDBID,tNAME), PRIMARY KEY (fDBID,fName,fUserId, fDataID) ); -CREATE TABLE md_update ( - uUserID INTEGER REFERENCES md_USERS(UserID), - uDBID TEXT REFERENCES md_DATABASES(DBID), +CREATE TABLE update ( + uUserID INTEGER REFERENCES USERS(UserID), + uDBID TEXT REFERENCES Databases(DBID), PRIMARY KEY (uUserID,uDBID) ); -CREATE TABLE md_access ( - aUserID INTEGER REFERENCES md_USERS(UserID), - aDBID TEXT REFERENCES md_DATABASES(DBID), +CREATE TABLE access ( + aUserID INTEGER REFERENCES USERS(UserID), + aDBID TEXT REFERENCES Databases(DBID), attime TIMESTAMP, download BOOLEAN, PRIMARY KEY (aUserID, aDBID) diff --git a/fda-container-service/rest-service/src/main/resources/application.yml b/fda-container-service/rest-service/src/main/resources/application.yml index 030500c2314b4a13606446ed08172c3f133f2e42..51d825bd7205885714ba0e91240b5ea5549b27da 100644 --- a/fda-container-service/rest-service/src/main/resources/application.yml +++ b/fda-container-service/rest-service/src/main/resources/application.yml @@ -6,7 +6,7 @@ spring: username: postgres password: postgres jpa: - show-sql: true + show-sql: false database-platform: org.hibernate.dialect.PostgreSQLDialect hibernate: ddl-auto: update @@ -15,7 +15,7 @@ spring: name: fda-container-service cloud: loadbalancer.ribbon.enabled: false -server.port: 9091 +server.port: 9093 logging: pattern.console: "%d %highlight(%-5level) %msg%n" level: diff --git a/fda-container-service/rest-service/src/main/resources/config.properties b/fda-container-service/rest-service/src/main/resources/config.properties index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..e993ed9c62272ab86ae23a64f6195f21e465216f 100644 --- a/fda-container-service/rest-service/src/main/resources/config.properties +++ b/fda-container-service/rest-service/src/main/resources/config.properties @@ -0,0 +1 @@ +# https://github.com/Netflix/Hystrix/issues/275 \ No newline at end of file diff --git a/fda-container-service/rest-service/src/test/java/at/tuwien/BaseIntegrationTest.java b/fda-container-service/rest-service/src/test/java/at/tuwien/BaseIntegrationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..bd720bbec7570de1df0735faff8af310060cdf5f --- /dev/null +++ b/fda-container-service/rest-service/src/test/java/at/tuwien/BaseIntegrationTest.java @@ -0,0 +1,95 @@ +package at.tuwien; + +import at.tuwien.entities.container.Container; +import at.tuwien.entities.container.image.ContainerImage; +import at.tuwien.entities.container.image.ContainerImageEnvironmentItem; +import org.springframework.test.context.TestPropertySource; + +import java.time.Instant; +import java.util.List; + +import static java.time.temporal.ChronoUnit.DAYS; +import static java.time.temporal.ChronoUnit.HOURS; + +@TestPropertySource(locations = "classpath:application.properties") +public abstract class BaseIntegrationTest { + + public final String IMAGE_1_REPOSITORY = "postgres"; + public final String IMAGE_1_TAG = "13-alpine"; + public final String IMAGE_1_HASH = "83b40f2726e5"; + public final Integer IMAGE_1_PORT = 5432; + public final Instant IMAGE_1_BUILT = Instant.now().minus(40, HOURS); + public final List<ContainerImageEnvironmentItem> IMAGE_1_ENV = List.of(ContainerImageEnvironmentItem.builder() + .key("POSTGRES_USER") + .value("postgres") + .build(), + ContainerImageEnvironmentItem.builder() + .key("POSTGRES_PASSWORD") + .value("postgres") + .build()); + + public final String IMAGE_2_REPOSITORY = "redis"; + public final String IMAGE_2_TAG = "latest"; + public final String IMAGE_2_HASH = "f877e80bb9ef"; + public final Integer IMAGE_2_PORT = 6379; + public final Instant IMAGE_2_BUILT = Instant.now().minus(9, DAYS); + public final List<ContainerImageEnvironmentItem> IMAGE_2_ENV = List.of(ContainerImageEnvironmentItem.builder() + .key("POSTGRES_USER") + .value("postgres") + .build(), + ContainerImageEnvironmentItem.builder() + .key("POSTGRES_PASSWORD") + .value("postgres") + .build()); + + public final ContainerImage IMAGE_1 = ContainerImage.builder() + .repository(IMAGE_1_REPOSITORY) + .tag(IMAGE_1_TAG) + .hash(IMAGE_1_HASH) + .compiled(IMAGE_1_BUILT) + .environment(IMAGE_1_ENV) + .defaultPort(IMAGE_1_PORT) + .build(); + + public final ContainerImage IMAGE_2 = ContainerImage.builder() + .repository(IMAGE_2_REPOSITORY) + .tag(IMAGE_2_TAG) + .hash(IMAGE_2_HASH) + .compiled(IMAGE_2_BUILT) + .environment(IMAGE_2_ENV) + .defaultPort(IMAGE_2_PORT) + .build(); + + public final Long CONTAINER_1_ID = 1L; + public final String CONTAINER_1_HASH = "deadbeef"; + public final ContainerImage CONTAINER_1_IMAGE = IMAGE_1; + public final String CONTAINER_1_NAME = "u01"; + public final String CONTAINER_1_DATABASE = "univie"; + public final String CONTAINER_1_IP = "231.145.98.83"; + public final Instant CONTAINER_1_CREATED = Instant.now().minus(1, HOURS); + + public final Long CONTAINER_2_ID = 2L; + public final String CONTAINER_2_HASH = "0ff1ce"; + public final ContainerImage CONTAINER_2_IMAGE = IMAGE_2; + public final String CONTAINER_2_NAME = "t01"; + public final String CONTAINER_2_DATABASE = "tuw"; + public final String CONTAINER_2_IP = "233.145.99.83"; + public final Instant CONTAINER_2_CREATED = Instant.now().minus(1, HOURS); + + public final Container CONTAINER_1 = Container.builder() + .id(CONTAINER_1_ID) + .name(CONTAINER_1_NAME) + .image(CONTAINER_1_IMAGE) + .hash(CONTAINER_1_HASH) + .containerCreated(CONTAINER_1_CREATED) + .build(); + + public final Container CONTAINER_2 = Container.builder() + .id(CONTAINER_2_ID) + .name(CONTAINER_2_NAME) + .image(CONTAINER_2_IMAGE) + .hash(CONTAINER_2_HASH) + .containerCreated(CONTAINER_2_CREATED) + .build(); + +} diff --git a/fda-container-service/rest-service/src/test/java/at/tuwien/endpoint/ImageEndpointUnitTest.java b/fda-container-service/rest-service/src/test/java/at/tuwien/endpoint/ImageEndpointUnitTest.java index 6c3a560fd788a263437c13242dc1fa2048f09f5b..08497cbf809594106ba953e339f5c32c508f7aa0 100644 --- a/fda-container-service/rest-service/src/test/java/at/tuwien/endpoint/ImageEndpointUnitTest.java +++ b/fda-container-service/rest-service/src/test/java/at/tuwien/endpoint/ImageEndpointUnitTest.java @@ -63,7 +63,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { } @Test - public void create_succeeds() { + public void create_succeeds() throws ImageNotFoundException { final ImageCreateDto request = ImageCreateDto.builder() .repository(IMAGE_1_REPOSITORY) .tag(IMAGE_1_TAG) @@ -81,7 +81,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { } @Test - public void create_duplicate_fails() { + public void create_duplicate_fails() throws ImageNotFoundException { final ImageCreateDto request = ImageCreateDto.builder() .repository(IMAGE_1_REPOSITORY) .tag(IMAGE_1_TAG) @@ -100,7 +100,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { } @Test - public void create_notExists_fails() { + public void create_notExists_fails() throws ImageNotFoundException { final ImageCreateDto request = ImageCreateDto.builder() .repository(IMAGE_1_REPOSITORY) .tag(IMAGE_1_TAG) @@ -119,7 +119,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { } @Test - public void findById_succeeds() { + public void findById_succeeds() throws ImageNotFoundException { when(imageService.getById(IMAGE_1_ID)) .thenReturn(CONTAINER_1_IMAGE); @@ -130,7 +130,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { } @Test - public void findById_notFound_fails() { + public void findById_notFound_fails() throws ImageNotFoundException { given(imageService.getById(IMAGE_1_ID)) .willAnswer(invocation -> { throw new ImageNotFoundException("not existing in docker hub"); @@ -143,7 +143,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { } @Test - public void delete_fails() { + public void delete_fails() throws ImageNotFoundException { doThrow(new ImageNotFoundException("not found")) .when(imageService) .delete(IMAGE_1_ID); @@ -155,7 +155,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { } @Test - public void update_succeeds() { + public void update_succeeds() throws ImageNotFoundException { final ImageChangeDto request = ImageChangeDto.builder() .defaultPort(1111) .build(); @@ -166,7 +166,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { } @Test - public void update_notFound_fails() { + public void update_notFound_fails() throws ImageNotFoundException { final ImageChangeDto request = ImageChangeDto.builder() .defaultPort(1111) .environment(IMAGE_1_ENV_DTO) diff --git a/fda-container-service/rest-service/src/test/java/at/tuwien/mapper/BaseMappingTest.java b/fda-container-service/rest-service/src/test/java/at/tuwien/mapper/BaseMappingTest.java new file mode 100644 index 0000000000000000000000000000000000000000..058dc455054d2458d9c24004c40afd7eba9033a7 --- /dev/null +++ b/fda-container-service/rest-service/src/test/java/at/tuwien/mapper/BaseMappingTest.java @@ -0,0 +1,52 @@ +package at.tuwien.mapper; + +import com.github.dockerjava.api.command.InspectContainerResponse; +import com.github.dockerjava.api.model.ContainerNetwork; +import com.github.dockerjava.api.model.NetworkSettings; +import lombok.SneakyThrows; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import java.lang.reflect.Field; +import java.util.Map; + +public abstract class BaseMappingTest { + + @Configuration + @ComponentScan(basePackages = {"at.tuwien"}) + public static class BaseMappingContext { + } + + final String CONTAINER_ID = "deadbeef"; + final String CONTAINER_NETWORK_IP = "154.234.88.15"; + + @SneakyThrows + final InspectContainerResponse mockInspectResponse() { + final InspectContainerResponse responseC = new InspectContainerResponse(); + final Object response = responseC.getClass().getConstructor().newInstance(); + final Field idField = responseC.getClass().getDeclaredField("id"); + idField.setAccessible(true); + idField.set(response, CONTAINER_ID); + final Field networkSettingsField = responseC.getClass().getDeclaredField("networkSettings"); + networkSettingsField.setAccessible(true); + + // define the network and address + final ContainerNetwork networkC = new ContainerNetwork(); + final Object network = networkC.getClass().getConstructor().newInstance(); + final Field ipField = networkC.getClass().getDeclaredField("ipAddress"); + ipField.setAccessible(true); + ipField.set(network, CONTAINER_NETWORK_IP); + final Map<String, ContainerNetwork> map = Map.of("fda-userdb", (ContainerNetwork) network); + + // add to network settings + final NetworkSettings settingsC = new NetworkSettings(); + final Object settings = settingsC.getClass().getConstructor().newInstance(); + final Field networksField = settingsC.getClass().getDeclaredField("networks"); + networksField.setAccessible(true); + networksField.set(settings, map); + networkSettingsField.set(response, settings); + + return (InspectContainerResponse) response; + } + +} diff --git a/fda-container-service/rest-service/src/test/java/at/tuwien/mapper/ContainerMappingTest.java b/fda-container-service/rest-service/src/test/java/at/tuwien/mapper/ContainerMappingTest.java new file mode 100644 index 0000000000000000000000000000000000000000..dd10e1e10f266860bdb44ad8742fc921fd5cc294 --- /dev/null +++ b/fda-container-service/rest-service/src/test/java/at/tuwien/mapper/ContainerMappingTest.java @@ -0,0 +1,30 @@ +package at.tuwien.mapper; + +import com.github.dockerjava.api.command.InspectContainerResponse; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit.jupiter.SpringExtension; + + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@ExtendWith(SpringExtension.class) +@SpringBootTest +public class ContainerMappingTest extends BaseMappingTest { + + @Test + public void inspectContainerResponseToDatabaseContainerMappingTest_succeeds() { + final InspectContainerResponse response = mockInspectResponse(); + + assertNotNull(response, "response must not be null"); + assertEquals(CONTAINER_ID, response.getId()); + assertNotNull(response.getNetworkSettings(), "networkSettings must not be null"); + assertNotNull(response.getNetworkSettings().getNetworks(), "networkSettings.networks must not be null"); + assertNotNull(response.getNetworkSettings().getNetworks().get("fda-userdb"), "networkSettings.networks['fda-userdb'] must not be null"); + assertNotNull(response.getNetworkSettings().getNetworks().get("fda-userdb").getIpAddress(), "networkSettings.networks['fda-userdb'].ipAddress must not be null"); + assertEquals(CONTAINER_NETWORK_IP, response.getNetworkSettings().getNetworks().get("fda-userdb").getIpAddress()); + } + +} diff --git a/fda-container-service/rest-service/src/test/java/at/tuwien/service/ContainerServiceIntegrationTest.java b/fda-container-service/rest-service/src/test/java/at/tuwien/service/ContainerServiceIntegrationTest.java index 8c9fe11e2a10c66ea26fe39bf453c95fe834f815..5b3661b45b0dbc0b7825f44ab41e9cea14c909f5 100644 --- a/fda-container-service/rest-service/src/test/java/at/tuwien/service/ContainerServiceIntegrationTest.java +++ b/fda-container-service/rest-service/src/test/java/at/tuwien/service/ContainerServiceIntegrationTest.java @@ -4,10 +4,7 @@ import at.tuwien.BaseUnitTest; import at.tuwien.api.container.ContainerCreateRequestDto; import at.tuwien.api.container.ContainerStateDto; import at.tuwien.entities.container.Container; -import at.tuwien.exception.ContainerNotFoundException; -import at.tuwien.exception.ContainerNotRunningException; -import at.tuwien.exception.ContainerStillRunningException; -import at.tuwien.exception.DockerClientException; +import at.tuwien.exception.*; import at.tuwien.repository.ContainerRepository; import at.tuwien.repository.ImageRepository; import com.github.dockerjava.api.DockerClient; @@ -143,7 +140,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { } @Test - public void getContainerState_succeeds() { + public void getContainerState_succeeds() throws DockerClientException { /* test */ final ContainerStateDto response = containerService.getContainerState(CONTAINER_1_HASH); @@ -162,7 +159,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { } @Test - public void create_succeeds() { + public void create_succeeds() throws DockerClientException, ImageNotFoundException { final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder() .repository(IMAGE_1_REPOSITORY) .tag(IMAGE_1_TAG) @@ -185,7 +182,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { } @Test - public void change_start_succeeds() { + public void change_start_succeeds() throws DockerClientException { dockerClient.stopContainerCmd(CONTAINER_1_HASH).exec(); /* test */ @@ -193,7 +190,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { } @Test - public void change_stop_succeeds() { + public void change_stop_succeeds() throws DockerClientException { /* test */ containerService.stop(CONTAINER_1_ID); @@ -209,7 +206,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { } @Test - public void remove_succeeds() { + public void remove_succeeds() throws DockerClientException { dockerClient.stopContainerCmd(CONTAINER_1_HASH).exec(); /* test */ diff --git a/fda-container-service/rest-service/src/test/java/at/tuwien/service/ImageServiceUnitTest.java b/fda-container-service/rest-service/src/test/java/at/tuwien/service/ImageServiceUnitTest.java index 929d4a4705c2789f59cd2bbd993780f0239390c6..a3f1513cb933b01e5145119d9a03385a2f4db3d8 100644 --- a/fda-container-service/rest-service/src/test/java/at/tuwien/service/ImageServiceUnitTest.java +++ b/fda-container-service/rest-service/src/test/java/at/tuwien/service/ImageServiceUnitTest.java @@ -55,7 +55,7 @@ public class ImageServiceUnitTest extends BaseUnitTest { } @Test - public void getById_succeeds() { + public void getById_succeeds() throws ImageNotFoundException { when(imageRepository.findById(IMAGE_1_ID)) .thenReturn(Optional.of(IMAGE_1)); @@ -77,7 +77,7 @@ public class ImageServiceUnitTest extends BaseUnitTest { } @Test - public void create_notFound_fails() { + public void create_notFound_fails() throws ImageNotFoundException { final ImageCreateDto request = ImageCreateDto.builder() .repository(IMAGE_1_REPOSITORY) .tag(IMAGE_1_TAG) @@ -94,7 +94,7 @@ public class ImageServiceUnitTest extends BaseUnitTest { } @Test - public void create_duplicate_fails() { + public void create_duplicate_fails() throws ImageNotFoundException { final ImageCreateDto request = ImageCreateDto.builder() .repository(IMAGE_1_REPOSITORY) .tag(IMAGE_1_TAG) @@ -111,7 +111,7 @@ public class ImageServiceUnitTest extends BaseUnitTest { } @Test - public void update_succeeds() { + public void update_succeeds() throws ImageNotFoundException { final ImageChangeDto request = ImageChangeDto.builder() .environment(IMAGE_1_ENV_DTO) .defaultPort(IMAGE_1_PORT) @@ -143,7 +143,7 @@ public class ImageServiceUnitTest extends BaseUnitTest { } @Test - public void delete_succeeds() { + public void delete_succeeds() throws ImageNotFoundException { doNothing() .when(imageRepository) .deleteById(IMAGE_1_ID); diff --git a/fda-container-service/services/src/main/java/at/tuwien/exception/DockerClientException.java b/fda-container-service/services/src/main/java/at/tuwien/exception/DockerClientException.java index b51bcff8df18b7fdc033babebff34d2f793d32b3..480f83583992c810e685741e4a684c39632f5c64 100644 --- a/fda-container-service/services/src/main/java/at/tuwien/exception/DockerClientException.java +++ b/fda-container-service/services/src/main/java/at/tuwien/exception/DockerClientException.java @@ -2,17 +2,20 @@ package at.tuwien.exception; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.server.ResponseStatusException; @ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "Docker failed") -public class DockerClientException extends ResponseStatusException { +public class DockerClientException extends Exception { public DockerClientException(String message) { - super(HttpStatus.BAD_REQUEST, message); + super(message); } public DockerClientException(String message, Throwable thr) { - super(HttpStatus.BAD_REQUEST, message, thr); + super(message, thr); + } + + public DockerClientException(Throwable thr) { + super(thr); } } diff --git a/fda-container-service/services/src/main/java/at/tuwien/exception/ImageNotFoundException.java b/fda-container-service/services/src/main/java/at/tuwien/exception/ImageNotFoundException.java index 98c1c30c41d7ef41f4534f2f131cd3da90d7abdd..a93d35f65b74ccdc667a7326e3c9d2f7710d214e 100644 --- a/fda-container-service/services/src/main/java/at/tuwien/exception/ImageNotFoundException.java +++ b/fda-container-service/services/src/main/java/at/tuwien/exception/ImageNotFoundException.java @@ -2,17 +2,20 @@ package at.tuwien.exception; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.server.ResponseStatusException; @ResponseStatus(code = HttpStatus.NOT_FOUND, reason = "Image not found") -public class ImageNotFoundException extends ResponseStatusException { +public class ImageNotFoundException extends Exception { public ImageNotFoundException(String message) { - super(HttpStatus.NOT_FOUND, message); + super(message); } public ImageNotFoundException(String message, Throwable thr) { - super(HttpStatus.NOT_FOUND, message, thr); + super(message, thr); + } + + public ImageNotFoundException(Throwable thr) { + super(thr); } } diff --git a/fda-database-service/.mvn/wrapper/MavenWrapperDownloader.java b/fda-database-service/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000000000000000000000000000000000000..a45eb6ba269cd38f8965cef786729790945d9537 --- /dev/null +++ b/fda-database-service/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,118 @@ +/* + * Copyright 2007-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Properties; + +public class MavenWrapperDownloader { + + private static final String WRAPPER_VERSION = "0.5.6"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if (mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if (mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if (!outputFile.getParentFile().exists()) { + if (!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { + String username = System.getenv("MVNW_USERNAME"); + char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); + Authenticator.setDefault(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + } + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/fda-database-service/.mvn/wrapper/maven-wrapper.jar b/fda-database-service/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..2cc7d4a55c0cd0092912bf49ae38b3a9e3fd0054 Binary files /dev/null and b/fda-database-service/.mvn/wrapper/maven-wrapper.jar differ diff --git a/fda-database-service/.mvn/wrapper/maven-wrapper.properties b/fda-database-service/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000000000000000000000000000000000..642d572ce90e5085986bdd9c9204b9404f028084 --- /dev/null +++ b/fda-database-service/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/fda-database-service/Dockerfile b/fda-database-service/Dockerfile index ac7301c4aa3f6f4592a412fa4109051be3abc36c..ba25367d021413408ff37c8c8d0f2cc81f5923ce 100644 --- a/fda-database-service/Dockerfile +++ b/fda-database-service/Dockerfile @@ -12,7 +12,6 @@ RUN mvn -fn -B dependency:go-offline > /dev/null COPY --from=dependency /root/.m2/repository/at/tuwien /root/.m2/repository/at/tuwien COPY ./rest-service ./rest-service -COPY ./gateway ./gateway COPY ./services ./services COPY ./report ./report diff --git a/fda-database-service/gateway/pom.xml b/fda-database-service/gateway/pom.xml deleted file mode 100644 index 3be01103dced6236342bbd22c91a5bb763957390..0000000000000000000000000000000000000000 --- a/fda-database-service/gateway/pom.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <artifactId>fda-database-service</artifactId> - <groupId>at.tuwien</groupId> - <version>0.0.1-SNAPSHOT</version> - </parent> - - <artifactId>gateway</artifactId> - <version>0.0.1-SNAPSHOT</version> - <name>fda-database-service-gateway</name> - - <dependencies /> - -</project> \ No newline at end of file diff --git a/fda-database-service/gateway/src/main/java/at/tuwien/config/RestClient.java b/fda-database-service/gateway/src/main/java/at/tuwien/config/RestClient.java deleted file mode 100644 index 739762ea072a56573ac62a159623db6dfe4576c5..0000000000000000000000000000000000000000 --- a/fda-database-service/gateway/src/main/java/at/tuwien/config/RestClient.java +++ /dev/null @@ -1,8 +0,0 @@ -package at.tuwien.config; - -import org.springframework.stereotype.Component; -import org.springframework.web.client.RestTemplate; - -@Component -public class RestClient extends RestTemplate { -} diff --git a/fda-database-service/gateway/src/main/java/at/tuwien/endpoint/ContainerGateway.java b/fda-database-service/gateway/src/main/java/at/tuwien/endpoint/ContainerGateway.java deleted file mode 100644 index 9318fcb9238e043a119baf0dd380f0f0fd6e76c2..0000000000000000000000000000000000000000 --- a/fda-database-service/gateway/src/main/java/at/tuwien/endpoint/ContainerGateway.java +++ /dev/null @@ -1,33 +0,0 @@ -package at.tuwien.endpoint; - -import at.tuwien.api.container.ContainerDto; -import at.tuwien.config.RestClient; -import lombok.extern.log4j.Log4j2; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; - -@Log4j2 -@Service -public class ContainerGateway { - - /** @apiNote this url is already in Eureka and NOT docker */ - private static final String URL = "http://fda-container-service/api/container/"; - - private final RestClient restClient; - - @Autowired - public ContainerGateway(RestClient restClient) { - this.restClient = restClient; - } - -// public ContainerDto inspect(Long id) { -// final ResponseEntity<ContainerDto> response; -// response = restClient.exchange(URL + id, HttpMethod.GET, null, new ParameterizedTypeReference<>() { -// }); -// return response.getBody(); -// } - -} diff --git a/fda-database-service/gateway/src/main/java/at/tuwien/exception/ExternalComponentException.java b/fda-database-service/gateway/src/main/java/at/tuwien/exception/ExternalComponentException.java deleted file mode 100644 index 4885715c80690094ef0280db720109f9d6f7f63f..0000000000000000000000000000000000000000 --- a/fda-database-service/gateway/src/main/java/at/tuwien/exception/ExternalComponentException.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_ACCEPTABLE, reason = "external service failed") -public class ExternalComponentException extends Exception { - - public ExternalComponentException(String message) { - super(message); - } - - public ExternalComponentException(String message, Throwable thr) { - super(message, thr); - } - - public ExternalComponentException(Throwable thr) { - super(thr); - } - -} diff --git a/fda-database-service/pom.xml b/fda-database-service/pom.xml index 60c64605b9c5c5693d936d959d724f4371f17f76..71222c18ef3d690d0a976c56e6b6c0bc082ce127 100644 --- a/fda-database-service/pom.xml +++ b/fda-database-service/pom.xml @@ -16,7 +16,6 @@ <packaging>pom</packaging> <modules> - <module>gateway</module> <module>rest-service</module> <module>services</module> <module>report</module> diff --git a/fda-database-service/report/pom.xml b/fda-database-service/report/pom.xml index 082f21829d5d97de495231377e8a761ff239825c..bcaf8880e53e932251f9206897e99ac093edb7a3 100644 --- a/fda-database-service/report/pom.xml +++ b/fda-database-service/report/pom.xml @@ -18,11 +18,6 @@ </properties> <dependencies> - <dependency> - <groupId>at.tuwien</groupId> - <artifactId>gateway</artifactId> - <version>${project.version}</version> - </dependency> <dependency> <groupId>at.tuwien</groupId> <artifactId>rest-service</artifactId> diff --git a/fda-database-service/rest-service/src/main/resources/config.properties b/fda-database-service/rest-service/src/main/resources/config.properties index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..e993ed9c62272ab86ae23a64f6195f21e465216f 100644 --- a/fda-database-service/rest-service/src/main/resources/config.properties +++ b/fda-database-service/rest-service/src/main/resources/config.properties @@ -0,0 +1 @@ +# https://github.com/Netflix/Hystrix/issues/275 \ No newline at end of file diff --git a/fda-database-service/rest-service/src/test/java/at/tuwien/gateway/GatewayUnitTest.java b/fda-database-service/rest-service/src/test/java/at/tuwien/gateway/GatewayUnitTest.java deleted file mode 100644 index 18f112e1e17273163a0ae684e6c4377c5b3c329a..0000000000000000000000000000000000000000 --- a/fda-database-service/rest-service/src/test/java/at/tuwien/gateway/GatewayUnitTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package at.tuwien.gateway; - -import at.tuwien.BaseUnitTest; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@SpringBootTest -@ExtendWith(SpringExtension.class) -public class GatewayUnitTest extends BaseUnitTest { - - - -} diff --git a/fda-database-service/services/pom.xml b/fda-database-service/services/pom.xml index 85345b70bb7c4777e0de724dcccb4cb224a0f986..60cd1750899b6c2e5ab982d425b0de8c47a04a78 100644 --- a/fda-database-service/services/pom.xml +++ b/fda-database-service/services/pom.xml @@ -13,13 +13,6 @@ <version>0.0.1-SNAPSHOT</version> <name>fda-database-service-services</name> - <dependencies> - <dependency> - <groupId>at.tuwien</groupId> - <artifactId>gateway</artifactId> - <version>${project.version}</version> - <scope>compile</scope> - </dependency> - </dependencies> + <dependencies /> </project> \ No newline at end of file diff --git a/fda-database-service/gateway/src/main/java/at/tuwien/exception/ImageNotSupportedException.java b/fda-database-service/services/src/main/java/at/tuwien/exception/ImageNotSupportedException.java similarity index 96% rename from fda-database-service/gateway/src/main/java/at/tuwien/exception/ImageNotSupportedException.java rename to fda-database-service/services/src/main/java/at/tuwien/exception/ImageNotSupportedException.java index f8a9f047e33ffe2268124b37c9c2cd47b0caad63..10cb1b1399a4d44a3889011d48aebd5284459b02 100644 --- a/fda-database-service/gateway/src/main/java/at/tuwien/exception/ImageNotSupportedException.java +++ b/fda-database-service/services/src/main/java/at/tuwien/exception/ImageNotSupportedException.java @@ -3,7 +3,7 @@ package at.tuwien.exception; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; -@ResponseStatus(code = HttpStatus.NOT_ACCEPTABLE, reason = "image is not supported") +@ResponseStatus(code = HttpStatus.NOT_ACCEPTABLE, reason = "image not supported") public class ImageNotSupportedException extends Exception { public ImageNotSupportedException(String message) { diff --git a/fda-discovery-service/mvnw b/fda-discovery-service/mvnw index a16b5431b4c3cab50323a3f558003fd0abd87dad..dea2123dccdfdb51caebcfe8e5964494fdeb2a89 100755 --- a/fda-discovery-service/mvnw +++ b/fda-discovery-service/mvnw @@ -68,7 +68,7 @@ esac if [ -z "$JAVA_HOME" ] ; then if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` + JAVA_HOME=`java-at.tuwien.gateway.config --jre-home` fi fi diff --git a/fda-discovery-service/mvnw.cmd b/fda-discovery-service/mvnw.cmd index c8d43372c986d97911cdc21bd87e0cbe3d83bdda..4a6729c8ab8f9413d3e6956fdef16f3621367758 100644 --- a/fda-discovery-service/mvnw.cmd +++ b/fda-discovery-service/mvnw.cmd @@ -108,10 +108,10 @@ cd "%EXEC_DIR%" :endDetectBaseDir -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.at.tuwien.gateway.config" goto endReadAdditionalConfig @setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.at.tuwien.gateway.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% :endReadAdditionalConfig 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 d30afa25d2cdfe9c2572960a9b5d33a6840c99a9..3815bb4e9997126039934b43f85b9a084b395f40 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 @@ -1,27 +1,31 @@ -package at.tuwien.api.database.query; +package at.tuwien.dto; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import java.sql.Timestamp; + +@Data @Getter @Setter @Builder -@AllArgsConstructor -@NoArgsConstructor public class QueryDto { - private Long id; - private Timestamp executionTimestamp; + private Timestamp execution_timestamp; private String query; - private String queryNormalized; + private String query_normalized; - private String queryHash; + private String query_hash; - private String resultHash; + private String result_hash; - private Integer resultNumber; + private Integer result_number; } diff --git a/fda-metadata-db/entities/src/main/java/at/tuwien/entities/database/table/Table.java b/fda-metadata-db/entities/src/main/java/at/tuwien/entities/database/table/Table.java index b3e796881988ff5c35fb7009de916e4a637c2bac..ea7653f204d7e6bb024b0250d31b36d0940d0679 100644 --- a/fda-metadata-db/entities/src/main/java/at/tuwien/entities/database/table/Table.java +++ b/fda-metadata-db/entities/src/main/java/at/tuwien/entities/database/table/Table.java @@ -9,7 +9,6 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; -import java.io.Serializable; import java.time.Instant; import java.util.List; diff --git a/fda-metadata-db/entities/src/main/java/at/tuwien/entities/database/table/View.java b/fda-metadata-db/entities/src/main/java/at/tuwien/entities/database/table/View.java index 22af798ba3887275aa3a8095676c0e015efd94b1..43a980f91bc6b8b509f48d1c7d521dabb0b2bea3 100644 --- a/fda-metadata-db/entities/src/main/java/at/tuwien/entities/database/table/View.java +++ b/fda-metadata-db/entities/src/main/java/at/tuwien/entities/database/table/View.java @@ -12,7 +12,7 @@ import java.time.Instant; import java.util.List; @Data -//@Entity +@Entity @Builder @AllArgsConstructor @NoArgsConstructor @@ -31,7 +31,7 @@ public class View { strategy = "enhanced-sequence", parameters = @org.hibernate.annotations.Parameter(name = "sequence_name", value = "mdb_view_seq") ) - private Long id; + Long id; @ToString.Include @Column(nullable = false) diff --git a/fda-query-service/Dockerfile b/fda-query-service/Dockerfile index 4bda6ed79adf13fb273885cb15b1a575acedbb0d..1a92864bd9f9ebe3555ac96b1d0fb7b18f238c9d 100644 --- a/fda-query-service/Dockerfile +++ b/fda-query-service/Dockerfile @@ -11,7 +11,6 @@ RUN mvn -fn -B dependency:go-offline > /dev/null COPY --from=dependency /root/.m2/repository/at/tuwien /root/.m2/repository/at/tuwien -COPY ./gateways ./gateways COPY ./rest-service ./rest-service COPY ./services ./services COPY ./report ./report diff --git a/fda-query-service/gateways/pom.xml b/fda-query-service/gateways/pom.xml deleted file mode 100644 index 7aa1a05df6d225152a1e02d4ed78c3debf83ff4c..0000000000000000000000000000000000000000 --- a/fda-query-service/gateways/pom.xml +++ /dev/null @@ -1,15 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <artifactId>fda-query-service</artifactId> - <groupId>at.tuwien</groupId> - <version>0.0.1-SNAPSHOT</version> - </parent> - - <artifactId>gateways</artifactId> - - <dependencies /> -</project> \ No newline at end of file diff --git a/fda-query-service/gateways/src/main/java/at/tuwien/config/GatewaysConfig.java b/fda-query-service/gateways/src/main/java/at/tuwien/config/GatewaysConfig.java deleted file mode 100644 index 2faff328f4fb73bbe1427d7a67de922e83a7bcb0..0000000000000000000000000000000000000000 --- a/fda-query-service/gateways/src/main/java/at/tuwien/config/GatewaysConfig.java +++ /dev/null @@ -1,16 +0,0 @@ -package at.tuwien.config; - -import org.springframework.cloud.client.loadbalancer.LoadBalanced; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.reactive.function.client.WebClient; - -@Configuration -public class GatewaysConfig { - - @Bean - @LoadBalanced - public WebClient.Builder getWebclientBuilder() { - return WebClient.builder(); - } -} diff --git a/fda-query-service/pom.xml b/fda-query-service/pom.xml index f0123c202c2e2283f0dc0152dfc5cb8f36c31764..ace9b93d64516845a55659d20762fd361ed02800 100644 --- a/fda-query-service/pom.xml +++ b/fda-query-service/pom.xml @@ -18,7 +18,6 @@ <modules> <module>rest-service</module> <module>services</module> - <module>gateways</module> <module>report</module> </modules> @@ -157,6 +156,45 @@ <artifactId>javax.ws.rs-api</artifactId> <version>2.1.1</version> </dependency> + + <!-- Swagger --> + <dependency> + <groupId>io.springfox</groupId> + <artifactId>springfox-boot-starter</artifactId> + <version>${springfox.version}</version> + </dependency> + <dependency> + <groupId>io.springfox</groupId> + <artifactId>springfox-swagger-ui</artifactId> + <version>${springfox.version}</version> + </dependency> + <dependency> + <groupId>io.springfox</groupId> + <artifactId>springfox-spring-web</artifactId> + <version>${springfox.version}</version> + </dependency> + <dependency> + <groupId>io.swagger.core.v3</groupId> + <artifactId>swagger-annotations</artifactId> + <version>${swagger.version}</version> + </dependency> + <dependency> + <groupId>io.swagger.core.v3</groupId> + <artifactId>swagger-models</artifactId> + <version>${swagger.version}</version> + </dependency> + <!-- Mapping --> + <dependency> + <groupId>org.mapstruct</groupId> + <artifactId>mapstruct-processor</artifactId> + <version>${mapstruct.version}</version> + <optional>true</optional><!-- IntelliJ --> + </dependency> + <dependency> + <groupId>org.mapstruct</groupId> + <artifactId>mapstruct</artifactId> + <version>${mapstruct.version}</version> + </dependency> </dependencies> <build> diff --git a/fda-query-service/report/pom.xml b/fda-query-service/report/pom.xml index d9af1777c87bd305cc9ac97b2714a3a81beeadf3..1e6fd134c3a5bf33474ba61f08141f4a64ce0df0 100644 --- a/fda-query-service/report/pom.xml +++ b/fda-query-service/report/pom.xml @@ -18,11 +18,6 @@ </description> <dependencies> - <dependency> - <groupId>at.tuwien</groupId> - <artifactId>gateways</artifactId> - <version>${project.version}</version> - </dependency> <dependency> <groupId>at.tuwien</groupId> <artifactId>rest-service</artifactId> diff --git a/fda-query-service/rest-service/pom.xml b/fda-query-service/rest-service/pom.xml index ec77d26b72a6185906965c92e3dfcd81f03a07c3..63041985d7e2ddeba819fe85fe99c28b14e2796c 100644 --- a/fda-query-service/rest-service/pom.xml +++ b/fda-query-service/rest-service/pom.xml @@ -19,6 +19,21 @@ <artifactId>services</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>io.springfox</groupId> + <artifactId>springfox-oas</artifactId> + <version>3.0.0</version> + </dependency> + <dependency> + <groupId>io.springfox</groupId> + <artifactId>springfox-oas</artifactId> + <version>3.0.0</version> + </dependency> + <dependency> + <groupId>io.springfox</groupId> + <artifactId>springfox-oas</artifactId> + <version>3.0.0</version> + </dependency> </dependencies> <build> diff --git a/fda-query-service/rest-service/src/main/java/at/tuwien/endpoint/QueryEndpoint.java b/fda-query-service/rest-service/src/main/java/at/tuwien/endpoint/QueryEndpoint.java index e423c6e3621dea6d3c84f50e1f225d50c22d501b..715f4a413b9c4762546a9d2c06062a4a54962279 100644 --- a/fda-query-service/rest-service/src/main/java/at/tuwien/endpoint/QueryEndpoint.java +++ b/fda-query-service/rest-service/src/main/java/at/tuwien/endpoint/QueryEndpoint.java @@ -1,7 +1,6 @@ package at.tuwien.endpoint; import at.tuwien.api.database.query.ExecuteQueryDto; -import at.tuwien.api.database.query.QueryDto; import at.tuwien.api.database.query.QueryResultDto; import at.tuwien.entities.database.query.Query; import at.tuwien.exception.DatabaseConnectionException; @@ -51,7 +50,7 @@ public class QueryEndpoint { @ApiResponse(code = 400, message = "Problem with reading the stored queries."), @ApiResponse(code = 404, message = "The database does not exist."), }) - public ResponseEntity<List<QueryDto>> findAll(@PathVariable Long id) throws DatabaseNotFoundException, + public ResponseEntity<List<QueryResultDto>> findAll(@PathVariable Long id) throws DatabaseNotFoundException, ImageNotSupportedException, DatabaseConnectionException, QueryMalformedException { final List<Query> queries = queryService.findAll(id); return ResponseEntity.ok(queries.stream() diff --git a/fda-query-service/services/pom.xml b/fda-query-service/services/pom.xml index 55fa4ae41f1303419d87b551ead76c62b3ec06de..6a6395670f5feb08e50b5bf10a700823fdd5be63 100644 --- a/fda-query-service/services/pom.xml +++ b/fda-query-service/services/pom.xml @@ -11,12 +11,6 @@ <artifactId>services</artifactId> - <dependencies> - <dependency> - <groupId>at.tuwien</groupId> - <artifactId>gateways</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> + <dependencies /> </project> \ No newline at end of file diff --git a/fda-query-service/services/src/main/java/at/tuwien/mapper/QueryMapper.java b/fda-query-service/services/src/main/java/at/tuwien/mapper/QueryMapper.java index 1b61d8d164e6d9b9ff5997c3eb565cd86fe2652b..09787ae611ec90d5c9eea8d9a23dac9db8aa3429 100644 --- a/fda-query-service/services/src/main/java/at/tuwien/mapper/QueryMapper.java +++ b/fda-query-service/services/src/main/java/at/tuwien/mapper/QueryMapper.java @@ -1,14 +1,14 @@ package at.tuwien.mapper; import at.tuwien.api.database.query.ExecuteQueryDto; -import at.tuwien.api.database.query.QueryDto; +import at.tuwien.api.database.query.QueryResultDto; import at.tuwien.entities.database.query.Query; import org.mapstruct.Mapper; @Mapper(componentModel = "spring") public interface QueryMapper { - QueryDto queryToQueryDTO(Query query); + QueryResultDto queryToQueryDTO(Query query); Query queryDTOtoQuery(ExecuteQueryDto queryDTO); } diff --git a/fda-table-service/Dockerfile b/fda-table-service/Dockerfile index 7fded984a464599ab047337010a62752c70f9387..b7dbb2dab3179dd440127c5e473f053fc3ed2ecd 100644 --- a/fda-table-service/Dockerfile +++ b/fda-table-service/Dockerfile @@ -11,7 +11,6 @@ RUN mvn -fn -B dependency:go-offline > /dev/null COPY --from=dependency /root/.m2/repository/at/tuwien /root/.m2/repository/at/tuwien -COPY ./gateway ./gateway COPY ./rest-service ./rest-service COPY ./services ./services COPY ./report ./report diff --git a/fda-table-service/gateway/src/main/java/at/tuwien/config/.gitkeep b/fda-table-service/gateway/src/main/java/at/tuwien/config/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/fda-table-service/gateway/pom.xml b/fda-table-service/gateways/pom.xml similarity index 69% rename from fda-table-service/gateway/pom.xml rename to fda-table-service/gateways/pom.xml index c3bb406715a2feb4a048c55c0aa1031522e9de68..53f17e3cd55fa338b26aec36bb262f461724fa46 100644 --- a/fda-table-service/gateway/pom.xml +++ b/fda-table-service/gateways/pom.xml @@ -9,16 +9,22 @@ <version>0.0.1-SNAPSHOT</version> </parent> - <artifactId>gateway</artifactId> + <artifactId>gateways</artifactId> <version>0.0.1-SNAPSHOT</version> - <name>fda-table-service-gateway</name> + <name>fda-table-service-gateways</name> <properties> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> </properties> - <dependencies /> + <dependencies> + <dependency> + <groupId>at.tuwien</groupId> + <artifactId>api</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> </project> \ No newline at end of file diff --git a/fda-table-service/gateways/src/main/java/at/tuwien/client/FdaQueryServiceClient.java b/fda-table-service/gateways/src/main/java/at/tuwien/client/FdaQueryServiceClient.java new file mode 100644 index 0000000000000000000000000000000000000000..c06264c3afa2d0bac0406715519edba699a62246 --- /dev/null +++ b/fda-table-service/gateways/src/main/java/at/tuwien/client/FdaQueryServiceClient.java @@ -0,0 +1,89 @@ +package at.tuwien.client; + +import at.tuwien.dto.CreateTableViaCsvDTO; +import at.tuwien.mapper.ContainerIdAndQueryToExecuteInternalQueryMapper; +import at.tuwien.mapper.CreateTableViaCsvToExecuteStatementMapper; +import at.tuwien.model.CreateCSVTableWithDataset; +import at.tuwien.model.ExecuteInternalQueryDTO; +import at.tuwien.model.ExecuteStatementDTO; +import at.tuwien.model.QueryResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.client.ClientResponse; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +@Component +public class FdaQueryServiceClient { + private static final Logger LOGGER = LoggerFactory.getLogger(FdaQueryServiceClient.class); + + + private WebClient.Builder webClientBuilder; + private CreateTableViaCsvToExecuteStatementMapper mapper; + + @Autowired + public FdaQueryServiceClient(WebClient.Builder webClientBuilder, CreateTableViaCsvToExecuteStatementMapper mapper) { + this.webClientBuilder = webClientBuilder; + this.mapper = mapper; + } + + /** + * @deprecated use Spring RestTempaltes in future releases + */ + public boolean executeStatement(CreateTableViaCsvDTO dto, String statement) { + LOGGER.debug("request fda-query-service for executing statement"); + ExecuteStatementDTO statementDTO = mapper.map(dto, statement); + ClientResponse response = webClientBuilder + .build() + .post() + .uri("http://fda-query-service/query/executeStatement") + .contentType(MediaType.APPLICATION_JSON) + .body(Mono.just(statementDTO), ExecuteStatementDTO.class) + .exchange() + .block(); + + return true; + } + + /** + * @deprecated use Spring RestTempaltes in future releases + */ + public QueryResult executeQuery(String containerID, String query) { + ContainerIdAndQueryToExecuteInternalQueryMapper mapper = new ContainerIdAndQueryToExecuteInternalQueryMapper(); + ExecuteInternalQueryDTO execInternalQueryDTO = mapper.map(containerID, query); + QueryResult queryResult = webClientBuilder + .build() + .post() + .uri("http://fda-query-service/query/executeQuery") + .contentType(MediaType.APPLICATION_JSON) + .body(Mono.just(execInternalQueryDTO), ExecuteInternalQueryDTO.class) + .retrieve() + .bodyToMono(QueryResult.class) + .block(); + + return queryResult; + + } + + /** + * @deprecated use Spring RestTempaltes in future releases + */ + public boolean copyCSVIntoTable(CreateCSVTableWithDataset tableWithDataset) { + ClientResponse response = webClientBuilder + .build() + .post() + .uri("http://fda-query-service/query/copyCSVIntoTable") + .contentType(MediaType.APPLICATION_JSON) + .body(Mono.just(tableWithDataset), CreateCSVTableWithDataset.class) + .exchange() + .block(); + + if(response.statusCode().is2xxSuccessful()){ + return true; + } + return false; + } +} diff --git a/fda-table-service/gateways/src/main/java/at/tuwien/mapper/CreateTableViaCsvToExecuteStatementMapper.java b/fda-table-service/gateways/src/main/java/at/tuwien/mapper/CreateTableViaCsvToExecuteStatementMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..c65a7f525ebc95d44e2efa46a5c9a7f3225fac71 --- /dev/null +++ b/fda-table-service/gateways/src/main/java/at/tuwien/mapper/CreateTableViaCsvToExecuteStatementMapper.java @@ -0,0 +1,16 @@ +package at.tuwien.mapper; + +import at.tuwien.dto.CreateTableViaCsvDTO; +import at.tuwien.model.ExecuteStatementDTO; +import org.springframework.stereotype.Component; + +@Component +public class CreateTableViaCsvToExecuteStatementMapper { + + public ExecuteStatementDTO map(CreateTableViaCsvDTO dto, String statement){ + ExecuteStatementDTO statementDTO = new ExecuteStatementDTO(); + statementDTO.setContainerID(dto.getContainerId()); + statementDTO.setStatement(statement); + return statementDTO; + } +} diff --git a/fda-table-service/pom.xml b/fda-table-service/pom.xml index 1c7ae718b3d28b1b27e5882e1d6f4fdd405b2aeb..12c7034f0fb2b73342f219790b692ca981a6c8ed 100644 --- a/fda-table-service/pom.xml +++ b/fda-table-service/pom.xml @@ -18,7 +18,6 @@ <modules> <module>rest-service</module> <module>services</module> - <module>gateway</module> <module>report</module> </modules> @@ -74,6 +73,17 @@ <scope>runtime</scope> </dependency> <!-- Testing --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + <!-- DataSource --> + <dependency> + <groupId>org.postgresql</groupId> + <artifactId>postgresql</artifactId> + <scope>runtime</scope> + </dependency> + <!-- Testing --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> diff --git a/fda-table-service/report/pom.xml b/fda-table-service/report/pom.xml index db6be6fb5615de5c0d79c6d2a26a5225be76a413..1a217e3cbc197f067ffb62ccf2d8173708540f00 100644 --- a/fda-table-service/report/pom.xml +++ b/fda-table-service/report/pom.xml @@ -18,11 +18,6 @@ </properties> <dependencies> - <dependency> - <groupId>at.tuwien</groupId> - <artifactId>gateway</artifactId> - <version>${project.version}</version> - </dependency> <dependency> <groupId>at.tuwien</groupId> <artifactId>rest-service</artifactId> diff --git a/fda-table-service/services/pom.xml b/fda-table-service/services/pom.xml index 932692ebe84f7639579cb26e94f605a89c6b0faf..36ae4c2139822bfdea2f30f487344e70ab45fcd5 100644 --- a/fda-table-service/services/pom.xml +++ b/fda-table-service/services/pom.xml @@ -14,11 +14,6 @@ <name>fda-table-service-services</name> <dependencies> - <dependency> - <groupId>at.tuwien</groupId> - <artifactId>gateway</artifactId> - <version>${project.version}</version> - </dependency> <dependency> <groupId>net.sf.supercsv</groupId> <artifactId>super-csv</artifactId> diff --git a/fda-table-service/services/src/main/java/at/tuwien/exception/FileStorageException.java b/fda-table-service/services/src/main/java/at/tuwien/exception/FileStorageException.java index dc3ac4c79e6eb6afb40855dc77d77c02dccd673c..c0c1c8588806fc38b0d7947f43b97602c203b1c0 100644 --- a/fda-table-service/services/src/main/java/at/tuwien/exception/FileStorageException.java +++ b/fda-table-service/services/src/main/java/at/tuwien/exception/FileStorageException.java @@ -1,11 +1,8 @@ package at.tuwien.exception; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(code = HttpStatus.UNPROCESSABLE_ENTITY) public class FileStorageException extends RuntimeException { + public FileStorageException(String msg) { super(msg); } diff --git a/fda-ui/pages/db/_db_id/tables/index.vue b/fda-ui/pages/db/_db_id/tables/index.vue index f6d687c77e972a536ec22fc8fa4c64d56621ef8d..492567c52f72ad86e1b6b99ef22b0508243747b3 100644 --- a/fda-ui/pages/db/_db_id/tables/index.vue +++ b/fda-ui/pages/db/_db_id/tables/index.vue @@ -5,13 +5,6 @@ </h3> <TableList /> <TableCreate /> - <v-card class="mt-1"> - <v-card-text> - <nuxt-link class="table_from_csv" :to="`/db/${$route.params.db_id}/tables/table_from_csv`"> - Create table from CSV file - </nuxt-link> - </v-card-text> - </v-card> </div> </template> <script> @@ -34,8 +27,5 @@ export default { } </script> -<style scoped> -a.table_from_csv { - font-size: 14pt; -} +<style> </style>