diff --git a/.jupyter/test.ipynb b/.jupyter/test.ipynb index 28029f957a063336085233d6d7990431eadc7660..d54a0256c97b3bc70c668de24edae06a4a607ed6 100644 --- a/.jupyter/test.ipynb +++ b/.jupyter/test.ipynb @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 99, + "execution_count": 107, "metadata": { "pycharm": { "name": "#%%\n" @@ -64,7 +64,7 @@ }, { "cell_type": "code", - "execution_count": 100, + "execution_count": 108, "metadata": { "pycharm": { "name": "#%%\n" @@ -115,7 +115,7 @@ }, { "cell_type": "code", - "execution_count": 101, + "execution_count": 109, "outputs": [], "source": [ "response = authentication.authenticate_user1({\n", @@ -154,13 +154,13 @@ }, { "cell_type": "code", - "execution_count": 102, + "execution_count": 110, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'created': datetime.datetime(2022, 7, 23, 11, 31, 39, 906000, tzinfo=tzutc()),\n", + "{'created': datetime.datetime(2022, 7, 23, 12, 10, 34, 731000, tzinfo=tzutc()),\n", " 'creator': {'affiliation': None,\n", " 'authorities': None,\n", " 'email': 'someone@example.com',\n", @@ -172,11 +172,11 @@ " 'titles_after': None,\n", " 'titles_before': None,\n", " 'username': 'user'},\n", - " 'hash': 'afa5b9a1ef1d07f09a90f6c76c696974a194376b5d3bae48e3a442056dc30ce2',\n", + " 'hash': 'a7ac6834e9c29d93a0c7049707bbb1350cbd87d9d2836fc4b19dfadc8bbe9724',\n", " 'id': 1,\n", - " 'internal_name': 'fda-userdb-airquality-0468fb50-0a7b-11ed-95b6-4f6e5b6c5022',\n", + " 'internal_name': 'fda-userdb-airquality-741b9886-0a80-11ed-95b6-4f6e5b6c5022',\n", " 'is_public': None,\n", - " 'name': 'Airquality 0468fb50-0a7b-11ed-95b6-4f6e5b6c5022'}\n" + " 'name': 'Airquality 741b9886-0a80-11ed-95b6-4f6e5b6c5022'}\n" ] } ], @@ -210,13 +210,13 @@ }, { "cell_type": "code", - "execution_count": 103, + "execution_count": 111, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'created': datetime.datetime(2022, 7, 23, 11, 31, 39, 906000, tzinfo=tzutc()),\n", + "{'created': datetime.datetime(2022, 7, 23, 12, 10, 34, 731000, tzinfo=tzutc()),\n", " 'creator': {'affiliation': None,\n", " 'authorities': None,\n", " 'email': 'someone@example.com',\n", @@ -228,11 +228,11 @@ " 'titles_after': None,\n", " 'titles_before': None,\n", " 'username': 'user'},\n", - " 'hash': 'afa5b9a1ef1d07f09a90f6c76c696974a194376b5d3bae48e3a442056dc30ce2',\n", + " 'hash': 'a7ac6834e9c29d93a0c7049707bbb1350cbd87d9d2836fc4b19dfadc8bbe9724',\n", " 'id': 1,\n", - " 'internal_name': 'fda-userdb-airquality-0468fb50-0a7b-11ed-95b6-4f6e5b6c5022',\n", + " 'internal_name': 'fda-userdb-airquality-741b9886-0a80-11ed-95b6-4f6e5b6c5022',\n", " 'is_public': None,\n", - " 'name': 'Airquality 0468fb50-0a7b-11ed-95b6-4f6e5b6c5022'}\n" + " 'name': 'Airquality 741b9886-0a80-11ed-95b6-4f6e5b6c5022'}\n" ] } ], @@ -264,13 +264,13 @@ }, { "cell_type": "code", - "execution_count": 104, + "execution_count": 112, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'container': {'created': datetime.datetime(2022, 7, 23, 11, 31, 39, 906000, tzinfo=tzutc()),\n", + "{'container': {'created': datetime.datetime(2022, 7, 23, 12, 10, 34, 731000, tzinfo=tzutc()),\n", " 'creator': {'affiliation': None,\n", " 'authorities': None,\n", " 'email': 'someone@example.com',\n", @@ -282,12 +282,12 @@ " 'titles_after': None,\n", " 'titles_before': None,\n", " 'username': 'user'},\n", - " 'hash': 'afa5b9a1ef1d07f09a90f6c76c696974a194376b5d3bae48e3a442056dc30ce2',\n", + " 'hash': 'a7ac6834e9c29d93a0c7049707bbb1350cbd87d9d2836fc4b19dfadc8bbe9724',\n", " 'id': 1,\n", - " 'internal_name': 'fda-userdb-airquality-0468fb50-0a7b-11ed-95b6-4f6e5b6c5022',\n", + " 'internal_name': 'fda-userdb-airquality-741b9886-0a80-11ed-95b6-4f6e5b6c5022',\n", " 'is_public': None,\n", - " 'name': 'Airquality 0468fb50-0a7b-11ed-95b6-4f6e5b6c5022'},\n", - " 'created': datetime.datetime(2022, 7, 23, 11, 31, 57, 23000, tzinfo=tzutc()),\n", + " 'name': 'Airquality 741b9886-0a80-11ed-95b6-4f6e5b6c5022'},\n", + " 'created': datetime.datetime(2022, 7, 23, 12, 10, 48, 550000, tzinfo=tzutc()),\n", " 'creator': {'affiliation': None,\n", " 'authorities': None,\n", " 'email': 'someone@example.com',\n", @@ -303,7 +303,7 @@ " 'engine': 'mariadb:10.5',\n", " 'id': 1,\n", " 'is_public': True,\n", - " 'name': 'Airquality 0e9a48ae-0a7b-11ed-95b6-4f6e5b6c5022'}\n" + " 'name': 'Airquality 7c5e7aea-0a80-11ed-95b6-4f6e5b6c5022'}\n" ] } ], @@ -337,25 +337,25 @@ }, { "cell_type": "code", - "execution_count": 105, + "execution_count": 113, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'contact': None,\n", - " 'container': {'created': datetime.datetime(2022, 7, 23, 11, 31, 39, 906000, tzinfo=tzutc()),\n", + " 'container': {'created': datetime.datetime(2022, 7, 23, 12, 10, 34, 731000, tzinfo=tzutc()),\n", " 'databases': None,\n", - " 'hash': 'afa5b9a1ef1d07f09a90f6c76c696974a194376b5d3bae48e3a442056dc30ce2',\n", + " 'hash': 'a7ac6834e9c29d93a0c7049707bbb1350cbd87d9d2836fc4b19dfadc8bbe9724',\n", " 'id': 1,\n", " 'image': {'id': 1, 'repository': 'mariadb', 'tag': '10.5'},\n", - " 'internal_name': 'fda-userdb-airquality-0468fb50-0a7b-11ed-95b6-4f6e5b6c5022',\n", + " 'internal_name': 'fda-userdb-airquality-741b9886-0a80-11ed-95b6-4f6e5b6c5022',\n", " 'ip_address': None,\n", " 'is_public': None,\n", - " 'name': 'Airquality 0468fb50-0a7b-11ed-95b6-4f6e5b6c5022',\n", - " 'port': 62344,\n", + " 'name': 'Airquality 741b9886-0a80-11ed-95b6-4f6e5b6c5022',\n", + " 'port': 35981,\n", " 'state': None},\n", - " 'created': datetime.datetime(2022, 7, 23, 11, 31, 57, 23000, tzinfo=tzutc()),\n", + " 'created': datetime.datetime(2022, 7, 23, 12, 10, 48, 550000, tzinfo=tzutc()),\n", " 'creator': {'affiliation': None,\n", " 'authorities': None,\n", " 'containers': None,\n", @@ -372,52 +372,52 @@ " 'username': 'user'},\n", " 'deleted': None,\n", " 'description': 'Hourly measurements in Zürich, Switzerland',\n", - " 'exchange': 'airquality_0e9a48ae-0a7b-11ed-95b6-4f6e5b6c5022',\n", + " 'exchange': 'airquality_7c5e7aea-0a80-11ed-95b6-4f6e5b6c5022',\n", " 'id': 1,\n", " 'image': {'compiled': None,\n", - " 'date_formats': [{'created_at': datetime.datetime(2022, 7, 23, 11, 29, 50, 206000, tzinfo=tzutc()),\n", + " 'date_formats': [{'created_at': datetime.datetime(2022, 7, 23, 12, 8, 54, 186000, tzinfo=tzutc()),\n", " 'database_format': '%Y-%c-%d',\n", " 'example': '2022-01-30',\n", " 'has_time': False,\n", " 'id': 1,\n", " 'unix_format': 'yyyy-MM-dd'},\n", - " {'created_at': datetime.datetime(2022, 7, 23, 11, 29, 50, 215000, tzinfo=tzutc()),\n", + " {'created_at': datetime.datetime(2022, 7, 23, 12, 8, 54, 192000, tzinfo=tzutc()),\n", " 'database_format': '%d.%c.%Y',\n", " 'example': '30.01.2022',\n", " 'has_time': False,\n", " 'id': 2,\n", " 'unix_format': 'yyyy-MM-dd'},\n", - " {'created_at': datetime.datetime(2022, 7, 23, 11, 29, 50, 220000, tzinfo=tzutc()),\n", + " {'created_at': datetime.datetime(2022, 7, 23, 12, 8, 54, 195000, tzinfo=tzutc()),\n", " 'database_format': '%d.%c.%y',\n", " 'example': '30.01.22',\n", " 'has_time': False,\n", " 'id': 3,\n", " 'unix_format': 'yyyy-MM-dd'},\n", - " {'created_at': datetime.datetime(2022, 7, 23, 11, 29, 50, 224000, tzinfo=tzutc()),\n", + " {'created_at': datetime.datetime(2022, 7, 23, 12, 8, 54, 198000, tzinfo=tzutc()),\n", " 'database_format': '%c/%d/%Y',\n", " 'example': '01/30/2022',\n", " 'has_time': False,\n", " 'id': 4,\n", " 'unix_format': 'yyyy-MM-dd'},\n", - " {'created_at': datetime.datetime(2022, 7, 23, 11, 29, 50, 228000, tzinfo=tzutc()),\n", + " {'created_at': datetime.datetime(2022, 7, 23, 12, 8, 54, 201000, tzinfo=tzutc()),\n", " 'database_format': '%c/%d/%y',\n", " 'example': '01/30/22',\n", " 'has_time': False,\n", " 'id': 5,\n", " 'unix_format': 'yyyy-MM-dd'},\n", - " {'created_at': datetime.datetime(2022, 7, 23, 11, 29, 50, 231000, tzinfo=tzutc()),\n", + " {'created_at': datetime.datetime(2022, 7, 23, 12, 8, 54, 203000, tzinfo=tzutc()),\n", " 'database_format': '%Y-%c-%d %H:%i:%S.%f',\n", " 'example': '2022-01-30 13:44:25.0',\n", " 'has_time': True,\n", " 'id': 6,\n", " 'unix_format': 'yyyy-MM-dd HH:mm:ss.SSSSSS'},\n", - " {'created_at': datetime.datetime(2022, 7, 23, 11, 29, 50, 234000, tzinfo=tzutc()),\n", + " {'created_at': datetime.datetime(2022, 7, 23, 12, 8, 54, 205000, tzinfo=tzutc()),\n", " 'database_format': '%Y-%c-%d %H:%i:%S',\n", " 'example': '2022-01-30 13:44:25',\n", " 'has_time': True,\n", " 'id': 7,\n", " 'unix_format': 'yyyy-MM-dd HH:mm:ss'},\n", - " {'created_at': datetime.datetime(2022, 7, 23, 11, 29, 50, 237000, tzinfo=tzutc()),\n", + " {'created_at': datetime.datetime(2022, 7, 23, 12, 8, 54, 208000, tzinfo=tzutc()),\n", " 'database_format': '%d.%c.%Y %H:%i:%S',\n", " 'example': '30.01.2022 13:44:25',\n", " 'has_time': True,\n", @@ -448,11 +448,11 @@ " 'repository': 'mariadb',\n", " 'size': None,\n", " 'tag': '10.5'},\n", - " 'internal_name': 'airquality_0e9a48ae-0a7b-11ed-95b6-4f6e5b6c5022',\n", + " 'internal_name': 'airquality_7c5e7aea-0a80-11ed-95b6-4f6e5b6c5022',\n", " 'is_public': True,\n", " 'language': None,\n", " 'license': None,\n", - " 'name': 'Airquality 0e9a48ae-0a7b-11ed-95b6-4f6e5b6c5022',\n", + " 'name': 'Airquality 7c5e7aea-0a80-11ed-95b6-4f6e5b6c5022',\n", " 'publication': None,\n", " 'publisher': None,\n", " 'subjects': [],\n", @@ -486,13 +486,13 @@ }, { "cell_type": "code", - "execution_count": 106, + "execution_count": 114, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'container': {'created': datetime.datetime(2022, 7, 23, 11, 31, 39, 906000, tzinfo=tzutc()),\n", + "{'container': {'created': datetime.datetime(2022, 7, 23, 12, 10, 34, 731000, tzinfo=tzutc()),\n", " 'creator': {'affiliation': None,\n", " 'authorities': None,\n", " 'email': 'someone@example.com',\n", @@ -504,12 +504,12 @@ " 'titles_after': None,\n", " 'titles_before': None,\n", " 'username': 'user'},\n", - " 'hash': 'afa5b9a1ef1d07f09a90f6c76c696974a194376b5d3bae48e3a442056dc30ce2',\n", + " 'hash': 'a7ac6834e9c29d93a0c7049707bbb1350cbd87d9d2836fc4b19dfadc8bbe9724',\n", " 'id': 1,\n", - " 'internal_name': 'fda-userdb-airquality-0468fb50-0a7b-11ed-95b6-4f6e5b6c5022',\n", + " 'internal_name': 'fda-userdb-airquality-741b9886-0a80-11ed-95b6-4f6e5b6c5022',\n", " 'is_public': None,\n", - " 'name': 'Airquality 0468fb50-0a7b-11ed-95b6-4f6e5b6c5022'},\n", - " 'created': datetime.datetime(2022, 7, 23, 11, 31, 57, 23000, tzinfo=tzutc()),\n", + " 'name': 'Airquality 741b9886-0a80-11ed-95b6-4f6e5b6c5022'},\n", + " 'created': datetime.datetime(2022, 7, 23, 12, 10, 48, 550000, tzinfo=tzutc()),\n", " 'creator': {'affiliation': None,\n", " 'authorities': None,\n", " 'email': 'someone@example.com',\n", @@ -534,7 +534,7 @@ " 'engine': 'mariadb:10.5',\n", " 'id': 1,\n", " 'is_public': True,\n", - " 'name': 'Airquality 0e9a48ae-0a7b-11ed-95b6-4f6e5b6c5022'}\n" + " 'name': 'Airquality 7c5e7aea-0a80-11ed-95b6-4f6e5b6c5022'}\n" ] } ], @@ -573,7 +573,7 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": 115, "outputs": [ { "name": "stdout", @@ -591,8 +591,8 @@ " 'titles_before': None,\n", " 'username': 'user'},\n", " 'id': 1,\n", - " 'internal_name': 'airquality_eaf435b0-0a78-11ed-95b6-4f6e5b6c5022',\n", - " 'name': 'Airquality eaf435b0-0a78-11ed-95b6-4f6e5b6c5022'}\n" + " 'internal_name': 'airquality_8138a716-0a80-11ed-95b6-4f6e5b6c5022',\n", + " 'name': 'Airquality 8138a716-0a80-11ed-95b6-4f6e5b6c5022'}\n" ] } ], @@ -669,7 +669,7 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": 116, "outputs": [ { "name": "stdout", @@ -695,7 +695,7 @@ " 'check_expression': None,\n", " 'column_concept': None,\n", " 'column_type': 'date',\n", - " 'date_format': {'created_at': datetime.datetime(2022, 7, 23, 11, 15, 16, 385000, tzinfo=tzutc()),\n", + " 'date_format': {'created_at': datetime.datetime(2022, 7, 23, 12, 8, 54, 186000, tzinfo=tzutc()),\n", " 'database_format': '%Y-%c-%d',\n", " 'example': '2022-01-30',\n", " 'has_time': False,\n", @@ -808,12 +808,12 @@ " 'name': 'Status',\n", " 'references': None,\n", " 'unique': False}],\n", - " 'created': datetime.datetime(2022, 7, 23, 11, 16, 38, 656000, tzinfo=tzutc()),\n", + " 'created': datetime.datetime(2022, 7, 23, 12, 10, 56, 764000, tzinfo=tzutc()),\n", " 'description': 'Airquality in Zürich, Switzerland',\n", " 'id': 1,\n", - " 'internal_name': 'airquality_eaf435b0-0a78-11ed-95b6-4f6e5b6c5022',\n", - " 'name': 'Airquality eaf435b0-0a78-11ed-95b6-4f6e5b6c5022',\n", - " 'topic': 'airquality_eaf435b0-0a78-11ed-95b6-4f6e5b6c5022'}\n" + " 'internal_name': 'airquality_8138a716-0a80-11ed-95b6-4f6e5b6c5022',\n", + " 'name': 'Airquality 8138a716-0a80-11ed-95b6-4f6e5b6c5022',\n", + " 'topic': 'airquality_8138a716-0a80-11ed-95b6-4f6e5b6c5022'}\n" ] } ], diff --git a/fda-table-service/pom.xml b/fda-table-service/pom.xml index ebb88583cccb95856d981f22cd03f9375895354e..e820284b184cec64a46cdd36ed2575d8966eb668 100644 --- a/fda-table-service/pom.xml +++ b/fda-table-service/pom.xml @@ -75,6 +75,12 @@ <artifactId>fda-metadata-db-api</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>at.tuwien</groupId> + <artifactId>fda-metadata-db-querystore</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-c3p0</artifactId> 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 6f0c1c1aeaa36f2e0af8f6f15434c19159d36b00..b024d9fd57669b3d2c290c4cff564332a887078e 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 @@ -68,7 +68,7 @@ public class TableEndpoint extends AbstractEndpoint { @NotNull @Valid @RequestBody TableCreateDto createDto, Principal principal) throws ImageNotSupportedException, DatabaseNotFoundException, TableMalformedException, AmqpException, - TableNameExistsException, ContainerNotFoundException, UserNotFoundException { + TableNameExistsException, ContainerNotFoundException, UserNotFoundException, DatabaseConnectionException { if (!hasDatabasePermission(containerId, databaseId, "TABLE_CREATE", principal)) { log.error("Missing table create permission"); throw new NotAllowedException("Missing table create permission"); @@ -122,7 +122,7 @@ public class TableEndpoint extends AbstractEndpoint { @NotNull @PathVariable("tableId") Long tableId, Principal principal) throws TableNotFoundException, DatabaseNotFoundException, ImageNotSupportedException, - DataProcessingException, ContainerNotFoundException, TableMalformedException { + DataProcessingException, ContainerNotFoundException, TableMalformedException, DatabaseConnectionException { if (!hasTablePermission(containerId, databaseId, tableId, "TABLE_DELETE", principal)) { log.error("Missing table delete permission"); throw new NotAllowedException("Missing table delete permission"); diff --git a/fda-table-service/rest-service/src/main/resources/mariadb_hibernate.cfg.xml b/fda-table-service/rest-service/src/main/resources/mariadb_hibernate.cfg.xml index 9193ed80caa051c2f993db9124c2cbad1f69a01a..5d1f8bd44e7e2f044e1effb24191f4262d83dd52 100644 --- a/fda-table-service/rest-service/src/main/resources/mariadb_hibernate.cfg.xml +++ b/fda-table-service/rest-service/src/main/resources/mariadb_hibernate.cfg.xml @@ -13,5 +13,8 @@ <property name="show_sql">true</property> <property name="format_sql">true</property> <property name="hbm2ddl.auto">update</property> + <mapping class="at.tuwien.querystore.Query" /> + <mapping class="at.tuwien.querystore.Table" /> + <mapping class="at.tuwien.querystore.Column" /> </session-factory> </hibernate-configuration> diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java deleted file mode 100644 index 4e29142f183988389f2fd1f8210d2bb224dc0455..0000000000000000000000000000000000000000 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java +++ /dev/null @@ -1,787 +0,0 @@ -package at.tuwien; - -import at.tuwien.api.database.table.columns.ColumnCreateDto; -import at.tuwien.api.database.table.columns.ColumnTypeDto; -import at.tuwien.entities.container.Container; -import at.tuwien.entities.container.image.ContainerImage; -import at.tuwien.entities.container.image.ContainerImageDate; -import at.tuwien.entities.container.image.ContainerImageEnvironmentItem; -import at.tuwien.entities.container.image.ContainerImageEnvironmentItemType; -import at.tuwien.entities.database.Database; -import at.tuwien.entities.database.table.Table; -import at.tuwien.entities.database.table.columns.TableColumn; -import at.tuwien.entities.database.table.columns.TableColumnType; -import org.springframework.test.context.TestPropertySource; - -import java.time.Instant; -import java.util.List; - -import static java.time.temporal.ChronoUnit.HOURS; -import static java.time.temporal.ChronoUnit.SECONDS; - -@TestPropertySource(locations = "classpath:application.properties") -public abstract class BaseUnitTest extends CsvUnitTest { - - public final static String USER_1_USERNAME = "junit"; - - public final static Long DATABASE_1_ID = 1L; - public final static String DATABASE_1_NAME = "Weather"; - public final static String DATABASE_1_INTERNALNAME = "weather"; - public final static String DATABASE_1_EXCHANGE = "fda." + DATABASE_1_INTERNALNAME; - public final static Instant DATABASE_1_CREATED = Instant.now().minus(2, SECONDS); - - public final static Long DATABASE_2_ID = 2L; - public final static String DATABASE_2_NAME = "Weather"; - public final static String DATABASE_2_INTERNALNAME = "weather"; - public final static String DATABASE_2_EXCHANGE = "fda." + DATABASE_2_INTERNALNAME; - - public final static Long DATABASE_3_ID = 3L; - public final static String DATABASE_3_NAME = "Traffic"; - public final static String DATABASE_3_INTERNALNAME = "traffic"; - public final static String DATABASE_3_EXCHANGE = "fda." + DATABASE_3_INTERNALNAME; - - public final static Long TABLE_1_ID = 1L; - public final static String TABLE_1_NAME = "Weather AUS"; - public final static String TABLE_1_INTERNALNAME = "weather_aus"; - public final static String TABLE_1_DESCRIPTION = "Weather in the world"; - public final static String TABLE_1_TOPIC = DATABASE_1_EXCHANGE + "." + TABLE_1_INTERNALNAME; - public final static Instant TABLE_1_LAST_MODIFIED = Instant.now(); - public final static Long TABLE_1_SKIP_HEADERS = 1L; - public final static String TABLE_1_NULL_ELEMENT = "NA"; - public final static Character TABLE_1_SEPARATOR = ','; - public final static String TABLE_1_TRUE_ELEMENT = null; - public final static String TABLE_1_FALSE_ELEMENT = null; - - public final static Long TABLE_2_ID = 2L; - public final static String TABLE_2_NAME = "Weather AT"; - public final static String TABLE_2_INTERNALNAME = "weather_at"; - public final static String TABLE_2_DESCRIPTION = "Weather in austria"; - public final static String TABLE_2_TOPIC = DATABASE_2_EXCHANGE + "." + TABLE_2_INTERNALNAME; - public final static Instant TABLE_2_LAST_MODIFIED = Instant.now(); - public final static Long TABLE_2_SKIP_HEADERS = 1L; - public final static String TABLE_2_NULL_ELEMENT = null; - public final static Character TABLE_2_SEPARATOR = ';'; - public final static String TABLE_2_TRUE_ELEMENT = null; - public final static String TABLE_2_FALSE_ELEMENT = null; - - public final static Long TABLE_3_ID = 3L; - public final static String TABLE_3_NAME = "Traffic"; - public final static String TABLE_3_INTERNALNAME = "traffic"; - public final static String TABLE_3_DESCRIPTION = "Traffic in Zürich"; - public final static String TABLE_3_TOPIC = DATABASE_3_EXCHANGE + "." + TABLE_3_INTERNALNAME; - public final static Instant TABLE_3_LAST_MODIFIED = Instant.now(); - public final static Long TABLE_3_SKIP_HEADERS = 1L; - public final static String TABLE_3_NULL_ELEMENT = "NA"; - public final static Character TABLE_3_SEPARATOR = ','; - public final static String TABLE_3_TRUE_ELEMENT = null; - public final static String TABLE_3_FALSE_ELEMENT = null; - - public final static Long COLUMN_1_1_ID = 1L; - public final static Integer COLUMN_1_1_ORDINALPOS = 0; - public final static Boolean COLUMN_1_1_PRIMARY = true; - public final static String COLUMN_1_1_NAME = "id"; - public final static String COLUMN_1_1_INTERNAL_NAME = "id"; - public final static TableColumnType COLUMN_1_1_TYPE = TableColumnType.NUMBER; - public final static ColumnTypeDto COLUMN_1_1_TYPE_DTO = ColumnTypeDto.NUMBER; - public final static Long COLUMN_1_1_DATE_FORMAT = null; - public final static Boolean COLUMN_1_1_NULL = false; - public final static Boolean COLUMN_1_1_UNIQUE = true; - public final static Boolean COLUMN_1_1_AUTO_GENERATED = false; - public final static String COLUMN_1_1_FOREIGN_KEY = null; - public final static String COLUMN_1_1_CHECK = null; - public final static List<String> COLUMN_1_1_ENUM_VALUES = null; - - public final static Long COLUMN_1_2_ID = 2L; - public final static Integer COLUMN_1_2_ORDINALPOS = 1; - public final static Boolean COLUMN_1_2_PRIMARY = false; - public final static String COLUMN_1_2_NAME = "Date"; - public final static String COLUMN_1_2_INTERNAL_NAME = "date"; - public final static TableColumnType COLUMN_1_2_TYPE = TableColumnType.DATE; - public final static ColumnTypeDto COLUMN_1_2_TYPE_DTO = ColumnTypeDto.DATE; - public final static Long COLUMN_1_2_DATE_FORMAT = 1L; - public final static Boolean COLUMN_1_2_NULL = true; - public final static Boolean COLUMN_1_2_UNIQUE = false; - public final static Boolean COLUMN_1_2_AUTO_GENERATED = false; - public final static String COLUMN_1_2_FOREIGN_KEY = null; - public final static String COLUMN_1_2_CHECK = null; - public final static List<String> COLUMN_1_2_ENUM_VALUES = null; - - public final static Long COLUMN_1_3_ID = 3L; - public final static Integer COLUMN_1_3_ORDINALPOS = 2; - public final static Boolean COLUMN_1_3_PRIMARY = false; - public final static String COLUMN_1_3_NAME = "Location"; - public final static String COLUMN_1_3_INTERNAL_NAME = "location"; - public final static TableColumnType COLUMN_1_3_TYPE = TableColumnType.STRING; - public final static ColumnTypeDto COLUMN_1_3_TYPE_DTO = ColumnTypeDto.STRING; - public final static Long COLUMN_1_3_DATE_FORMAT = null; - public final static Boolean COLUMN_1_3_NULL = true; - public final static Boolean COLUMN_1_3_UNIQUE = false; - public final static Boolean COLUMN_1_3_AUTO_GENERATED = false; - public final static String COLUMN_1_3_FOREIGN_KEY = null; - public final static String COLUMN_1_3_CHECK = null; - public final static List<String> COLUMN_1_3_ENUM_VALUES = null; - - public final static Long COLUMN_1_4_ID = 4L; - public final static Integer COLUMN_1_4_ORDINALPOS = 3; - public final static Boolean COLUMN_1_4_PRIMARY = false; - public final static String COLUMN_1_4_NAME = "MinTemp"; - public final static String COLUMN_1_4_INTERNAL_NAME = "mintemp"; - public final static TableColumnType COLUMN_1_4_TYPE = TableColumnType.DECIMAL; - public final static ColumnTypeDto COLUMN_1_4_TYPE_DTO = ColumnTypeDto.DECIMAL; - public final static Long COLUMN_1_4_DATE_FORMAT = null; - public final static Boolean COLUMN_1_4_NULL = true; - public final static Boolean COLUMN_1_4_UNIQUE = false; - public final static Boolean COLUMN_1_4_AUTO_GENERATED = false; - public final static String COLUMN_1_4_FOREIGN_KEY = null; - public final static String COLUMN_1_4_CHECK = null; - public final static List<String> COLUMN_1_4_ENUM_VALUES = null; - - public final static Long COLUMN_1_5_ID = 5L; - public final static Integer COLUMN_1_5_ORDINALPOS = 4; - public final static Boolean COLUMN_1_5_PRIMARY = false; - public final static String COLUMN_1_5_NAME = "Rainfall"; - public final static String COLUMN_1_5_INTERNAL_NAME = "rainfall"; - public final static TableColumnType COLUMN_1_5_TYPE = TableColumnType.DECIMAL; - public final static ColumnTypeDto COLUMN_1_5_TYPE_DTO = ColumnTypeDto.DECIMAL; - public final static Long COLUMN_1_5_DATE_FORMAT = null; - public final static Boolean COLUMN_1_5_NULL = true; - public final static Boolean COLUMN_1_5_UNIQUE = false; - public final static Boolean COLUMN_1_5_AUTO_GENERATED = false; - public final static String COLUMN_1_5_FOREIGN_KEY = null; - public final static String COLUMN_1_5_CHECK = null; - public final static List<String> COLUMN_1_5_ENUM_VALUES = null; - - public final static Long IMAGE_1_ID = 1L; - public final static String IMAGE_1_REPOSITORY = "mariadb"; - public final static String IMAGE_1_TAG = "10.5"; - public final static String IMAGE_1_HASH = "d6a5e003eae42397f7ee4589e9f21e231d3721ac131970d2286bd616e7f55bb4\n"; - public final static String IMAGE_1_DIALECT = "org.hibernate.dialect.MariaDBDialect"; - public final static String IMAGE_1_DRIVER = "org.mariadb.jdbc.Driver"; - public final static String IMAGE_1_JDBC = "mariadb"; - public final static String IMAGE_1_LOGO = "AAAA"; - public final static Integer IMAGE_1_PORT = 3306; - public final static Long IMAGE_1_SIZE = 12000L; - public final static Instant IMAGE_1_BUILT = Instant.now().minus(40, HOURS); - - public final static List<ContainerImageEnvironmentItem> IMAGE_1_ENV = List.of(ContainerImageEnvironmentItem.builder() - .iid(IMAGE_1_ID) - .key("MARIADB_USER") - .value("mariadb") - .type(ContainerImageEnvironmentItemType.USERNAME) - .build(), - ContainerImageEnvironmentItem.builder() - .iid(IMAGE_1_ID) - .key("MARIADB_PASSWORD") - .value("mariadb") - .type(ContainerImageEnvironmentItemType.PASSWORD) - .build(), - ContainerImageEnvironmentItem.builder() - .iid(IMAGE_1_ID) - .key("UZERNAME") - .value("root") - .type(ContainerImageEnvironmentItemType.PRIVILEGED_USERNAME) - .build(), - ContainerImageEnvironmentItem.builder() - .iid(IMAGE_1_ID) - .key("MARIADB_ROOT_PASSWORD") - .value("mariadb") - .type(ContainerImageEnvironmentItemType.PRIVILEGED_PASSWORD) - .build()); - - public final static ContainerImage IMAGE_1 = ContainerImage.builder() - .id(IMAGE_1_ID) - .repository(IMAGE_1_REPOSITORY) - .tag(IMAGE_1_TAG) - .hash(IMAGE_1_HASH) - .compiled(IMAGE_1_BUILT) - .dialect(IMAGE_1_DIALECT) - .jdbcMethod(IMAGE_1_JDBC) - .driverClass(IMAGE_1_DRIVER) - .size(IMAGE_1_SIZE) - .environment(IMAGE_1_ENV) - .defaultPort(IMAGE_1_PORT) - .logo(IMAGE_1_LOGO) - .build(); - - public final static Long CONTAINER_1_ID = 1L; - public final static String CONTAINER_1_HASH = "deadbeef"; - public final static ContainerImage CONTAINER_1_IMAGE = IMAGE_1; - public final static String CONTAINER_1_NAME = "u01"; - public final static String CONTAINER_1_INTERNALNAME = "fda-userdb-u01"; - public final static String CONTAINER_1_IP = "172.28.0.5"; - public final static Instant CONTAINER_1_CREATED = Instant.now().minus(1, HOURS); - - public final static Long CONTAINER_2_ID = 2L; - public final static String CONTAINER_2_HASH = "deadbeef"; - public final static ContainerImage CONTAINER_2_IMAGE = IMAGE_1; - public final static String CONTAINER_2_NAME = "u02"; - public final static String CONTAINER_2_INTERNALNAME = "fda-userdb-u02"; - public final static String CONTAINER_2_IP = "172.28.0.6"; - public final static Instant CONTAINER_2_CREATED = Instant.now().minus(1, HOURS); - - public final static Long CONTAINER_3_ID = 3L; - public final static String CONTAINER_3_HASH = "deadbeef"; - public final static ContainerImage CONTAINER_3_IMAGE = IMAGE_1; - public final static String CONTAINER_3_NAME = "u03"; - public final static String CONTAINER_3_INTERNALNAME = "fda-userdb-u03"; - public final static String CONTAINER_3_IP = "172.28.0.7"; - public final static Instant CONTAINER_3_CREATED = Instant.now().minus(1, HOURS); - - public final static Container CONTAINER_1 = Container.builder() - .id(CONTAINER_1_ID) - .name(CONTAINER_1_NAME) - .internalName(CONTAINER_1_INTERNALNAME) - .image(CONTAINER_1_IMAGE) - .hash(CONTAINER_1_HASH) - .created(CONTAINER_1_CREATED) - .build(); - - public final static Container CONTAINER_2 = Container.builder() - .id(CONTAINER_2_ID) - .name(CONTAINER_2_NAME) - .internalName(CONTAINER_2_INTERNALNAME) - .image(CONTAINER_2_IMAGE) - .hash(CONTAINER_2_HASH) - .created(CONTAINER_2_CREATED) - .build(); - - public final static Container CONTAINER_3 = Container.builder() - .id(CONTAINER_3_ID) - .name(CONTAINER_3_NAME) - .internalName(CONTAINER_3_INTERNALNAME) - .image(CONTAINER_3_IMAGE) - .hash(CONTAINER_3_HASH) - .created(CONTAINER_3_CREATED) - .build(); - - public final static List<TableColumn> TABLE_1_COLUMNS = List.of(TableColumn.builder() - .id(COLUMN_1_1_ID) - .ordinalPosition(COLUMN_1_1_ORDINALPOS) - .cdbid(DATABASE_1_ID) - .tid(TABLE_1_ID) - .name(COLUMN_1_1_NAME) - .internalName(COLUMN_1_1_INTERNAL_NAME) - .columnType(COLUMN_1_1_TYPE) - .dfid(COLUMN_1_1_DATE_FORMAT) - .isNullAllowed(COLUMN_1_1_NULL) - .isUnique(COLUMN_1_1_UNIQUE) - .autoGenerated(COLUMN_1_1_AUTO_GENERATED) - .isPrimaryKey(COLUMN_1_1_PRIMARY) - .enumValues(COLUMN_1_1_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_1_2_ID) - .ordinalPosition(COLUMN_1_2_ORDINALPOS) - .cdbid(DATABASE_1_ID) - .tid(TABLE_1_ID) - .name(COLUMN_1_2_NAME) - .internalName(COLUMN_1_2_INTERNAL_NAME) - .columnType(COLUMN_1_2_TYPE) - .dfid(COLUMN_1_2_DATE_FORMAT) - .isNullAllowed(COLUMN_1_2_NULL) - .isUnique(COLUMN_1_2_UNIQUE) - .autoGenerated(COLUMN_1_2_AUTO_GENERATED) - .isPrimaryKey(COLUMN_1_2_PRIMARY) - .enumValues(COLUMN_1_2_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_1_3_ID) - .ordinalPosition(COLUMN_1_3_ORDINALPOS) - .cdbid(DATABASE_1_ID) - .tid(TABLE_1_ID) - .name(COLUMN_1_3_NAME) - .internalName(COLUMN_1_3_INTERNAL_NAME) - .columnType(COLUMN_1_3_TYPE) - .dfid(COLUMN_1_3_DATE_FORMAT) - .isNullAllowed(COLUMN_1_3_NULL) - .isUnique(COLUMN_1_3_UNIQUE) - .autoGenerated(COLUMN_1_3_AUTO_GENERATED) - .isPrimaryKey(COLUMN_1_3_PRIMARY) - .enumValues(COLUMN_1_3_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_1_4_ID) - .ordinalPosition(COLUMN_1_4_ORDINALPOS) - .cdbid(DATABASE_1_ID) - .tid(TABLE_1_ID) - .name(COLUMN_1_4_NAME) - .internalName(COLUMN_1_4_INTERNAL_NAME) - .columnType(COLUMN_1_4_TYPE) - .dfid(COLUMN_1_4_DATE_FORMAT) - .isNullAllowed(COLUMN_1_4_NULL) - .isUnique(COLUMN_1_4_UNIQUE) - .autoGenerated(COLUMN_1_4_AUTO_GENERATED) - .isPrimaryKey(COLUMN_1_4_PRIMARY) - .enumValues(COLUMN_1_4_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_1_5_ID) - .ordinalPosition(COLUMN_1_5_ORDINALPOS) - .cdbid(DATABASE_1_ID) - .tid(TABLE_1_ID) - .name(COLUMN_1_5_NAME) - .internalName(COLUMN_1_5_INTERNAL_NAME) - .columnType(COLUMN_1_5_TYPE) - .dfid(COLUMN_1_5_DATE_FORMAT) - .isNullAllowed(COLUMN_1_5_NULL) - .isUnique(COLUMN_1_5_UNIQUE) - .autoGenerated(COLUMN_1_5_AUTO_GENERATED) - .isPrimaryKey(COLUMN_1_5_PRIMARY) - .enumValues(COLUMN_1_5_ENUM_VALUES) - .build()); - - public final static Table TABLE_1 = Table.builder() - .id(TABLE_1_ID) - .created(Instant.now()) - .internalName(TABLE_1_INTERNALNAME) - .description(TABLE_1_DESCRIPTION) - .name(TABLE_1_NAME) - .lastModified(TABLE_1_LAST_MODIFIED) - .columns(TABLE_1_COLUMNS) - .tdbid(DATABASE_1_ID) - .topic(TABLE_1_TOPIC) - .build(); - - public final static Table TABLE_2 = Table.builder() - .id(TABLE_2_ID) - .created(Instant.now()) - .internalName(TABLE_2_INTERNALNAME) - .description(TABLE_2_DESCRIPTION) - .name(TABLE_2_NAME) - .lastModified(TABLE_2_LAST_MODIFIED) - .tdbid(DATABASE_2_ID) - .topic(TABLE_2_TOPIC) - .build(); - - public final static Table TABLE_3 = Table.builder() - .id(TABLE_3_ID) - .created(Instant.now()) - .internalName(TABLE_3_INTERNALNAME) - .description(TABLE_3_DESCRIPTION) - .name(TABLE_3_NAME) - .lastModified(TABLE_3_LAST_MODIFIED) - .tdbid(DATABASE_3_ID) - .topic(TABLE_3_TOPIC) - .build(); - - public final static Database DATABASE_1 = Database.builder() - .id(DATABASE_1_ID) - .created(Instant.now().minus(1, HOURS)) - .lastModified(Instant.now()) - .isPublic(false) - .name(DATABASE_1_NAME) - .container(CONTAINER_1) - .tables(List.of(TABLE_1)) - .internalName(DATABASE_1_INTERNALNAME) - .exchange(DATABASE_1_EXCHANGE) - .build(); - - public final static Database DATABASE_2 = Database.builder() - .id(DATABASE_2_ID) - .created(Instant.now().minus(1, HOURS)) - .lastModified(Instant.now()) - .isPublic(false) - .name(DATABASE_2_NAME) - .container(CONTAINER_2) - .tables(List.of(TABLE_2)) - .internalName(DATABASE_2_INTERNALNAME) - .exchange(DATABASE_2_EXCHANGE) - .build(); - - public final static Database DATABASE_3 = Database.builder() - .id(DATABASE_3_ID) - .created(Instant.now().minus(1, HOURS)) - .lastModified(Instant.now()) - .isPublic(false) - .name(DATABASE_3_NAME) - .container(CONTAINER_3) - .tables(List.of(TABLE_3)) - .internalName(DATABASE_3_INTERNALNAME) - .exchange(DATABASE_3_EXCHANGE) - .build(); - - public final static Long IMAGE_DATE_1_ID = 1L; - public final static Long IMAGE_DATE_1_IMAGE_ID = IMAGE_1_ID; - public final static String IMAGE_DATE_1_DATABASE_FORMAT = "%d.%c.%y"; - public final static String IMAGE_DATE_1_UNIX_FORMAT = "dd.mm.yy"; - public final static String IMAGE_DATE_1_EXAMPLE = "30.01.2022"; - - public final static ContainerImageDate IMAGE_DATE_1 = ContainerImageDate.builder() - .id(IMAGE_DATE_1_ID) - .iid(IMAGE_DATE_1_IMAGE_ID) - .databaseFormat(IMAGE_DATE_1_DATABASE_FORMAT) - .unixFormat(IMAGE_DATE_1_UNIX_FORMAT) - .example(IMAGE_DATE_1_EXAMPLE) - .build(); - - public final static ColumnCreateDto[] COLUMNS_CSV01 = new ColumnCreateDto[]{ - ColumnCreateDto.builder() - .type(COLUMN_1_1_TYPE_DTO) - .name(COLUMN_1_1_NAME) - .nullAllowed(COLUMN_1_1_NULL) - .primaryKey(COLUMN_1_1_PRIMARY) - .unique(COLUMN_1_1_UNIQUE) - .build(), - ColumnCreateDto.builder() - .type(COLUMN_1_2_TYPE_DTO) - .name(COLUMN_1_2_NAME) - .nullAllowed(COLUMN_1_2_NULL) - .primaryKey(COLUMN_1_2_PRIMARY) - .unique(COLUMN_1_2_UNIQUE) - .build(), - ColumnCreateDto.builder() - .type(COLUMN_1_3_TYPE_DTO) - .name(COLUMN_1_3_NAME) - .nullAllowed(COLUMN_1_3_NULL) - .primaryKey(COLUMN_1_3_PRIMARY) - .unique(COLUMN_1_3_UNIQUE) - .build(), - ColumnCreateDto.builder() - .type(COLUMN_1_4_TYPE_DTO) - .name(COLUMN_1_4_NAME) - .nullAllowed(COLUMN_1_4_NULL) - .primaryKey(COLUMN_1_4_PRIMARY) - .unique(COLUMN_1_4_UNIQUE) - .build(), - ColumnCreateDto.builder() - .type(COLUMN_1_5_TYPE_DTO) - .name(COLUMN_1_5_NAME) - .nullAllowed(COLUMN_1_5_NULL) - .primaryKey(COLUMN_1_5_PRIMARY) - .unique(COLUMN_1_5_UNIQUE) - .build()}; - - public final static ColumnCreateDto[] COLUMNS_CSV_CH = new ColumnCreateDto[]{ - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("linie") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("richtung") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.DATE) - .name("betriebsdatum") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(IMAGE_DATE_1_ID) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("fahrzeug") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("kurs") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("seq_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_diva_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_punkt_diva_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_kurz_von1") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.DATE) - .name("datum_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(IMAGE_DATE_1_ID) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("soll_an_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("ist_an_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("soll_ab_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("seq_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_diva_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_punkt_diva_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_kurz_nach1") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.DATE) - .name("datum_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(IMAGE_DATE_1_ID) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("soll_an_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("ist_an_nach1") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("soll_ab_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("ist_ab_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("fahrt_id") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("fahrweg_id") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("fw_no") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("fw_typ") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("fw_kurz") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.STRING) - .name("fw_lang") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("umlauf_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_id_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_id_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_punkt_id_von") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("halt_punkt_id_nach") - .nullAllowed(true) - .primaryKey(false) - .unique(false) - .dfid(null) - .checkExpression(null) - .enumValues(null) - .build() - }; - -} diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/CsvUnitTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/CsvUnitTest.java deleted file mode 100644 index 3fc5193115d118dc854ae55a8d8d873067853808..0000000000000000000000000000000000000000 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/CsvUnitTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package at.tuwien; - -import at.tuwien.api.database.table.columns.ColumnCreateDto; -import at.tuwien.api.database.table.columns.ColumnTypeDto; - -public abstract class CsvUnitTest { - - public final static ColumnCreateDto[] COLUMNS_CSV02 = new ColumnCreateDto[]{ - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("id") - .nullAllowed(false) - .primaryKey(true) - .unique(true) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.STRING) - .name("nouniquestr") - .nullAllowed(false) - .primaryKey(false) - .unique(false) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.ENUM) - .name("method") - .nullAllowed(false) - .primaryKey(false) - .unique(false) - .enumValues(new String[] {"mk", "zf", "ac", "em"}) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.STRING) - .name("company") - .nullAllowed(false) - .primaryKey(false) - .unique(false) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("measurements") - .nullAllowed(false) - .primaryKey(false) - .unique(false) - .build(), - ColumnCreateDto.builder() - .type(ColumnTypeDto.NUMBER) - .name("trialn") - .nullAllowed(false) - .primaryKey(false) - .unique(false) - .build(),}; - -} diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/TableEndpointIntegrationTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/TableEndpointIntegrationTest.java deleted file mode 100644 index a0edbf3a1eaf85293c9d21f34b9639164d03c0d5..0000000000000000000000000000000000000000 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/TableEndpointIntegrationTest.java +++ /dev/null @@ -1,136 +0,0 @@ -package at.tuwien.endpoint; - -import at.tuwien.BaseUnitTest; -import at.tuwien.api.database.table.TableBriefDto; -import at.tuwien.api.database.table.TableCreateDto; -import at.tuwien.config.DockerConfig; -import at.tuwien.config.ReadyConfig; -import at.tuwien.endpoints.TableEndpoint; -import at.tuwien.exception.*; -import at.tuwien.repository.jpa.DatabaseRepository; -import at.tuwien.repository.jpa.ImageRepository; -import com.github.dockerjava.api.command.CreateContainerResponse; -import com.github.dockerjava.api.exception.NotModifiedException; -import com.github.dockerjava.api.model.Network; -import com.rabbitmq.client.Channel; -import lombok.extern.slf4j.Slf4j; -import org.apache.http.auth.BasicUserPrincipal; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.transaction.annotation.Transactional; - -import java.security.Principal; -import java.util.Arrays; - -import static at.tuwien.config.DockerConfig.dockerClient; -import static at.tuwien.config.DockerConfig.hostConfig; -import static org.junit.jupiter.api.Assertions.assertEquals; - -@Slf4j -@SpringBootTest -@ExtendWith(SpringExtension.class) -public class TableEndpointIntegrationTest extends BaseUnitTest { - - @MockBean - private Channel channel; - - @MockBean - private ReadyConfig readyConfig; - - @Autowired - private TableEndpoint tableEndpoint; - - @Autowired - private ImageRepository imageRepository; - - @Autowired - private DatabaseRepository databaseRepository; - - @BeforeEach - @Transactional - public void beforeEach() { - afterEach(); - - /* create network */ - dockerClient.createNetworkCmd() - .withName("fda-userdb") - .withIpam(new Network.Ipam() - .withConfig(new Network.Ipam.Config() - .withSubnet("172.28.0.0/16"))) - .withEnableIpv6(false) - .exec(); - - /* create container */ - final CreateContainerResponse response = dockerClient.createContainerCmd(IMAGE_1_REPOSITORY + ":" + IMAGE_1_TAG) - .withHostConfig(hostConfig.withNetworkMode("fda-userdb")) - .withName(CONTAINER_3_INTERNALNAME) - .withIpv4Address(CONTAINER_3_IP) - .withHostName(CONTAINER_3_INTERNALNAME) - .withEnv("MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", - "MARIADB_DATABASE=traffic") - .exec(); - CONTAINER_3.setHash(response.getId()); - - /* repository */ - imageRepository.save(IMAGE_1); - databaseRepository.save(DATABASE_1); - databaseRepository.save(DATABASE_2); - databaseRepository.save(DATABASE_3); - } - - @AfterEach - public void afterEach() { - /* stop containers and remove them */ - dockerClient.listContainersCmd() - .withShowAll(true) - .exec() - .forEach(container -> { - log.info("Delete container {}", Arrays.asList(container.getNames())); - try { - dockerClient.stopContainerCmd(container.getId()).exec(); - } catch (NotModifiedException e) { - // ignore - } - dockerClient.removeContainerCmd(container.getId()).exec(); - }); - /* remove networks */ - dockerClient.listNetworksCmd() - .exec() - .stream() - .filter(n -> n.getName().startsWith("fda")) - .forEach(network -> { - log.info("Delete network {}", network.getName()); - dockerClient.removeNetworkCmd(network.getId()).exec(); - }); - } - - @Test - public void create_succeeds() throws DatabaseNotFoundException, ImageNotSupportedException, - TableMalformedException, AmqpException, TableNameExistsException, InterruptedException, - ContainerNotFoundException, - UserNotFoundException { - final TableCreateDto request = TableCreateDto.builder() - .name(TABLE_3_NAME) - .description(TABLE_3_DESCRIPTION) - .columns(COLUMNS_CSV_CH) - .build(); - final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); - - /* mock */ - DockerConfig.startContainer(CONTAINER_3); - - /* test */ - final ResponseEntity<TableBriefDto> response = tableEndpoint.create(CONTAINER_3_ID, DATABASE_3_ID, request, - principal); - assertEquals(HttpStatus.CREATED, response.getStatusCode()); - } - -} diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/TableEndpointUnitTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/TableEndpointUnitTest.java deleted file mode 100644 index 5ae25874f2fbb9c171b63cc1ffedc2f4cd217c0f..0000000000000000000000000000000000000000 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/endpoint/TableEndpointUnitTest.java +++ /dev/null @@ -1,186 +0,0 @@ -package at.tuwien.endpoint; - -import at.tuwien.BaseUnitTest; -import at.tuwien.api.database.table.TableBriefDto; -import at.tuwien.api.database.table.TableCreateDto; -import at.tuwien.api.database.table.TableDto; -import at.tuwien.config.ReadyConfig; -import at.tuwien.endpoints.TableEndpoint; -import at.tuwien.exception.*; -import at.tuwien.repository.jpa.DatabaseRepository; -import at.tuwien.repository.jpa.TableRepository; -import at.tuwien.service.MessageQueueService; -import at.tuwien.service.impl.TableServiceImpl; -import com.rabbitmq.client.Channel; -import org.apache.http.auth.BasicUserPrincipal; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.io.IOException; -import java.security.Principal; -import java.util.List; -import java.util.Objects; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.*; - -@SpringBootTest -@ExtendWith(SpringExtension.class) -public class TableEndpointUnitTest extends BaseUnitTest { - - @MockBean - private Channel channel; - - @MockBean - private ReadyConfig readyConfig; - - @MockBean - private TableServiceImpl tableService; - - @MockBean - private TableRepository tableRepository; - - @MockBean - private DatabaseRepository databaseRepository; - - @MockBean - private MessageQueueService messageQueueService; - - @Autowired - private TableEndpoint tableEndpoint; - -// @Test -// public void findAll_succeeds() throws DatabaseNotFoundException { -// -// /* mock */ -// when(tableRepository.findByDatabase(DATABASE_1)) -// .thenReturn(List.of(TABLE_1)); -// when(tableService.findAll(CONTAINER_1_ID, DATABASE_1_ID)) -// .thenReturn(List.of(TABLE_1)); -// -// /* test */ -// final ResponseEntity<List<TableBriefDto>> response = tableEndpoint.findAll(CONTAINER_1_ID, DATABASE_1_ID); -// assertEquals(HttpStatus.OK, response.getStatusCode()); -// assertEquals(1, Objects.requireNonNull(response.getBody()).size()); -// } -// -// @Test -// public void create_succeeds() throws DatabaseNotFoundException, ImageNotSupportedException, -// TableNotFoundException, TableMalformedException, AmqpException, TableNameExistsException, -// ContainerNotFoundException, UserNotFoundException { -// final TableCreateDto request = TableCreateDto.builder() -// .name(TABLE_1_NAME) -// .description(TABLE_1_DESCRIPTION) -// .columns(COLUMNS_CSV01) -// .build(); -// final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); -// -// /* mock */ -// when(tableRepository.findById(TABLE_1_ID)) -// .thenReturn(Optional.of(TABLE_1)); -// when(tableService.findById(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID)) -// .thenReturn(TABLE_1); -// doNothing() -// .when(messageQueueService) -// .create(TABLE_1); -// -// /* test */ -// final ResponseEntity<TableBriefDto> response = tableEndpoint.create(CONTAINER_1_ID, DATABASE_1_ID, request, -// principal); -// assertEquals(HttpStatus.CREATED, response.getStatusCode()); -// } -// -// @Test -// public void create_databaseNotFound_fails() throws DatabaseNotFoundException, ImageNotSupportedException, -// TableMalformedException, TableNameExistsException, ContainerNotFoundException, UserNotFoundException { -// final TableCreateDto request = TableCreateDto.builder() -// .name(TABLE_1_NAME) -// .description(TABLE_1_DESCRIPTION) -// .columns(COLUMNS_CSV01) -// .build(); -// final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); -// -// /* mock */ -// when(tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, request, principal)) -// .thenAnswer(invocation -> { -// throw new DatabaseNotFoundException("no db"); -// }); -// -// /* test */ -// assertThrows(DatabaseNotFoundException.class, () -> { -// tableEndpoint.create(CONTAINER_1_ID, DATABASE_1_ID, request, principal); -// }); -// } -// -// @Test -// public void findById_succeeds() throws TableNotFoundException, DatabaseNotFoundException, -// ContainerNotFoundException { -// -// /* mock */ -// when(tableService.findById(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID)) -// .thenReturn(TABLE_1); -// -// /* test */ -// final ResponseEntity<TableDto> response = tableEndpoint.findById(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); -// assertEquals(HttpStatus.OK, response.getStatusCode()); -// assertEquals(TABLE_1_ID, Objects.requireNonNull(response.getBody()).getId()); -// assertEquals(TABLE_1_NAME, Objects.requireNonNull(response.getBody()).getName()); -// } -// -// @Test -// public void findById_notFound_fails() throws TableNotFoundException, DatabaseNotFoundException, -// ContainerNotFoundException { -// -// /* mock */ -// when(tableRepository.findById(TABLE_1_ID)) -// .thenReturn(Optional.empty()); -// doThrow(TableNotFoundException.class) -// .when(tableService) -// .findById(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); -// -// /* test */ -// assertThrows(TableNotFoundException.class, () -> { -// tableEndpoint.findById(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); -// }); -// } -// -// @Test -// public void delete_notFound_fails() throws TableNotFoundException, DatabaseNotFoundException, -// ImageNotSupportedException, ContainerNotFoundException { -// -// /* mock */ -// doThrow(TableNotFoundException.class) -// .when(tableService) -// .deleteTable(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); -// -// /* test */ -// assertThrows(TableNotFoundException.class, () -> { -// tableEndpoint.delete(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); -// }); -// } -// -// @Test -// public void delete_succeeds() throws TableNotFoundException, DatabaseNotFoundException, ImageNotSupportedException, -// DataProcessingException, ContainerNotFoundException { -// -// /* test */ -// tableEndpoint.delete(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); -// } -// -// @Test -// public void update_fails() { -// -// /* test */ -// final ResponseEntity<TableBriefDto> response = tableEndpoint.update(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); -// assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, response.getStatusCode()); -// } - -} diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/service/HibernateConnectorUnitTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/service/HibernateConnectorUnitTest.java deleted file mode 100644 index 095d9f2958145c84f0555c200df8fac3e16a1c83..0000000000000000000000000000000000000000 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/service/HibernateConnectorUnitTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package at.tuwien.service; - -import at.tuwien.BaseUnitTest; -import at.tuwien.api.database.table.TableCsvDto; -import at.tuwien.config.DockerConfig; -import at.tuwien.config.ReadyConfig; -import at.tuwien.exception.*; -import at.tuwien.repository.jpa.DatabaseRepository; -import at.tuwien.repository.jpa.TableRepository; -import at.tuwien.service.impl.HibernateConnector; -import com.github.dockerjava.api.command.CreateContainerResponse; -import com.github.dockerjava.api.exception.NotModifiedException; -import com.github.dockerjava.api.model.Bind; -import com.github.dockerjava.api.model.Network; -import com.rabbitmq.client.Channel; -import lombok.extern.log4j.Log4j2; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.io.File; -import java.io.IOException; -import java.time.Instant; -import java.time.temporal.ChronoUnit; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import static at.tuwien.config.DockerConfig.dockerClient; -import static at.tuwien.config.DockerConfig.hostConfig; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.when; - -@SpringBootTest -@ExtendWith(SpringExtension.class) -@Log4j2 -public class HibernateConnectorUnitTest extends BaseUnitTest { - - @MockBean - private Channel channel; - - @MockBean - private ReadyConfig readyConfig; - - @Test - public void isReserved_succeeds() throws IOException { - final String request = "TIMESTAMP"; - - /* test */ - assertTrue(HibernateConnector.isReserved(request)); - } - - @Test - public void isReserved_fails() throws IOException { - final String request = "foobar"; - - /* test */ - assertFalse(HibernateConnector.isReserved(request)); - } - -} diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java deleted file mode 100644 index 66e9b9483c90f1cccb06778cfe0f009bf760a9ea..0000000000000000000000000000000000000000 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java +++ /dev/null @@ -1,562 +0,0 @@ -package at.tuwien.service; - -import at.tuwien.BaseUnitTest; -import at.tuwien.api.database.table.TableCreateDto; -import at.tuwien.api.database.table.columns.ColumnCreateDto; -import at.tuwien.api.database.table.columns.ColumnTypeDto; -import at.tuwien.config.DockerConfig; -import at.tuwien.config.MariaDbConfig; -import at.tuwien.config.ReadyConfig; -import at.tuwien.entities.database.table.Table; -import at.tuwien.exception.*; -import at.tuwien.repository.jpa.ContainerRepository; -import at.tuwien.repository.jpa.DatabaseRepository; -import at.tuwien.repository.jpa.ImageRepository; -import at.tuwien.repository.jpa.TableRepository; -import com.github.dockerjava.api.command.CreateContainerResponse; -import com.github.dockerjava.api.exception.NotModifiedException; -import com.github.dockerjava.api.model.Bind; -import com.github.dockerjava.api.model.Network; -import com.rabbitmq.client.Channel; -import lombok.extern.log4j.Log4j2; -import org.apache.http.auth.BasicUserPrincipal; -import org.hibernate.HibernateException; -import org.junit.jupiter.api.*; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.transaction.annotation.Transactional; - -import java.io.File; -import java.security.Principal; -import java.sql.SQLException; -import java.util.Arrays; -import java.util.List; - -import static at.tuwien.config.DockerConfig.dockerClient; -import static at.tuwien.config.DockerConfig.hostConfig; -import static org.junit.jupiter.api.Assertions.*; - -@Log4j2 -@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) -@ExtendWith(SpringExtension.class) -@SpringBootTest -public class TableServiceIntegrationTest extends BaseUnitTest { - - @MockBean - private Channel channel; - - @MockBean - private ReadyConfig readyConfig; - - @Autowired - private ImageRepository imageRepository; - - @Autowired - private DatabaseRepository databaseRepository; - - @Autowired - private ContainerRepository containerRepository; - - @Autowired - private TableRepository tableRepository; - - @Autowired - private TableService tableService; - - @BeforeEach - @Transactional - public void beforeEach() { - afterEach(); - - /* create network */ - dockerClient.createNetworkCmd() - .withName("fda-userdb") - .withIpam(new Network.Ipam() - .withConfig(new Network.Ipam.Config() - .withSubnet("172.28.0.0/16"))) - .withEnableIpv6(false) - .exec(); - - /* create container */ - final String bind = new File( - "./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; - log.trace("container bind {}", bind); - final CreateContainerResponse response = dockerClient.createContainerCmd(IMAGE_1_REPOSITORY + ":" + IMAGE_1_TAG) - .withHostConfig(hostConfig.withNetworkMode("fda-userdb")) - .withName(CONTAINER_1_INTERNALNAME) - .withIpv4Address(CONTAINER_1_IP) - .withHostName(CONTAINER_1_INTERNALNAME) - .withEnv("MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", - "MARIADB_DATABASE=weather") - .withBinds(Bind.parse(bind)) - .exec(); - CONTAINER_1.setHash(response.getId()); - - /* repository */ - TABLE_1.setDatabase(DATABASE_1); - TABLE_2.setDatabase(DATABASE_1); - imageRepository.save(IMAGE_1); - databaseRepository.save(DATABASE_1); - } - - @AfterEach - public void afterEach() { - /* stop containers and remove them */ - dockerClient.listContainersCmd() - .withShowAll(true) - .exec() - .forEach(container -> { - log.info("Delete container {}", Arrays.asList(container.getNames())); - try { - dockerClient.stopContainerCmd(container.getId()).exec(); - } catch (NotModifiedException e) { - // ignore - } - dockerClient.removeContainerCmd(container.getId()).exec(); - }); - /* remove networks */ - dockerClient.listNetworksCmd() - .exec() - .stream() - .filter(n -> n.getName().startsWith("fda")) - .forEach(network -> { - log.info("Delete network {}", network.getName()); - dockerClient.removeNetworkCmd(network.getId()).exec(); - }); - } - - @Test - public void createTable_succeeds() - throws DatabaseNotFoundException, ImageNotSupportedException, TableMalformedException, InterruptedException, - TableNameExistsException, ContainerNotFoundException, UserNotFoundException { - final TableCreateDto request = TableCreateDto.builder() - .name(TABLE_2_NAME) - .description(TABLE_2_DESCRIPTION) - .columns(COLUMNS_CSV01) - .build(); - final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); - - /* mock */ - DockerConfig.startContainer(CONTAINER_1); - - /* test */ - final Table response = tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, request, principal); - assertEquals(TABLE_2_NAME, response.getName()); - assertEquals(TABLE_2_INTERNALNAME, response.getInternalName()); - assertEquals(TABLE_2_DESCRIPTION, response.getDescription()); - assertEquals(TABLE_2_TOPIC, response.getTopic()); - assertEquals(DATABASE_1_ID, response.getTdbid()); - assertEquals(COLUMNS_CSV01.length, response.getColumns().size()); - } - - @Test - public void createTable_noPrimaryKeyAutoGenerate_succeeds() - throws DatabaseNotFoundException, ImageNotSupportedException, TableMalformedException, - InterruptedException, TableNameExistsException, ContainerNotFoundException, UserNotFoundException { - final ColumnCreateDto[] columns = new ColumnCreateDto[]{ - ColumnCreateDto.builder() - .name(COLUMN_1_2_NAME) - .type(COLUMN_1_2_TYPE_DTO) - .nullAllowed(COLUMN_1_2_NULL) - .unique(COLUMN_1_2_UNIQUE) - .primaryKey(false) - .enumValues(null) - .foreignKey(COLUMN_1_2_FOREIGN_KEY) - .checkExpression(COLUMN_1_2_CHECK) - .build() - }; - final TableCreateDto request = TableCreateDto.builder() - .name(TABLE_2_NAME) - .description(TABLE_2_DESCRIPTION) - .columns(columns) - .build(); - final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); - - /* mock */ - DockerConfig.startContainer(CONTAINER_1); - - /* test */ - final Table response = tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, request, principal); - assertEquals(TABLE_2_NAME, response.getName()); - assertEquals(TABLE_2_INTERNALNAME, response.getInternalName()); - assertEquals(TABLE_2_DESCRIPTION, response.getDescription()); - assertEquals(DATABASE_1_ID, response.getTdbid()); - assertEquals(2, response.getColumns().size()); - assertTrue(response.getColumns().get(1).getAutoGenerated()); - } - - @Test - public void createTable_noPrimaryKeyAutoGenerateEmpty_succeeds() - throws DatabaseNotFoundException, ImageNotSupportedException, TableMalformedException, - InterruptedException, TableNameExistsException, ContainerNotFoundException, UserNotFoundException { - final ColumnCreateDto[] columns = new ColumnCreateDto[0]; - final TableCreateDto request = TableCreateDto.builder() - .name(TABLE_2_NAME) - .description(TABLE_2_DESCRIPTION) - .columns(columns) - .build(); - final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); - - /* mock */ - DockerConfig.startContainer(CONTAINER_1); - - /* test */ - final Table response = tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, request, principal); - assertEquals(TABLE_2_NAME, response.getName()); - assertEquals(TABLE_2_INTERNALNAME, response.getInternalName()); - assertEquals(TABLE_2_DESCRIPTION, response.getDescription()); - assertEquals(DATABASE_1_ID, response.getTdbid()); - assertEquals(1, response.getColumns().size()); - assertTrue(response.getColumns().get(0).getAutoGenerated()); - } - - @Test - public void createTable_noPrimaryKeyAutoGenerate_fails() throws InterruptedException { - final ColumnCreateDto[] columns = new ColumnCreateDto[]{ - ColumnCreateDto.builder() - .name(COLUMN_1_1_NAME) - .type(COLUMN_1_1_TYPE_DTO) - .nullAllowed(COLUMN_1_1_NULL) - .unique(COLUMN_1_1_UNIQUE) - .primaryKey(false) - .enumValues(null) - .foreignKey(COLUMN_1_1_FOREIGN_KEY) - .checkExpression(COLUMN_1_1_CHECK) - .build(), - ColumnCreateDto.builder() - .name(COLUMN_1_2_NAME) - .type(COLUMN_1_2_TYPE_DTO) - .nullAllowed(COLUMN_1_2_NULL) - .unique(COLUMN_1_2_UNIQUE) - .primaryKey(false) - .enumValues(null) - .foreignKey(COLUMN_1_2_FOREIGN_KEY) - .checkExpression(COLUMN_1_2_CHECK) - .build() - }; - final TableCreateDto request = TableCreateDto.builder() - .name(TABLE_2_NAME) - .description(TABLE_2_DESCRIPTION) - .columns(columns) - .build(); - final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); - - /* mock */ - DockerConfig.startContainer(CONTAINER_1); - - /* test */ - assertThrows(TableMalformedException.class, () -> { - tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, request, principal); - }); - } - - @Test - public void createTable_groupPrimaryKey_succeeds() - throws DatabaseNotFoundException, ImageNotSupportedException, TableMalformedException, InterruptedException, - TableNameExistsException, ContainerNotFoundException, UserNotFoundException { - final ColumnCreateDto[] columns = new ColumnCreateDto[]{ - ColumnCreateDto.builder() - .name(COLUMN_1_1_NAME) - .type(COLUMN_1_1_TYPE_DTO) - .nullAllowed(COLUMN_1_1_NULL) - .unique(COLUMN_1_1_UNIQUE) - .primaryKey(COLUMN_1_1_PRIMARY) - .enumValues(null) - .foreignKey(COLUMN_1_1_FOREIGN_KEY) - .checkExpression(COLUMN_1_1_CHECK) - .build(), - ColumnCreateDto.builder() - .name(COLUMN_1_3_NAME) - .type(COLUMN_1_3_TYPE_DTO) - .nullAllowed(COLUMN_1_3_NULL) - .unique(COLUMN_1_3_UNIQUE) - .primaryKey(true) - .enumValues(null) - .foreignKey(COLUMN_1_3_FOREIGN_KEY) - .checkExpression(COLUMN_1_3_CHECK) - .build() - }; - final TableCreateDto request = TableCreateDto.builder() - .name(TABLE_2_NAME) - .description(TABLE_2_DESCRIPTION) - .columns(columns) - .build(); - final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); - - /* mock */ - DockerConfig.startContainer(CONTAINER_1); - - /* test */ - final Table response = tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, request, principal); - assertEquals(TABLE_2_NAME, response.getName()); - assertEquals(TABLE_2_INTERNALNAME, response.getInternalName()); - assertEquals(TABLE_2_DESCRIPTION, response.getDescription()); - assertEquals(DATABASE_1_ID, response.getTdbid()); - } - - @Test - public void createTable_checkExpression_succeeds() - throws DatabaseNotFoundException, ImageNotSupportedException, TableMalformedException, InterruptedException, - TableNameExistsException, ContainerNotFoundException, UserNotFoundException { - final ColumnCreateDto[] columns = new ColumnCreateDto[]{ - ColumnCreateDto.builder() - .name(COLUMN_1_1_NAME) - .type(COLUMN_1_1_TYPE_DTO) - .nullAllowed(COLUMN_1_1_NULL) - .unique(COLUMN_1_1_UNIQUE) - .primaryKey(COLUMN_1_1_PRIMARY) - .enumValues(null) - .foreignKey(COLUMN_1_1_FOREIGN_KEY) - .checkExpression("`id` > 0") - .build() - }; - final TableCreateDto request = TableCreateDto.builder() - .name(TABLE_2_NAME) - .description(TABLE_2_DESCRIPTION) - .columns(columns) - .build(); - final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); - - /* mock */ - DockerConfig.startContainer(CONTAINER_1); - - /* test */ - final Table response = tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, request, principal); - assertEquals(TABLE_2_NAME, response.getName()); - assertEquals(TABLE_2_INTERNALNAME, response.getInternalName()); - assertEquals(TABLE_2_DESCRIPTION, response.getDescription()); - assertEquals(DATABASE_1_ID, response.getTdbid()); - } - - @Test - public void createTable_withEnum_succeeds() - throws DatabaseNotFoundException, ImageNotSupportedException, TableMalformedException, InterruptedException, - TableNameExistsException, ContainerNotFoundException, UserNotFoundException { - final ColumnCreateDto[] columns = new ColumnCreateDto[]{ - ColumnCreateDto.builder() - .name(COLUMN_1_1_NAME) - .type(COLUMN_1_1_TYPE_DTO) - .nullAllowed(COLUMN_1_1_NULL) - .unique(COLUMN_1_1_UNIQUE) - .primaryKey(COLUMN_1_1_PRIMARY) - .enumValues(null) - .foreignKey(COLUMN_1_1_FOREIGN_KEY) - .checkExpression(COLUMN_1_1_CHECK) - .build(), - ColumnCreateDto.builder() - .name(COLUMN_1_3_NAME) - .type(COLUMN_1_3_TYPE_DTO) - .nullAllowed(COLUMN_1_3_NULL) - .unique(COLUMN_1_3_UNIQUE) - .primaryKey(COLUMN_1_3_PRIMARY) - .enumValues(new String[]{"A", "B", "C"}) - .foreignKey(COLUMN_1_3_FOREIGN_KEY) - .checkExpression(COLUMN_1_3_CHECK) - .build() - }; - final TableCreateDto request = TableCreateDto.builder() - .name(TABLE_2_NAME) - .description(TABLE_2_DESCRIPTION) - .columns(columns) - .build(); - final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); - - /* mock */ - DockerConfig.startContainer(CONTAINER_1); - - /* test */ - final Table response = tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, request, principal); - assertEquals(TABLE_2_NAME, response.getName()); - assertEquals(TABLE_2_INTERNALNAME, response.getInternalName()); - assertEquals(TABLE_2_DESCRIPTION, response.getDescription()); - assertEquals(DATABASE_1_ID, response.getTdbid()); - assertEquals(2, response.getColumns().size()); - assertEquals(List.of("A", "B", "C"), response.getColumns().get(1).getEnumValues()); - } - - @Test - public void createTable_withUniqueColumn_succeeds() - throws DatabaseNotFoundException, ImageNotSupportedException, TableMalformedException, InterruptedException, - TableNameExistsException, ContainerNotFoundException, UserNotFoundException { - final ColumnCreateDto[] columns = new ColumnCreateDto[]{ - ColumnCreateDto.builder() - .name(COLUMN_1_1_NAME) - .type(COLUMN_1_1_TYPE_DTO) - .nullAllowed(COLUMN_1_1_NULL) - .unique(COLUMN_1_1_UNIQUE) - .primaryKey(COLUMN_1_1_PRIMARY) - .enumValues(null) - .foreignKey(COLUMN_1_1_FOREIGN_KEY) - .checkExpression(COLUMN_1_1_CHECK) - .build(), - ColumnCreateDto.builder() - .name(COLUMN_1_3_NAME) - .type(COLUMN_1_3_TYPE_DTO) - .nullAllowed(COLUMN_1_3_NULL) - .unique(true) - .primaryKey(COLUMN_1_3_PRIMARY) - .enumValues(null) - .foreignKey(COLUMN_1_3_FOREIGN_KEY) - .checkExpression(COLUMN_1_3_CHECK) - .build() - }; - final TableCreateDto request = TableCreateDto.builder() - .name(TABLE_2_NAME) - .description(TABLE_2_DESCRIPTION) - .columns(columns) - .build(); - final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); - - /* mock */ - DockerConfig.startContainer(CONTAINER_1); - - /* test */ - final Table response = tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, request, principal); - assertEquals(TABLE_2_NAME, response.getName()); - assertEquals(TABLE_2_INTERNALNAME, response.getInternalName()); - assertEquals(TABLE_2_DESCRIPTION, response.getDescription()); - assertEquals(DATABASE_1_ID, response.getTdbid()); - assertEquals(2, response.getColumns().size()); - } - -// @Test -// public void deleteTable_succeeds() throws DatabaseNotFoundException, ImageNotSupportedException, -// InterruptedException, TableNotFoundException, DataProcessingException, ContainerNotFoundException { -// -// /* mock */ -// DockerConfig.startContainer(CONTAINER_1); -// -// /* test */ -// tableService.deleteTable(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); -// } - - /** - * TODO https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services/-/issues/99 - * <p> - * When creating a table (POST /database/1/table) with columns of these types, I get this error: - * <p> - * type: "STRING", name: "username" - * type: "BLOB" - */ - @Test - public void createTable_textPrimaryKey_succeeds() - throws InterruptedException, SQLException, TableMalformedException, DatabaseNotFoundException, - ImageNotSupportedException, TableNameExistsException, ContainerNotFoundException, UserNotFoundException { - final TableCreateDto request = TableCreateDto.builder() - .name("Issue 99") - .description("Related to issue 99") - .columns(new ColumnCreateDto[]{ - ColumnCreateDto.builder() - .name("username") - .nullAllowed(false) - .type(ColumnTypeDto.TEXT) - .unique(true) - .primaryKey(true) - .build(), - ColumnCreateDto.builder() - .name("data") - .nullAllowed(true) - .type(ColumnTypeDto.BLOB) - .unique(false) - .primaryKey(false) - .build() - }) - .build(); - final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); - - /* start */ - DockerConfig.startContainer(CONTAINER_1); - MariaDbConfig.clearDatabase(TABLE_1); - - /* test */ - tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, request, principal); - } - - @Test - public void createTable_blobPrimaryKey_succeeds() - throws InterruptedException, SQLException, TableMalformedException, DatabaseNotFoundException, - ImageNotSupportedException, TableNameExistsException, ContainerNotFoundException, UserNotFoundException { - final TableCreateDto request = TableCreateDto.builder() - .name("Issue 99") - .description("Related to issue 99") - .columns(new ColumnCreateDto[]{ - ColumnCreateDto.builder() - .name("username") - .nullAllowed(false) - .type(ColumnTypeDto.BLOB) - .unique(true) - .primaryKey(true) - .build(), - ColumnCreateDto.builder() - .name("data") - .nullAllowed(true) - .type(ColumnTypeDto.BLOB) - .unique(false) - .primaryKey(false) - .build() - }) - .build(); - final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); - - /* start */ - DockerConfig.startContainer(CONTAINER_1); - MariaDbConfig.clearDatabase(TABLE_1); - - /* test */ - tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, request, principal); - } - -// @Test -// public void deleteTable_notRunning_fails() { -// -// /* start */ -// DockerConfig.stopContainer(CONTAINER_1); -// -// /* test */ -// assertThrows(HibernateException.class, () -> { -// tableService.deleteTable(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); -// }); -// } - - @Test - public void createTable_issue106_succeeds() throws InterruptedException, SQLException, TableMalformedException, - DatabaseNotFoundException, ImageNotSupportedException, TableNameExistsException, - ContainerNotFoundException, UserNotFoundException { - final TableCreateDto request = TableCreateDto.builder() - .name("Table") - .description(TABLE_2_DESCRIPTION) - .columns(COLUMNS_CSV01) - .build(); - final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); - - /* start */ - DockerConfig.startContainer(CONTAINER_1); - MariaDbConfig.clearDatabase(TABLE_1); - - /* test */ - tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, request, principal); - } - - @Test - public void createTable_emptyName_fails() throws InterruptedException { - final TableCreateDto request = TableCreateDto.builder() - .name("") - .description(TABLE_2_DESCRIPTION) - .columns(COLUMNS_CSV01) - .build(); - final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); - - /* start */ - DockerConfig.startContainer(CONTAINER_1); - - /* test */ - assertThrows(TableMalformedException.class, () -> { - tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, request, principal); - }); - } - -} diff --git a/fda-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceUnitTest.java b/fda-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceUnitTest.java deleted file mode 100644 index 1d12f9055d0a45714c4f87754c364acef4e3cd23..0000000000000000000000000000000000000000 --- a/fda-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceUnitTest.java +++ /dev/null @@ -1,125 +0,0 @@ -package at.tuwien.service; - -import at.tuwien.BaseUnitTest; -import at.tuwien.config.ReadyConfig; -import at.tuwien.entities.database.table.Table; -import at.tuwien.exception.*; -import at.tuwien.repository.jpa.DatabaseRepository; -import at.tuwien.repository.jpa.TableRepository; -import at.tuwien.service.impl.TableServiceImpl; -import com.rabbitmq.client.Channel; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import java.util.List; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.*; - -@SpringBootTest -@ExtendWith(SpringExtension.class) -public class TableServiceUnitTest extends BaseUnitTest { - - @MockBean - private Channel channel; - - @MockBean - private ReadyConfig readyConfig; - - @Autowired - private TableServiceImpl tableService; - - @MockBean - private DatabaseRepository databaseRepository; - - @MockBean - private TableRepository tableRepository; - - @BeforeAll - public static void beforeAll() { - TABLE_1.setDatabase(DATABASE_1); - } - -// @Test -// public void findAll_succeeds() throws DatabaseNotFoundException { -// when(databaseRepository.findById(DATABASE_1_ID)) -// .thenReturn(Optional.of(DATABASE_1)); -// when(tableRepository.findByDatabase(DATABASE_1)) -// .thenReturn(List.of(TABLE_1)); -// -// /* test */ -// final List<Table> response = tableService.findAll(CONTAINER_1_ID, DATABASE_1_ID); -// assertEquals(1, response.size()); -// assertEquals(TABLE_1_ID, response.get(0).getId()); -// } -// -// @Test -// public void findAll_notFound_fails() { -// when(databaseRepository.findById(DATABASE_1_ID)) -// .thenReturn(Optional.empty()); -// -// /* test */ -// assertThrows(DatabaseNotFoundException.class, () -> { -// tableService.findAll(CONTAINER_1_ID, DATABASE_1_ID); -// }); -// } -// -// @Test -// public void delete_notFound_fails() { -// when(databaseRepository.findById(DATABASE_1_ID)) -// .thenReturn(Optional.empty()); -// -// /* test */ -// assertThrows(DatabaseNotFoundException.class, () -> { -// tableService.deleteTable(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); -// }); -// } -// -// @Test -// public void delete_noSql_fails() { -// when(databaseRepository.findById(DATABASE_1_ID)) -// .thenReturn(Optional.of(DATABASE_1)); -// when(tableRepository.findByDatabaseAndId(DATABASE_1, TABLE_1_ID)) -// .thenReturn(Optional.empty()); -// -// /* test */ -// assertThrows(TableNotFoundException.class, () -> { -// tableService.deleteTable(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); -// }); -// } -// -// @Test -// public void findById_succeeds() throws TableNotFoundException, DatabaseNotFoundException, -// ContainerNotFoundException { -// when(databaseRepository.findById(DATABASE_1_ID)) -// .thenReturn(Optional.of(DATABASE_1)); -// when(tableRepository.findByDatabaseAndId(DATABASE_1, TABLE_1_ID)) -// .thenReturn(Optional.of(TABLE_1)); -// -// /* test */ -// final Table response = tableService.findById(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); -// assertEquals(TABLE_1_ID, response.getId()); -// assertEquals(TABLE_1_NAME, response.getName()); -// } -// -// @Test -// public void findById_noTable_fails() { -// when(databaseRepository.findById(DATABASE_1_ID)) -// .thenReturn(Optional.of(DATABASE_1)); -// when(tableRepository.findByDatabaseAndId(DATABASE_1, 9999L)) -// .thenReturn(Optional.empty()); -// -// /* test */ -// assertThrows(TableNotFoundException.class, () -> { -// tableService.findById(CONTAINER_1_ID, DATABASE_1_ID, 9999L); -// }); -// } - -} diff --git a/fda-table-service/services/src/main/java/at/tuwien/service/TableService.java b/fda-table-service/services/src/main/java/at/tuwien/service/TableService.java index b541cd140e4e7bb65df6ccac0ba57e535e5b035c..511467cdd009cde8fb5697d10685f614ddf11716 100644 --- a/fda-table-service/services/src/main/java/at/tuwien/service/TableService.java +++ b/fda-table-service/services/src/main/java/at/tuwien/service/TableService.java @@ -33,7 +33,7 @@ public interface TableService { */ void deleteTable(Long containerId, Long databaseId, Long tableId, Principal principal) throws TableNotFoundException, DatabaseNotFoundException, - ImageNotSupportedException, DataProcessingException, ContainerNotFoundException, TableMalformedException; + ImageNotSupportedException, DataProcessingException, ContainerNotFoundException, TableMalformedException, DatabaseConnectionException; /** * Find a table by database-table id pair @@ -66,5 +66,5 @@ public interface TableService { */ Table createTable(Long containerId, Long databaseId, TableCreateDto createDto, Principal principal) throws ImageNotSupportedException, DatabaseNotFoundException, TableMalformedException, - TableNameExistsException, ContainerNotFoundException, UserNotFoundException; + TableNameExistsException, ContainerNotFoundException, UserNotFoundException, DatabaseConnectionException; } diff --git a/fda-table-service/services/src/main/java/at/tuwien/service/impl/HibernateConnector.java b/fda-table-service/services/src/main/java/at/tuwien/service/impl/HibernateConnector.java index 28b7cfd61ed555c9944f657c91f15565328c1f55..9cb24ee589fd979c0537c4d35be52c7feea437b8 100644 --- a/fda-table-service/services/src/main/java/at/tuwien/service/impl/HibernateConnector.java +++ b/fda-table-service/services/src/main/java/at/tuwien/service/impl/HibernateConnector.java @@ -5,89 +5,79 @@ import at.tuwien.entities.container.image.ContainerImage; import at.tuwien.entities.container.image.ContainerImageEnvironmentItem; import at.tuwien.entities.container.image.ContainerImageEnvironmentItemType; import at.tuwien.entities.database.Database; +import at.tuwien.exception.DatabaseConnectionException; +import com.mchange.v2.c3p0.ComboPooledDataSource; import lombok.extern.log4j.Log4j2; -import org.apache.commons.io.IOUtils; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.boot.Metadata; -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.cfg.Configuration; -import org.hibernate.query.NativeQuery; -import org.hibernate.service.ServiceRegistry; -import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import javax.persistence.PersistenceException; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.stream.Collectors; @Log4j2 @Service public abstract class HibernateConnector { - protected static Session getCurrentSession(ContainerImage image, Container container, Database database) { - final String url = "jdbc:" + image.getJdbcMethod() + "://" + container.getInternalName() + "/" + database.getInternalName(); + protected static Connection getConnection(ContainerImage image, Container container, Database database) throws DatabaseConnectionException { + final ComboPooledDataSource dataSource = new ComboPooledDataSource(); + final String url = "jdbc:" + image.getJdbcMethod() + "://" + container.getInternalName() + "/" + (database != null ? database.getInternalName() : ""); + dataSource.setJdbcUrl(url); final String username = image.getEnvironment() .stream() .filter(e -> e.getType().equals(ContainerImageEnvironmentItemType.PRIVILEGED_USERNAME)) .map(ContainerImageEnvironmentItem::getValue) .collect(Collectors.toList()) .get(0); + dataSource.setUser(username); final String password = image.getEnvironment() .stream() .filter(e -> e.getType().equals(ContainerImageEnvironmentItemType.PRIVILEGED_PASSWORD)) .map(ContainerImageEnvironmentItem::getValue) .collect(Collectors.toList()) .get(0); - - final Configuration config = new Configuration(); - config.configure("mariadb_hibernate.cfg.xml"); - config.setProperty("hibernate.connection.url", url); - config.setProperty("hibernate.connection.username", username); - config.setProperty("hibernate.connection.password", password); - config.setProperty("hibernate.connection.driver_class", image.getDriverClass()); - config.setProperty("hibernate.dialect", image.getDialect()); - final SessionFactory sessionFactory = config.buildSessionFactory(); - Session session = sessionFactory.getCurrentSession(); - if (!session.isOpen()) { - log.warn("Session is closed, opening..."); - session = sessionFactory.openSession(); + dataSource.setPassword(password); + dataSource.setInitialPoolSize(5); + dataSource.setMinPoolSize(5); + dataSource.setAcquireIncrement(5); + dataSource.setMaxPoolSize(20); + dataSource.setMaxStatements(100); + final Connection connection; + try { + connection = dataSource.getConnection(); + } catch (SQLException e) { + log.error("Failed to connect to the database"); + log.debug("failed to connect to the database {}", database); + throw new DatabaseConnectionException("Failed to connect to the database"); } - return session; + return connection; } - protected static Long activeConnection(Session session) { - final NativeQuery<?> nativeQuery = session.createSQLQuery("SHOW STATUS LIKE 'threads_connected'"); - final List<?> result; + protected static Long activeConnection(Connection connection) throws DatabaseConnectionException { + final ResultSet resultSet = execute(connection, "SHOW STATUS LIKE 'threads_connected'"); try { - result = nativeQuery.getResultList(); - } catch (PersistenceException e) { - log.error("Failed to collect number of used connections"); - /* ignore */ - return null; + if (resultSet.next()) { + return resultSet.getLong(2); + } + } catch (SQLException e) { + log.error("Failed to determine active connections"); + throw new DatabaseConnectionException("Failed to determine active connections", e); } - final Object[] row = (Object[]) result.get(0); - log.debug("current number of connections: {}", Long.parseLong(String.valueOf(row[1]))); - return Long.parseLong(String.valueOf(row[1])); + log.error("Failed to determine active connections"); + throw new DatabaseConnectionException("Failed to determine active connections"); } - /** - * Checks if the word is in the reserved word csv (i.e. an SQL keyword), solves issue 106 - * - * @param word The word - * @return True if it is reserved word - */ - public static Boolean isReserved(String word) throws IOException { - final InputStream stream = new ClassPathResource("mariadb/reserved.csv").getInputStream(); - final List<String> reserved = IOUtils.readLines(stream, "UTF-8"); - return reserved.contains(word.toUpperCase()); + protected static ResultSet execute(Connection connection, String statement) throws DatabaseConnectionException { + final PreparedStatement preparedStatement; + try { + preparedStatement = connection.prepareStatement(statement); + return preparedStatement.executeQuery(); + } catch (SQLException e) { + log.error("Failed to execute statement"); + log.debug("failed to execute statement {}", statement); + throw new DatabaseConnectionException("Failed to execute statement", e); + } } - } diff --git a/fda-table-service/services/src/main/java/at/tuwien/service/impl/TableServiceImpl.java b/fda-table-service/services/src/main/java/at/tuwien/service/impl/TableServiceImpl.java index 120ff8b49100cdac514969acbc58c4946e55971e..c8e4b0f52072982de1cc44ba930505058487979c 100644 --- a/fda-table-service/services/src/main/java/at/tuwien/service/impl/TableServiceImpl.java +++ b/fda-table-service/services/src/main/java/at/tuwien/service/impl/TableServiceImpl.java @@ -24,6 +24,7 @@ import javax.persistence.PersistenceContext; import javax.persistence.PersistenceException; import javax.persistence.PersistenceUnit; import java.security.Principal; +import java.sql.Connection; import java.sql.SQLException; import java.util.*; import java.util.stream.Collectors; @@ -57,24 +58,16 @@ public class TableServiceImpl extends HibernateConnector implements TableService @Override @Transactional public void deleteTable(Long containerId, Long databaseId, Long tableId, Principal principal) - throws TableNotFoundException, DatabaseNotFoundException, ImageNotSupportedException, TableMalformedException { + throws TableNotFoundException, DatabaseNotFoundException, ImageNotSupportedException, + TableMalformedException, DatabaseConnectionException { /* find */ final Database database = databaseService.findPublicOrMineById(containerId, databaseId, principal); final Table table = findById(containerId, databaseId, tableId, principal); /* run query */ - final Session session = getCurrentSession(database.getContainer().getImage(), database.getContainer(), database); - final Transaction transaction = session.beginTransaction(); - try { - session.createSQLQuery(tableMapper.tableToDropTableRawQuery(table)); - activeConnection(session); - transaction.commit(); - log.info("Deleted table with id {}", table.getId()); - log.debug("deleted table {}", table); - } catch (PersistenceException e) { - log.error("Failed to drop table with id {}", tableId); - log.debug("failed to drop table {}", table); - throw new TableMalformedException("Failed to drop table"); - } + final Connection connection = getConnection(database.getContainer().getImage(), database.getContainer(), database); + execute(connection, tableMapper.tableToDropTableRawQuery(table)); + log.info("Deleted table with id {}", table.getId()); + log.debug("deleted table {}", table); } @Override @@ -94,7 +87,7 @@ public class TableServiceImpl extends HibernateConnector implements TableService @Transactional public Table createTable(Long containerId, Long databaseId, TableCreateDto createDto, Principal principal) throws ImageNotSupportedException, DatabaseNotFoundException, TableMalformedException, - TableNameExistsException, UserNotFoundException { + TableNameExistsException, UserNotFoundException, DatabaseConnectionException { /* find */ final Database database = databaseService.findPublicOrMineById(containerId, databaseId, principal); final Optional<Table> optional = tableRepository.findByDatabaseAndInternalName(database, @@ -105,33 +98,14 @@ public class TableServiceImpl extends HibernateConnector implements TableService throw new TableNameExistsException("Table name exists"); } /* run query */ - final Session session = getCurrentSession(database.getContainer().getImage(), database.getContainer(), database); - final Transaction transaction = session.beginTransaction(); + final Connection connection = getConnection(database.getContainer().getImage(), database.getContainer(), database); final CreateTableRawQuery query = tableMapper.tableToCreateTableRawQuery(database, createDto); if (query.getGenerated()) { /* in case the id column needs to be generated, we need to generate the sequence too */ - try { - session.createSQLQuery(tableMapper.tableToCreateSequenceRawQuery(database, createDto)) - .executeUpdate(); - } catch (PersistenceException e) { - log.error("Table sequence exists, but table does not. Create an issue for this."); - session.close(); - throw new TableNameExistsException("Sequence exists", e); - } + execute(connection, tableMapper.tableToCreateSequenceRawQuery(database, createDto)); log.debug("created id sequence"); } - try { - session.createSQLQuery(query.getQuery()) - .executeUpdate(); - activeConnection(session); - transaction.commit(); - } catch (PersistenceException e) { - log.error("Failed to create table"); - log.debug("failed to create table: {}", e.getMessage()); - session.close(); - throw new TableMalformedException("Failed to create table", e); - } - session.close(); + execute(connection, query.getQuery()); int[] idx = {0}; /* map table */ final Table tmp = tableMapper.tableCreateDtoToTable(createDto); @@ -155,20 +129,7 @@ public class TableServiceImpl extends HibernateConnector implements TableService column.setOrdinalPosition(idx[0]++); }); /* create history view */ - final Session session2 = getCurrentSession(database.getContainer().getImage(), database.getContainer(), database); - try { - final Transaction transaction2 = session2.beginTransaction(); - session2.createSQLQuery(tableMapper.tableToCreateHistoryViewRawQuery(entity)) - .executeUpdate(); - activeConnection(session2); - transaction2.commit(); - } catch (PersistenceException e) { - log.error("Failed to create history view"); - log.debug("failed to create history view: {}", e.getMessage()); - session2.close(); - throw new TableMalformedException("Failed to create history view"); - } - session2.close(); + execute(connection, tableMapper.tableToCreateHistoryViewRawQuery(entity)); /* save */ final Table table = tableRepository.save(entity); log.info("Created table with id {}", table.getId());