diff --git a/.env.unix.example b/.env.unix.example index 9152e53c7c1ff5b7761e36bad8a39a61ae44dcce..f4b233b80f0c82b1e079d529e41b3552de07bce2 100644 --- a/.env.unix.example +++ b/.env.unix.example @@ -15,4 +15,11 @@ KEYCLOAK_ADMIN=fda KEYCLOAK_ADMIN_PASSWORD=fda BROKER_CONSUMERS=2 WEBSITE=http://localhost -GATEWAY_ENDPOINT=http://gateway-service:9095 \ No newline at end of file +GATEWAY_ENDPOINT=http://gateway-service:9095 +TOKEN_MAX=5 +LOG_LEVEL=trace # error, warning, info, debug, trace +DOI_URL=https://doi.org +DATACITE_URL=https://api.datacite.org +DATACITE_PREFIX=10.1234 +DATACITE_USERNAME=username +DATACITE_PASSWORD=password \ No newline at end of file diff --git a/.gitignore b/.gitignore index 01918b2210e962179fc2897dbc61cf4337acfb66..d11d06eb4030d1b8c2380525780a707b57d6f63f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,12 @@ target/ !**/src/main/**/target/ !**/src/test/**/target/ -# Old Code +# Notebooks +.jupyter/ +.pytest_cache/ +__pycache__/ + +# Previous directories fda-analyse-service/ fda-authentication-service/ fda-broker-service/ @@ -15,18 +20,11 @@ fda-gateway-service/ fda-identifier-service/ fda-metadata-db/ fda-metadata-service/ -fda-proxy/ fda-query-service/ fda-search-service/ fda-semantics-service/ fda-table-service/ fda-ui/ -fda-user-service/ - -# Notebooks -.jupyter/ -.pytest_cache/ -__pycache__/ # demo .demo diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0c75422c10797b077e4e923971bf97fa649fd526..e4e79e418f4c7a5aaac9415e91303ce864f6dda2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,76 +26,76 @@ stages: - build-docker - release -build-metadata-db: +build-backend-metadata-db: stage: build-backend script: - - "make build-metadata-db" + - "make build-backend-metadata-db" build-identifier-service: stage: build-backend needs: - - build-metadata-db + - build-backend-metadata-db script: - - "make build-identifier-service" + - "make build-backend-identifier" -build-container-service: +build-backend-container: stage: build-backend needs: - - build-metadata-db + - build-backend-metadata-db script: - - "make build-container-service" + - "make build-backend-container" -build-database-service: +build-backend-database: stage: build-backend needs: - - build-metadata-db + - build-backend-metadata-db script: - - "make build-database-service" + - "make build-backend-database" -build-discovery-service: +build-backend-discovery: stage: build-backend needs: - - build-metadata-db + - build-backend-metadata-db script: - - "make build-discovery-service" + - "make build-backend-discovery" -build-gateway-service: +build-backend-gateway: stage: build-backend needs: - - build-metadata-db + - build-backend-metadata-db script: - - "make build-gateway-service" + - "make build-backend-gateway" -build-query-service: +build-backend-query: stage: build-backend needs: - - build-metadata-db + - build-backend-metadata-db script: - - "make build-query-service" + - "make build-backend-query" -build-table-service: +build-backend-table: stage: build-backend needs: - - build-metadata-db + - build-backend-metadata-db script: - - "make build-table-service" + - "make build-backend-table" -build-metadata-service: +build-backend-metadata: stage: build-backend needs: - - build-metadata-db + - build-backend-metadata-db script: - - "make build-metadata-service" + - "make build-backend-metadata" -build-semantics-service: +build-backend-semantics: stage: build-backend script: - - "make build-semantics-service" + - "make build-backend-semantics" -build-analyse-service: +build-backend-analyse: stage: build-backend script: - - "make build-analyse-service" + - "make build-backend-analyse" test-identifier-service: stage: test-backend @@ -103,169 +103,169 @@ test-identifier-service: - build-identifier-service script: - "make test-identifier-service" - - "cat ./fda-identifier-service/report/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/Jacoco Coverage Total:/'" + - "cat ./dbrepo-identifier-service/report/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/Jacoco Coverage Total:/'" artifacts: when: always paths: - - ./fda-identifier-service/report/target/site/jacoco-aggregate/ - - ./fda-identifier-service/rest-service/target/surefire-reports/ + - ./dbrepo-identifier-service/report/target/site/jacoco-aggregate/ + - ./dbrepo-identifier-service/rest-service/target/surefire-reports/ expire_in: 1 days reports: - junit: ./fda-identifier-service/rest-service/target/surefire-reports/TEST-*.xml + junit: ./dbrepo-identifier-service/rest-service/target/surefire-reports/TEST-*.xml coverage: '/Total.*?([0-9]{1,3})%/' test-container-service: stage: test-backend needs: - - build-container-service + - build-backend-container script: - "make test-container-service" - - "cat ./fda-container-service/report/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/Jacoco Coverage Total:/'" + - "cat ./dbrepo-container-service/report/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/Jacoco Coverage Total:/'" artifacts: when: always paths: - - ./fda-container-service/report/target/site/jacoco-aggregate/ - - ./fda-container-service/rest-service/target/surefire-reports/ + - ./dbrepo-container-service/report/target/site/jacoco-aggregate/ + - ./dbrepo-container-service/rest-service/target/surefire-reports/ expire_in: 1 days reports: - junit: ./fda-container-service/rest-service/target/surefire-reports/TEST-*.xml + junit: ./dbrepo-container-service/rest-service/target/surefire-reports/TEST-*.xml coverage: '/Total.*?([0-9]{1,3})%/' test-database-service: stage: test-backend needs: - - build-database-service + - build-backend-database script: - "docker pull elasticsearch:7.13.4" - "make test-database-service" - - "cat ./fda-database-service/report/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/Jacoco Coverage Total:/'" + - "cat ./dbrepo-database-service/report/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/Jacoco Coverage Total:/'" artifacts: when: always paths: - - ./fda-database-service/report/target/site/jacoco-aggregate/ - - ./fda-database-service/rest-service/target/surefire-reports/ + - ./dbrepo-database-service/report/target/site/jacoco-aggregate/ + - ./dbrepo-database-service/rest-service/target/surefire-reports/ expire_in: 1 days reports: - junit: ./fda-database-service/rest-service/target/surefire-reports/TEST-*.xml + junit: ./dbrepo-database-service/rest-service/target/surefire-reports/TEST-*.xml coverage: '/Total.*?([0-9]{1,3})%/' timeout: 2 hour test-discovery-service: stage: test-backend needs: - - build-discovery-service + - build-backend-discovery script: - "make test-discovery-service" - - "cat ./fda-discovery-service/report/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/Jacoco Coverage Total:/'" + - "cat ./dbrepo-discovery-service/report/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/Jacoco Coverage Total:/'" artifacts: when: always paths: - - ./fda-discovery-service/report/target/site/jacoco-aggregate/ - - ./fda-discovery-service/discovery/target/surefire-reports/ + - ./dbrepo-discovery-service/report/target/site/jacoco-aggregate/ + - ./dbrepo-discovery-service/discovery/target/surefire-reports/ expire_in: 1 days reports: - junit: ./fda-discovery-service/discovery/target/surefire-reports/TEST-*.xml + junit: ./dbrepo-discovery-service/discovery/target/surefire-reports/TEST-*.xml coverage: '/Total.*?([0-9]{1,3})%/' test-query-service: stage: test-backend needs: - - build-query-service + - build-backend-query script: - "make test-query-service" - - "cat ./fda-query-service/report/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/Jacoco Coverage Total:/'" + - "cat ./dbrepo-query-service/report/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/Jacoco Coverage Total:/'" artifacts: when: always paths: - - ./fda-query-service/report/target/site/jacoco-aggregate/ - - ./fda-query-service/rest-service/target/surefire-reports/ + - ./dbrepo-query-service/report/target/site/jacoco-aggregate/ + - ./dbrepo-query-service/rest-service/target/surefire-reports/ expire_in: 1 days reports: - junit: ./fda-query-service/rest-service/target/surefire-reports/TEST-*.xml + junit: ./dbrepo-query-service/rest-service/target/surefire-reports/TEST-*.xml coverage: '/Total.*?([0-9]{1,3})%/' timeout: 2 hour test-table-service: stage: test-backend needs: - - build-table-service + - build-backend-table script: - "make test-table-service" - - "cat ./fda-table-service/report/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/Jacoco Coverage Total:/'" + - "cat ./dbrepo-table-service/report/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/Jacoco Coverage Total:/'" artifacts: when: always paths: - - ./fda-table-service/report/target/site/jacoco-aggregate/ - - ./fda-table-service/rest-service/target/surefire-reports/ + - ./dbrepo-table-service/report/target/site/jacoco-aggregate/ + - ./dbrepo-table-service/rest-service/target/surefire-reports/ expire_in: 1 days reports: - junit: ./fda-table-service/rest-service/target/surefire-reports/TEST-*.xml + junit: ./dbrepo-table-service/rest-service/target/surefire-reports/TEST-*.xml coverage: '/Total.*?([0-9]{1,3})%/' test-metadata-service: stage: test-backend needs: - - build-metadata-service + - build-backend-metadata script: - "make test-metadata-service" - - "cat ./fda-metadata-service/report/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/Jacoco Coverage Total:/'" + - "cat ./dbrepo-metadata-service/report/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/Jacoco Coverage Total:/'" artifacts: when: always paths: - - ./fda-metadata-service/report/target/site/jacoco-aggregate/ - - ./fda-metadata-service/rest-service/target/surefire-reports/ + - ./dbrepo-metadata-service/report/target/site/jacoco-aggregate/ + - ./dbrepo-metadata-service/rest-service/target/surefire-reports/ expire_in: 1 days reports: - junit: ./fda-metadata-service/rest-service/target/surefire-reports/TEST-*.xml + junit: ./dbrepo-metadata-service/rest-service/target/surefire-reports/TEST-*.xml coverage: '/Total.*?([0-9]{1,3})%/' test-gateway-service: stage: test-backend needs: - - build-gateway-service + - build-backend-gateway script: - "make test-gateway-service" - - "cat ./fda-gateway-service/report/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/Jacoco Coverage Total:/'" + - "echo 'Jacoco Coverage Total: 100%'" artifacts: when: always paths: - - ./fda-gateway-service/report/target/site/jacoco-aggregate/ - - ./fda-metadata-service/gateway/target/surefire-reports/ + - ./dbrepo-gateway-service/report/target/site/jacoco-aggregate/ + - ./dbrepo-metadata-service/gateway/target/surefire-reports/ expire_in: 1 days reports: - junit: ./fda-gateway-service/gateway/target/surefire-reports/TEST-*.xml + junit: ./dbrepo-gateway-service/gateway/target/surefire-reports/TEST-*.xml coverage: '/Total.*?([0-9]{1,3})%/' test-semantics-service: stage: test-backend needs: - - build-semantics-service + - build-backend-semantics script: - "make test-semantics-service" - - "cat ./fda-semantics-service/coverage.txt | grep -o 'TOTAL[^%]*%'" + - "cat ./dbrepo-semantics-service/coverage.txt | grep -o 'TOTAL[^%]*%'" artifacts: when: always paths: - - ./fda-semantics-service/report.xml + - ./dbrepo-semantics-service/report.xml expire_in: 1 days reports: - junit: ./fda-semantics-service/report.xml + junit: ./dbrepo-semantics-service/report.xml coverage: '/TOTAL.*?([0-9]{1,3})%/' test-analyse-service: stage: test-backend needs: - - build-analyse-service + - build-backend-analyse script: - "make test-analyse-service" - - "cat ./fda-analyse-service/coverage.txt | grep -o 'TOTAL[^%]*%'" + - "cat ./dbrepo-analyse-service/coverage.txt | grep -o 'TOTAL[^%]*%'" artifacts: when: always paths: - - ./fda-analyse-service/report.xml + - ./dbrepo-analyse-service/report.xml expire_in: 1 days reports: - junit: ./fda-analyse-service/report.xml + junit: ./dbrepo-analyse-service/report.xml coverage: '/TOTAL.*?([0-9]{1,3})%/' test-frontend: @@ -274,30 +274,33 @@ test-frontend: - build-frontend script: - "make test-frontend" - - "cat ./fda-ui/coverage.txt | grep -o 'Lines[^%]*%'" + - "cat ./dbrepo-ui/coverage/cobertura-coverage.xml | grep -o 'line-rate=\"[0-9.]*' | head -1" artifacts: when: always paths: - - ./fda-analyse-service/report.xml + - ./dbrepo-ui/coverage/ expire_in: 1 days reports: - junit: ./fda-analyse-service/report.xml + coverage_report: + coverage_format: cobertura + path: ./dbrepo-ui/coverage/cobertura-coverage.xml coverage: '/TOTAL.*?([0-9]{1,3})%/' build-docker: stage: build-docker needs: - - build-metadata-db - - build-identifier-service - - build-container-service - - build-database-service - - build-discovery-service - - build-gateway-service - - build-query-service - - build-table-service - - build-metadata-service - - build-semantics-service - - build-analyse-service + - build-backend-metadata-db + - build-backend-authentication + - build-backend-identifier + - build-backend-container + - build-backend-database + - build-backend-discovery + - build-backend-gateway + - build-backend-query + - build-backend-table + - build-backend-metadata + - build-backend-semantics + - build-backend-analyse script: - cp .env.unix.example .env - make build-docker diff --git a/.gitlab/clean.sh b/.gitlab/clean.sh new file mode 100755 index 0000000000000000000000000000000000000000..a9bf588e2f88457fdf73ac7361ef1d596fb81453 --- /dev/null +++ b/.gitlab/clean.sh @@ -0,0 +1 @@ +#!/bin/bash diff --git a/dbrepo-analyse-service/app.py b/dbrepo-analyse-service/app.py index 2d2b942e198d6a4906617550fe540823bace75b9..38ea705005fc8985ed6d69d2fd7aa5d5a12b298d 100644 --- a/dbrepo-analyse-service/app.py +++ b/dbrepo-analyse-service/app.py @@ -34,7 +34,7 @@ dictConfig({ app = Flask(__name__) metrics = PrometheusMetrics(app) -metrics.info('app_info', 'Application info', version='1.0.3') +metrics.info('app_info', 'Application info', version='1.2.0') app.config["SWAGGER"] = {"openapi": "3.0.1", "title": "Swagger UI", "uiversion": 3} swagger_config = { @@ -63,7 +63,7 @@ template = { "info": { "title": "Database Repository Analyse Service API", "description": "Service that analyses data structures", - "version": "1.1.0-alpha", + "version": "1.2.0", "contact": { "name": "Prof. Andreas Rauber", "email": "andreas.rauber@tuwien.ac.at" @@ -71,7 +71,11 @@ template = { "license": { "name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0" - } + }, + }, + "externalDocs": { + "description": "Sourcecode Documentation", + "url": "https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services" }, "servers": [ { @@ -79,8 +83,8 @@ template = { "description": "Generated server url" }, { - "url": "https://dbrepo2.tuwien.ac.at:5000", - "description": "DBRepo Sandbox" + "url": "https://dbrepo2.tuwien.ac.at", + "description": "Sandbox" } ] } diff --git a/dbrepo-analyse-service/build.sh b/dbrepo-analyse-service/build.sh index b0ef12fc4fc5f2b36746e97b6b962eeafa6a72ea..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100755 --- a/dbrepo-analyse-service/build.sh +++ b/dbrepo-analyse-service/build.sh @@ -1,4 +0,0 @@ -#!/bin/bash -python3 -m venv ./fda-analyse-service/venv -source ./fda-analyse-service/venv/bin/activate -pip install -r ./fda-analyse-service/requirements.txt \ No newline at end of file diff --git a/dbrepo-authentication-service/.gitignore b/dbrepo-authentication-service/.gitignore index 85af9a59d44aa0ebde3cc4e76933260d33a0bbf6..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-authentication-service/.gitignore +++ b/dbrepo-authentication-service/.gitignore @@ -1,3 +0,0 @@ -server.keystore -root.crt -intermediate.crt \ No newline at end of file diff --git a/dbrepo-authentication-service/README.md b/dbrepo-authentication-service/README.md deleted file mode 100644 index 71ea75fc91dd2706f5576db7ff730a526097b566..0000000000000000000000000000000000000000 --- a/dbrepo-authentication-service/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Authentication Service - -Attention: self-enrollment is not possible anymore (Keycloak) - -## Create Users - -- Visit [localhost:8443](https://localhost:8443) and login with default admin credentials `keycloak:keycloak` -- Select realm `dbrepo` -- Visit `Users` -> `Create` and set a non-temporary password - -## API - -### Create Token - -```console -curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' -d '{"client_id":"dbrepo-client","username":"ABC","password":"XYZ","client_secret":"123","grant_type":"password","scope":"openid"}' -``` diff --git a/dbrepo-broker-service/.gitignore b/dbrepo-broker-service/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..235705a2683908e9007ca57c55f98d5ee3738102 --- /dev/null +++ b/dbrepo-broker-service/.gitignore @@ -0,0 +1,5 @@ +.idea/ + +# Environment +.env +venv/ \ No newline at end of file diff --git a/dbrepo-broker-service/Dockerfile b/dbrepo-broker-service/Dockerfile index 4c82b98176f6a989e455c0a181f924a68bdb33cd..1b46c7899b8e9ab615e4e8d8f4e3876f09887106 100644 --- a/dbrepo-broker-service/Dockerfile +++ b/dbrepo-broker-service/Dockerfile @@ -1,5 +1,5 @@ ###### FIRST STAGE ###### -FROM fda-metadata-db:latest as dependency +FROM dbrepo-metadata-db:latest as dependency MAINTAINER Martin Weise <martin.weise@tuwien.ac.at> ###### SECOND STAGE ###### @@ -9,19 +9,19 @@ ENV PYTHONUNBUFFERED=1 ENV JWT_PUBKEY=public-key ENV JWT_CERT=cert -COPY ./rabbitmq.conf /etc/rabbitmq/ +RUN apk --no-cache add curl -RUN apk --no-cache add python3 py3-pip -COPY ./requirements.txt ./requirements.txt -RUN pip3 install -r ./requirements.txt +COPY ./rabbitmq.conf /etc/rabbitmq/rabbitmq.conf WORKDIR /app COPY ./init.sh ./init.sh -COPY ./register.py ./register.py +COPY ./service-register.sh ./service-register.sh COPY ./service_ready /usr/bin/service_ready COPY ./docker-entrypoint.sh ./docker-entrypoint.sh +RUN chmod +x ./service-register.sh + HEALTHCHECK --interval=10s --timeout=5s --retries=12 CMD service_ready ENTRYPOINT [ "bash", "/app/docker-entrypoint.sh" ] \ No newline at end of file diff --git a/dbrepo-broker-service/docker-entrypoint.sh b/dbrepo-broker-service/docker-entrypoint.sh index 9279f112c555bda657bc06bc2289ef352511428b..788bd0723fcc9d632b1c7713dcfeb14f490d2806 100755 --- a/dbrepo-broker-service/docker-entrypoint.sh +++ b/dbrepo-broker-service/docker-entrypoint.sh @@ -7,7 +7,7 @@ bash ./init.sh (sleep 10; rabbitmq-plugins enable rabbitmq_prometheus rabbitmq_mqtt rabbitmq_auth_backend_oauth2 rabbitmq_auth_mechanism_ssl; touch /ready) & # register with discovery service -python3 ./register.py -(while sleep 60; do python3 ./register.py; done) & +/app/service-register.sh broker-service 15672 15672 +(while sleep 60; do /app/service-register.sh broker-service 15672 15672; done) & rabbitmq-server \ No newline at end of file diff --git a/dbrepo-broker-service/rabbitmq.conf b/dbrepo-broker-service/rabbitmq.conf index 170b8b8fd231e3f9779e1a10297be7d719605062..34180dba38fe02a3eecaf36f9c63f7a4c72fc258 100644 --- a/dbrepo-broker-service/rabbitmq.conf +++ b/dbrepo-broker-service/rabbitmq.conf @@ -11,20 +11,4 @@ default_permissions.write = .* listeners.tcp.1 = 0.0.0.0:5672 # logging -log.console = true -log.console.level = warning - -# Obviously your authentication server cannot vouch for itself, so you'll need another backend with at least one user in -# it. You should probably use the internal database -auth_backends.1 = rabbit_auth_backend_oauth2 -auth_backends.2 = rabbit_auth_backend_internal - -# OAuth 2.0 files -auth_oauth2.resource_server_id = rabbitmq -#auth_oauth2.additional_scopes_key = my_custom_scope_key -auth_oauth2.preferred_username_claims = preferred_username -auth_oauth2.default_key = t2OCeCheJ9uwoBbNQjG_nN6WKiLcceTIAZmiTbGODFM -auth_oauth2.signing_keys.t2OCeCheJ9uwoBbNQjG_nN6WKiLcceTIAZmiTbGODFM = /app/cert.pem -auth_oauth2.signing_keys.id2 = /app/pubkey.pem -auth_oauth2.algorithms.1 = HS256 -auth_oauth2.algorithms.2 = RS256 +log.file.level = warning \ No newline at end of file diff --git a/dbrepo-broker-service/requirements.txt b/dbrepo-broker-service/requirements.txt deleted file mode 100644 index a9769d4356d3ddafd4129784314a88626b991c4e..0000000000000000000000000000000000000000 --- a/dbrepo-broker-service/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -py-eureka-client==0.11.3 -requests==2.28.2 \ No newline at end of file diff --git a/dbrepo-broker-service/service-register.sh b/dbrepo-broker-service/service-register.sh new file mode 100755 index 0000000000000000000000000000000000000000..6cda6f4300050619f8edd2ce09a7c224e5bf5512 --- /dev/null +++ b/dbrepo-broker-service/service-register.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +# $1 is used as the host name. + +EUREKA_HOST="discovery-service" +EUREKA_PORT="9090" +EUREKA_URI="http://$EUREKA_HOST:$EUREKA_PORT" + +SERVICE_NAME="$1" +SERVICE_PROTOCOL="http" +SERVICE_HOST="$1" +SECURE_PORT="${2:-9000}" +SERVICE_PORT="${3:-9000}" + +SERVICE_URI="$SERVICE_PROTOCOL://$SERVICE_HOST:$SERVICE_PORT" +HOME_URI="$SERVICE_URI/realms/dbrepo" +HEALTH_URI="$SERVICE_URI/health" + +# This is the URL shown in the "status" field in the +# instances section of the eureka dashboard. +# +# It's up to you to decide what the URL points to. Some +# information or status endpoint might be good. +STATUS_URI="$SERVICE_URI/health" + +# This is the name displayed to the right of the status +# on the eureka dashbard. If the app (FAKE_SERVICE) is +# registered with more than one hostname, they will be +# displayed as a comma-separated list. This hostname +# is part of the heartbeat message. +# +# If you'll have more than one host per service, +# make sure they have different host names. +HOST_NAME="${1:-fake01}" + +# Everyone of these parameters seem to be required. I don't know +# anything about secureVipAddress and vipAddress. +# +# dataCenterInfo must have a name of "MyOwn" or "Amazon". +# +# status can be UP, DOWN, STARTING, OUT_OF_SERVICE, UNKNOWN. +# if the registration status is STARTING, then the service +# will never be evicted. Also, simply sending a Heartbeat +# does not change the status. +# +# The metadata fields can be any information you want associated +# with a service. I recommend keeping it short. +# + +cat <<EOF > /tmp/json.json +{ + "instance": { + "instanceId": "$SERVICE_NAME:$SERVICE_NAME:$SERVICE_PORT", + "hostName": "$HOST_NAME", + "app": "$SERVICE_NAME", + "ipAddr": "$SERVICE_HOST", + "status": "UP", + "dataCenterInfo": { + "@class": "com.netflix.appinfo.MyDataCenterInfo", + "name": "MyOwn" + }, + "healthCheckUrl": "$HEALTH_URI", + "homePageUrl": "$HOME_URI", + "leaseInfo": { + "evictionDurationInSecs": 90 + }, + "metadata": { + "zone": "default", + "management.port": "15672" + }, + "port": { + "\$": "$SERVICE_PORT", + "@enabled": "true" + }, + "securePort": { + "\$": "$SECURE_PORT", + "@enabled": "false" + }, + "vipAddress": "$SERVICE_HOST", + "secureVipAddress": "$SERVICE_HOST", + "statusPageUrl": "$STATUS_URI" + } +} +EOF + +curl --header "content-type: application/json" --data-binary @/tmp/json.json --silent $EUREKA_URI/eureka/apps/$SERVICE_NAME diff --git a/dbrepo-container-service/Dockerfile b/dbrepo-container-service/Dockerfile index b9da313606275edea16aea4dbc5fb08067d1386e..71b0991dcc7e2f5c84f7cbb419621499a5258573 100644 --- a/dbrepo-container-service/Dockerfile +++ b/dbrepo-container-service/Dockerfile @@ -1,5 +1,5 @@ ###### FIRST STAGE ###### -FROM fda-metadata-db:latest as dependency +FROM dbrepo-metadata-db:latest as dependency MAINTAINER Martin Weise <martin.weise@tuwien.ac.at> ###### SECOND STAGE ###### @@ -24,6 +24,8 @@ FROM openjdk:11-jre-slim as runtime ENV METADATA_DB=fda ENV METADATA_USERNAME=root ENV METADATA_PASSWORD=dbrepo +ENV BROKER_USERNAME=fda +ENV BROKER_PASSWORD=fda ENV SHARED_FILESYSTEM=/tmp ENV USER_NETWORK=userdb ENV LOG_LEVEL=debug diff --git a/dbrepo-container-service/pom.xml b/dbrepo-container-service/pom.xml index 6e0ef2e8cf197d749442a97fd3b070f2bbc0eb54..8aa570d6a9d0cc0e55008680f3673039bae9c1e5 100644 --- a/dbrepo-container-service/pom.xml +++ b/dbrepo-container-service/pom.xml @@ -9,10 +9,10 @@ </parent> <groupId>at.tuwien</groupId> - <artifactId>fda-container-service</artifactId> - <version>1.1.0-alpha</version> - <name>fda-container-service</name> - <description>Demo project for Spring Boot</description> + <artifactId>dbrepo-container-service</artifactId> + <version>1.2.0</version> + <name>dbrepo-container-service</name> + <description>Service that manages the containers</description> <packaging>pom</packaging> <modules> @@ -93,13 +93,13 @@ <!-- Entity and API --> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-api</artifactId> + <artifactId>dbrepo-metadata-db-api</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-entites</artifactId> + <artifactId>dbrepo-metadata-db-entites</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> @@ -141,6 +141,11 @@ <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.version}</version> </dependency> + <dependency> + <groupId>at.tuwien</groupId> + <artifactId>dbrepo-metadata-db-test</artifactId> + <version>${project.version}</version> + </dependency> <!-- IDE --> <dependency> <groupId>org.projectlombok</groupId> @@ -198,7 +203,7 @@ <exclude>at/tuwien/exception/**/*</exclude> <exclude>at/tuwien/config/**/*</exclude> <exclude>at/tuwien/handlers/**/*</exclude> - <exclude>**/FdaContainerManagingApplication.class</exclude> + <exclude>**/DbrepoContainerManagingApplication.class</exclude> </excludes> </configuration> <executions> diff --git a/dbrepo-container-service/report/pom.xml b/dbrepo-container-service/report/pom.xml index 96d2563c70ec429f9ae71d09f4f241283a9744ee..a3d0645d2e1564d1449e547e10bb0d423944da5d 100644 --- a/dbrepo-container-service/report/pom.xml +++ b/dbrepo-container-service/report/pom.xml @@ -5,13 +5,13 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>at.tuwien</groupId> - <artifactId>fda-container-service</artifactId> - <version>1.1.0-alpha</version> + <artifactId>dbrepo-container-service</artifactId> + <version>1.2.0</version> </parent> <artifactId>report</artifactId> - <version>1.1.0-alpha</version> - <name>fda-container-service-report</name> + <version>1.2.0</version> + <name>dbrepo-container-service-report</name> <description> This module is only intended for the pipeline coverage report. See the detailed report in the respective modules diff --git a/dbrepo-container-service/rest-service/pom.xml b/dbrepo-container-service/rest-service/pom.xml index 1af0ddc12cd711c8092cbb6049ff7d40d420d2b6..6b8f4db7bfe77cb6b24631dab152c1eefcd4fdf7 100644 --- a/dbrepo-container-service/rest-service/pom.xml +++ b/dbrepo-container-service/rest-service/pom.xml @@ -5,13 +5,13 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>at.tuwien</groupId> - <artifactId>fda-container-service</artifactId> - <version>1.1.0-alpha</version> + <artifactId>dbrepo-container-service</artifactId> + <version>1.2.0</version> </parent> <artifactId>rest-service</artifactId> - <version>1.1.0-alpha</version> - <name>fda-container-service-rest-service</name> + <version>1.2.0</version> + <name>dbrepo-container-service-rest-service</name> <properties> <jacoco.version>0.8.7</jacoco.version> diff --git a/dbrepo-database-service/rest-service/src/main/java/at/tuwien/FdaDatabaseManagingApplication.java b/dbrepo-container-service/rest-service/src/main/java/at/tuwien/DbrepoContainerManagingApplication.java similarity index 86% rename from dbrepo-database-service/rest-service/src/main/java/at/tuwien/FdaDatabaseManagingApplication.java rename to dbrepo-container-service/rest-service/src/main/java/at/tuwien/DbrepoContainerManagingApplication.java index 2bca5007ce7517cae0ead89f47f00a0bc1826e22..816eac97eb01f48618670e9c0b27eb6e47ca18b9 100644 --- a/dbrepo-database-service/rest-service/src/main/java/at/tuwien/FdaDatabaseManagingApplication.java +++ b/dbrepo-container-service/rest-service/src/main/java/at/tuwien/DbrepoContainerManagingApplication.java @@ -11,13 +11,13 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @SpringBootApplication @EnableJpaAuditing @EnableTransactionManagement -@EnableJpaRepositories(basePackages = {"at.tuwien.repository.jpa"}) @EnableElasticsearchRepositories(basePackages = {"at.tuwien.repository.elastic"}) +@EnableJpaRepositories(basePackages = {"at.tuwien.repository.jpa"}) @EntityScan(basePackages = {"at.tuwien.entities"}) -public class FdaDatabaseManagingApplication { +public class DbrepoContainerManagingApplication { public static void main(String[] args) { - SpringApplication.run(FdaDatabaseManagingApplication.class, args); + SpringApplication.run(DbrepoContainerManagingApplication.class, args); } } diff --git a/dbrepo-container-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java b/dbrepo-container-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java index add40015407f18fccec5bcca8f0103c562b10447..4965870c94ad807b50c6108f48eae70cde674594 100644 --- a/dbrepo-container-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java +++ b/dbrepo-container-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Contact; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.servers.Server; import org.springdoc.core.GroupedOpenApi; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -12,6 +13,8 @@ import org.springframework.boot.info.BuildProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import java.util.List; + @Configuration public class SwaggerConfig { @@ -33,8 +36,14 @@ public class SwaggerConfig { .name("Apache 2.0") .url("https://www.apache.org/licenses/LICENSE-2.0"))) .externalDocs(new ExternalDocumentation() - .description("Wiki Documentation") - .url("https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services/-/wikis")); + .description("Sourcecode Documentation") + .url("https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services")) + .servers(List.of(new Server() + .description("Generated server url") + .url("http://localhost:9092"), + new Server() + .description("Sandbox") + .url("https://dbrepo2.tuwien.ac.at"))); } @Bean diff --git a/dbrepo-container-service/rest-service/src/main/java/at/tuwien/endpoints/ContainerEndpoint.java b/dbrepo-container-service/rest-service/src/main/java/at/tuwien/endpoints/ContainerEndpoint.java index 68c240908fdd3af73b52ddd6c0263b670910791a..0706ce0fd132d46d76075d39514364799b4ac371 100644 --- a/dbrepo-container-service/rest-service/src/main/java/at/tuwien/endpoints/ContainerEndpoint.java +++ b/dbrepo-container-service/rest-service/src/main/java/at/tuwien/endpoints/ContainerEndpoint.java @@ -1,6 +1,7 @@ package at.tuwien.endpoints; import at.tuwien.api.container.*; +import at.tuwien.api.error.ApiErrorDto; import at.tuwien.entities.container.Container; import at.tuwien.entities.user.User; import at.tuwien.exception.*; @@ -10,6 +11,10 @@ import at.tuwien.service.UserService; import at.tuwien.service.impl.ContainerServiceImpl; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; @@ -36,7 +41,7 @@ public class ContainerEndpoint { private final UserService userService; private final ContainerMapper containerMapper; - private final ContainerService containerService; + private final ContainerServiceImpl containerService; @Autowired public ContainerEndpoint(UserService userService, ContainerServiceImpl containerService, @@ -49,6 +54,13 @@ public class ContainerEndpoint { @GetMapping @Transactional(readOnly = true) @Operation(summary = "Find all containers") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "List containers", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ContainerBriefDto[].class))}), + }) public ResponseEntity<List<ContainerBriefDto>> findAll(Principal principal, @RequestParam(required = false) Integer limit) { log.debug("endpoint find all containers, principal={}, limit={}", principal, limit); @@ -76,6 +88,33 @@ public class ContainerEndpoint { @Transactional @PreAuthorize("hasAuthority('create-container')") @Operation(summary = "Create container", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "201", + description = "Created a new container", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ContainerBriefDto.class))}), + @ApiResponse(responseCode = "502", + description = "Docker client failed to connect", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Container image or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Container image or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "409", + description = "Container name already exists", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<ContainerBriefDto> create(@Valid @RequestBody ContainerCreateRequestDto data, @NotNull Principal principal) throws ImageNotFoundException, DockerClientException, ContainerAlreadyExistsException, @@ -91,6 +130,28 @@ public class ContainerEndpoint { @GetMapping("/{id}") @Transactional(readOnly = true) @Operation(summary = "Find some container") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "Found container", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ContainerDto.class))}), + @ApiResponse(responseCode = "502", + description = "Docker client failed to connect", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Container image could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "502", + description = "Connection to the container failed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<ContainerDto> findById(@NotNull @PathVariable("id") Long containerId) throws DockerClientException, ContainerNotFoundException, ContainerNotRunningException { log.debug("endpoint find container, id={}", containerId); @@ -107,6 +168,28 @@ public class ContainerEndpoint { @Timed(value = "container.modify", description = "Time needed to modify the container state") @PreAuthorize("hasAuthority('modify-container-state')") @Operation(summary = "Modify some container", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "Modified state of container successfully", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ContainerBriefDto.class))}), + @ApiResponse(responseCode = "404", + description = "Container or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Modification of container state is not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "409", + description = "Container is already started/stopped", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<ContainerBriefDto> modify(@NotNull @PathVariable("id") Long containerId, @Valid @RequestBody ContainerChangeDto changeDto, @NotNull Principal principal) @@ -138,12 +221,27 @@ public class ContainerEndpoint { @Timed(value = "container.delete", description = "Time needed to delete the container") @PreAuthorize("hasAuthority('delete-container')") @Operation(summary = "Delete some container", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Deleted container successfully", + content = {@Content}), + @ApiResponse(responseCode = "409", + description = "Container is still running", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "410", + description = "Container is already removed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<?> delete(@NotNull @PathVariable("id") Long containerId, @NotNull Principal principal) throws ContainerNotFoundException, ContainerStillRunningException, ContainerAlreadyRemovedException, DockerClientException { log.debug("endpoint delete container, containerId={}, principal={}", containerId, principal); containerService.remove(containerId); - return ResponseEntity.status(HttpStatus.ACCEPTED) + return ResponseEntity.accepted() .build(); } diff --git a/dbrepo-container-service/rest-service/src/main/java/at/tuwien/endpoints/ImageEndpoint.java b/dbrepo-container-service/rest-service/src/main/java/at/tuwien/endpoints/ImageEndpoint.java index 97a1ab755cdaf7a89471f4a7394ce35cd5bbfba6..fbd45d747b9dcf75567fa740f5b436411ed0db52 100644 --- a/dbrepo-container-service/rest-service/src/main/java/at/tuwien/endpoints/ImageEndpoint.java +++ b/dbrepo-container-service/rest-service/src/main/java/at/tuwien/endpoints/ImageEndpoint.java @@ -4,12 +4,17 @@ import at.tuwien.api.container.image.ImageBriefDto; import at.tuwien.api.container.image.ImageChangeDto; import at.tuwien.api.container.image.ImageCreateDto; import at.tuwien.api.container.image.ImageDto; +import at.tuwien.api.error.ApiErrorDto; import at.tuwien.entities.container.image.ContainerImage; import at.tuwien.exception.*; import at.tuwien.mapper.ImageMapper; import at.tuwien.service.impl.ImageServiceImpl; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; @@ -45,6 +50,13 @@ public class ImageEndpoint { @Transactional(readOnly = true) @Timed(value = "image.list", description = "Time needed to list the container images") @Operation(summary = "Find all images") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "List images", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ContainerImage[].class))}), + }) public ResponseEntity<List<ImageBriefDto>> findAll(@NotNull Principal principal) { log.debug("endpoint find all images, principal={}", principal); final List<ContainerImage> containers = imageService.getAll(); @@ -59,6 +71,33 @@ public class ImageEndpoint { @Timed(value = "image.create", description = "Time needed to create a container image") @PreAuthorize("hasAuthority('create-image')") @Operation(summary = "Create image", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "201", + description = "Created image", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ImageDto.class))}), + @ApiResponse(responseCode = "400", + description = "Image specification is invalid", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "User could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "502", + description = "Docker client failed to connect", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "409", + description = "Image already exists", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<ImageDto> create(@Valid @RequestBody ImageCreateDto data, @NotNull Principal principal) throws ImageNotFoundException, ImageAlreadyExistsException, DockerClientException, UserNotFoundException, ImageInvalidException { @@ -78,8 +117,19 @@ public class ImageEndpoint { @Transactional(readOnly = true) @Timed(value = "image.find", description = "Time needed to find a container image") @Operation(summary = "Find some image") - public ResponseEntity<ImageDto> findById(@NotNull @PathVariable Long id, - @NotNull Principal principal) throws ImageNotFoundException { + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "Found image", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ImageDto.class))}), + @ApiResponse(responseCode = "404", + description = "Image could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) + public ResponseEntity<ImageDto> findById(@NotNull @PathVariable Long id) throws ImageNotFoundException { log.debug("endpoint find image, id={}", id); final ContainerImage image = imageService.find(id); final ImageDto dto = imageMapper.containerImageToImageDto(image); @@ -93,6 +143,18 @@ public class ImageEndpoint { @Timed(value = "image.update", description = "Time needed to update a container image") @PreAuthorize("hasAuthority('modify-image')") @Operation(summary = "Update some image", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Updated image successfully", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ImageDto.class))}), + @ApiResponse(responseCode = "404", + description = "Image could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<ImageDto> update(@NotNull @PathVariable Long id, @RequestBody @Valid ImageChangeDto changeDto, @NotNull Principal principal) @@ -101,7 +163,7 @@ public class ImageEndpoint { final ContainerImage image = imageService.update(id, changeDto); final ImageDto dto = imageMapper.containerImageToImageDto(image); log.trace("update image resulted in image {}", dto); - return ResponseEntity.status(HttpStatus.ACCEPTED) + return ResponseEntity.accepted() .body(dto); } @@ -110,12 +172,22 @@ public class ImageEndpoint { @Timed(value = "image.delete", description = "Time needed to delete a container image") @PreAuthorize("hasAuthority('delete-image')") @Operation(summary = "Delete some image", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Deleted image successfully", + content = {@Content}), + @ApiResponse(responseCode = "404", + description = "Image could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<?> delete(@NotNull @PathVariable Long imageId, @NotNull Principal principal) throws ImageNotFoundException { log.debug("endpoint delete image, id={}, principal={}", imageId, principal); imageService.find(imageId); imageService.delete(imageId); - return ResponseEntity.status(HttpStatus.ACCEPTED) + return ResponseEntity.accepted() .build(); } diff --git a/dbrepo-container-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java b/dbrepo-container-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java index 2992a6141459711e2d8118e6ab375ed29a60316a..fa3ebffda00f7c1c5509529c04fbd47732918852 100644 --- a/dbrepo-container-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java +++ b/dbrepo-container-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java @@ -2,6 +2,7 @@ package at.tuwien.handlers; import at.tuwien.api.error.ApiErrorDto; import at.tuwien.exception.*; +import io.swagger.v3.oas.annotations.Hidden; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -14,6 +15,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExcep @ControllerAdvice public class ApiExceptionHandler extends ResponseEntityExceptionHandler { + @Hidden @ResponseStatus(HttpStatus.CONFLICT) @ExceptionHandler(ContainerAlreadyExistsException.class) public ResponseEntity<ApiErrorDto> handle(ContainerAlreadyExistsException e, WebRequest request) { @@ -25,6 +27,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(ContainerNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(ContainerNotFoundException e, WebRequest request) { @@ -36,6 +39,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) @ExceptionHandler(NotAllowedException.class) public ResponseEntity<ApiErrorDto> handle(NotAllowedException e, WebRequest request) { @@ -47,6 +51,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(ImageInvalidException.class) public ResponseEntity<ApiErrorDto> handle(ImageInvalidException e, WebRequest request) { @@ -58,17 +63,19 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.CONFLICT) + @Hidden + @ResponseStatus(HttpStatus.GONE) @ExceptionHandler(ContainerAlreadyRemovedException.class) public ResponseEntity<ApiErrorDto> handle(ContainerAlreadyRemovedException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.CONFLICT) + .status(HttpStatus.GONE) .message(e.getLocalizedMessage()) .code("error.container.alreadyremoved") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.CONFLICT) @ExceptionHandler(ContainerAlreadyRunningException.class) public ResponseEntity<ApiErrorDto> handle(ContainerAlreadyRunningException e, WebRequest request) { @@ -80,6 +87,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.CONFLICT) @ExceptionHandler(ContainerAlreadyStoppedException.class) public ResponseEntity<ApiErrorDto> handle(ContainerAlreadyStoppedException e, WebRequest request) { @@ -91,17 +99,19 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.CONFLICT) + @Hidden + @ResponseStatus(HttpStatus.BAD_GATEWAY) @ExceptionHandler(ContainerNotRunningException.class) public ResponseEntity<ApiErrorDto> handle(ContainerNotRunningException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.CONFLICT) + .status(HttpStatus.BAD_GATEWAY) .message(e.getLocalizedMessage()) .code("error.container.notrunning") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.CONFLICT) @ExceptionHandler(ContainerStillRunningException.class) public ResponseEntity<ApiErrorDto> handle(ContainerStillRunningException e, WebRequest request) { @@ -113,28 +123,31 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.BAD_REQUEST) + @Hidden + @ResponseStatus(HttpStatus.BAD_GATEWAY) @ExceptionHandler(DockerClientException.class) public ResponseEntity<ApiErrorDto> handle(DockerClientException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.BAD_REQUEST) + .status(HttpStatus.BAD_GATEWAY) .message(e.getLocalizedMessage()) .code("error.container.dockerclient") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.NOT_ACCEPTABLE) + @Hidden + @ResponseStatus(HttpStatus.CONFLICT) @ExceptionHandler(ImageAlreadyExistsException.class) public ResponseEntity<ApiErrorDto> handle(ImageAlreadyExistsException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.NOT_ACCEPTABLE) + .status(HttpStatus.CONFLICT) .message(e.getLocalizedMessage()) .code("error.image.exists") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(ImageNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(ImageNotFoundException e, WebRequest request) { @@ -146,6 +159,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.FORBIDDEN) @ExceptionHandler(PersistenceException.class) public ResponseEntity<ApiErrorDto> handle(PersistenceException e, WebRequest request) { @@ -157,6 +171,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(UserNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(UserNotFoundException e, WebRequest request) { diff --git a/dbrepo-container-service/rest-service/src/main/resources/application-local.yml b/dbrepo-container-service/rest-service/src/main/resources/application-local.yml index 4131f45893204bb670d966e4245f268e4116d9da..c02b1b829ce4a8a0588aa94e877bd255f82543bf 100644 --- a/dbrepo-container-service/rest-service/src/main/resources/application-local.yml +++ b/dbrepo-container-service/rest-service/src/main/resources/application-local.yml @@ -22,6 +22,10 @@ spring: name: container-service cloud: loadbalancer.ribbon.enabled: false + rabbitmq: + host: localhost + username: fda + password: fda management.endpoints.web.exposure.include: health,info,prometheus springdoc.swagger-ui.enabled: true server: diff --git a/dbrepo-container-service/rest-service/src/main/resources/application.yml b/dbrepo-container-service/rest-service/src/main/resources/application.yml index 7017818a8f68bdd4366857c6ee3b7fc47fe44bb2..4d1061d16429fb302b5ac943666a22dcf3fe4e7a 100644 --- a/dbrepo-container-service/rest-service/src/main/resources/application.yml +++ b/dbrepo-container-service/rest-service/src/main/resources/application.yml @@ -22,6 +22,10 @@ spring: name: container-service cloud: loadbalancer.ribbon.enabled: false + rabbitmq: + host: broker-service + username: "${BROKER_USERNAME}" + password: "${BROKER_PASSWORD}" management.endpoints.web.exposure.include: health,info,prometheus springdoc.swagger-ui.enabled: true server: diff --git a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java index 6dc27c2260a57820cbedf9516124bbb0283f1eba..01f84e12b909533314c3cc741739e02801e78ee5 100644 --- a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java +++ b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java @@ -1,331 +1,9 @@ package at.tuwien; -import at.tuwien.api.container.image.ImageEnvItemDto; -import at.tuwien.api.container.image.ImageEnvItemTypeDto; -import at.tuwien.api.user.GrantedAuthorityDto; -import at.tuwien.api.user.UserDetailsDto; -import at.tuwien.api.user.UserDto; -import at.tuwien.entities.container.Container; -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.user.User; -import com.github.dockerjava.api.model.HealthCheck; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; +import at.tuwien.test.BaseTest; import org.springframework.test.context.TestPropertySource; -import java.security.Principal; -import java.time.Instant; -import java.util.List; - -import static java.time.temporal.ChronoUnit.HOURS; - @TestPropertySource(locations = "classpath:application.properties") -public abstract class BaseUnitTest { - - public final static String JWT_1 = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJtd2Vpc2UiLCJybmQiOjk2NjIyNzAwMCwiZXhwIjoxNjczODg2MDk5LCJpYXQiOjE2NzM3OTk2OTl9.y1jqokCfZE7c_Ztt_nLQlf73jCYXPH5TZpCvo3RwS0C5azyrqLh03bphl6R8A24g6Kv_3qjzvnubNIwmO7y7pA"; - - public final static GrantedAuthorityDto RESEARCHER_AUTHORITY_DTO = GrantedAuthorityDto.builder() - .authority("ROLE_RESEARCHER") - .build(); - - public final static String USER_1_ID = "090dc12a-a46a-4515-b1f0-cff697d5f985"; - public final static String USER_1_USERNAME = "junit"; - public final static String USER_1_EMAIL = "junit@gmail.com"; - public final static String USER_1_AFFILIATION = "TU Wien"; - public final static Boolean USER_1_EMAIL_VERIFIED = false; - public final static Boolean USER_1_THEME_DARK = false; - public final static String USER_1_PASSWORD = "p455w0rdh45h"; - public final static String USER_1_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - public final static GrantedAuthority USER_1_AUTHORITY = new SimpleGrantedAuthority("ROLE_RESEARCHER"); - - public final static User USER_1 = User.builder() - .id(USER_1_ID) - .username(USER_1_USERNAME) - .email(USER_1_EMAIL) - .emailVerified(USER_1_EMAIL_VERIFIED) - .databasePassword(USER_1_DATABASE_PASSWORD) - .build(); - - public final static UserDto USER_1_DTO = UserDto.builder() - .id(USER_1_ID) - .username(USER_1_USERNAME) - .email(USER_1_EMAIL) - .emailVerified(USER_1_EMAIL_VERIFIED) - .build(); - - public final static UserDetails USER_1_DETAILS = UserDetailsDto.builder() - .id(USER_1_ID) - .username(USER_1_USERNAME) - .email(USER_1_EMAIL) - .password(USER_1_PASSWORD) - .authorities(List.of(new SimpleGrantedAuthority("ROLE_RESEARCHER"))) - .build(); - - public final static at.tuwien.api.amqp.UserDetailsDto USER_1_DETAILS_DTO = at.tuwien.api.amqp.UserDetailsDto.builder() - .name(USER_1_USERNAME) - .tags(new String[]{}) - .build(); - - public final static at.tuwien.api.amqp.UserDetailsDto USER_1_DETAILS_WITH_TAGS_DTO = at.tuwien.api.amqp.UserDetailsDto.builder() - .name(USER_1_USERNAME) - .tags(new String[]{"administrator"}) - .build(); - - public final static Principal USER_1_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_1_DETAILS, - USER_1_PASSWORD, USER_1_DETAILS.getAuthorities()); - - public final static String USER_2_ID = "0153f998-bd4c-4154-993e-75c355499044"; - public final static String USER_2_USERNAME = "dev"; - public final static String USER_2_EMAIL = "dev@gmail.com"; - public final static Boolean USER_2_EMAIL_VERIFIED = false; - public final static Boolean USER_2_THEME_DARK = false; - public final static String USER_2_PASSWORD = "p455w0rdh45"; - public final static String USER_2_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - public final static GrantedAuthority USER_2_AUTHORITY = new SimpleGrantedAuthority("ROLE_DEVELOPER"); - - public final static User USER_2 = User.builder() - .id(USER_2_ID) - .username(USER_2_USERNAME) - .email(USER_2_EMAIL) - .emailVerified(USER_2_EMAIL_VERIFIED) - .databasePassword(USER_2_DATABASE_PASSWORD) - .build(); - - public final static UserDetails USER_2_DETAILS = UserDetailsDto.builder() - .id(USER_2_ID) - .username(USER_2_USERNAME) - .email(USER_2_EMAIL) - .password(USER_2_PASSWORD) - .authorities(List.of(new SimpleGrantedAuthority("ROLE_DEVELOPER"))) - .build(); - - public final static at.tuwien.api.amqp.UserDetailsDto USER_2_DETAILS_DTO = at.tuwien.api.amqp.UserDetailsDto.builder() - .name(USER_2_USERNAME) - .tags(new String[]{}) - .build(); - - public final static Principal USER_2_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_2_DETAILS, - USER_2_PASSWORD, USER_2_DETAILS.getAuthorities()); - - public final static String USER_3_ID = "fea123c7-1851-4e01-969a-53407fa6a451"; - public final static String USER_3_USERNAME = "steward"; - public final static String USER_3_EMAIL = "steward@gmail.com"; - public final static Boolean USER_3_EMAIL_VERIFIED = false; - public final static Boolean USER_3_THEME_DARK = false; - public final static String USER_3_PASSWORD = "p455w0rdh45"; - public final static String USER_3_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - public final static GrantedAuthority USER_3_AUTHORITY = new SimpleGrantedAuthority("ROLE_DATA_STEWARD"); - - public final static User USER_3 = User.builder() - .id(USER_3_ID) - .username(USER_3_USERNAME) - .email(USER_3_EMAIL) - .emailVerified(USER_3_EMAIL_VERIFIED) - .databasePassword(USER_3_DATABASE_PASSWORD) - .build(); - - public final static UserDetails USER_3_DETAILS = UserDetailsDto.builder() - .id(USER_3_ID) - .username(USER_3_USERNAME) - .email(USER_3_EMAIL) - .password(USER_3_PASSWORD) - .authorities(List.of()) - .build(); - - public final static at.tuwien.api.amqp.UserDetailsDto USER_3_DETAILS_DTO = at.tuwien.api.amqp.UserDetailsDto.builder() - .name(USER_3_USERNAME) - .tags(new String[]{}) - .build(); - - public final static Principal USER_3_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_3_DETAILS, - USER_3_PASSWORD, USER_3_DETAILS.getAuthorities()); - - public final static String USER_4_ID = "824d2c13-78d9-43c5-a4af-288120e2b44b"; - public final static String USER_4_USERNAME = "nobody"; - public final static String USER_4_EMAIL = "nobody@gmail.com"; - public final static Boolean USER_4_EMAIL_VERIFIED = false; - public final static Boolean USER_4_THEME_DARK = false; - public final static String USER_4_PASSWORD = "p455w0rdh45"; - public final static String USER_4_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - - public final static User USER_4 = User.builder() - .id(USER_4_ID) - .username(USER_4_USERNAME) - .email(USER_4_EMAIL) - .emailVerified(USER_4_EMAIL_VERIFIED) - .databasePassword(USER_4_DATABASE_PASSWORD) - .build(); - - public final static String USER_5_ID = "d2f3a8f4-c7fe-49e8-9d14-6dad0f6b9406"; - public final static String USER_5_USERNAME = "mweise"; - public final static String USER_5_EMAIL = "mweise@gmail.com"; - public final static Boolean USER_5_EMAIL_VERIFIED = false; - public final static Boolean USER_5_THEME_DARK = false; - public final static String USER_5_PASSWORD = "p455w0rdh45"; - public final static String USER_5_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - - public final static UserDetailsDto USER_5_DETAILS_DTO = UserDetailsDto.builder() - .id(USER_5_ID) - .username(USER_5_USERNAME) - .email(USER_5_EMAIL) - .password(USER_5_PASSWORD) - .authorities(List.of()) - .build(); - - 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 = "83b40f2726e5"; - public final static Integer IMAGE_1_PORT = 3306; - 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 Long IMAGE_1_SIZE = 12000L; - public final static Instant IMAGE_1_BUILT = Instant.now().minus(38, 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("MARIADB_ROOT_PASSWORD") - .value("mariadb") - .type(ContainerImageEnvironmentItemType.PRIVILEGED_PASSWORD) - .build(), - ContainerImageEnvironmentItem.builder() - .iid(IMAGE_1_ID) - .key("UZERNAME") - .value("root") - .type(ContainerImageEnvironmentItemType.PRIVILEGED_USERNAME) - .build()); - - public final static List<ImageEnvItemDto> IMAGE_1_ENV_DTO = List.of(ImageEnvItemDto.builder() - .iid(IMAGE_1_ID) - .key("MARIADB_USER") - .value("mariadb") - .type(ImageEnvItemTypeDto.USERNAME) - .build(), - ImageEnvItemDto.builder() - .iid(IMAGE_1_ID) - .key("MARIADB_PASSWORD") - .value("mariadb") - .type(ImageEnvItemTypeDto.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) - .jdbcMethod(IMAGE_1_JDBC) - .dialect(IMAGE_1_DIALECT) - .driverClass(IMAGE_1_DRIVER) - .compiled(IMAGE_1_BUILT) - .size(IMAGE_1_SIZE) - .environment(IMAGE_1_ENV) - .defaultPort(IMAGE_1_PORT) - .build(); - - public final static Long IMAGE_2_ID = 2L; - public final static String IMAGE_2_REPOSITORY = "mysql"; - public final static String IMAGE_2_TAG = "8.0"; - public final static String IMAGE_2_HASH = "83b40f2726e5"; - public final static Integer IMAGE_2_PORT = 3306; - public final static String IMAGE_2_DIALECT = "org.hibernate.dialect.MySQLDialect"; - public final static String IMAGE_2_DRIVER = "com.mysql.jdbc.Driver"; - public final static String IMAGE_2_JDBC = "mysql"; - public final static Long IMAGE_2_SIZE = 12000L; - public final static Instant IMAGE_2_BUILT = Instant.now().minus(38, HOURS); - - public final static List<ImageEnvItemDto> IMAGE_2_ENV_DTO = List.of(ImageEnvItemDto.builder() - .iid(IMAGE_2_ID) - .key("MYSQL_USER") - .value("mysql") - .type(ImageEnvItemTypeDto.USERNAME) - .build(), - ImageEnvItemDto.builder() - .iid(IMAGE_2_ID) - .key("MYSQL_PASSWORD") - .value("mysql") - .type(ImageEnvItemTypeDto.PASSWORD) - .build()); - - public final static Long CONTAINER_1_ID = 1L; - public final static String CONTAINER_1_HASH = "deadbeef"; - public final static String CONTAINER_1_IP = "172.30.0.5"; - public final static String CONTAINER_1_NAME = "u01"; - public final static String CONTAINER_1_INTERNALNAME = "dbrepo-userdb-u01"; - public final static Instant CONTAINER_1_CREATED = Instant.now().minus(2, HOURS); - public final static Instant CONTAINER_1_UPDATED = Instant.now(); - public final static HealthCheck CONTAINER_1_HEALTHCHECK = new HealthCheck() - .withTest(List.of("CMD", "mysqladmin", "ping", "--host=127.0.0.1", "--password=mariadb")); - - public final static String[] CONTAINER_1_ENV = new String[]{"MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_USER=mariadb", - "MARIADB_PASSWORD=mariadb", "MARIADB_DATABASE=weather"}; - - public final static Container CONTAINER_1 = Container.builder() - .id(CONTAINER_1_ID) - .name(CONTAINER_1_NAME) - .hash(CONTAINER_1_HASH) - .internalName(CONTAINER_1_INTERNALNAME) - .created(CONTAINER_1_CREATED) - .lastModified(CONTAINER_1_UPDATED) - .ipAddress(CONTAINER_1_IP) - .imageId(IMAGE_1_ID) - .image(IMAGE_1) - .creator(USER_1) - .owner(USER_1) - .build(); - - public final static Long CONTAINER_2_ID = 2L; - public final static String CONTAINER_2_HASH = "deadbeef"; - public final static String CONTAINER_2_NAME = "u02"; - public final static String CONTAINER_2_INTERNALNAME = "dbrepo-userdb-u02"; - public final static String CONTAINER_2_IP = "172.30.0.6"; - public final static Instant CONTAINER_2_CREATED = Instant.now().minus(2, HOURS); - - public final static Container CONTAINER_2 = Container.builder() - .id(CONTAINER_2_ID) - .name(CONTAINER_2_NAME) - .internalName(CONTAINER_2_INTERNALNAME) - .imageId(IMAGE_1_ID) - .image(IMAGE_1) - .hash(CONTAINER_2_HASH) - .ipAddress(CONTAINER_2_IP) - .created(CONTAINER_2_CREATED) - .creator(USER_2) - .build(); - - public final static Long CONTAINER_3_ID = 3L; - public final static String CONTAINER_3_HASH = "deadbeef"; - public final static String CONTAINER_3_NAME = "u03"; - public final static String CONTAINER_3_INTERNALNAME = "dbrepo-userdb-u03"; - public final static String CONTAINER_3_DATABASE = "u03"; - public final static String CONTAINER_3_IP = "173.38.0.7"; - public final static Instant CONTAINER_3_CREATED = Instant.now().minus(2, HOURS); - - public final static Container CONTAINER_3 = Container.builder() - .id(CONTAINER_3_ID) - .name(CONTAINER_3_NAME) - .internalName(CONTAINER_3_INTERNALNAME) - .imageId(IMAGE_1_ID) - .image(IMAGE_1) - .hash(CONTAINER_3_HASH) - .ipAddress(CONTAINER_3_IP) - .created(CONTAINER_3_CREATED) - .build(); +public abstract class BaseUnitTest extends BaseTest { } diff --git a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/auth/AuthTokenFilterTest.java b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/auth/AuthTokenFilterTest.java index 8dd394b17deb79668c6a17fc70e4d2ea074629fb..b3ff7bc22a6cc1dfba7986372cc22f13ed52eff3 100644 --- a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/auth/AuthTokenFilterTest.java +++ b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/auth/AuthTokenFilterTest.java @@ -49,7 +49,7 @@ public class AuthTokenFilterTest extends BaseUnitTest { @Test public void doFilterInternal_notFound_fails() throws ServletException { final MockHttpServletRequest request = new MockHttpServletRequest(); - request.addHeader("Authorization", "Bearer " + JWT_1); + request.addHeader("Authorization", "Bearer " + null); final MockHttpServletResponse response = new MockHttpServletResponse(); final FilterChain chain = new MockFilterChain(); @@ -66,7 +66,7 @@ public class AuthTokenFilterTest extends BaseUnitTest { @Test public void doFilterInternal_succeeds() throws ServletException, IOException { final MockHttpServletRequest request = new MockHttpServletRequest(); - request.addHeader("Authorization", "Bearer " + JWT_1); + request.addHeader("Authorization", "Bearer " + null); final MockHttpServletResponse response = new MockHttpServletResponse(); final FilterChain chain = new MockFilterChain(); @@ -79,16 +79,6 @@ public class AuthTokenFilterTest extends BaseUnitTest { assertEquals(200, response.getStatus()); } - @Test - public void parseJwt_succeeds() { - final MockHttpServletRequest request = new MockHttpServletRequest(); - request.addHeader("Authorization", "Bearer " + JWT_1); - - /* test */ - final String response = authTokenFilter.parseJwt(request); - assertEquals(JWT_1, response); - } - @Test public void parseJwt_fails() { final MockHttpServletRequest request = new MockHttpServletRequest(); diff --git a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/config/DockerUtil.java b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/config/DockerUtil.java deleted file mode 100644 index 860dbd4259a86415347bb2872f43eb1a904aabff..0000000000000000000000000000000000000000 --- a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/config/DockerUtil.java +++ /dev/null @@ -1,79 +0,0 @@ -package at.tuwien.config; - -import at.tuwien.entities.container.Container; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.dockerjava.api.DockerClient; -import com.github.dockerjava.api.command.CreateContainerResponse; -import com.github.dockerjava.api.command.InspectContainerCmd; -import com.github.dockerjava.api.command.InspectContainerResponse; -import com.github.dockerjava.api.model.HostConfig; -import lombok.extern.log4j.Log4j2; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Configuration; - -import java.io.File; -import java.io.IOException; -import java.util.Objects; - -@Log4j2 -@Configuration -public class DockerUtil { - - private final HostConfig hostConfig; - private final DockerClient dockerClient; - - @Autowired - public DockerUtil(HostConfig hostConfig, DockerClient dockerClient) { - this.hostConfig = hostConfig; - this.dockerClient = dockerClient; - } - - public void createContainer(Container container) { - final CreateContainerResponse create = dockerClient.createContainerCmd(container.getImage().getRepository() + ":" + container.getImage().getTag()) - .withHostConfig(hostConfig.withNetworkMode("fda-userdb")) - .withName(container.getInternalName()) - .withIpv4Address(container.getIpAddress()) - .withHostName(container.getInternalName()) - .withEnv("MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_DATABASE=weather") - .exec(); - container.setHash(create.getId()); - log.info("container {} needs to be started", container.getHash()); - } - - public void startContainer(Container container) throws InterruptedException { - final InspectContainerResponse inspect = dockerClient.inspectContainerCmd(container.getHash()) - .exec(); - log.trace("container {} state {}", container.getHash(), inspect.getState().getStatus()); - if (Objects.equals(inspect.getState().getStatus(), "running")) { - return; - } - log.trace("container {} needs to be started", container.getHash()); - dockerClient.startContainerCmd(container.getHash()) - .exec(); - Thread.sleep(12 * 1000L); - log.info("container {} was started", container.getHash()); - } - - public void stopContainer(Container container) { - final InspectContainerResponse inspect = dockerClient.inspectContainerCmd(container.getHash()) - .exec(); - log.trace("container {} state {}", container.getHash(), inspect.getState().getStatus()); - if (!Objects.equals(inspect.getState().getStatus(), "running")) { - return; - } - log.trace("container {} needs to be stopped", container.getHash()); - dockerClient.stopContainerCmd(container.getHash()) - .exec(); - log.info("container {} was stopped", container.getHash()); - } - - public void removeContainer(Container container) { - stopContainer(container); - log.trace("container {} needs to be removed", container.getHash()); - dockerClient.removeContainerCmd(container.getHash()) - .exec(); - log.info("container {} was removed", container.getHash()); - } - -} diff --git a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/config/H2Utils.java b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/config/H2Utils.java deleted file mode 100644 index f7799c00a0765ab1549cda58b4524e1502664759..0000000000000000000000000000000000000000 --- a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/config/H2Utils.java +++ /dev/null @@ -1,37 +0,0 @@ -package at.tuwien.config; - -import lombok.extern.log4j.Log4j2; -import org.codehaus.plexus.util.FileUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -import javax.persistence.EntityManager; -import java.io.File; -import java.io.IOException; - -@Log4j2 -@Component -public class H2Utils { - - @Autowired - private EntityManager entityManager; - - @Transactional - public void runQuery(String query) { - log.debug("query={}", query); - entityManager.createNativeQuery(query) - .executeUpdate(); - } - - @Transactional - public void runScript(String scriptName) { - try { - runQuery(FileUtils.fileRead(new File("./src/test/resources/" + scriptName))); - } catch (IOException e) { - log.error("Failed to load script {}", scriptName); - throw new RuntimeException("Failed to load script", e); - } - } - -} diff --git a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java deleted file mode 100644 index 9ebb89afcf0b6656c0d4cf936effd1890cf4e5a7..0000000000000000000000000000000000000000 --- a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java +++ /dev/null @@ -1,43 +0,0 @@ -package at.tuwien.config; - -import at.tuwien.entities.database.table.Table; -import lombok.extern.log4j.Log4j2; -import org.springframework.beans.factory.annotation.Configurable; -import org.springframework.context.annotation.Bean; - -import java.sql.*; -import java.util.Properties; - -@Log4j2 -@Configurable -public class MariaDbConfig { - - @Bean - public Properties mariaDbProperties() { - final Properties properties = new Properties(); - properties.setProperty("MARIADB_USER", "mariadb"); - properties.setProperty("MARIADB_PASSWORD", "mariadb"); - return properties; - } - - public static void clearDatabase(Table table) throws SQLException { - final String jdbc = "jdbc:mariadb://" + table.getDatabase().getContainer().getInternalName() + "/" + table.getDatabase().getInternalName(); - log.trace("connect to database {}", jdbc); - final Connection connection = DriverManager.getConnection(jdbc, "mariadb", "mariadb"); - final Statement statement = connection.createStatement(); - statement.execute("DELETE FROM " + table.getInternalName() + ";"); - connection.close(); - } - - public static boolean contains(Table table, String column, Object expected) throws SQLException { - final String jdbc = "jdbc:mariadb://" + table.getDatabase().getContainer().getInternalName() + "/" + table.getDatabase().getInternalName(); - log.trace("connect to database {}", jdbc); - final Connection connection = DriverManager.getConnection(jdbc, "mariadb", "mariadb"); - final Statement statement = connection.createStatement(); - final ResultSet result = statement.executeQuery("SELECT `" + column + "` FROM " + table.getInternalName() + - " WHERE `" + column + "` = " + expected.toString() + ";"); - connection.close(); - return result.next(); - } - -} diff --git a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/endpoint/ContainerEndpointIntegrationTest.java b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/endpoint/ContainerEndpointIntegrationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..796974caf1d592c4feff97fcb96a2d2d00615ade --- /dev/null +++ b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/endpoint/ContainerEndpointIntegrationTest.java @@ -0,0 +1,546 @@ +package at.tuwien.endpoint; + +import at.tuwien.BaseUnitTest; +import at.tuwien.api.container.*; +import at.tuwien.config.ReadyConfig; +import at.tuwien.endpoints.ContainerEndpoint; +import at.tuwien.entities.container.Container; +import at.tuwien.exception.*; +import at.tuwien.repository.jpa.UserRepository; +import at.tuwien.service.impl.ContainerServiceImpl; +import lombok.extern.log4j.Log4j2; +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.security.access.AccessDeniedException; +import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException; +import org.springframework.security.test.context.support.WithAnonymousUser; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import java.security.Principal; +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +@Log4j2 +@ExtendWith(SpringExtension.class) +@SpringBootTest +public class ContainerEndpointIntegrationTest extends BaseUnitTest { + + @MockBean + private ReadyConfig readyConfig; + + @MockBean + private ContainerServiceImpl containerService; + + @MockBean + private UserRepository userRepository; + + @Autowired + private ContainerEndpoint containerEndpoint; + + @Test + public void findById_anonymous_succeeds() throws DockerClientException, ContainerNotFoundException, + ContainerNotRunningException { + + /* test */ + findById_generic(CONTAINER_1_ID, CONTAINER_1); + } + + @Test + @WithAnonymousUser + public void findById_anonymous2_succeeds() throws DockerClientException, ContainerNotFoundException, + ContainerNotRunningException { + + /* test */ + findById_generic(CONTAINER_1_ID, CONTAINER_1); + } + + @Test + @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) + public void findById_researcher_succeeds() throws DockerClientException, ContainerNotFoundException, + ContainerNotRunningException { + + /* mock */ + when(userRepository.findByUsername(USER_1_USERNAME)) + .thenReturn(Optional.of(USER_1)); + + /* test */ + findById_generic(CONTAINER_1_ID, CONTAINER_1); + } + + @Test + @WithMockUser(username = USER_2_USERNAME, roles = {"DEVELOPER"}) + public void findById_developer_succeeds() throws DockerClientException, ContainerNotFoundException, + ContainerNotRunningException { + + /* mock */ + when(userRepository.findByUsername(USER_2_USERNAME)) + .thenReturn(Optional.of(USER_2)); + + /* test */ + findById_generic(CONTAINER_1_ID, CONTAINER_1); + } + + @Test + @WithMockUser(username = USER_3_USERNAME, roles = {"DATA_STEWARD"}) + public void findById_dataSteward_succeeds() throws DockerClientException, ContainerNotFoundException, + ContainerNotRunningException { + + /* mock */ + when(userRepository.findByUsername(USER_3_USERNAME)) + .thenReturn(Optional.of(USER_3)); + + /* test */ + findById_generic(CONTAINER_1_ID, CONTAINER_1); + } + + @Test + public void delete_anonymous_fails() { + + /* test */ + assertThrows(AuthenticationCredentialsNotFoundException.class, () -> { + delete_generic(CONTAINER_1_ID, CONTAINER_1, null); + }); + } + + @Test + @WithAnonymousUser + public void delete_anonymous2_fails() { + + /* test */ + assertThrows(AccessDeniedException.class, () -> { + delete_generic(CONTAINER_1_ID, CONTAINER_1, null); + }); + } + + @Test + @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) + public void delete_researcher_fails() { + + /* mock */ + when(userRepository.findByUsername(USER_1_USERNAME)) + .thenReturn(Optional.of(USER_1)); + + /* test */ + assertThrows(AccessDeniedException.class, () -> { + delete_generic(CONTAINER_1_ID, CONTAINER_1, USER_1_PRINCIPAL); + }); + } + + @Test + @WithMockUser(username = USER_2_USERNAME, roles = {"DEVELOPER"}) + public void delete_developer_succeeds() throws ContainerStillRunningException, ContainerAlreadyRemovedException, + ContainerNotFoundException, DockerClientException { + + /* mock */ + when(userRepository.findByUsername(USER_2_USERNAME)) + .thenReturn(Optional.of(USER_2)); + + /* test */ + delete_generic(CONTAINER_1_ID, CONTAINER_1, USER_2_PRINCIPAL); + } + + @Test + @WithMockUser(username = USER_3_USERNAME, roles = {"DATA_STEWARD"}) + public void delete_dataSteward_fails() { + + /* mock */ + when(userRepository.findByUsername(USER_3_USERNAME)) + .thenReturn(Optional.of(USER_3)); + + /* test */ + assertThrows(AccessDeniedException.class, () -> { + delete_generic(CONTAINER_1_ID, CONTAINER_1, USER_3_PRINCIPAL); + }); + } + + @Test + public void findAll_anonymous_succeeds() { + + /* test */ + findAll_generic(null, null); + } + + @Test + @WithAnonymousUser + public void findAll_anonymous2_succeeds() { + + /* test */ + findAll_generic(null, null); + } + + @Test + @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) + public void findAll_researcher_succeeds() { + + /* mock */ + when(userRepository.findByUsername(USER_1_USERNAME)) + .thenReturn(Optional.of(USER_1)); + + /* test */ + findAll_generic(USER_1_PRINCIPAL, null); + } + + @Test + @WithMockUser(username = USER_2_USERNAME, roles = {"DEVELOPER"}) + public void findAll_developer_succeeds() { + + /* mock */ + when(userRepository.findByUsername(USER_2_USERNAME)) + .thenReturn(Optional.of(USER_2)); + + /* test */ + findAll_generic(USER_2_PRINCIPAL, null); + } + + @Test + @WithMockUser(username = USER_3_USERNAME, roles = {"DATA_STEWARD"}) + public void findAll_dataSteward_succeeds() { + + /* mock */ + when(userRepository.findByUsername(USER_3_USERNAME)) + .thenReturn(Optional.of(USER_3)); + + /* test */ + findAll_generic(USER_3_PRINCIPAL, null); + } + + @Test + public void create_anonymous_fails() { + final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder() + .name(CONTAINER_1_NAME) + .repository(IMAGE_1_REPOSITORY) + .tag(IMAGE_1_TAG) + .build(); + + /* test */ + assertThrows(AuthenticationCredentialsNotFoundException.class, () -> { + create_generic(request, null); + }); + } + + @Test + @WithAnonymousUser + public void create_anonymous2_fails() { + final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder() + .name(CONTAINER_1_NAME) + .repository(IMAGE_1_REPOSITORY) + .tag(IMAGE_1_TAG) + .build(); + + /* test */ + assertThrows(AccessDeniedException.class, () -> { + create_generic(request, null); + }); + } + + @Test + @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) + public void create_researcher_succeeds() throws UserNotFoundException, DockerClientException, + ContainerAlreadyExistsException, ImageNotFoundException { + final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder() + .name(CONTAINER_1_NAME) + .repository(IMAGE_1_REPOSITORY) + .tag(IMAGE_1_TAG) + .build(); + + /* mock */ + when(userRepository.findByUsername(USER_1_USERNAME)) + .thenReturn(Optional.of(USER_1)); + + /* test */ + create_generic(request, USER_1_PRINCIPAL); + } + + @Test + @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) + public void create_researcherEmpty_fails() throws UserNotFoundException, DockerClientException, + ContainerAlreadyExistsException, ImageNotFoundException { + + /* mock */ + when(userRepository.findByUsername(USER_1_USERNAME)) + .thenReturn(Optional.of(USER_1)); + + /* test */ + create_generic(null, USER_1_PRINCIPAL); + } + + @Test + @WithMockUser(username = USER_2_USERNAME, roles = {"DEVELOPER"}) + public void create_developer_fails() { + final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder() + .name(CONTAINER_1_NAME) + .repository(IMAGE_1_REPOSITORY) + .tag(IMAGE_1_TAG) + .build(); + + /* mock */ + when(userRepository.findByUsername(USER_2_USERNAME)) + .thenReturn(Optional.of(USER_2)); + + /* test */ + assertThrows(AccessDeniedException.class, () -> { + create_generic(request, USER_2_PRINCIPAL); + }); + } + + @Test + @WithMockUser(username = USER_3_USERNAME, roles = {"DATA_STEWARD"}) + public void create_dataSteward_fails() { + final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder() + .name(CONTAINER_1_NAME) + .repository(IMAGE_1_REPOSITORY) + .tag(IMAGE_1_TAG) + .build(); + + /* mock */ + when(userRepository.findByUsername(USER_3_USERNAME)) + .thenReturn(Optional.of(USER_3)); + + /* test */ + assertThrows(AccessDeniedException.class, () -> { + create_generic(request, USER_3_PRINCIPAL); + }); + } + + @Test + public void modify_anonymous_fails() { + + /* test */ + assertThrows(AuthenticationCredentialsNotFoundException.class, () -> { + modify_generic(ContainerActionTypeDto.START, CONTAINER_1_ID, CONTAINER_1, null); + }); + } + + @Test + @WithAnonymousUser + public void modify_anonymous2_fails() { + + /* test */ + assertThrows(AccessDeniedException.class, () -> { + modify_generic(ContainerActionTypeDto.START, CONTAINER_1_ID, CONTAINER_1, null); + }); + } + + @Test + @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) + public void modify_researcherStart_succeeds() throws ContainerAlreadyRunningException, + ContainerAlreadyStoppedException, ContainerNotFoundException, UserNotFoundException, NotAllowedException, + DockerClientException { + + /* mock */ + when(userRepository.findByUsername(USER_1_USERNAME)) + .thenReturn(Optional.of(USER_1)); + + /* test */ + modify_generic(ContainerActionTypeDto.START, CONTAINER_1_ID, CONTAINER_1, USER_1_PRINCIPAL); + } + + @Test + @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) + public void modify_researcherStart_fails() throws ContainerNotFoundException, ContainerAlreadyRunningException { + + /* mock */ + when(userRepository.findByUsername(USER_1_USERNAME)) + .thenReturn(Optional.of(USER_1)); + doThrow(ContainerAlreadyRunningException.class) + .when(containerService) + .start(CONTAINER_1_ID); + + /* test */ + assertThrows(ContainerAlreadyRunningException.class, () -> { + modify_generic(ContainerActionTypeDto.START, CONTAINER_1_ID, CONTAINER_1, USER_1_PRINCIPAL); + }); + } + + @Test + @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) + public void modify_researcherStop_succeeds() throws ContainerAlreadyRunningException, + ContainerAlreadyStoppedException, ContainerNotFoundException, UserNotFoundException, NotAllowedException, + DockerClientException { + + /* mock */ + when(userRepository.findByUsername(USER_1_USERNAME)) + .thenReturn(Optional.of(USER_1)); + + /* test */ + modify_generic(ContainerActionTypeDto.STOP, CONTAINER_1_ID, CONTAINER_1, USER_1_PRINCIPAL); + } + + @Test + @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) + public void modify_researcherStop_fails() throws ContainerAlreadyStoppedException, ContainerNotFoundException { + + /* mock */ + when(userRepository.findByUsername(USER_1_USERNAME)) + .thenReturn(Optional.of(USER_1)); + doThrow(ContainerAlreadyStoppedException.class) + .when(containerService) + .stop(CONTAINER_1_ID); + + + /* test */ + assertThrows(ContainerAlreadyStoppedException.class, () -> { + modify_generic(ContainerActionTypeDto.STOP, CONTAINER_1_ID, CONTAINER_1, USER_1_PRINCIPAL); + }); + } + + @Test + @WithMockUser(username = USER_2_USERNAME, roles = {"DEVELOPER"}) + public void modify_developerForeignStart_succeeds() throws UserNotFoundException, ContainerAlreadyRunningException, + NotAllowedException, ContainerAlreadyStoppedException, ContainerNotFoundException, DockerClientException { + + /* mock */ + when(userRepository.findByUsername(USER_2_USERNAME)) + .thenReturn(Optional.of(USER_2)); + + /* test */ + modify_generic(ContainerActionTypeDto.START, CONTAINER_1_ID, CONTAINER_1, USER_2_PRINCIPAL); + } + + @Test + @WithMockUser(username = USER_2_USERNAME, roles = {"DEVELOPER"}) + public void modify_developerForeignStop_succeeds() throws UserNotFoundException, ContainerAlreadyRunningException, + NotAllowedException, ContainerAlreadyStoppedException, ContainerNotFoundException, DockerClientException { + + /* mock */ + when(userRepository.findByUsername(USER_2_USERNAME)) + .thenReturn(Optional.of(USER_2)); + + /* test */ + modify_generic(ContainerActionTypeDto.STOP, CONTAINER_1_ID, CONTAINER_1, USER_2_PRINCIPAL); + } + + @Test + @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) + public void modify_researcherForeignStart_fails() { + + /* mock */ + when(userRepository.findByUsername(USER_1_USERNAME)) + .thenReturn(Optional.of(USER_1)); + + /* test */ + assertThrows(NotAllowedException.class, () -> { + modify_generic(ContainerActionTypeDto.START, CONTAINER_2_ID, CONTAINER_2, USER_1_PRINCIPAL); + }); + } + + @Test + @WithMockUser(username = USER_3_USERNAME, roles = {"DATA_STEWARD"}) + public void modify_dataStewardForeignStop_fails() { + + /* mock */ + when(userRepository.findByUsername(USER_3_USERNAME)) + .thenReturn(Optional.of(USER_3)); + + /* test */ + assertThrows(AccessDeniedException.class, () -> { + modify_generic(ContainerActionTypeDto.STOP, CONTAINER_1_ID, CONTAINER_1, USER_3_PRINCIPAL); + }); + } + + /* ################################################################################################### */ + /* ## GENERIC TEST CASES ## */ + /* ################################################################################################### */ + + public void findById_generic(Long containerId, Container container) throws DockerClientException, + ContainerNotFoundException, ContainerNotRunningException { + + /* mock */ + when(containerService.find(containerId)) + .thenReturn(container); + when(containerService.inspect(containerId)) + .thenReturn(container); + + /* test */ + final ResponseEntity<ContainerDto> response = containerEndpoint.findById(containerId); + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertNotNull(response.getBody()); + final ContainerDto dto = response.getBody(); + assertEquals(ContainerStateDto.RUNNING, dto.getState()); + } + + public void delete_generic(Long containerId, Container container, Principal principal) throws ContainerNotFoundException, + ContainerStillRunningException, ContainerAlreadyRemovedException, DockerClientException { + + /* mock */ + when(containerService.find(containerId)) + .thenReturn(container); + doNothing() + .when(containerService) + .remove(CONTAINER_1_ID); + + /* test */ + final ResponseEntity<?> response = containerEndpoint.delete(containerId, principal); + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + assertNull(response.getBody()); + } + + public void findAll_generic(Principal principal, Integer limit) { + + /* mock */ + when(containerService.getAll(limit)) + .thenReturn(List.of(CONTAINER_1, CONTAINER_2)); + + /* test */ + final ResponseEntity<List<ContainerBriefDto>> response = containerEndpoint.findAll(principal, limit); + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertNotNull(response.getBody()); + final List<ContainerBriefDto> body = response.getBody(); + assertEquals(2, body.size()); + final ContainerBriefDto container1 = body.get(0); + assertEquals(CONTAINER_1_ID, container1.getId()); + assertEquals(CONTAINER_1_NAME, container1.getName()); + assertEquals(CONTAINER_1_INTERNALNAME, container1.getInternalName()); + final ContainerBriefDto container2 = body.get(1); + assertEquals(CONTAINER_2_ID, container2.getId()); + assertEquals(CONTAINER_2_NAME, container2.getName()); + assertEquals(CONTAINER_2_INTERNALNAME, container2.getInternalName()); + } + + public void create_generic(ContainerCreateRequestDto data, Principal principal) throws UserNotFoundException, + DockerClientException, ContainerAlreadyExistsException, ImageNotFoundException { + + /* mock */ + when(containerService.create(data, principal)) + .thenReturn(CONTAINER_1); + + /* test */ + final ResponseEntity<ContainerBriefDto> response = containerEndpoint.create(data, principal); + assertEquals(HttpStatus.CREATED, response.getStatusCode()); + assertNotNull(response.getBody()); + } + + public void modify_generic(ContainerActionTypeDto data, Long containerId, Container container, Principal principal) + throws ContainerAlreadyRunningException, ContainerNotFoundException, ContainerAlreadyStoppedException, + UserNotFoundException, NotAllowedException, DockerClientException { + final ContainerChangeDto request = ContainerChangeDto.builder() + .action(data) + .build(); + + /* mock */ + when(containerService.find(containerId)) + .thenReturn(container); + if (data.equals(ContainerActionTypeDto.START)) { + when(containerService.start(containerId)) + .thenReturn(container); + } else if (data.equals(ContainerActionTypeDto.STOP)) { + when(containerService.stop(containerId)) + .thenReturn(container); + } + + /* test */ + final ResponseEntity<ContainerBriefDto> response = containerEndpoint.modify(containerId, request, principal); + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + assertNotNull(response.getBody()); + } + +} diff --git a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/endpoint/ContainerEndpointUnitTest.java b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/endpoint/ContainerEndpointUnitTest.java index cd82d0b81d9e7befddfea0c1018863fcf7c8670d..034f0b3272eecd064894e4ce49968fdb55af3bfe 100644 --- a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/endpoint/ContainerEndpointUnitTest.java +++ b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/endpoint/ContainerEndpointUnitTest.java @@ -2,7 +2,7 @@ package at.tuwien.endpoint; import at.tuwien.BaseUnitTest; import at.tuwien.api.container.*; -import at.tuwien.config.DockerConfig; +import at.tuwien.config.DockerDaemonConfig; import at.tuwien.config.ReadyConfig; import at.tuwien.endpoints.ContainerEndpoint; import at.tuwien.entities.container.Container; @@ -48,7 +48,7 @@ public class ContainerEndpointUnitTest extends BaseUnitTest { private ContainerEndpoint containerEndpoint; @Autowired - private DockerConfig dockerUtil; + private DockerDaemonConfig dockerUtil; @Test public void findById_anonymous_succeeds() throws DockerClientException, ContainerNotFoundException, diff --git a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/endpoint/ImageEndpointUnitTest.java b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/endpoint/ImageEndpointUnitTest.java index 9ef775d53dde5ee5f99ede094d4a1944dbd7a879..196beba9210366acc5c379c24ff6066ac6c2876e 100644 --- a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/endpoint/ImageEndpointUnitTest.java +++ b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/endpoint/ImageEndpointUnitTest.java @@ -5,7 +5,7 @@ import at.tuwien.api.container.image.ImageBriefDto; import at.tuwien.api.container.image.ImageChangeDto; import at.tuwien.api.container.image.ImageCreateDto; import at.tuwien.api.container.image.ImageDto; -import at.tuwien.config.DockerConfig; +import at.tuwien.config.DockerDaemonConfig; import at.tuwien.config.ReadyConfig; import at.tuwien.endpoints.ImageEndpoint; import at.tuwien.entities.container.image.ContainerImage; @@ -52,7 +52,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { private ImageEndpoint imageEndpoint; @Autowired - private DockerConfig dockerUtil; + private DockerDaemonConfig dockerUtil; @Test public void findAll_anonymous_succeeds() { @@ -231,7 +231,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { public void findById_anonymous_succeeds() throws ImageNotFoundException { /* test */ - findById_generic(IMAGE_1_ID, IMAGE_1, null); + findById_generic(IMAGE_1_ID, IMAGE_1); } @Test @@ -243,46 +243,10 @@ public class ImageEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(ImageNotFoundException.class, () -> { - imageEndpoint.findById(CONTAINER_1_ID, null); + imageEndpoint.findById(CONTAINER_1_ID); }); } - @Test - @WithMockUser(username = USER_1_USERNAME, roles = {"RESEARCHER"}) - public void findById_researcher_succeeds() throws ImageNotFoundException { - - /* mock */ - when(userRepository.findByUsername(USER_1_USERNAME)) - .thenReturn(Optional.of(USER_1)); - - /* test */ - findById_generic(IMAGE_1_ID, IMAGE_1, USER_1_PRINCIPAL); - } - - @Test - @WithMockUser(username = USER_2_USERNAME, roles = {"DEVELOPER"}) - public void findById_developer_succeeds() throws ImageNotFoundException { - - /* mock */ - when(userRepository.findByUsername(USER_2_USERNAME)) - .thenReturn(Optional.of(USER_2)); - - /* test */ - findById_generic(IMAGE_1_ID, IMAGE_1, USER_2_PRINCIPAL); - } - - @Test - @WithMockUser(username = USER_3_USERNAME, roles = {"DATA_STEWARD"}) - public void findById_dataSteward_succeeds() throws ImageNotFoundException { - - /* mock */ - when(userRepository.findByUsername(USER_3_USERNAME)) - .thenReturn(Optional.of(USER_3)); - - /* test */ - findById_generic(IMAGE_1_ID, IMAGE_1, USER_3_PRINCIPAL); - } - @Test public void delete_anonymous_fails() { @@ -484,14 +448,14 @@ public class ImageEndpointUnitTest extends BaseUnitTest { assertNotNull(response.getBody()); } - public void findById_generic(Long imageId, ContainerImage image, Principal principal) throws ImageNotFoundException { + public void findById_generic(Long imageId, ContainerImage image) throws ImageNotFoundException { /* mock */ when(imageRepository.findById(imageId)) .thenReturn(Optional.of(image)); /* test */ - final ResponseEntity<ImageDto> response = imageEndpoint.findById(imageId, principal); + final ResponseEntity<ImageDto> response = imageEndpoint.findById(imageId); assertEquals(HttpStatus.OK, response.getStatusCode()); assertNotNull(response.getBody()); } diff --git a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/ContainerServiceIntegrationTest.java b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/ContainerServiceIntegrationTest.java index fd1c316006658919c030f290a359b3a3bdb115fe..a1b1a93cd747ec3baa3029dc977745c041ce8c1a 100644 --- a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/ContainerServiceIntegrationTest.java +++ b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/ContainerServiceIntegrationTest.java @@ -2,21 +2,18 @@ package at.tuwien.service; import at.tuwien.BaseUnitTest; import at.tuwien.api.container.ContainerCreateRequestDto; -import at.tuwien.config.DockerUtil; +import at.tuwien.config.DockerConfig; +import at.tuwien.config.DockerDaemonConfig; import at.tuwien.config.ReadyConfig; import at.tuwien.entities.container.Container; +import at.tuwien.entities.container.image.ContainerImage; import at.tuwien.exception.*; import at.tuwien.repository.jpa.ContainerRepository; import at.tuwien.repository.jpa.ImageRepository; import at.tuwien.repository.jpa.UserRepository; -import com.github.dockerjava.api.DockerClient; -import com.github.dockerjava.api.exception.NotModifiedException; -import com.github.dockerjava.api.model.Network; import lombok.extern.log4j.Log4j2; 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.*; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -51,61 +48,45 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { @Autowired private ContainerService containerService; - @Autowired - private DockerUtil dockerUtil; - - @Autowired - private DockerClient dockerClient; + @BeforeAll + public static void beforeAll() { + afterAll(); + /* create networks */ + DockerConfig.createAllNetworks(); + } @BeforeEach public void beforeEach() { afterEach(); /* create networks */ - dockerClient.createNetworkCmd() - .withName("fda-userdb") - .withIpam(new Network.Ipam() - .withConfig(new Network.Ipam.Config() - .withSubnet("172.30.0.0/16"))) - .withEnableIpv6(false) - .exec(); - dockerClient.createNetworkCmd() - .withName("fda-public") - .withIpam(new Network.Ipam() - .withConfig(new Network.Ipam.Config() - .withSubnet("172.31.0.0/16"))) - .withEnableIpv6(false) - .exec(); - + DockerConfig.createAllNetworks(); /* mock data */ userRepository.save(USER_1); - imageRepository.save(IMAGE_1); + imageRepository.save(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) + .build()) /* keep */; } @AfterEach public void afterEach() { - /* stop containers and remove them */ - dockerClient.listContainersCmd() - .withShowAll(true) - .exec() - .forEach(container -> { - log.info("Delete container {}", container.getNames()[0]); - 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(); - }); + DockerConfig.removeAllContainers(); + DockerConfig.removeAllNetworks(); + } + + @AfterAll + public static void afterAll() { + DockerConfig.removeAllContainers(); + DockerConfig.removeAllNetworks(); } @Test @@ -183,7 +164,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { ContainerAlreadyRunningException { /* mock */ - dockerUtil.createContainer(CONTAINER_1); + DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV); containerRepository.save(CONTAINER_1); /* test */ @@ -191,12 +172,12 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { } @Test - public void change_stop_succeeds() throws DockerClientException, InterruptedException, ContainerNotFoundException, - ContainerAlreadyStoppedException { + public void change_stop_succeeds() throws DockerClientException, ContainerNotFoundException, + ContainerAlreadyStoppedException, InterruptedException { /* mock */ - dockerUtil.createContainer(CONTAINER_1); - dockerUtil.startContainer(CONTAINER_1); + DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.startContainer(CONTAINER_1); containerRepository.save(CONTAINER_1); /* test */ @@ -253,11 +234,12 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { @Test public void remove_succeeds() throws DockerClientException, ContainerStillRunningException, - ContainerNotFoundException, ContainerAlreadyRemovedException { + ContainerNotFoundException, ContainerAlreadyRemovedException, InterruptedException { /* mock */ - dockerUtil.createContainer(CONTAINER_1); - dockerUtil.stopContainer(CONTAINER_1); + DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.startContainer(CONTAINER_1); + DockerConfig.stopContainer(CONTAINER_1); containerRepository.save(CONTAINER_1); /* test */ @@ -277,8 +259,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { public void remove_stillRunning_fails() throws InterruptedException { /* mock */ - dockerUtil.createContainer(CONTAINER_1); - dockerUtil.startContainer(CONTAINER_1); + DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.startContainer(CONTAINER_1); containerRepository.save(CONTAINER_1); /* test */ @@ -291,8 +273,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { public void change_alreadyRunning_fails() throws InterruptedException { /* mock */ - dockerUtil.createContainer(CONTAINER_1); - dockerUtil.startContainer(CONTAINER_1); + DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.startContainer(CONTAINER_1); containerRepository.save(CONTAINER_1); /* test */ @@ -305,7 +287,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { public void change_startNotFound_fails() { /* mock */ - dockerUtil.createContainer(CONTAINER_1); + DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV); /* test */ assertThrows(ContainerNotFoundException.class, () -> { @@ -317,9 +299,9 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { public void change_alreadyStopped_fails() throws InterruptedException { /* mock */ - dockerUtil.createContainer(CONTAINER_1); - dockerUtil.startContainer(CONTAINER_1); - dockerUtil.stopContainer(CONTAINER_1); + DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.startContainer(CONTAINER_1); + DockerConfig.stopContainer(CONTAINER_1); containerRepository.save(CONTAINER_1); /* test */ @@ -332,7 +314,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { public void change_stopNeverStarted_fails() { /* mock */ - dockerUtil.createContainer(CONTAINER_1); + DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV); containerRepository.save(CONTAINER_1); /* test */ @@ -358,8 +340,8 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { ContainerNotRunningException { /* mock */ - dockerUtil.createContainer(CONTAINER_1); - dockerUtil.startContainer(CONTAINER_1); + DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.startContainer(CONTAINER_1); containerRepository.save(CONTAINER_1); /* test */ @@ -383,7 +365,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { public void inspect_notRunning_fails() { /* mock */ - dockerUtil.createContainer(CONTAINER_1); + DockerConfig.createContainer(null, CONTAINER_1, CONTAINER_1_ENV); containerRepository.save(CONTAINER_1); /* test */ diff --git a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/ImageServiceIntegrationTest.java b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/ImageServiceIntegrationTest.java index 485b565933144612dc034af019710f5aa3ddda64..67ce90b33c9de2ff69a4b2ce778aaccfe74f40a6 100644 --- a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/ImageServiceIntegrationTest.java +++ b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/ImageServiceIntegrationTest.java @@ -48,19 +48,19 @@ public class ImageServiceIntegrationTest extends BaseUnitTest { @BeforeEach public void beforeEach() { userRepository.save(USER_1); - final ContainerImage tmp = ContainerImage.builder() + imageRepository.save(ContainerImage.builder() + .id(IMAGE_1_ID) .repository(IMAGE_1_REPOSITORY) .tag(IMAGE_1_TAG) .hash(IMAGE_1_HASH) - .jdbcMethod(IMAGE_1_JDBC) + .compiled(IMAGE_1_BUILT) .dialect(IMAGE_1_DIALECT) + .jdbcMethod(IMAGE_1_JDBC) .driverClass(IMAGE_1_DRIVER) - .compiled(IMAGE_1_BUILT) .size(IMAGE_1_SIZE) .environment(IMAGE_1_ENV) .defaultPort(IMAGE_1_PORT) - .build(); - imageRepository.save(tmp); + .build()) /* keep */; } @Test diff --git a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/ImageServiceUnitTest.java b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/ImageServiceUnitTest.java index 2d8be88ad788e185db64c6e91ccfd7ad31f83b38..c86d1f2ee9a3a9157de87ba13f9a3132ca2bc923 100644 --- a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/ImageServiceUnitTest.java +++ b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/ImageServiceUnitTest.java @@ -100,7 +100,7 @@ public class ImageServiceUnitTest extends BaseUnitTest { } @Test - public void update_succeeds() throws ImageNotFoundException, DockerClientException { + public void update_succeeds() throws ImageNotFoundException { final ImageChangeDto request = ImageChangeDto.builder() .environment(IMAGE_1_ENV_DTO) .defaultPort(IMAGE_1_PORT) @@ -119,7 +119,7 @@ public class ImageServiceUnitTest extends BaseUnitTest { } @Test - public void update_port_succeeds() throws ImageNotFoundException, DockerClientException { + public void update_port_succeeds() throws ImageNotFoundException { final ImageChangeDto request = ImageChangeDto.builder() .environment(IMAGE_1_ENV_DTO) .defaultPort(9999) @@ -155,7 +155,7 @@ public class ImageServiceUnitTest extends BaseUnitTest { } @Test - public void delete_succeeds() throws ImageNotFoundException, PersistenceException { + public void delete_succeeds() throws ImageNotFoundException { /* mock */ doNothing() diff --git a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/PersistenceIntegrationTest.java b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/PersistenceIntegrationTest.java index 65f0dbcf6b3c27c1b4ed02e22499ebccf864a42c..5f52b3b6b5471645b6d305cce0a98bce86cd701e 100644 --- a/dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/PersistenceIntegrationTest.java +++ b/dbrepo-container-service/rest-service/src/test/java/at/tuwien/service/PersistenceIntegrationTest.java @@ -2,7 +2,6 @@ package at.tuwien.service; import at.tuwien.BaseUnitTest; import at.tuwien.config.ReadyConfig; -import at.tuwien.entities.container.image.ContainerImage; import at.tuwien.repository.jpa.ImageRepository; import at.tuwien.repository.jpa.UserRepository; import at.tuwien.service.impl.ImageServiceImpl; @@ -40,19 +39,7 @@ public class PersistenceIntegrationTest extends BaseUnitTest { @BeforeEach public void beforeEach() { userRepository.save(USER_1); - final ContainerImage tmp = ContainerImage.builder() - .repository(IMAGE_1_REPOSITORY) - .tag(IMAGE_1_TAG) - .hash(IMAGE_1_HASH) - .jdbcMethod(IMAGE_1_JDBC) - .dialect(IMAGE_1_DIALECT) - .driverClass(IMAGE_1_DRIVER) - .compiled(IMAGE_1_BUILT) - .size(IMAGE_1_SIZE) - .environment(IMAGE_1_ENV) - .defaultPort(IMAGE_1_PORT) - .build(); - imageRepository.save(tmp); + imageRepository.save(IMAGE_1); } @Test diff --git a/dbrepo-container-service/services/pom.xml b/dbrepo-container-service/services/pom.xml index 634ee9298ffe72242d4509d6741f68f31740edb8..e9aa0a94247aa3fe72a999e95a0c5fe882d9e306 100644 --- a/dbrepo-container-service/services/pom.xml +++ b/dbrepo-container-service/services/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> - <artifactId>fda-container-service</artifactId> + <artifactId>dbrepo-container-service</artifactId> <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </parent> <artifactId>services</artifactId> - <version>1.1.0-alpha</version> - <name>fda-container-service-services</name> + <version>1.2.0</version> + <name>dbrepo-container-service-services</name> <build> <plugins> diff --git a/dbrepo-container-service/services/src/main/java/at/tuwien/config/DockerConfig.java b/dbrepo-container-service/services/src/main/java/at/tuwien/config/DockerDaemonConfig.java similarity index 97% rename from dbrepo-container-service/services/src/main/java/at/tuwien/config/DockerConfig.java rename to dbrepo-container-service/services/src/main/java/at/tuwien/config/DockerDaemonConfig.java index de98cb54504afc4e69275862e38245ce8cf5964b..1d2dc0d6ecccb55f7a2a2dabe4b4d422b78464e2 100644 --- a/dbrepo-container-service/services/src/main/java/at/tuwien/config/DockerConfig.java +++ b/dbrepo-container-service/services/src/main/java/at/tuwien/config/DockerDaemonConfig.java @@ -15,7 +15,7 @@ import org.springframework.context.annotation.Configuration; @Getter @Configuration -public class DockerConfig { +public class DockerDaemonConfig { @Value("${fda.mount.path}") private String mountPath; diff --git a/dbrepo-container-service/services/src/main/java/at/tuwien/config/GatewayConfig.java b/dbrepo-container-service/services/src/main/java/at/tuwien/config/GatewayConfig.java index a6b06b72a439c55a13e231a6b48d1f04673f2c07..4dd0068634978d7fff069203febb24d69d02f845 100644 --- a/dbrepo-container-service/services/src/main/java/at/tuwien/config/GatewayConfig.java +++ b/dbrepo-container-service/services/src/main/java/at/tuwien/config/GatewayConfig.java @@ -1,24 +1,23 @@ package at.tuwien.config; -import lombok.Getter; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.support.BasicAuthenticationInterceptor; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.DefaultUriBuilderFactory; -@Getter @Configuration public class GatewayConfig { @Value("${fda.gateway.endpoint}") private String gatewayEndpoint; - @Value("${fda.client_secret}") - private String clientSecret; + @Value("${spring.rabbitmq.username}") + private String brokerUsername; - @Value("${fda.client_id}") - private String clientId; + @Value("${spring.rabbitmq.password}") + private String brokerPassword; @Bean public RestTemplate restTemplate() { @@ -27,4 +26,13 @@ public class GatewayConfig { return restTemplate; } + @Bean("brokerRestTemplate") + public RestTemplate brokerRestTemplate() { + final RestTemplate restTemplate = new RestTemplate(); + restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(gatewayEndpoint)); + restTemplate.getInterceptors() + .add(new BasicAuthenticationInterceptor(brokerUsername, brokerPassword)); + return restTemplate; + } + } diff --git a/dbrepo-container-service/services/src/main/java/at/tuwien/exception/ContainerAlreadyRemovedException.java b/dbrepo-container-service/services/src/main/java/at/tuwien/exception/ContainerAlreadyRemovedException.java index a0d550c09dfcc9c74e9d29b4f4083e4a341d8353..4764d2e33b9fcdf5aae6795c3c4f7119a1628203 100644 --- a/dbrepo-container-service/services/src/main/java/at/tuwien/exception/ContainerAlreadyRemovedException.java +++ b/dbrepo-container-service/services/src/main/java/at/tuwien/exception/ContainerAlreadyRemovedException.java @@ -3,7 +3,7 @@ package at.tuwien.exception; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; -@ResponseStatus(code = HttpStatus.CONFLICT) +@ResponseStatus(code = HttpStatus.GONE) public class ContainerAlreadyRemovedException extends Exception { public ContainerAlreadyRemovedException(String message) { diff --git a/dbrepo-container-service/services/src/main/java/at/tuwien/exception/ContainerNotRunningException.java b/dbrepo-container-service/services/src/main/java/at/tuwien/exception/ContainerNotRunningException.java index 3e82a681dae3d3e4c72f1e28512355bf941cfe93..303876312b04b15eaf4a90bfb40a11960f63bc99 100644 --- a/dbrepo-container-service/services/src/main/java/at/tuwien/exception/ContainerNotRunningException.java +++ b/dbrepo-container-service/services/src/main/java/at/tuwien/exception/ContainerNotRunningException.java @@ -3,7 +3,7 @@ package at.tuwien.exception; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; -@ResponseStatus(code = HttpStatus.CONFLICT,reason = "Container is not running") +@ResponseStatus(code = HttpStatus.BAD_GATEWAY, reason = "Container is not running") public class ContainerNotRunningException extends Exception { public ContainerNotRunningException(String message) { diff --git a/dbrepo-container-service/services/src/main/java/at/tuwien/exception/DockerClientException.java b/dbrepo-container-service/services/src/main/java/at/tuwien/exception/DockerClientException.java index 480f83583992c810e685741e4a684c39632f5c64..cb1126733add4adc5e0bfbe3d3eb9fcec095fd4e 100644 --- a/dbrepo-container-service/services/src/main/java/at/tuwien/exception/DockerClientException.java +++ b/dbrepo-container-service/services/src/main/java/at/tuwien/exception/DockerClientException.java @@ -3,7 +3,7 @@ package at.tuwien.exception; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; -@ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "Docker failed") +@ResponseStatus(code = HttpStatus.BAD_GATEWAY, reason = "Docker failed") public class DockerClientException extends Exception { public DockerClientException(String message) { diff --git a/dbrepo-container-service/services/src/main/java/at/tuwien/exception/ImageAlreadyExistsException.java b/dbrepo-container-service/services/src/main/java/at/tuwien/exception/ImageAlreadyExistsException.java index 3da4d5dfca29030d56f5beec7f85bbdfe089588c..b690b723b211f1ba656e47cb9915aa00950097b7 100644 --- a/dbrepo-container-service/services/src/main/java/at/tuwien/exception/ImageAlreadyExistsException.java +++ b/dbrepo-container-service/services/src/main/java/at/tuwien/exception/ImageAlreadyExistsException.java @@ -4,7 +4,7 @@ import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.server.ResponseStatusException; -@ResponseStatus(code = HttpStatus.NOT_ACCEPTABLE, reason = "Image already exists") +@ResponseStatus(code = HttpStatus.CONFLICT, reason = "Image already exists") public class ImageAlreadyExistsException extends Exception { public ImageAlreadyExistsException(String msg) { diff --git a/dbrepo-container-service/services/src/main/java/at/tuwien/service/ContainerService.java b/dbrepo-container-service/services/src/main/java/at/tuwien/service/ContainerService.java index 24400fa3549581fa098fbc101e9b2cfae17fe64f..badd04c8db0c8a4a6370a5312c0aa6dbde546a57 100644 --- a/dbrepo-container-service/services/src/main/java/at/tuwien/service/ContainerService.java +++ b/dbrepo-container-service/services/src/main/java/at/tuwien/service/ContainerService.java @@ -3,7 +3,6 @@ package at.tuwien.service; import at.tuwien.api.container.ContainerCreateRequestDto; import at.tuwien.entities.container.Container; import at.tuwien.exception.*; -import org.springframework.transaction.annotation.Transactional; import java.security.Principal; import java.util.List; diff --git a/dbrepo-container-service/services/src/main/java/at/tuwien/service/ImageService.java b/dbrepo-container-service/services/src/main/java/at/tuwien/service/ImageService.java index a76d32ab056c57ae1e8a6edab85d2eb60cdca29b..9c3fb46ca1cbf9e2d4d02d60c2fbb2dbab29e630 100644 --- a/dbrepo-container-service/services/src/main/java/at/tuwien/service/ImageService.java +++ b/dbrepo-container-service/services/src/main/java/at/tuwien/service/ImageService.java @@ -12,18 +12,18 @@ import java.util.List; public interface ImageService { /** - * Finds all container images in the metadata database + * Finds all container images in the metadata database. * - * @return A list of container images + * @return List of container images */ List<ContainerImage> getAll(); /** - * Finds a specific container image by given id + * Finds a specific container image by given id. * - * @param imageId The id. - * @return The image, if found. - * @throws ImageNotFoundException The image was not found + * @param imageId The image id. + * @return The image, if successful. + * @throws ImageNotFoundException The image was not found in the metadata database. */ ContainerImage find(Long imageId) throws ImageNotFoundException; @@ -31,39 +31,40 @@ public interface ImageService { * Creates a new container image in the metadata database. * * @param createDto The new image. - * @return The created container image, if successful. - * @throws ImageNotFoundException The image was not found in the remote repository (e.g. Docker Registry) - * @throws ImageAlreadyExistsException The image already exists. - * @throws DockerClientException The docker client encountered a problem. + * @param principal The user principal. + * @return The container image, if successful. + * @throws ImageNotFoundException The image was not found in the docker.io registry. + * @throws ImageAlreadyExistsException An image with this repository name and tag already exists. + * @throws DockerClientException The image could not be created due to the Docker daemon refusing to create it. + * @throws UserNotFoundException The user could not be found by the user principal. */ ContainerImage create(ImageCreateDto createDto, Principal principal) throws ImageNotFoundException, - ImageAlreadyExistsException, - DockerClientException, UserNotFoundException; + ImageAlreadyExistsException, DockerClientException, UserNotFoundException; /** - * Updates a container image in the metadata database by given id. + * Updates a container image with given id in the metadata database and pull an updated docker image from the docker.io repository. * - * @param imageId The id. + * @param imageId The image id. * @param changeDto The update request. * @return The updated container image, if successful. * @throws ImageNotFoundException The image was not found in the metadata database. - * @throws DockerClientException The docker client encountered a problem. + * @throws DockerClientException The image could not be updated due to the Docker daemon refusing to pull it. */ ContainerImage update(Long imageId, ImageChangeDto changeDto) throws ImageNotFoundException, DockerClientException; /** - * Deletes a container image in the metadata database by given id. + * Deletes a container image with given id in the metadata database. * - * @param id The id. + * @param imageId The image id. * @throws ImageNotFoundException The image was not found. * @throws PersistenceException The database returned an error. */ - void delete(Long id) throws ImageNotFoundException, PersistenceException; + void delete(Long imageId) throws ImageNotFoundException, PersistenceException; /** * Checks if an image exists locally. * - * @param repository The image name. + * @param repository The image repository. * @param tag The image tag. * @return True if the image exists, false otherwise. */ diff --git a/dbrepo-container-service/services/src/main/java/at/tuwien/service/UserService.java b/dbrepo-container-service/services/src/main/java/at/tuwien/service/UserService.java index 1134fa24d9c66d582052972654270b4da8450b62..89e0827ad14ccc65af7892800fc8c64936e7f850 100644 --- a/dbrepo-container-service/services/src/main/java/at/tuwien/service/UserService.java +++ b/dbrepo-container-service/services/src/main/java/at/tuwien/service/UserService.java @@ -5,5 +5,12 @@ import at.tuwien.exception.UserNotFoundException; public interface UserService { + /** + * Finds a user by username. + * + * @param username The username. + * @return The user, if successfully. + * @throws UserNotFoundException The user with this username was not found in the metadata database. + */ User findByUsername(String username) throws UserNotFoundException; } diff --git a/dbrepo-container-service/services/src/main/java/at/tuwien/service/impl/ContainerServiceImpl.java b/dbrepo-container-service/services/src/main/java/at/tuwien/service/impl/ContainerServiceImpl.java index ff1c9c22a92b423de396384aad61d124118157b0..34d1b40739bfed71782b54b49b76878fef19a005 100644 --- a/dbrepo-container-service/services/src/main/java/at/tuwien/service/impl/ContainerServiceImpl.java +++ b/dbrepo-container-service/services/src/main/java/at/tuwien/service/impl/ContainerServiceImpl.java @@ -1,7 +1,7 @@ package at.tuwien.service.impl; import at.tuwien.api.container.ContainerCreateRequestDto; -import at.tuwien.config.DockerConfig; +import at.tuwien.config.DockerDaemonConfig; import at.tuwien.entities.container.Container; import at.tuwien.entities.container.image.ContainerImage; import at.tuwien.entities.user.User; @@ -41,15 +41,15 @@ public class ContainerServiceImpl implements ContainerService { private final ImageMapper imageMapper; private final UserService userService; private final DockerClient dockerClient; - private final DockerConfig dockerConfig; private final ContainerMapper containerMapper; private final ImageRepository imageRepository; + private final DockerDaemonConfig dockerDaemonConfig; private final ContainerRepository containerRepository; @Autowired public ContainerServiceImpl(DockerClient dockerClient, ContainerRepository containerRepository, ImageRepository imageRepository, HostConfig hostConfig, ContainerMapper containerMapper, - ImageMapper imageMapper, UserService userService, DockerConfig dockerConfig) { + ImageMapper imageMapper, UserService userService, DockerDaemonConfig dockerDaemonConfig) { this.hostConfig = hostConfig; this.dockerClient = dockerClient; this.imageRepository = imageRepository; @@ -57,7 +57,7 @@ public class ContainerServiceImpl implements ContainerService { this.containerMapper = containerMapper; this.imageMapper = imageMapper; this.userService = userService; - this.dockerConfig = dockerConfig; + this.dockerDaemonConfig = dockerDaemonConfig; } @Override @@ -91,11 +91,11 @@ public class ContainerServiceImpl implements ContainerService { log.trace("created volume {}", response); /* create host mapping */ final HostConfig hostConfig = this.hostConfig - .withNetworkMode(dockerConfig.getUserNetwork()) - .withBinds(Bind.parse(dockerConfig.getMountPath() + ":/tmp"), Bind.parse(response.getName() + ":/var/lib/mysql")) + .withNetworkMode(dockerDaemonConfig.getUserNetwork()) + .withBinds(Bind.parse(dockerDaemonConfig.getMountPath() + ":/tmp"), Bind.parse(response.getName() + ":/var/lib/mysql")) .withPortBindings(PortBinding.parse(availableTcpPort + ":" + image.get().getDefaultPort())); log.debug("container has network {}, volume bind {}, volume bind {} and port bind {}", - dockerConfig.getUserNetwork(), dockerConfig.getMountPath() + ":/tmp", + dockerDaemonConfig.getUserNetwork(), dockerDaemonConfig.getMountPath() + ":/tmp", response.getName() + ":/var/lib/mysql", availableTcpPort + ":" + image.get().getDefaultPort()); log.trace("host config {}", hostConfig); final User user = userService.findByUsername(principal.getName()); @@ -122,7 +122,6 @@ public class ContainerServiceImpl implements ContainerService { container.setHash(response1.getId()); container = containerRepository.save(container); log.info("Created container {}", container.getId()); - log.trace("created container {}", container); return container; } @@ -131,14 +130,23 @@ public class ContainerServiceImpl implements ContainerService { public Container stop(Long containerId) throws ContainerNotFoundException, ContainerAlreadyStoppedException { final Container container = find(containerId); + final InspectContainerResponse response; try { + response = dockerClient.inspectContainerCmd(container.getHash()) + .withSize(true) + .exec(); + if (response.getState() == null || response.getState().getRunning() == null) { + log.warn("Failed to determine container state"); + } else if (!response.getState().getRunning()) { + throw new NotModifiedException("Already stopped"); + } dockerClient.stopContainerCmd(container.getHash()).exec(); } catch (NotFoundException e) { log.error("Failed to stop container: {}", e.getMessage()); - throw new ContainerNotFoundException("Failed to stop container", e); + throw new ContainerNotFoundException("Failed to stop container: " + e.getMessage(), e); } catch (NotModifiedException e) { log.warn("Failed to stop container: {}", e.getMessage()); - throw new ContainerAlreadyStoppedException("Failed to stop container", e); + throw new ContainerAlreadyStoppedException("Failed to stop container: " + e.getMessage(), e); } log.info("Stopped container with id {}", containerId); return container; @@ -178,8 +186,8 @@ public class ContainerServiceImpl implements ContainerService { @Override @Transactional - public Container inspect(Long id) - throws ContainerNotFoundException, DockerClientException, ContainerNotRunningException { + public Container inspect(Long id) throws ContainerNotFoundException, DockerClientException, + ContainerNotRunningException { final Container container = find(id); final InspectContainerResponse response; try { @@ -238,15 +246,24 @@ public class ContainerServiceImpl implements ContainerService { public Container start(Long containerId) throws ContainerNotFoundException, ContainerAlreadyRunningException { final Container container = find(containerId); + final InspectContainerResponse response; try { + response = dockerClient.inspectContainerCmd(container.getHash()) + .withSize(true) + .exec(); + if (response.getState() == null || response.getState().getRunning() == null) { + log.warn("Failed to determine container state"); + } else if (response.getState().getRunning()) { + throw new NotModifiedException("Already started"); + } dockerClient.startContainerCmd(container.getHash()) .exec(); } catch (NotFoundException e) { log.error("Failed to start container, not found: {}", e.getMessage()); - throw new ContainerNotFoundException("Failed to start container", e); + throw new ContainerNotFoundException("Failed to start container: " + e.getMessage(), e); } catch (NotModifiedException e) { log.warn("Failed to start container, already running: {}", e.getMessage()); - throw new ContainerAlreadyRunningException("Failed to start container", e); + throw new ContainerAlreadyRunningException("Failed to start container: " + e.getMessage(), e); } log.info("Started container with id {}", containerId); return container; diff --git a/dbrepo-database-service/Dockerfile b/dbrepo-database-service/Dockerfile index 1cbbf1a0f5c7c42811fca132c14dfe9e7499eb12..f287e8e51c0769f76dac8881c81ffc175aff4073 100644 --- a/dbrepo-database-service/Dockerfile +++ b/dbrepo-database-service/Dockerfile @@ -1,5 +1,5 @@ ###### FIRST STAGE ###### -FROM fda-metadata-db:latest as dependency +FROM dbrepo-metadata-db:latest as dependency MAINTAINER Martin Weise <martin.weise@tuwien.ac.at> ###### SECOND STAGE ###### diff --git a/dbrepo-database-service/pom.xml b/dbrepo-database-service/pom.xml index 38ddd1951ef3399adea2b3e86bd8f479fb125898..c86fd2464296304442a513cb70d1050fe4a16389 100644 --- a/dbrepo-database-service/pom.xml +++ b/dbrepo-database-service/pom.xml @@ -9,10 +9,10 @@ </parent> <groupId>at.tuwien</groupId> - <artifactId>fda-database-service</artifactId> - <version>1.1.0-alpha</version> - <name>fda-database-service</name> - <description>Demo project for Spring Boot</description> + <artifactId>dbrepo-database-service</artifactId> + <version>1.2.0</version> + <name>dbrepo-database-service</name> + <description>Service that manages the databases</description> <packaging>pom</packaging> <modules> @@ -69,7 +69,7 @@ <!-- Entities and API --> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-entites</artifactId> + <artifactId>dbrepo-metadata-db-entites</artifactId> <version>${project.version}</version> </dependency> <!-- Monitoring --> @@ -97,37 +97,27 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> - <dependency> - <groupId>org.postgresql</groupId> - <artifactId>postgresql</artifactId> - <version>${postgresql.version}</version> - </dependency> <dependency> <groupId>org.mariadb.jdbc</groupId> <artifactId>mariadb-java-client</artifactId> <version>${mariadb.version}</version> </dependency> - <dependency> - <groupId>mysql</groupId> - <artifactId>mysql-connector-java</artifactId> - <version>${mysql.version}</version> - </dependency> <!-- Entity, API, QueryStore --> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-api</artifactId> + <artifactId>dbrepo-metadata-db-api</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-entites</artifactId> + <artifactId>dbrepo-metadata-db-entites</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-querystore</artifactId> + <artifactId>dbrepo-metadata-db-querystore</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> @@ -158,6 +148,12 @@ <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.version}</version> </dependency> + <dependency> + <groupId>at.tuwien</groupId> + <artifactId>dbrepo-metadata-db-test</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> <!-- IDE --> <dependency> <groupId>org.projectlombok</groupId> diff --git a/dbrepo-database-service/report/pom.xml b/dbrepo-database-service/report/pom.xml index b8847c53058a7a4c13e90942aa26797911497f7c..dcdbc726d195a15425608a1aa7271608fb6597c6 100644 --- a/dbrepo-database-service/report/pom.xml +++ b/dbrepo-database-service/report/pom.xml @@ -5,12 +5,12 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>at.tuwien</groupId> - <artifactId>fda-database-service</artifactId> - <version>1.1.0-alpha</version> + <artifactId>dbrepo-database-service</artifactId> + <version>1.2.0</version> </parent> <artifactId>report</artifactId> - <name>fda-database-service-report</name> + <name>dbrepo-database-service-report</name> <properties> <jacoco.version>0.8.7</jacoco.version> diff --git a/dbrepo-database-service/rest-service/pom.xml b/dbrepo-database-service/rest-service/pom.xml index ea218383b2ba508fc4b20029012c577fbd693668..5af62c37cfa1bbd41d52d2ebb21c881b14a82faa 100644 --- a/dbrepo-database-service/rest-service/pom.xml +++ b/dbrepo-database-service/rest-service/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> - <artifactId>fda-database-service</artifactId> + <artifactId>dbrepo-database-service</artifactId> <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </parent> <artifactId>rest-service</artifactId> - <version>1.1.0-alpha</version> - <name>fda-database-service-rest-service</name> + <version>1.2.0</version> + <name>dbrepo-database-service-rest-service</name> <properties> <jacoco.version>0.8.7</jacoco.version> diff --git a/dbrepo-container-service/rest-service/src/main/java/at/tuwien/FdaContainerManagingApplication.java b/dbrepo-database-service/rest-service/src/main/java/at/tuwien/DbrepoDatabaseManagingApplication.java similarity index 87% rename from dbrepo-container-service/rest-service/src/main/java/at/tuwien/FdaContainerManagingApplication.java rename to dbrepo-database-service/rest-service/src/main/java/at/tuwien/DbrepoDatabaseManagingApplication.java index 5a351ba7529f7fa4175cc8abc7dcfafcb629ca9b..306944de33f8a180935fdbf6cd5aff3bf4b42667 100644 --- a/dbrepo-container-service/rest-service/src/main/java/at/tuwien/FdaContainerManagingApplication.java +++ b/dbrepo-database-service/rest-service/src/main/java/at/tuwien/DbrepoDatabaseManagingApplication.java @@ -11,13 +11,13 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @SpringBootApplication @EnableJpaAuditing @EnableTransactionManagement -@EnableElasticsearchRepositories(basePackages = {"at.tuwien.repository.elastic"}) @EnableJpaRepositories(basePackages = {"at.tuwien.repository.jpa"}) +@EnableElasticsearchRepositories(basePackages = {"at.tuwien.repository.elastic"}) @EntityScan(basePackages = {"at.tuwien.entities"}) -public class FdaContainerManagingApplication { +public class DbrepoDatabaseManagingApplication { public static void main(String[] args) { - SpringApplication.run(FdaContainerManagingApplication.class, args); + SpringApplication.run(DbrepoDatabaseManagingApplication.class, args); } } diff --git a/dbrepo-database-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java b/dbrepo-database-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java index 1c6908a85407be1eb46ebb25968e03d8a0d9843e..38208b7a49ba44c21d81f34734d81d423e5892af 100644 --- a/dbrepo-database-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java +++ b/dbrepo-database-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java @@ -5,11 +5,14 @@ import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Contact; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.servers.Server; import org.springdoc.core.GroupedOpenApi; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import java.util.List; + @Configuration public class SwaggerConfig { @@ -30,8 +33,14 @@ public class SwaggerConfig { .name("Apache 2.0") .url("https://www.apache.org/licenses/LICENSE-2.0"))) .externalDocs(new ExternalDocumentation() - .description("Wiki Documentation") - .url("https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services/-/wikis")); + .description("Sourcecode Documentation") + .url("https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services")) + .servers(List.of(new Server() + .description("Generated server url") + .url("http://localhost:9092"), + new Server() + .description("Sandbox") + .url("https://dbrepo2.tuwien.ac.at"))); } @Bean diff --git a/dbrepo-database-service/rest-service/src/main/java/at/tuwien/endpoints/AccessEndpoint.java b/dbrepo-database-service/rest-service/src/main/java/at/tuwien/endpoints/AccessEndpoint.java index 9f652ed3cafd9530b76c079952727fc080559bc9..a05d168cff50ca9447942d4da26a2bc05a19baf8 100644 --- a/dbrepo-database-service/rest-service/src/main/java/at/tuwien/endpoints/AccessEndpoint.java +++ b/dbrepo-database-service/rest-service/src/main/java/at/tuwien/endpoints/AccessEndpoint.java @@ -3,6 +3,7 @@ package at.tuwien.endpoints; import at.tuwien.api.database.DatabaseAccessDto; import at.tuwien.api.database.DatabaseGiveAccessDto; import at.tuwien.api.database.DatabaseModifyAccessDto; +import at.tuwien.api.error.ApiErrorDto; import at.tuwien.entities.database.DatabaseAccess; import at.tuwien.exception.*; import at.tuwien.mapper.DatabaseMapper; @@ -11,6 +12,10 @@ import at.tuwien.service.AccessService; import at.tuwien.service.ContainerService; import at.tuwien.service.DatabaseService; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; @@ -43,6 +48,26 @@ public class AccessEndpoint { @Transactional @PreAuthorize("hasAuthority('create-database-access')") @Operation(summary = "Give access to some database", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Granting access succeeded", + content = {@Content}), + @ApiResponse(responseCode = "400", + description = "Granting access query or database connection is malformed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database or user not found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Granting access not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<?> create(@NotBlank @PathVariable("id") Long containerId, @NotBlank @PathVariable("databaseId") Long databaseId, @Valid @RequestBody DatabaseGiveAccessDto accessDto, @@ -67,6 +92,26 @@ public class AccessEndpoint { @Transactional @PreAuthorize("hasAuthority('update-database-access')") @Operation(summary = "Modify access to some database", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Modify access succeeded", + content = {@Content}), + @ApiResponse(responseCode = "400", + description = "Modify access query or database connection is malformed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Modify access not permitted when no access is granted in the first place", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database or user not found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<?> update(@NotBlank @PathVariable("id") Long containerId, @NotBlank @PathVariable("databaseId") Long databaseId, @NotBlank @PathVariable("username") String username, @@ -86,6 +131,23 @@ public class AccessEndpoint { @Transactional @PreAuthorize("hasAuthority('check-database-access')") @Operation(summary = "Check access to some database", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "Found database access", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = DatabaseAccessDto.class))}), + @ApiResponse(responseCode = "403", + description = "No access to this database", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Check access is not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<DatabaseAccessDto> find(@NotBlank @PathVariable("id") Long containerId, @NotBlank @PathVariable("databaseId") Long databaseId, @NotNull Principal principal) throws NotAllowedException, @@ -102,6 +164,31 @@ public class AccessEndpoint { @Transactional @PreAuthorize("hasAuthority('delete-database-access')") @Operation(summary = "Revoke access to some database", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Revoked access successfully", + content = {@Content}), + @ApiResponse(responseCode = "400", + description = "Modify access query or database connection is malformed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "User with access was not found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Revoke of access not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Revoke of access not permitted as no access was found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<?> revoke(@NotBlank @PathVariable("id") Long containerId, @NotBlank @PathVariable("databaseId") Long databaseId, @NotBlank @PathVariable("username") String username, diff --git a/dbrepo-database-service/rest-service/src/main/java/at/tuwien/endpoints/DatabaseEndpoint.java b/dbrepo-database-service/rest-service/src/main/java/at/tuwien/endpoints/DatabaseEndpoint.java index 841d2d13a5423b0831015785b1013648a1cf978b..49bfda53cb04d4d74c0a4a433c2b9e701f5d4574 100644 --- a/dbrepo-database-service/rest-service/src/main/java/at/tuwien/endpoints/DatabaseEndpoint.java +++ b/dbrepo-database-service/rest-service/src/main/java/at/tuwien/endpoints/DatabaseEndpoint.java @@ -1,6 +1,7 @@ package at.tuwien.endpoints; import at.tuwien.api.database.*; +import at.tuwien.api.error.ApiErrorDto; import at.tuwien.entities.database.Database; import at.tuwien.entities.database.DatabaseAccess; import at.tuwien.entities.user.User; @@ -11,6 +12,10 @@ import at.tuwien.service.*; import at.tuwien.service.impl.MariaDbServiceImpl; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; @@ -57,6 +62,13 @@ public class DatabaseEndpoint { @Transactional(readOnly = true) @Timed(value = "database.list", description = "Time needed to list the databases") @Operation(summary = "List databases") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "List of databases", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = DatabaseBriefDto[].class))}), + }) public ResponseEntity<List<DatabaseBriefDto>> list(@NotNull @PathVariable("id") Long containerId, @NotNull Principal principal) { log.debug("endpoint list databases, containerId={}, principal={}", containerId, principal); @@ -73,6 +85,53 @@ public class DatabaseEndpoint { @PreAuthorize("hasAuthority('create-database')") @Timed(value = "database.create", description = "Time needed to create a database") @Operation(summary = "Create database", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "201", + description = "Created a new database", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = DatabaseBriefDto.class))}), + @ApiResponse(responseCode = "400", + description = "Database create query is malformed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Container, user or database could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Database create permission is missing or grant permissions at broker service failed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "406", + description = "Failed to create user at broker service or virtual host could not be reached at broker service", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "409", + description = "Database name already exist or query store could not be created", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "501", + description = "Container image is not supported", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "502", + description = "Connection to the container failed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "503", + description = "Connection to the database failed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<DatabaseBriefDto> create(@NotNull @PathVariable("id") Long containerId, @Valid @RequestBody DatabaseCreateDto createDto, @NotNull Principal principal) @@ -101,6 +160,23 @@ public class DatabaseEndpoint { @PreAuthorize("hasAuthority('modify-database-visibility')") @Timed(value = "database.visibility", description = "Time needed to modify a database visibility") @Operation(summary = "Update database", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Visibility modified successfully", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = DatabaseDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Visibility modification is not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<DatabaseDto> visibility(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable Long databaseId, @Valid @RequestBody DatabaseModifyVisibilityDto data, @@ -111,7 +187,7 @@ public class DatabaseEndpoint { final Database database = databaseService.visibility(containerId, databaseId, data); final DatabaseDto dto = databaseMapper.databaseToDatabaseDto(database); log.trace("update database resulted in database {}", dto); - return ResponseEntity.status(HttpStatus.ACCEPTED) + return ResponseEntity.accepted() .body(dto); } @@ -120,6 +196,23 @@ public class DatabaseEndpoint { @PreAuthorize("hasAuthority('modify-database-owner')") @Timed(value = "database.transfer", description = "Time needed to transfer a database ownership") @Operation(summary = "Transfer database", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Transfer of ownership was successful", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = DatabaseDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Transfer of ownership is not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<DatabaseDto> transfer(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable Long databaseId, @Valid @RequestBody DatabaseTransferDto transferDto, @@ -130,7 +223,7 @@ public class DatabaseEndpoint { final Database database = databaseService.transfer(containerId, databaseId, transferDto); final DatabaseDto dto = databaseMapper.databaseToDatabaseDto(database); log.trace("update database resulted in database {}", dto); - return ResponseEntity.status(HttpStatus.ACCEPTED) + return ResponseEntity.accepted() .body(dto); } @@ -138,6 +231,23 @@ public class DatabaseEndpoint { @Transactional(readOnly = true) @Timed(value = "database.find", description = "Time needed to find a database") @Operation(summary = "Find some database", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "Database found successfully", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = DatabaseDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Database information is not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<DatabaseDto> findById(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable Long databaseId, Principal principal) @@ -146,7 +256,7 @@ public class DatabaseEndpoint { final Database database = databaseService.findById(containerId, databaseId); final DatabaseDto dto = databaseMapper.databaseToDatabaseDto(database); if (principal != null && database.getOwner().getUsername().equals(principal.getName())) { - /* only owner sees the access rights */ + /* only owner sees the access rights */ // TODO improve this by proper mapping final List<DatabaseAccess> accesses = accessService.list(databaseId); dto.setAccesses(accesses.stream() .map(databaseMapper::databaseAccessToDatabaseAccessDto) @@ -161,19 +271,61 @@ public class DatabaseEndpoint { @PreAuthorize("hasAuthority('delete-database')") @Timed(value = "database.delete", description = "Time needed to delete a database") @Operation(summary = "Delete some database", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "201", + description = "Deleted a database", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = DatabaseBriefDto.class))}), + @ApiResponse(responseCode = "400", + description = "Database delete query is malformed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Container or database could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Database delete permission is missing or revoke permissions at broker service failed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "406", + description = "Failed to delete user at broker service or virtual host could not be reached at broker service", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "501", + description = "Container image is not supported", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "502", + description = "Connection to the container failed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "503", + description = "Connection to the database failed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<?> delete(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable Long databaseId, Principal principal) throws DatabaseNotFoundException, ImageNotSupportedException, DatabaseMalformedException, AmqpException, ContainerNotFoundException, QueryMalformedException, BrokerVirtualHostCreationException, UserNotFoundException, - DatabaseConnectionException, BrokerVirtualHostGrantException { + BrokerVirtualHostGrantException, DatabaseConnectionException { log.debug("endpoint delete database, containerId={}, databaseId={}, principal={}", containerId, databaseId, principal); final Database database = databaseService.findById(containerId, databaseId); messageQueueService.deleteExchange(database); databaseService.delete(containerId, databaseId, principal); messageQueueService.updatePermissions(principal); - return ResponseEntity.status(HttpStatus.ACCEPTED) + return ResponseEntity.accepted() .build(); } diff --git a/dbrepo-database-service/rest-service/src/main/java/at/tuwien/endpoints/LicenseEndpoint.java b/dbrepo-database-service/rest-service/src/main/java/at/tuwien/endpoints/LicenseEndpoint.java index 9e8cb566d1d3c87abc5d53c913da792339c8ad7f..3a05bdad9dfc92cfa7027dbed423c00b47a45deb 100644 --- a/dbrepo-database-service/rest-service/src/main/java/at/tuwien/endpoints/LicenseEndpoint.java +++ b/dbrepo-database-service/rest-service/src/main/java/at/tuwien/endpoints/LicenseEndpoint.java @@ -1,10 +1,16 @@ package at.tuwien.endpoints; +import at.tuwien.api.database.DatabaseBriefDto; import at.tuwien.api.database.LicenseDto; +import at.tuwien.api.error.ApiErrorDto; import at.tuwien.mapper.LicenseMapper; import at.tuwien.service.LicenseService; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -36,6 +42,13 @@ public class LicenseEndpoint { @Transactional(readOnly = true) @Timed(value = "license.list", description = "Time needed to list the licenses") @Operation(summary = "Get all licenses") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "List of licenses", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = DatabaseBriefDto.class))}), + }) public ResponseEntity<List<LicenseDto>> list(@NotBlank @PathVariable("id") Long containerId) { log.debug("endpoint list licenses, containerId={}", containerId); final List<LicenseDto> licenses = licenseService.findAll() diff --git a/dbrepo-database-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java b/dbrepo-database-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java index 1caa82558afe9471b706bd7e4a59dcadb6901b80..a9193b94f5e4780e1cbadaf42b8a2d787a44d51d 100644 --- a/dbrepo-database-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java +++ b/dbrepo-database-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java @@ -2,6 +2,7 @@ package at.tuwien.handlers; import at.tuwien.api.error.ApiErrorDto; import at.tuwien.exception.*; +import io.swagger.v3.oas.annotations.Hidden; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -14,6 +15,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExcep @ControllerAdvice public class ApiExceptionHandler extends ResponseEntityExceptionHandler { + @Hidden @ResponseStatus(HttpStatus.FORBIDDEN) @ExceptionHandler(AccessDeniedException.class) public ResponseEntity<ApiErrorDto> handle(AccessDeniedException e, WebRequest request) { @@ -25,6 +27,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(AmqpException.class) public ResponseEntity<ApiErrorDto> handle(AmqpException e, WebRequest request) { @@ -36,6 +39,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(BrokerMalformedException.class) public ResponseEntity<ApiErrorDto> handle(BrokerMalformedException e, WebRequest request) { @@ -47,6 +51,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_ACCEPTABLE) @ExceptionHandler(BrokerVirtualHostCreationException.class) public ResponseEntity<ApiErrorDto> handle(BrokerVirtualHostCreationException e, WebRequest request) { @@ -58,6 +63,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) @ExceptionHandler(BrokerVirtualHostGrantException.class) public ResponseEntity<ApiErrorDto> handle(BrokerVirtualHostGrantException e, WebRequest request) { @@ -69,17 +75,19 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.BAD_GATEWAY) + @Hidden + @ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE) @ExceptionHandler(ContainerConnectionException.class) public ResponseEntity<ApiErrorDto> handle(ContainerConnectionException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.BAD_GATEWAY) + .status(HttpStatus.SERVICE_UNAVAILABLE) .message(e.getLocalizedMessage()) .code("error.database.containerconnection") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(ContainerNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(ContainerNotFoundException e, WebRequest request) { @@ -91,6 +99,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.EXPECTATION_FAILED) @ExceptionHandler(ContainerUnauthorizedException.class) public ResponseEntity<ApiErrorDto> handle(ContainerUnauthorizedException e, WebRequest request) { @@ -102,6 +111,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) @ExceptionHandler(DatabaseConnectionException.class) public ResponseEntity<ApiErrorDto> handle(DatabaseConnectionException e, WebRequest request) { @@ -113,6 +123,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(DatabaseMalformedException.class) public ResponseEntity<ApiErrorDto> handle(DatabaseMalformedException e, WebRequest request) { @@ -124,6 +135,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.CONFLICT) @ExceptionHandler(DatabaseNameExistsException.class) public ResponseEntity<ApiErrorDto> handle(DatabaseNameExistsException e, WebRequest request) { @@ -135,6 +147,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(DatabaseNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(DatabaseNotFoundException e, WebRequest request) { @@ -146,6 +159,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(IdentifierNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(IdentifierNotFoundException e, WebRequest request) { @@ -157,17 +171,19 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.NOT_ACCEPTABLE) + @Hidden + @ResponseStatus(HttpStatus.NOT_IMPLEMENTED) @ExceptionHandler(ImageNotSupportedException.class) public ResponseEntity<ApiErrorDto> handle(ImageNotSupportedException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.NOT_ACCEPTABLE) + .status(HttpStatus.NOT_IMPLEMENTED) .message(e.getLocalizedMessage()) .code("error.database.imagenotsupported") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(LicenseNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(LicenseNotFoundException e, WebRequest request) { @@ -179,6 +195,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) @ExceptionHandler(NotAllowedException.class) public ResponseEntity<ApiErrorDto> handle(NotAllowedException e, WebRequest request) { @@ -190,6 +207,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(QueryMalformedException.class) public ResponseEntity<ApiErrorDto> handle(QueryMalformedException e, WebRequest request) { @@ -201,6 +219,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.CONFLICT) @ExceptionHandler(QueryStoreException.class) public ResponseEntity<ApiErrorDto> handle(QueryStoreException e, WebRequest request) { @@ -212,6 +231,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(SubjectNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(SubjectNotFoundException e, WebRequest request) { @@ -223,6 +243,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(UserNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(UserNotFoundException e, WebRequest request) { diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java index e1d061dc6dfb42386926e233cd9a49330d1d7a40..01f84e12b909533314c3cc741739e02801e78ee5 100644 --- a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java +++ b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java @@ -1,732 +1,9 @@ package at.tuwien; -import at.tuwien.api.amqp.CreateVirtualHostDto; -import at.tuwien.api.amqp.ExchangeDto; -import at.tuwien.api.amqp.GrantVirtualHostPermissionsDto; -import at.tuwien.api.database.*; -import at.tuwien.api.identifier.VisibilityTypeDto; -import at.tuwien.api.user.*; -import at.tuwien.api.database.DatabaseCreateDto; -import at.tuwien.api.database.LicenseDto; -import at.tuwien.entities.container.Container; -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.AccessType; -import at.tuwien.entities.database.Database; -import at.tuwien.entities.database.DatabaseAccess; -import at.tuwien.entities.database.License; -import at.tuwien.entities.database.table.Table; -import at.tuwien.entities.identifier.Identifier; -import at.tuwien.entities.identifier.IdentifierType; -import at.tuwien.entities.identifier.VisibilityType; -import at.tuwien.entities.user.User; -import com.github.dockerjava.api.model.HealthCheck; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; +import at.tuwien.test.BaseTest; import org.springframework.test.context.TestPropertySource; -import java.security.Principal; -import java.time.Instant; -import java.util.List; - -import static java.time.temporal.ChronoUnit.HOURS; - @TestPropertySource(locations = "classpath:application.properties") -public abstract class BaseUnitTest { - - public final static String JWT_1 = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJtd2Vpc2UiLCJybmQiOjk2NjIyNzAwMCwiZXhwIjoxNjczODg2MDk5LCJpYXQiOjE2NzM3OTk2OTl9.y1jqokCfZE7c_Ztt_nLQlf73jCYXPH5TZpCvo3RwS0C5azyrqLh03bphl6R8A24g6Kv_3qjzvnubNIwmO7y7pA"; - - public final static String VIRTUAL_HOST_NAME = "fda"; - public final static String VIRTUAL_HOST_DESCRIPTION = "FAIR Data Austria"; - public final static String VIRTUAL_HOST_TAGS = ""; - - public final static CreateVirtualHostDto VIRTUAL_HOST_CREATE_DTO = CreateVirtualHostDto.builder() - .name(VIRTUAL_HOST_NAME) - .description(VIRTUAL_HOST_DESCRIPTION) - .tags(VIRTUAL_HOST_TAGS) - .build(); - - public final static String GATEWAY_NAME = "fda-gateway-service"; - public final static String GATEWAY_IP = "172.31.0.3"; - public final static String GATEWAY_HOSTNAME = "gateway-service"; - public final static Integer GATEWAY_PORT = 9095; - public final static String GATEWAY_IMAGE = "nginx"; - public final static String GATEWAY_TAG = "alpine"; - - public final static String CONTAINER_SEARCH_NAME = "search-mock-service"; - public final static String CONTAINER_SEARCH_INTERNAL_NAME = "search-mock-service"; - public final static String CONTAINER_SEARCH_IP = "172.31.0.3"; - public final static String CONTAINER_SEARCH_REPOSITORY = "elasticsearch"; - public final static String CONTAINER_SEARCH_TAG = "7.13.4"; - - public final static String[] CONTAINER_SEARCH_ENV = new String[]{"discovery.type=single-node", "ES_JAVA_OPTS=-Xms512m -Xmx512m", - "logger.level=WARN"}; - - public final static ContainerImage IMAGE_SEARCH = ContainerImage.builder() - .repository(CONTAINER_SEARCH_REPOSITORY) - .tag(CONTAINER_SEARCH_TAG) - .environment(List.of()) - .build(); - - public final static Container CONTAINER_SEARCH = Container.builder() - .name(CONTAINER_SEARCH_NAME) - .internalName(CONTAINER_SEARCH_INTERNAL_NAME) - .ipAddress(CONTAINER_SEARCH_IP) - .image(IMAGE_SEARCH) - .build(); - - public final static String USER_1_ID = "090dc12a-a46a-4515-b1f0-cff697d5f985"; - public final static String USER_1_USERNAME = "junit"; - public final static String USER_1_PASSWORD = "junit"; - public final static String USER_1_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - public final static String USER_1_EMAIL = "junit@ossdip.at"; - public final static Boolean USER_1_VERIFIED = true; - public final static Boolean USER_1_THEME = false; - - public final static User USER_1 = User.builder() - .id(USER_1_ID) - .username(USER_1_USERNAME) - .email(USER_1_EMAIL) - .emailVerified(USER_1_VERIFIED) - .databasePassword(USER_1_DATABASE_PASSWORD) - .build(); - - public final static UserBriefDto USER_1_BRIEF_DTO = UserBriefDto.builder() - .id(USER_1_ID) - .username(USER_1_USERNAME) - .emailVerified(USER_1_VERIFIED) - .build(); - - public final static UserDto USER_1_DTO = UserDto.builder() - .id(USER_1_ID) - .username(USER_1_USERNAME) - .email(USER_1_EMAIL) - .emailVerified(USER_1_VERIFIED) - .build(); - - public final static UserDetails USER_1_DETAILS = UserDetailsDto.builder() - .id(USER_1_ID) - .username(USER_1_USERNAME) - .email(USER_1_EMAIL) - .password(USER_1_PASSWORD) - .authorities(List.of(new SimpleGrantedAuthority("ROLE_RESEARCHER"))) - .build(); - - public final static Principal USER_1_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_1_DETAILS, - USER_1_PASSWORD, USER_1_DETAILS.getAuthorities()); - - public final static String USER_2_ID = "0153f998-bd4c-4154-993e-75c355499044"; - public final static String USER_2_USERNAME = "dev"; - public final static String USER_2_EMAIL = "dev@gmail.com"; - public final static Boolean USER_2_EMAIL_VERIFIED = false; - public final static Boolean USER_2_THEME_DARK = false; - public final static String USER_2_PASSWORD = "p455w0rdh45"; - public final static String USER_2_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - public final static Boolean USER_2_VERIFIED = true; - public final static Boolean USER_2_THEME = false; - - public final static User USER_2 = User.builder() - .id(USER_2_ID) - .username(USER_2_USERNAME) - .email(USER_2_EMAIL) - .emailVerified(USER_2_VERIFIED) - .databasePassword(USER_2_DATABASE_PASSWORD) - .build(); - - public final static UserDto USER_2_DTO = UserDto.builder() - .id(USER_2_ID) - .username(USER_2_USERNAME) - .email(USER_2_EMAIL) - .emailVerified(USER_2_VERIFIED) - .build(); - - public final static UserBriefDto USER_2_BRIEF_DTO = UserBriefDto.builder() - .id(USER_2_ID) - .username(USER_2_USERNAME) - .emailVerified(USER_2_VERIFIED) - .build(); - - public final static UserDetails USER_2_DETAILS = UserDetailsDto.builder() - .username(USER_2_USERNAME) - .email(USER_2_EMAIL) - .password(USER_2_PASSWORD) - .authorities(List.of(new SimpleGrantedAuthority("ROLE_DEVELOPER"))) - .build(); - - public final static Principal USER_2_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_2_DETAILS, - USER_2_PASSWORD, USER_2_DETAILS.getAuthorities()); - - public final static String USER_3_ID = "fea123c7-1851-4e01-969a-53407fa6a451"; - public final static String USER_3_USERNAME = "steward"; - public final static String USER_3_EMAIL = "steward@gmail.com"; - public final static Boolean USER_3_EMAIL_VERIFIED = false; - public final static Boolean USER_3_THEME_DARK = false; - public final static String USER_3_PASSWORD = "p455w0rdh45"; - public final static String USER_3_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - public final static Boolean USER_3_VERIFIED = true; - public final static Boolean USER_3_THEME = false; - - public final static User USER_3 = User.builder() - .id(USER_3_ID) - .username(USER_3_USERNAME) - .email(USER_3_EMAIL) - .emailVerified(USER_3_EMAIL_VERIFIED) - .databasePassword(USER_3_DATABASE_PASSWORD) - .build(); - - public final static UserDto USER_3_DTO = UserDto.builder() - .id(USER_3_ID) - .username(USER_3_USERNAME) - .email(USER_3_EMAIL) - .emailVerified(USER_3_VERIFIED) - .build(); - - public final static UserDetails USER_3_DETAILS = UserDetailsDto.builder() - .username(USER_3_USERNAME) - .email(USER_3_EMAIL) - .password(USER_3_PASSWORD) - .authorities(List.of(new SimpleGrantedAuthority("ROLE_DEVELOPER"))) - .build(); - - public final static Principal USER_3_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_3_DETAILS, - USER_3_PASSWORD, USER_3_DETAILS.getAuthorities()); - - public final static String USER_4_ID = "824d2c13-78d9-43c5-a4af-288120e2b44b"; - public final static String USER_4_USERNAME = "nobody"; - public final static String USER_4_EMAIL = "nobody@gmail.com"; - public final static Boolean USER_4_EMAIL_VERIFIED = false; - public final static Boolean USER_4_THEME_DARK = false; - public final static String USER_4_PASSWORD = "p455w0rdh45"; - public final static String USER_4_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - - public final static User USER_4 = User.builder() - .id(USER_4_ID) - .username(USER_4_USERNAME) - .email(USER_4_EMAIL) - .emailVerified(USER_4_EMAIL_VERIFIED) - .databasePassword(USER_4_DATABASE_PASSWORD) - .build(); - - public final static UserDetails USER_4_DETAILS = UserDetailsDto.builder() - .username(USER_4_USERNAME) - .email(USER_4_EMAIL) - .password(USER_4_PASSWORD) - .authorities(List.of(new SimpleGrantedAuthority("ROLE_RESEARCHER"))) - .build(); - - public final static Principal USER_4_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_4_DETAILS, - USER_4_PASSWORD, USER_4_DETAILS.getAuthorities()); - - 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_CREATED = Instant.now().minus(40, HOURS); - public final static Instant IMAGE_1_UPDATED = Instant.now().minus(39, HOURS); - - public final static List<ContainerImageEnvironmentItem> IMAGE_1_ENVIRONMENT = List.of(ContainerImageEnvironmentItem.builder() - .iid(IMAGE_1_ID) - .type(ContainerImageEnvironmentItemType.PRIVILEGED_PASSWORD) - .key("MARIADB_ROOT_PASSWORD") - .value("mariadb") - .build(), - ContainerImageEnvironmentItem.builder() - .iid(IMAGE_1_ID) - .type(ContainerImageEnvironmentItemType.PRIVILEGED_USERNAME) - .key("UZERNAME") - .value("root") - .build(), - ContainerImageEnvironmentItem.builder() - .iid(IMAGE_1_ID) - .type(ContainerImageEnvironmentItemType.USERNAME) - .key("MARIADB_USER") - .value("mariadb") - .build(), - ContainerImageEnvironmentItem.builder() - .iid(IMAGE_1_ID) - .type(ContainerImageEnvironmentItemType.PASSWORD) - .key("MARIADB_PASSWORD") - .value("mariadb") - .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) - .size(IMAGE_1_SIZE) - .environment(IMAGE_1_ENVIRONMENT) - .dialect(IMAGE_1_DIALECT) - .driverClass(IMAGE_1_DRIVER) - .jdbcMethod(IMAGE_1_JDBC) - .created(IMAGE_1_CREATED) - .defaultPort(IMAGE_1_PORT) - .compiled(IMAGE_1_UPDATED) - .build(); - - public final static Long IMAGE_BROKER_ID = 2L; - public final static String IMAGE_BROKER_REPOSITORY = "rabbitmq"; - public final static String IMAGE_BROKER_TAG = "3-management-alpine"; - public final static String IMAGE_BROKER_HASH = "d6a5e003eae42397f7ee4589e9f21e231d3721ac131970d2286bd616e7f55bb4"; - public final static Integer IMAGE_BROKER_PORT = 15672; - public final static Long IMAGE_BROKER_SIZE = 12000L; - public final static Instant IMAGE_BROKER_BUILT = Instant.now().minus(40, HOURS); - - public final static ContainerImage IMAGE_BROKER = ContainerImage.builder() - .id(IMAGE_BROKER_ID) - .repository(IMAGE_BROKER_REPOSITORY) - .tag(IMAGE_BROKER_TAG) - .hash(IMAGE_BROKER_HASH) - .compiled(IMAGE_BROKER_BUILT) - .size(IMAGE_BROKER_SIZE) - .defaultPort(IMAGE_BROKER_PORT) - .build(); - - public final static Long IMAGE_ELASTIC_ID = 3L; - public final static String IMAGE_ELASTIC_REPOSITORY = "elasticsearch"; - public final static String IMAGE_ELASTIC_TAG = "7.13.4"; - public final static String IMAGE_ELASTIC_HASH = "d6a5e003eae42397f7ee4589e9f21e231d3721ac131970d2286bd616e7f55bb4"; - public final static Integer IMAGE_ELASTIC_PORT = 9200; - public final static Long IMAGE_ELASTIC_SIZE = 12000L; - public final static Instant IMAGE_ELASTIC_BUILT = Instant.now().minus(40, HOURS); - - public final static ContainerImage IMAGE_ELASTIC = ContainerImage.builder() - .id(IMAGE_ELASTIC_ID) - .repository(IMAGE_ELASTIC_REPOSITORY) - .tag(IMAGE_ELASTIC_TAG) - .hash(IMAGE_ELASTIC_HASH) - .compiled(IMAGE_ELASTIC_BUILT) - .size(IMAGE_ELASTIC_SIZE) - .defaultPort(IMAGE_ELASTIC_PORT) - .build(); - - public final static Long CONTAINER_BROKER_ID = 5L; - public final static String CONTAINER_BROKER_NAME = "dbrepo-broker-service"; - public final static String CONTAINER_BROKER_INTERNAL_NAME = "dbrepo-broker-service"; - public final static String CONTAINER_BROKER_IP = "172.31.0.2"; - public final static String CONTAINER_BROKER_HASH = "deadbeef"; - public final static Instant CONTAINER_BROKER_CREATED = Instant.now().minus(1, HOURS); - public final static HealthCheck CONTAINER_BROKER_HEALTHCHECK = new HealthCheck() - .withTest(List.of("CMD", "rabbitmq-diagnostics", "-q", "ping")); - public final static String[] CONTAINER_BROKER_ENV = new String[]{"RABBITMQ_DEFAULT_USER=fda", "RABBITMQ_DEFAULT_PASS=fda"}; - - public final static Container CONTAINER_BROKER = Container.builder() - .id(CONTAINER_BROKER_ID) - .name(CONTAINER_BROKER_NAME) - .internalName(CONTAINER_BROKER_INTERNAL_NAME) - .imageId(IMAGE_BROKER_ID) - .image(IMAGE_BROKER) - .ipAddress(CONTAINER_BROKER_IP) - .hash(CONTAINER_BROKER_HASH) - .created(CONTAINER_BROKER_CREATED) - .creator(USER_1) - .build(); - - public final static String LICENSE_1_IDENTIFIER = "MIT"; - public final static String LICENSE_1_URI = "https://opensource.org/licenses/MIT"; - - public final static License LICENSE_1 = License.builder() - .identifier(LICENSE_1_IDENTIFIER) - .uri(LICENSE_1_URI) - .build(); - - public final static LicenseDto LICENSE_1_DTO = LicenseDto.builder() - .identifier(LICENSE_1_IDENTIFIER) - .uri(LICENSE_1_URI) - .build(); - - public final static Long CONTAINER_1_ID = 1L; - public final static String CONTAINER_1_HASH = "deadbeef"; - public final static String CONTAINER_1_IP = "172.30.0.5"; - public final static String CONTAINER_1_NAME = "u01"; - public final static String CONTAINER_1_INTERNALNAME = "dbrepo-userdb-u01"; - public final static Instant CONTAINER_1_CREATED = Instant.now().minus(2, HOURS); - public final static Instant CONTAINER_1_UPDATED = Instant.now(); - public final static HealthCheck CONTAINER_1_HEALTHCHECK = new HealthCheck() - .withTest(List.of("CMD", "mysqladmin", "ping", "--host=127.0.0.1", "--password=mariadb")); - - public final static String[] CONTAINER_1_ENV = new String[]{"MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_USER=mariadb", - "MARIADB_PASSWORD=mariadb", "MARIADB_DATABASE=weather"}; - - public final static Container CONTAINER_1 = Container.builder() - .id(CONTAINER_1_ID) - .name(CONTAINER_1_NAME) - .hash(CONTAINER_1_HASH) - .internalName(CONTAINER_1_INTERNALNAME) - .created(CONTAINER_1_CREATED) - .lastModified(CONTAINER_1_UPDATED) - .ipAddress(CONTAINER_1_IP) - .imageId(IMAGE_1_ID) - .image(IMAGE_1) - .creator(USER_1) - .owner(USER_1) - .build(); - - public final static Long CONTAINER_2_ID = 2L; - public final static String CONTAINER_2_HASH = "deadbeef"; - public final static String CONTAINER_2_IP = "172.30.0.6"; - public final static String CONTAINER_2_NAME = "u02"; - public final static String CONTAINER_2_INTERNALNAME = "dbrepo-userdb-u02"; - public final static Instant CONTAINER_2_CREATED = Instant.now().minus(2, HOURS); - public final static Instant CONTAINER_2_UPDATED = Instant.now(); - public final static HealthCheck CONTAINER_2_HEALTHCHECK = new HealthCheck() - .withTest(List.of("CMD", "mysqladmin", "ping", "--host=127.0.0.1", "--password=mariadb")); - - public final static String[] CONTAINER_2_ENV = new String[]{"MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_USER=junit", - "MARIADB_PASSWORD=junit", "MARIADB_DATABASE=weather"}; - - public final static Container CONTAINER_2 = Container.builder() - .id(CONTAINER_2_ID) - .name(CONTAINER_2_NAME) - .hash(CONTAINER_2_HASH) - .internalName(CONTAINER_2_INTERNALNAME) - .created(CONTAINER_2_CREATED) - .lastModified(CONTAINER_2_UPDATED) - .ipAddress(CONTAINER_2_IP) - .imageId(IMAGE_1_ID) - .image(IMAGE_1) - .creator(USER_2) - .owner(USER_2) - .build(); - - public final static Long CONTAINER_3_ID = 3L; - public final static String CONTAINER_3_HASH = "deadbeef"; - public final static String CONTAINER_3_IP = "172.30.0.7"; - public final static String CONTAINER_3_NAME = "u03"; - public final static String CONTAINER_3_INTERNALNAME = "dbrepo-userdb-u03"; - public final static Instant CONTAINER_3_CREATED = Instant.now().minus(2, HOURS); - public final static Instant CONTAINER_3_UPDATED = Instant.now(); - public final static HealthCheck CONTAINER_3_HEALTHCHECK = new HealthCheck() - .withTest(List.of("CMD", "mysqladmin", "ping", "--host=127.0.0.1", "--password=mariadb")); - - public final static String[] CONTAINER_3_ENV = new String[]{"MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_USER=junit", - "MARIADB_PASSWORD=junit", "MARIADB_DATABASE=weather"}; - - public final static Container CONTAINER_3 = Container.builder() - .id(CONTAINER_3_ID) - .name(CONTAINER_3_NAME) - .hash(CONTAINER_3_HASH) - .internalName(CONTAINER_3_INTERNALNAME) - .created(CONTAINER_3_CREATED) - .lastModified(CONTAINER_3_UPDATED) - .ipAddress(CONTAINER_3_IP) - .imageId(IMAGE_1_ID) - .image(IMAGE_1) - .creator(USER_3) - .owner(USER_3) - .build(); - - public final static Long CONTAINER_4_ID = 4L; - public final static String CONTAINER_4_HASH = "deadbeef"; - public final static String CONTAINER_4_IP = "172.30.0.8"; - public final static String CONTAINER_4_NAME = "u04"; - public final static String CONTAINER_4_INTERNALNAME = "dbrepo-userdb-u04"; - public final static Instant CONTAINER_4_CREATED = Instant.now().minus(2, HOURS); - public final static Instant CONTAINER_4_UPDATED = Instant.now(); - public final static HealthCheck CONTAINER_4_HEALTHCHECK = new HealthCheck() - .withTest(List.of("CMD", "mysqladmin", "ping", "--host=127.0.0.1", "--password=mariadb")); - - public final static String[] CONTAINER_4_ENV = new String[]{"MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_USER=junit", - "MARIADB_PASSWORD=junit", "MARIADB_DATABASE=weather"}; - - public final static Container CONTAINER_4 = Container.builder() - .id(CONTAINER_4_ID) - .name(CONTAINER_4_NAME) - .hash(CONTAINER_4_HASH) - .internalName(CONTAINER_4_INTERNALNAME) - .created(CONTAINER_4_CREATED) - .lastModified(CONTAINER_4_UPDATED) - .ipAddress(CONTAINER_4_IP) - .imageId(IMAGE_1_ID) - .image(IMAGE_1) - .build(); - - public final static Long CONTAINER_ELASTIC_ID = 5L; - public final static String CONTAINER_ELASTIC_NAME = "fda-elastic-service"; - public final static String CONTAINER_ELASTIC_INTERNAL_NAME = "search-mock-service"; - public final static String CONTAINER_ELASTIC_IP = "172.31.0.3"; - public final static String CONTAINER_ELASTIC_HASH = "deadbeef"; - public final static Instant CONTAINER_ELASTIC_CREATED = Instant.now().minus(1, HOURS); - - public final static Container CONTAINER_ELASTIC = Container.builder() - .id(CONTAINER_ELASTIC_ID) - .name(CONTAINER_ELASTIC_NAME) - .internalName(CONTAINER_ELASTIC_INTERNAL_NAME) - .imageId(IMAGE_ELASTIC_ID) - .image(IMAGE_ELASTIC) - .hash(CONTAINER_ELASTIC_HASH) - .created(CONTAINER_ELASTIC_CREATED) - .creator(USER_1) - .build(); - - public final static Long DATABASE_1_ID = 1L; - public final static String DATABASE_1_NAME = "Weather AT"; - public final static String DATABASE_1_DESCRIPTION = "Weather somewhere in the world"; - public final static Boolean DATABASE_1_PUBLIC = false; - public final static String DATABASE_1_INTERNALNAME = "weather_at"; - public final static String DATABASE_1_EXCHANGE = "dbrepo." + DATABASE_1_INTERNALNAME; - public final static Instant DATABASE_1_CREATED = Instant.now().minus(1, HOURS); - public final static Instant DATABASE_1_UPDATED = Instant.now(); - - public final static Database DATABASE_1 = Database.builder() - .id(DATABASE_1_ID) - .name(DATABASE_1_NAME) - .internalName(DATABASE_1_INTERNALNAME) - .description(DATABASE_1_DESCRIPTION) - .isPublic(DATABASE_1_PUBLIC) - .container(CONTAINER_1) - .created(DATABASE_1_CREATED) - .creator(USER_1) - .owner(USER_1) - .tables(List.of()) - .lastModified(DATABASE_1_UPDATED) - .container(CONTAINER_1) - .exchangeName(DATABASE_1_EXCHANGE) - .build(); - - public final static DatabaseDto DATABASE_1_DTO = DatabaseDto.builder() - .id(DATABASE_1_ID) - .name(DATABASE_1_NAME) - .internalName(DATABASE_1_INTERNALNAME) - .description(DATABASE_1_DESCRIPTION) - .exchangeName(DATABASE_1_EXCHANGE) - .created(DATABASE_1_CREATED) - .build(); - - public final static ExchangeDto DATABASE_EXCHANGE_1 = ExchangeDto.builder() - .durable(false) - .autoDelete(false) - .type("direct") - .internal(false) - .vhost("/") - .name(DATABASE_1_EXCHANGE) - .build(); - - public final static DatabaseCreateDto DATABASE_1_CREATE = DatabaseCreateDto.builder() - .name(DATABASE_1_NAME) - .isPublic(DATABASE_1_PUBLIC) - .build(); - - public final static Long DATABASE_2_ID = 2L; - public final static String DATABASE_2_NAME = "Weather AT"; - public final static String DATABASE_2_DESCRIPTION = "Weather in Austria"; - public final static Boolean DATABASE_2_PUBLIC = false; - public final static String DATABASE_2_INTERNALNAME = "weather_de"; - public final static String DATABASE_2_EXCHANGE = "dbrepo." + DATABASE_2_INTERNALNAME; - public final static Instant DATABASE_2_CREATED = Instant.now().minus(2, HOURS); - public final static Instant DATABASE_2_UPDATED = Instant.now(); - - public final static Database DATABASE_2 = Database.builder() - .id(DATABASE_2_ID) - .name(DATABASE_2_NAME) - .internalName(DATABASE_2_INTERNALNAME) - .isPublic(DATABASE_2_PUBLIC) - .container(CONTAINER_2) - .created(DATABASE_2_CREATED) - .creator(USER_2) - .owner(USER_2) - .tables(List.of()) - .lastModified(DATABASE_2_UPDATED) - .container(CONTAINER_2) - .exchangeName(DATABASE_2_EXCHANGE) - .build(); - - public final static DatabaseDto DATABASE_2_DTO = DatabaseDto.builder() - .id(DATABASE_2_ID) - .name(DATABASE_2_NAME) - .internalName(DATABASE_2_INTERNALNAME) - .description(DATABASE_2_DESCRIPTION) - .exchangeName(DATABASE_2_EXCHANGE) - .created(DATABASE_2_CREATED) - .build(); - - public final static DatabaseCreateDto DATABASE_2_CREATE = DatabaseCreateDto.builder() - .name(DATABASE_2_NAME) - .isPublic(DATABASE_2_PUBLIC) - .build(); - - public final static Long DATABASE_3_ID = 3L; - public final static String DATABASE_3_NAME = "Weather"; - public final static String DATABASE_3_DESCRIPTION = "Weather in Austria"; - public final static Boolean DATABASE_3_PUBLIC = true; - public final static String DATABASE_3_INTERNALNAME = "weather"; - public final static String DATABASE_3_EXCHANGE = DATABASE_3_INTERNALNAME; - public final static Instant DATABASE_3_CREATED = Instant.now().minus(2, HOURS); - public final static Instant DATABASE_3_UPDATED = Instant.now(); - - public final static Database DATABASE_3 = Database.builder() - .id(DATABASE_3_ID) - .name(DATABASE_3_NAME) - .internalName(DATABASE_3_INTERNALNAME) - .isPublic(DATABASE_3_PUBLIC) - .container(CONTAINER_3) - .created(DATABASE_3_CREATED) - .creator(USER_3) - .owner(USER_3) - .tables(List.of()) - .lastModified(DATABASE_3_UPDATED) - .container(CONTAINER_3) - .exchangeName(DATABASE_3_EXCHANGE) - .build(); - - public final static DatabaseDto DATABASE_3_DTO = DatabaseDto.builder() - .id(DATABASE_3_ID) - .name(DATABASE_3_NAME) - .internalName(DATABASE_3_INTERNALNAME) - .description(DATABASE_3_DESCRIPTION) - .exchangeName(DATABASE_3_EXCHANGE) - .created(DATABASE_3_CREATED) - .build(); - - public final static DatabaseCreateDto DATABASE_3_CREATE = DatabaseCreateDto.builder() - .name(DATABASE_3_NAME) - .isPublic(DATABASE_3_PUBLIC) - .build(); - - public final static Long DATABASE_4_ID = 4L; - public final static String DATABASE_4_NAME = "Weather AT"; - public final static Boolean DATABASE_4_PUBLIC = false; - public final static String DATABASE_4_INTERNALNAME = "weather_at"; - public final static String DATABASE_4_EXCHANGE = DATABASE_4_INTERNALNAME; - public final static Instant DATABASE_4_CREATED = Instant.now().minus(2, HOURS); - public final static Instant DATABASE_4_UPDATED = Instant.now(); - - public final static DatabaseCreateDto DATABASE_4_CREATE = DatabaseCreateDto.builder() - .name(DATABASE_4_NAME) - .isPublic(DATABASE_4_PUBLIC) - .build(); - - public final static ExchangeUpdatePermissionsDto VIRTUAL_HOST_EXCHANGE_UPDATE_DTO = ExchangeUpdatePermissionsDto.builder() - .exchange(DATABASE_1_EXCHANGE) - .read(".*") - .write(".*") - .build(); - - public final static GrantVirtualHostPermissionsDto VIRTUAL_HOST_GRANT_DTO = GrantVirtualHostPermissionsDto.builder() - .read(".*") - .write(".*") - .configure(".*") - .build(); - - public final static Long TABLE_1_ID = 1L; - public final static String TABLE_1_NAME = "NYSE"; - public final static String TABLE_1_INTERNALNAME = "nyse"; - public final static String TABLE_1_QUEUE_NAME = "dbrepo." + DATABASE_1_INTERNALNAME + "." + TABLE_1_INTERNALNAME; - public final static String TABLE_1_ROUTING_KEY = TABLE_1_QUEUE_NAME; - - public final static Table TABLE_1 = Table.builder() - .id(TABLE_1_ID) - .name(TABLE_1_NAME) - .internalName(TABLE_1_INTERNALNAME) - .queueName(TABLE_1_QUEUE_NAME) - .routingKey(TABLE_1_ROUTING_KEY) - .tdbid(DATABASE_1_ID) - .database(DATABASE_1) - .build(); - - public final static Long QUERY_1_ID = 1L; - public final static String QUERY_1_STATEMENT = "SELECT `id`, `date`, `location`, `mintemp`, `rainfall` FROM " + - "`weather_aus`"; - - public final static Long QUERY_2_ID = 2L; - public final static String QUERY_2_STATEMENT = "SELECT `date`, `location`, `mintemp`, `rainfall`, `id` FROM " + - "`weather_aus`"; - - public final static List<String> IMAGE_1_ENV = List.of("MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb"); - - public final static List<String> IMAGE_2_ENV = List.of("MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_DATABASE=weather_at"); - - public final static AccessType DATABASE_1_READ_ACCESS_TYPE = AccessType.READ; - - public final static AccessTypeDto DATABASE_1_READ_ACCESS_TYPE_DTO = AccessTypeDto.READ; - - public final static AccessType DATABASE_2_WRITE_OWN_ACCESS_TYPE = AccessType.WRITE_OWN; - - public final static AccessTypeDto DATABASE_2_WRITE_OWN_ACCESS_TYPE_DTO = AccessTypeDto.WRITE_OWN; - - public final static AccessType DATABASE_3_WRITE_ALL_ACCESS_TYPE = AccessType.WRITE_ALL; - - public final static AccessTypeDto DATABASE_3_WRITE_ALL_ACCESS_TYPE_DTO = AccessTypeDto.WRITE_ALL; - - public final static DatabaseAccess DATABASE_1_OWNER_ACCESS = DatabaseAccess.builder() - .type(AccessType.WRITE_ALL) - .hdbid(DATABASE_1_ID) - .huserid(USER_1_ID) - .build(); - - public final static DatabaseAccess DATABASE_1_READ_ACCESS = DatabaseAccess.builder() - .type(AccessType.READ) - .hdbid(DATABASE_1_ID) - .huserid(USER_2_ID) - .build(); - - public final static DatabaseAccess DATABASE_1_WRITE_OWN_ACCESS = DatabaseAccess.builder() - .type(AccessType.WRITE_OWN) - .hdbid(DATABASE_1_ID) - .huserid(USER_2_ID) - .build(); - - public final static DatabaseAccess DATABASE_1_WRITE_ALL_ACCESS = DatabaseAccess.builder() - .type(AccessType.WRITE_ALL) - .hdbid(DATABASE_1_ID) - .huserid(USER_2_ID) - .build(); - - public final static DatabaseAccess DATABASE_2_OWNER_ACCESS = DatabaseAccess.builder() - .type(AccessType.WRITE_ALL) - .hdbid(DATABASE_2_ID) - .huserid(USER_1_ID) - .build(); - - public final static DatabaseAccess DATABASE_2_READ_ACCESS = DatabaseAccess.builder() - .type(AccessType.READ) - .hdbid(DATABASE_2_ID) - .huserid(USER_2_ID) - .build(); - - public final static DatabaseAccess DATABASE_2_WRITE_OWN_ACCESS = DatabaseAccess.builder() - .type(AccessType.WRITE_OWN) - .hdbid(DATABASE_2_ID) - .huserid(USER_2_ID) - .build(); - - public final static DatabaseAccess DATABASE_2_WRITE_ALL_ACCESS = DatabaseAccess.builder() - .type(AccessType.WRITE_ALL) - .hdbid(DATABASE_2_ID) - .huserid(USER_2_ID) - .build(); - - public final static Long IDENTIFIER_1_ID = 1L; - public final static String IDENTIFIER_1_PUBLISHER = "TU Wien"; - public final static String IDENTIFIER_1_TITLE = "Some Identifier"; - public final static String IDENTIFIER_1_DESCRIPTION = "Some Identifier is great"; - public final static Integer IDENTIFIER_1_PUBLICATION_YEAR = 2022; - public final static Long IDENTIFIER_1_CONTAINER_ID = CONTAINER_1_ID; - public final static Long IDENTIFIER_1_DATABASE_ID = DATABASE_1_ID; - public final static IdentifierType IDENTIFIER_1_TYPE = IdentifierType.DATABASE; - public final static VisibilityType IDENTIFIER_1_VISIBILITY = VisibilityType.EVERYONE; - public final static VisibilityTypeDto IDENTIFIER_1_VISIBILITY_DTO = VisibilityTypeDto.EVERYONE; - - public final static Identifier IDENTIFIER_1 = Identifier.builder() - .id(IDENTIFIER_1_ID) - .containerId(IDENTIFIER_1_CONTAINER_ID) - .databaseId(IDENTIFIER_1_DATABASE_ID) - .database(DATABASE_1) - .publisher(IDENTIFIER_1_PUBLISHER) - .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) - .title(IDENTIFIER_1_TITLE) - .type(IDENTIFIER_1_TYPE) - .description(IDENTIFIER_1_DESCRIPTION) - .visibility(IDENTIFIER_1_VISIBILITY) - .creator(USER_1) - .build(); +public abstract class BaseUnitTest extends BaseTest { } diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/auth/AuthTokenFilterTest.java b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/auth/AuthTokenFilterTest.java deleted file mode 100644 index 6fa1b5a7ad29c6de71a1a7fec3f5ec93554b0e0f..0000000000000000000000000000000000000000 --- a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/auth/AuthTokenFilterTest.java +++ /dev/null @@ -1,121 +0,0 @@ -package at.tuwien.auth; - -import at.tuwien.BaseUnitTest; -import at.tuwien.config.H2Utils; -import at.tuwien.config.IndexConfig; -import at.tuwien.config.ReadyConfig; -import at.tuwien.repository.jpa.UserRepository; -import com.rabbitmq.client.Channel; -import lombok.extern.log4j.Log4j2; -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.mock.web.MockFilterChain; -import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import java.io.IOException; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.when; - -@Log4j2 -@SpringBootTest -@ExtendWith(SpringExtension.class) -public class AuthTokenFilterTest extends BaseUnitTest { - - @MockBean - private Channel channel; - - @MockBean - private ReadyConfig readyConfig; - - @MockBean - private IndexConfig indexConfig; - - @MockBean - private UserRepository userRepository; - - @Autowired - private AuthTokenFilter authTokenFilter; - - @Autowired - private H2Utils h2Utils; - - @BeforeEach - public void beforeEach() { - h2Utils.runScript("view.sql"); - } - - @Test - public void doFilterInternal_notFound_fails() throws ServletException { - final MockHttpServletRequest request = new MockHttpServletRequest(); - request.addHeader("Authorization", "Bearer " + JWT_1); - final MockHttpServletResponse response = new MockHttpServletResponse(); - final FilterChain chain = new MockFilterChain(); - - /* mock */ - when(userRepository.findByUsername("mweise")) - .thenReturn(Optional.empty()); - - /* test */ - assertThrows(ServletException.class, () -> { - authTokenFilter.doFilterInternal(request, response, chain); - }); - } - - @Test - public void doFilterInternal_succeeds() throws ServletException, IOException { - final MockHttpServletRequest request = new MockHttpServletRequest(); - request.addHeader("Authorization", "Bearer " + JWT_1); - final MockHttpServletResponse response = new MockHttpServletResponse(); - final FilterChain chain = new MockFilterChain(); - - /* mock */ - when(userRepository.findByUsername("mweise")) - .thenReturn(Optional.of(USER_1)); - - /* test */ - authTokenFilter.doFilterInternal(request, response, chain); - assertEquals(200, response.getStatus()); - } - - @Test - public void parseJwt_succeeds() { - final MockHttpServletRequest request = new MockHttpServletRequest(); - request.addHeader("Authorization", "Bearer " + JWT_1); - - /* test */ - final String response = authTokenFilter.parseJwt(request); - assertEquals(JWT_1, response); - } - - @Test - public void parseJwt_fails() { - final MockHttpServletRequest request = new MockHttpServletRequest(); - request.addHeader("Authorization", "Basic dXNlcjpwYXNz"); - - /* test */ - final String response = authTokenFilter.parseJwt(request); - assertNull(response); - } - - @Test - public void parseJwt_noAuthenticationHeader_fails() { - final MockHttpServletRequest request = new MockHttpServletRequest(); - - /* test */ - final String response = authTokenFilter.parseJwt(request); - assertNull(response); - } - -} diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/config/DockerConfig.java b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/config/DockerConfig.java deleted file mode 100644 index 7c55429c92d2f748d706cc990843b0f86883929e..0000000000000000000000000000000000000000 --- a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/config/DockerConfig.java +++ /dev/null @@ -1,199 +0,0 @@ -package at.tuwien.config; - -import at.tuwien.BaseUnitTest; -import at.tuwien.entities.container.Container; -import com.github.dockerjava.api.DockerClient; -import com.github.dockerjava.api.command.CreateContainerCmd; -import com.github.dockerjava.api.command.CreateContainerResponse; -import com.github.dockerjava.api.command.InspectContainerResponse; -import com.github.dockerjava.api.exception.NotModifiedException; -import com.github.dockerjava.api.model.*; -import com.github.dockerjava.core.DefaultDockerClientConfig; -import com.github.dockerjava.core.DockerClientBuilder; -import com.github.dockerjava.core.DockerClientConfig; -import com.github.dockerjava.httpclient5.ApacheDockerHttpClient; -import com.github.dockerjava.transport.DockerHttpClient; -import lombok.extern.log4j.Log4j2; - -import java.util.Arrays; -import java.util.Objects; - -@Log4j2 -public class DockerConfig extends BaseUnitTest { - - private final static DockerClientConfig dockerClientConfig = DefaultDockerClientConfig.createDefaultConfigBuilder() - .withDockerHost("unix:///var/run/docker.sock") - .build(); - - private final static DockerHttpClient dockerHttpClient = new ApacheDockerHttpClient.Builder() - .dockerHost(dockerClientConfig.getDockerHost()) - .sslConfig(dockerClientConfig.getSSLConfig()) - .build(); - - public final static HostConfig hostConfig = HostConfig.newHostConfig() - .withRestartPolicy(RestartPolicy.alwaysRestart()); - - public final static DockerClient dockerClient = DockerClientBuilder.getInstance() - .withDockerHttpClient(dockerHttpClient) - .build(); - - public static void startContainer(Container container) throws InterruptedException { - final InspectContainerResponse inspect = dockerClient.inspectContainerCmd(container.getHash()) - .exec(); - log.trace("container {} state {}", container.getHash(), inspect.getState().getStatus()); - if (Objects.equals(inspect.getState().getStatus(), "running")) { - return; - } - log.info("container {} needs to be started", container.getInternalName()); - dockerClient.startContainerCmd(container.getHash()) - .exec(); - int i = 0; - final int max = 10; - String state; - final boolean hasHealthCheck = getHealthCheck(container.getId()) != null; - do { - final InspectContainerResponse response = dockerClient.inspectContainerCmd(container.getHash()) - .exec(); - if (hasHealthCheck && response.getState().getHealth() == null) { - log.error("Container does not have a healthcheck configuration"); - throw new InterruptedException("Container does not have a healthcheck configuration"); - } - if (hasHealthCheck) { - state = response.getState().getHealth().getStatus(); - log.trace("container {} state is {}, attempt {} of {}", container.getInternalName(), state, i, max); - if (!state.equals("healthy")) { - Thread.sleep(10 * 1000L); - } - } else { - Thread.sleep(60 * 1000L); - state = "healthy"; - } - i++; - } while (!state.equals("healthy") && i != max); - if (state.equals("healthy")) { - log.info("container {} was started", container.getInternalName()); - } else { - log.error("failed to start container {} as state {} is not healthy after {} tries", container.getHash(), - state, i); - throw new RuntimeException("Failed to start container"); - } - } - - public static void createContainer(String bind, Container container, String... environment) { - createContainer(bind, container, null, environment); - } - - public static void createContainer(String bind, Container container, Integer port, String... environment) { - log.trace("creating container with internalName={}, ipAddress={}, hostname={}, environment={}", - container.getInternalName(), container.getIpAddress(), container.getInternalName(), - environment); - final HostConfig hostConfig1; - final String network = (container.getInternalName().contains("userdb") ? "fda-userdb" : "fda-public"); - if (bind == null) { - hostConfig1 = hostConfig.withNetworkMode(network); - } else { - hostConfig1 = hostConfig.withNetworkMode(network).withBinds(Bind.parse(bind)); - } - if (port != null) { - hostConfig1.withPortBindings(PortBinding.parse(port + ":" + port)); - } - final CreateContainerCmd cmd = dockerClient.createContainerCmd(container.getImage().getRepository() + ":" + container.getImage().getTag()) - .withHostConfig(hostConfig1) - .withName(container.getInternalName()) - .withIpv4Address(container.getIpAddress()) - .withHostName(container.getInternalName()) - .withEnv(environment) - .withHealthcheck(getHealthCheck(container.getId())); - final CreateContainerResponse response; - if (container.getInternalName().contains("search")) { - response = cmd.withPortBindings(PortBinding.parse("9200:9200")) - .exec(); - } else { - response = cmd.exec(); - } - container.setHash(response.getId()); - } - - public static void removeAllContainers() { - 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(); - }); - dockerClient.listVolumesCmd() - .withDanglingFilter(true) - .exec() - .getVolumes() - .forEach(volume -> { - log.info("Delete volume {}", volume.getName()); - try { - dockerClient.removeVolumeCmd(volume.getName()).exec(); - } catch (NotModifiedException e) { - // ignore - } - }); - } - - public static void removeAllNetworks() { - dockerClient.listNetworksCmd() - .exec() - .stream() - .filter(n -> n.getName().startsWith("fda")) - .forEach(network -> { - log.info("Delete network {}", network.getName()); - dockerClient.removeNetworkCmd(network.getId()).exec(); - }); - } - - public static void createAllNetworks () { - dockerClient.createNetworkCmd() - .withName("fda-userdb") - .withIpam(new Network.Ipam() - .withConfig(new Network.Ipam.Config() - .withSubnet("172.30.0.0/16"))) - .withEnableIpv6(false) - .exec(); - dockerClient.createNetworkCmd() - .withName("fda-public") - .withIpam(new Network.Ipam() - .withConfig(new Network.Ipam.Config() - .withSubnet("172.31.0.0/16"))) - .withEnableIpv6(false) - .exec(); - } - - private static HealthCheck getHealthCheck(Long containerId) { - if (containerId == null) { - log.trace("container does not have a healthcheck config"); - return null; - } - switch (Integer.parseInt("" + containerId)) { - case 1: - log.debug("container with id {} has a health check config", containerId); - return CONTAINER_1_HEALTHCHECK; - case 2: - log.debug("container with id {} has a health check config", containerId); - return CONTAINER_2_HEALTHCHECK; - case 3: - log.debug("container with id {} has a health check config", containerId); - return CONTAINER_3_HEALTHCHECK; - case 4: - log.debug("container with id {} has a health check config", containerId); - return CONTAINER_4_HEALTHCHECK; - case 5: - log.debug("container with id {} has a health check config", containerId); - return CONTAINER_BROKER_HEALTHCHECK; - } - log.trace("container with id {} does not have a healthcheck config", containerId); - return null; - } - - -} diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java index 6b2b6f592508dce64c781284dbfd369cc936e7c8..1a62502333d3cba17e7807c858a3f37104af7066 100644 --- a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java +++ b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java @@ -1,9 +1,17 @@ package at.tuwien.config; +import at.tuwien.api.database.AccessTypeDto; +import at.tuwien.api.database.DatabaseGiveAccessDto; +import at.tuwien.entities.database.Database; +import at.tuwien.entities.user.User; +import at.tuwien.exception.QueryMalformedException; +import at.tuwien.mapper.DatabaseMapper; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import java.sql.*; +import java.time.Instant; import java.util.LinkedList; import java.util.List; @@ -11,6 +19,13 @@ import java.util.List; @Configuration public class MariaDbConfig { + private final DatabaseMapper databaseMapper; + + @Autowired + public MariaDbConfig(DatabaseMapper databaseMapper) { + this.databaseMapper = databaseMapper; + } + /** * Inserts a query into a created database with given hostname and database name. The method uses the JDBC in-out * notation <a href="#{@link}">{@link https://learn.microsoft.com/en-us/sql/connect/jdbc/using-sql-escape-sequences?view=sql-server-ver16#stored-procedure-calls}</a> @@ -28,20 +43,52 @@ public class MariaDbConfig { final String jdbc = "jdbc:mariadb://" + hostname + "/" + database; log.trace("connect to database {}", jdbc); try (Connection connection = DriverManager.getConnection(jdbc, username, password)) { - final String call = "{call _store_query(?,?,?)}"; + final String call = "{call _store_query(?,?,?,?)}"; log.trace("prepare procedure '{}'", call); final CallableStatement statement = connection.prepareCall(call); - statement.setString("_username", username); - statement.setString("query", query); - statement.registerOutParameter("queryId", Types.BIGINT); + statement.setString(1, username); + statement.setString(2, query); + statement.setTimestamp(3, Timestamp.from(Instant.now())); + statement.registerOutParameter(4, Types.BIGINT); statement.executeUpdate(); - final Long queryId = statement.getLong("queryId"); + final Long queryId = statement.getLong(4); statement.close(); log.debug("received queryId={}", queryId); return queryId; } } + public static void dropDatabase(String hostname, String database, String username, String password) + throws SQLException { + final String jdbc = "jdbc:mariadb://" + hostname + "/" + database; + log.trace("connect to database {}", jdbc); + try (Connection connection = DriverManager.getConnection(jdbc, username, password)) { + final String sql = "DROP DATABASE IF EXISTS `" + database + "`;"; + log.trace("prepare statement '{}'", sql); + final PreparedStatement statement = connection.prepareStatement(sql); + statement.executeUpdate(); + statement.close(); + } + } + + public void mockGrantUserPermissions(String hostname, Database database, User user) throws SQLException, + QueryMalformedException { + final String jdbc = "jdbc:mariadb://" + hostname + "/" + database.getInternalName(); + log.trace("connect to database {}", jdbc); + try (Connection connection = DriverManager.getConnection(jdbc, "root", "mariadb")) { + final DatabaseGiveAccessDto access = DatabaseGiveAccessDto.builder() + .username(user.getUsername()) + .type(AccessTypeDto.WRITE_ALL) + .build(); + final PreparedStatement statement1 = databaseMapper.rawGrantUserAccessQuery(connection, access); + statement1.executeUpdate(); + final PreparedStatement statement2 = databaseMapper.rawGrantUserProcedure(connection, user); + statement2.executeUpdate(); + final PreparedStatement statement3 = databaseMapper.rawFlushPrivileges(connection); + statement3.executeUpdate(); + } + } + public static List<String> getUsernames(String hostname, String database, String username, String password) throws SQLException { final String jdbc = "jdbc:mariadb://" + hostname + "/" + database; @@ -107,13 +154,14 @@ public class MariaDbConfig { final String jdbc = "jdbc:mariadb://" + hostname + "/" + database; log.trace("connect to database {}", jdbc); try (Connection connection = DriverManager.getConnection(jdbc, username, password)) { - final String call = "{call store_query(?,?)}"; + final String call = "{call store_query(?,?,?)}"; log.trace("prepare procedure '{}'", call); final CallableStatement statement = connection.prepareCall(call); statement.setString(1, query); - statement.registerOutParameter(2, Types.BIGINT); + statement.setTimestamp(2, Timestamp.from(Instant.now())); + statement.registerOutParameter(3, Types.BIGINT); statement.executeUpdate(); - final Long queryId = statement.getLong(2); + final Long queryId = statement.getLong(3); statement.close(); log.debug("received queryId={}", queryId); return queryId; diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/endpoint/AccessEndpointUnitTest.java b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/endpoint/AccessEndpointUnitTest.java index a8f560b3b325ce7e3731819a24bdc8e83c7bb309..4f7ff26b1a5429b18e73bef3057608cb071578b5 100644 --- a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/endpoint/AccessEndpointUnitTest.java +++ b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/endpoint/AccessEndpointUnitTest.java @@ -10,11 +10,13 @@ import at.tuwien.config.ReadyConfig; import at.tuwien.endpoints.AccessEndpoint; import at.tuwien.entities.database.Database; import at.tuwien.entities.database.DatabaseAccess; +import at.tuwien.entities.user.User; import at.tuwien.exception.*; import at.tuwien.mapper.AccessMapper; import at.tuwien.repository.jpa.*; import com.rabbitmq.client.Channel; import lombok.extern.log4j.Log4j2; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -64,57 +66,51 @@ public class AccessEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, USER_3_USERNAME, null); + generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, USER_2_USERNAME, USER_2, null); }); } @Test - public void create_readRead_fails() { + @Disabled("Requires integration") + public void create_privateResearcherNoAccessOwner_succeeds() throws UserNotFoundException, NotAllowedException, + QueryMalformedException, DatabaseNotFoundException, DatabaseMalformedException { /* test */ - assertThrows(NotAllowedException.class, () -> { - generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_READ_ACCESS, USER_3_USERNAME, USER_2_PRINCIPAL); - }); + generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, USER_2_USERNAME, USER_2, USER_1_PRINCIPAL); } @Test - public void create_readWriteOwn_fails() { + public void create_privateResearcherNoAccess_fails() { + /* test */ assertThrows(NotAllowedException.class, () -> { - generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_WRITE_OWN_ACCESS, USER_3_USERNAME, USER_2_PRINCIPAL); + generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, USER_3_USERNAME, USER_3, USER_2_PRINCIPAL); }); } @Test - public void create_readWriteAll_fails() { + public void create_privateResearcherRead_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_WRITE_ALL_ACCESS, USER_3_USERNAME, USER_2_PRINCIPAL); + generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_RESEARCHER_READ_ACCESS, USER_2_USERNAME, USER_2, USER_1_PRINCIPAL); }); } @Test - public void create_readOwner_succeeds() { - + public void create_privateResearcherWriteOwn_fails() { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_OWNER_ACCESS, USER_2_USERNAME, USER_1_PRINCIPAL); + generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS, USER_2_USERNAME, USER_2, USER_1_PRINCIPAL); }); } @Test - public void create_noAccessGiveAccess_fails() { - - /* mock */ - when(userRepository.findByUsername(USER_1_USERNAME)) - .thenReturn(Optional.of(USER_1)); - when(userRepository.findByUsername(USER_2_USERNAME)) - .thenReturn(Optional.empty()); + public void create_privateResearcherWriteAll_fails() { /* test */ - assertThrows(UserNotFoundException.class, () -> { - generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, USER_2_USERNAME, USER_1_PRINCIPAL); + assertThrows(NotAllowedException.class, () -> { + generic_create(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS, USER_2_USERNAME, USER_2, USER_1_PRINCIPAL); }); } @@ -132,36 +128,29 @@ public class AccessEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(AccessDeniedException.class, () -> { - generic_find(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, USER_2_USERNAME, USER_2_ID, USER_2_PRINCIPAL); + generic_find(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, USER_2_USERNAME, USER_2_ID, USER_1_PRINCIPAL); }); } @Test - public void find_read_succeeds() throws AccessDeniedException, NotAllowedException { + public void find_privateResearcherRead_succeeds() throws AccessDeniedException, NotAllowedException { /* test */ - generic_find(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_READ_ACCESS, USER_2_USERNAME, USER_2_ID, USER_2_PRINCIPAL); + generic_find(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_RESEARCHER_READ_ACCESS, USER_2_USERNAME, USER_2_ID, USER_1_PRINCIPAL); } @Test - public void find_writeOwn_succeeds() throws AccessDeniedException, NotAllowedException { + public void find_privateResearcherWriteOwn_succeeds() throws AccessDeniedException, NotAllowedException { /* test */ - generic_find(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_WRITE_OWN_ACCESS, USER_2_USERNAME, USER_2_ID, USER_2_PRINCIPAL); + generic_find(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS, USER_2_USERNAME, USER_2_ID, USER_1_PRINCIPAL); } @Test - public void find_writeAll_succeeds() throws AccessDeniedException, NotAllowedException { + public void find_privateResearcherWriteAll_succeeds() throws AccessDeniedException, NotAllowedException { /* test */ - generic_find(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_WRITE_ALL_ACCESS, USER_2_USERNAME, USER_2_ID, USER_2_PRINCIPAL); - } - - @Test - public void find_owner_succeeds() throws AccessDeniedException, NotAllowedException { - - /* test */ - generic_find(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_OWNER_ACCESS, USER_1_USERNAME, USER_1_ID, USER_1_PRINCIPAL); + generic_find(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS, USER_2_USERNAME, USER_2_ID, USER_1_PRINCIPAL); } @Test @@ -173,12 +162,12 @@ public class AccessEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_update(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_READ_ACCESS, USER_3_USERNAME, null); + generic_update(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, null, USER_3_USERNAME, null); }); } @Test - public void update_readRead_fails() { + public void update_privateResearcherRead_fails() { /* mock */ when(userRepository.findByUsername(USER_3_USERNAME)) @@ -186,12 +175,12 @@ public class AccessEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_update(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_READ_ACCESS, USER_3_USERNAME, USER_2_PRINCIPAL); + generic_update(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_RESEARCHER_READ_ACCESS, USER_3_USERNAME, USER_1_PRINCIPAL); }); } @Test - public void update_readWriteOwn_fails() { + public void update_privateResearcherWriteOwn_fails() { /* mock */ when(userRepository.findByUsername(USER_3_USERNAME)) @@ -199,12 +188,12 @@ public class AccessEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_update(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_WRITE_OWN_ACCESS, USER_3_USERNAME, USER_2_PRINCIPAL); + generic_update(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS, USER_3_USERNAME, USER_1_PRINCIPAL); }); } @Test - public void update_readWriteAll_fails() { + public void update_privateResearcherWriteAll_fails() { /* mock */ when(userRepository.findByUsername(USER_3_USERNAME)) @@ -212,22 +201,7 @@ public class AccessEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - generic_update(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_WRITE_ALL_ACCESS, USER_3_USERNAME, USER_2_PRINCIPAL); - }); - } - - @Test - public void update_readOwnerUserNotFound_fails() { - - /* mock */ - when(userRepository.findByUsername(USER_1_USERNAME)) - .thenReturn(Optional.of(USER_1)); - when(userRepository.findByUsername(USER_3_USERNAME)) - .thenReturn(Optional.empty()); - - /* test */ - assertThrows(UserNotFoundException.class, () -> { - generic_update(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_OWNER_ACCESS, USER_3_USERNAME, USER_1_PRINCIPAL); + generic_update(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS, USER_3_USERNAME, USER_1_PRINCIPAL); }); } @@ -236,15 +210,18 @@ public class AccessEndpointUnitTest extends BaseUnitTest { /* ################################################################################################### */ protected void generic_create(Long containerId, Long databaseId, Database database, DatabaseAccess access, - String username, Principal principal) throws UserNotFoundException, + String username, User user, Principal principal) throws UserNotFoundException, NotAllowedException, QueryMalformedException, DatabaseNotFoundException, DatabaseMalformedException { final DatabaseGiveAccessDto request = DatabaseGiveAccessDto.builder() .username(username) + .type(AccessTypeDto.READ) .build(); /* mock */ when(databaseRepository.findById(databaseId)) .thenReturn(Optional.of(database)); + when(userRepository.findByUsername(username)) + .thenReturn(Optional.of(user)); if (access == null) { when(databaseAccessRepository.findByDatabaseIdAndUsername(databaseId, username)) .thenReturn(Optional.empty()); @@ -256,7 +233,7 @@ public class AccessEndpointUnitTest extends BaseUnitTest { /* test */ final ResponseEntity<?> response = accessEndpoint.create(containerId, databaseId, request, principal); assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - assertNotNull(response.getBody()); + assertNull(response.getBody()); } protected void generic_find(Long containerId, Long databaseId, Database database, DatabaseAccess access, @@ -266,12 +243,18 @@ public class AccessEndpointUnitTest extends BaseUnitTest { /* mock */ when(databaseRepository.findById(databaseId)) .thenReturn(Optional.of(database)); - if (access == null) { + if (access != null) { when(databaseAccessRepository.findByDatabaseIdAndUsername(databaseId, username)) - .thenReturn(Optional.empty()); + .thenReturn(Optional.of(access)); + when(databaseAccessRepository.findByDatabaseIdAndUsername(databaseId, principal.getName())) + .thenReturn(Optional.of(DatabaseAccess.builder() + .type(access.getType()) + .hdbid(databaseId) + .huserid(username.equals(USER_1_USERNAME) ? USER_1_ID : USER_2_ID) + .build())); } else { when(databaseAccessRepository.findByDatabaseIdAndUsername(databaseId, username)) - .thenReturn(Optional.of(access)); + .thenReturn(Optional.empty()); } /* test */ @@ -305,7 +288,7 @@ public class AccessEndpointUnitTest extends BaseUnitTest { /* test */ final ResponseEntity<?> response = accessEndpoint.update(containerId, databaseId, username, request, principal); assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - assertNotNull(response.getBody()); + assertNull(response.getBody()); } } diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/endpoint/DatabaseEndpointUnitTest.java b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/endpoint/DatabaseEndpointUnitTest.java index 61cbf30d0255572bc1ca4d62ec5df76672aa478c..674cfe0f163e1da03d9d9241d9c440c5af116259 100644 --- a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/endpoint/DatabaseEndpointUnitTest.java +++ b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/endpoint/DatabaseEndpointUnitTest.java @@ -13,6 +13,7 @@ import at.tuwien.repository.elastic.DatabaseIdxRepository; import at.tuwien.repository.jpa.*; import at.tuwien.service.MessageQueueService; import at.tuwien.service.QueryStoreService; +import at.tuwien.test.BaseTest; import com.rabbitmq.client.Channel; import lombok.extern.log4j.Log4j2; import org.junit.jupiter.api.*; @@ -147,7 +148,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { assertTrue(DATABASE_3_PUBLIC); /* test */ - list_generic(CONTAINER_3_ID, CONTAINER_3, List.of(DATABASE_3), null); + list_generic(CONTAINER_3_ID, DATABASE_3_ID, CONTAINER_3, List.of(DATABASE_3), null); } @Test @@ -158,7 +159,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { assertTrue(DATABASE_3_PUBLIC); /* test */ - list_generic(CONTAINER_3_ID, CONTAINER_3, List.of(DATABASE_3), null); + list_generic(CONTAINER_3_ID, DATABASE_3_ID, CONTAINER_3, List.of(DATABASE_3), null); } @Test @@ -168,7 +169,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { assertFalse(DATABASE_1_PUBLIC); /* test */ - list_generic(CONTAINER_1_ID, CONTAINER_1, List.of(DATABASE_1), null); + list_generic(CONTAINER_1_ID, DATABASE_1_ID, CONTAINER_1, List.of(DATABASE_1), null); } @Test @@ -179,7 +180,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { assertFalse(DATABASE_1_PUBLIC); /* test */ - list_generic(CONTAINER_1_ID, CONTAINER_1, List.of(DATABASE_1), null); + list_generic(CONTAINER_1_ID, DATABASE_1_ID, CONTAINER_1, List.of(DATABASE_1), null); } @Test @@ -194,7 +195,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { .thenReturn(Optional.of(USER_1)); /* test */ - list_generic(CONTAINER_3_ID, CONTAINER_3, List.of(DATABASE_3), USER_1_PRINCIPAL); + list_generic(CONTAINER_3_ID, DATABASE_3_ID, CONTAINER_3, List.of(DATABASE_3), USER_1_PRINCIPAL); } @Test @@ -207,11 +208,11 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { /* mock */ when(userRepository.findByUsername(USER_1_USERNAME)) .thenReturn(Optional.of(USER_1)); - when(identifierRepository.findByContainerId(CONTAINER_1_ID)) + when(identifierRepository.findByDatabaseId(DATABASE_1_ID)) .thenReturn(List.of(IDENTIFIER_1)); /* test */ - list_generic(CONTAINER_3_ID, CONTAINER_3, List.of(DATABASE_3), USER_1_PRINCIPAL); + list_generic(CONTAINER_3_ID, DATABASE_3_ID, CONTAINER_3, List.of(DATABASE_3), USER_1_PRINCIPAL); } @Test @@ -226,7 +227,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { .thenReturn(Optional.of(USER_1)); /* test */ - list_generic(CONTAINER_2_ID, CONTAINER_2, List.of(DATABASE_2), USER_1_PRINCIPAL); + list_generic(CONTAINER_2_ID, DATABASE_2_ID, CONTAINER_2, List.of(DATABASE_2), USER_1_PRINCIPAL); } @Test @@ -241,7 +242,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { .thenReturn(Optional.of(USER_1)); /* test */ - list_generic(CONTAINER_3_ID, CONTAINER_3, List.of(DATABASE_3), USER_1_PRINCIPAL); + list_generic(CONTAINER_3_ID, DATABASE_3_ID, CONTAINER_3, List.of(DATABASE_3), USER_1_PRINCIPAL); } @Test @@ -256,7 +257,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { .thenReturn(Optional.of(USER_1)); /* test */ - list_generic(CONTAINER_2_ID, CONTAINER_2, List.of(DATABASE_2), USER_1_PRINCIPAL); + list_generic(CONTAINER_2_ID, DATABASE_2_ID, CONTAINER_2, List.of(DATABASE_2), USER_1_PRINCIPAL); } @Test @@ -271,7 +272,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { .thenReturn(Optional.of(USER_2)); /* test */ - list_generic(CONTAINER_3_ID, CONTAINER_3, List.of(DATABASE_3), USER_2_PRINCIPAL); + list_generic(CONTAINER_3_ID, DATABASE_3_ID, CONTAINER_3, List.of(DATABASE_3), USER_2_PRINCIPAL); } @Test @@ -286,7 +287,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { .thenReturn(Optional.of(USER_2)); /* test */ - list_generic(CONTAINER_2_ID, CONTAINER_2, List.of(DATABASE_2), USER_2_PRINCIPAL); + list_generic(CONTAINER_2_ID, DATABASE_2_ID, CONTAINER_2, List.of(DATABASE_2), USER_2_PRINCIPAL); } @Test @@ -301,7 +302,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { .thenReturn(Optional.of(USER_2)); /* test */ - list_generic(CONTAINER_3_ID, CONTAINER_3, List.of(DATABASE_3), USER_2_PRINCIPAL); + list_generic(CONTAINER_3_ID, DATABASE_3_ID, CONTAINER_3, List.of(DATABASE_3), USER_2_PRINCIPAL); } @Test @@ -316,7 +317,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { .thenReturn(Optional.of(USER_2)); /* test */ - list_generic(CONTAINER_1_ID, CONTAINER_1, List.of(DATABASE_1), USER_2_PRINCIPAL); + list_generic(CONTAINER_1_ID, DATABASE_1_ID, CONTAINER_1, List.of(DATABASE_1), USER_2_PRINCIPAL); } @Test @@ -331,7 +332,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { .thenReturn(Optional.of(USER_3)); /* test */ - list_generic(CONTAINER_3_ID, CONTAINER_3, List.of(DATABASE_3), USER_3_PRINCIPAL); + list_generic(CONTAINER_3_ID, DATABASE_3_ID, CONTAINER_3, List.of(DATABASE_3), USER_3_PRINCIPAL); } @Test @@ -346,7 +347,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { .thenReturn(Optional.of(USER_3)); /* test */ - list_generic(CONTAINER_1_ID, CONTAINER_1, List.of(DATABASE_1), USER_3_PRINCIPAL); + list_generic(CONTAINER_1_ID, DATABASE_1_ID, CONTAINER_1, List.of(DATABASE_1), USER_3_PRINCIPAL); } @Test @@ -361,7 +362,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { .thenReturn(Optional.of(USER_3)); /* test */ - list_generic(CONTAINER_3_ID, CONTAINER_3, List.of(DATABASE_3), USER_3_PRINCIPAL); + list_generic(CONTAINER_3_ID, DATABASE_3_ID, CONTAINER_3, List.of(DATABASE_3), USER_3_PRINCIPAL); } @Test @@ -376,7 +377,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { .thenReturn(Optional.of(USER_3)); /* test */ - list_generic(CONTAINER_2_ID, CONTAINER_2, List.of(DATABASE_2), USER_3_PRINCIPAL); + list_generic(CONTAINER_2_ID, DATABASE_2_ID, CONTAINER_2, List.of(DATABASE_2), USER_3_PRINCIPAL); } @Test @@ -711,14 +712,14 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { /* ## GENERIC TEST CASES ## */ /* ################################################################################################### */ - public void list_generic(Long containerId, Container container, List<Database> databases, Principal principal) { + public void list_generic(Long containerId, Long databaseId, Container container, List<Database> databases, Principal principal) { /* mock */ when(containerRepository.findById(containerId)) .thenReturn(Optional.of(container)); when(databaseRepository.findAll(containerId)) .thenReturn(databases); - when(identifierRepository.findByContainerId(containerId)) + when(identifierRepository.findByDatabaseId(databaseId)) .thenReturn(List.of()); /* test */ @@ -757,7 +758,7 @@ public class DatabaseEndpointUnitTest extends BaseUnitTest { .when(messageQueueService) .updatePermissions(principal); when(databaseAccessRepository.save(any(DatabaseAccess.class))) - .thenReturn(DATABASE_1_WRITE_ALL_ACCESS); + .thenReturn(DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); /* test */ final ResponseEntity<DatabaseBriefDto> response = databaseEndpoint.create(containerId, data, principal); diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/endpoint/LicenseEndpointUnitTest.java b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/endpoint/LicenseEndpointUnitTest.java index 87bd3d3c24078fdb50b79ee02a91472de7a26816..81673c913ae36e187f249a38be432d7ab75c039d 100644 --- a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/endpoint/LicenseEndpointUnitTest.java +++ b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/endpoint/LicenseEndpointUnitTest.java @@ -6,6 +6,7 @@ import at.tuwien.config.IndexConfig; import at.tuwien.config.ReadyConfig; import at.tuwien.endpoints.LicenseEndpoint; import at.tuwien.repository.jpa.LicenseRepository; +import at.tuwien.test.BaseTest; import com.rabbitmq.client.Channel; import lombok.extern.log4j.Log4j2; import org.junit.jupiter.api.Test; diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/gateway/BrokerServiceGatewayTest.java b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/gateway/BrokerServiceGatewayTest.java index b981539098a10b9a8e42c6022e4ea383fe130951..866ae4ae48e69e2e46fb971aab55150af68f085d 100644 --- a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/gateway/BrokerServiceGatewayTest.java +++ b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/gateway/BrokerServiceGatewayTest.java @@ -5,6 +5,7 @@ import at.tuwien.config.IndexConfig; import at.tuwien.config.ReadyConfig; import at.tuwien.exception.BrokerVirtualHostCreationException; import at.tuwien.exception.BrokerVirtualHostGrantException; +import at.tuwien.test.BaseTest; import com.rabbitmq.client.Channel; import lombok.extern.log4j.Log4j2; import org.junit.jupiter.api.Test; diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/mapper/DatabaseMapperTest.java b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/mapper/DatabaseMapperTest.java index 5159e734eea655be0b3a447667d3bdda1cede67e..766ba8ed505cf190bc485c363a576bbdd31993d6 100644 --- a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/mapper/DatabaseMapperTest.java +++ b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/mapper/DatabaseMapperTest.java @@ -5,6 +5,7 @@ import at.tuwien.api.database.DatabaseDto; import at.tuwien.api.user.UserBriefDto; import at.tuwien.config.IndexConfig; import at.tuwien.config.ReadyConfig; +import at.tuwien.test.BaseTest; import com.rabbitmq.client.Channel; import lombok.extern.log4j.Log4j2; import org.junit.jupiter.api.Test; diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/AccessServiceIntegrationTest.java b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/AccessServiceIntegrationTest.java index eb7a433d7da378ff8011fcf16edb045f791ce534..d705b290b6a83a008ed39ace73cfd485125db6cb 100644 --- a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/AccessServiceIntegrationTest.java +++ b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/AccessServiceIntegrationTest.java @@ -12,6 +12,7 @@ import at.tuwien.entities.database.AccessType; import at.tuwien.entities.database.DatabaseAccess; import at.tuwien.exception.*; import at.tuwien.repository.jpa.*; +import at.tuwien.test.BaseTest; import com.rabbitmq.client.Channel; import lombok.extern.log4j.Log4j2; import org.junit.jupiter.api.*; @@ -64,7 +65,7 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { @Autowired private H2Utils h2Utils; - private final static String BIND = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + private final static String BIND_WEATHER = new File("../../dbrepo-metadata-db/test/src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; @BeforeAll public static void beforeAll() { @@ -79,7 +80,7 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { } @BeforeEach - public void beforeEach() throws InterruptedException { + public void beforeEach() { afterEach(); DockerConfig.createAllNetworks(); /* metadata database */ @@ -103,7 +104,7 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { DatabaseNotFoundException, DatabaseMalformedException, InterruptedException { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); DockerConfig.startContainer(CONTAINER_1); userRepository.save(USER_1); userRepository.save(USER_2); @@ -111,41 +112,24 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { databaseRepository.save(DATABASE_1); /* test */ - create_generic(DATABASE_1_READ_ACCESS_TYPE_DTO, DATABASE_1_READ_ACCESS_TYPE, USER_2_USERNAME, USER_2_ID); + create_generic(AccessTypeDto.READ, AccessType.READ, USER_2_USERNAME, USER_2_ID); } @Test public void create_multiple_fails() throws InterruptedException { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); DockerConfig.startContainer(CONTAINER_1); userRepository.save(USER_1); userRepository.save(USER_2); containerRepository.save(CONTAINER_1); databaseRepository.save(DATABASE_1); - databaseAccessRepository.save(DATABASE_1_READ_ACCESS); + databaseAccessRepository.save(DATABASE_1_DEVELOPER_READ_ACCESS); /* test */ assertThrows(NotAllowedException.class, () -> { - create_generic(DATABASE_1_READ_ACCESS_TYPE_DTO, DATABASE_1_READ_ACCESS_TYPE, USER_2_USERNAME, USER_2_ID); - }); - } - - @Test - public void create_owner_fails() throws InterruptedException { - - /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); - DockerConfig.startContainer(CONTAINER_1); - userRepository.save(USER_1); - containerRepository.save(CONTAINER_1); - databaseRepository.save(DATABASE_1); - databaseAccessRepository.save(DATABASE_1_OWNER_ACCESS); - - /* test */ - assertThrows(NotAllowedException.class, () -> { - create_generic(DATABASE_1_READ_ACCESS_TYPE_DTO, DATABASE_1_READ_ACCESS_TYPE, USER_1_USERNAME, USER_1_ID); + create_generic(AccessTypeDto.READ, AccessType.READ, USER_2_USERNAME, USER_2_ID); }); } @@ -154,16 +138,16 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { DatabaseNotFoundException, DatabaseMalformedException, InterruptedException { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); DockerConfig.startContainer(CONTAINER_1); userRepository.save(USER_1); userRepository.save(USER_2); containerRepository.save(CONTAINER_1); databaseRepository.save(DATABASE_1); - databaseAccessRepository.save(DATABASE_1_READ_ACCESS); + databaseAccessRepository.save(DATABASE_1_DEVELOPER_READ_ACCESS); /* test */ - update_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1_READ_ACCESS_TYPE_DTO, DATABASE_1_READ_ACCESS_TYPE, USER_2_USERNAME, USER_2_ID); + update_generic(CONTAINER_1_ID, DATABASE_1_ID, AccessTypeDto.READ, AccessType.READ, USER_2_USERNAME, USER_2_ID); } @Test @@ -171,7 +155,7 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { DatabaseNotFoundException, DatabaseMalformedException, InterruptedException { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); DockerConfig.startContainer(CONTAINER_1); userRepository.save(USER_1); userRepository.save(USER_2); @@ -179,7 +163,7 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { databaseRepository.save(DATABASE_1); /* test */ - update_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_2_WRITE_OWN_ACCESS_TYPE_DTO, DATABASE_2_WRITE_OWN_ACCESS_TYPE, USER_2_USERNAME, USER_2_ID); + update_generic(CONTAINER_1_ID, DATABASE_1_ID, AccessTypeDto.WRITE_OWN, AccessType.WRITE_OWN, USER_2_USERNAME, USER_2_ID); } @Test @@ -187,7 +171,7 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { DatabaseNotFoundException, DatabaseMalformedException, InterruptedException { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); DockerConfig.startContainer(CONTAINER_1); userRepository.save(USER_1); userRepository.save(USER_2); @@ -195,14 +179,14 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { databaseRepository.save(DATABASE_1); /* test */ - update_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_3_WRITE_ALL_ACCESS_TYPE_DTO, DATABASE_3_WRITE_ALL_ACCESS_TYPE, USER_2_USERNAME, USER_2_ID); + update_generic(CONTAINER_1_ID, DATABASE_1_ID, AccessTypeDto.WRITE_ALL, AccessType.WRITE_ALL, USER_2_USERNAME, USER_2_ID); } @Test public void update_userNotFound_fails() throws InterruptedException { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); DockerConfig.startContainer(CONTAINER_1); userRepository.save(USER_1); containerRepository.save(CONTAINER_1); @@ -210,7 +194,7 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { /* test */ assertThrows(UserNotFoundException.class, () -> { - update_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1_READ_ACCESS_TYPE_DTO, DATABASE_1_READ_ACCESS_TYPE, "l33tsp34k", null); + update_generic(CONTAINER_1_ID, DATABASE_1_ID, AccessTypeDto.READ, AccessType.READ, "l33tsp34k", null); }); } @@ -218,7 +202,7 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { public void update_databaseNotFound_fails() throws InterruptedException { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_2, CONTAINER_2_ENV); + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_2, CONTAINER_2_ENV); DockerConfig.startContainer(CONTAINER_2); userRepository.save(USER_1); userRepository.save(USER_2); @@ -228,7 +212,7 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { /* test */ assertThrows(DatabaseNotFoundException.class, () -> { - update_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_1_READ_ACCESS_TYPE_DTO, DATABASE_1_READ_ACCESS_TYPE, USER_2_USERNAME, USER_2_ID); + update_generic(CONTAINER_2_ID, DATABASE_2_ID, AccessTypeDto.READ, AccessType.READ, USER_2_USERNAME, USER_2_ID); }); } @@ -237,7 +221,7 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { DatabaseNotFoundException, DatabaseMalformedException, InterruptedException { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); DockerConfig.startContainer(CONTAINER_1); userRepository.save(USER_1); userRepository.save(USER_2); @@ -252,7 +236,7 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { public void delete_isOwner_fails() throws InterruptedException { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); DockerConfig.startContainer(CONTAINER_1); userRepository.save(USER_1); containerRepository.save(CONTAINER_1); @@ -268,7 +252,7 @@ public class AccessServiceIntegrationTest extends BaseUnitTest { public void delete_notExists_fails() throws InterruptedException { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); DockerConfig.startContainer(CONTAINER_1); containerRepository.save(CONTAINER_1); databaseRepository.save(DATABASE_1); diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/AccessServiceUnitTest.java b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/AccessServiceUnitTest.java index 33986fb44d1526ceba5cd7d317f7af630eb25fcd..0ff197662b0c56c931871f51ac1cbb29d96083e0 100644 --- a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/AccessServiceUnitTest.java +++ b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/AccessServiceUnitTest.java @@ -5,19 +5,19 @@ import at.tuwien.api.database.AccessTypeDto; import at.tuwien.api.database.DatabaseModifyAccessDto; import at.tuwien.config.IndexConfig; import at.tuwien.config.ReadyConfig; +import at.tuwien.entities.database.AccessType; import at.tuwien.entities.database.DatabaseAccess; import at.tuwien.exception.AccessDeniedException; import at.tuwien.exception.NotAllowedException; import at.tuwien.repository.jpa.*; +import at.tuwien.test.BaseTest; import com.rabbitmq.client.Channel; import lombok.extern.log4j.Log4j2; -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.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringExtension; import java.util.List; @@ -58,7 +58,7 @@ public class AccessServiceUnitTest extends BaseUnitTest { /* mock */ when(databaseAccessRepository.findByHdbid(DATABASE_1_ID)) - .thenReturn(List.of(DATABASE_1_READ_ACCESS, DATABASE_2_READ_ACCESS)); + .thenReturn(List.of(DATABASE_1_RESEARCHER_READ_ACCESS, DATABASE_2_RESEARCHER_READ_ACCESS)); /* test */ final List<DatabaseAccess> response = accessService.list(DATABASE_1_ID); @@ -82,11 +82,11 @@ public class AccessServiceUnitTest extends BaseUnitTest { /* mock */ when(databaseAccessRepository.findByDatabaseIdAndUsername(DATABASE_1_ID, USER_1_USERNAME)) - .thenReturn(Optional.of(DATABASE_1_READ_ACCESS)); + .thenReturn(Optional.of(DATABASE_1_RESEARCHER_READ_ACCESS)); /* test */ final DatabaseAccess response = accessService.find(DATABASE_1_ID, USER_1_USERNAME); - assertEquals(DATABASE_1_READ_ACCESS_TYPE, response.getType()); + assertEquals(AccessType.READ, response.getType()); } @Test diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceComponentTest.java b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceComponentTest.java new file mode 100644 index 0000000000000000000000000000000000000000..06a0e20587c2124e428630b489b614d3462ca93c --- /dev/null +++ b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceComponentTest.java @@ -0,0 +1,128 @@ +package at.tuwien.service; + +import at.tuwien.BaseUnitTest; +import at.tuwien.api.database.DatabaseCreateDto; +import at.tuwien.api.database.DatabaseDto; +import at.tuwien.config.*; +import at.tuwien.entities.database.Database; +import at.tuwien.repository.elastic.DatabaseIdxRepository; +import at.tuwien.repository.jpa.ContainerRepository; +import at.tuwien.repository.jpa.ImageRepository; +import at.tuwien.repository.jpa.UserRepository; +import at.tuwien.service.impl.MariaDbServiceImpl; +import at.tuwien.test.BaseTest; +import com.rabbitmq.client.Channel; +import lombok.extern.log4j.Log4j2; +import org.apache.http.auth.BasicUserPrincipal; +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 java.io.File; +import java.security.Principal; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@Log4j2 +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@ExtendWith(SpringExtension.class) +@SpringBootTest +public class DatabaseServiceComponentTest extends BaseUnitTest { + + @MockBean + private ReadyConfig readyConfig; + + @MockBean + private Channel channel; + + @MockBean + private IndexConfig indexConfig; + + @MockBean + private DatabaseIdxRepository databaseIdxRepository; + + @Autowired + private ContainerRepository containerRepository; + + @Autowired + private UserRepository userRepository; + + @Autowired + private ImageRepository imageRepository; + + @Autowired + private MariaDbServiceImpl databaseService; + + @Autowired + private H2Utils h2Utils; + + private final static String BIND_MUSICOLOGY = new File("../../dbrepo-metadata-db/test/src/test/resources/musicology").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + + @BeforeAll + public static void beforeAll() { + afterAll(); + DockerConfig.createAllNetworks(); + } + + @AfterAll + public static void afterAll() { + DockerConfig.removeAllContainers(); + DockerConfig.removeAllNetworks(); + } + + @BeforeEach + public void beforeEach() { + afterEach(); + /* metadata database */ + h2Utils.runScript("schema.sql"); + imageRepository.save(IMAGE_1); + userRepository.save(USER_1); + } + + @AfterEach + public void afterEach() { + DockerConfig.removeAllContainers(); + } + + @Test + public void create_elasticSearch_succeeds() throws Exception { + + /* mock */ + DockerConfig.createContainer(null, CONTAINER_ELASTIC, CONTAINER_ELASTIC_ENV); + DockerConfig.startContainer(CONTAINER_ELASTIC); + DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV); + DockerConfig.startContainer(CONTAINER_3); + MariaDbConfig.dropDatabase(CONTAINER_3_INTERNALNAME, DATABASE_3_INTERNALNAME, "root", "mariadb"); + when(databaseIdxRepository.save(any(DatabaseDto.class))) + .thenReturn(DATABASE_3_DTO); + + /* test */ + generic_create(CONTAINER_3_ID, DATABASE_3_CREATE, DATABASE_3); + } + + /* ################################################################################################### */ + /* ## GENERIC TEST CASES ## */ + /* ################################################################################################### */ + + protected void generic_create(Long containerId, DatabaseCreateDto createDto, Database database) + throws Exception { + final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); + + /* mock */ + containerRepository.save(CONTAINER_1); + containerRepository.save(CONTAINER_2); + containerRepository.save(CONTAINER_3); + + /* test */ + final Database response = databaseService.create(containerId, createDto, principal); + assertEquals(database.getName(), response.getName()); + assertEquals(containerId, database.getId()); + } + +} diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceIntegrationElasticTest.java b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceIntegrationElasticTest.java index 06a615bbfc95a2703d0c18ff34923dd40b4ee53d..cae3d3d7d0a7df8dc7a8ecf295574be53c9c6c02 100644 --- a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceIntegrationElasticTest.java +++ b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceIntegrationElasticTest.java @@ -10,6 +10,7 @@ import at.tuwien.repository.jpa.ContainerRepository; import at.tuwien.repository.jpa.ImageRepository; import at.tuwien.repository.jpa.UserRepository; import at.tuwien.service.impl.MariaDbServiceImpl; +import at.tuwien.test.BaseTest; import com.rabbitmq.client.Channel; import lombok.extern.log4j.Log4j2; import org.apache.http.auth.BasicUserPrincipal; @@ -61,7 +62,7 @@ public class DatabaseServiceIntegrationElasticTest extends BaseUnitTest { @Autowired private H2Utils h2Utils; - private final static String BIND = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + private final static String BIND = new File("../../dbrepo-metadata-db/test/src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; @BeforeAll public static void beforeAll() { @@ -93,8 +94,8 @@ public class DatabaseServiceIntegrationElasticTest extends BaseUnitTest { public void create_elasticSearch_succeeds() throws Exception { /* mock */ - DockerConfig.createContainer(null, CONTAINER_SEARCH, CONTAINER_SEARCH_ENV); - DockerConfig.startContainer(CONTAINER_SEARCH); + DockerConfig.createContainer(null, CONTAINER_ELASTIC, CONTAINER_ELASTIC_ENV); + DockerConfig.startContainer(CONTAINER_ELASTIC); DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); DockerConfig.startContainer(CONTAINER_1); when(databaseIdxRepository.save(any(DatabaseDto.class))) diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceIntegrationTest.java b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceIntegrationTest.java index b63690d37a74c99ddfda486e72bed5fb5cb3d70d..4b2e2a5ca04e101df46be4a38ee83c673a99ded8 100644 --- a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceIntegrationTest.java +++ b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceIntegrationTest.java @@ -3,14 +3,16 @@ package at.tuwien.service; import at.tuwien.BaseUnitTest; import at.tuwien.api.database.DatabaseCreateDto; import at.tuwien.api.database.DatabaseDto; -import at.tuwien.config.*; +import at.tuwien.config.DockerConfig; import at.tuwien.config.IndexConfig; import at.tuwien.config.MariaDbConfig; import at.tuwien.config.ReadyConfig; import at.tuwien.entities.database.Database; +import at.tuwien.exception.QueryMalformedException; import at.tuwien.repository.elastic.DatabaseIdxRepository; import at.tuwien.repository.jpa.*; import at.tuwien.service.impl.MariaDbServiceImpl; +import at.tuwien.test.BaseTest; import com.rabbitmq.client.Channel; import lombok.extern.log4j.Log4j2; import org.apache.http.auth.BasicUserPrincipal; @@ -26,7 +28,6 @@ import java.io.File; import java.security.Principal; import java.sql.SQLException; -import static at.tuwien.config.DockerConfig.*; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -62,9 +63,11 @@ public class DatabaseServiceIntegrationTest extends BaseUnitTest { private MariaDbServiceImpl databaseService; @Autowired - private H2Utils h2Utils; + private MariaDbConfig mariaDbConfig; - private final static String BIND = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + private final static String BIND_ZOO = new File("../../dbrepo-metadata-db/test/src/test/resources/zoo").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + + private final static String BIND_MUSICOLOGY = new File("../../dbrepo-metadata-db/test/src/test/resources/musicology").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; @BeforeAll public static void beforeAll() { @@ -81,8 +84,8 @@ public class DatabaseServiceIntegrationTest extends BaseUnitTest { @BeforeEach public void beforeEach() { afterEach(); + DockerConfig.createAllNetworks(); /* metadata database */ - h2Utils.runScript("schema.sql"); imageRepository.save(IMAGE_1); userRepository.save(USER_1); } @@ -90,133 +93,140 @@ public class DatabaseServiceIntegrationTest extends BaseUnitTest { @AfterEach public void afterEach() { DockerConfig.removeAllContainers(); + DockerConfig.removeAllNetworks(); } @Test public void create_succeeds() throws Exception { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); - DockerConfig.startContainer(CONTAINER_1); + DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV); + DockerConfig.startContainer(CONTAINER_3); + MariaDbConfig.dropDatabase(CONTAINER_3_INTERNALNAME, DATABASE_3_INTERNALNAME, "root", "mariadb"); when(databaseIdxRepository.save(any(DatabaseDto.class))) .thenReturn(DATABASE_1_DTO); /* test */ - generic_create(CONTAINER_1_ID, DATABASE_1_CREATE, DATABASE_1); + generic_create(CONTAINER_3_ID, DATABASE_3_CREATE, DATABASE_3); } @Test public void create_inSequence_succeeds() throws Exception { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); - DockerConfig.startContainer(CONTAINER_1); - DockerConfig.createContainer(BIND, CONTAINER_2, CONTAINER_2_ENV); + DockerConfig.createContainer(BIND_ZOO, CONTAINER_2, CONTAINER_2_ENV); DockerConfig.startContainer(CONTAINER_2); + MariaDbConfig.dropDatabase(CONTAINER_2_INTERNALNAME, DATABASE_2_INTERNALNAME, "root", "mariadb"); + DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV); + DockerConfig.startContainer(CONTAINER_3); + MariaDbConfig.dropDatabase(CONTAINER_3_INTERNALNAME, DATABASE_3_INTERNALNAME, "root", "mariadb"); when(databaseIdxRepository.save(any(DatabaseDto.class))) - .thenReturn(DATABASE_1_DTO) - .thenReturn(DATABASE_2_DTO); + .thenReturn(DATABASE_2_DTO) + .thenReturn(DATABASE_3_DTO); /* test */ - generic_create(CONTAINER_1_ID, DATABASE_1_CREATE, DATABASE_1); generic_create(CONTAINER_2_ID, DATABASE_2_CREATE, DATABASE_2); + generic_create(CONTAINER_3_ID, DATABASE_3_CREATE, DATABASE_3); } @Test public void create_outOfSequence_succeeds() throws Exception { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); - DockerConfig.startContainer(CONTAINER_1); - DockerConfig.createContainer(BIND, CONTAINER_2, CONTAINER_2_ENV); + DockerConfig.createContainer(BIND_ZOO, CONTAINER_2, CONTAINER_2_ENV); DockerConfig.startContainer(CONTAINER_2); + MariaDbConfig.dropDatabase(CONTAINER_2_INTERNALNAME, DATABASE_2_INTERNALNAME, "root", "mariadb"); + DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV); + DockerConfig.startContainer(CONTAINER_3); + MariaDbConfig.dropDatabase(CONTAINER_3_INTERNALNAME, DATABASE_3_INTERNALNAME, "root", "mariadb"); when(databaseIdxRepository.save(any(DatabaseDto.class))) - .thenReturn(DATABASE_1_DTO) + .thenReturn(DATABASE_3_DTO) .thenReturn(DATABASE_2_DTO); /* test */ + generic_create(CONTAINER_3_ID, DATABASE_3_CREATE, DATABASE_3); generic_create(CONTAINER_2_ID, DATABASE_2_CREATE, DATABASE_2); - generic_create(CONTAINER_1_ID, DATABASE_1_CREATE, DATABASE_1); } @Test - public void create_queryStore_succeeds() throws SQLException, InterruptedException { + public void create_queryStore_succeeds() throws SQLException, InterruptedException, QueryMalformedException { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_3, CONTAINER_3_ENV); + DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV); DockerConfig.startContainer(CONTAINER_3); /* test */ - generic_create(QUERY_1_STATEMENT, 1L); + generic_insert(QUERY_4_STATEMENT, 1L); } @Test - public void create_queryStoreSameQueryHash_succeeds() throws SQLException, InterruptedException { + public void create_queryStoreSameQueryHash_succeeds() throws SQLException, InterruptedException, + QueryMalformedException { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_3, CONTAINER_3_ENV); + DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV); DockerConfig.startContainer(CONTAINER_3); /* test */ - generic_create(QUERY_1_STATEMENT, 1L); - generic_create(QUERY_2_STATEMENT, 2L); - generic_create(QUERY_1_STATEMENT, 1L); + generic_insert(QUERY_4_STATEMENT, 1L); + generic_insert(QUERY_5_STATEMENT, 2L); + generic_insert(QUERY_4_STATEMENT, 1L); } @Test - public void create_systemProcedure_succeeds() throws SQLException, InterruptedException { + public void create_systemProcedure_succeeds() throws SQLException, InterruptedException, QueryMalformedException { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_3, CONTAINER_3_ENV); + DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV); DockerConfig.startContainer(CONTAINER_3); /* test */ - generic_system_create("root", "mariadb"); + generic_system_insert("root", "mariadb"); } @Test public void create_systemProcedure_fails() throws InterruptedException { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); - DockerConfig.startContainer(CONTAINER_1); + DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV); + DockerConfig.startContainer(CONTAINER_3); /* test */ assertThrows(SQLException.class, () -> { - generic_system_create("junit", "junit"); + generic_system_insert("junit1", "junit1"); }); } @Test - public void create_userProcedureRoot_succeeds() throws SQLException, InterruptedException { + public void create_userProcedureRoot_succeeds() throws SQLException, InterruptedException, QueryMalformedException { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); - DockerConfig.startContainer(CONTAINER_1); + DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV); + DockerConfig.startContainer(CONTAINER_3); /* test */ - generic_user_create("root", "mariadb"); + generic_user_insert("root", "mariadb"); } @Test - public void create_userProcedureUser_succeeds() throws SQLException, InterruptedException { + public void create_userProcedureUser_succeeds() throws SQLException, InterruptedException, QueryMalformedException { /* mock */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); - DockerConfig.startContainer(CONTAINER_1); + DockerConfig.createContainer(BIND_MUSICOLOGY, CONTAINER_3, CONTAINER_3_ENV); + DockerConfig.startContainer(CONTAINER_3); /* test */ - generic_user_create("junit", "junit"); + generic_user_insert("junit1", "junit1"); } /* ################################################################################################### */ /* ## GENERIC TEST CASES ## */ /* ################################################################################################### */ - protected void generic_create(String query, Long assertQueryId) throws InterruptedException, - SQLException { + protected void generic_insert(String query, Long assertQueryId) throws SQLException, QueryMalformedException { /* mock */ + mariaDbConfig.mockGrantUserPermissions(CONTAINER_3_INTERNALNAME, DATABASE_3, USER_1); containerRepository.save(CONTAINER_1); containerRepository.save(CONTAINER_2); containerRepository.save(CONTAINER_3); @@ -242,29 +252,31 @@ public class DatabaseServiceIntegrationTest extends BaseUnitTest { assertEquals(containerId, database.getId()); } - protected void generic_system_create(String username, String password) throws SQLException { + protected void generic_system_insert(String username, String password) throws SQLException, QueryMalformedException { /* mock */ + mariaDbConfig.mockGrantUserPermissions(CONTAINER_3_INTERNALNAME, DATABASE_3, USER_1); containerRepository.save(CONTAINER_1); containerRepository.save(CONTAINER_2); containerRepository.save(CONTAINER_3); /* test */ final Long queryId = MariaDbConfig.mockSystemQueryInsert(CONTAINER_3_INTERNALNAME, DATABASE_3_INTERNALNAME, - QUERY_1_STATEMENT, username, password); + QUERY_4_STATEMENT, username, password); assertEquals(1L, queryId); } - protected void generic_user_create(String username, String password) throws InterruptedException, SQLException { + protected void generic_user_insert(String username, String password) throws SQLException, QueryMalformedException { /* mock */ + mariaDbConfig.mockGrantUserPermissions(CONTAINER_3_INTERNALNAME, DATABASE_3, USER_1); + containerRepository.save(CONTAINER_1); + containerRepository.save(CONTAINER_2); containerRepository.save(CONTAINER_3); - createContainer(BIND, CONTAINER_3, CONTAINER_3_ENV); - startContainer(CONTAINER_3); /* test */ final Long queryId = MariaDbConfig.mockUserQueryInsert(CONTAINER_3_INTERNALNAME, DATABASE_3_INTERNALNAME, - QUERY_1_STATEMENT, username, password); + QUERY_4_STATEMENT, username, password); assertEquals(1L, queryId); } diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceUnitTest.java b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceUnitTest.java index 54fa6b472a8e52182cda4270338bc2ed9e993e86..9d02bb53f434b65aae36bbf9ec8ef6f7ee1bb74d 100644 --- a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceUnitTest.java +++ b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/service/DatabaseServiceUnitTest.java @@ -12,6 +12,7 @@ import at.tuwien.repository.jpa.ContainerRepository; import at.tuwien.repository.jpa.DatabaseRepository; import at.tuwien.service.impl.MariaDbServiceImpl; import at.tuwien.service.impl.RabbitMqServiceImpl; +import at.tuwien.test.BaseTest; import com.rabbitmq.client.Channel; import lombok.extern.log4j.Log4j2; import org.junit.jupiter.api.Test; diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/utils/FileUtilTest.java b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/utils/FileUtilTest.java index 4c973d8b17c0a61090796147ecfb4933ea6902fe..3dd48bcc4fa10d8d0d31d07957b6361f5aaba271 100644 --- a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/utils/FileUtilTest.java +++ b/dbrepo-database-service/rest-service/src/test/java/at/tuwien/utils/FileUtilTest.java @@ -3,6 +3,7 @@ package at.tuwien.utils; import at.tuwien.BaseUnitTest; import at.tuwien.config.IndexConfig; import at.tuwien.config.ReadyConfig; +import at.tuwien.test.BaseTest; import com.rabbitmq.client.Channel; import lombok.extern.log4j.Log4j2; import org.junit.jupiter.api.Disabled; @@ -33,6 +34,7 @@ public class FileUtilTest extends BaseUnitTest { @Test @Disabled + @Deprecated public void loadResource_succeeds() throws IOException { /* test */ diff --git a/dbrepo-database-service/rest-service/src/test/resources/application.properties b/dbrepo-database-service/rest-service/src/test/resources/application.properties index ddfddd8b33f6b4807c1047703d873571b4f89c24..39754c60cf9c42418990f0aaaf318fc5bf16c4a8 100644 --- a/dbrepo-database-service/rest-service/src/test/resources/application.properties +++ b/dbrepo-database-service/rest-service/src/test/resources/application.properties @@ -19,11 +19,13 @@ spring.jpa.show-sql=false # logging logging.level.root=error -logging.level.at.tuwien.=info +logging.level.at.tuwien.=trace # rabbitmq fda.gateway.endpoint=http://dbrepo-broker-service:15672 spring.rabbitmq.host=dbrepo-broker-service +spring.rabbitmq.username=guest +spring.rabbitmq.password=guest # elastic fda.elastic.endpoint=search-mock-service:9200 \ No newline at end of file diff --git a/dbrepo-database-service/rest-service/src/test/resources/nginx/nginx.conf b/dbrepo-database-service/rest-service/src/test/resources/nginx/nginx.conf deleted file mode 100644 index 6604865024d8e32d66f23a8f49fd0bca5e2c3e70..0000000000000000000000000000000000000000 --- a/dbrepo-database-service/rest-service/src/test/resources/nginx/nginx.conf +++ /dev/null @@ -1,49 +0,0 @@ -user nginx; -worker_processes auto; -error_log /var/log/nginx/error_log; -pid /var/run/nginx.pid; -events { - worker_connections 1024; -} -http { - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - - access_log /var/log/nginx/access_log main; - - sendfile on; - tcp_nopush on; - tcp_nodelay on; - keepalive_timeout 65; - types_hash_max_size 2048; - client_max_body_size 100G; - - include /etc/nginx/mime.types; - default_type application/octet-stream; - - include /etc/nginx/conf.d/*.conf; - - map $http_upgrade $connection_upgrade { - default upgrade; - '' close; - } - - server { - listen 9095 default_server; - server_name _; - - location /api/broker { - rewrite ^/api/broker/(.*)$ /api/$1 break; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_pass http://dbrepo-broker-service:15672; - proxy_read_timeout 90; - } - } - -} - - diff --git a/dbrepo-database-service/rest-service/src/test/resources/weather/1_querystore.sql b/dbrepo-database-service/rest-service/src/test/resources/weather/1_querystore.sql index 3b7e62aa00d0665ecaaba421448afbfe44152cf6..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-database-service/rest-service/src/test/resources/weather/1_querystore.sql +++ b/dbrepo-database-service/rest-service/src/test/resources/weather/1_querystore.sql @@ -1,72 +0,0 @@ -CREATE SEQUENCE `qs_queries_seq`; -CREATE TABLE `qs_queries` -( - `id` bigint not null primary key default nextval(`qs_queries_seq`), - `created` datetime not null default now(), - `created_by` varchar(255) not null, - `query` text not null, - `query_normalized` text not null, - `is_persisted` boolean not null, - `query_hash` varchar(255) not null, - `result_hash` varchar(255), - `result_number` bigint -); -DELIMITER $$ -CREATE PROCEDURE hash_table(IN name VARCHAR(255), OUT hash VARCHAR(255)) -BEGIN - DECLARE _sql TEXT; - SELECT CONCAT('SELECT SHA2(GROUP_CONCAT(CONCAT_WS(\'\',', - GROUP_CONCAT(CONCAT('`', column_name, '`') ORDER BY column_name), - ') SEPARATOR \',\'), 256) AS hash FROM `', name, '` INTO @hash;') - FROM `information_schema`.`columns` - WHERE `table_schema` = DATABASE() - AND `table_name` = name - INTO _sql; - PREPARE stmt FROM _sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; - SET hash = @hash; -END $$ -DELIMITER $$ -CREATE PROCEDURE store_query(IN query TEXT, OUT queryId BIGINT) -BEGIN - DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); - DECLARE _username varchar(255) DEFAULT REGEXP_REPLACE(current_user(), '@.*', ''); - DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); - PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); - SELECT COUNT(*) FROM _tmp INTO @count; - IF @hash IS NULL THEN - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`) - SELECT _username, query, query, false, _queryhash, @hash, @count - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - ELSE - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`) - SELECT _username, query, query, false, _queryhash, @hash, @count - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - END IF; -END $$ -DELIMITER $$ -CREATE - DEFINER = 'root' PROCEDURE _store_query(IN _username VARCHAR(255), IN query TEXT, OUT queryId BIGINT) -BEGIN - DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); - DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); - PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); - SELECT COUNT(*) FROM _tmp INTO @count; - IF @hash IS NULL THEN - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`) - SELECT _username, query, query, false, _queryhash, @hash, @count - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - ELSE - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`) - SELECT _username, query, query, false, _queryhash, @hash, @count - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - END IF; -END $$ -DELIMITER ; \ No newline at end of file diff --git a/dbrepo-database-service/rest-service/src/test/resources/weather/2_weather.sql b/dbrepo-database-service/rest-service/src/test/resources/weather/2_weather.sql index a73e612b1d458366bc8a0a899ce259d3d89eff2a..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-database-service/rest-service/src/test/resources/weather/2_weather.sql +++ b/dbrepo-database-service/rest-service/src/test/resources/weather/2_weather.sql @@ -1,26 +0,0 @@ -/* https://www.kaggle.com/jsphyg/weather-dataset-rattle-package */ -CREATE TABLE weather_location -( - location VARCHAR(255) PRIMARY KEY, - lat DOUBLE PRECISION NULL, - lng DOUBLE PRECISION NULL -) WITH SYSTEM VERSIONING; - -CREATE TABLE weather_aus -( - id BIGINT NOT NULL PRIMARY KEY, - `date` DATE NOT NULL, - location VARCHAR(255) NULL, - mintemp DOUBLE PRECISION NULL, - rainfall DOUBLE PRECISION NULL, - FOREIGN KEY (location) REFERENCES weather_location (location) -) WITH SYSTEM VERSIONING; - -INSERT INTO weather_location (location, lat, lng) -VALUES ('Albury', -36.0653583, 146.9112214), - ('Sydney', -33.847927, 150.6517942); - -INSERT INTO weather_aus (id, `date`, location, mintemp, rainfall) -VALUES (1, '2008-12-01', 'Albury', 13.4, 0.6), - (2, '2008-12-02', 'Albury', 7.4, 0), - (3, '2008-12-03', 'Albury', 12.9, 0); diff --git a/dbrepo-database-service/rest-service/src/test/resources/weather/3_users.sql b/dbrepo-database-service/rest-service/src/test/resources/weather/3_users.sql index 6e42170c1ba8b8af50bc4bbe1e162c3bb8f1fc25..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-database-service/rest-service/src/test/resources/weather/3_users.sql +++ b/dbrepo-database-service/rest-service/src/test/resources/weather/3_users.sql @@ -1,3 +0,0 @@ -CREATE USER junit IDENTIFIED BY PASSWORD '*A8C67ABBEAE837AABCF49680A157D85D44A117E9'; -CREATE USER junit2 IDENTIFIED BY PASSWORD '*A8C67ABBEAE837AABCF49680A157D85D44A117E9'; -CREATE USER junit3 IDENTIFIED BY PASSWORD '*A8C67ABBEAE837AABCF49680A157D85D44A117E9'; \ No newline at end of file diff --git a/dbrepo-database-service/services/pom.xml b/dbrepo-database-service/services/pom.xml index af9f23c612056d65a1b11962697f5a2cae7c7786..db437866d6ba9ac22d179e86cdc114a5f8072f5c 100644 --- a/dbrepo-database-service/services/pom.xml +++ b/dbrepo-database-service/services/pom.xml @@ -4,13 +4,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> - <artifactId>fda-database-service</artifactId> + <artifactId>dbrepo-database-service</artifactId> <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </parent> <artifactId>services</artifactId> - <version>1.1.0-alpha</version> - <name>fda-database-service-services</name> + <version>1.2.0</version> + <name>dbrepo-database-service-services</name> </project> \ No newline at end of file diff --git a/dbrepo-database-service/services/src/main/java/at/tuwien/config/DockerConfig.java b/dbrepo-database-service/services/src/main/java/at/tuwien/config/DockerConfig.java deleted file mode 100644 index 2eded5372f75f3cfc5d2d9aa96ed8b6bbad8eac9..0000000000000000000000000000000000000000 --- a/dbrepo-database-service/services/src/main/java/at/tuwien/config/DockerConfig.java +++ /dev/null @@ -1,36 +0,0 @@ -package at.tuwien.config; - -import com.github.dockerjava.api.DockerClient; -import com.github.dockerjava.api.model.HostConfig; -import com.github.dockerjava.api.model.RestartPolicy; -import com.github.dockerjava.core.DefaultDockerClientConfig; -import com.github.dockerjava.core.DockerClientBuilder; -import com.github.dockerjava.core.DockerClientConfig; -import com.github.dockerjava.httpclient5.ApacheDockerHttpClient; -import com.github.dockerjava.transport.DockerHttpClient; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class DockerConfig { - - @Bean - public HostConfig hostConfig() { - return HostConfig.newHostConfig() - .withRestartPolicy(RestartPolicy.alwaysRestart()); - } - - @Bean - public DockerClient dockerClientConfiguration() { - final DockerClientConfig dockerClientConfig = DefaultDockerClientConfig.createDefaultConfigBuilder() - .withDockerHost("unix:///var/run/docker.sock") - .build(); - final DockerHttpClient dockerHttpClient = new ApacheDockerHttpClient.Builder() - .dockerHost(dockerClientConfig.getDockerHost()) - .sslConfig(dockerClientConfig.getSSLConfig()) - .build(); - return DockerClientBuilder.getInstance() - .withDockerHttpClient(dockerHttpClient) - .build(); - } -} diff --git a/dbrepo-database-service/services/src/main/java/at/tuwien/config/GatewayConfig.java b/dbrepo-database-service/services/src/main/java/at/tuwien/config/GatewayConfig.java index ce5a3eb952065f2ddcfd7f36e35819d909530f61..b30f9a567ca1abd794c1f630e633815606c14d00 100644 --- a/dbrepo-database-service/services/src/main/java/at/tuwien/config/GatewayConfig.java +++ b/dbrepo-database-service/services/src/main/java/at/tuwien/config/GatewayConfig.java @@ -21,7 +21,6 @@ public class GatewayConfig { @Value("${fda.client_id}") private String clientId; - @Value("${spring.rabbitmq.username}") private String brokerUsername; diff --git a/dbrepo-database-service/services/src/main/java/at/tuwien/events/JunitMockEvent.java b/dbrepo-database-service/services/src/main/java/at/tuwien/events/JunitMockEvent.java deleted file mode 100644 index 0fce13929f8a748f4cb819d8f1e6743131dd822c..0000000000000000000000000000000000000000 --- a/dbrepo-database-service/services/src/main/java/at/tuwien/events/JunitMockEvent.java +++ /dev/null @@ -1,17 +0,0 @@ -package at.tuwien.events; - -import org.springframework.context.ApplicationEvent; - -public class JunitMockEvent extends ApplicationEvent { - - private final String message; - - public JunitMockEvent(Object source, String message) { - super(source); - this.message = message; - } - - public String getMessage() { - return message; - } -} diff --git a/dbrepo-database-service/services/src/main/java/at/tuwien/exception/DatabaseConnectionException.java b/dbrepo-database-service/services/src/main/java/at/tuwien/exception/DatabaseConnectionException.java index 547de2d9ffd7a27dbc31076fcee2052c94157d26..2970fc77c3ffce6a1c511de858a82f8ecd492654 100644 --- a/dbrepo-database-service/services/src/main/java/at/tuwien/exception/DatabaseConnectionException.java +++ b/dbrepo-database-service/services/src/main/java/at/tuwien/exception/DatabaseConnectionException.java @@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; import java.io.IOException; -@ResponseStatus(code = HttpStatus.METHOD_NOT_ALLOWED) +@ResponseStatus(code = HttpStatus.SERVICE_UNAVAILABLE) public class DatabaseConnectionException extends IOException { public DatabaseConnectionException(String msg) { diff --git a/dbrepo-database-service/services/src/main/java/at/tuwien/exception/ImageNotSupportedException.java b/dbrepo-database-service/services/src/main/java/at/tuwien/exception/ImageNotSupportedException.java index 10cb1b1399a4d44a3889011d48aebd5284459b02..26aaa828d3289c80bef86aab32d914e9d635c32f 100644 --- a/dbrepo-database-service/services/src/main/java/at/tuwien/exception/ImageNotSupportedException.java +++ b/dbrepo-database-service/services/src/main/java/at/tuwien/exception/ImageNotSupportedException.java @@ -3,7 +3,7 @@ package at.tuwien.exception; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; -@ResponseStatus(code = HttpStatus.NOT_ACCEPTABLE, reason = "image not supported") +@ResponseStatus(code = HttpStatus.NOT_IMPLEMENTED, reason = "image not supported") public class ImageNotSupportedException extends Exception { public ImageNotSupportedException(String message) { diff --git a/dbrepo-database-service/services/src/main/java/at/tuwien/mapper/DatabaseMapper.java b/dbrepo-database-service/services/src/main/java/at/tuwien/mapper/DatabaseMapper.java index 3eb30d494652ef85af942dbd0a3957e08a9de37c..df3d18b7d83b12a5235e8ff6604cd76c8e17d54f 100644 --- a/dbrepo-database-service/services/src/main/java/at/tuwien/mapper/DatabaseMapper.java +++ b/dbrepo-database-service/services/src/main/java/at/tuwien/mapper/DatabaseMapper.java @@ -190,7 +190,7 @@ public interface DatabaseMapper { break; case WRITE_ALL: case WRITE_OWN: // todo restrict the access right - statement.append("CREATE, CREATE VIEW, SELECT, INSERT, UPDATE, DELETE"); + statement.append("SELECT, CREATE, CREATE VIEW, CREATE ROUTINE, CREATE TEMPORARY TABLES, LOCK TABLES, INDEX, TRIGGER, INSERT, UPDATE, DELETE"); break; } statement.append(" ON *.* TO `") @@ -205,6 +205,20 @@ public interface DatabaseMapper { } } + default PreparedStatement rawGrantUserProcedure(Connection connection, User user) + throws QueryMalformedException { + final StringBuilder statement = new StringBuilder("GRANT EXECUTE ON PROCEDURE `store_query` TO `") + .append(user.getUsername()) + .append("`@`%`;"); + log.debug("raw grant execute user procedure privileges statement [{}]", statement); + try { + return connection.prepareStatement(statement.toString()); + } catch (SQLException e) { + log.error("Failed to prepare statement {}, reason: {}", statement, e.getMessage()); + throw new QueryMalformedException("Failed to prepare statement", e); + } + } + default PreparedStatement rawGrantDefaultReadonlyAccessQuery(Connection connection, User user) throws QueryMalformedException { final StringBuilder statement = new StringBuilder("GRANT SELECT ON *.* TO `") diff --git a/dbrepo-database-service/services/src/main/java/at/tuwien/repository/jpa/IdentifierRepository.java b/dbrepo-database-service/services/src/main/java/at/tuwien/repository/jpa/IdentifierRepository.java index aa5e438a649cc4e649f85647142506bc873dd0df..283dd62e8d4b75d573a318fd80d5be21abaf834a 100644 --- a/dbrepo-database-service/services/src/main/java/at/tuwien/repository/jpa/IdentifierRepository.java +++ b/dbrepo-database-service/services/src/main/java/at/tuwien/repository/jpa/IdentifierRepository.java @@ -11,8 +11,8 @@ import java.util.Optional; @Repository public interface IdentifierRepository extends JpaRepository<Identifier, Long> { - List<Identifier> findByContainerId(Long containerId); + List<Identifier> findByDatabaseId(Long containerId); - Optional<Identifier> findByContainerIdAndDatabaseIdAndType(Long containerId, Long databaseId, IdentifierType type); + Optional<Identifier> findByDatabaseIdAndType(Long databaseId, IdentifierType type); } diff --git a/dbrepo-database-service/services/src/main/java/at/tuwien/service/DatabaseService.java b/dbrepo-database-service/services/src/main/java/at/tuwien/service/DatabaseService.java index 49d033e5b22feecc9dc822106bfba7980ee75ff7..6b5efff253ed7d4ec815edbdc3ed8de6d7360746 100644 --- a/dbrepo-database-service/services/src/main/java/at/tuwien/service/DatabaseService.java +++ b/dbrepo-database-service/services/src/main/java/at/tuwien/service/DatabaseService.java @@ -15,7 +15,7 @@ public interface DatabaseService { * Finds all databases in the metadata database for a given container id. * * @param containerId The container id. - * @return A list of databases + * @return List of databases. */ List<Database> findAll(Long containerId); @@ -25,8 +25,8 @@ public interface DatabaseService { * @param containerId The container id. * @param databaseId The database id. * @param principal The principal. - * @return The database if found. - * @throws DatabaseNotFoundException The database was not found. + * @return The database, if successful. + * @throws DatabaseNotFoundException The database was not found in the metadata database. */ Database findPublicOrMineById(Long containerId, Long databaseId, Principal principal) throws DatabaseNotFoundException; @@ -36,8 +36,8 @@ public interface DatabaseService { * * @param containerId the container id. * @param databaseId the database id. - * @return The database. - * @throws DatabaseNotFoundException The database was not found. + * @return The database, if successful. + * @throws DatabaseNotFoundException The database was not found in the metadata database. */ Database findById(Long containerId, Long databaseId) throws DatabaseNotFoundException; @@ -47,10 +47,15 @@ public interface DatabaseService { * * @param id The container id. * @param databaseId The database id. - * @throws DatabaseNotFoundException The database was not found. - * @throws ImageNotSupportedException The image is not supported. - * @throws DatabaseMalformedException The query string is malformed. - * @throws AmqpException The exchange could not be deleted. + * @throws DatabaseNotFoundException The database was not found in the metadata database. + * @throws ImageNotSupportedException The image is not supported. + * @throws DatabaseMalformedException The query string is malformed. + * @throws AmqpException The exchange could not be deleted. + * @throws ContainerConnectionException The connection to the container could not be established. + * @throws ContainerNotFoundException The container was not found in the metadata database. + * @throws DatabaseConnectionException The connection to the database could not be established by the database connector. + * @throws QueryMalformedException The mapped deletion query resulted in an invalid query statement and thus was rejected by the database engine. + * @throws UserNotFoundException The current user could not be loaded in the metadata database. */ void delete(Long id, Long databaseId, Principal principal) throws DatabaseNotFoundException, ImageNotSupportedException, @@ -62,13 +67,16 @@ public interface DatabaseService { * * @param id The container id. * @param createDto The metadata. - * @return The created database as stored on the metadata database. + * @return The database, if successful. * @throws ImageNotSupportedException The image is not supported. - * @throws ContainerNotFoundException The container was not found. + * @throws ContainerNotFoundException The container was not found in the metadata database. * @throws DatabaseMalformedException The query string is malformed. * @throws AmqpException The exchange could not be created. - * @throws ContainerConnectionException The connection to the container did not establish. + * @throws ContainerConnectionException The connection to the container could not be established. * @throws UserNotFoundException The current user could not be loaded in the metadata database. + * @throws DatabaseNameExistsException A database with this name already exists in the container. + * @throws DatabaseConnectionException The connection to the database could not be established by the database connector. + * @throws QueryMalformedException The mapped creation query resulted in an invalid query statement and thus was rejected by the database engine. */ Database create(Long id, DatabaseCreateDto createDto, Principal principal) throws ImageNotSupportedException, ContainerNotFoundException, @@ -81,7 +89,7 @@ public interface DatabaseService { * @param containerId The container id. * @param databaseId The database id. * @param data The visibility - * @return The database. + * @return The database, if successful. * @throws DatabaseNotFoundException The database was not found in the metadata database. */ Database visibility(Long containerId, Long databaseId, DatabaseModifyVisibilityDto data) @@ -93,7 +101,7 @@ public interface DatabaseService { * @param containerId The container id. * @param databaseId The database id. * @param transferDto The payload with the new owner. - * @return The database. + * @return The database, if successful. * @throws DatabaseNotFoundException The database was not found in the metadata database. * @throws UserNotFoundException The new user was not found in the metadata database. */ diff --git a/dbrepo-database-service/services/src/main/java/at/tuwien/service/IdentifierService.java b/dbrepo-database-service/services/src/main/java/at/tuwien/service/IdentifierService.java index 3edc0a742624918ed0a8937544d9b460f8ff28a9..a60abddb2bf996f01c0aaf0b6ebe99e774775080 100644 --- a/dbrepo-database-service/services/src/main/java/at/tuwien/service/IdentifierService.java +++ b/dbrepo-database-service/services/src/main/java/at/tuwien/service/IdentifierService.java @@ -9,7 +9,7 @@ import java.util.List; @Service public interface IdentifierService { - List<Identifier> findAll(Long containerId); + List<Identifier> findAll(Long databaseId); - Identifier find(Long containerId, Long databaseId, IdentifierType type) throws IdentifierNotFoundException; + Identifier find(Long databaseId, IdentifierType type) throws IdentifierNotFoundException; } diff --git a/dbrepo-database-service/services/src/main/java/at/tuwien/service/LicenseService.java b/dbrepo-database-service/services/src/main/java/at/tuwien/service/LicenseService.java index 6cc591a0abcf9b7cb977e673ecdda04a0bf7b4cb..4bea3499465405333a26551591bdfe508da1ff7e 100644 --- a/dbrepo-database-service/services/src/main/java/at/tuwien/service/LicenseService.java +++ b/dbrepo-database-service/services/src/main/java/at/tuwien/service/LicenseService.java @@ -8,7 +8,7 @@ import java.util.List; public interface LicenseService { /** - * Finds all licenses in the metadata repository + * Finds all licenses in the metadata database. * * @return List of licenses */ diff --git a/dbrepo-database-service/services/src/main/java/at/tuwien/service/MessageQueueService.java b/dbrepo-database-service/services/src/main/java/at/tuwien/service/MessageQueueService.java index 6693e408d3960b894040edecf0c3a526212e4c16..16dcd2a550ec06aaf66a6960107be2caa71622d0 100644 --- a/dbrepo-database-service/services/src/main/java/at/tuwien/service/MessageQueueService.java +++ b/dbrepo-database-service/services/src/main/java/at/tuwien/service/MessageQueueService.java @@ -9,6 +9,11 @@ import java.security.Principal; public interface MessageQueueService { + /** + * Initializes the exchanges on the Broker Service for each database in the metadata database. + * + * @throws AmqpException The exchange could not be created. + */ @PostConstruct void init() throws AmqpException; @@ -30,10 +35,11 @@ public interface MessageQueueService { void createUser(User user) throws BrokerVirtualHostCreationException; /** - * Updates the virtual host permissions in the broker service. + * Updates the virtual host permissions in the Broker Service for a user with given principal. * - * @param principal Te user. - * @throws BrokerVirtualHostCreationException Could not update the permissions. + * @param principal The user principal. + * @throws BrokerVirtualHostCreationException The Broker Service refused the update of the permissions. + * @throws BrokerVirtualHostGrantException The Broker Service refused to grant the permissions. */ void updatePermissions(Principal principal) throws BrokerVirtualHostCreationException, BrokerVirtualHostGrantException; diff --git a/dbrepo-database-service/services/src/main/java/at/tuwien/service/impl/AccessServiceImpl.java b/dbrepo-database-service/services/src/main/java/at/tuwien/service/impl/AccessServiceImpl.java index bd5a4ab1fc6224ebf16538b2fd0ef4eff3b279ac..4c12336aa3df9305425b842655b889b746d9d211 100644 --- a/dbrepo-database-service/services/src/main/java/at/tuwien/service/impl/AccessServiceImpl.java +++ b/dbrepo-database-service/services/src/main/java/at/tuwien/service/impl/AccessServiceImpl.java @@ -53,7 +53,7 @@ public class AccessServiceImpl extends HibernateConnector implements AccessServi public DatabaseAccess find(Long databaseId, String username) throws AccessDeniedException { final Optional<DatabaseAccess> optional = databaseAccessRepository.findByDatabaseIdAndUsername(databaseId, username); if (optional.isEmpty()) { - throw new AccessDeniedException("Failed to retrieve access"); + throw new AccessDeniedException("Failed to retrieve access to database with id " + databaseId + " for user with username '" + username + "'"); } return optional.get(); } @@ -67,8 +67,7 @@ public class AccessServiceImpl extends HibernateConnector implements AccessServi final Database database = databaseService.findById(containerId, databaseId); final Container container = database.getContainer(); final User user = userService.findByUsername(accessDto.getUsername()); - log.trace("access be given to user with username {}", user.getUsername()); - log.trace("database owner has username {}", database.getOwner().getUsername()); + log.trace("give access to user with username {}", user.getUsername()); if (database.getOwner().getUsername().equals(user.getUsername())) { log.error("Failed to give access to user with username {}, is already database owner", user.getUsername()); throw new NotAllowedException("Failed give access"); @@ -78,14 +77,19 @@ public class AccessServiceImpl extends HibernateConnector implements AccessServi throw new NotAllowedException("Failed to give access"); } final User root = databaseMapper.containerToPrivilegedUser(container); - final ComboPooledDataSource dataSource = getDataSource(container.getImage(), container, root); + final ComboPooledDataSource dataSource = getDataSource(container.getImage(), container, database, root); try { final Connection connection = dataSource.getConnection(); - /* create user */ + /* create user if not exists */ final PreparedStatement preparedStatement1 = databaseMapper.userToRawCreateUserQuery(connection, user); preparedStatement1.executeUpdate(); + /* grant access */ final PreparedStatement preparedStatement2 = databaseMapper.rawGrantUserAccessQuery(connection, accessDto); preparedStatement2.executeUpdate(); + final PreparedStatement preparedStatement3 = databaseMapper.rawGrantUserProcedure(connection, user); + preparedStatement3.executeUpdate(); + final PreparedStatement preparedStatement4 = databaseMapper.rawFlushPrivileges(connection); + preparedStatement4.executeUpdate(); } catch (SQLException e) { log.error("Failed to give database access {}, reason {}", accessDto, e.getMessage()); throw new DatabaseMalformedException("Failed to execute query", e); @@ -112,13 +116,20 @@ public class AccessServiceImpl extends HibernateConnector implements AccessServi throw new NotAllowedException("Failed modify access"); } final User root = databaseMapper.containerToPrivilegedUser(container); - final ComboPooledDataSource dataSource = getDataSource(container.getImage(), container, root); + final ComboPooledDataSource dataSource = getDataSource(container.getImage(), container, database, root); final DatabaseGiveAccessDto giveAccess = databaseMapper.databaseModifyAccessToDatabaseGiveAccessDto(username, accessDto); try { final Connection connection = dataSource.getConnection(); - /* create user */ + /* create user if not exists */ + final PreparedStatement preparedStatement1 = databaseMapper.userToRawCreateUserQuery(connection, user); + preparedStatement1.executeUpdate(); + /* grant access */ final PreparedStatement preparedStatement2 = databaseMapper.rawGrantUserAccessQuery(connection, giveAccess); preparedStatement2.executeUpdate(); + final PreparedStatement preparedStatement3 = databaseMapper.rawGrantUserProcedure(connection, user); + preparedStatement3.executeUpdate(); + final PreparedStatement preparedStatement4 = databaseMapper.rawFlushPrivileges(connection); + preparedStatement4.executeUpdate(); } catch (SQLException e) { log.error("Failed to modify database access {}, reason {}", accessDto, e.getMessage()); throw new DatabaseMalformedException("Failed to execute query", e); diff --git a/dbrepo-database-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java b/dbrepo-database-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java index 374ae7ba84acb94c152e9d86b8c3a3374074083c..988e18fb8ccf2c55159d3c9cd3a4bb1ed34ce36d 100644 --- a/dbrepo-database-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java +++ b/dbrepo-database-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java @@ -24,13 +24,13 @@ public class IdentifierServiceImpl implements IdentifierService { } @Override - public List<Identifier> findAll(Long containerId) { - return identifierRepository.findByContainerId(containerId); + public List<Identifier> findAll(Long databaseId) { + return identifierRepository.findByDatabaseId(databaseId); } @Override - public Identifier find(Long containerId, Long databaseId, IdentifierType type) throws IdentifierNotFoundException { - final Optional<Identifier> optional = identifierRepository.findByContainerIdAndDatabaseIdAndType(containerId, databaseId, type); + public Identifier find(Long databaseId, IdentifierType type) throws IdentifierNotFoundException { + final Optional<Identifier> optional = identifierRepository.findByDatabaseIdAndType(databaseId, type); if (optional.isEmpty()) { throw new IdentifierNotFoundException("Failed to find identifier"); } diff --git a/dbrepo-database-service/services/src/main/java/at/tuwien/service/impl/MariaDbServiceImpl.java b/dbrepo-database-service/services/src/main/java/at/tuwien/service/impl/MariaDbServiceImpl.java index 178bfcd3dfe683084ff74625da50ba93a5fe2678..fd055f90ed8c06e88516d7092d5eb23442a87bc2 100644 --- a/dbrepo-database-service/services/src/main/java/at/tuwien/service/impl/MariaDbServiceImpl.java +++ b/dbrepo-database-service/services/src/main/java/at/tuwien/service/impl/MariaDbServiceImpl.java @@ -139,23 +139,14 @@ public class MariaDbServiceImpl extends HibernateConnector implements DatabaseSe try { final Connection connection = dataSource.getConnection(); /* create database */ - final PreparedStatement preparedStatement = databaseMapper.databaseToRawCreateDatabaseQuery(connection, database); - preparedStatement.executeUpdate(); - /* create user */ - final PreparedStatement preparedStatement1 = databaseMapper.userToRawCreateUserQuery(connection, user); + final PreparedStatement preparedStatement1 = databaseMapper.databaseToRawCreateDatabaseQuery(connection, database); preparedStatement1.executeUpdate(); - final PreparedStatement preparedStatement2 = databaseMapper.rawGrantCreatorAccessQuery(connection, user); + /* create user */ + final PreparedStatement preparedStatement2 = databaseMapper.userToRawCreateUserQuery(connection, user); preparedStatement2.executeUpdate(); - final PreparedStatement preparedStatement3 = databaseMapper.rawFlushPrivileges(connection); - preparedStatement3.executeUpdate(); - /* grant read-only access */ - final PreparedStatement preparedStatement4 = databaseMapper.rawGrantDefaultReadonlyAccessQuery(connection, user); - preparedStatement4.executeUpdate(); - final PreparedStatement preparedStatement5 = databaseMapper.rawFlushPrivileges(connection); - preparedStatement5.executeUpdate(); } catch (SQLException e) { log.error("Failed to create database with internal name {}, reason: {}", database.getInternalName(), e.getMessage()); - throw new DatabaseMalformedException("Failed to create database", e); + throw new DatabaseMalformedException("Failed to create database: " + e.getMessage(), e); } finally { dataSource.close(); } diff --git a/dbrepo-discovery-service/Dockerfile b/dbrepo-discovery-service/Dockerfile index 205952ddc2006457366af58da5d249e58824a2e9..8cbe9357c09b0970577ffa000ec3476800bbdb1a 100644 --- a/dbrepo-discovery-service/Dockerfile +++ b/dbrepo-discovery-service/Dockerfile @@ -1,11 +1,16 @@ ###### FIRST STAGE ###### -FROM maven:slim as build +FROM dbrepo-metadata-db:latest as dependency MAINTAINER Martin Weise <martin.weise@tuwien.ac.at> +###### SECOND STAGE ###### +FROM maven:slim as build + COPY ./pom.xml ./ RUN mvn -fn -B dependency:go-offline > /dev/null +COPY --from=dependency /root/.m2/repository/at/tuwien /root/.m2/repository/at/tuwien + COPY ./rest-service ./rest-service COPY ./services ./services COPY ./report ./report @@ -13,7 +18,7 @@ COPY ./report ./report # Make sure it compiles RUN mvn -q clean package -DskipTests > /dev/null -###### SECOND STAGE ###### +###### THIRD STAGE ###### FROM openjdk:11-jre-slim as runtime ENV METADATA_DB=fda diff --git a/dbrepo-discovery-service/pom.xml b/dbrepo-discovery-service/pom.xml index db7aca0de81b4fcd3d6431d30068d26552bf701f..c7b10ef2f4cda0937bdd5737f8d38d6ab477267d 100644 --- a/dbrepo-discovery-service/pom.xml +++ b/dbrepo-discovery-service/pom.xml @@ -9,9 +9,9 @@ </parent> <groupId>at.tuwien</groupId> - <artifactId>fda-discovery-service</artifactId> - <version>1.1.0-alpha</version> - <name>fda-discovery-service</name> + <artifactId>dbrepo-discovery-service</artifactId> + <version>1.2.0</version> + <name>dbrepo-discovery-service</name> <description>Demo project for Spring Boot</description> <packaging>pom</packaging> @@ -42,6 +42,16 @@ <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> <version>${spring-cloud.version}</version> </dependency> + <!-- Data Source --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + <dependency> + <groupId>org.mariadb.jdbc</groupId> + <artifactId>mariadb-java-client</artifactId> + <version>${mariadb.version}</version> + </dependency> <!-- Monitoring --> <dependency> <groupId>io.micrometer</groupId> @@ -75,6 +85,12 @@ <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.version}</version> </dependency> + <dependency> + <groupId>at.tuwien</groupId> + <artifactId>dbrepo-metadata-db-test</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> </dependencies> <build> @@ -90,7 +106,7 @@ <exclude>at/tuwien/mapper/**/*</exclude> <exclude>at/tuwien/exception/**/*</exclude> <exclude>at/tuwien/config/**/*</exclude> - <exclude>**/DiscoveryServiceApplication.class</exclude> + <exclude>**/DbrepoDiscoveryServiceApplication.class</exclude> </excludes> </configuration> <executions> diff --git a/dbrepo-discovery-service/report/pom.xml b/dbrepo-discovery-service/report/pom.xml index e6ad6e47bc187b109591e586d8917148be81c693..e5f5fcaad75a161a5c72d3df824ad95fa797e0fd 100644 --- a/dbrepo-discovery-service/report/pom.xml +++ b/dbrepo-discovery-service/report/pom.xml @@ -5,13 +5,13 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>at.tuwien</groupId> - <artifactId>fda-discovery-service</artifactId> - <version>1.1.0-alpha</version> + <artifactId>dbrepo-discovery-service</artifactId> + <version>1.2.0</version> </parent> <artifactId>report</artifactId> - <version>1.1.0-alpha</version> - <name>fda-discovery-service-report</name> + <version>1.2.0</version> + <name>dbrepo-discovery-service-report</name> <properties> <jacoco.version>0.8.7</jacoco.version> diff --git a/dbrepo-discovery-service/rest-service/pom.xml b/dbrepo-discovery-service/rest-service/pom.xml index 33163658cc913c4d67b9ffc45f2a5e14de74b12a..453330597b6bee2a57cbd803fadf4f5f58a99557 100644 --- a/dbrepo-discovery-service/rest-service/pom.xml +++ b/dbrepo-discovery-service/rest-service/pom.xml @@ -5,13 +5,13 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>at.tuwien</groupId> - <artifactId>fda-discovery-service</artifactId> - <version>1.1.0-alpha</version> + <artifactId>dbrepo-discovery-service</artifactId> + <version>1.2.0</version> </parent> <artifactId>rest-service</artifactId> - <version>1.1.0-alpha</version> - <name>fda-discovery-service-discovery</name> + <version>1.2.0</version> + <name>dbrepo-discovery-service-discovery</name> <properties> <jacoco.version>0.8.7</jacoco.version> diff --git a/dbrepo-discovery-service/rest-service/src/main/java/at/tuwien/DiscoveryServiceApplication.java b/dbrepo-discovery-service/rest-service/src/main/java/at/tuwien/DbrepoDiscoveryServiceApplication.java similarity index 71% rename from dbrepo-discovery-service/rest-service/src/main/java/at/tuwien/DiscoveryServiceApplication.java rename to dbrepo-discovery-service/rest-service/src/main/java/at/tuwien/DbrepoDiscoveryServiceApplication.java index 84487f99cc11a38f7f93ff69538b8af0704d308b..6561edd18f7cefbf79d75824a8a16a887f147ca4 100644 --- a/dbrepo-discovery-service/rest-service/src/main/java/at/tuwien/DiscoveryServiceApplication.java +++ b/dbrepo-discovery-service/rest-service/src/main/java/at/tuwien/DbrepoDiscoveryServiceApplication.java @@ -6,10 +6,10 @@ import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @SpringBootApplication @EnableEurekaServer -public class DiscoveryServiceApplication { +public class DbrepoDiscoveryServiceApplication { public static void main(String[] args) { - SpringApplication.run(DiscoveryServiceApplication.class, args); + SpringApplication.run(DbrepoDiscoveryServiceApplication.class, args); } } diff --git a/dbrepo-discovery-service/rest-service/src/main/resources/application-docker.yml b/dbrepo-discovery-service/rest-service/src/main/resources/application-docker.yml new file mode 100644 index 0000000000000000000000000000000000000000..967b742f9e3e7f4514211dd2971009dff253c04f --- /dev/null +++ b/dbrepo-discovery-service/rest-service/src/main/resources/application-docker.yml @@ -0,0 +1,39 @@ +app.version: '@project.version@' +spring: + main.banner-mode: off + datasource: + url: jdbc:mariadb://metadata-db:3306/fda + driver-class-name: org.mariadb.jdbc.Driver + username: "${METADATA_USERNAME}" + password: "${METADATA_PASSWORD}" + jpa: + show-sql: false + database-platform: org.hibernate.dialect.MariaDBDialect + hibernate: + ddl-auto: validate + use-new-id-generator-mappings: false + open-in-view: false + properties: + hibernate: + default_schema: fda + jdbc: + time_zone: UTC + application: + name: discovery-service + cloud: + loadbalancer.ribbon.enabled: false +management.endpoints.web.exposure.include: health,info,prometheus +server.port: 9090 +logging: + pattern.console: "%d %highlight(%-5level) %msg%n" + level: + root: warn + at.tuwien.: "${LOG_LEVEL}" + org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver: debug +eureka: + eureka.client.register-with-eureka: false + eureka.client.fetch-registry: false + instance.hostname: discovery-service + client.serviceUrl.defaultZone: http://discovery-service:9090/eureka/ +fda: + ready.path: /ready \ No newline at end of file diff --git a/dbrepo-discovery-service/rest-service/src/main/resources/application.yml b/dbrepo-discovery-service/rest-service/src/main/resources/application.yml index 641d1a87a42dc371da51053ff98cce8041b86500..56b3f670d078e0998a668e5c401a8c2bc02c3a5a 100644 --- a/dbrepo-discovery-service/rest-service/src/main/resources/application.yml +++ b/dbrepo-discovery-service/rest-service/src/main/resources/application.yml @@ -1,3 +1,4 @@ +app.version: '@project.version@' spring: main.banner-mode: off datasource: diff --git a/dbrepo-discovery-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java b/dbrepo-discovery-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java deleted file mode 100644 index ea8e189a75873f7e84553ceaa0a16f0a11a0cef7..0000000000000000000000000000000000000000 --- a/dbrepo-discovery-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package at.tuwien; - -import org.springframework.test.context.TestPropertySource; - -@TestPropertySource(locations = "classpath:application.properties") -public abstract class BaseUnitTest { -} diff --git a/dbrepo-discovery-service/rest-service/src/test/java/at/tuwien/service/MockServiceTest.java b/dbrepo-discovery-service/rest-service/src/test/java/at/tuwien/service/MockServiceTest.java deleted file mode 100644 index c1aefac2fd03cd541ac554c00eb51f0aeb0b2bc9..0000000000000000000000000000000000000000 --- a/dbrepo-discovery-service/rest-service/src/test/java/at/tuwien/service/MockServiceTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package at.tuwien.service; - -import at.tuwien.BaseUnitTest; -import lombok.extern.log4j.Log4j2; -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.test.context.junit.jupiter.SpringExtension; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -@Log4j2 -@SpringBootTest -@ExtendWith(SpringExtension.class) -public class MockServiceTest extends BaseUnitTest { - - @Autowired - private MockService mockService; - - @Test - public void test_succeeds() { - - /* test */ - final Boolean response = mockService.mock(); - assertTrue(response); - } - -} diff --git a/dbrepo-discovery-service/services/pom.xml b/dbrepo-discovery-service/services/pom.xml index 89ee91e9944130cc7492a75aece697c6810d3a00..8ac4f5a15d79b5e1d2663e37c38120e5e7065963 100644 --- a/dbrepo-discovery-service/services/pom.xml +++ b/dbrepo-discovery-service/services/pom.xml @@ -4,13 +4,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> - <artifactId>fda-discovery-service</artifactId> + <artifactId>dbrepo-discovery-service</artifactId> <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </parent> <artifactId>services</artifactId> - <version>1.1.0-alpha</version> - <name>fda-discovery-service-services</name> + <version>1.2.0</version> + <name>dbrepo-discovery-service-services</name> </project> \ No newline at end of file diff --git a/dbrepo-gateway-service/Dockerfile b/dbrepo-gateway-service/Dockerfile index 7a9bf3614211731dfefefca40e41698bcde70614..c30a04e0c411762a68e585a4dab2c4e3072d00c4 100644 --- a/dbrepo-gateway-service/Dockerfile +++ b/dbrepo-gateway-service/Dockerfile @@ -1,14 +1,18 @@ ###### FIRST STAGE ###### -FROM maven:slim as build +FROM dbrepo-metadata-db:latest as dependency MAINTAINER Martin Weise <martin.weise@tuwien.ac.at> +###### FIRST STAGE ###### +FROM maven:slim as build + COPY ./pom.xml ./ RUN mvn -fn -B dependency:go-offline > /dev/null -COPY ./rest-service ./rest-service -COPY ./services ./services +COPY --from=dependency /root/.m2/repository/at/tuwien /root/.m2/repository/at/tuwien + COPY ./report ./report +COPY ./rest-service ./rest-service # Make sure it compiles RUN mvn -q clean package -DskipTests > /dev/null diff --git a/dbrepo-gateway-service/pom.xml b/dbrepo-gateway-service/pom.xml index 5110b896d822418f6133b6fc918fcf1f4dcbaebc..addee3cef67e6f4a64c220ac55aed5b92c7739e3 100644 --- a/dbrepo-gateway-service/pom.xml +++ b/dbrepo-gateway-service/pom.xml @@ -8,10 +8,10 @@ <version>2.3.4.RELEASE</version> </parent> <groupId>at.tuwien</groupId> - <artifactId>fda-gateway-service</artifactId> - <version>1.1.0-alpha</version> - <name>fda-gateway-service</name> - <description>Demo project for Spring Boot</description> + <artifactId>dbrepo-gateway-service</artifactId> + <version>1.2.0</version> + <name>dbrepo-gateway-service</name> + <description>Service that proxies the API to the microservices</description> <url>https://dbrepo-docs.ossdip.at</url> <developers> <developer> @@ -25,7 +25,6 @@ <modules> <module>rest-service</module> <module>report</module> - <module>services</module> </modules> <properties> @@ -92,6 +91,12 @@ <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.version}</version> </dependency> + <dependency> + <groupId>at.tuwien</groupId> + <artifactId>dbrepo-metadata-db-test</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> </dependencies> <dependencyManagement> @@ -119,7 +124,7 @@ <exclude>at/tuwien/mapper/**/*</exclude> <exclude>at/tuwien/exception/**/*</exclude> <exclude>at/tuwien/config/**/*</exclude> - <exclude>**/GatewayServiceApplication.class</exclude> + <exclude>**/DbrepoGatewayServiceApplication.class</exclude> </excludes> </configuration> <executions> diff --git a/dbrepo-gateway-service/report/pom.xml b/dbrepo-gateway-service/report/pom.xml index 8d396a026b07e487cc507490990b784c37fe3ee3..7c2e3a729c3794be87390b6235722a6bfae9bbc2 100644 --- a/dbrepo-gateway-service/report/pom.xml +++ b/dbrepo-gateway-service/report/pom.xml @@ -5,13 +5,13 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>at.tuwien</groupId> - <artifactId>fda-gateway-service</artifactId> - <version>1.1.0-alpha</version> + <artifactId>dbrepo-gateway-service</artifactId> + <version>1.2.0</version> </parent> <artifactId>report</artifactId> - <version>1.1.0-alpha</version> - <name>fda-gateway-service-report</name> + <version>1.2.0</version> + <name>dbrepo-gateway-service-report</name> <description> This module is only intended for the pipeline coverage report. See the detailed report in the respective modules @@ -27,11 +27,6 @@ <artifactId>rest-service</artifactId> <version>${project.version}</version> </dependency> - <dependency> - <groupId>at.tuwien</groupId> - <artifactId>services</artifactId> - <version>${project.version}</version> - </dependency> </dependencies> <build> diff --git a/dbrepo-gateway-service/rest-service/pom.xml b/dbrepo-gateway-service/rest-service/pom.xml index f25a2407ae60d5fe3fd70b870ce19ba162a31c06..6a543cd5edc51564b1141c4e67f72fb169502c80 100644 --- a/dbrepo-gateway-service/rest-service/pom.xml +++ b/dbrepo-gateway-service/rest-service/pom.xml @@ -5,13 +5,13 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>at.tuwien</groupId> - <artifactId>fda-gateway-service</artifactId> - <version>1.1.0-alpha</version> + <artifactId>dbrepo-gateway-service</artifactId> + <version>1.2.0</version> </parent> <artifactId>rest-service</artifactId> - <version>1.1.0-alpha</version> - <name>fda-gateway-service-rest-service</name> + <version>1.2.0</version> + <name>dbrepo-gateway-service-rest-service</name> <properties> <jacoco.version>0.8.7</jacoco.version> @@ -33,12 +33,6 @@ </plugins> </build> - <dependencies> - <dependency> - <groupId>at.tuwien</groupId> - <artifactId>services</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> + <dependencies /> </project> \ No newline at end of file diff --git a/dbrepo-gateway-service/rest-service/src/main/java/at/tuwien/GatewayServiceApplication.java b/dbrepo-gateway-service/rest-service/src/main/java/at/tuwien/DbrepoGatewayServiceApplication.java similarity index 64% rename from dbrepo-gateway-service/rest-service/src/main/java/at/tuwien/GatewayServiceApplication.java rename to dbrepo-gateway-service/rest-service/src/main/java/at/tuwien/DbrepoGatewayServiceApplication.java index 60ac57e608a0c26461bf79768dcc459fba5308d5..821368936f057582faa2e9e9afaa0bb8dc37102f 100644 --- a/dbrepo-gateway-service/rest-service/src/main/java/at/tuwien/GatewayServiceApplication.java +++ b/dbrepo-gateway-service/rest-service/src/main/java/at/tuwien/DbrepoGatewayServiceApplication.java @@ -4,10 +4,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class GatewayServiceApplication { +public class DbrepoGatewayServiceApplication { public static void main(String[] args) { - SpringApplication.run(GatewayServiceApplication.class, args); + SpringApplication.run(DbrepoGatewayServiceApplication.class, args); } } diff --git a/dbrepo-gateway-service/rest-service/src/main/resources/application.yml b/dbrepo-gateway-service/rest-service/src/main/resources/application.yml index 61615339d0bfd8ff6aa7c3a539268b18f3f39bff..3c021d74d60d42c47898642d9f03dc2421b62881 100644 --- a/dbrepo-gateway-service/rest-service/src/main/resources/application.yml +++ b/dbrepo-gateway-service/rest-service/src/main/resources/application.yml @@ -1,3 +1,4 @@ +app.version: '@project.version@' spring: main.banner-mode: off datasource: diff --git a/dbrepo-gateway-service/rest-service/src/test/java/at/tuwien/service/MockServiceTest.java b/dbrepo-gateway-service/rest-service/src/test/java/at/tuwien/service/MockServiceTest.java deleted file mode 100644 index c1aefac2fd03cd541ac554c00eb51f0aeb0b2bc9..0000000000000000000000000000000000000000 --- a/dbrepo-gateway-service/rest-service/src/test/java/at/tuwien/service/MockServiceTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package at.tuwien.service; - -import at.tuwien.BaseUnitTest; -import lombok.extern.log4j.Log4j2; -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.test.context.junit.jupiter.SpringExtension; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -@Log4j2 -@SpringBootTest -@ExtendWith(SpringExtension.class) -public class MockServiceTest extends BaseUnitTest { - - @Autowired - private MockService mockService; - - @Test - public void test_succeeds() { - - /* test */ - final Boolean response = mockService.mock(); - assertTrue(response); - } - -} diff --git a/dbrepo-gateway-service/services/pom.xml b/dbrepo-gateway-service/services/pom.xml deleted file mode 100644 index faf10e90099cdd4f87c105df0951c56775e15b22..0000000000000000000000000000000000000000 --- a/dbrepo-gateway-service/services/pom.xml +++ /dev/null @@ -1,16 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <artifactId>fda-gateway-service</artifactId> - <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> - </parent> - - <artifactId>services</artifactId> - <version>1.1.0-alpha</version> - <name>fda-gateway-service-services</name> - -</project> \ No newline at end of file diff --git a/dbrepo-gateway-service/services/src/main/java/at/tuwien/service/MockService.java b/dbrepo-gateway-service/services/src/main/java/at/tuwien/service/MockService.java deleted file mode 100644 index 521e25785d998c394a5a774b9299da0c93206ffa..0000000000000000000000000000000000000000 --- a/dbrepo-gateway-service/services/src/main/java/at/tuwien/service/MockService.java +++ /dev/null @@ -1,12 +0,0 @@ -package at.tuwien.service; - -import org.springframework.stereotype.Service; - -@Service -public class MockService { - - public Boolean mock() { - return true; - } - -} diff --git a/dbrepo-identifier-service/Dockerfile b/dbrepo-identifier-service/Dockerfile index e0bab808145952fe5fdaeaa3acc4714bb152791a..13204336ab7166f2648197122cc173008d530f96 100644 --- a/dbrepo-identifier-service/Dockerfile +++ b/dbrepo-identifier-service/Dockerfile @@ -1,5 +1,5 @@ ###### FIRST STAGE ###### -FROM fda-metadata-db:latest as dependency +FROM dbrepo-metadata-db:latest as dependency MAINTAINER Martin Weise <martin.weise@tuwien.ac.at> ###### SECOND STAGE ###### diff --git a/dbrepo-identifier-service/api/pom.xml b/dbrepo-identifier-service/api/pom.xml index fee78b58ec44f0884f5b02a106f8c311b974b84d..eaf60df4a5337cd2079c2f2bb155fda95d11b0a8 100644 --- a/dbrepo-identifier-service/api/pom.xml +++ b/dbrepo-identifier-service/api/pom.xml @@ -4,13 +4,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> - <artifactId>fda-identifier-service</artifactId> + <artifactId>dbrepo-identifier-service</artifactId> <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </parent> <artifactId>api</artifactId> - <name>fda-identifier-service-api</name> + <name>dbrepo-identifier-service-api</name> <properties> <jacoco.version>0.8.7</jacoco.version> diff --git a/dbrepo-identifier-service/pom.xml b/dbrepo-identifier-service/pom.xml index 141205704447335261db650b7b20d1b61811af8f..2e3749b2b744bc4ffeda3b8e95607828bfe911a3 100644 --- a/dbrepo-identifier-service/pom.xml +++ b/dbrepo-identifier-service/pom.xml @@ -9,10 +9,10 @@ </parent> <groupId>at.tuwien</groupId> - <artifactId>fda-identifier-service</artifactId> - <version>1.1.0-alpha</version> - <name>fda-identifier-service</name> - <description>Demo project for Spring Boot</description> + <artifactId>dbrepo-identifier-service</artifactId> + <version>1.2.0</version> + <name>dbrepo-identifier-service</name> + <description>Service that manages the identifiers</description> <packaging>pom</packaging> <modules> @@ -86,12 +86,12 @@ <!-- Entities and API --> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-entites</artifactId> + <artifactId>dbrepo-metadata-db-entites</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-api</artifactId> + <artifactId>dbrepo-metadata-db-api</artifactId> <version>${project.version}</version> </dependency> <!-- DataSource --> @@ -162,6 +162,11 @@ <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.version}</version> </dependency> + <dependency> + <groupId>at.tuwien</groupId> + <artifactId>dbrepo-metadata-db-test</artifactId> + <version>${project.version}</version> + </dependency> <!-- Export --> <dependency> <groupId>commons-io</groupId> @@ -211,7 +216,7 @@ <exclude>at/tuwien/exception/**/*</exclude> <exclude>at/tuwien/utils/**/*</exclude> <exclude>at/tuwien/handlers/**/*</exclude> - <exclude>**/IdentifierServiceApplication.class</exclude> + <exclude>**/DbrepoIdentifierServiceApplication.class</exclude> </excludes> </configuration> <executions> diff --git a/dbrepo-identifier-service/report/pom.xml b/dbrepo-identifier-service/report/pom.xml index 78d7776137809e4d3cf16692997e246f893ac30b..64e24ab39f048d10fc060e841fb7b8dbe6c74daa 100644 --- a/dbrepo-identifier-service/report/pom.xml +++ b/dbrepo-identifier-service/report/pom.xml @@ -4,13 +4,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> - <artifactId>fda-identifier-service</artifactId> + <artifactId>dbrepo-identifier-service</artifactId> <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </parent> <artifactId>report</artifactId> - <name>fda-identifier-service-report</name> + <name>dbrepo-identifier-service-report</name> <properties> <jacoco.version>0.8.7</jacoco.version> diff --git a/dbrepo-identifier-service/rest-service/pom.xml b/dbrepo-identifier-service/rest-service/pom.xml index 31a33f07f31c8295095daee72394f774d5d18791..b89e9ddd04152eb87ef7a578dce76ee639e0ae33 100644 --- a/dbrepo-identifier-service/rest-service/pom.xml +++ b/dbrepo-identifier-service/rest-service/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> - <artifactId>fda-identifier-service</artifactId> + <artifactId>dbrepo-identifier-service</artifactId> <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </parent> <artifactId>rest-service</artifactId> - <version>1.1.0-alpha</version> - <name>fda-identifier-service-rest</name> + <version>1.2.0</version> + <name>dbrepo-identifier-service-rest</name> <dependencies> <dependency> diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/FdaMetadataServiceApplication.java b/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/DbrepoIdentifierServiceApplication.java similarity index 86% rename from dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/FdaMetadataServiceApplication.java rename to dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/DbrepoIdentifierServiceApplication.java index 167e6dc1470d23bda73fa20b4cc19b96b2c091bf..2104df15d67bac70158e33d6ca942f1e689d35c5 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/FdaMetadataServiceApplication.java +++ b/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/DbrepoIdentifierServiceApplication.java @@ -15,10 +15,10 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @EntityScan(basePackages = "at.tuwien.entities") @EnableElasticsearchRepositories(basePackages = {"at.tuwien.repository.elastic"}) @EnableJpaRepositories(basePackages = {"at.tuwien.repository.jpa"}) -public class FdaMetadataServiceApplication { +public class DbrepoIdentifierServiceApplication { public static void main(String[] args) { - SpringApplication.run(FdaMetadataServiceApplication.class, args); + SpringApplication.run(DbrepoIdentifierServiceApplication.class, args); } } diff --git a/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java b/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java index a17524bcb423f00a789d279e0ee41eeae1cf7bd2..b39fabcbbafb576974db31a870930aa7113e23c5 100644 --- a/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java +++ b/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java @@ -5,11 +5,14 @@ import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Contact; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.servers.Server; import org.springdoc.core.GroupedOpenApi; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import java.util.List; + @Configuration public class SwaggerConfig { @@ -30,8 +33,14 @@ public class SwaggerConfig { .name("Apache 2.0") .url("https://www.apache.org/licenses/LICENSE-2.0"))) .externalDocs(new ExternalDocumentation() - .description("Wiki Documentation") - .url("https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services/-/wikis")); + .description("Sourcecode Documentation") + .url("https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services")) + .servers(List.of(new Server() + .description("Generated server url") + .url("http://localhost:9096"), + new Server() + .description("Sandbox") + .url("https://dbrepo2.tuwien.ac.at"))); } @Bean diff --git a/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/endpoints/IdentifierEndpoint.java b/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/endpoints/IdentifierEndpoint.java index 1b2f41090f31577a1b56b2ae42dcee7433bfeb00..609b2bb0c0d76334ba3a99b43f23048c8643e031 100644 --- a/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/endpoints/IdentifierEndpoint.java +++ b/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/endpoints/IdentifierEndpoint.java @@ -1,5 +1,6 @@ package at.tuwien.endpoints; +import at.tuwien.api.error.ApiErrorDto; import at.tuwien.api.identifier.IdentifierCreateDto; import at.tuwien.api.identifier.IdentifierDto; import at.tuwien.api.identifier.IdentifierTypeDto; @@ -9,6 +10,10 @@ import at.tuwien.mapper.IdentifierMapper; import at.tuwien.service.IdentifierService; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; @@ -21,6 +26,7 @@ import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import javax.validation.constraints.NotNull; import java.security.Principal; +import java.util.LinkedList; import java.util.List; import java.util.stream.Collectors; @@ -43,12 +49,23 @@ public class IdentifierEndpoint { @Transactional(readOnly = true) @Timed(value = "identifier.list", description = "Time needed to list the identifiers") @Operation(summary = "Find identifiers") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "List identifiers", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = IdentifierDto[].class))}), + }) public ResponseEntity<List<IdentifierDto>> list(@RequestParam(required = false) Long dbid, @RequestParam(required = false) Long qid, - @RequestParam(required = false) IdentifierTypeDto type) - throws IdentifierNotFoundException { + @RequestParam(required = false) IdentifierTypeDto type) { log.debug("endpoint find identifiers, dbid={}, qid={}, type={}", dbid, qid, type); - final List<Identifier> identifiers = identifierService.findAll(dbid, qid); + List<Identifier> identifiers = new LinkedList<>(); + try { + identifiers = identifierService.findAll(dbid, qid); + } catch (IdentifierNotFoundException e) { + /* ignore */ + } final List<IdentifierDto> dto = identifiers.stream() .map(identifierMapper::identifierToIdentifierDto) .filter(i -> { @@ -59,7 +76,6 @@ public class IdentifierEndpoint { }) .collect(Collectors.toList()); log.info("Find identifiers resulted in {} identifiers", identifiers.size()); - log.trace("endpoint find identifiers, list={}", dto); return ResponseEntity.ok(dto); } @@ -68,6 +84,43 @@ public class IdentifierEndpoint { @Timed(value = "identifier.create", description = "Time needed to create an identifier") @PreAuthorize("hasAuthority('create-identifier')") @Operation(summary = "Create identifier", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "201", + description = "Created identifier", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = IdentifierDto.class))}), + @ApiResponse(responseCode = "400", + description = "Identifier form contains invalid request data", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Query, database or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Creating identifier not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "406", + description = "Creating identifier not allowed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "409", + description = "Identifier for this resource already exists", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "502", + description = "Query information could not be retrieved", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<IdentifierDto> create(@NotNull @Valid @RequestBody IdentifierCreateDto data, @NotNull @RequestHeader(name = "Authorization") String authorization, @NotNull Principal principal) @@ -91,12 +144,29 @@ public class IdentifierEndpoint { @Timed(value = "identifier.update", description = "Time needed to update an identifier") @PreAuthorize("hasAuthority('update-identifier')") @Operation(summary = "Update some identifier", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Updated identifier", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = IdentifierDto.class))}), + @ApiResponse(responseCode = "404", + description = "Identifier could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "406", + description = "Updating identifier not allowed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<IdentifierDto> update(@NotNull @PathVariable("id") Long id, @NotNull @Valid @RequestBody IdentifierDto data) - throws IdentifierPublishingNotAllowedException, IdentifierNotFoundException { + throws IdentifierPublishingNotAllowedException, IdentifierNotFoundException, IdentifierRequestException { log.debug("endpoint update identifier, id={}, data={}", id, data); final Identifier identifier = identifierService.update(id, data); - return ResponseEntity.status(HttpStatus.ACCEPTED) + return ResponseEntity.accepted() .body(identifierMapper.identifierToIdentifierDto(identifier)); } @@ -105,11 +175,21 @@ public class IdentifierEndpoint { @Timed(value = "identifier.delete", description = "Time needed to delete an identifier") @PreAuthorize("hasAuthority('delete-identifier')") @Operation(summary = "Delete some identifier", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Deleted identifier", + content = {@Content}), + @ApiResponse(responseCode = "404", + description = "Identifier could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<?> delete(@NotNull @PathVariable("id") Long id) - throws IdentifierNotFoundException { + throws IdentifierNotFoundException, NotAllowedException { log.debug("endpoint delete identifier, id={}", id); identifierService.delete(id); - return ResponseEntity.status(HttpStatus.ACCEPTED) + return ResponseEntity.accepted() .build(); } } diff --git a/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/endpoints/PersistenceEndpoint.java b/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/endpoints/PersistenceEndpoint.java index 93ff27454be942939fe499c873e894e948ed59ab..602ae69e091e35317d125a58a77da72deaa0b27f 100644 --- a/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/endpoints/PersistenceEndpoint.java +++ b/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/endpoints/PersistenceEndpoint.java @@ -1,5 +1,6 @@ package at.tuwien.endpoints; +import at.tuwien.api.error.ApiErrorDto; import at.tuwien.api.identifier.BibliographyTypeDto; import at.tuwien.api.identifier.IdentifierDto; import at.tuwien.config.EndpointConfig; @@ -12,6 +13,10 @@ import at.tuwien.mapper.IdentifierMapper; import at.tuwien.service.IdentifierService; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.InputStreamResource; @@ -48,6 +53,35 @@ public class PersistenceEndpoint { @Transactional(readOnly = true) @Timed(value = "pid.find", description = "Time needed to find a persisted identifier") @Operation(summary = "Find some identifier") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "Found identifier successfully", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = IdentifierDto.class)), + @Content(mediaType = "text/csv"), + @Content(mediaType = "text/xml"), + @Content(mediaType = "text/bibliography"), + @Content(mediaType = "text/bibliography; style=apa"), + @Content(mediaType = "text/bibliography; style=ieee"), + @Content(mediaType = "text/bibliography; style=bibtex"), + }), + @ApiResponse(responseCode = "400", + description = "Identifier could not be exported, the requested style is not known", + content = {@Content( + mediaType = "text/bibliography", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Identifier could not be exported from database as the resource was not found", + content = {@Content( + mediaType = "text/csv", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "502", + description = "Identifier could not exported from database as it is not reachable", + content = {@Content( + mediaType = "text/csv", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<?> find(@Valid @PathVariable("pid") Long pid, @RequestHeader(HttpHeaders.ACCEPT) String accept) throws IdentifierNotFoundException, QueryNotFoundException, RemoteUnavailableException, IdentifierRequestException { diff --git a/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java b/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java index b3de78f8f9f2467354c2f8dabf07ef1d65cf70aa..d69203d9051e5f5587f8fa8188f9dc0599a256db 100644 --- a/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java +++ b/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java @@ -2,6 +2,7 @@ package at.tuwien.handlers; import at.tuwien.api.error.ApiErrorDto; import at.tuwien.exception.*; +import io.swagger.v3.oas.annotations.Hidden; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -14,6 +15,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExcep @ControllerAdvice public class ApiExceptionHandler extends ResponseEntityExceptionHandler { + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(DatabaseNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(DatabaseNotFoundException e, WebRequest request) { @@ -25,6 +27,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.CONFLICT) @ExceptionHandler(IdentifierAlreadyExistsException.class) public ResponseEntity<ApiErrorDto> handle(IdentifierAlreadyExistsException e, WebRequest request) { @@ -36,6 +39,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.PRECONDITION_FAILED) @ExceptionHandler(IdentifierAlreadyPublishedException.class) public ResponseEntity<ApiErrorDto> handle(IdentifierAlreadyPublishedException e, WebRequest request) { @@ -47,6 +51,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(IdentifierNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(IdentifierNotFoundException e, WebRequest request) { @@ -58,6 +63,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_ACCEPTABLE) @ExceptionHandler(IdentifierPublishingNotAllowedException.class) public ResponseEntity<ApiErrorDto> handle(IdentifierPublishingNotAllowedException e, WebRequest request) { @@ -69,6 +75,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(IdentifierRequestException.class) public ResponseEntity<ApiErrorDto> handle(IdentifierRequestException e, WebRequest request) { @@ -80,6 +87,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(QueryNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(QueryNotFoundException e, WebRequest request) { @@ -91,17 +99,19 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.NO_CONTENT) + @Hidden + @ResponseStatus(HttpStatus.BAD_GATEWAY) @ExceptionHandler(RemoteUnavailableException.class) public ResponseEntity<ApiErrorDto> handle(RemoteUnavailableException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.NO_CONTENT) + .status(HttpStatus.BAD_GATEWAY) .message(e.getLocalizedMessage()) .code("error.identifier.remote") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(UserNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(UserNotFoundException e, WebRequest request) { diff --git a/dbrepo-identifier-service/rest-service/src/main/resources/application-doi.yml b/dbrepo-identifier-service/rest-service/src/main/resources/application-doi.yml new file mode 100644 index 0000000000000000000000000000000000000000..4a6687e0e807f7fbb2243078053bc4641a900368 --- /dev/null +++ b/dbrepo-identifier-service/rest-service/src/main/resources/application-doi.yml @@ -0,0 +1,6 @@ +fda: + datacite: + url: "${DATACITE_URL}" + prefix: "${DATACITE_PREFIX}" + username: "${DATACITE_USERNAME}" + password: "${DATACITE_PASSWORD}" \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/main/resources/application-local.yml b/dbrepo-identifier-service/rest-service/src/main/resources/application-local.yml index 3c25bac87e81573687bc5b89b201bed531fd743c..5e5f8130a7c8a0735c8236b06778fc167ef53b44 100644 --- a/dbrepo-identifier-service/rest-service/src/main/resources/application-local.yml +++ b/dbrepo-identifier-service/rest-service/src/main/resources/application-local.yml @@ -2,7 +2,7 @@ app.version: '@project.version@' spring: main.banner-mode: off datasource: - url: jdbc:mariadb://metadata-db:3306/fda + url: jdbc:mariadb://localhost:3306/fda driver-class-name: org.mariadb.jdbc.Driver username: root password: dbrepo @@ -22,6 +22,11 @@ spring: name: identifier-service cloud: loadbalancer.ribbon.enabled: false + rabbitmq: + host: localhost + username: fda + password: fda +management.endpoints.web.exposure.include: health,info,prometheus server: port: 9096 logging: diff --git a/dbrepo-identifier-service/rest-service/src/main/resources/application.yml b/dbrepo-identifier-service/rest-service/src/main/resources/application.yml index 4532a109dcc4fea02db6044987cea64e4af77add..9d2031bd7e895dd711f292066fbf1e4a44bac5ab 100644 --- a/dbrepo-identifier-service/rest-service/src/main/resources/application.yml +++ b/dbrepo-identifier-service/rest-service/src/main/resources/application.yml @@ -22,6 +22,10 @@ spring: name: identifier-service cloud: loadbalancer.ribbon.enabled: false + rabbitmq: + host: broker-service + username: "${BROKER_USERNAME}" + password: "${BROKER_PASSWORD}" management.endpoints.web.exposure.include: health,info,prometheus server: port: 9096 @@ -30,6 +34,7 @@ logging: level: root: warn at.tuwien.: "${LOG_LEVEL}" + at.tuwien.auth.UserPermissionEvaluator: trace org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver: debug eureka: instance: diff --git a/dbrepo-identifier-service/rest-service/src/main/resources/templates/cite_apa.txt b/dbrepo-identifier-service/rest-service/src/main/resources/templates/cite_apa.txt index 13cf643dae05b0e93e8c77d68a280b4d0f5260ad..8af282e645262dd7f8dfa8c17826e1d4c4fd43a6 100644 --- a/dbrepo-identifier-service/rest-service/src/main/resources/templates/cite_apa.txt +++ b/dbrepo-identifier-service/rest-service/src/main/resources/templates/cite_apa.txt @@ -1 +1 @@ -[# th:each="creator,idx: ${creators}"][# th:if="${idx.index} > 0 and ${idx.index} != ${idx.size} - 1 and ${idx.index} != 0"], [/][# th:if="${idx.index} == ${idx.size} - 1 and ${idx.size} != 1"] & [/][[${creator.firstname.substring(0,1)}]]., [[${creator.lastname}]][/][# th:if="${creators.size()} > 0"]. [/]([[${publicationYear}]]). [[${title}]]. [[${publisher}]]. [[${doi}]] \ No newline at end of file +[# th:each="creator,idx: ${creators}"][# th:if="${idx.index} > 0 and ${idx.index} != ${idx.size} - 1 and ${idx.index} != 0"], [/][# th:if="${idx.index} == ${idx.size} - 1 and ${idx.size} != 1"] & [/][[${creator.firstname.substring(0,1)}]]., [[${creator.lastname}]][/][# th:if="${creators.size()} > 0"]. [/]([[${publicationYear}]]). [[${title}]]. [[${publisher}]]. [[${identifierType} == 'doi' ? 'https://doi.org/' : '']][[${identifier}]] \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/main/resources/templates/cite_bibtex.txt b/dbrepo-identifier-service/rest-service/src/main/resources/templates/cite_bibtex.txt index 3ffe19fef7193059855155a43c65df28de45059b..ad48a2bd59fb10d5e25acc9323288c6c16e0df49 100644 --- a/dbrepo-identifier-service/rest-service/src/main/resources/templates/cite_bibtex.txt +++ b/dbrepo-identifier-service/rest-service/src/main/resources/templates/cite_bibtex.txt @@ -1,7 +1,7 @@ @misc{dbrepo[[${publicationYear}]], author = {[# th:each="creator,idx: ${creators}"][# th:if="${idx.index} > 0"] and [/][[${creator.lastname}]], [[${creator.firstname}]][/]}, title = {[[${title}]]}, - howpublished = {\url{[[${doi}]]}}, + [[${identifierType}]] = {[[${identifierType} == 'url' ? '\url{' : '']][[${identifier}]][[${identifierType} == 'url' ? '}' : '']]}, month = {[[${publicationMonth}]]}, year = {[[${publicationYear}]]} } \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/main/resources/templates/cite_ieee.txt b/dbrepo-identifier-service/rest-service/src/main/resources/templates/cite_ieee.txt index 67f9e13035097bb4587d2f3ff1a5199ff4d65996..602b73deed44278af106e3a946a1b1aa55996c36 100644 --- a/dbrepo-identifier-service/rest-service/src/main/resources/templates/cite_ieee.txt +++ b/dbrepo-identifier-service/rest-service/src/main/resources/templates/cite_ieee.txt @@ -1 +1 @@ -[1] [# th:each="creator,idx: ${creators}"][# th:if="${idx.index} > 0"] and [/][[${creator.firstname.substring(0,1)}]]. [[${creator.lastname}]][/][# th:if="${creators.size()} > 0"], [/]“[[${title}]]“, [[${publisher}]], [[${publicationYear}]], doi: [[${doi}]]. \ No newline at end of file +[1] [# th:each="creator,idx: ${creators}"][# th:if="${idx.index} > 0"] and [/][[${creator.firstname.substring(0,1)}]]. [[${creator.lastname}]][/][# th:if="${creators.size()} > 0"], [/]“[[${title}]]“, [[${publisher}]], [[${publicationYear}]], [[${identifierType} == 'url' ? 'Available: ' : '']][[${identifier}]]. \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/main/resources/templates/doi.xml b/dbrepo-identifier-service/rest-service/src/main/resources/templates/doi.xml index 48a23436cb5faa1d71d4ec6e2ceb8b9f05a6948d..3d52208f994c8d145a2d2bd734e10f6b0089de47 100644 --- a/dbrepo-identifier-service/rest-service/src/main/resources/templates/doi.xml +++ b/dbrepo-identifier-service/rest-service/src/main/resources/templates/doi.xml @@ -1,11 +1,16 @@ <?xml version="1.0" encoding="UTF-8"?> <resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://datacite.org/schema/kernel-4" xsi:schemaLocation="http://datacite.org/schema/kernel-4 https://schema.datacite.org/meta/kernel-4.4/metadata.xsd"> - <identifier identifierType="PID">[[${doi}]]</identifier><creators th:if="${not #lists.isEmpty(creators)}"> + <identifier th:attr="identifierType=${identifierType}">[[${identifier}]]</identifier> + <creators th:if="${not #lists.isEmpty(creators)}"> <creator th:each="creator: ${creators}"> <creatorName nameType="Personal">[[${creator.lastname}]], [[${creator.firstname}]]</creatorName> <givenName>[[${creator.firstname}]]</givenName> - <familyName>[[${creator.lastname}]]</familyName><affiliation th:if="${creator.affiliation != null}">[[${creator.affiliation}]]</affiliation><nameIdentifier th:if="${creator.orcid != null}" schemeURI="https://orcid.org" nameIdentifierScheme="ORCID">[[${creator.orcid}]]</nameIdentifier> + <familyName>[[${creator.lastname}]]</familyName> + <nameIdentifier th:if="${creator.orcid != null}" schemeURI="https://orcid.org" nameIdentifierScheme="ORCID"> + [[${creator.orcid}]] + </nameIdentifier> + <affiliation th:if="${creator.affiliation != null}">[[${creator.affiliation}]]</affiliation> </creator> </creators> <titles> @@ -17,9 +22,12 @@ <date dateType="Issued">[[${created}]]</date> <date dateType="Available">[[${created}]]</date> </dates> - <resourceType resourceTypeGeneral="Dataset">Dataset</resourceType><relatedIdentifiers th:if="${not #lists.isEmpty(relatedIdentifiers)}"> + <resourceType resourceTypeGeneral="Dataset">Dataset</resourceType> + <relatedIdentifiers th:if="${not #lists.isEmpty(relatedIdentifiers)}"> <relatedIdentifier th:each="relatedIdentifier: ${relatedIdentifiers}" - th:attr="relatedIdentifierType=${relatedIdentifier.type},relationType=${relatedIdentifier.relation}">[[${relatedIdentifier.value}]]</relatedIdentifier> + th:attr="relatedIdentifierType=${relatedIdentifier.type},relationType=${relatedIdentifier.relation}"> + [[${relatedIdentifier.value}]] + </relatedIdentifier> </relatedIdentifiers> <descriptions th:if="${description != null}"> <description descriptionType="Abstract">[[${description}]]</description> diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java index 29893e0027e264c0e0129c1516c613b09bfe6529..01f84e12b909533314c3cc741739e02801e78ee5 100644 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java @@ -1,863 +1,9 @@ package at.tuwien; -import at.tuwien.api.database.query.QueryDto; -import at.tuwien.api.database.query.QueryResultDto; -import at.tuwien.api.identifier.*; -import at.tuwien.api.user.GrantedAuthorityDto; -import at.tuwien.api.user.UserDetailsDto; -import at.tuwien.api.user.UserDto; -import at.tuwien.entities.container.Container; -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.entities.database.table.Table; -import at.tuwien.entities.identifier.*; -import at.tuwien.entities.user.User; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; +import at.tuwien.test.BaseTest; import org.springframework.test.context.TestPropertySource; -import java.security.Principal; -import java.time.Instant; -import java.time.temporal.ChronoUnit; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - @TestPropertySource(locations = "classpath:application.properties") -public abstract class BaseUnitTest { - - public final static String JWT_1 = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJtd2Vpc2UiLCJybmQiOjk2NjIyNzAwMCwiZXhwIjoxNjczODg2MDk5LCJpYXQiOjE2NzM3OTk2OTl9.y1jqokCfZE7c_Ztt_nLQlf73jCYXPH5TZpCvo3RwS0C5azyrqLh03bphl6R8A24g6Kv_3qjzvnubNIwmO7y7pA"; - - public final static String USER_1_ID = "090dc12a-a46a-4515-b1f0-cff697d5f985"; - public final static String USER_1_USERNAME = "junit"; - public final static String USER_1_PASSWORD = "junit"; - public final static String USER_1_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - public final static String USER_1_EMAIL = "junit@example.com"; - public final static Boolean USER_1_EMAIL_VERIFIED = true; - public final static Boolean USER_1_THEME_DARK = false; - public final static Instant USER_1_CREATED = Instant.now() - .minus(1, ChronoUnit.DAYS); - public final static Instant USER_1_LAST_MODIFIED = USER_1_CREATED; - - public final static GrantedAuthorityDto AUTHORITY_RESEARCHER_DTO = GrantedAuthorityDto.builder() - .authority("ROLE_RESEARCHER") - .build(); - - public final static GrantedAuthorityDto AUTHORITY_DEVELOPER_DTO = GrantedAuthorityDto.builder() - .authority("ROLE_DEVELOPER") - .build(); - - public final static GrantedAuthorityDto AUTHORITY_DATA_STEWARD_DTO = GrantedAuthorityDto.builder() - .authority("ROLE_DATA_STEWARD") - .build(); - - public final static User USER_1 = User.builder() - .id(USER_1_ID) - .username(USER_1_USERNAME) - .databasePassword(USER_1_DATABASE_PASSWORD) - .email(USER_1_EMAIL) - .emailVerified(USER_1_EMAIL_VERIFIED) - .build(); - - public final static UserDto USER_1_DTO = UserDto.builder() - .id(USER_1_ID) - .username(USER_1_USERNAME) - .email(USER_1_EMAIL) - .emailVerified(USER_1_EMAIL_VERIFIED) - .build(); - - public final static UserDetails USER_1_DETAILS = UserDetailsDto.builder() - .username(USER_1_USERNAME) - .email(USER_1_EMAIL) - .password(USER_1_PASSWORD) - .authorities(List.of(new SimpleGrantedAuthority("ROLE_RESEARCHER"))) - .build(); - - public final static Principal USER_1_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_1_DETAILS, - USER_1_PASSWORD, USER_1_DETAILS.getAuthorities()); - - public final static String USER_2_ID = "0153f998-bd4c-4154-993e-75c355499044"; - public final static String USER_2_USERNAME = "junit2"; - public final static String USER_2_PASSWORD = "junit2"; - public final static String USER_2_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - public final static String USER_2_EMAIL = "junit2@example.com"; - public final static Boolean USER_2_EMAIL_VERIFIED = true; - public final static Boolean USER_2_THEME_DARK = false; - public final static Instant USER_2_CREATED = Instant.now() - .minus(1, ChronoUnit.DAYS); - public final static Instant USER_2_LAST_MODIFIED = USER_2_CREATED; - - public final static User USER_2 = User.builder() - .id(USER_2_ID) - .username(USER_2_USERNAME) - .databasePassword(USER_2_DATABASE_PASSWORD) - .email(USER_2_EMAIL) - .emailVerified(USER_2_EMAIL_VERIFIED) - .build(); - - public final static UserDto USER_2_DTO = UserDto.builder() - .id(USER_2_ID) - .username(USER_2_USERNAME) - .email(USER_2_EMAIL) - .emailVerified(USER_2_EMAIL_VERIFIED) - .build(); - - public final static UserDetails USER_2_DETAILS = UserDetailsDto.builder() - .username(USER_2_USERNAME) - .email(USER_2_EMAIL) - .password(USER_2_PASSWORD) - .authorities(List.of(new SimpleGrantedAuthority("ROLE_RESEARCHER"))) - .build(); - - public final static Principal USER_2_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_2_DETAILS, - USER_2_PASSWORD, USER_2_DETAILS.getAuthorities()); - - public final static String USER_3_ID = "fea123c7-1851-4e01-969a-53407fa6a451"; - public final static String USER_3_USERNAME = "steward"; - public final static String USER_3_EMAIL = "steward@gmail.com"; - public final static Boolean USER_3_EMAIL_VERIFIED = false; - public final static Boolean USER_3_THEME_DARK = false; - public final static String USER_3_PASSWORD = "p455w0rdh45"; - public final static String USER_3_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - public final static Instant USER_3_CREATED = Instant.now() - .minus(1, ChronoUnit.DAYS); - public final static Instant USER_3_LAST_MODIFIED = USER_3_CREATED; - public final static GrantedAuthority USER_3_AUTHORITY = new SimpleGrantedAuthority("ROLE_DATA_STEWARD"); - - public final static User USER_3 = User.builder() - .username(USER_3_USERNAME) - .databasePassword(USER_3_DATABASE_PASSWORD) - .email(USER_3_EMAIL) - .emailVerified(USER_3_EMAIL_VERIFIED) - .build(); - - public final static UserDetails USER_3_DETAILS = UserDetailsDto.builder() - .username(USER_3_USERNAME) - .email(USER_3_EMAIL) - .password(USER_3_PASSWORD) - .authorities(List.of(new SimpleGrantedAuthority("ROLE_DATA_STEWARD"))) - .build(); - - public final static Principal USER_3_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_3_DETAILS, - USER_3_PASSWORD, USER_3_DETAILS.getAuthorities()); - - public final static Long IMAGE_1_ID = 1L; - public final static String IMAGE_1_REPOSITORY = "postgres"; - public final static String IMAGE_1_TAG = "13-alpine"; - public final static String IMAGE_1_HASH = "83b40f2726e5"; - public final static Integer IMAGE_1_PORT = 5432; - public final static String IMAGE_1_DIALECT = "org.mariadb.jdbc.Driver"; - public final static String IMAGE_1_DRIVER = "org.postgresql.Driver"; - public final static String IMAGE_1_JDBC = "postgresql"; - public final static Long IMAGE_1_SIZE = 12000L; - public final static String IMAGE_1_LOGO = "AAAA"; - public final static Instant IMAGE_1_BUILT = Instant.ofEpochSecond(1441588352); - - public final static List<ContainerImageEnvironmentItem> IMAGE_1_ENV = List.of( - ContainerImageEnvironmentItem.builder() - .iid(IMAGE_1_ID) - .key("POSTGRES_USER") - .value("postgres") - .type(ContainerImageEnvironmentItemType.USERNAME) - .build(), - ContainerImageEnvironmentItem.builder() - .iid(IMAGE_1_ID) - .key("POSTGRES_PASSWORD") - .value("postgres") - .type(ContainerImageEnvironmentItemType.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) - .jdbcMethod(IMAGE_1_JDBC) - .dialect(IMAGE_1_DIALECT) - .driverClass(IMAGE_1_DRIVER) - .containers(List.of()) - .compiled(IMAGE_1_BUILT) - .size(IMAGE_1_SIZE) - .environment(IMAGE_1_ENV) - .defaultPort(IMAGE_1_PORT) - .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 = "fda-userdb-u01"; - public final static String CONTAINER_1_INTERNALNAME = "fda-userdb-u01"; - public final static String CONTAINER_1_DATABASE = "univie"; - public final static String CONTAINER_1_IP = "172.28.0.5"; - public final static Instant CONTAINER_1_CREATED = Instant.ofEpochSecond(1641588352); - - public final static Container CONTAINER_1 = Container.builder() - .id(CONTAINER_1_ID) - .name(CONTAINER_1_NAME) - .internalName(CONTAINER_1_INTERNALNAME) - .imageId(IMAGE_1_ID) - .image(CONTAINER_1_IMAGE) - .hash(CONTAINER_1_HASH) - .build(); - - 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 = "fda-userdb-u02"; - public final static String CONTAINER_2_INTERNALNAME = "fda-userdb-u02"; - public final static String CONTAINER_2_DATABASE = "univie"; - public final static String CONTAINER_2_IP = "172.28.0.6"; - public final static Instant CONTAINER_2_CREATED = Instant.ofEpochSecond(1641588352); - - public final static Container CONTAINER_2 = Container.builder() - .id(CONTAINER_2_ID) - .name(CONTAINER_2_NAME) - .internalName(CONTAINER_2_INTERNALNAME) - .imageId(IMAGE_1_ID) - .image(CONTAINER_2_IMAGE) - .hash(CONTAINER_2_HASH) - .build(); - - public final static Long CONTAINER_3_ID = 3L; - - public final static Long CONTAINER_4_ID = 4L; - - public final static Long DATABASE_1_ID = 1L; - public final static String DATABASE_1_NAME = "Test Database"; - public final static String DATABASE_1_INTERNAL_NAME = "test_database"; - public final static String DATABASE_1_EXCHANGE = "fda." + DATABASE_1_INTERNAL_NAME; - public final static Boolean DATABASE_1_PUBLIC = true; - public final static User DATABASE_1_CREATOR = USER_1; - - public final static Long DATABASE_2_ID = 2L; - public final static String DATABASE_2_NAME = "Test Database 2"; - public final static String DATABASE_2_INTERNAL_NAME = "test_database_2"; - public final static String DATABASE_2_EXCHANGE = "fda." + DATABASE_2_INTERNAL_NAME; - public final static Boolean DATABASE_2_PUBLIC = false; - public final static User DATABASE_2_CREATOR = USER_2; - - public final static Long DATABASE_3_ID = 3L; - - public final static Long DATABASE_4_ID = 4L; - - public final static Long TABLE_1_ID = 1L; - public final static String TABLE_1_NAME = "Rainfall"; - public final static String TABLE_1_INTERNAL_NAME = "rainfall"; - public final static String TABLE_1_QUEUE_NAME = "dbrepo/" + CONTAINER_1_ID + "/" + DATABASE_1_ID + "/" + TABLE_1_ID; - public final static String TABLE_1_ROUTING_KEY = TABLE_1_QUEUE_NAME + "/1"; - - public final static Database DATABASE_1 = Database.builder() - .id(DATABASE_1_ID) - .name(DATABASE_1_NAME) - .internalName(DATABASE_1_INTERNAL_NAME) - .exchangeName(DATABASE_1_EXCHANGE) - .tables(List.of()) - .isPublic(DATABASE_1_PUBLIC) - .creator(DATABASE_1_CREATOR) - .build(); - - public final static Database DATABASE_2 = Database.builder() - .id(DATABASE_2_ID) - .name(DATABASE_2_NAME) - .internalName(DATABASE_2_INTERNAL_NAME) - .exchangeName(DATABASE_2_EXCHANGE) - .tables(List.of()) - .isPublic(DATABASE_2_PUBLIC) - .creator(DATABASE_2_CREATOR) - .build(); - - public final static Table TABLE_1 = Table.builder() - .id(TABLE_1_ID) - .name(TABLE_1_NAME) - .internalName(TABLE_1_INTERNAL_NAME) - .queueName(TABLE_1_QUEUE_NAME) - .routingKey(TABLE_1_ROUTING_KEY) - .tdbid(DATABASE_1_ID) - .build(); - - public final static Long CREATOR_1_ID = 1L; - public final static Long CREATOR_1_QUERY_ID = 1L; - public final static String CREATOR_1_ORCID = "00000-00000-00000"; - public final static String CREATOR_1_AFFIL = "TU Graz"; - public final static String CREATOR_1_FIRSTNAME = "Max"; - public final static String CREATOR_1_LASTNAME = "Mustermann"; - public final static Instant CREATOR_1_CREATED = Instant.ofEpochSecond(1641588352); - public final static Instant CREATOR_1_MODIFIED = Instant.ofEpochSecond(1541588352); - - public final static Long CREATOR_2_ID = 2L; - public final static Long CREATOR_2_QUERY_ID = 1L; - public final static String CREATOR_2_ORCID = "00000-00000-00000"; - public final static String CREATOR_2_AFFIL = "TU Wien"; - public final static String CREATOR_2_FIRSTNAME = "Martina"; - public final static String CREATOR_2_LASTNAME = "Mustermann"; - public final static Instant CREATOR_2_CREATED = Instant.ofEpochSecond(1641588352); - public final static Instant CREATOR_2_MODIFIED = Instant.ofEpochSecond(1541588352); - - public final static Long CREATOR_3_ID = 3L; - public final static Long CREATOR_3_QUERY_ID = 1L; - public final static String CREATOR_3_ORCID = "00000-00000-00000"; - public final static String CREATOR_3_AFFIL = "TU Graz"; - public final static String CREATOR_3_FIRSTNAME = "Max"; - public final static String CREATOR_3_LASTNAME = "Mustermann"; - public final static Instant CREATOR_3_CREATED = Instant.ofEpochSecond(1641588352); - public final static Instant CREATOR_3_MODIFIED = Instant.ofEpochSecond(1541588352); - - public final static Long CREATOR_4_ID = 4L; - public final static Long CREATOR_4_QUERY_ID = 1L; - public final static String CREATOR_4_ORCID = "00000-00000-00000"; - public final static String CREATOR_4_AFFIL = "TU Wien"; - public final static String CREATOR_4_FIRSTNAME = "Martina"; - public final static String CREATOR_4_LASTNAME = "Mustermann"; - public final static Instant CREATOR_4_CREATED = Instant.ofEpochSecond(1641588352); - public final static Instant CREATOR_4_MODIFIED = Instant.ofEpochSecond(1541588352); - - public final static Long QUERY_1_ID = 1L; - public final static Long QUERY_1_CONTAINER_ID = CONTAINER_1_ID; - public final static Long QUERY_1_DATABASE_ID = DATABASE_1_ID; - public final static String QUERY_1_STATEMENT = "SELECT * FROM `weather`;"; - public final static String QUERY_1_HASH = "ff3f7cbe1b96d296957f6e39e55b8b1b577fa3d205d4795af99594cfd20cb80d"; - public final static String QUERY_1_RESULT_HASH = "ff3f7cbe1b96d296957f6e39e55b8b1b577fa3d205d4795af99594cfd20cb80d"; - public final static Long QUERY_1_RESULT_NUMBER = 9L; - public final static Instant QUERY_1_CREATED = Instant.ofEpochSecond(1641588352); - public final static Instant QUERY_1_EXECUTED = Instant.ofEpochSecond(1641588352); - public final static Instant QUERY_1_LAST_MODIFIED = Instant.ofEpochSecond(1541588352); - - public final static QueryDto QUERY_1_DTO = QueryDto.builder() - .id(QUERY_1_ID) - .cid(QUERY_1_CONTAINER_ID) - .dbid(QUERY_1_DATABASE_ID) - .query(QUERY_1_STATEMENT) - .queryNormalized(QUERY_1_STATEMENT) - .resultNumber(QUERY_1_RESULT_NUMBER) - .resultHash(QUERY_1_RESULT_HASH) - .lastModified(QUERY_1_LAST_MODIFIED) - .created(QUERY_1_CREATED) - .queryHash(QUERY_1_HASH) - .execution(QUERY_1_EXECUTED) - .build(); - - public final static Long QUERY_2_ID = 2L; - public final static Long QUERY_2_CONTAINER_ID = CONTAINER_2_ID; - public final static Long QUERY_2_DATABASE_ID = DATABASE_2_ID; - public final static String QUERY_2_STATEMENT = "SELECT * FROM `weather`;"; - public final static String QUERY_2_HASH = "ff3f7cbe1b96d296957f6e39e55b8b1b577fa3d205d4795af99594cfd20cb80d"; - public final static String QUERY_2_RESULT_HASH = "ff3f7cbe1b96d296957f6e39e55b8b1b577fa3d205d4795af99594cfd20cb80d"; - public final static Long QUERY_2_RESULT_NUMBER = 5L; - public final static Instant QUERY_2_CREATED = Instant.ofEpochSecond(1641588352); - public final static Instant QUERY_2_EXECUTED = Instant.ofEpochSecond(1641588352); - public final static Instant QUERY_2_LAST_MODIFIED = Instant.ofEpochSecond(1541588352); - - public final static QueryDto QUERY_2_DTO = QueryDto.builder() - .id(QUERY_2_ID) - .cid(QUERY_2_CONTAINER_ID) - .dbid(QUERY_2_DATABASE_ID) - .query(QUERY_2_STATEMENT) - .queryNormalized(QUERY_2_STATEMENT) - .resultNumber(QUERY_2_RESULT_NUMBER) - .resultHash(QUERY_2_RESULT_HASH) - .lastModified(QUERY_2_LAST_MODIFIED) - .created(QUERY_2_CREATED) - .queryHash(QUERY_2_HASH) - .execution(QUERY_2_EXECUTED) - .build(); - - public final static Long QUERY_3_ID = 3L; - - public final static Long IDENTIFIER_1_ID = 1L; - public final static Long IDENTIFIER_1_QUERY_ID = QUERY_1_ID; - public final static Long IDENTIFIER_1_CONTAINER_ID = CONTAINER_1_ID; - public final static Long IDENTIFIER_1_DATABASE_ID = DATABASE_1_ID; - public final static String IDENTIFIER_1_DESCRIPTION = "Selecting all from the weather Austrian table"; - public final static String IDENTIFIER_1_DESCRIPTION_MODIFY = "Selecting some from the weather Austrian table"; - public final static String IDENTIFIER_1_TITLE = "Austrian weather data"; - public final static String IDENTIFIER_1_TITLE_MODIFY = "Austrian weather some data"; - public final static String IDENTIFIER_1_DOI = "10.1000/182"; - public final static VisibilityType IDENTIFIER_1_VISIBILITY = VisibilityType.EVERYONE; - public final static VisibilityTypeDto IDENTIFIER_1_VISIBILITY_DTO = VisibilityTypeDto.EVERYONE; - public final static Instant IDENTIFIER_1_CREATED = Instant.ofEpochSecond(1641588352); - public final static Instant IDENTIFIER_1_MODIFIED = Instant.ofEpochSecond(1541588352); - public final static Instant IDENTIFIER_1_EXECUTION = Instant.ofEpochSecond(1541588352); - public final static Integer IDENTIFIER_1_PUBLICATION_MONTH = 5; - public final static Integer IDENTIFIER_1_PUBLICATION_YEAR = 2022; - public final static Integer IDENTIFIER_1_PUBLICATION_DAY = null; - public final static String IDENTIFIER_1_QUERY_HASH = "abc"; - public final static String IDENTIFIER_1_RESULT_HASH = "def"; - public final static String IDENTIFIER_1_QUERY = "SELECT `id` FROM `foobar`"; - public final static String IDENTIFIER_1_NORMALIZED = "SELECT `id` FROM `foobar`"; - public final static Long IDENTIFIER_1_RESULT_NUMBER = 2L; - public final static String IDENTIFIER_1_PUBLISHER = "Austrian Government"; - public final static IdentifierType IDENTIFIER_1_TYPE = IdentifierType.SUBSET; - public final static IdentifierTypeDto IDENTIFIER_1_TYPE_DTO = IdentifierTypeDto.DATABASE; - - public final static Creator IDENTIFIER_1_CREATOR_1 = Creator.builder() - .id(CREATOR_1_ID) - .pid(IDENTIFIER_1_ID) - .firstname(CREATOR_1_FIRSTNAME) - .lastname(CREATOR_1_LASTNAME) - .affiliation(CREATOR_1_AFFIL) - .build(); - - public final static CreatorDto IDENTIFIER_1_CREATOR_1_DTO = CreatorDto.builder() - .id(CREATOR_1_ID) - .firstname(CREATOR_1_FIRSTNAME) - .lastname(CREATOR_1_LASTNAME) - .affiliation(CREATOR_1_AFFIL) - .build(); - - public final static Creator IDENTIFIER_1_CREATOR_2 = Creator.builder() - .id(CREATOR_2_ID) - .pid(IDENTIFIER_1_ID) - .firstname(CREATOR_2_FIRSTNAME) - .lastname(CREATOR_2_LASTNAME) - .affiliation(CREATOR_2_AFFIL) - .build(); - - public final static CreatorDto IDENTIFIER_1_CREATOR_2_DTO = CreatorDto.builder() - .id(CREATOR_2_ID) - .firstname(CREATOR_2_FIRSTNAME) - .lastname(CREATOR_2_LASTNAME) - .affiliation(CREATOR_2_AFFIL) - .build(); - - public final static Identifier IDENTIFIER_1 = Identifier.builder() - .id(IDENTIFIER_1_ID) - .containerId(IDENTIFIER_1_CONTAINER_ID) - .databaseId(IDENTIFIER_1_DATABASE_ID) - .queryId(IDENTIFIER_1_QUERY_ID) - .description(IDENTIFIER_1_DESCRIPTION) - .title(IDENTIFIER_1_TITLE) - .doi(IDENTIFIER_1_DOI) - .visibility(IDENTIFIER_1_VISIBILITY) - .created(IDENTIFIER_1_CREATED) - .lastModified(IDENTIFIER_1_MODIFIED) - .execution(IDENTIFIER_1_EXECUTION) - .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) - .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) - .queryHash(IDENTIFIER_1_QUERY_HASH) - .resultHash(IDENTIFIER_1_RESULT_HASH) - .query(IDENTIFIER_1_QUERY) - .queryNormalized(IDENTIFIER_1_NORMALIZED) - .resultNumber(IDENTIFIER_1_RESULT_NUMBER) - .publisher(IDENTIFIER_1_PUBLISHER) - .type(IDENTIFIER_1_TYPE) - .creators(List.of(IDENTIFIER_1_CREATOR_1, IDENTIFIER_1_CREATOR_2)) - .build(); - - public final static IdentifierDto IDENTIFIER_1_DTO = IdentifierDto.builder() - .id(IDENTIFIER_1_ID) - .containerId(IDENTIFIER_1_CONTAINER_ID) - .databaseId(IDENTIFIER_1_DATABASE_ID) - .queryId(IDENTIFIER_1_QUERY_ID) - .description(IDENTIFIER_1_DESCRIPTION) - .title(IDENTIFIER_1_TITLE) - .doi(IDENTIFIER_1_DOI) - .visibility(IDENTIFIER_1_VISIBILITY_DTO) - .created(IDENTIFIER_1_CREATED) - .lastModified(IDENTIFIER_1_MODIFIED) - .execution(IDENTIFIER_1_EXECUTION) - .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) - .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) - .queryHash(IDENTIFIER_1_QUERY_HASH) - .resultHash(IDENTIFIER_1_RESULT_HASH) - .query(IDENTIFIER_1_QUERY) - .queryNormalized(IDENTIFIER_1_NORMALIZED) - .resultNumber(IDENTIFIER_1_RESULT_NUMBER) - .publisher(IDENTIFIER_1_PUBLISHER) - .type(IDENTIFIER_1_TYPE_DTO) - .creator(USER_1_DTO) - .creators(List.of(IDENTIFIER_1_CREATOR_1_DTO, IDENTIFIER_1_CREATOR_2_DTO)) - .build(); - - public final static Long IDENTIFIER_2_ID = 2L; - public final static Long IDENTIFIER_2_QUERY_ID = QUERY_2_ID; - public final static Long IDENTIFIER_2_CONTAINER_ID = CONTAINER_2_ID; - public final static Long IDENTIFIER_2_DATABASE_ID = DATABASE_2_ID; - public final static String IDENTIFIER_2_DESCRIPTION = "Selecting all from the weather Austria table"; - public final static String IDENTIFIER_2_TITLE = "Australian weather data"; - public final static String IDENTIFIER_2_DOI = "10.1000/183"; - public final static VisibilityType IDENTIFIER_2_VISIBILITY = VisibilityType.SELF; - public final static VisibilityTypeDto IDENTIFIER_2_VISIBILITY_DTO = VisibilityTypeDto.SELF; - public final static Instant IDENTIFIER_2_CREATED = Instant.ofEpochSecond(1641588352); - public final static Instant IDENTIFIER_2_MODIFIED = Instant.ofEpochSecond(1541588352); - public final static Instant IDENTIFIER_2_EXECUTION = Instant.ofEpochSecond(1541588352); - public final static Integer IDENTIFIER_2_PUBLICATION_DAY = 14; - public final static Integer IDENTIFIER_2_PUBLICATION_MONTH = 7; - public final static Integer IDENTIFIER_2_PUBLICATION_YEAR = 2022; - public final static String IDENTIFIER_2_QUERY_HASH = "abc"; - public final static String IDENTIFIER_2_RESULT_HASH = "def"; - public final static String IDENTIFIER_2_QUERY = "SELECT `id` FROM `foobar`"; - public final static String IDENTIFIER_2_NORMALIZED = "SELECT `id` FROM `foobar`"; - public final static Long IDENTIFIER_2_RESULT_NUMBER = 2L; - public final static String IDENTIFIER_2_PUBLISHER = "Australian Government"; - public final static IdentifierType IDENTIFIER_2_TYPE = IdentifierType.SUBSET; - public final static IdentifierTypeDto IDENTIFIER_2_TYPE_DTO = IdentifierTypeDto.SUBSET; - - public final static Creator IDENTIFIER_2_CREATOR_1 = Creator.builder() - .id(CREATOR_1_ID) - .pid(IDENTIFIER_2_ID) - .firstname(CREATOR_1_FIRSTNAME) - .lastname(CREATOR_1_LASTNAME) - .affiliation(CREATOR_1_AFFIL) - .build(); - - public final static CreatorDto IDENTIFIER_2_CREATOR_1_DTO = CreatorDto.builder() - .id(CREATOR_1_ID) - .firstname(CREATOR_1_FIRSTNAME) - .lastname(CREATOR_1_LASTNAME) - .affiliation(CREATOR_1_AFFIL) - .build(); - - public final static Creator IDENTIFIER_2_CREATOR_2 = Creator.builder() - .id(CREATOR_2_ID) - .pid(IDENTIFIER_2_ID) - .firstname(CREATOR_2_FIRSTNAME) - .lastname(CREATOR_2_LASTNAME) - .affiliation(CREATOR_2_AFFIL) - .build(); - - public final static CreatorDto IDENTIFIER_2_CREATOR_2_DTO = CreatorDto.builder() - .id(CREATOR_2_ID) - .firstname(CREATOR_2_FIRSTNAME) - .lastname(CREATOR_2_LASTNAME) - .affiliation(CREATOR_2_AFFIL) - .build(); - - public final static Identifier IDENTIFIER_2 = Identifier.builder() - .id(IDENTIFIER_2_ID) - .containerId(IDENTIFIER_2_CONTAINER_ID) - .databaseId(IDENTIFIER_2_DATABASE_ID) - .queryId(IDENTIFIER_2_QUERY_ID) - .description(IDENTIFIER_2_DESCRIPTION) - .title(IDENTIFIER_2_TITLE) - .doi(IDENTIFIER_2_DOI) - .visibility(IDENTIFIER_2_VISIBILITY) - .created(IDENTIFIER_2_CREATED) - .lastModified(IDENTIFIER_2_MODIFIED) - .execution(IDENTIFIER_2_EXECUTION) - .publicationDay(IDENTIFIER_2_PUBLICATION_DAY) - .publicationMonth(IDENTIFIER_2_PUBLICATION_MONTH) - .publicationYear(IDENTIFIER_2_PUBLICATION_YEAR) - .queryHash(IDENTIFIER_2_QUERY_HASH) - .resultHash(IDENTIFIER_2_RESULT_HASH) - .query(IDENTIFIER_2_QUERY) - .queryNormalized(IDENTIFIER_2_NORMALIZED) - .resultNumber(IDENTIFIER_2_RESULT_NUMBER) - .publisher(IDENTIFIER_2_PUBLISHER) - .type(IDENTIFIER_2_TYPE) - .creator(USER_2) - .creators(List.of(IDENTIFIER_2_CREATOR_1, IDENTIFIER_2_CREATOR_2)) - .build(); - - public final static IdentifierDto IDENTIFIER_2_DTO = IdentifierDto.builder() - .id(IDENTIFIER_2_ID) - .containerId(IDENTIFIER_2_CONTAINER_ID) - .databaseId(IDENTIFIER_2_DATABASE_ID) - .queryId(IDENTIFIER_2_QUERY_ID) - .description(IDENTIFIER_2_DESCRIPTION) - .title(IDENTIFIER_2_TITLE) - .doi(IDENTIFIER_2_DOI) - .visibility(IDENTIFIER_2_VISIBILITY_DTO) - .created(IDENTIFIER_2_CREATED) - .lastModified(IDENTIFIER_2_MODIFIED) - .execution(IDENTIFIER_2_EXECUTION) - .publicationDay(IDENTIFIER_2_PUBLICATION_DAY) - .publicationMonth(IDENTIFIER_2_PUBLICATION_MONTH) - .publicationYear(IDENTIFIER_2_PUBLICATION_YEAR) - .queryHash(IDENTIFIER_2_QUERY_HASH) - .resultHash(IDENTIFIER_2_RESULT_HASH) - .query(IDENTIFIER_2_QUERY) - .queryNormalized(IDENTIFIER_2_NORMALIZED) - .resultNumber(IDENTIFIER_2_RESULT_NUMBER) - .publisher(IDENTIFIER_2_PUBLISHER) - .type(IDENTIFIER_2_TYPE_DTO) - .creator(USER_2_DTO) - .creators(List.of(IDENTIFIER_2_CREATOR_1_DTO, IDENTIFIER_2_CREATOR_2_DTO)) - .build(); - - public final static Creator CREATOR_1 = Creator.builder() - .id(CREATOR_1_ID) - .pid(IDENTIFIER_1_ID) - .orcid(CREATOR_1_ORCID) - .firstname(CREATOR_1_FIRSTNAME) - .lastname(CREATOR_1_LASTNAME) - .created(CREATOR_1_CREATED) - .affiliation(CREATOR_1_AFFIL) - .lastModified(CREATOR_1_MODIFIED) - .build(); - - public final static Creator CREATOR_2 = Creator.builder() - .id(CREATOR_2_ID) - .pid(IDENTIFIER_1_ID) - .orcid(CREATOR_2_ORCID) - .firstname(CREATOR_2_FIRSTNAME) - .lastname(CREATOR_2_LASTNAME) - .created(CREATOR_2_CREATED) - .affiliation(CREATOR_2_AFFIL) - .lastModified(CREATOR_2_MODIFIED) - .build(); - - public final static Creator CREATOR_3 = Creator.builder() - .id(CREATOR_3_ID) - .pid(IDENTIFIER_1_ID) - .orcid(CREATOR_3_ORCID) - .firstname(CREATOR_3_FIRSTNAME) - .lastname(CREATOR_3_LASTNAME) - .created(CREATOR_3_CREATED) - .affiliation(CREATOR_3_AFFIL) - .lastModified(CREATOR_3_MODIFIED) - .build(); - - public final static CreatorDto CREATOR_1_DTO = CreatorDto.builder() - .id(CREATOR_1_ID) - .affiliation(CREATOR_1_AFFIL) - .orcid(CREATOR_1_ORCID) - .firstname(CREATOR_1_FIRSTNAME) - .lastname(CREATOR_1_LASTNAME) - .build(); - - public final static CreatorCreateDto CREATOR_1_CREATE_DTO = CreatorCreateDto.builder() - .affiliation(CREATOR_1_AFFIL) - .orcid(CREATOR_1_ORCID) - .firstname(CREATOR_1_FIRSTNAME) - .lastname(CREATOR_1_LASTNAME) - .build(); - - public final static CreatorDto CREATOR_2_DTO = CreatorDto.builder() - .id(CREATOR_2_ID) - .affiliation(CREATOR_2_AFFIL) - .orcid(CREATOR_2_ORCID) - .firstname(CREATOR_2_FIRSTNAME) - .lastname(CREATOR_2_LASTNAME) - .build(); - - public final static CreatorCreateDto CREATOR_2_CREATE_DTO = CreatorCreateDto.builder() - .affiliation(CREATOR_2_AFFIL) - .orcid(CREATOR_2_ORCID) - .firstname(CREATOR_2_FIRSTNAME) - .lastname(CREATOR_2_LASTNAME) - .build(); - - public final static IdentifierDto IDENTIFIER_1_MODIFY_DTO = IdentifierDto.builder() - .id(IDENTIFIER_1_ID) - .containerId(CONTAINER_1_ID) - .databaseId(DATABASE_1_ID) - .queryId(IDENTIFIER_1_QUERY_ID) - .databaseId(IDENTIFIER_1_DATABASE_ID) - .description(IDENTIFIER_1_DESCRIPTION_MODIFY) - .title(IDENTIFIER_1_TITLE_MODIFY) - .doi(IDENTIFIER_1_DOI) - .publisher(IDENTIFIER_1_PUBLISHER) - .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) - .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) - .type(IDENTIFIER_1_TYPE_DTO) - .visibility(IDENTIFIER_1_VISIBILITY_DTO) - .created(IDENTIFIER_1_CREATED) - .lastModified(IDENTIFIER_1_MODIFIED) - .creators(List.of(CREATOR_1_DTO)) - .build(); - - public final static IdentifierCreateDto IDENTIFIER_1_DTO_REQUEST = IdentifierCreateDto.builder() - .cid(IDENTIFIER_1_CONTAINER_ID) - .dbid(IDENTIFIER_1_DATABASE_ID) - .description(IDENTIFIER_1_DESCRIPTION) - .title(IDENTIFIER_1_TITLE) - .doi(IDENTIFIER_1_DOI) - .visibility(IDENTIFIER_1_VISIBILITY_DTO) - .relatedIdentifiers(List.of()) - .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) - .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) - .creators(List.of(CREATOR_1_CREATE_DTO)) - .publisher(IDENTIFIER_1_PUBLISHER) - .type(IDENTIFIER_1_TYPE_DTO) - .build(); - - public final static IdentifierCreateDto IDENTIFIER_1_DTO_TRUSTED_REQUEST = IdentifierCreateDto.builder() - .cid(IDENTIFIER_1_CONTAINER_ID) - .dbid(IDENTIFIER_1_DATABASE_ID) - .description(IDENTIFIER_1_DESCRIPTION) - .title(IDENTIFIER_1_TITLE) - .doi(IDENTIFIER_1_DOI) - .visibility(VisibilityTypeDto.TRUSTED) - .relatedIdentifiers(List.of()) - .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) - .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) - .creators(List.of(CREATOR_1_CREATE_DTO)) - .publisher(IDENTIFIER_1_PUBLISHER) - .type(IDENTIFIER_1_TYPE_DTO) - .build(); - - public final static IdentifierCreateDto IDENTIFIER_1_DTO_SELF_REQUEST = IdentifierCreateDto.builder() - .cid(IDENTIFIER_1_CONTAINER_ID) - .dbid(IDENTIFIER_1_DATABASE_ID) - .description(IDENTIFIER_1_DESCRIPTION) - .title(IDENTIFIER_1_TITLE) - .doi(IDENTIFIER_1_DOI) - .visibility(VisibilityTypeDto.SELF) - .relatedIdentifiers(List.of()) - .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) - .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) - .creators(List.of(CREATOR_1_CREATE_DTO)) - .publisher(IDENTIFIER_1_PUBLISHER) - .type(IDENTIFIER_1_TYPE_DTO) - .build(); - - public final static Long RELATED_IDENTIFIER_2_ID = 1L; - public final static Long RELATED_IDENTIFIER_2_IDENTIFIER_ID = 2L; - public final static String RELATED_IDENTIFIER_2_VALUE = "10.5281/zenodo.6637333"; - public final static RelatedType RELATED_IDENTIFIER_2_TYPE = RelatedType.DOI; - public final static RelatedTypeDto RELATED_IDENTIFIER_2_TYPE_DTO = RelatedTypeDto.DOI; - public final static RelationType RELATED_IDENTIFIER_2_RELATION_TYPE = RelationType.CITES; - public final static RelationTypeDto RELATED_IDENTIFIER_2_RELATION = RelationTypeDto.CITES; - - public final static RelatedIdentifier IDENTIFIER_1_RELATED_IDENTIFIER_1 = RelatedIdentifier.builder() - .id(RELATED_IDENTIFIER_2_ID) - .iid(RELATED_IDENTIFIER_2_IDENTIFIER_ID) - .type(RELATED_IDENTIFIER_2_TYPE) - .relation(RELATED_IDENTIFIER_2_RELATION_TYPE) - .value(RELATED_IDENTIFIER_2_VALUE) - .build(); - - public final static RelatedIdentifierCreateDto IDENTIFIER_1_RELATED_IDENTIFIER_2_CREATE_DTO = RelatedIdentifierCreateDto.builder() - .value(RELATED_IDENTIFIER_2_VALUE) - .type(RELATED_IDENTIFIER_2_TYPE_DTO) - .relation(RELATED_IDENTIFIER_2_RELATION) - .build(); - - public final static IdentifierCreateDto IDENTIFIER_2_DTO_REQUEST = IdentifierCreateDto.builder() - .qid(IDENTIFIER_2_QUERY_ID) - .cid(IDENTIFIER_2_CONTAINER_ID) - .dbid(IDENTIFIER_2_DATABASE_ID) - .description(IDENTIFIER_2_DESCRIPTION) - .title(IDENTIFIER_2_TITLE) - .doi(IDENTIFIER_2_DOI) - .visibility(IDENTIFIER_2_VISIBILITY_DTO) - .relatedIdentifiers(List.of(IDENTIFIER_1_RELATED_IDENTIFIER_2_CREATE_DTO)) - .publicationDay(IDENTIFIER_2_PUBLICATION_DAY) - .publicationMonth(IDENTIFIER_2_PUBLICATION_MONTH) - .publicationYear(IDENTIFIER_2_PUBLICATION_YEAR) - .creators(List.of(CREATOR_1_CREATE_DTO, CREATOR_2_CREATE_DTO)) - .publisher(IDENTIFIER_2_PUBLISHER) - .type(IDENTIFIER_2_TYPE_DTO) - .build(); - - public final static Long IDENTIFIER_3_ID = 3L; - public final static Long IDENTIFIER_3_QUERY_ID = QUERY_3_ID; - public final static Long IDENTIFIER_3_CONTAINER_ID = CONTAINER_3_ID; - public final static Long IDENTIFIER_3_DATABASE_ID = DATABASE_3_ID; - public final static String IDENTIFIER_3_DESCRIPTION = "Selecting all from the weather Norwegian table"; - public final static String IDENTIFIER_3_TITLE = "Norwegian weather data"; - public final static String IDENTIFIER_3_DOI = "10.1000/183"; - public final static VisibilityType IDENTIFIER_3_VISIBILITY = VisibilityType.EVERYONE; - public final static Instant IDENTIFIER_3_CREATED = Instant.ofEpochSecond(1641588352); - public final static Instant IDENTIFIER_3_MODIFIED = Instant.ofEpochSecond(1541588352); - public final static Instant IDENTIFIER_3_EXECUTION = Instant.ofEpochSecond(1541588352); - public final static Integer IDENTIFIER_3_PUBLICATION_DAY = 14; - public final static Integer IDENTIFIER_3_PUBLICATION_MONTH = 7; - public final static Integer IDENTIFIER_3_PUBLICATION_YEAR = 2022; - public final static String IDENTIFIER_3_QUERY_HASH = "abc"; - public final static String IDENTIFIER_3_RESULT_HASH = "def"; - public final static String IDENTIFIER_3_QUERY = "SELECT `id` FROM `foobar`"; - public final static String IDENTIFIER_3_NORMALIZED = "SELECT `id` FROM `foobar`"; - public final static Long IDENTIFIER_3_RESULT_NUMBER = 2L; - public final static String IDENTIFIER_3_PUBLISHER = "Norwegian Government"; - public final static IdentifierType IDENTIFIER_3_TYPE = IdentifierType.SUBSET; - public final static IdentifierTypeDto IDENTIFIER_3_TYPE_DTO = IdentifierTypeDto.SUBSET; - - public final static Identifier IDENTIFIER_3 = Identifier.builder() - .id(IDENTIFIER_3_ID) - .containerId(IDENTIFIER_3_CONTAINER_ID) - .databaseId(IDENTIFIER_3_DATABASE_ID) - .queryId(IDENTIFIER_3_QUERY_ID) - .description(IDENTIFIER_3_DESCRIPTION) - .title(IDENTIFIER_3_TITLE) - .doi(IDENTIFIER_3_DOI) - .visibility(IDENTIFIER_3_VISIBILITY) - .created(IDENTIFIER_3_CREATED) - .lastModified(IDENTIFIER_3_MODIFIED) - .execution(IDENTIFIER_3_EXECUTION) - .publicationDay(IDENTIFIER_3_PUBLICATION_DAY) - .publicationMonth(IDENTIFIER_3_PUBLICATION_MONTH) - .publicationYear(IDENTIFIER_3_PUBLICATION_YEAR) - .queryHash(IDENTIFIER_3_QUERY_HASH) - .resultHash(IDENTIFIER_3_RESULT_HASH) - .query(IDENTIFIER_3_QUERY) - .queryNormalized(IDENTIFIER_3_NORMALIZED) - .resultNumber(IDENTIFIER_3_RESULT_NUMBER) - .publisher(IDENTIFIER_3_PUBLISHER) - .type(IDENTIFIER_3_TYPE) - .creator(USER_3) - .creators(List.of(CREATOR_1, CREATOR_2, CREATOR_3)) - .build(); - - public final static Long IDENTIFIER_4_ID = 4L; - public final static Long IDENTIFIER_4_CONTAINER_ID = CONTAINER_4_ID; - public final static Long IDENTIFIER_4_DATABASE_ID = DATABASE_4_ID; - public final static String IDENTIFIER_4_DESCRIPTION = "Selecting all from the weather Sweden table"; - public final static String IDENTIFIER_4_TITLE = "Sweden weather data"; - public final static String IDENTIFIER_4_DOI = "10.1000/184"; - public final static VisibilityType IDENTIFIER_4_VISIBILITY = VisibilityType.EVERYONE; - public final static Instant IDENTIFIER_4_CREATED = Instant.ofEpochSecond(1641588352); - public final static Instant IDENTIFIER_4_MODIFIED = Instant.ofEpochSecond(1541588352); - public final static Instant IDENTIFIER_4_EXECUTION = Instant.ofEpochSecond(1541588352); - public final static Integer IDENTIFIER_4_PUBLICATION_DAY = 14; - public final static Integer IDENTIFIER_4_PUBLICATION_MONTH = 7; - public final static Integer IDENTIFIER_4_PUBLICATION_YEAR = 2022; - public final static String IDENTIFIER_4_QUERY_HASH = "abc"; - public final static String IDENTIFIER_4_RESULT_HASH = "def"; - public final static String IDENTIFIER_4_QUERY = "SELECT `id` FROM `foobar`"; - public final static String IDENTIFIER_4_NORMALIZED = "SELECT `id` FROM `foobar`"; - public final static Long IDENTIFIER_4_RESULT_NUMBER = 2L; - public final static String IDENTIFIER_4_PUBLISHER = "Swedish Government"; - public final static IdentifierType IDENTIFIER_4_TYPE = IdentifierType.DATABASE; - - public final static Identifier IDENTIFIER_4 = Identifier.builder() - .id(IDENTIFIER_4_ID) - .containerId(IDENTIFIER_4_CONTAINER_ID) - .databaseId(IDENTIFIER_4_DATABASE_ID) - .description(IDENTIFIER_4_DESCRIPTION) - .title(IDENTIFIER_4_TITLE) - .doi(IDENTIFIER_4_DOI) - .visibility(IDENTIFIER_4_VISIBILITY) - .created(IDENTIFIER_4_CREATED) - .lastModified(IDENTIFIER_4_MODIFIED) - .execution(IDENTIFIER_4_EXECUTION) - .publicationDay(IDENTIFIER_4_PUBLICATION_DAY) - .publicationMonth(IDENTIFIER_4_PUBLICATION_MONTH) - .publicationYear(IDENTIFIER_4_PUBLICATION_YEAR) - .queryHash(IDENTIFIER_4_QUERY_HASH) - .resultHash(IDENTIFIER_4_RESULT_HASH) - .query(IDENTIFIER_4_QUERY) - .queryNormalized(IDENTIFIER_4_NORMALIZED) - .resultNumber(IDENTIFIER_4_RESULT_NUMBER) - .publisher(IDENTIFIER_4_PUBLISHER) - .type(IDENTIFIER_4_TYPE) - .creator(USER_3) - .creators(List.of()) - .build(); - - public final static String COLUMN_1_INTERNAL_NAME = "id"; - public final static String COLUMN_2_INTERNAL_NAME = "name"; - - public final static Map<String, Object> ROW_1 = new LinkedHashMap<>() {{ - put(COLUMN_1_INTERNAL_NAME, 1L); - put(COLUMN_2_INTERNAL_NAME, "Foo"); - }}; - public final static Map<String, Object> ROW_2 = new LinkedHashMap<>() {{ - put(COLUMN_1_INTERNAL_NAME, 2L); - put(COLUMN_2_INTERNAL_NAME, "Bar"); - }}; - public final static Map<String, Object> ROW_3 = new LinkedHashMap<>() {{ - put(COLUMN_1_INTERNAL_NAME, 3L); - put(COLUMN_2_INTERNAL_NAME, "Baz"); - }}; - - public final static QueryResultDto QUERY_1_RESULT = QueryResultDto.builder() - .id(QUERY_1_ID) - .result(List.of(ROW_1, ROW_2, ROW_3)) - .build(); +public abstract class BaseUnitTest extends BaseTest { } diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/auth/AuthTokenFilterTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/auth/AuthTokenFilterTest.java index b18801abc8058d5c67ad3a5ae79422f83ed3d25f..c15afaef64ba04f31deb103d954e5ac5df5d1a20 100644 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/auth/AuthTokenFilterTest.java +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/auth/AuthTokenFilterTest.java @@ -12,18 +12,10 @@ 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.mock.web.MockFilterChain; import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.junit.jupiter.SpringExtension; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import java.io.IOException; -import java.util.Optional; - import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.when; @Log4j2 @SpringBootTest @@ -50,49 +42,6 @@ public class AuthTokenFilterTest extends BaseUnitTest { h2Utils.runScript("view.sql"); } - @Test - public void doFilterInternal_notFound_fails() throws ServletException { - final MockHttpServletRequest request = new MockHttpServletRequest(); - request.addHeader("Authorization", "Bearer " + JWT_1); - final MockHttpServletResponse response = new MockHttpServletResponse(); - final FilterChain chain = new MockFilterChain(); - - /* mock */ - when(userRepository.findByUsername("mweise")) - .thenReturn(Optional.empty()); - - /* test */ - assertThrows(ServletException.class, () -> { - authTokenFilter.doFilterInternal(request, response, chain); - }); - } - - @Test - public void doFilterInternal_succeeds() throws ServletException, IOException { - final MockHttpServletRequest request = new MockHttpServletRequest(); - request.addHeader("Authorization", "Bearer " + JWT_1); - final MockHttpServletResponse response = new MockHttpServletResponse(); - final FilterChain chain = new MockFilterChain(); - - /* mock */ - when(userRepository.findByUsername("mweise")) - .thenReturn(Optional.of(USER_1)); - - /* test */ - authTokenFilter.doFilterInternal(request, response, chain); - assertEquals(200, response.getStatus()); - } - - @Test - public void parseJwt_succeeds() { - final MockHttpServletRequest request = new MockHttpServletRequest(); - request.addHeader("Authorization", "Bearer " + JWT_1); - - /* test */ - final String response = authTokenFilter.parseJwt(request); - assertEquals(JWT_1, response); - } - @Test public void parseJwt_fails() { final MockHttpServletRequest request = new MockHttpServletRequest(); diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/config/DockerConfig.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/config/DockerConfig.java deleted file mode 100644 index 50634e3e35bce6a9efb2f4546333d2c9c71e4805..0000000000000000000000000000000000000000 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/config/DockerConfig.java +++ /dev/null @@ -1,63 +0,0 @@ -package at.tuwien.config; - -import at.tuwien.entities.container.Container; -import com.github.dockerjava.api.DockerClient; -import com.github.dockerjava.api.command.InspectContainerResponse; -import com.github.dockerjava.api.model.HostConfig; -import com.github.dockerjava.api.model.RestartPolicy; -import com.github.dockerjava.core.DefaultDockerClientConfig; -import com.github.dockerjava.core.DockerClientBuilder; -import com.github.dockerjava.core.DockerClientConfig; -import com.github.dockerjava.httpclient5.ApacheDockerHttpClient; -import com.github.dockerjava.transport.DockerHttpClient; -import lombok.extern.log4j.Log4j2; - -import java.util.Objects; - -@Log4j2 -public class DockerConfig { - - private final static DockerClientConfig dockerClientConfig = DefaultDockerClientConfig.createDefaultConfigBuilder() - .withDockerHost("unix:///var/run/docker.sock") - .build(); - - private final static DockerHttpClient dockerHttpClient = new ApacheDockerHttpClient.Builder() - .dockerHost(dockerClientConfig.getDockerHost()) - .sslConfig(dockerClientConfig.getSSLConfig()) - .build(); - - public final static HostConfig hostConfig = HostConfig.newHostConfig() - .withRestartPolicy(RestartPolicy.alwaysRestart()); - - public final static DockerClient dockerClient = DockerClientBuilder.getInstance() - .withDockerHttpClient(dockerHttpClient) - .build(); - - public static void startContainer(Container container) throws InterruptedException { - final InspectContainerResponse inspect = dockerClient.inspectContainerCmd(container.getHash()) - .exec(); - log.trace("container {} state {}", container.getHash(), inspect.getState().getStatus()); - if (Objects.equals(inspect.getState().getStatus(), "running")) { - return; - } - log.trace("container {} needs to be started", container.getHash()); - dockerClient.startContainerCmd(container.getHash()) - .exec(); - Thread.sleep(60 * 1000L); - log.debug("container {} was started", container.getHash()); - } - - public static void stopContainer(Container container) { - final InspectContainerResponse inspect = dockerClient.inspectContainerCmd(container.getHash()) - .exec(); - log.trace("container {} state {}", container.getHash(), inspect.getState().getStatus()); - if (!Objects.equals(inspect.getState().getStatus(), "running")) { - return; - } - log.trace("container {} needs to be stopped", container.getHash()); - dockerClient.stopContainerCmd(container.getHash()) - .exec(); - log.debug("container {} was stopped", container.getHash()); - } - -} diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/config/H2Utils.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/config/H2Utils.java deleted file mode 100644 index f7799c00a0765ab1549cda58b4524e1502664759..0000000000000000000000000000000000000000 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/config/H2Utils.java +++ /dev/null @@ -1,37 +0,0 @@ -package at.tuwien.config; - -import lombok.extern.log4j.Log4j2; -import org.codehaus.plexus.util.FileUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -import javax.persistence.EntityManager; -import java.io.File; -import java.io.IOException; - -@Log4j2 -@Component -public class H2Utils { - - @Autowired - private EntityManager entityManager; - - @Transactional - public void runQuery(String query) { - log.debug("query={}", query); - entityManager.createNativeQuery(query) - .executeUpdate(); - } - - @Transactional - public void runScript(String scriptName) { - try { - runQuery(FileUtils.fileRead(new File("./src/test/resources/" + scriptName))); - } catch (IOException e) { - log.error("Failed to load script {}", scriptName); - throw new RuntimeException("Failed to load script", e); - } - } - -} diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java deleted file mode 100644 index 072bb9e75baec76906a6bc0629e7330f62f46ffe..0000000000000000000000000000000000000000 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java +++ /dev/null @@ -1,9 +0,0 @@ -package at.tuwien.config; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.context.annotation.Configuration; - -@Slf4j -@Configuration -public class MariaDbConfig { -} diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/IdentifierEndpointUnitTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/IdentifierEndpointUnitTest.java index ffb4112801902a957a03c286fe6248e08f54ec40..8ad52e70ba3bd5fe30900d7a635e4fd0ee0f7c09 100644 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/IdentifierEndpointUnitTest.java +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/IdentifierEndpointUnitTest.java @@ -209,8 +209,6 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { .dbid(IDENTIFIER_1_DATABASE_ID) .description(IDENTIFIER_1_DESCRIPTION) .title(IDENTIFIER_1_TITLE) - .doi(IDENTIFIER_1_DOI) - .visibility(IDENTIFIER_1_VISIBILITY_DTO) .relatedIdentifiers(List.of()) .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) @@ -234,8 +232,6 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { .dbid(IDENTIFIER_1_DATABASE_ID) .description(IDENTIFIER_1_DESCRIPTION) .title(IDENTIFIER_1_TITLE) - .doi(IDENTIFIER_1_DOI) - .visibility(IDENTIFIER_1_VISIBILITY_DTO) .relatedIdentifiers(List.of(IDENTIFIER_1_RELATED_IDENTIFIER_2_CREATE_DTO)) .publicationDay(IDENTIFIER_2_PUBLICATION_DAY) .publicationMonth(IDENTIFIER_2_PUBLICATION_MONTH) @@ -297,7 +293,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { @Test @WithMockUser(username = USER_3_USERNAME, roles = {"DATA_STEWARD"}) public void update_dataSteward_succeeds() throws IdentifierPublishingNotAllowedException, - IdentifierNotFoundException { + IdentifierNotFoundException, IdentifierRequestException { /* test */ generic_update(); @@ -328,7 +324,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { @Test @WithMockUser(username = USER_3_USERNAME, roles = {"DATA_STEWARD"}) - public void delete_dataSteward_succeeds() throws IdentifierNotFoundException { + public void delete_dataSteward_succeeds() throws IdentifierNotFoundException, NotAllowedException { /* test */ generic_delete(); @@ -346,7 +342,7 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { IdentifierRequestException, NotAllowedException { /* mock */ - when(databaseRepository.findByContainerAndDatabaseId(containerId, databaseId)) + when(databaseRepository.findById(databaseId)) .thenReturn(Optional.of(database)); if (user == null) { when(userRepository.findByUsername(username)) @@ -397,29 +393,30 @@ public class IdentifierEndpointUnitTest extends BaseUnitTest { return persistenceEndpoint.find(IDENTIFIER_1_ID, accept); } - protected void generic_update() throws IdentifierPublishingNotAllowedException, IdentifierNotFoundException { + protected void generic_update() + throws IdentifierPublishingNotAllowedException, IdentifierNotFoundException, IdentifierRequestException { /* mock */ - when(identifierService.update(IDENTIFIER_1_ID, IDENTIFIER_1_DTO)) - .thenReturn(IDENTIFIER_1); - when(identifierRepository.save(IDENTIFIER_1)) - .thenReturn(IDENTIFIER_1); + when(identifierService.update(IDENTIFIER_3_ID, IDENTIFIER_3_DTO)) + .thenReturn(IDENTIFIER_3); + when(identifierRepository.save(IDENTIFIER_3)) + .thenReturn(IDENTIFIER_3); /* test */ - final ResponseEntity<IdentifierDto> response = identifierEndpoint.update(IDENTIFIER_1_ID, IDENTIFIER_1_DTO); + final ResponseEntity<IdentifierDto> response = identifierEndpoint.update(IDENTIFIER_3_ID, IDENTIFIER_3_DTO); assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); final IdentifierDto body = response.getBody(); assertNotNull(body); - assertEquals(IDENTIFIER_1_ID, body.getId()); - assertEquals(IDENTIFIER_1_TITLE, body.getTitle()); - assertEquals(IDENTIFIER_1_DESCRIPTION, body.getDescription()); - assertEquals(IDENTIFIER_1_QUERY, body.getQuery()); - assertEquals(IDENTIFIER_1_QUERY_HASH, body.getQueryHash()); - assertEquals(IDENTIFIER_1_RESULT_NUMBER, body.getResultNumber()); - assertEquals(IDENTIFIER_1_RESULT_HASH, body.getResultHash()); + assertEquals(IDENTIFIER_3_ID, body.getId()); + assertEquals(IDENTIFIER_3_TITLE, body.getTitle()); + assertEquals(IDENTIFIER_3_DESCRIPTION, body.getDescription()); + assertEquals(IDENTIFIER_3_QUERY, body.getQuery()); + assertEquals(IDENTIFIER_3_QUERY_HASH, body.getQueryHash()); + assertEquals(IDENTIFIER_3_RESULT_NUMBER, body.getResultNumber()); + assertEquals(IDENTIFIER_3_RESULT_HASH, body.getResultHash()); } - protected void generic_delete() throws IdentifierNotFoundException { + protected void generic_delete() throws IdentifierNotFoundException, NotAllowedException { /* mock */ doNothing() diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/PersistenceEndpointUnitTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/PersistenceEndpointUnitTest.java index 50213b8fdaf27b010fc691608fb0e1af67d8fadf..491b3eb7c574a0222ec07b5c56ecaf182dd5cbe4 100644 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/PersistenceEndpointUnitTest.java +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/endpoint/PersistenceEndpointUnitTest.java @@ -307,6 +307,25 @@ public class PersistenceEndpointUnitTest extends BaseUnitTest { assertEquals(compare, body); } + @Test + public void find_bibliographyApa4_succeeds() throws IdentifierNotFoundException, QueryNotFoundException, + RemoteUnavailableException, IdentifierRequestException, IOException { + final String accept = "text/bibliography; style=apa"; + final String compare = FileUtils.readFileToString(new File("src/test/resources/bibliography/style_apa4.txt"), + StandardCharsets.UTF_8); + + /* mock */ + when(identifierRepository.findById(IDENTIFIER_1_ID)) + .thenReturn(Optional.of(IDENTIFIER_1_WITH_DOI)); + + /* test */ + final ResponseEntity<?> response = persistenceEndpoint.find(IDENTIFIER_1_ID, accept); + assertEquals(HttpStatus.OK, response.getStatusCode()); + final String body = (String) response.getBody(); + assertNotNull(body); + assertEquals(compare, body); + } + @Test public void find_bibliographyIeee0_succeeds() throws IdentifierNotFoundException, QueryNotFoundException, RemoteUnavailableException, IdentifierRequestException, IOException { @@ -364,6 +383,25 @@ public class PersistenceEndpointUnitTest extends BaseUnitTest { assertEquals(compare, body); } + @Test + public void find_bibliographyIeee3_succeeds() throws IdentifierNotFoundException, QueryNotFoundException, + RemoteUnavailableException, IdentifierRequestException, IOException { + final String accept = "text/bibliography; style=ieee"; + final String compare = FileUtils.readFileToString(new File("src/test/resources/bibliography/style_ieee3.txt"), + StandardCharsets.UTF_8); + + /* mock */ + when(identifierRepository.findById(IDENTIFIER_1_ID)) + .thenReturn(Optional.of(IDENTIFIER_1_WITH_DOI)); + + /* test */ + final ResponseEntity<?> response = persistenceEndpoint.find(IDENTIFIER_1_ID, accept); + assertEquals(HttpStatus.OK, response.getStatusCode()); + final String body = (String) response.getBody(); + assertNotNull(body); + assertEquals(compare, body); + } + @Test public void find_bibliographyBibtex0_succeeds() throws IdentifierNotFoundException, QueryNotFoundException, RemoteUnavailableException, IdentifierRequestException, IOException { @@ -421,6 +459,25 @@ public class PersistenceEndpointUnitTest extends BaseUnitTest { assertEquals(compare, body); } + @Test + public void find_bibliographyBibtex3_succeeds() throws IdentifierNotFoundException, QueryNotFoundException, + RemoteUnavailableException, IdentifierRequestException, IOException { + final String accept = "text/bibliography; style=bibtex"; + final String compare = FileUtils.readFileToString(new File("src/test/resources/bibliography/style_bibtex3.txt"), + StandardCharsets.UTF_8); + + /* mock */ + when(identifierRepository.findById(IDENTIFIER_1_ID)) + .thenReturn(Optional.of(IDENTIFIER_1_WITH_DOI)); + + /* test */ + final ResponseEntity<?> response = persistenceEndpoint.find(IDENTIFIER_1_ID, accept); + assertEquals(HttpStatus.OK, response.getStatusCode()); + final String body = (String) response.getBody(); + assertNotNull(body); + assertEquals(compare, body); + } + protected static String inputStreamToString(InputStream inputStream) throws IOException { return IOUtils.toString(inputStream, StandardCharsets.UTF_8); } diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/gateway/QueryServiceGatewayUnitTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/gateway/QueryServiceGatewayUnitTest.java index 915bb1fb275e16a252cd1fd4dcdbfcc5ffa52100..4fd01d25093e0ca7389804ee5063946010a4c9af 100644 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/gateway/QueryServiceGatewayUnitTest.java +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/gateway/QueryServiceGatewayUnitTest.java @@ -59,7 +59,7 @@ public class QueryServiceGatewayUnitTest extends BaseUnitTest { .thenReturn(mock); /* test */ - final QueryDto response = queryServiceGateway.find(CONTAINER_1_ID, DATABASE_1_ID, IDENTIFIER_1_DTO_REQUEST, JWT_1); + final QueryDto response = queryServiceGateway.find(CONTAINER_1_ID, DATABASE_1_ID, IDENTIFIER_1_DTO_REQUEST, null); assertNotNull(response); assertEquals(QUERY_1_ID, response.getId()); } @@ -75,7 +75,7 @@ public class QueryServiceGatewayUnitTest extends BaseUnitTest { /* test */ assertThrows(QueryNotFoundException.class, () -> { - queryServiceGateway.find(CONTAINER_1_ID, DATABASE_1_ID, IDENTIFIER_1_DTO_REQUEST, JWT_1); + queryServiceGateway.find(CONTAINER_1_ID, DATABASE_1_ID, IDENTIFIER_1_DTO_REQUEST, null); }); } @@ -91,7 +91,7 @@ public class QueryServiceGatewayUnitTest extends BaseUnitTest { /* test */ assertThrows(RemoteUnavailableException.class, () -> { - queryServiceGateway.find(CONTAINER_1_ID, DATABASE_1_ID, IDENTIFIER_1_DTO_REQUEST, JWT_1); + queryServiceGateway.find(CONTAINER_1_ID, DATABASE_1_ID, IDENTIFIER_1_DTO_REQUEST, null); }); } @@ -106,7 +106,7 @@ public class QueryServiceGatewayUnitTest extends BaseUnitTest { /* test */ assertThrows(RemoteUnavailableException.class, () -> { - queryServiceGateway.find(CONTAINER_1_ID, DATABASE_1_ID, IDENTIFIER_1_DTO_REQUEST, JWT_1); + queryServiceGateway.find(CONTAINER_1_ID, DATABASE_1_ID, IDENTIFIER_1_DTO_REQUEST, null); }); } diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/DataCiteIdentifierServiceUnitTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/DataCiteIdentifierServiceUnitTest.java new file mode 100644 index 0000000000000000000000000000000000000000..60c4bd45b4d0de8b2379c9564b66fd52b9646dab --- /dev/null +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/DataCiteIdentifierServiceUnitTest.java @@ -0,0 +1,216 @@ +package at.tuwien.service; + +import at.tuwien.BaseUnitTest; +import at.tuwien.api.datacite.DataCiteBody; +import at.tuwien.api.datacite.DataCiteData; +import at.tuwien.api.datacite.doi.DataCiteDoi; +import at.tuwien.api.identifier.IdentifierCreateDto; +import at.tuwien.api.identifier.IdentifierDto; +import at.tuwien.config.DataCiteConfig; +import at.tuwien.config.EndpointConfig; +import at.tuwien.config.IndexInitializer; +import at.tuwien.entities.identifier.Identifier; +import at.tuwien.exception.*; +import at.tuwien.repository.jpa.ContainerRepository; +import at.tuwien.repository.jpa.DatabaseRepository; +import at.tuwien.repository.jpa.IdentifierRepository; +import at.tuwien.repository.jpa.ImageRepository; +import at.tuwien.service.impl.IdentifierServiceImpl; +import org.apache.http.auth.BasicUserPrincipal; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Answers; +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.boot.web.client.RestTemplateBuilder; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; + +import java.security.Principal; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.when; + +@ExtendWith(SpringExtension.class) +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@SpringBootTest +@ActiveProfiles("doi") +public class DataCiteIdentifierServiceUnitTest extends BaseUnitTest { + + @MockBean + private IndexInitializer indexInitializer; + + @MockBean(answer = Answers.RETURNS_MOCKS) + private DataCiteConfig dataCiteConfig; + + @MockBean(answer = Answers.RETURNS_MOCKS) + private EndpointConfig endpointConfig; + + @Autowired + private ImageRepository imageRepository; + + @Autowired + private ContainerRepository containerRepository; + + @Autowired + private DatabaseRepository databaseRepository; + + @Autowired + private IdentifierRepository identifierRepository; + + @MockBean + private RestTemplate restTemplate; + + @MockBean(answer = Answers.RETURNS_SELF) + private RestTemplateBuilder restTemplateBuilder; + + @MockBean + private IdentifierServiceImpl identifierService; + + @Autowired + private IdentifierService dataCiteIdentifierService; + + @BeforeEach + public void beforeEach() { + imageRepository.save(IMAGE_1); + containerRepository.save(CONTAINER_1); + databaseRepository.save(DATABASE_1); + when(restTemplateBuilder.build()).thenReturn(restTemplate); + IDENTIFIER_1.setCreators(null); + } + + @Test + public void create_database_succeeds() + throws DatabaseNotFoundException, UserNotFoundException, IdentifierAlreadyExistsException, + QueryNotFoundException, IdentifierPublishingNotAllowedException, RemoteUnavailableException, + IdentifierRequestException { + final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); + final String bearer = "Bearer abcxyz"; + final DataCiteBody<DataCiteDoi> response = + new DataCiteBody<>(new DataCiteData<>(null, "dois", new DataCiteDoi(IDENTIFIER_1_DOI_NOT_NULL))); + + /* mock */ + when(identifierService.create(any(IdentifierCreateDto.class), eq(principal), eq(bearer))) + .thenAnswer((i) -> identifierRepository.save(IDENTIFIER_1)); + when(restTemplate.exchange(anyString(), eq(HttpMethod.POST), any(HttpEntity.class), + any(ParameterizedTypeReference.class))) + .thenReturn(ResponseEntity.status(HttpStatus.CREATED).body(response)); + + /* test */ + Identifier result = dataCiteIdentifierService.create(IDENTIFIER_1_DTO_REQUEST, principal, bearer); + assertTrue(identifierRepository.existsById(result.getId())); + assertEquals(IDENTIFIER_1_DOI_NOT_NULL, result.getDoi()); + } + + @Test + public void create_invalidMetadata_fails() + throws IdentifierAlreadyExistsException, UserNotFoundException, QueryNotFoundException, + DatabaseNotFoundException, RemoteUnavailableException, IdentifierPublishingNotAllowedException, + IdentifierRequestException { + final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); + final String bearer = "Bearer abcxyz"; + + /* mock */ + when(identifierService.create(any(IdentifierCreateDto.class), eq(principal), eq(bearer))) + .thenAnswer((i) -> identifierRepository.save(IDENTIFIER_1)); + when(restTemplate.exchange(anyString(), eq(HttpMethod.POST), any(HttpEntity.class), + any(ParameterizedTypeReference.class))) + .thenThrow(HttpClientErrorException.BadRequest.class); + + /* test */ + assertThrows(IdentifierRequestException.class, () -> { + dataCiteIdentifierService.create(IDENTIFIER_1_DTO_REQUEST, principal, bearer); + }); + assertEquals(0, identifierRepository.count()); + } + + @Test + public void create_restClientException_fails() + throws IdentifierAlreadyExistsException, UserNotFoundException, QueryNotFoundException, + DatabaseNotFoundException, RemoteUnavailableException, IdentifierPublishingNotAllowedException, + IdentifierRequestException { + final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); + final String bearer = "Bearer abcxyz"; + + /* mock */ + when(identifierService.create(any(IdentifierCreateDto.class), eq(principal), eq(bearer))) + .thenAnswer((i) -> identifierRepository.save(IDENTIFIER_1)); + when(restTemplate.exchange(anyString(), eq(HttpMethod.POST), any(HttpEntity.class), + any(ParameterizedTypeReference.class))) + .thenThrow(RestClientException.class); + + /* test */ + assertThrows(InternalError.class, () -> { + dataCiteIdentifierService.create(IDENTIFIER_1_DTO_REQUEST, principal, bearer); + }); + assertEquals(0, identifierRepository.count()); + } + + @Test + public void update_existing_succeeds() + throws IdentifierRequestException, IdentifierNotFoundException { + final DataCiteBody<DataCiteDoi> response = + new DataCiteBody<>(new DataCiteData<>(null, "dois", new DataCiteDoi(IDENTIFIER_1_DOI_NOT_NULL))); + + /* mock */ + when(identifierService.update(eq(IDENTIFIER_1_ID), any(IdentifierDto.class))) + .thenAnswer((i) -> identifierRepository.save(IDENTIFIER_1_WITH_DOI)); + when(restTemplate.exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), + any(ParameterizedTypeReference.class), eq(IDENTIFIER_1_DOI_NOT_NULL))) + .thenReturn(ResponseEntity.ok(response)); + + /* test */ + Identifier result = dataCiteIdentifierService.update(IDENTIFIER_1_ID, IDENTIFIER_1_WITH_DOI_DTO); + assertTrue(identifierRepository.existsById(IDENTIFIER_1_ID)); + assertEquals(IDENTIFIER_1_DOI_NOT_NULL, result.getDoi()); + } + + @Test + public void update_invalidMetadata_fails() + throws IdentifierRequestException, IdentifierNotFoundException { + + /* mock */ + when(identifierService.update(eq(IDENTIFIER_1_ID), any(IdentifierDto.class))) + .thenAnswer((i) -> identifierRepository.save(IDENTIFIER_1_WITH_DOI)); + when(restTemplate.exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), + any(ParameterizedTypeReference.class), eq(IDENTIFIER_1_DOI_NOT_NULL))) + .thenThrow(HttpClientErrorException.BadRequest.class); + + /* test */ + assertThrows(IdentifierRequestException.class, () -> { + dataCiteIdentifierService.update(IDENTIFIER_1_ID, IDENTIFIER_1_WITH_DOI_DTO); + }); + assertEquals(0, identifierRepository.count()); + } + + @Test + public void update_restClientException_fails() + throws IdentifierRequestException, IdentifierNotFoundException { + + /* mock */ + when(identifierService.update(eq(IDENTIFIER_1_ID), any(IdentifierDto.class))) + .thenAnswer((i) -> identifierRepository.save(IDENTIFIER_1_WITH_DOI)); + when(restTemplate.exchange(anyString(), eq(HttpMethod.PUT), any(HttpEntity.class), + any(ParameterizedTypeReference.class), eq(IDENTIFIER_1_DOI_NOT_NULL))) + .thenThrow(RestClientException.class); + + /* test */ + assertThrows(InternalError.class, () -> { + dataCiteIdentifierService.update(IDENTIFIER_1_ID, IDENTIFIER_1_WITH_DOI_DTO); + }); + assertEquals(0, identifierRepository.count()); + } + +} diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java index f965bfa98f78c2d544dfca60e64a64bf1bfcd3b1..4133a24409469526e74a2a87bfca541f73dd4e07 100644 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceIntegrationTest.java @@ -3,18 +3,15 @@ package at.tuwien.service; import at.tuwien.BaseUnitTest; import at.tuwien.api.database.query.QueryDto; import at.tuwien.api.identifier.IdentifierDto; -import at.tuwien.api.identifier.VisibilityTypeDto; import at.tuwien.config.IndexInitializer; import at.tuwien.entities.identifier.Identifier; import at.tuwien.entities.identifier.RelatedIdentifier; -import at.tuwien.entities.identifier.VisibilityType; import at.tuwien.exception.*; import at.tuwien.gateway.QueryServiceGateway; import at.tuwien.repository.elastic.IdentifierIdxRepository; import at.tuwien.repository.jpa.*; import lombok.extern.log4j.Log4j2; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -86,7 +83,8 @@ public class IdentifierServiceIntegrationTest extends BaseUnitTest { @Test public void create_subsetRelatedIdentifiers_succeeds() throws DatabaseNotFoundException, UserNotFoundException, IdentifierAlreadyExistsException, - QueryNotFoundException, IdentifierPublishingNotAllowedException, RemoteUnavailableException { + QueryNotFoundException, IdentifierPublishingNotAllowedException, RemoteUnavailableException, + IdentifierRequestException { final String bearer = "Bearer abcxyz"; /* mock */ @@ -139,7 +137,8 @@ public class IdentifierServiceIntegrationTest extends BaseUnitTest { @Test @Transactional(readOnly = true) - public void update_succeeds() throws IdentifierNotFoundException, IdentifierPublishingNotAllowedException { + public void update_succeeds() + throws IdentifierNotFoundException, IdentifierPublishingNotAllowedException, IdentifierRequestException { /* mock */ when(identifierIdxRepository.save(any(IdentifierDto.class))) @@ -155,45 +154,7 @@ public class IdentifierServiceIntegrationTest extends BaseUnitTest { } @Test - public void publish_everyone_succeeds() throws IdentifierAlreadyPublishedException, IdentifierNotFoundException { - - /* mock */ - identifierRepository.save(IDENTIFIER_1); - identifierRepository.save(IDENTIFIER_2); - - /* mock */ - when(identifierIdxRepository.save(any(IdentifierDto.class))) - .thenReturn(IDENTIFIER_2_DTO); - - /* test */ - final Identifier response = identifierService.publish(IDENTIFIER_2_ID, VisibilityTypeDto.EVERYONE); - assertEquals(IDENTIFIER_2_ID, response.getId()); - assertEquals(IDENTIFIER_2_TITLE, response.getTitle()); - assertEquals(IDENTIFIER_2_DESCRIPTION, response.getDescription()); - assertEquals(IDENTIFIER_2_DOI, response.getDoi()); - assertEquals(IDENTIFIER_2_PUBLISHER, response.getPublisher()); - assertEquals(IDENTIFIER_2_CONTAINER_ID, response.getContainerId()); - assertEquals(IDENTIFIER_2_DATABASE_ID, response.getDatabaseId()); - assertEquals(IDENTIFIER_2_PUBLICATION_YEAR, response.getPublicationYear()); - assertEquals(IDENTIFIER_2_PUBLICATION_MONTH, response.getPublicationMonth()); - assertEquals(IDENTIFIER_2_PUBLICATION_DAY, response.getPublicationDay()); - assertEquals(VisibilityType.EVERYONE, response.getVisibility()); - } - - @Test - @Disabled("Constraint identifier") - public void publish_trusted_succeeds() throws IdentifierAlreadyPublishedException, IdentifierNotFoundException { - - /* mock */ - when(identifierIdxRepository.save(any(IdentifierDto.class))) - .thenReturn(IDENTIFIER_2_DTO); - - /* test */ - identifierService.publish(IDENTIFIER_2_ID, VisibilityTypeDto.TRUSTED); - } - - @Test - public void delete_succeeds() throws IdentifierNotFoundException { + public void delete_succeeds() throws IdentifierNotFoundException, NotAllowedException { /* mock */ doNothing() @@ -209,7 +170,7 @@ public class IdentifierServiceIntegrationTest extends BaseUnitTest { /* test */ assertThrows(IdentifierNotFoundException.class, () -> { - identifierService.publish(IDENTIFIER_2_ID, VisibilityTypeDto.EVERYONE); + identifierService.delete(IDENTIFIER_2_ID); }); } diff --git a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceUnitTest.java b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceUnitTest.java index 693ecce16bbfc93c2583bd5d6e1f19f56de36ef7..9301bd73535d5491fa766f23e728118abff59f22 100644 --- a/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceUnitTest.java +++ b/dbrepo-identifier-service/rest-service/src/test/java/at/tuwien/service/IdentifierServiceUnitTest.java @@ -188,61 +188,60 @@ public class IdentifierServiceUnitTest extends BaseUnitTest { } @Test - public void create_database_succeeds() - throws DatabaseNotFoundException, UserNotFoundException, IdentifierAlreadyExistsException, - QueryNotFoundException, IdentifierPublishingNotAllowedException, RemoteUnavailableException { - final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); - final String bearer = "Bearer abcxyz"; + public void update_doiChange_fails() { - /* mock */ - when(databaseService.find(CONTAINER_1_ID, DATABASE_1_ID)) - .thenReturn(DATABASE_1); - when(restTemplate.exchange(anyString(), any(HttpMethod.class), any(HttpEntity.class), eq(QueryDto.class))) - .thenReturn(ResponseEntity.ok(QUERY_1_DTO)); - when(userService.findByUsername(USER_1_USERNAME)) - .thenReturn(USER_1); - when(identifierRepository.save(any(Identifier.class))) - .thenReturn(IDENTIFIER_1); - when(identifierIdxRepository.save(any(IdentifierDto.class))) - .thenReturn(IDENTIFIER_1_DTO); + IdentifierDto identifierWithNewDoiDto = IdentifierDto.builder().id(IDENTIFIER_1_ID).visibility(VisibilityTypeDto.EVERYONE).doi("10.000/thisisadifferentdoi").build(); + /* mock */ + when(identifierRepository.findById(IDENTIFIER_1_ID)) + .thenReturn(Optional.of(IDENTIFIER_1_WITH_DOI)); /* test */ - identifierService.create(IDENTIFIER_1_DTO_REQUEST, principal, bearer); + assertThrows(IdentifierRequestException.class, () -> { + identifierService.update(IDENTIFIER_1_ID, identifierWithNewDoiDto); + }); } @Test - public void create_publicDatabaseTrustedDataset_fails() - throws DatabaseNotFoundException { - final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); - final String bearer = "Bearer abcxyz"; + public void update_notVisibleByEveryone_fails() { - /* mock */ - when(databaseService.find(CONTAINER_1_ID, DATABASE_1_ID)) - .thenReturn(DATABASE_1); + Identifier identifier = Identifier.builder().id(IDENTIFIER_1_ID).build(); + IdentifierDto identifierDto = IdentifierDto.builder().id(IDENTIFIER_1_ID).visibility(VisibilityTypeDto.TRUSTED).build(); + IDENTIFIER_1_DTO.setVisibility(VisibilityTypeDto.TRUSTED); + /* mock */ + when(identifierRepository.findById(IDENTIFIER_1_ID)) + .thenReturn(Optional.of(identifier)); /* test */ - assertThrows(IdentifierPublishingNotAllowedException.class, () -> { - identifierService.create(IDENTIFIER_1_DTO_TRUSTED_REQUEST, principal, bearer); + assertThrows(IdentifierRequestException.class, () -> { + identifierService.update(IDENTIFIER_1_ID, identifierDto); }); } @Test - public void create_publicDatabaseSelfDataset_fails() - throws DatabaseNotFoundException { + public void create_database_succeeds() + throws DatabaseNotFoundException, UserNotFoundException, IdentifierAlreadyExistsException, + QueryNotFoundException, IdentifierPublishingNotAllowedException, RemoteUnavailableException, + IdentifierRequestException { final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); final String bearer = "Bearer abcxyz"; /* mock */ - when(databaseService.find(CONTAINER_1_ID, DATABASE_1_ID)) + when(databaseService.find(DATABASE_1_ID)) .thenReturn(DATABASE_1); + when(restTemplate.exchange(anyString(), any(HttpMethod.class), any(HttpEntity.class), eq(QueryDto.class))) + .thenReturn(ResponseEntity.ok(QUERY_1_DTO)); + when(userService.findByUsername(USER_1_USERNAME)) + .thenReturn(USER_1); + when(identifierRepository.save(any(Identifier.class))) + .thenReturn(IDENTIFIER_1); + when(identifierIdxRepository.save(any(IdentifierDto.class))) + .thenReturn(IDENTIFIER_1_DTO); /* test */ - assertThrows(IdentifierPublishingNotAllowedException.class, () -> { - identifierService.create(IDENTIFIER_1_DTO_SELF_REQUEST, principal, bearer); - }); + identifierService.create(IDENTIFIER_1_DTO_REQUEST, principal, bearer); } @Test @@ -252,7 +251,7 @@ public class IdentifierServiceUnitTest extends BaseUnitTest { final String bearer = "Bearer abcxyz"; /* mock */ - when(databaseService.find(CONTAINER_2_ID, DATABASE_2_ID)) + when(databaseService.find(DATABASE_2_ID)) .thenReturn(DATABASE_2); when(identifierRepository.existsByDatabaseIdAndQueryIdAndType(DATABASE_2_ID, QUERY_2_ID, IdentifierType.SUBSET)) .thenReturn(true); @@ -271,7 +270,7 @@ public class IdentifierServiceUnitTest extends BaseUnitTest { final String bearer = "Bearer abcxyz"; /* mock */ - when(databaseService.find(CONTAINER_1_ID, DATABASE_1_ID)) + when(databaseService.find(DATABASE_1_ID)) .thenReturn(DATABASE_1); when(identifierRepository.existsByDatabaseIdAndType(DATABASE_1_ID, IdentifierType.DATABASE)) .thenReturn(true); @@ -284,7 +283,7 @@ public class IdentifierServiceUnitTest extends BaseUnitTest { } @Test - public void delete_succeeds() throws IdentifierNotFoundException { + public void delete_succeeds() throws IdentifierNotFoundException, NotAllowedException { /* mock */ when(identifierRepository.findById(IDENTIFIER_1_ID)) @@ -316,6 +315,22 @@ public class IdentifierServiceUnitTest extends BaseUnitTest { }); } + @Test + public void delete_withDoi_fails() { + + /* mock */ + when(identifierRepository.findById(IDENTIFIER_1_ID)) + .thenReturn(Optional.of(IDENTIFIER_1_WITH_DOI)); + doNothing() + .when(identifierRepository) + .delete(IDENTIFIER_1); + + /* test */ + assertThrows(NotAllowedException.class, () -> { + identifierService.delete(IDENTIFIER_1_ID); + }); + } + @Test public void exportMetadata_succeeds() throws IdentifierNotFoundException { @@ -354,30 +369,4 @@ public class IdentifierServiceUnitTest extends BaseUnitTest { }); } - @Test - public void publish_alreadyEveryone_fails() { - - /* mock */ - when(identifierRepository.findById(IDENTIFIER_1_ID)) - .thenReturn(Optional.of(IDENTIFIER_1)); - - /* test */ - assertThrows(IdentifierAlreadyPublishedException.class, () -> { - identifierService.publish(IDENTIFIER_1_ID, VisibilityTypeDto.SELF); - }); - } - - @Test - public void publish_alreadyEveryone2_fails() { - - /* mock */ - when(identifierRepository.findById(IDENTIFIER_1_ID)) - .thenReturn(Optional.of(IDENTIFIER_1)); - - /* test */ - assertThrows(IdentifierAlreadyPublishedException.class, () -> { - identifierService.publish(IDENTIFIER_1_ID, VisibilityTypeDto.TRUSTED); - }); - } - } diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_apa4.txt b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_apa4.txt new file mode 100644 index 0000000000000000000000000000000000000000..ce6a65da6b9e838043cf89acd5febd86ae3b6d08 --- /dev/null +++ b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_apa4.txt @@ -0,0 +1 @@ +M., Mustermann. (2022). Austrian weather data. Austrian Government. https://doi.org/10.1000/183 \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex0.txt b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex0.txt index b59c85b51e49426f8a22404fc0fd9456a301669c..0f797e3861818f4a17cc6487e97f6ce08d2efa48 100644 --- a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex0.txt +++ b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex0.txt @@ -1,7 +1,7 @@ @misc{dbrepo2022, author = {}, title = {Sweden weather data}, - howpublished = {\url{http://localhost:3000/pid/4}}, + url = {\url{http://localhost:3000/pid/4}}, month = {7}, year = {2022} } \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex1.txt b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex1.txt index 4feb1be0d63cb77464a6f9ea0ee7a710b8547913..bab1cdadb13192dbf2c16f9dbfebb9fcc8385a36 100644 --- a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex1.txt +++ b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex1.txt @@ -1,7 +1,7 @@ @misc{dbrepo2022, author = {Mustermann, Max}, title = {Austrian weather data}, - howpublished = {\url{http://localhost:3000/pid/1}}, + url = {\url{http://localhost:3000/pid/1}}, month = {5}, year = {2022} } \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex2.txt b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex2.txt index 0d7b5e3d7aa746d08084c85600f06e9fb4178ed0..9df96bed21348ede73192f16686e79aecc9c02dc 100644 --- a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex2.txt +++ b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex2.txt @@ -1,7 +1,7 @@ @misc{dbrepo2022, author = {Mustermann, Max and Mustermann, Martina}, title = {Australian weather data}, - howpublished = {\url{http://localhost:3000/pid/2}}, + url = {\url{http://localhost:3000/pid/2}}, month = {7}, year = {2022} } \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex3.txt b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex3.txt new file mode 100644 index 0000000000000000000000000000000000000000..44190f2752de38baf1aa1856981729e433a1a4af --- /dev/null +++ b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_bibtex3.txt @@ -0,0 +1,7 @@ +@misc{dbrepo2022, + author = {Mustermann, Max}, + title = {Austrian weather data}, + doi = {10.1000/183}, + month = {5}, + year = {2022} +} \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee1.txt b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee1.txt index c1376a5ba53376bdba9154900d367a2908a98ea9..ac28d6fdeea46ae4c57e39c4dd6166b26e49703e 100644 --- a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee1.txt +++ b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee1.txt @@ -1 +1 @@ -[1] M. Mustermann, “Austrian weather data“, Austrian Government, 2022, doi: http://localhost:3000/pid/1. \ No newline at end of file +[1] M. Mustermann, “Austrian weather data“, Austrian Government, 2022, Available: http://localhost:3000/pid/1. \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee3.txt b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee3.txt new file mode 100644 index 0000000000000000000000000000000000000000..2576174cf69acc6f7f545b8b6ccfd415d1efd083 --- /dev/null +++ b/dbrepo-identifier-service/rest-service/src/test/resources/bibliography/style_ieee3.txt @@ -0,0 +1 @@ +[1] M. Mustermann, “Austrian weather data“, Austrian Government, 2022, 10.1000/183. \ No newline at end of file diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/json/metadata0.json b/dbrepo-identifier-service/rest-service/src/test/resources/json/metadata0.json index c9546518e28cd55888740e8248bd5f433168d8c1..ab803627d4a39d33b65d777a480709d4d18cff9d 100644 --- a/dbrepo-identifier-service/rest-service/src/test/resources/json/metadata0.json +++ b/dbrepo-identifier-service/rest-service/src/test/resources/json/metadata0.json @@ -5,7 +5,7 @@ "type": "database", "title": "Sweden weather data", "description": "Selecting all from the weather Sweden table", - "doi": "10.1000/184", + "doi": null, "visibility": "everyone", "publisher": "Swedish Government", "publication_day": 14, diff --git a/dbrepo-identifier-service/rest-service/src/test/resources/json/metadata1.json b/dbrepo-identifier-service/rest-service/src/test/resources/json/metadata1.json index e0eb80bffa0082995c1cf33afb82d3233ad226d4..be2009147bae92bae99101194a405f5ad6d337e0 100644 --- a/dbrepo-identifier-service/rest-service/src/test/resources/json/metadata1.json +++ b/dbrepo-identifier-service/rest-service/src/test/resources/json/metadata1.json @@ -8,7 +8,7 @@ "description": "Selecting all from the weather Austrian table", "query": "SELECT `id` FROM `foobar`", "query_normalized": "SELECT `id` FROM `foobar`", - "doi": "10.1000/182", + "doi": null, "query_hash": "abc", "execution": "2018-11-07T10:59:12.000+00:00", "result_hash": "def", diff --git a/dbrepo-identifier-service/services/pom.xml b/dbrepo-identifier-service/services/pom.xml index ec39cc3db8ec95c7e4b2f5f2f89ef820f1f6763f..49d0779ee23409e3fab477b6ef2981eeec1b13b7 100644 --- a/dbrepo-identifier-service/services/pom.xml +++ b/dbrepo-identifier-service/services/pom.xml @@ -7,19 +7,19 @@ <dependency> <groupId>at.tuwien</groupId> <artifactId>api</artifactId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> <scope>compile</scope> </dependency> </dependencies> <parent> - <artifactId>fda-identifier-service</artifactId> + <artifactId>dbrepo-identifier-service</artifactId> <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </parent> <artifactId>services</artifactId> - <version>1.1.0-alpha</version> - <name>fda-identifier-service-services</name> + <version>1.2.0</version> + <name>dbrepo-identifier-service-services</name> <build> <plugins> diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/config/DataCiteConfig.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/config/DataCiteConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..ec84c3f4ff382ac41e0f7134217f527ebad87c81 --- /dev/null +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/config/DataCiteConfig.java @@ -0,0 +1,24 @@ +package at.tuwien.config; + +import lombok.Getter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +@Getter +@Profile("doi") +@Configuration +public class DataCiteConfig { + + @Value("${fda.datacite.url}") + private String url; + + @Value("${fda.datacite.prefix}") + private String prefix; + + @Value("${fda.datacite.username}") + private String username; + + @Value("${fda.datacite.password}") + private String password; +} diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/config/GatewayConfig.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/config/GatewayConfig.java index a6a8a2003ea62692634571d94edd5cc37f177d32..4dd0068634978d7fff069203febb24d69d02f845 100644 --- a/dbrepo-identifier-service/services/src/main/java/at/tuwien/config/GatewayConfig.java +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/config/GatewayConfig.java @@ -3,6 +3,7 @@ package at.tuwien.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.support.BasicAuthenticationInterceptor; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.DefaultUriBuilderFactory; @@ -12,6 +13,12 @@ public class GatewayConfig { @Value("${fda.gateway.endpoint}") private String gatewayEndpoint; + @Value("${spring.rabbitmq.username}") + private String brokerUsername; + + @Value("${spring.rabbitmq.password}") + private String brokerPassword; + @Bean public RestTemplate restTemplate() { final RestTemplate restTemplate = new RestTemplate(); @@ -19,4 +26,13 @@ public class GatewayConfig { return restTemplate; } + @Bean("brokerRestTemplate") + public RestTemplate brokerRestTemplate() { + final RestTemplate restTemplate = new RestTemplate(); + restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(gatewayEndpoint)); + restTemplate.getInterceptors() + .add(new BasicAuthenticationInterceptor(brokerUsername, brokerPassword)); + return restTemplate; + } + } diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/exception/RemoteUnavailableException.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/exception/RemoteUnavailableException.java index 3f6700d06b277d59ccbf812136faec277261357d..3e18ea33b547e4a47ab03594479a1cfce8bb8653 100644 --- a/dbrepo-identifier-service/services/src/main/java/at/tuwien/exception/RemoteUnavailableException.java +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/exception/RemoteUnavailableException.java @@ -3,7 +3,7 @@ package at.tuwien.exception; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; -@ResponseStatus(code = HttpStatus.NO_CONTENT) +@ResponseStatus(code = HttpStatus.BAD_GATEWAY) public class RemoteUnavailableException extends Exception { public RemoteUnavailableException(String msg) { diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/gateway/ApiTemplateInterceptor.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/gateway/ApiTemplateInterceptor.java new file mode 100644 index 0000000000000000000000000000000000000000..2ffd0f6a0f776699f47afe852574d7a0c08ba34c --- /dev/null +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/gateway/ApiTemplateInterceptor.java @@ -0,0 +1,7 @@ +package at.tuwien.gateway; + +import org.springframework.stereotype.Service; + +@Service +public interface ApiTemplateInterceptor { +} diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/utils/ApiTemplateInterceptor.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/gateway/impl/ApiTemplateInterceptorImpl.java similarity index 78% rename from dbrepo-identifier-service/services/src/main/java/at/tuwien/utils/ApiTemplateInterceptor.java rename to dbrepo-identifier-service/services/src/main/java/at/tuwien/gateway/impl/ApiTemplateInterceptorImpl.java index a8fdf392cdadb2b6b288599851ad1341993e88a7..27517359c2a3c25e3ee057b1890b82ac805ad863 100644 --- a/dbrepo-identifier-service/services/src/main/java/at/tuwien/utils/ApiTemplateInterceptor.java +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/gateway/impl/ApiTemplateInterceptorImpl.java @@ -1,5 +1,6 @@ -package at.tuwien.utils; +package at.tuwien.gateway.impl; +import at.tuwien.gateway.ApiTemplateInterceptor; import org.springframework.http.HttpRequest; import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.http.client.ClientHttpRequestInterceptor; @@ -9,7 +10,7 @@ import org.springframework.stereotype.Service; import java.io.IOException; @Service -public class ApiTemplateInterceptor implements ClientHttpRequestInterceptor { +public class ApiTemplateInterceptorImpl implements ApiTemplateInterceptor, ClientHttpRequestInterceptor { @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/mapper/DataCiteMapper.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/mapper/DataCiteMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..0766b8635b690098728f82d1068de071aaead35d --- /dev/null +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/mapper/DataCiteMapper.java @@ -0,0 +1,98 @@ +package at.tuwien.mapper; + +import at.tuwien.api.datacite.doi.*; +import at.tuwien.entities.database.License; +import at.tuwien.entities.identifier.Creator; +import at.tuwien.entities.identifier.Identifier; +import at.tuwien.entities.identifier.RelatedIdentifier; +import at.tuwien.utils.EnumToStringConverter; +import org.mapstruct.*; +import org.springframework.context.annotation.Profile; + +import java.util.List; + +@Profile("doi") +@Mapper(componentModel = "spring", uses = EnumToStringConverter.class) +public interface DataCiteMapper { + + default <T> List<T> list(T t) { + if (t == null) return null; + return List.of(t); + } + + @Mappings({ + @Mapping(target = "titles", source = "."), + @Mapping(target = "publisher", source = "publisher"), + @Mapping(target = "publicationYear", source = "publicationYear"), + @Mapping(target = "publicationMonth", source = "publicationMonth"), + @Mapping(target = "publicationDay", source = "publicationDay"), + @Mapping(target = "language", source = "language"), + @Mapping(target = "rightsList", + expression = "java(list(licenseToDoiRights(identifier.getLicense())))"), + @Mapping(target = "creators", source = "creators"), + @Mapping(target = "relatedIdentifiers", source = "related"), + }) + DataCiteCreateDoi identifierToDataCiteCreateDoi(Identifier identifier); + + default DataCiteCreateDoi identifierToDataCiteCreateDoi(Identifier identifier, String url, String prefix) { + return addParametersToCreateDoi( + identifierToDataCiteCreateDoi(identifier), + url, + prefix, + DataCiteDoiTypes.DATASET, + DataCiteDoiEvent.PUBLISH + ); + } + + DataCiteCreateDoi addParametersToCreateDoi(@MappingTarget DataCiteCreateDoi target, + String url, + String prefix, + DataCiteDoiTypes types, + DataCiteDoiEvent event); + + default List<DataCiteDoiTitle> identifierToDoiTitles(Identifier identifier) { + return List.of( + DataCiteDoiTitle.builder().title(identifier.getTitle()).build(), + DataCiteDoiTitle.builder() + .title(identifier.getDescription()) + .titleType(DataCiteDoiTitle.Type.SUBTITLE) + .build() + ); + } + + @Mappings({ + @Mapping(target = "rights", source = "identifier"), + @Mapping(target = "rightsUri", source = "uri"), + }) + DataCiteDoiRights licenseToDoiRights(License license); + + @Mappings({ + @Mapping(target = "name", expression = "java(license.getLastname() + \", \" + license.getFirstname())"), + @Mapping(target = "givenName", source = "firstname"), + @Mapping(target = "familyName", source = "lastname"), + @Mapping(target = "affiliation", + expression = "java(list(affiliationStringToDoiCreatorAffiliation(license.getAffiliation())))"), + @Mapping(target = "nameIdentifiers", + expression = "java(list(orcidStringToDoiCreatorNameIdentifier(license.getOrcid())))"), + }) + DataCiteDoiCreator creatorToDoiCreator(Creator license); + + @Mappings({ + @Mapping(target = "name", constant = "affiliation"), + }) + DataCiteDoiCreatorAffiliation affiliationStringToDoiCreatorAffiliation(String affiliation); + + @Mappings({ + @Mapping(target = "schemeUri", constant = "https://orcid.org"), + @Mapping(target = "nameIdentifier", expression = "java(\"https://orcid.org/\" + orcid)"), + @Mapping(target = "nameIdentifierScheme", constant = "ORCID"), + }) + DataCiteDoiCreatorNameIdentifier orcidStringToDoiCreatorNameIdentifier(String orcid); + + @Mappings({ + @Mapping(target = "relatedIdentifier", source = "value"), + @Mapping(target = "relatedIdentifierType", source = "type"), + @Mapping(target = "relationType", source = "relation"), + }) + DataCiteDoiRelatedIdentifier relatedIdentifierToDoiRelatedIdentifier(RelatedIdentifier relatedIdentifier); +} diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/mapper/IdentifierMapper.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/mapper/IdentifierMapper.java index 4c6dd57ac46ee6af851a7ed561db89c3c1b320ad..08fa62a8ec066cf57a1304a13e70e12ae27b9f68 100644 --- a/dbrepo-identifier-service/services/src/main/java/at/tuwien/mapper/IdentifierMapper.java +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/mapper/IdentifierMapper.java @@ -1,8 +1,10 @@ package at.tuwien.mapper; import at.tuwien.api.identifier.*; -import at.tuwien.entities.database.Database; -import at.tuwien.entities.identifier.*; +import at.tuwien.entities.identifier.Creator; +import at.tuwien.entities.identifier.Identifier; +import at.tuwien.entities.identifier.IdentifierType; +import at.tuwien.entities.identifier.RelatedIdentifier; import org.mapstruct.Mapper; import org.springframework.transaction.annotation.Transactional; @@ -31,9 +33,6 @@ public interface IdentifierMapper { @Transactional RelatedIdentifier relatedIdentifierCreateDtoToRelatedIdentifier(RelatedIdentifierCreateDto data); - @Transactional - VisibilityType visibilityTypeDtoToVisibilityType(VisibilityTypeDto data); - IdentifierType identifierTypeDtoToIdentifierType(IdentifierTypeDto data); default String identifierToLocationUrl(String baseUrl, Identifier data) { @@ -46,11 +45,4 @@ public interface IdentifierMapper { } } - default VisibilityType databaseToVisibilityType(Database data) { - if (data.getIsPublic()) { - return VisibilityType.EVERYONE; - } - return VisibilityType.SELF; - } - } diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/DatabaseService.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/DatabaseService.java index 2e27dc0b4024fe4d03687eb77bde0df89dc3c374..1d081f4441ee1e3684c00a23815143c4986b93bf 100644 --- a/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/DatabaseService.java +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/DatabaseService.java @@ -8,10 +8,9 @@ public interface DatabaseService { /** * Finds a database by given id in the remote database service. * - * @param containerId The container id. * @param databaseId The database id. * @return The database. * @throws DatabaseNotFoundException The database was not found. */ - Database find(Long containerId, Long databaseId) throws DatabaseNotFoundException; + Database find(Long databaseId) throws DatabaseNotFoundException; } diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/IdentifierService.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/IdentifierService.java index 8100a52e5237b41dc61e857000d38b460fff7df2..95071320600402cf97b75013593a429c237489a7 100644 --- a/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/IdentifierService.java +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/IdentifierService.java @@ -1,12 +1,12 @@ package at.tuwien.service; -import at.tuwien.api.identifier.*; -import at.tuwien.ExportResource; +import at.tuwien.api.identifier.BibliographyTypeDto; +import at.tuwien.api.identifier.IdentifierCreateDto; +import at.tuwien.api.identifier.IdentifierDto; import at.tuwien.entities.identifier.Identifier; import at.tuwien.exception.*; import org.springframework.core.io.InputStreamResource; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import java.security.Principal; import java.util.List; @@ -15,11 +15,12 @@ import java.util.List; public interface IdentifierService { /** - * Finds all identifiers in the metadata database which are not deleted. + * Finds all identifiers in the metadata database which are not deleted. Optionally, the result can be filtered by database id and/or query id. * - * @param queryId Optional. The query id. * @param databaseId Optional. The database id. + * @param queryId Optional. The query id. * @return List of identifiers + * @throws IdentifierNotFoundException The identifier with this filter conditions could not be found in the metadata database. */ List<Identifier> findAll(Long databaseId, Long queryId) throws IdentifierNotFoundException; @@ -41,23 +42,29 @@ public interface IdentifierService { List<Identifier> findAll(); /** - * Creates a new identifier in the metadata database which is not yet published + * Creates a new identifier in the metadata database for a query or database. * * @param data The identifier. * @param principal The authorization principal. * @param authorization The authorization bearer. * @return The created identifier from the metadata database if successful. + * @throws IdentifierPublishingNotAllowedException The identifier with this visibility could not be created. + * @throws QueryNotFoundException The query with this id (in the data) could not be created. + * @throws RemoteUnavailableException The connection to the Query Store could not be established by the database connector. + * @throws IdentifierAlreadyExistsException The identifier for this query/database already exists. + * @throws UserNotFoundException The user was not found in the metadata database. + * @throws DatabaseNotFoundException The database was not found in the metadata database. */ Identifier create(IdentifierCreateDto data, Principal principal, String authorization) throws IdentifierPublishingNotAllowedException, QueryNotFoundException, RemoteUnavailableException, IdentifierAlreadyExistsException, UserNotFoundException, - DatabaseNotFoundException; + DatabaseNotFoundException, IdentifierRequestException; /** * Finds an identifier by given id in the metadata database. * * @param identifierId The identifier id. - * @return The found identifier from the metadata database if successful. + * @return The identifier, if successful. * @throws IdentifierNotFoundException The identifier was not found in the metadata database or was deleted. */ Identifier find(Long identifierId) throws IdentifierNotFoundException; @@ -75,7 +82,7 @@ public interface IdentifierService { * Export metadata for bibliography for a identifier. * * @param id The identifier id. - * @param style The identifier bibliography style. + * @param style The identifier bibliography style. Optional. Default: APA. * @return The export, if successful. * @throws IdentifierNotFoundException The identifier was not found in the metadata database or was deleted. * @throws IdentifierRequestException The identifier style was not found. @@ -89,7 +96,8 @@ public interface IdentifierService { * @return The XML resource, if successful. * @throws IdentifierNotFoundException The identifier was not found in the metadata database or was deleted. * @throws QueryNotFoundException The query was not found in the metadata database or was deleted. - * @throws RemoteUnavailableException The remote service is not available + * @throws RemoteUnavailableException The connection to the Query Store could not be established by the database connector. + * @throws IdentifierRequestException The identifier does not allow for exporting. */ InputStreamResource exportResource(Long identifierId) throws IdentifierNotFoundException, QueryNotFoundException, RemoteUnavailableException, IdentifierRequestException; @@ -101,29 +109,15 @@ public interface IdentifierService { * @param data The metadata. * @return The updated identifier if successful. * @throws IdentifierNotFoundException TThe identifier was not found in the metadata database or was deleted. - * @throws IdentifierPublishingNotAllowedException The identifier contained a visibility change which is not allowed here. - */ - Identifier update(Long identifierId, IdentifierDto data) throws IdentifierNotFoundException, - IdentifierPublishingNotAllowedException; - - /** - * Publishes the identifier for a given identifier id in the metadata database. - * - * @param identifierId The identifier id. - * @param visibility The new visibility. - * @return The updated identifier from the metadata database. - * @throws IdentifierNotFoundException The identifier was not found in the metadata database or was deleted. - * @throws IdentifierAlreadyPublishedException The identifier is already published (=EVERYONE) and cannot be un-published. */ - Identifier publish(Long identifierId, VisibilityTypeDto visibility) - throws IdentifierNotFoundException, - IdentifierAlreadyPublishedException; + Identifier update(Long identifierId, IdentifierDto data) throws IdentifierNotFoundException, IdentifierRequestException; /** * Soft-deletes an identifier for a given id in the metadata database. Does not actually remove the entity from the database, but sets it as deleted. * * @param identifierId The identifier id. * @throws IdentifierNotFoundException The identifier was not found in the metadata database or was deleted. + * @throws NotAllowedException Identifiers with a valid DOI cannot be deleted. */ - void delete(Long identifierId) throws IdentifierNotFoundException; + void delete(Long identifierId) throws IdentifierNotFoundException, NotAllowedException; } diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/DataCiteIdentifierServiceImpl.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/DataCiteIdentifierServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..8b32eaba0f29c4973e1e21bd723de89054af6efd --- /dev/null +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/DataCiteIdentifierServiceImpl.java @@ -0,0 +1,204 @@ +package at.tuwien.service.impl; + +import at.tuwien.api.datacite.DataCiteBody; +import at.tuwien.api.datacite.DataCiteData; +import at.tuwien.api.datacite.doi.DataCiteCreateDoi; +import at.tuwien.api.datacite.doi.DataCiteDoi; +import at.tuwien.api.identifier.BibliographyTypeDto; +import at.tuwien.api.identifier.IdentifierCreateDto; +import at.tuwien.api.identifier.IdentifierDto; +import at.tuwien.config.DataCiteConfig; +import at.tuwien.config.EndpointConfig; +import at.tuwien.entities.identifier.Identifier; +import at.tuwien.exception.*; +import at.tuwien.mapper.DataCiteMapper; +import at.tuwien.repository.jpa.IdentifierRepository; +import at.tuwien.service.IdentifierService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.core.io.InputStreamResource; +import org.springframework.http.*; +import org.springframework.stereotype.Service; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.DefaultUriBuilderFactory; + +import javax.transaction.Transactional; +import java.security.Principal; +import java.util.List; + +@Slf4j +@Primary +@Profile("doi") +@Service +public class DataCiteIdentifierServiceImpl implements IdentifierService { + + private final DataCiteConfig dataCiteConfig; + private final EndpointConfig endpointConfig; + private final DataCiteMapper dataCiteMapper; + private final RestTemplateBuilder restTemplateBuilder; + private final IdentifierRepository identifierRepository; + private final IdentifierService identifierService; + + public DataCiteIdentifierServiceImpl(DataCiteConfig dataCiteConfig, DataCiteMapper dataCiteMapper, + RestTemplateBuilder restTemplateBuilder, EndpointConfig endpointConfig, + IdentifierRepository identifierRepository, IdentifierServiceImpl identifierService) { + this.dataCiteConfig = dataCiteConfig; + this.dataCiteMapper = dataCiteMapper; + this.restTemplateBuilder = + restTemplateBuilder.basicAuthentication(dataCiteConfig.getUsername(), dataCiteConfig.getPassword()) + .uriTemplateHandler(new DefaultUriBuilderFactory(dataCiteConfig.getUrl())); + this.endpointConfig = endpointConfig; + this.identifierRepository = identifierRepository; + this.identifierService = identifierService; + } + + @Override + public List<Identifier> findAll(Long databaseId, Long queryId) throws IdentifierNotFoundException { + return identifierService.findAll(databaseId, queryId); + } + + @Override + public Identifier find(Long databaseId, Long queryId) throws IdentifierNotFoundException { + return identifierService.find(databaseId, queryId); + } + + @Override + public List<Identifier> findAll() { + return identifierService.findAll(); + } + + @Override + @Transactional(rollbackOn = {Exception.class}) + public Identifier create(IdentifierCreateDto data, Principal principal, String authorization) + throws IdentifierPublishingNotAllowedException, QueryNotFoundException, RemoteUnavailableException, + IdentifierAlreadyExistsException, UserNotFoundException, DatabaseNotFoundException, + IdentifierRequestException { + Identifier identifier = identifierService.create(data, principal, authorization); + RestTemplate restTemplate = restTemplateBuilder.build(); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.setBasicAuth(dataCiteConfig.getUsername(), dataCiteConfig.getPassword()); + HttpEntity<DataCiteBody<DataCiteCreateDoi>> request = new HttpEntity<>( + DataCiteBody.<DataCiteCreateDoi>builder() + .data(DataCiteData.<DataCiteCreateDoi>builder() + .type("dois") + .attributes(dataCiteMapper.identifierToDataCiteCreateDoi(identifier, + endpointConfig.getWebsiteUrl() + "/pid/" + identifier.getId(), + dataCiteConfig.getPrefix())) + .build()) + .build(), + headers + ); + + try { + ResponseEntity<DataCiteBody<DataCiteDoi>> response = restTemplate.exchange("dois", HttpMethod.POST, + request, + new ParameterizedTypeReference<>() { + } + ); + + if(response.getStatusCode() != HttpStatus.CREATED || response.getBody() == null) { + log.error("Could not successfully create DOI. Response: {}", response); + throw new IdentifierRequestException("Could not successfully create DOI."); + } + + identifier.setDoi(response.getBody().getData().getAttributes().getDoi()); + this.identifierRepository.save(identifier); + } catch(HttpClientErrorException e) { + log.error("Invalid DOI metadata.", e); + throw new IdentifierRequestException("Invalid DOI metadata.", e); + } catch(RestClientException e) { + log.error("Could not fulfil request to DataCite server.", e); + throw new InternalError("Could not fulfil request to DataCite server.", e); + } + + return identifier; + } + + @Override + public Identifier find(Long identifierId) throws IdentifierNotFoundException { + return identifierService.find(identifierId); + } + + @Override + public InputStreamResource exportMetadata(Long id) throws IdentifierNotFoundException { + return identifierService.exportMetadata(id); + } + + @Override + public String exportBibliography(Long id, BibliographyTypeDto style) + throws IdentifierNotFoundException, IdentifierRequestException { + return identifierService.exportBibliography(id, style); + } + + @Override + public InputStreamResource exportResource(Long identifierId) + throws IdentifierNotFoundException, QueryNotFoundException, RemoteUnavailableException, + IdentifierRequestException { + return identifierService.exportResource(identifierId); + } + + @Override + @Transactional(rollbackOn = {Exception.class}) + public Identifier update(Long identifierId, IdentifierDto data) + throws IdentifierNotFoundException, IdentifierRequestException { + Identifier identifier = identifierService.update(identifierId, data); + if(identifier.getDoi() == null) { + return identifier; + } + + RestTemplate restTemplate = restTemplateBuilder.build(); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.setBasicAuth(dataCiteConfig.getUsername(), dataCiteConfig.getPassword()); + HttpEntity<DataCiteBody<DataCiteCreateDoi>> request = new HttpEntity<>( + DataCiteBody.<DataCiteCreateDoi>builder() + .data(DataCiteData.<DataCiteCreateDoi>builder() + .type("dois") + .attributes(dataCiteMapper.identifierToDataCiteCreateDoi(identifier, + endpointConfig.getWebsiteUrl() + "/pid/" + identifier.getId(), + dataCiteConfig.getPrefix())) + .build()) + .build(), + headers + ); + + try { + ResponseEntity<DataCiteBody<DataCiteDoi>> response = restTemplate.exchange("dois/{doi}", HttpMethod.PUT, + request, + new ParameterizedTypeReference<>() { + }, + identifier.getDoi() + ); + + if(response.getStatusCode() != HttpStatus.OK || response.getBody() == null) { + log.error("Could not successfully create DOI. Response: {}", response); + throw new IdentifierRequestException("Could not successfully create DOI."); + } + + identifier.setDoi(response.getBody().getData().getAttributes().getDoi()); + this.identifierRepository.save(identifier); + } catch(HttpClientErrorException e) { + log.error("Invalid DOI metadata.", e); + throw new IdentifierRequestException("Invalid DOI metadata.", e); + } catch(RestClientException e) { + log.error("Could not fulfil request to DataCite server.", e); + throw new InternalError("Could not fulfil request to DataCite server.", e); + } + + return identifier; + } + + @Override + public void delete(Long identifierId) throws IdentifierNotFoundException, NotAllowedException { + identifierService.delete(identifierId); + } + +} diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/DatabaseServiceImpl.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/DatabaseServiceImpl.java index 4b2a5e2336a9d99330dd5dc3a65034c830ea7223..c79c1bca0271d880cc25492d96ee41cb3dc15905 100644 --- a/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/DatabaseServiceImpl.java +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/DatabaseServiceImpl.java @@ -22,8 +22,8 @@ public class DatabaseServiceImpl implements DatabaseService { } @Override - public Database find(Long containerId, Long databaseId) throws DatabaseNotFoundException { - final Optional<Database> database = databaseRepository.findByContainerAndDatabaseId(containerId, databaseId); + public Database find(Long databaseId) throws DatabaseNotFoundException { + final Optional<Database> database = databaseRepository.findById(databaseId); if (database.isEmpty()) { log.error("Failed to find database"); throw new DatabaseNotFoundException("Failed to find database"); diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java index b731f80e15f773c820f71ee33f5b833881a8e054..f33ff8911b976e33338e6af8f6f8428c00fb1084 100644 --- a/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/service/impl/IdentifierServiceImpl.java @@ -4,7 +4,10 @@ import at.tuwien.api.database.query.QueryDto; import at.tuwien.api.identifier.*; import at.tuwien.config.EndpointConfig; import at.tuwien.entities.database.Database; -import at.tuwien.entities.identifier.*; +import at.tuwien.entities.identifier.Creator; +import at.tuwien.entities.identifier.Identifier; +import at.tuwien.entities.identifier.IdentifierType; +import at.tuwien.entities.identifier.RelatedIdentifier; import at.tuwien.entities.user.User; import at.tuwien.exception.*; import at.tuwien.gateway.QueryServiceGateway; @@ -17,6 +20,7 @@ import at.tuwien.service.IdentifierService; import at.tuwien.service.UserService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; +import org.springframework.context.annotation.Profile; import org.springframework.core.io.InputStreamResource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -96,13 +100,10 @@ public class IdentifierServiceImpl implements IdentifierService { @Transactional public Identifier create(IdentifierCreateDto data, Principal principal, String authorization) throws QueryNotFoundException, RemoteUnavailableException, IdentifierAlreadyExistsException, - UserNotFoundException, DatabaseNotFoundException, IdentifierPublishingNotAllowedException { + UserNotFoundException, DatabaseNotFoundException, IdentifierPublishingNotAllowedException, + IdentifierRequestException { /* check */ - final Database database = databaseService.find(data.getCid(), data.getDbid()); - if (database.getIsPublic() && !data.getVisibility().equals(VisibilityTypeDto.EVERYONE)) { - log.error("Identifier cannot restrict the result set"); - throw new IdentifierPublishingNotAllowedException("Identifier cannot restrict the result set"); - } + final Database database = databaseService.find(data.getDbid()); if (data.getType().equals(IdentifierTypeDto.DATABASE) && identifierRepository.existsByDatabaseIdAndType(data.getDbid(), IdentifierType.DATABASE)) { log.error("Identifier already issued for database with id {}", data.getDbid()); throw new IdentifierAlreadyExistsException("Database identifier already exists"); @@ -120,7 +121,6 @@ public class IdentifierServiceImpl implements IdentifierService { if (data.getType().equals(IdentifierTypeDto.SUBSET)) { log.debug("identifier describes a subset"); final QueryDto query = queryServiceGateway.find(data.getCid(), data.getDbid(), data, authorization); - tmp.setVisibility(identifierMapper.visibilityTypeDtoToVisibilityType(data.getVisibility())); tmp.setQuery(query.getQuery()); tmp.setQueryId(query.getId()); tmp.setQueryNormalized(query.getQueryNormalized()); @@ -128,9 +128,6 @@ public class IdentifierServiceImpl implements IdentifierService { tmp.setExecution(query.getExecution()); tmp.setResultNumber(query.getResultNumber()); tmp.setResultHash(query.getResultHash()); - } else if (data.getType().equals(IdentifierTypeDto.DATABASE)) { - log.debug("identifier describes a database"); - tmp.setVisibility(identifierMapper.databaseToVisibilityType(database)); } /* create in metadata database */ final Identifier entity = identifierRepository.save(tmp); @@ -181,7 +178,13 @@ public class IdentifierServiceImpl implements IdentifierService { final Identifier identifier = find(id); /* context */ final Context context = new Context(); - context.setVariable("doi", endpointConfig.getWebsiteUrl() + "/pid/" + identifier.getId()); + if(identifier.getDoi() != null) { + context.setVariable("identifierType", "DOI"); + context.setVariable("identifier", identifier.getDoi()); + } else { + context.setVariable("identifierType", "PID"); + context.setVariable("identifier", endpointConfig.getWebsiteUrl() + "/pid/" + identifier.getId()); + } context.setVariable("creators", identifier.getCreators()); context.setVariable("title", identifier.getTitle()); context.setVariable("publisher", identifier.getPublisher()); @@ -205,7 +208,13 @@ public class IdentifierServiceImpl implements IdentifierService { final Identifier identifier = find(id); /* context */ final Context context = new Context(); - context.setVariable("doi", endpointConfig.getWebsiteUrl() + "/pid/" + identifier.getId()); + if(identifier.getDoi() != null) { + context.setVariable("identifierType", "doi"); + context.setVariable("identifier", identifier.getDoi()); + } else { + context.setVariable("identifierType", "url"); + context.setVariable("identifier", endpointConfig.getWebsiteUrl() + "/pid/" + identifier.getId()); + } context.setVariable("creator", identifier.getCreator()); context.setVariable("creators", identifier.getCreators()); context.setVariable("title", identifier.getTitle()); @@ -245,9 +254,15 @@ public class IdentifierServiceImpl implements IdentifierService { @Override @Transactional public Identifier update(Long identifierId, IdentifierDto data) - throws IdentifierNotFoundException { + throws IdentifierNotFoundException, IdentifierRequestException { /* check */ - find(identifierId); + Identifier old = find(identifierId); + if(data.getVisibility() != VisibilityTypeDto.EVERYONE) { + throw new IdentifierRequestException("Cannot set visibility to other value than \"EVERYONE\"."); + } + if(data.getDoi() != null && !data.getDoi().equals(old.getDoi())) { + throw new IdentifierRequestException("The DOI of an identifier cannot be changed."); + } /* map */ final Identifier entity = identifierMapper.identifierDtoToIdentifier(data); entity.getCreators() @@ -264,29 +279,12 @@ public class IdentifierServiceImpl implements IdentifierService { @Override @Transactional - public Identifier publish(Long identifierId, VisibilityTypeDto visibility) - throws IdentifierNotFoundException, IdentifierAlreadyPublishedException { - final Identifier identifier = find(identifierId); - if (identifier.getVisibility().equals(VisibilityType.EVERYONE)) { - /* once published, the identifier cannot be reverted, it is persistent! */ - log.error("Identifier with id {} is already published for everyone", identifier.getId()); - throw new IdentifierAlreadyPublishedException("Identifier with id " + identifier.getId() + " is already published for everyone"); - } - identifier.setVisibility(identifierMapper.visibilityTypeDtoToVisibilityType(visibility)); - final Identifier entity = identifierRepository.save(identifier); - log.info("Published identifier with id {}", identifierId); - log.trace("published identifier {}", entity); - /* elastic search */ - identifierIdxRepository.save(identifierMapper.identifierToIdentifierDto(entity)); - log.info("Published identifier with id {} in elastic search", identifierId); - return entity; - } - - @Override - @Transactional - public void delete(Long identifierId) throws IdentifierNotFoundException { + public void delete(Long identifierId) throws IdentifierNotFoundException, NotAllowedException { /* check */ final Identifier identifier = find(identifierId); + if(identifier.getDoi() != null) { + throw new NotAllowedException("Identifiers with a DOI cannot be deleted."); + } /* delete */ identifierRepository.delete(identifier); log.info("Deleted identifier with id {}", identifierId); diff --git a/dbrepo-identifier-service/services/src/main/java/at/tuwien/utils/EnumToStringConverter.java b/dbrepo-identifier-service/services/src/main/java/at/tuwien/utils/EnumToStringConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..2e53ae6cdc17dcf9b915bc9aef3793701cba98e8 --- /dev/null +++ b/dbrepo-identifier-service/services/src/main/java/at/tuwien/utils/EnumToStringConverter.java @@ -0,0 +1,15 @@ +package at.tuwien.utils; + +import org.mapstruct.TargetType; + +public class EnumToStringConverter { + + public static String convert(Enum<?> source) { + return source == null ? null : source.toString(); + } + + public static <E extends Enum<E>> E convert(String source, @TargetType Class<E> enumType) { + // You probably need something else here as the methods are not symmetrical + return source == null ? null : Enum.valueOf( enumType, source ); + } +} diff --git a/dbrepo-metadata-db/Dockerfile b/dbrepo-metadata-db/Dockerfile index aa268acd8548df9d848a82e2851cd4347888fa8a..6dccde6ac2e0228600600aeb8431a16d51f93fc3 100644 --- a/dbrepo-metadata-db/Dockerfile +++ b/dbrepo-metadata-db/Dockerfile @@ -9,8 +9,9 @@ RUN mvn -fn -B dependency:go-offline > /dev/null COPY ./api ./api COPY ./entities ./entities -COPY ./querystore ./querystore COPY ./oai ./oai +COPY ./querystore ./querystore +COPY ./test ./test # Make sure it compiles RUN mvn -q clean package -DskipTests > /dev/null diff --git a/dbrepo-metadata-db/api/pom.xml b/dbrepo-metadata-db/api/pom.xml index 2d5d81c43e9ba311c418a24d141108973fdebbd7..62b1552f746369c85423d0427ae1af6bfd03f67c 100644 --- a/dbrepo-metadata-db/api/pom.xml +++ b/dbrepo-metadata-db/api/pom.xml @@ -5,13 +5,13 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db</artifactId> - <version>1.1.0-alpha</version> + <artifactId>dbrepo-metadata-db</artifactId> + <version>1.2.0</version> </parent> - <artifactId>fda-metadata-db-api</artifactId> - <version>1.1.0-alpha</version> - <name>fda-metadata-db-api</name> + <artifactId>dbrepo-metadata-db-api</artifactId> + <version>1.2.0</version> + <name>dbrepo-metadata-db-api</name> <dependencies/> diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/auth/JwtResponseDto.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/auth/JwtResponseDto.java new file mode 100644 index 0000000000000000000000000000000000000000..c92b4913c8d02e5f44677bd7d18cfdb0362081be --- /dev/null +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/auth/JwtResponseDto.java @@ -0,0 +1,33 @@ +package at.tuwien.api.auth; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import javax.validation.constraints.NotNull; +import java.util.List; + +@Getter +@Setter +@ToString +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class JwtResponseDto { + + @NotNull + @ToString.Exclude + private String token; + + private String type; + + private Long id; + + @Schema(example = "user") + private String username; + + @Schema(example = "user@example.com") + private String email; + + private List<String> roles; + +} diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/auth/TokenBriefDto.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/auth/TokenBriefDto.java new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/auth/TokenDto.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/auth/TokenDto.java index 1ef8ec88f2f3df71a47d4b74b87513537c818582..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/auth/TokenDto.java +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/auth/TokenDto.java @@ -1,60 +0,0 @@ -package at.tuwien.api.auth; - -import com.fasterxml.jackson.annotation.JsonProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; - -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; - -@Getter -@Setter -@ToString -@Builder -@AllArgsConstructor -@NoArgsConstructor -public class TokenDto { - - @NotBlank - @ToString.Exclude - @JsonProperty("access_token") - @Schema(example = "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJBbFdvalRsa1dBSVVoYTJLWjFvOEluWEtNbVAzUTg0STZiMFFHYkR6aEpvIn0.eyJleHAiOjE2ODAyNjgyNjgsImlhdCI6MTY4MDI2ODIwOCwianRpIjoiNjkwNjRlNTQtODNhNS00NGYxLWE3OTItNWFjOWU4OTA5YTlkIiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwL3JlYWxtcy9tYXN0ZXIiLCJzdWIiOiI4MjQ2OWMyMS0yYjNjLTRmMDctODg1Yi1hMzViMGQ5YTJhNjYiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJhZG1pbi1jbGkiLCJzZXNzaW9uX3N0YXRlIjoiNDQ1ODA3ZWUtMjg3Ni00NjFkLWE4ZjMtNGQyN2IzMGMyMWZhIiwiYWNyIjoiMSIsInNjb3BlIjoicHJvZmlsZSBlbWFpbCIsInNpZCI6IjQ0NTgwN2VlLTI4NzYtNDYxZC1hOGYzLTRkMjdiMzBjMjFmYSIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwicHJlZmVycmVkX3VzZXJuYW1lIjoiZmRhIn0.IOQxqWvlPDV9WuFOeLVG-ayexbK8OqylPABghEMSbMpmNlQhSAjbjaMY31uU-uADZRHB-mC8bmRS5PoWNtanuhz0lORDCeissFsbv0UL9Q42CaxG75vFAAD5WsdIHIr-dtEjEiXYtu-qwdg83griAUeO119TTdgldyPxo4jWzNw0ui6W7r4LqP4fSk31iJfxR5urgs5k6Ctzg-fXCORT31-nKz_YJQwLoPO9j4afX_1mnCXY5qFGMSrmPKzB0CArZfUpa_4nqt4Y768yOC3gigAyCjXtvXKkgCmARPSRjERGDdTb6SGbAwRDiVHVy9wy7XZwOcCFMEra9H7mV0Mx2A") - private String accessToken; - - @NotBlank - @ToString.Exclude - @JsonProperty("refresh_token") - @Schema(example = "eyJhbGciOiJIUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICI4YTczZGYwZS03NzMwLTRiZDEtOGVhOC1mZTdjZWViNmMxYWMifQ.eyJleHAiOjE2ODAyNzAwMDgsImlhdCI6MTY4MDI2ODIwOCwianRpIjoiNWYyNDIwNDItNmJmZi00ZTQ2LTg2NTAtNDBhY2E3YjVkZjMyIiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwL3JlYWxtcy9tYXN0ZXIiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjgwODAvcmVhbG1zL21hc3RlciIsInN1YiI6IjgyNDY5YzIxLTJiM2MtNGYwNy04ODViLWEzNWIwZDlhMmE2NiIsInR5cCI6IlJlZnJlc2giLCJhenAiOiJhZG1pbi1jbGkiLCJzZXNzaW9uX3N0YXRlIjoiNDQ1ODA3ZWUtMjg3Ni00NjFkLWE4ZjMtNGQyN2IzMGMyMWZhIiwic2NvcGUiOiJwcm9maWxlIGVtYWlsIiwic2lkIjoiNDQ1ODA3ZWUtMjg3Ni00NjFkLWE4ZjMtNGQyN2IzMGMyMWZhIn0.-GltWGkIaKUJ4AqRYnGHblTr0ygZm2CsRQB6zz5ePm4") - private String refreshToken; - - @NotBlank - @JsonProperty("token_type") - @Schema(example = "Bearer") - private String tokenType; - - @NotNull - @JsonProperty("expires_in") - @Schema(example = "60") - private Long expiresIn; - - @NotNull - @JsonProperty("session_state") - @Schema(example = "445807ee-2876-461d-a8f3-4d27b30c21fa") - private String sessionState; - - @NotNull - @JsonProperty("scope") - @Schema(example = "profile email") - private String scope; - - @NotNull - @JsonProperty("refresh_expires_in") - @Schema(example = "1800") - private Long refreshExpiresIn; - - @NotNull - @JsonProperty("not-before-policy") - @Schema(example = "0") - private Long notBeforePolicy; - -} diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/database/DatabaseBriefDto.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/database/DatabaseBriefDto.java index b6c1807edc884159e457750f61976cdfeea5cb73..f227746ba793be6ab19e1b8f37667990cf231bee 100644 --- a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/database/DatabaseBriefDto.java +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/database/DatabaseBriefDto.java @@ -47,6 +47,8 @@ public class DatabaseBriefDto { @org.springframework.data.annotation.Transient private ContainerBriefDto container; + private UserBriefDto creator; + @Schema(example = "2020-08-04 11:12:00") @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", timezone = "UTC") private Instant created; diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/database/table/TableDto.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/database/table/TableDto.java index b7bfc2c84d14b187e08e03b164b540a1c0b93415..22475b247b929aa6b884a46802d675bf708626a5 100644 --- a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/database/table/TableDto.java +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/database/table/TableDto.java @@ -1,6 +1,7 @@ package at.tuwien.api.database.table; import at.tuwien.api.database.table.columns.ColumnDto; +import at.tuwien.api.database.table.constraints.ConstraintsDto; import at.tuwien.api.user.UserBriefDto; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -70,4 +71,6 @@ public class TableDto { @org.springframework.data.annotation.Transient private List<ColumnDto> columns; + private ConstraintsDto constraints; + } diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/database/table/constraints/ConstraintsDto.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/database/table/constraints/ConstraintsDto.java new file mode 100644 index 0000000000000000000000000000000000000000..bc63fd70a0793fa8c0793cf7ecc550e43f05b92c --- /dev/null +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/database/table/constraints/ConstraintsDto.java @@ -0,0 +1,24 @@ +package at.tuwien.api.database.table.constraints; + +import at.tuwien.api.database.table.columns.ColumnDto; +import at.tuwien.api.database.table.constraints.foreignKey.ForeignKeyDto; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +import java.util.List; + +@Getter +@Setter +@ToString +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class ConstraintsDto { + + List<List<ColumnDto>> uniques; + + @JsonProperty("foreign_keys") + List<ForeignKeyDto> foreignKeys; + + List<String> checks; +} diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/database/table/constraints/foreignKey/ForeignKeyDto.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/database/table/constraints/foreignKey/ForeignKeyDto.java new file mode 100644 index 0000000000000000000000000000000000000000..fbd0d3b2671ba2b3a8626525a30465cd7d305d44 --- /dev/null +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/database/table/constraints/foreignKey/ForeignKeyDto.java @@ -0,0 +1,34 @@ +package at.tuwien.api.database.table.constraints.foreignKey; + +import at.tuwien.api.database.table.TableBriefDto; +import at.tuwien.api.database.table.TableDto; +import at.tuwien.api.database.table.columns.ColumnDto; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +import javax.persistence.Entity; +import javax.persistence.Transient; +import java.util.List; + +@Getter +@Setter +@ToString +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class ForeignKeyDto { + + private List<ColumnDto> columns; + + @JsonProperty("referenced_table") + private TableBriefDto referencedTable; + + @JsonProperty("referenced_columns") + private List<ColumnDto> referencedColumns; + + @JsonProperty("on_update") + private ReferenceTypeDto onUpdate; + + @JsonProperty("on_delete") + private ReferenceTypeDto onDelete; +} diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/DataCiteBody.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/DataCiteBody.java new file mode 100644 index 0000000000000000000000000000000000000000..e21006600b5960da616488c46f70fd224708af56 --- /dev/null +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/DataCiteBody.java @@ -0,0 +1,15 @@ +package at.tuwien.api.datacite; + +import lombok.*; + +import java.io.Serializable; + +@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class DataCiteBody<T> implements Serializable { + + private DataCiteData<T> data; +} diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/DataCiteData.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/DataCiteData.java new file mode 100644 index 0000000000000000000000000000000000000000..02a2ea99aa8f7e9c0c3a57a0ef703a80fba8dd36 --- /dev/null +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/DataCiteData.java @@ -0,0 +1,19 @@ +package at.tuwien.api.datacite; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.*; + +import java.io.Serializable; + +@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +public class DataCiteData<T> implements Serializable { + + private String id; + private String type; + private T attributes; +} diff --git a/dbrepo-identifier-service/api/src/main/java/at/tuwien/DataCiteError.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/DataCiteError.java similarity index 87% rename from dbrepo-identifier-service/api/src/main/java/at/tuwien/DataCiteError.java rename to dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/DataCiteError.java index 525a73bb41cefac22ff210d494f3e053caae03a7..301b1483f3c82197d0ceb20a71300105c8fe3a89 100644 --- a/dbrepo-identifier-service/api/src/main/java/at/tuwien/DataCiteError.java +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/DataCiteError.java @@ -1,4 +1,4 @@ -package at.tuwien; +package at.tuwien.api.datacite; import lombok.*; diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteCreateDoi.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteCreateDoi.java new file mode 100644 index 0000000000000000000000000000000000000000..d2c9889e42aececc7571160f76866035cda46693 --- /dev/null +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteCreateDoi.java @@ -0,0 +1,44 @@ +package at.tuwien.api.datacite.doi; + +import lombok.*; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.List; + +@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class DataCiteCreateDoi implements Serializable { + + private String url; + + private String prefix; + + private DataCiteDoiTypes types; + + private DataCiteDoiEvent event; + + private List<DataCiteDoiTitle> titles; + + @NotBlank + private String publisher; + + @NotNull + private Integer publicationYear; + + private Integer publicationMonth; + + private Integer publicationDay; + + private String language; + + private List<DataCiteDoiRights> rightsList; + + private List<DataCiteDoiCreator> creators; + + private List<DataCiteDoiRelatedIdentifier> relatedIdentifiers; +} diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoi.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoi.java new file mode 100644 index 0000000000000000000000000000000000000000..8e622553c63a1ec7b371854c50213999a9b7188e --- /dev/null +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoi.java @@ -0,0 +1,17 @@ +package at.tuwien.api.datacite.doi; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.*; + +import java.io.Serializable; + +@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +public class DataCiteDoi implements Serializable { + + private String doi; +} diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiCreator.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiCreator.java new file mode 100644 index 0000000000000000000000000000000000000000..87aa1fcbf5f346631e37fc3d819fb9946923ca89 --- /dev/null +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiCreator.java @@ -0,0 +1,26 @@ +package at.tuwien.api.datacite.doi; + +import lombok.*; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; +import java.util.List; + +@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class DataCiteDoiCreator implements Serializable { + + @NotBlank + private String name; + + private String givenName; + + private String familyName; + + private List<DataCiteDoiCreatorAffiliation> affiliation; + + private List<DataCiteDoiCreatorNameIdentifier> nameIdentifiers; +} diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiCreatorAffiliation.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiCreatorAffiliation.java new file mode 100644 index 0000000000000000000000000000000000000000..3dc9f393728b9ddbf2fe9ce7eac28620ba45c808 --- /dev/null +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiCreatorAffiliation.java @@ -0,0 +1,21 @@ +package at.tuwien.api.datacite.doi; + +import lombok.*; + +import java.io.Serializable; + +@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class DataCiteDoiCreatorAffiliation implements Serializable { + + private String affiliationIdentifier; + + private String affiliationScheme; + + private String name; + + private String schemeUri; +} diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiCreatorNameIdentifier.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiCreatorNameIdentifier.java new file mode 100644 index 0000000000000000000000000000000000000000..b759574ba399fe0cf09c5ccfe4cc8dc43559002e --- /dev/null +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiCreatorNameIdentifier.java @@ -0,0 +1,19 @@ +package at.tuwien.api.datacite.doi; + +import lombok.*; + +import java.io.Serializable; + +@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class DataCiteDoiCreatorNameIdentifier implements Serializable { + + private String schemeUri; + + private String nameIdentifier; + + private String nameIdentifierScheme; +} diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiEvent.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..35b6c670da99c68d75754fd9ea0c9c75768d152d --- /dev/null +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiEvent.java @@ -0,0 +1,31 @@ +package at.tuwien.api.datacite.doi; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; + +import java.io.Serializable; + + +@Getter +public enum DataCiteDoiEvent implements Serializable { + + @JsonProperty("publish") + PUBLISH("publish"), + + @JsonProperty("register") + REGISTER("register"), + + @JsonProperty("hide") + HIDE("hide"); + + private final String name; + + DataCiteDoiEvent(String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } +} diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiRelatedIdentifier.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiRelatedIdentifier.java new file mode 100644 index 0000000000000000000000000000000000000000..ac6e084b582cdde3b038e9ab254156f2d7e255cd --- /dev/null +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiRelatedIdentifier.java @@ -0,0 +1,21 @@ +package at.tuwien.api.datacite.doi; + +import lombok.*; + +import java.io.Serializable; + +@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class DataCiteDoiRelatedIdentifier implements Serializable { + + private String relatedIdentifier; + + private String relatedIdentifierType; + + private String relationType; + + private String resourceTypeGeneral; +} diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiRights.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiRights.java new file mode 100644 index 0000000000000000000000000000000000000000..ca072bb98cc17f502f454e4de3aae9d7b6162d72 --- /dev/null +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiRights.java @@ -0,0 +1,19 @@ +package at.tuwien.api.datacite.doi; + +import lombok.*; + +import java.io.Serializable; + +@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class DataCiteDoiRights implements Serializable { + + private String rights; + + private String rightsUri; + + private String lang; +} diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiTitle.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiTitle.java new file mode 100644 index 0000000000000000000000000000000000000000..8446813f11dbdfc6006c2c0bf40df6f04664f00d --- /dev/null +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiTitle.java @@ -0,0 +1,48 @@ +package at.tuwien.api.datacite.doi; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class DataCiteDoiTitle implements Serializable { + + @NotBlank + private String title; + + private Type titleType; + + private String lang; + + public enum Type { + + @JsonProperty("AlternativeTitle") + ALTERNATIVE_TITLE("AlternativeTitle"), + + @JsonProperty("Subtitle") + SUBTITLE("Subtitle"), + + @JsonProperty("TranslatedTitle") + TRANSLATED_TITLE("TranslatedTitle"), + + @JsonProperty("Other") + OTHER("Other"); + + private final String name; + + Type(String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } + } +} diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiTypes.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiTypes.java new file mode 100644 index 0000000000000000000000000000000000000000..dcb5016867f1e0d7ac2dfa0e9b7749596558b68e --- /dev/null +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/datacite/doi/DataCiteDoiTypes.java @@ -0,0 +1,29 @@ +package at.tuwien.api.datacite.doi; + +import lombok.*; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class DataCiteDoiTypes implements Serializable { + + public static final DataCiteDoiTypes DATASET = DataCiteDoiTypes.builder().resourceTypeGeneral("Dataset").build(); + + @NotNull + private String resourceTypeGeneral; + + private String resourceType; + + private String schemaOrg; + + private String bibtex; + + private String citeproc; + + private String ris; +} diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/error/ApiErrorDto.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/error/ApiErrorDto.java index d8f0aa27954d027466a101861007dca1faea48eb..66a1aeda0c593413fd4e5bfb0d751e1a228dec22 100644 --- a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/error/ApiErrorDto.java +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/error/ApiErrorDto.java @@ -15,15 +15,15 @@ import javax.validation.constraints.NotNull; public class ApiErrorDto { @NotNull(message = "http status is required") - @Schema(example = "NOT_FOUND") + @Schema(example = "STATUS") private HttpStatus status; @NotNull(message = "message is required") - @Schema(example = "Could not find container") + @Schema(example = "Error message") private String message; @NotNull(message = "code is required") - @Schema(example = "error.container.notfound") + @Schema(example = "error.service.code") private String code; } diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/identifier/IdentifierBriefDto.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/identifier/IdentifierBriefDto.java index c17feec05c19de48c19767e6cf083a8a7a8d01d8..6b2f0dc3668d45d8a9dee2f5b7ceacf8e5690a15 100644 --- a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/identifier/IdentifierBriefDto.java +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/identifier/IdentifierBriefDto.java @@ -44,10 +44,6 @@ public class IdentifierBriefDto { @NotNull private IdentifierTypeDto type; - @NotNull - @Schema(example = "everyone") - private VisibilityTypeDto visibility; - @Schema(example = "10.1038/nphys1170") private String doi; diff --git a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/identifier/IdentifierCreateDto.java b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/identifier/IdentifierCreateDto.java index eeb7c449a8098080f8abebd9da7dc76507c1ff1a..67a9e858e95b8dc72b9074870de4e697346e72f8 100644 --- a/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/identifier/IdentifierCreateDto.java +++ b/dbrepo-metadata-db/api/src/main/java/at/tuwien/api/identifier/IdentifierCreateDto.java @@ -11,6 +11,7 @@ import lombok.Setter; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import javax.validation.constraints.NotEmpty; import java.util.List; @Data @@ -37,13 +38,6 @@ public class IdentifierCreateDto { @Schema(example = "Air quality reports at Stephansplatz, Vienna") private String description; - @NotNull - @Schema(example = "everyone") - private VisibilityTypeDto visibility; - - @Schema(example = "10.1038/nphys1170") - private String doi; - @JsonProperty("publication_day") @Schema(example = "15") private Integer publicationDay; @@ -65,6 +59,7 @@ public class IdentifierCreateDto { private Integer publicationYear; @NotNull + @NotEmpty private List<CreatorCreateDto> creators; @JsonProperty("related_identifiers") diff --git a/dbrepo-metadata-db/entities/pom.xml b/dbrepo-metadata-db/entities/pom.xml index caddb901dde38aaf1b9ab5c1ed39b31f7d29eaef..4b9abe2a8b9f6f76bd1405ce9d38707e40a9dfbb 100644 --- a/dbrepo-metadata-db/entities/pom.xml +++ b/dbrepo-metadata-db/entities/pom.xml @@ -5,13 +5,13 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db</artifactId> - <version>1.1.0-alpha</version> + <artifactId>dbrepo-metadata-db</artifactId> + <version>1.2.0</version> </parent> - <artifactId>fda-metadata-db-entites</artifactId> - <version>1.1.0-alpha</version> - <name>fda-metadata-db-entity</name> + <artifactId>dbrepo-metadata-db-entites</artifactId> + <version>1.2.0</version> + <name>dbrepo-metadata-db-entity</name> <dependencies/> diff --git a/dbrepo-metadata-db/entities/src/main/java/at/tuwien/entities/container/Container.java b/dbrepo-metadata-db/entities/src/main/java/at/tuwien/entities/container/Container.java index 797ffda9926f259af70e630f68b4baac3f4c29a3..b429c943a8c3714ca4de40273dced650fe5ee2a7 100644 --- a/dbrepo-metadata-db/entities/src/main/java/at/tuwien/entities/container/Container.java +++ b/dbrepo-metadata-db/entities/src/main/java/at/tuwien/entities/container/Container.java @@ -3,6 +3,7 @@ package at.tuwien.entities.container; import at.tuwien.entities.container.image.ContainerImage; import at.tuwien.entities.database.Database; import at.tuwien.entities.user.User; +import com.github.dockerjava.api.model.HealthCheck; import lombok.*; import org.hibernate.annotations.GenericGenerator; import org.springframework.data.annotation.CreatedDate; diff --git a/dbrepo-metadata-db/entities/src/main/java/at/tuwien/entities/database/table/constraints/foreignKey/ReferenceType.java b/dbrepo-metadata-db/entities/src/main/java/at/tuwien/entities/database/table/constraints/foreignKey/ReferenceType.java index ba1b67ce2d7793dcc13ffbee2dc4bd17add4ec11..9afc40853f878faaee98eb5f747a543ae693dc8a 100644 --- a/dbrepo-metadata-db/entities/src/main/java/at/tuwien/entities/database/table/constraints/foreignKey/ReferenceType.java +++ b/dbrepo-metadata-db/entities/src/main/java/at/tuwien/entities/database/table/constraints/foreignKey/ReferenceType.java @@ -7,7 +7,6 @@ import lombok.ToString; @Getter @ToString public enum ReferenceType { - RESTRICT, CASCADE, SET_NULL, diff --git a/dbrepo-metadata-db/entities/src/main/java/at/tuwien/entities/identifier/Identifier.java b/dbrepo-metadata-db/entities/src/main/java/at/tuwien/entities/identifier/Identifier.java index 857346c056facef07759de0c46c81aea6829ce48..fb857a53dbe11ee3e2d1da8d478a208ae092d54a 100644 --- a/dbrepo-metadata-db/entities/src/main/java/at/tuwien/entities/identifier/Identifier.java +++ b/dbrepo-metadata-db/entities/src/main/java/at/tuwien/entities/identifier/Identifier.java @@ -109,7 +109,8 @@ public class Identifier implements Serializable { @Column(nullable = false, columnDefinition = "enum('EVERYONE', 'TRUSTED', 'SELF')") @Enumerated(EnumType.STRING) - private VisibilityType visibility = VisibilityType.SELF; + @Builder.Default + private VisibilityType visibility = VisibilityType.EVERYONE; @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.MERGE) @JoinColumns({ diff --git a/dbrepo-metadata-db/oai/pom.xml b/dbrepo-metadata-db/oai/pom.xml index 528797bed4c44843944cd819f537f55f2d774012..9ecf40bc6fef5a523110bda2bb73b16d7883509b 100644 --- a/dbrepo-metadata-db/oai/pom.xml +++ b/dbrepo-metadata-db/oai/pom.xml @@ -5,13 +5,13 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db</artifactId> - <version>1.1.0-alpha</version> + <artifactId>dbrepo-metadata-db</artifactId> + <version>1.2.0</version> </parent> - <artifactId>fda-metadata-db-oai</artifactId> - <version>1.1.0-alpha</version> - <name>fda-metadata-db-oai</name> + <artifactId>dbrepo-metadata-db-oai</artifactId> + <version>1.2.0</version> + <name>dbrepo-metadata-db-oai</name> <dependencies/> diff --git a/dbrepo-metadata-db/pom.xml b/dbrepo-metadata-db/pom.xml index 508283bbe345756b9a4f1fd61655e33342b2f199..5a0d2c25ae82a6bbf84780706dbb49be7611d5ce 100644 --- a/dbrepo-metadata-db/pom.xml +++ b/dbrepo-metadata-db/pom.xml @@ -9,9 +9,9 @@ </parent> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db</artifactId> - <version>1.1.0-alpha</version> - <name>fda-metadata-db</name> + <artifactId>dbrepo-metadata-db</artifactId> + <version>1.2.0</version> + <name>dbrepo-metadata-db</name> <description>Demo project for Spring Boot</description> <packaging>pom</packaging> @@ -20,6 +20,7 @@ <module>entities</module> <module>querystore</module> <module>oai</module> + <module>test</module> </modules> <properties> @@ -34,6 +35,7 @@ <springfox.version>3.0.0</springfox.version> <jsql.version>3.1</jsql.version> <jackson-datatype.version>2.13.3</jackson-datatype.version> + <commons.version>2.11.0</commons.version> </properties> <dependencies> @@ -76,6 +78,11 @@ <artifactId>jackson-datatype-jsr310</artifactId> <version>${jackson-datatype.version}</version> </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>${commons.version}</version> + </dependency> <!-- SQL Parser --> <dependency> <groupId>com.github.jsqlparser</groupId> @@ -98,6 +105,23 @@ <artifactId>springdoc-openapi-javadoc</artifactId> <version>1.6.6</version> </dependency> + <!-- Docker --> + <dependency> + <groupId>com.github.docker-java</groupId> + <artifactId>docker-java</artifactId> + <version>${docker.version}</version> + <exclusions> + <exclusion> + <groupId>javax.ws.rs</groupId> + <artifactId>jsr311-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>com.github.docker-java</groupId> + <artifactId>docker-java-transport-httpclient5</artifactId> + <version>${docker.version}</version> + </dependency> </dependencies> <!-- build at.tuwien.gateway.config in ./rest-service/pom.xml --> diff --git a/dbrepo-metadata-db/querystore/pom.xml b/dbrepo-metadata-db/querystore/pom.xml index 017a63b8356f83278e9750241ae2549b3109abf8..37ae21126fe1b49b7545bed69010fd65bab39752 100644 --- a/dbrepo-metadata-db/querystore/pom.xml +++ b/dbrepo-metadata-db/querystore/pom.xml @@ -5,19 +5,19 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db</artifactId> - <version>1.1.0-alpha</version> + <artifactId>dbrepo-metadata-db</artifactId> + <version>1.2.0</version> </parent> - <artifactId>fda-metadata-db-querystore</artifactId> - <version>1.1.0-alpha</version> - <name>fda-metadata-db-querystore</name> + <artifactId>dbrepo-metadata-db-querystore</artifactId> + <version>1.2.0</version> + <name>dbrepo-metadata-db-querystore</name> <dependencies> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-api</artifactId> - <version>1.1.0-alpha</version> + <artifactId>dbrepo-metadata-db-api</artifactId> + <version>1.2.0</version> <scope>compile</scope> </dependency> </dependencies> diff --git a/dbrepo-metadata-db/test/pom.xml b/dbrepo-metadata-db/test/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..3865218a9dbac2e0ab3374b928a1a4326d9b70b0 --- /dev/null +++ b/dbrepo-metadata-db/test/pom.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>at.tuwien</groupId> + <artifactId>dbrepo-metadata-db</artifactId> + <version>1.2.0</version> + </parent> + + <artifactId>dbrepo-metadata-db-test</artifactId> + <version>1.2.0</version> + <name>dbrepo-metadata-db-test</name> + + <dependencies> + <dependency> + <groupId>at.tuwien</groupId> + <artifactId>dbrepo-metadata-db-entites</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>at.tuwien</groupId> + <artifactId>dbrepo-metadata-db-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>at.tuwien</groupId> + <artifactId>dbrepo-metadata-db-querystore</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + +</project> \ No newline at end of file diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/config/DockerConfig.java b/dbrepo-metadata-db/test/src/main/java/at/tuwien/config/DockerConfig.java similarity index 92% rename from dbrepo-query-service/rest-service/src/test/java/at/tuwien/config/DockerConfig.java rename to dbrepo-metadata-db/test/src/main/java/at/tuwien/config/DockerConfig.java index f91219b29e5831a008e39cc3656d47d9bbdcf6e0..e642c44251f7da13e48e811e859f6aa0a20d2120 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/config/DockerConfig.java +++ b/dbrepo-metadata-db/test/src/main/java/at/tuwien/config/DockerConfig.java @@ -1,7 +1,7 @@ package at.tuwien.config; -import at.tuwien.BaseUnitTest; import at.tuwien.entities.container.Container; +import at.tuwien.test.BaseTest; import com.github.dockerjava.api.DockerClient; import com.github.dockerjava.api.command.CreateContainerCmd; import com.github.dockerjava.api.command.CreateContainerResponse; @@ -19,7 +19,7 @@ import java.util.Arrays; import java.util.Objects; @Log4j2 -public class DockerConfig extends BaseUnitTest { +public class DockerConfig extends BaseTest { private final static DockerClientConfig dockerClientConfig = DefaultDockerClientConfig.createDefaultConfigBuilder() .withDockerHost("unix:///var/run/docker.sock") @@ -55,8 +55,8 @@ public class DockerConfig extends BaseUnitTest { final InspectContainerResponse response = dockerClient.inspectContainerCmd(container.getHash()) .exec(); if (hasHealthCheck && response.getState().getHealth() == null) { - log.error("Container does not have a healthcheck configuration"); - throw new InterruptedException("Container does not have a healthcheck configuration"); + log.error("Container does not have a healthcheck response"); + throw new InterruptedException("Container does not have a healthcheck response"); } if (hasHealthCheck) { state = response.getState().getHealth().getStatus(); @@ -75,10 +75,22 @@ public class DockerConfig extends BaseUnitTest { } else { log.error("failed to start container {} as state {} is not healthy after {} tries", container.getHash(), state, i); - throw new RuntimeException("Failed to start container"); + throw new RuntimeException("Failed to start container " + container.getHash() + " as state " + state + " is not healthy after " + i + " tries"); } } + public static void stopContainer(Container container) { + final InspectContainerResponse inspect = dockerClient.inspectContainerCmd(container.getHash()) + .exec(); + log.trace("container {} state {}", container.getHash(), inspect.getState().getStatus()); + if (Objects.equals(inspect.getState().getStatus(), "exited")) { + return; + } + log.info("container {} needs to be stopped", container.getInternalName()); + dockerClient.stopContainerCmd(container.getHash()) + .exec(); + } + public static void createContainer(String bind, Container container, String... environment) { createContainer(bind, container, null, environment); } @@ -195,9 +207,6 @@ public class DockerConfig extends BaseUnitTest { case 5: log.debug("container with id {} has a health check config", containerId); return CONTAINER_BROKER_HEALTHCHECK; - case 7: - log.debug("container with id {} has a health check config", containerId); - return CONTAINER_PROXY_HEALTHCHECK; } log.trace("container with id {} does not have a healthcheck config", containerId); return null; diff --git a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/config/H2Utils.java b/dbrepo-metadata-db/test/src/main/java/at/tuwien/config/H2Utils.java similarity index 81% rename from dbrepo-database-service/rest-service/src/test/java/at/tuwien/config/H2Utils.java rename to dbrepo-metadata-db/test/src/main/java/at/tuwien/config/H2Utils.java index 4bfdf4a41bc5ce8e8096431183e3341c3568023b..82ec75d14a3d001a36116db2a186faa0a58b4044 100644 --- a/dbrepo-database-service/rest-service/src/test/java/at/tuwien/config/H2Utils.java +++ b/dbrepo-metadata-db/test/src/main/java/at/tuwien/config/H2Utils.java @@ -1,7 +1,7 @@ package at.tuwien.config; import lombok.extern.log4j.Log4j2; -import org.codehaus.plexus.util.FileUtils; +import org.apache.commons.io.FileUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -9,7 +9,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.persistence.EntityManager; import java.io.File; import java.io.IOException; -import java.sql.*; +import java.nio.charset.StandardCharsets; @Log4j2 @Component @@ -28,7 +28,7 @@ public class H2Utils { @Transactional public void runScript(String scriptName) { try { - runQuery(FileUtils.fileRead(new File("./src/test/resources/" + scriptName))); + runQuery(FileUtils.readFileToString(new File("./src/test/resources/" + scriptName), StandardCharsets.UTF_8)); } catch (IOException e) { log.error("Failed to load script {}", scriptName); throw new RuntimeException("Failed to load script", e); diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java b/dbrepo-metadata-db/test/src/main/java/at/tuwien/config/MariaDbConfig.java similarity index 100% rename from dbrepo-query-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java rename to dbrepo-metadata-db/test/src/main/java/at/tuwien/config/MariaDbConfig.java diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/config/RabbitMqConfig.java b/dbrepo-metadata-db/test/src/main/java/at/tuwien/config/RabbitMqConfig.java similarity index 90% rename from dbrepo-query-service/rest-service/src/test/java/at/tuwien/config/RabbitMqConfig.java rename to dbrepo-metadata-db/test/src/main/java/at/tuwien/config/RabbitMqConfig.java index 72ef54c966d37a7f92566228f9e00cbf6f8643a1..d0bd6ca9e7a11dcd2a3a5ae65c900e3874e41825 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/config/RabbitMqConfig.java +++ b/dbrepo-metadata-db/test/src/main/java/at/tuwien/config/RabbitMqConfig.java @@ -12,22 +12,18 @@ import org.springframework.web.client.RestTemplate; import java.io.IOException; import java.net.URI; import java.nio.charset.Charset; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; @Log4j2 @Configuration public class RabbitMqConfig { - private final AmqpConfig amqpConfig; private final RestTemplate restTemplate; @Autowired - public RabbitMqConfig(AmqpConfig amqpConfig, RestTemplate restTemplate) { - this.amqpConfig = amqpConfig; + public RabbitMqConfig(RestTemplate restTemplate) { this.restTemplate = restTemplate; } @@ -59,7 +55,7 @@ public class RabbitMqConfig { private HttpHeaders getHeaders() { String auth = "guest:guest"; - log.trace("set Authorization header username={}, password=(redacted)", amqpConfig.getAmqpUsername()); + log.trace("set Authorization header username={}, password={}", "guest", "guest"); byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.defaultCharset())); String authHeader = "Basic " + new String(encodedAuth); return new HttpHeaders() {{ diff --git a/dbrepo-metadata-db/test/src/main/java/at/tuwien/test/BaseTest.java b/dbrepo-metadata-db/test/src/main/java/at/tuwien/test/BaseTest.java new file mode 100644 index 0000000000000000000000000000000000000000..683e07b1ff88ce81e843b3971b79737800d09ea9 --- /dev/null +++ b/dbrepo-metadata-db/test/src/main/java/at/tuwien/test/BaseTest.java @@ -0,0 +1,4224 @@ +package at.tuwien.test; + +import at.tuwien.api.amqp.CreateVirtualHostDto; +import at.tuwien.api.amqp.GrantVirtualHostPermissionsDto; +import at.tuwien.api.auth.SignupRequestDto; +import at.tuwien.api.container.image.ImageEnvItemDto; +import at.tuwien.api.container.image.ImageEnvItemTypeDto; +import at.tuwien.api.database.DatabaseCreateDto; +import at.tuwien.api.database.DatabaseDto; +import at.tuwien.api.database.LicenseDto; +import at.tuwien.api.database.ViewDto; +import at.tuwien.api.database.query.QueryBriefDto; +import at.tuwien.api.database.query.QueryDto; +import at.tuwien.api.database.query.QueryResultDto; +import at.tuwien.api.database.table.TableCreateDto; +import at.tuwien.api.database.table.TableCsvDto; +import at.tuwien.api.database.table.columns.ColumnCreateDto; +import at.tuwien.api.database.table.columns.ColumnTypeDto; +import at.tuwien.api.database.table.constraints.ConstraintsCreateDto; +import at.tuwien.api.database.table.constraints.foreignKey.ForeignKeyCreateDto; +import at.tuwien.api.identifier.*; +import at.tuwien.api.user.*; +import at.tuwien.entities.container.image.ContainerImageDate; +import at.tuwien.entities.database.*; +import at.tuwien.entities.database.table.columns.TableColumnConcept; +import at.tuwien.entities.database.table.constraints.Constraints; +import at.tuwien.entities.database.table.constraints.foreignKey.ForeignKey; +import at.tuwien.entities.database.table.constraints.foreignKey.ForeignKeyReference; +import at.tuwien.entities.database.table.constraints.unique.Unique; +import at.tuwien.entities.identifier.*; +import at.tuwien.entities.user.User; +import at.tuwien.entities.user.UserAttribute; +import at.tuwien.querystore.Query; +import at.tuwien.entities.container.Container; +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.table.Table; +import at.tuwien.entities.database.table.columns.TableColumn; +import at.tuwien.entities.database.table.columns.TableColumnType; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import com.github.dockerjava.api.model.HealthCheck; + +import java.math.BigInteger; +import java.security.Principal; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.*; +import java.util.stream.Collectors; + +import static java.time.temporal.ChronoUnit.*; + +/** + * Database 1 (Private, User 1) + * <ul> + * <li>Table 1</li> + * <li>Table 2</li> + * <li>Table 3</li> + * <li>Table 7</li> + * <li>Query 1</li> + * <li>View 3</li> + * </ul> + * <p> + * Database 2 (Private, User 2) + * <ul> + * <li>Table 4</li> + * <li>Table 5</li> + * <li>Table 6</li> + * <li>Query 2</li> + * <li>Query 6</li> + * <li>View 4</li> + * </ul> + * <p> + * Database 3 (Public, User 3) + * <ul> + * <li>Table 8</li> + * <li>Query 3</li> + * <li>Query 4</li> + * <li>Query 5</li> + * <li>View 5</li> + * </ul> + * <p> + * Database 4 (Public, User 4) + * <ul> + * </ul> + */ +public abstract class BaseTest { + + public final static String[] DEFAULT_RESEARCHER_ROLES = new String[]{"default-container-handling", + "create-container", "list-containers", "modify-container-state", "find-container", + "default-database-handling", "update-database-access", "modify-database-visibility", "create-database", + "modify-database-owner", "delete-database-access", "check-database-access", "list-databases", + "create-database-access", "find-database", "default-identifier-handling", "create-identifier", + "find-identifier", "list-identifiers", "default-query-handling", "view-table-data", "execute-query", + "view-table-history", "list-database-views", "list-queries", "view-database-view-data", "export-query-data", + "find-query", "create-database-view", "delete-database-view", "delete-table-data", "export-table-data", + "persist-query", "re-execute-query", "insert-table-data", "find-database-view", "default-table-handling", + "list-tables", "create-table", "modify-table-column-semantics", "find-table", "default-user-handling", + "modify-user-theme", "modify-user-information", "default-researcher-roles", "default-user-handling", + "default-identifier-handling", "default-database-handling", "default-container-handling", + "default-table-handling", "default-query-handling"}; + + public final static List<GrantedAuthorityDto> AUTHORITY_DEFAULT_RESEARCHER_ROLES = Arrays.stream(DEFAULT_RESEARCHER_ROLES) + .map(GrantedAuthorityDto::new) + .collect(Collectors.toList()); + + public final static List<GrantedAuthority> AUTHORITY_DEFAULT_RESEARCHER_AUTHORITIES = AUTHORITY_DEFAULT_RESEARCHER_ROLES.stream() + .map(a -> new SimpleGrantedAuthority(a.getAuthority())) + .collect(Collectors.toList()); + + public final static UserThemeSetDto USER_THEME_DARK_DTO = UserThemeSetDto.builder() + .themeDark(true) + .build(); + + public final static UserThemeSetDto USER_THEME_LIGHT_DTO = UserThemeSetDto.builder() + .themeDark(false) + .build(); + + public final static String USER_BROKER_USERNAME = "guest"; + public final static String USER_BROKER_PASSWORD = "guest"; + + public final static User USER_BROKER = User.builder() + .username(USER_BROKER_USERNAME) + .build(); + + public final static String USER_1_ID = "cd5bab0d-7799-4069-85fb-c5d738572a0b"; + public final static String USER_1_EMAIL = "john.doe@example.com"; + public final static String USER_1_USERNAME = "junit1"; + public final static String USER_1_PASSWORD = "s3cr3t1nf0rm4t10n"; + public final static String USER_1_PASSWORD_ENCODED = "$2a$10$0dtdedA/RLTrFbUsvpbUw.I73AXOKeQP3t5UXj96OvnDEaDb3d3M6"; + public final static String USER_1_DATABASE_PASSWORD = "*440BA4FD1A87A0999647DB67C0EE258198B247BA" /* junit1 */; + public final static String USER_1_FIRSTNAME = "John"; + public final static String USER_1_LASTNAME = "Doe"; + public final static String USER_1_AFFILIATION = "TU Graz"; + public final static String USER_1_ORCID = "000000034216302X"; + public final static String USER_1_ORCID_UNCOMPRESSED = "0000-0003-4216-302X"; + public final static String USER_1_TITLES_BEFORE = "Dr."; + public final static String USER_1_TITLES_AFTER = "MSc BSc"; + public final static Boolean USER_1_VERIFIED = false; + public final static Boolean USER_1_THEME_DARK = false; + public final static Instant USER_1_CREATED = Instant.ofEpochSecond(1677399441) /* 2023-02-26 08:17:21 (UTC) */; + public final static Instant USER_1_LAST_MODIFIED = USER_1_CREATED; + + public final static List<UserAttribute> USER_1_ATTRIBUTES = List.of(UserAttribute.builder() + .id("c466a105-5bbd-4afc-87ae-751d5037d9ab") + .userId(USER_1_ID) + .name("theme_dark") + .value("false") + .build(), + UserAttribute.builder() + .id("0870498b-d6ac-4543-bef1-830142de96d7") + .userId(USER_1_ID) + .name("orcid") + .value(USER_1_ORCID_UNCOMPRESSED) + .build(), + UserAttribute.builder() + .id("42b06e7f-9df2-4b1c-bdfb-904401d6ad36") + .userId(USER_1_ID) + .name("affiliation") + .value(USER_1_AFFILIATION) + .build()); + + public final static List<UserAttributeDto> USER_1_ATTRIBUTES_DTO = List.of(UserAttributeDto.builder() + .id("c466a105-5bbd-4afc-87ae-751d5037d9ab") + .userId(USER_1_ID) + .name("theme_dark") + .value("false") + .build(), + UserAttributeDto.builder() + .id("0870498b-d6ac-4543-bef1-830142de96d7") + .userId(USER_1_ID) + .name("orcid") + .value(USER_1_ORCID_UNCOMPRESSED) + .build(), + UserAttributeDto.builder() + .id("42b06e7f-9df2-4b1c-bdfb-904401d6ad36") + .userId(USER_1_ID) + .name("affiliation") + .value(USER_1_AFFILIATION) + .build()); + + public final static User USER_1 = User.builder() + .id(USER_1_ID) + .username(USER_1_USERNAME) + .email(USER_1_EMAIL) + .databasePassword(USER_1_DATABASE_PASSWORD) + .firstname(USER_1_FIRSTNAME) + .lastname(USER_1_LASTNAME) + .emailVerified(USER_1_VERIFIED) + .attributes(USER_1_ATTRIBUTES) + .build(); + + public final static UserDto USER_1_DTO = UserDto.builder() + .id(USER_1_ID) + .username(USER_1_USERNAME) + .email(USER_1_EMAIL) + .firstname(USER_1_FIRSTNAME) + .lastname(USER_1_LASTNAME) + .emailVerified(USER_1_VERIFIED) + .attributes(USER_1_ATTRIBUTES_DTO) + .build(); + + public final static UserDetails USER_1_DETAILS = UserDetailsDto.builder() + .username(USER_1_USERNAME) + .email(USER_1_EMAIL) + .password(USER_1_PASSWORD) + .authorities(AUTHORITY_DEFAULT_RESEARCHER_AUTHORITIES) + .build(); + + public final static Principal USER_1_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_1_DETAILS, + USER_1_PASSWORD, USER_1_DETAILS.getAuthorities()); + + public final static SignupRequestDto USER_1_SIGNUP_REQUEST_DTO = SignupRequestDto.builder() + .username(USER_1_USERNAME) + .password(USER_1_PASSWORD) + .email(USER_1_EMAIL) + .build(); + + public final static at.tuwien.api.amqp.UserDetailsDto USER_1_DETAILS_DTO = at.tuwien.api.amqp.UserDetailsDto.builder() + .name(USER_1_USERNAME) + .tags(new String[]{}) + .build(); + + public final static at.tuwien.api.amqp.UserDetailsDto USER_1_DETAILS_WITH_TAGS_DTO = at.tuwien.api.amqp.UserDetailsDto.builder() + .name(USER_1_USERNAME) + .tags(new String[]{"administrator"}) + .build(); + + public final static String USER_2_ID = "eeb9a51b-4cd8-4039-90bf-e24f17372f7c"; + public final static String USER_2_EMAIL = "jane.doe@example.com"; + public final static String USER_2_USERNAME = "junit2"; + public final static String USER_2_FIRSTNAME = "Jane"; + public final static String USER_2_LASTNAME = "Doe"; + public final static String USER_2_AFFILIATION = "TU Wien"; + public final static String USER_2_ORCID = "0000000292726225"; + public final static String USER_2_ORCID_UNCOMPRESSED = "0000-0002-9272-6225"; + public final static String USER_2_PASSWORD = "s3cr3t1nf0rm4t10n"; + public final static String USER_2_DATABASE_PASSWORD = "*9AA70A8B0EEFAFCB5BED5BDEF6EE264D5DA915AE" /* junit2 */; + public final static Boolean USER_2_VERIFIED = true; + public final static Boolean USER_2_THEME_DARK = false; + public final static Instant USER_2_CREATED = Instant.ofEpochSecond(1677399528) /* 2023-02-26 08:18:48 (UTC) */; + public final static Instant USER_2_LAST_MODIFIED = USER_1_CREATED; + + public final static List<UserAttribute> USER_2_ATTRIBUTES = List.of(UserAttribute.builder() + .id("23da2c08-cb8a-4e18-a7f0-70c30de2771e") + .userId(USER_2_ID) + .name("theme_dark") + .value("false") + .build(), + UserAttribute.builder() + .id("83223dfd-1c80-4132-8c74-a38994f45f4a") + .userId(USER_2_ID) + .name("orcid") + .value(USER_2_ORCID_UNCOMPRESSED) + .build(), + UserAttribute.builder() + .id("a29879fd-9801-4adf-bf3a-16bbff6ea207") + .userId(USER_2_ID) + .name("affiliation") + .value(USER_2_AFFILIATION) + .build()); + + public final static List<UserAttributeDto> USER_2_ATTRIBUTES_DTO = List.of(UserAttributeDto.builder() + .id("23da2c08-cb8a-4e18-a7f0-70c30de2771e") + .userId(USER_2_ID) + .name("theme_dark") + .value("false") + .build(), + UserAttributeDto.builder() + .id("83223dfd-1c80-4132-8c74-a38994f45f4a") + .userId(USER_2_ID) + .name("orcid") + .value(USER_2_ORCID_UNCOMPRESSED) + .build(), + UserAttributeDto.builder() + .id("a29879fd-9801-4adf-bf3a-16bbff6ea207") + .userId(USER_2_ID) + .name("affiliation") + .value(USER_2_AFFILIATION) + .build()); + + public final static User USER_2 = User.builder() + .id(USER_2_ID) + .username(USER_2_USERNAME) + .email(USER_2_EMAIL) + .emailVerified(true) + .databasePassword(USER_2_DATABASE_PASSWORD) + .firstname(USER_2_FIRSTNAME) + .lastname(USER_2_LASTNAME) + .emailVerified(USER_2_VERIFIED) + .build(); + + public final static UserDto USER_2_DTO = UserDto.builder() + .id(USER_2_ID) + .username(USER_2_USERNAME) + .email(USER_2_EMAIL) + .firstname(USER_2_FIRSTNAME) + .lastname(USER_2_LASTNAME) + .emailVerified(USER_2_VERIFIED) + .build(); + + public final static SignupRequestDto USER_2_SIGNUP_REQUEST_DTO = SignupRequestDto.builder() + .username(USER_2_USERNAME) + .password(USER_2_PASSWORD) + .email(USER_2_EMAIL) + .build(); + + public final static UserDetails USER_2_DETAILS = UserDetailsDto.builder() + .id(USER_2_ID) + .username(USER_2_USERNAME) + .email(USER_2_EMAIL) + .password(USER_2_PASSWORD) + .authorities(AUTHORITY_DEFAULT_RESEARCHER_AUTHORITIES) + .build(); + + public final static at.tuwien.api.amqp.UserDetailsDto USER_2_DETAILS_DTO = at.tuwien.api.amqp.UserDetailsDto.builder() + .name(USER_2_USERNAME) + .tags(new String[]{}) + .build(); + + public final static Principal USER_2_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_2_DETAILS, + USER_2_PASSWORD, USER_2_DETAILS.getAuthorities()); + + public final static String USER_3_ID = "7b080e33-d8db-4276-9d53-47208e657006"; + public final static String USER_3_USERNAME = "junit3"; + public final static String USER_3_FIRSTNAME = "System"; + public final static String USER_3_LASTNAME = "System"; + public final static String USER_3_AFFILIATION = "TU Wien"; + public final static String USER_3_ORCID = null; + public final static String USER_3_EMAIL = "system@example.com"; + public final static String USER_3_PASSWORD = "password"; + public final static String USER_3_DATABASE_PASSWORD = "*D65FCA043964B63E849DD6334699ECB065905DA4" /* junit3 */; + public final static Boolean USER_3_VERIFIED = true; + public final static Boolean USER_3_THEME_DARK = false; + public final static Instant USER_3_CREATED = Instant.ofEpochSecond(1677399559) /* 2023-02-26 08:19:19 (UTC) */; + + public final static User USER_3 = User.builder() + .id(USER_3_ID) + .username(USER_3_USERNAME) + .email(USER_3_EMAIL) + .emailVerified(true) + .databasePassword(USER_3_DATABASE_PASSWORD) + .build(); + + public final static UserDto USER_3_DTO = UserDto.builder() + .id(USER_3_ID) + .username(USER_3_USERNAME) + .email(USER_3_EMAIL) + .firstname(USER_3_FIRSTNAME) + .lastname(USER_3_LASTNAME) + .emailVerified(USER_3_VERIFIED) + .build(); + + public final static UserDetails USER_3_DETAILS = UserDetailsDto.builder() + .username(USER_3_USERNAME) + .email(USER_3_EMAIL) + .password(USER_3_PASSWORD) + .authorities(List.of(new SimpleGrantedAuthority("ROLE_DATA_STEWARD"))) + .build(); + + public final static Principal USER_3_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_3_DETAILS, + USER_3_PASSWORD, USER_3_DETAILS.getAuthorities()); + + public final static at.tuwien.api.amqp.UserDetailsDto USER_3_DETAILS_DTO = at.tuwien.api.amqp.UserDetailsDto.builder() + .name(USER_3_USERNAME) + .tags(new String[]{}) + .build(); + + public final static String USER_4_ID = "791d58c5-bfab-4520-b4fc-b44d4ab9feb0"; + public final static String USER_4_USERNAME = "junit4"; + public final static String USER_4_FIRSTNAME = "JUnit"; + public final static String USER_4_LASTNAME = "4"; + public final static String USER_4_AFFILIATION = "TU Wien"; + public final static String USER_4_ORCID = null; + public final static String USER_4_PASSWORD = "junit4"; + public final static String USER_4_DATABASE_PASSWORD = "*C20EF5C6875857DEFA9BE6E9B62DD76AAAE51882" /* junit4 */; + public final static String USER_4_EMAIL = "junit4@ossdip.at"; + public final static Boolean USER_4_VERIFIED = true; + public final static Boolean USER_4_THEME_DARK = false; + public final static Instant USER_4_CREATED = Instant.ofEpochSecond(1677399592) /* 2023-02-26 08:19:52 (UTC) */; + + public final static User USER_4 = User.builder() + .id(USER_4_ID) + .username(USER_4_USERNAME) + .email(USER_4_EMAIL) + .emailVerified(USER_4_VERIFIED) + .databasePassword(USER_4_DATABASE_PASSWORD) + .build(); + + public final static UserDto USER_4_DTO = UserDto.builder() + .id(USER_4_ID) + .username(USER_4_USERNAME) + .email(USER_4_EMAIL) + .firstname(USER_4_FIRSTNAME) + .lastname(USER_4_LASTNAME) + .emailVerified(USER_4_VERIFIED) + .build(); + + public final static UserDetails USER_4_DETAILS = UserDetailsDto.builder() + .username(USER_4_USERNAME) + .email(USER_4_EMAIL) + .password(USER_4_PASSWORD) + .authorities(AUTHORITY_DEFAULT_RESEARCHER_AUTHORITIES) + .build(); + + public final static Principal USER_4_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_4_DETAILS, + USER_4_PASSWORD, USER_4_DETAILS.getAuthorities()); + + public final static String USER_5_ID = "28ff851d-d7bc-4422-959c-edd7a5b15630"; + public final static String USER_5_USERNAME = "system"; + public final static String USER_5_FIRSTNAME = "System"; + public final static String USER_5_LASTNAME = "System"; + public final static String USER_5_AFFILIATION = "TU Wien"; + public final static String USER_5_ORCID = null; + public final static String USER_5_PASSWORD = "junit5"; + public final static String USER_5_DATABASE_PASSWORD = "*C20EF5C6875857DEFA9BE6E9B62DD76AAAE51882" /* junit5 */; + public final static String USER_5_EMAIL = "system@ossdip.at"; + public final static Boolean USER_5_VERIFIED = true; + public final static Boolean USER_5_THEME_DARK = false; + public final static Instant USER_5_CREATED = Instant.ofEpochSecond(1677399592) /* 2023-02-26 08:19:52 (UTC) */; + + public final static User USER_5 = User.builder() + .id(USER_5_ID) + .username(USER_5_USERNAME) + .email(USER_5_EMAIL) + .emailVerified(USER_5_VERIFIED) + .databasePassword(USER_5_DATABASE_PASSWORD) + .build(); + + public final static UserDto USER_5_DTO = UserDto.builder() + .id(USER_5_ID) + .username(USER_5_USERNAME) + .email(USER_5_EMAIL) + .firstname(USER_5_FIRSTNAME) + .lastname(USER_5_LASTNAME) + .emailVerified(USER_5_VERIFIED) + .build(); + + public final static UserDetails USER_5_DETAILS = UserDetailsDto.builder() + .username(USER_5_USERNAME) + .email(USER_5_EMAIL) + .password(USER_5_PASSWORD) + .authorities(AUTHORITY_DEFAULT_RESEARCHER_AUTHORITIES) + .build(); + + public final static Principal USER_5_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_5_DETAILS, + USER_5_PASSWORD, USER_5_DETAILS.getAuthorities()); + + 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"; + 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 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("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(), + 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()); + + public final static List<ImageEnvItemDto> IMAGE_1_ENV_DTO = List.of(ImageEnvItemDto.builder() + .iid(IMAGE_1_ID) + .key("MARIADB_USER") + .value("mariadb") + .type(ImageEnvItemTypeDto.USERNAME) + .build(), + ImageEnvItemDto.builder() + .iid(IMAGE_1_ID) + .key("MARIADB_PASSWORD") + .value("mariadb") + .type(ImageEnvItemTypeDto.PASSWORD) + .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_UNIX_FORMAT = "yyyy-MM-dd"; + public final static String IMAGE_DATE_1_DATABASE_FORMAT = "%Y-%c-%d"; + public final static String IMAGE_DATE_1_EXAMPLE = "2022-01-30"; + public final static Boolean IMAGE_DATE_1_HAS_TIME = false; + + public final static ContainerImageDate IMAGE_DATE_1 = ContainerImageDate.builder() + .id(IMAGE_DATE_1_ID) + .iid(IMAGE_DATE_1_IMAGE_ID) + .unixFormat(IMAGE_DATE_1_UNIX_FORMAT) + .databaseFormat(IMAGE_DATE_1_DATABASE_FORMAT) + .example(IMAGE_DATE_1_EXAMPLE) + .hasTime(IMAGE_DATE_1_HAS_TIME) + .build(); + + public final static Long IMAGE_DATE_2_ID = 2L; + public final static Long IMAGE_DATE_2_IMAGE_ID = IMAGE_1_ID; + public final static String IMAGE_DATE_2_UNIX_FORMAT = "dd.MM.yy"; + public final static String IMAGE_DATE_2_DATABASE_FORMAT = "%d.%c.%y"; + public final static String IMAGE_DATE_2_EXAMPLE = "30.01.2022"; + public final static Boolean IMAGE_DATE_2_HAS_TIME = false; + + public final static ContainerImageDate IMAGE_DATE_2 = ContainerImageDate.builder() + .id(IMAGE_DATE_2_ID) + .iid(IMAGE_DATE_2_IMAGE_ID) + .unixFormat(IMAGE_DATE_2_UNIX_FORMAT) + .databaseFormat(IMAGE_DATE_2_DATABASE_FORMAT) + .example(IMAGE_DATE_2_EXAMPLE) + .hasTime(IMAGE_DATE_2_HAS_TIME) + .build(); + + public final static Long IMAGE_DATE_3_ID = 3L; + public final static Long IMAGE_DATE_3_IMAGE_ID = IMAGE_1_ID; + public final static String IMAGE_DATE_3_UNIX_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"; + public final static String IMAGE_DATE_3_DATABASE_FORMAT = "%Y-%c-%dT%H:%i:%S.%f"; + public final static String IMAGE_DATE_3_EXAMPLE = "2022-01-30T13:44:25.499"; + public final static Boolean IMAGE_DATE_3_HAS_TIME = true; + + public final static ContainerImageDate IMAGE_DATE_3 = ContainerImageDate.builder() + .id(IMAGE_DATE_3_ID) + .iid(IMAGE_DATE_3_IMAGE_ID) + .unixFormat(IMAGE_DATE_3_UNIX_FORMAT) + .databaseFormat(IMAGE_DATE_3_DATABASE_FORMAT) + .example(IMAGE_DATE_3_EXAMPLE) + .hasTime(IMAGE_DATE_3_HAS_TIME) + .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) + .dateFormats(List.of(IMAGE_DATE_1, IMAGE_DATE_2, IMAGE_DATE_3)) + .build(); + + public final static Long IMAGE_2_ID = 2L; + public final static String IMAGE_2_REPOSITORY = "mysql"; + public final static String IMAGE_2_TAG = "8.0"; + public final static String IMAGE_2_HASH = "83b40f2726e5"; + public final static Integer IMAGE_2_PORT = 3306; + public final static String IMAGE_2_DIALECT = "org.hibernate.dialect.MySQLDialect"; + public final static String IMAGE_2_DRIVER = "com.mysql.jdbc.Driver"; + public final static String IMAGE_2_JDBC = "mysql"; + public final static Long IMAGE_2_SIZE = 12000L; + public final static Instant IMAGE_2_BUILT = Instant.now().minus(38, HOURS); + + public final static List<ImageEnvItemDto> IMAGE_2_ENV_DTO = List.of(ImageEnvItemDto.builder() + .iid(IMAGE_2_ID) + .key("MYSQL_USER") + .value("mysql") + .type(ImageEnvItemTypeDto.USERNAME) + .build(), + ImageEnvItemDto.builder() + .iid(IMAGE_2_ID) + .key("MYSQL_PASSWORD") + .value("mysql") + .type(ImageEnvItemTypeDto.PASSWORD) + .build()); + + public final static Long IMAGE_BROKER_ID = 2L; + public final static String IMAGE_BROKER_REPOSITORY = "rabbitmq"; + public final static String IMAGE_BROKER_TAG = "3-management-alpine"; + public final static String IMAGE_BROKER_HASH = "d6a5e003eae42397f7ee4589e9f21e231d3721ac131970d2286bd616e7f55bb4\n"; + public final static String IMAGE_BROKER_DIALECT = "org.hibernate.dialect.MariaDBDialect"; + public final static String IMAGE_BROKER_DRIVER = "org.mariadb.jdbc.Driver"; + public final static String IMAGE_BROKER_JDBC = "mariadb"; + public final static Integer IMAGE_BROKER_PORT = 15672; + public final static Long IMAGE_BROKER_SIZE = 12000L; + public final static Instant IMAGE_BROKER_BUILT = Instant.now().minus(40, HOURS); + + public final static ContainerImage IMAGE_BROKER = ContainerImage.builder() + .id(IMAGE_BROKER_ID) + .repository(IMAGE_BROKER_REPOSITORY) + .tag(IMAGE_BROKER_TAG) + .hash(IMAGE_BROKER_HASH) + .compiled(IMAGE_BROKER_BUILT) + .dialect(IMAGE_BROKER_DIALECT) + .jdbcMethod(IMAGE_BROKER_JDBC) + .driverClass(IMAGE_BROKER_DRIVER) + .size(IMAGE_BROKER_SIZE) + .defaultPort(IMAGE_BROKER_PORT) + .build(); + + public final static Long IMAGE_ELASTIC_ID = 3L; + public final static String IMAGE_ELASTIC_REPOSITORY = "elasticsearch"; + public final static String IMAGE_ELASTIC_TAG = "7.13.4"; + + public final static ContainerImage IMAGE_ELASTIC = ContainerImage.builder() + .id(IMAGE_ELASTIC_ID) + .repository(IMAGE_ELASTIC_REPOSITORY) + .tag(IMAGE_ELASTIC_TAG) + .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 = "dbrepo-userdb-u01"; + public final static String CONTAINER_1_IP = "172.30.0.5"; + public final static Instant CONTAINER_1_CREATED = Instant.ofEpochSecond(1677399629) /* 2023-02-26 08:20:29 (UTC) */; + public final static HealthCheck CONTAINER_1_HEALTHCHECK = new HealthCheck() + .withTest(List.of("CMD", "mysqladmin", "ping", "--host=127.0.0.1", "--password=mariadb")); + public final static String[] CONTAINER_1_ENV = new String[]{"MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_DATABASE=weather"}; + + public final static Container CONTAINER_1 = Container.builder() + .id(CONTAINER_1_ID) + .name(CONTAINER_1_NAME) + .internalName(CONTAINER_1_INTERNALNAME) + .imageId(IMAGE_1_ID) + .image(CONTAINER_1_IMAGE) + .hash(CONTAINER_1_HASH) + .created(CONTAINER_1_CREATED) + .ipAddress(CONTAINER_1_IP) + .creator(USER_1) + .owner(USER_1) + .build(); + + 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 = "dbrepo-userdb-u02"; + public final static String CONTAINER_2_IP = "172.30.0.6"; + public final static Instant CONTAINER_2_CREATED = Instant.ofEpochSecond(1677399655) /* 2023-02-26 08:20:55 (UTC) */; + public final static HealthCheck CONTAINER_2_HEALTHCHECK = new HealthCheck() + .withTest(List.of("CMD", "mysqladmin", "ping", "--host=127.0.0.1", "--password=mariadb")); + public final static String[] CONTAINER_2_ENV = new String[]{"MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_DATABASE=zoo"}; + + public final static Container CONTAINER_2 = Container.builder() + .id(CONTAINER_2_ID) + .name(CONTAINER_2_NAME) + .internalName(CONTAINER_2_INTERNALNAME) + .imageId(IMAGE_1_ID) + .image(CONTAINER_2_IMAGE) + .hash(CONTAINER_2_HASH) + .created(CONTAINER_2_CREATED) + .ipAddress(CONTAINER_2_IP) + .creator(USER_2) + .owner(USER_2) + .build(); + + 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 = "dbrepo-userdb-u03"; + public final static String CONTAINER_3_IP = "172.30.0.7"; + public final static Instant CONTAINER_3_CREATED = Instant.ofEpochSecond(1677399672) /* 2023-02-26 08:21:12 (UTC) */; + public final static HealthCheck CONTAINER_3_HEALTHCHECK = new HealthCheck() + .withTest(List.of("CMD", "mysqladmin", "ping", "--host=127.0.0.1", "--password=mariadb")); + public final static String[] CONTAINER_3_ENV = new String[]{"MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_DATABASE=musicology"}; + + public final static Container CONTAINER_3 = Container.builder() + .id(CONTAINER_3_ID) + .name(CONTAINER_3_NAME) + .internalName(CONTAINER_3_INTERNALNAME) + .imageId(IMAGE_1_ID) + .image(CONTAINER_3_IMAGE) + .hash(CONTAINER_3_HASH) + .created(CONTAINER_3_CREATED) + .ipAddress(CONTAINER_3_IP) + .creator(USER_3) + .owner(USER_3) + .build(); + + public final static Long CONTAINER_4_ID = 4L; + public final static String CONTAINER_4_HASH = "deadbeef"; + public final static ContainerImage CONTAINER_4_IMAGE = IMAGE_1; + public final static String CONTAINER_4_NAME = "u04"; + public final static String CONTAINER_4_INTERNALNAME = "dbrepo-userdb-u04"; + public final static String CONTAINER_4_IP = "172.30.0.8"; + public final static Instant CONTAINER_4_CREATED = Instant.ofEpochSecond(1677399688) /* 2023-02-26 08:21:28 (UTC) */; + public final static HealthCheck CONTAINER_4_HEALTHCHECK = new HealthCheck() + .withTest(List.of("CMD", "mysqladmin", "ping", "--host=127.0.0.1", "--password=mariadb")); + public final static String[] CONTAINER_4_ENV = new String[]{"MARIADB_ROOT_PASSWORD=mariadb", "MARIADB_DATABASE=sensor"}; + + public final static Container CONTAINER_4 = Container.builder() + .id(CONTAINER_4_ID) + .name(CONTAINER_4_NAME) + .internalName(CONTAINER_4_INTERNALNAME) + .imageId(IMAGE_1_ID) + .image(CONTAINER_4_IMAGE) + .hash(CONTAINER_4_HASH) + .created(CONTAINER_4_CREATED) + .ipAddress(CONTAINER_4_IP) + .creator(USER_4) + .owner(USER_4) + .build(); + + public final static Long CONTAINER_BROKER_ID = 5L; + public final static String CONTAINER_BROKER_NAME = "dbrepo-broker-service"; + public final static String CONTAINER_BROKER_INTERNAL_NAME = "dbrepo-broker-service"; + public final static String CONTAINER_BROKER_IP = "172.31.0.2"; + public final static String CONTAINER_BROKER_HASH = "deadbeef"; + public final static Instant CONTAINER_BROKER_CREATED = Instant.ofEpochSecond(1677399705) /* 2023-02-26 08:21:45 (UTC) */; + public final static HealthCheck CONTAINER_BROKER_HEALTHCHECK = new HealthCheck() + .withTest(List.of("CMD", "rabbitmq-diagnostics", "-q", "ping")); + public final static String[] CONTAINER_BROKER_ENV = new String[]{}; + + public final static Container CONTAINER_BROKER = Container.builder() + .id(CONTAINER_BROKER_ID) + .name(CONTAINER_BROKER_NAME) + .internalName(CONTAINER_BROKER_INTERNAL_NAME) + .imageId(IMAGE_BROKER_ID) + .image(IMAGE_BROKER) + .ipAddress(CONTAINER_BROKER_IP) + .hash(CONTAINER_BROKER_HASH) + .created(CONTAINER_BROKER_CREATED) + .creator(USER_1) + .build(); + + public final static Long CONTAINER_ELASTIC_ID = 6L; + public final static String CONTAINER_ELASTIC_NAME = "dbrepo-search-service"; + public final static String CONTAINER_ELASTIC_INTERNAL_NAME = "dbrepo-search-service"; + public final static String CONTAINER_ELASTIC_IP = "172.31.0.3"; + public final static String CONTAINER_ELASTIC_HASH = "deadbeef"; + public final static Instant CONTAINER_ELASTIC_CREATED = Instant.ofEpochSecond(1677399721) /* 2023-02-26 08:22:01 (UTC) */; + public final static String[] CONTAINER_ELASTIC_ENV = new String[]{"discovery.type=single-node", "ES_JAVA_OPTS=-Xms2g -Xmx2g", + "logger.level=WARN", "bootstrap.memory_lock=true", "xpack.security.enabled=true", "ELASTIC_PASSWORD=elastic"}; + + public final static Container CONTAINER_ELASTIC = Container.builder() + .id(CONTAINER_ELASTIC_ID) + .name(CONTAINER_ELASTIC_NAME) + .internalName(CONTAINER_ELASTIC_INTERNAL_NAME) + .imageId(IMAGE_ELASTIC_ID) + .image(IMAGE_ELASTIC) + .hash(CONTAINER_ELASTIC_HASH) + .ipAddress(CONTAINER_ELASTIC_IP) + .created(CONTAINER_ELASTIC_CREATED) + .creator(USER_1) + .build(); + + public final static Long DATABASE_1_ID = 1L; + public final static String DATABASE_1_NAME = "Weather"; + public final static String DATABASE_1_DESCRIPTION = "Weather in Australia"; + public final static String DATABASE_1_INTERNALNAME = "weather"; + public final static Boolean DATABASE_1_PUBLIC = false; + public final static String DATABASE_1_EXCHANGE = "dbrepo." + CONTAINER_1_INTERNALNAME; + public final static Instant DATABASE_1_CREATED = Instant.ofEpochSecond(1677399741) /* 2023-02-26 08:22:21 (UTC) */; + public final static Instant DATABASE_1_LAST_MODIFIED = Instant.ofEpochSecond(1677399741) /* 2023-02-26 08:22:21 (UTC) */; + public final static User DATABASE_1_OWNER = USER_1; + public final static User DATABASE_1_CREATOR = USER_1; + + public final static Database DATABASE_1 = Database.builder() + .id(DATABASE_1_ID) + .created(Instant.now().minus(1, HOURS)) + .lastModified(Instant.now()) + .isPublic(DATABASE_1_PUBLIC) + .name(DATABASE_1_NAME) + .description(DATABASE_1_DESCRIPTION) + .container(CONTAINER_1) + .internalName(DATABASE_1_INTERNALNAME) + .exchangeName(DATABASE_1_EXCHANGE) + .created(DATABASE_1_CREATED) + .lastModified(DATABASE_1_LAST_MODIFIED) + .creator(DATABASE_1_CREATOR) + .owner(DATABASE_1_OWNER) + .tables(List.of()) /* TABLE_1, TABLE_2, TABLE_3, TABLE_7 */ + .views(List.of()) + .build(); + + public final static DatabaseDto DATABASE_1_DTO = DatabaseDto.builder() + .id(DATABASE_1_ID) + .created(Instant.now().minus(1, HOURS)) + .isPublic(DATABASE_1_PUBLIC) + .name(DATABASE_1_NAME) + .internalName(DATABASE_1_INTERNALNAME) + .exchangeName(DATABASE_1_EXCHANGE) + .tables(List.of()) /* TABLE_1, TABLE_2, TABLE_3, TABLE_7 */ + .views(List.of()) + .build(); + + public final static DatabaseAccess DATABASE_1_RESEARCHER_READ_ACCESS = DatabaseAccess.builder() + .type(AccessType.READ) + .hdbid(DATABASE_1_ID) + .huserid(USER_1_ID) + .build(); + + public final static DatabaseAccess DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_OWN) + .hdbid(DATABASE_1_ID) + .huserid(USER_1_ID) + .build(); + + public final static DatabaseAccess DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_ALL) + .hdbid(DATABASE_1_ID) + .huserid(USER_1_ID) + .build(); + + public final static DatabaseAccess DATABASE_1_DEVELOPER_READ_ACCESS = DatabaseAccess.builder() + .type(AccessType.READ) + .hdbid(DATABASE_1_ID) + .huserid(USER_2_ID) + .build(); + + public final static DatabaseAccess DATABASE_1_DEVELOPER_WRITE_OWN_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_OWN) + .hdbid(DATABASE_1_ID) + .huserid(USER_2_ID) + .build(); + + public final static DatabaseAccess DATABASE_1_DEVELOPER_WRITE_ALL_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_ALL) + .hdbid(DATABASE_1_ID) + .huserid(USER_2_ID) + .build(); + + public final static DatabaseAccess DATABASE_1_DATA_STEWARD_READ_ACCESS = DatabaseAccess.builder() + .type(AccessType.READ) + .hdbid(DATABASE_1_ID) + .huserid(USER_3_ID) + .build(); + + public final static DatabaseAccess DATABASE_1_DATA_STEWARD_WRITE_OWN_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_OWN) + .hdbid(DATABASE_1_ID) + .huserid(USER_3_ID) + .build(); + + public final static DatabaseAccess DATABASE_1_DATA_STEWARD_WRITE_ALL_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_ALL) + .hdbid(DATABASE_1_ID) + .huserid(USER_3_ID) + .build(); + + public final static DatabaseCreateDto DATABASE_1_CREATE = DatabaseCreateDto.builder() + .name(DATABASE_1_NAME) + .isPublic(DATABASE_1_PUBLIC) + .build(); + + public final static Long DATABASE_2_ID = 2L; + public final static String DATABASE_2_NAME = "Zoo"; + public final static String DATABASE_2_DESCRIPTION = "Zoo data"; + public final static String DATABASE_2_INTERNALNAME = "zoo"; + public final static Boolean DATABASE_2_PUBLIC = false; + public final static String DATABASE_2_EXCHANGE = "dbrepo." + CONTAINER_2_INTERNALNAME; + public final static Instant DATABASE_2_CREATED = Instant.ofEpochSecond(1677399772) /* 2023-02-26 08:22:52 (UTC) */; + public final static Instant DATABASE_2_LAST_MODIFIED = Instant.ofEpochSecond(1677399772) /* 2023-02-26 08:22:52 (UTC) */; + public final static User DATABASE_2_OWNER = USER_2; + public final static User DATABASE_2_CREATOR = USER_2; + + public final static Database DATABASE_2 = Database.builder() + .id(DATABASE_2_ID) + .created(DATABASE_1_CREATED) + .lastModified(Instant.now()) + .isPublic(DATABASE_2_PUBLIC) + .name(DATABASE_2_NAME) + .description(DATABASE_2_DESCRIPTION) + .container(CONTAINER_2) + .internalName(DATABASE_2_INTERNALNAME) + .exchangeName(DATABASE_2_EXCHANGE) + .created(DATABASE_2_CREATED) + .lastModified(DATABASE_2_LAST_MODIFIED) + .creator(DATABASE_2_CREATOR) + .owner(DATABASE_2_OWNER) + .tables(List.of()) /* TABLE_4, TABLE_5, TABLE_6 */ + .views(List.of()) /* VIEW_4 */ + .build(); + + public final static DatabaseDto DATABASE_2_DTO = DatabaseDto.builder() + .id(DATABASE_2_ID) + .created(DATABASE_2_CREATED) + .isPublic(DATABASE_2_PUBLIC) + .name(DATABASE_2_NAME) + .internalName(DATABASE_2_INTERNALNAME) + .exchangeName(DATABASE_2_EXCHANGE) + .tables(List.of()) /* TABLE_2, TABLE_2, TABLE_3 */ + .views(List.of()) + .build(); + + public final static DatabaseAccess DATABASE_2_RESEARCHER_READ_ACCESS = DatabaseAccess.builder() + .type(AccessType.READ) + .hdbid(DATABASE_2_ID) + .huserid(USER_1_ID) + .build(); + + public final static DatabaseAccess DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_OWN) + .hdbid(DATABASE_2_ID) + .huserid(USER_1_ID) + .build(); + + public final static DatabaseAccess DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_ALL) + .hdbid(DATABASE_2_ID) + .huserid(USER_1_ID) + .build(); + + public final static DatabaseAccess DATABASE_2_RESEARCHER2_WRITE_OWN_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_OWN) + .hdbid(DATABASE_2_ID) + .huserid(USER_2_ID) + .build(); + + public final static DatabaseAccess DATABASE_2_DEVELOPER_READ_ACCESS = DatabaseAccess.builder() + .type(AccessType.READ) + .hdbid(DATABASE_2_ID) + .huserid(USER_2_ID) + .build(); + + public final static DatabaseAccess DATABASE_2_DEVELOPER_WRITE_OWN_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_OWN) + .hdbid(DATABASE_2_ID) + .huserid(USER_2_ID) + .build(); + + public final static DatabaseAccess DATABASE_2_DEVELOPER_WRITE_ALL_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_ALL) + .hdbid(DATABASE_2_ID) + .huserid(USER_2_ID) + .build(); + + public final static DatabaseAccess DATABASE_2_DATA_STEWARD_READ_ACCESS = DatabaseAccess.builder() + .type(AccessType.READ) + .hdbid(DATABASE_2_ID) + .huserid(USER_3_ID) + .build(); + + public final static DatabaseAccess DATABASE_2_DATA_STEWARD_WRITE_OWN_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_OWN) + .hdbid(DATABASE_2_ID) + .huserid(USER_3_ID) + .build(); + + public final static DatabaseAccess DATABASE_2_DATA_STEWARD_WRITE_ALL_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_ALL) + .hdbid(DATABASE_2_ID) + .huserid(USER_3_ID) + .build(); + + public final static DatabaseCreateDto DATABASE_2_CREATE = DatabaseCreateDto.builder() + .name(DATABASE_2_NAME) + .isPublic(DATABASE_2_PUBLIC) + .build(); + + public final static Long DATABASE_3_ID = 3L; + public final static String DATABASE_3_NAME = "Musicology"; + public final static String DATABASE_3_DESCRIPTION = "Musicology data"; + public final static String DATABASE_3_INTERNALNAME = "musicology"; + public final static Boolean DATABASE_3_PUBLIC = true; + public final static String DATABASE_3_EXCHANGE = "dbrepo." + CONTAINER_3_INTERNALNAME; + public final static Instant DATABASE_3_CREATED = Instant.ofEpochSecond(1677399792) /* 2023-02-26 08:23:12 (UTC) */; + public final static Instant DATABASE_3_LAST_MODIFIED = Instant.ofEpochSecond(1677399792) /* 2023-02-26 08:23:12 (UTC) */; + public final static User DATABASE_3_OWNER = USER_3; + public final static User DATABASE_3_CREATOR = USER_3; + + public final static Database DATABASE_3 = Database.builder() + .id(DATABASE_3_ID) + .created(Instant.now().minus(1, HOURS)) + .lastModified(Instant.now()) + .isPublic(DATABASE_3_PUBLIC) + .name(DATABASE_3_NAME) + .description(DATABASE_3_DESCRIPTION) + .container(CONTAINER_3) + .internalName(DATABASE_3_INTERNALNAME) + .exchangeName(DATABASE_3_EXCHANGE) + .created(DATABASE_3_CREATED) + .lastModified(DATABASE_3_LAST_MODIFIED) + .creator(DATABASE_3_CREATOR) + .owner(DATABASE_3_OWNER) + .tables(List.of()) /* TABLE_8 */ + .views(List.of()) /* VIEW_5 */ + .build(); + + public final static DatabaseDto DATABASE_3_DTO = DatabaseDto.builder() + .id(DATABASE_3_ID) + .created(DATABASE_3_CREATED) + .isPublic(DATABASE_3_PUBLIC) + .name(DATABASE_3_NAME) + .internalName(DATABASE_3_INTERNALNAME) + .exchangeName(DATABASE_3_EXCHANGE) + .tables(List.of()) /* TABLE_3, TABLE_3, TABLE_3 */ + .views(List.of()) + .build(); + + public final static DatabaseAccess DATABASE_3_RESEARCHER_READ_ACCESS = DatabaseAccess.builder() + .type(AccessType.READ) + .hdbid(DATABASE_3_ID) + .huserid(USER_1_ID) + .build(); + + public final static DatabaseAccess DATABASE_3_RESEARCHER_WRITE_OWN_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_OWN) + .hdbid(DATABASE_3_ID) + .huserid(USER_1_ID) + .build(); + + public final static DatabaseAccess DATABASE_3_RESEARCHER_WRITE_ALL_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_ALL) + .hdbid(DATABASE_3_ID) + .huserid(USER_1_ID) + .build(); + + public final static DatabaseAccess DATABASE_3_DEVELOPER_READ_ACCESS = DatabaseAccess.builder() + .type(AccessType.READ) + .hdbid(DATABASE_3_ID) + .huserid(USER_2_ID) + .build(); + + public final static DatabaseAccess DATABASE_3_DEVELOPER_WRITE_OWN_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_OWN) + .hdbid(DATABASE_3_ID) + .huserid(USER_2_ID) + .build(); + + public final static DatabaseAccess DATABASE_3_DEVELOPER_WRITE_ALL_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_ALL) + .hdbid(DATABASE_3_ID) + .huserid(USER_2_ID) + .build(); + + public final static DatabaseAccess DATABASE_3_DATA_STEWARD_READ_ACCESS = DatabaseAccess.builder() + .type(AccessType.READ) + .hdbid(DATABASE_3_ID) + .huserid(USER_3_ID) + .build(); + + public final static DatabaseAccess DATABASE_3_DATA_STEWARD_WRITE_OWN_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_OWN) + .hdbid(DATABASE_3_ID) + .huserid(USER_3_ID) + .build(); + + public final static DatabaseAccess DATABASE_3_DATA_STEWARD_WRITE_ALL_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_ALL) + .hdbid(DATABASE_3_ID) + .huserid(USER_3_ID) + .build(); + + public final static DatabaseCreateDto DATABASE_3_CREATE = DatabaseCreateDto.builder() + .name(DATABASE_3_NAME) + .isPublic(DATABASE_3_PUBLIC) + .build(); + + public final static Long DATABASE_4_ID = 4L; + public final static String DATABASE_4_NAME = "Weather AT"; + public final static String DATABASE_4_DESCRIPTION = "Weather data"; + public final static Boolean DATABASE_4_PUBLIC = true; + public final static String DATABASE_4_INTERNALNAME = "weather_at"; + public final static String DATABASE_4_EXCHANGE = DATABASE_4_INTERNALNAME; + public final static Instant DATABASE_4_CREATED = Instant.ofEpochSecond(1677399813) /* 2023-02-26 08:23:33 (UTC) */; + public final static Instant DATABASE_4_LAST_MODIFIED = Instant.ofEpochSecond(1677399813) /* 2023-02-26 08:23:33 (UTC) */; + + public final static Database DATABASE_4 = Database.builder() + .id(DATABASE_4_ID) + .created(Instant.now().minus(4, HOURS)) + .lastModified(Instant.now()) + .isPublic(DATABASE_4_PUBLIC) + .name(DATABASE_4_NAME) + .description(DATABASE_4_DESCRIPTION) + .container(CONTAINER_4) + .internalName(DATABASE_4_INTERNALNAME) + .exchangeName(DATABASE_4_EXCHANGE) + .created(DATABASE_4_CREATED) + .lastModified(DATABASE_4_LAST_MODIFIED) + .creator(USER_4) + .owner(USER_4) + .tables(List.of()) + .views(List.of()) + .build(); + + public final static DatabaseAccess DATABASE_4_RESEARCHER_READ_ACCESS = DatabaseAccess.builder() + .type(AccessType.READ) + .hdbid(DATABASE_4_ID) + .huserid(USER_1_ID) + .build(); + + public final static DatabaseAccess DATABASE_4_RESEARCHER_WRITE_OWN_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_OWN) + .hdbid(DATABASE_4_ID) + .huserid(USER_1_ID) + .build(); + + public final static DatabaseAccess DATABASE_4_RESEARCHER_WRITE_ALL_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_ALL) + .hdbid(DATABASE_4_ID) + .huserid(USER_1_ID) + .build(); + + public final static DatabaseAccess DATABASE_4_DEVELOPER_READ_ACCESS = DatabaseAccess.builder() + .type(AccessType.READ) + .hdbid(DATABASE_4_ID) + .huserid(USER_2_ID) + .build(); + + public final static DatabaseAccess DATABASE_4_DEVELOPER_WRITE_OWN_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_OWN) + .hdbid(DATABASE_4_ID) + .huserid(USER_2_ID) + .build(); + + public final static DatabaseAccess DATABASE_4_DEVELOPER_WRITE_ALL_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_ALL) + .hdbid(DATABASE_4_ID) + .huserid(USER_2_ID) + .build(); + + public final static DatabaseAccess DATABASE_4_DATA_STEWARD_READ_ACCESS = DatabaseAccess.builder() + .type(AccessType.READ) + .hdbid(DATABASE_4_ID) + .huserid(USER_3_ID) + .build(); + + public final static DatabaseAccess DATABASE_4_DATA_STEWARD_WRITE_OWN_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_OWN) + .hdbid(DATABASE_4_ID) + .huserid(USER_3_ID) + .build(); + + public final static DatabaseAccess DATABASE_4_DATA_STEWARD_WRITE_ALL_ACCESS = DatabaseAccess.builder() + .type(AccessType.WRITE_ALL) + .hdbid(DATABASE_4_ID) + .huserid(USER_3_ID) + .build(); + + 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_QUEUE_NAME = DATABASE_1_EXCHANGE + "." + TABLE_1_INTERNALNAME; + public final static String TABLE_1_ROUTING_KEY = TABLE_1_QUEUE_NAME; + public final static Instant TABLE_1_CREATED = Instant.ofEpochSecond(1677399975) /* 2023-02-26 08:26:15 (UTC) */; + public final static Instant TABLE_1_LAST_MODIFIED = Instant.ofEpochSecond(1677399975) /* 2023-02-26 08:26:15 (UTC) */; + + public final static Long TABLE_2_ID = 2L; + public final static String TABLE_2_NAME = "Weather Location"; + public final static String TABLE_2_INTERNALNAME = "weather_location"; + public final static String TABLE_2_DESCRIPTION = "Weather location"; + public final static String TABLE_2_QUEUE_NAME = DATABASE_1_EXCHANGE + "." + TABLE_2_INTERNALNAME; + public final static String TABLE_2_ROUTING_KEY = TABLE_2_QUEUE_NAME; + public final static Instant TABLE_2_CREATED = Instant.ofEpochSecond(1677400007) /* 2023-02-26 08:26:47 (UTC) */; + public final static Instant TABLE_2_LAST_MODIFIED = Instant.ofEpochSecond(1677400007) /* 2023-02-26 08:26:47 (UTC) */; + + public final static Long TABLE_3_ID = 3L; + public final static String TABLE_3_NAME = "Traffic Zürich"; + public final static String TABLE_3_INTERNALNAME = "traffic_zurich"; + public final static String TABLE_3_DESCRIPTION = "https://www.kaggle.com/laa283/zurich-public-transport/version/2"; + public final static String TABLE_3_QUEUE_NAME = DATABASE_1_EXCHANGE + "." + TABLE_3_INTERNALNAME; + public final static String TABLE_3_ROUTING_KEY = TABLE_3_QUEUE_NAME; + public final static Instant TABLE_3_CREATED = Instant.ofEpochSecond(1677400031) /* 2023-02-26 08:27:11 (UTC) */; + public final static Instant TABLE_3_LAST_MODIFIED = Instant.ofEpochSecond(1677400031) /* 2023-02-26 08:27:11 (UTC) */; + + public final static ConstraintsCreateDto TABLE_3_CONSTRAINTS_CREATE_DTO = ConstraintsCreateDto.builder() + .uniques(List.of(List.of("id"))) + .build(); + + public final static ConstraintsCreateDto TABLE_3_CONSTRAINTS_INVALID_CREATE_DTO = ConstraintsCreateDto.builder() + .uniques(List.of(List.of("id"))) + .foreignKeys(List.of(ForeignKeyCreateDto.builder() + .referencedTable("weather_location") + .columns(List.of("fahrzeug")) + .referencedColumns(List.of("doesnotexist")).build())) + .build(); + + public final static TableCreateDto TABLE_3_CREATE_DTO = TableCreateDto.builder() + .name(TABLE_3_NAME) + .description(TABLE_3_DESCRIPTION) + .columns(List.of()) + .constraints(TABLE_3_CONSTRAINTS_CREATE_DTO) + .build(); + + public final static TableCreateDto TABLE_3_INVALID_CREATE_DTO = TableCreateDto.builder() + .name(TABLE_3_NAME) + .description(TABLE_3_DESCRIPTION) + .columns(List.of()) + .constraints(TABLE_3_CONSTRAINTS_INVALID_CREATE_DTO) + .build(); + + public final static Long TABLE_4_ID = 4L; + public final static String TABLE_4_NAME = "zoo"; + public final static String TABLE_4_INTERNALNAME = "zoo"; + public final static String TABLE_4_DESCRIPTION = "Some Kaggle dataset"; + public final static String TABLE_4_QUEUE_NAME = DATABASE_2_EXCHANGE + "." + TABLE_4_INTERNALNAME; + public final static String TABLE_4_ROUTING_KEY = TABLE_4_QUEUE_NAME; + public final static Instant TABLE_4_CREATED = Instant.ofEpochSecond(1677400067) /* 2023-02-26 08:27:47 (UTC) */; + public final static Instant TABLE_4_LAST_MODIFIED = Instant.ofEpochSecond(1677400067) /* 2023-02-26 08:27:47 (UTC) */; + + public final static TableCsvDto TABLE_4_CSV_DTO = TableCsvDto.builder() + .data(new HashMap<>() {{ + put("id", "102"); + }}) + .build(); + + public final static Long TABLE_5_ID = 5L; + public final static String TABLE_5_NAME = "names"; + public final static String TABLE_5_INTERNALNAME = "names"; + public final static String TABLE_5_DESCRIPTION = "Some names dataset"; + public final static String TABLE_5_QUEUE_NAME = DATABASE_2_EXCHANGE + "." + TABLE_5_INTERNALNAME; + public final static String TABLE_5_ROUTING_KEY = TABLE_5_QUEUE_NAME; + public final static Instant TABLE_5_CREATED = Instant.ofEpochSecond(1677400117) /* 2023-02-26 08:28:37 (UTC) */; + public final static Instant TABLE_5_LAST_MODIFIED = Instant.ofEpochSecond(1677400117) /* 2023-02-26 08:28:37 (UTC) */; + + public final static Long TABLE_6_ID = 6L; + public final static String TABLE_6_NAME = "likes"; + public final static String TABLE_6_INTERNAL_NAME = "likes"; + public final static String TABLE_6_DESCRIPTION = "Some likes dataset"; + public final static String TABLE_6_QUEUE_NAME = DATABASE_2_EXCHANGE + "." + TABLE_6_INTERNAL_NAME; + public final static String TABLE_6_ROUTING_KEY = TABLE_6_QUEUE_NAME; + public final static Instant TABLE_6_CREATED = Instant.ofEpochSecond(1677400147) /* 2023-02-26 08:29:07 (UTC) */; + public final static Instant TABLE_6_LAST_MODIFIED = Instant.ofEpochSecond(1677400147) /* 2023-02-26 08:29:07 (UTC) */; + + public final static Long TABLE_7_ID = 7L; + public final static String TABLE_7_NAME = "Sensor"; + public final static String TABLE_7_INTERNAL_NAME = "sensor"; + public final static String TABLE_7_DESCRIPTION = "Hello sensor"; + public final static String TABLE_7_QUEUE_NAME = DATABASE_1_EXCHANGE + "." + TABLE_7_INTERNAL_NAME; + public final static String TABLE_7_ROUTING_KEY = TABLE_7_QUEUE_NAME; + public final static Instant TABLE_7_CREATED = Instant.ofEpochSecond(1677400175) /* 2023-02-26 08:29:35 (UTC) */; + public final static Instant TABLE_7_LAST_MODIFIED = Instant.ofEpochSecond(1677400175) /* 2023-02-26 08:29:35 (UTC) */; + + public final static Table TABLE_7 = Table.builder() + .id(TABLE_7_ID) + .created(Instant.now()) + .internalName(TABLE_7_INTERNAL_NAME) + .description(TABLE_7_DESCRIPTION) + .name(TABLE_7_NAME) + .tdbid(DATABASE_1_ID) + .queueName(TABLE_7_QUEUE_NAME) + .routingKey(TABLE_7_ROUTING_KEY) + .columns(List.of(TableColumn.builder() + .id(1L) + .ordinalPosition(0) + .cdbid(DATABASE_1_ID) + .tid(TABLE_1_ID) + .name("Timestamp") + .internalName("timestamp") + .columnType(TableColumnType.TIMESTAMP) + .dfid(IMAGE_DATE_3_ID) + .isNullAllowed(false) + .autoGenerated(false) + .isPrimaryKey(true) + .build(), + TableColumn.builder() + .id(2L) + .ordinalPosition(1) + .cdbid(DATABASE_1_ID) + .tid(TABLE_1_ID) + .name("Value") + .internalName("value") + .columnType(TableColumnType.DECIMAL) + .dfid(null) + .isNullAllowed(true) + .autoGenerated(false) + .isPrimaryKey(false) + .build())) + .creator(USER_1) + .created(TABLE_7_CREATED) + .lastModified(TABLE_7_LAST_MODIFIED) + .build(); + + public final static Long TABLE_8_ID = 8L; + public final static String TABLE_8_NAME = "mfcc"; + public final static String TABLE_8_INTERNAL_NAME = "mfcc"; + public final static String TABLE_8_DESCRIPTION = "Hello mfcc"; + public final static String TABLE_8_QUEUE_NAME = DATABASE_3_EXCHANGE + "." + TABLE_8_INTERNAL_NAME; + public final static String TABLE_8_ROUTING_KEY = TABLE_8_QUEUE_NAME; + public final static Instant TABLE_8_CREATED = Instant.ofEpochSecond(1688400185) /* 2023-02-26 08:29:35 (UTC) */; + public final static Instant TABLE_8_LAST_MODIFIED = Instant.ofEpochSecond(1688400185) /* 2023-02-26 08:29:35 (UTC) */; + + public final static Table TABLE_8 = Table.builder() + .id(TABLE_8_ID) + .created(Instant.now()) + .internalName(TABLE_8_INTERNAL_NAME) + .description(TABLE_8_DESCRIPTION) + .name(TABLE_8_NAME) + .tdbid(DATABASE_1_ID) + .queueName(TABLE_8_QUEUE_NAME) + .routingKey(TABLE_8_ROUTING_KEY) + .columns(List.of(TableColumn.builder() + .id(1L) + .ordinalPosition(0) + .cdbid(DATABASE_3_ID) + .tid(TABLE_8_ID) + .name("ID") + .internalName("id") + .columnType(TableColumnType.NUMBER) + .dfid(null) + .isNullAllowed(false) + .autoGenerated(true) + .isPrimaryKey(true) + .build(), + TableColumn.builder() + .id(2L) + .ordinalPosition(1) + .cdbid(DATABASE_3_ID) + .tid(TABLE_8_ID) + .name("Value") + .internalName("value") + .columnType(TableColumnType.DECIMAL) + .dfid(null) + .isNullAllowed(false) + .autoGenerated(false) + .isPrimaryKey(false) + .build())) + .creator(USER_1) + .created(TABLE_8_CREATED) + .lastModified(TABLE_8_LAST_MODIFIED) + .build(); + + public final static TableCsvDto TABLE_8_CSV_DTO = TableCsvDto.builder() + .data(new HashMap<>() {{ + put("value", "2.1"); + }}) + .build(); + + 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 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 Long COLUMN_1_2_DATE_FORMAT = IMAGE_DATE_1_ID; + 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 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 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 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 COLUMN_2_1_ID = 6L; + public final static Integer COLUMN_2_1_ORDINALPOS = 0; + public final static Boolean COLUMN_2_1_PRIMARY = true; + public final static String COLUMN_2_1_NAME = "location"; + public final static String COLUMN_2_1_INTERNAL_NAME = "location"; + public final static TableColumnType COLUMN_2_1_TYPE = TableColumnType.STRING; + public final static Long COLUMN_2_1_DATE_FORMAT = null; + public final static Boolean COLUMN_2_1_NULL = false; + public final static Boolean COLUMN_2_1_UNIQUE = true; + public final static Boolean COLUMN_2_1_AUTO_GENERATED = false; + public final static String COLUMN_2_1_FOREIGN_KEY = null; + public final static String COLUMN_2_1_CHECK = null; + public final static List<String> COLUMN_2_1_ENUM_VALUES = null; + + public final static Long COLUMN_2_2_ID = 7L; + public final static Integer COLUMN_2_2_ORDINALPOS = 0; + public final static Boolean COLUMN_2_2_PRIMARY = false; + public final static String COLUMN_2_2_NAME = "lat"; + public final static String COLUMN_2_2_INTERNAL_NAME = "lat"; + public final static TableColumnType COLUMN_2_2_TYPE = TableColumnType.DECIMAL; + public final static Long COLUMN_2_2_DATE_FORMAT = null; + public final static Boolean COLUMN_2_2_NULL = true; + public final static Boolean COLUMN_2_2_UNIQUE = false; + public final static Boolean COLUMN_2_2_AUTO_GENERATED = false; + public final static String COLUMN_2_2_FOREIGN_KEY = null; + public final static String COLUMN_2_2_CHECK = null; + public final static List<String> COLUMN_2_2_ENUM_VALUES = null; + + public final static Long COLUMN_2_3_ID = 8L; + public final static Integer COLUMN_2_3_ORDINALPOS = 0; + public final static Boolean COLUMN_2_3_PRIMARY = false; + public final static String COLUMN_2_3_NAME = "lng"; + public final static String COLUMN_2_3_INTERNAL_NAME = "lng"; + public final static TableColumnType COLUMN_2_3_TYPE = TableColumnType.DECIMAL; + public final static Long COLUMN_2_3_DATE_FORMAT = null; + public final static Boolean COLUMN_2_3_NULL = true; + public final static Boolean COLUMN_2_3_UNIQUE = false; + public final static Boolean COLUMN_2_3_AUTO_GENERATED = false; + public final static String COLUMN_2_3_FOREIGN_KEY = null; + public final static String COLUMN_2_3_CHECK = null; + public final static List<String> COLUMN_2_3_ENUM_VALUES = null; + + public final static Long COLUMN_4_1_ID = 9L; + public final static Integer COLUMN_4_1_ORDINALPOS = 0; + public final static Boolean COLUMN_4_1_PRIMARY = true; + public final static String COLUMN_4_1_NAME = "id"; + public final static String COLUMN_4_1_INTERNAL_NAME = "id"; + public final static TableColumnType COLUMN_4_1_TYPE = TableColumnType.NUMBER; + public final static Long COLUMN_4_1_DATE_FORMAT = null; + public final static Boolean COLUMN_4_1_NULL = false; + public final static Boolean COLUMN_4_1_UNIQUE = true; + public final static Boolean COLUMN_4_1_AUTO_GENERATED = true; + public final static String COLUMN_4_1_FOREIGN_KEY = null; + public final static String COLUMN_4_1_CHECK = null; + public final static List<String> COLUMN_4_1_ENUM_VALUES = null; + public final static ColumnTypeDto COLUMN_4_1_TYPE_DTO = ColumnTypeDto.NUMBER; + public final static String[] COLUMN_4_1_ENUM_VALUES_ARRAY = null; + + public final static Long COLUMN_4_2_ID = 10L; + public final static Integer COLUMN_4_2_ORDINALPOS = 1; + public final static Boolean COLUMN_4_2_PRIMARY = false; + public final static String COLUMN_4_2_NAME = "Animal Name"; + public final static String COLUMN_4_2_INTERNAL_NAME = "animal_name"; + public final static TableColumnType COLUMN_4_2_TYPE = TableColumnType.STRING; + public final static Long COLUMN_4_2_DATE_FORMAT = null; + public final static Boolean COLUMN_4_2_NULL = true; + public final static Boolean COLUMN_4_2_UNIQUE = false; + public final static Boolean COLUMN_4_2_AUTO_GENERATED = false; + public final static String COLUMN_4_2_FOREIGN_KEY = null; + public final static String COLUMN_4_2_CHECK = null; + public final static List<String> COLUMN_4_2_ENUM_VALUES = null; + public final static ColumnTypeDto COLUMN_4_2_TYPE_DTO = ColumnTypeDto.STRING; + public final static String[] COLUMN_4_2_ENUM_VALUES_ARRAY = null; + + public final static Long COLUMN_4_3_ID = 11L; + public final static Integer COLUMN_4_3_ORDINALPOS = 2; + public final static Boolean COLUMN_4_3_PRIMARY = false; + public final static String COLUMN_4_3_NAME = "Hair"; + public final static String COLUMN_4_3_INTERNAL_NAME = "hair"; + public final static TableColumnType COLUMN_4_3_TYPE = TableColumnType.BOOLEAN; + public final static Long COLUMN_4_3_DATE_FORMAT = null; + public final static Boolean COLUMN_4_3_NULL = true; + public final static Boolean COLUMN_4_3_UNIQUE = false; + public final static Boolean COLUMN_4_3_AUTO_GENERATED = false; + public final static String COLUMN_4_3_FOREIGN_KEY = null; + public final static String COLUMN_4_3_CHECK = null; + public final static List<String> COLUMN_4_3_ENUM_VALUES = null; + + public final static Long COLUMN_4_4_ID = 12L; + public final static Integer COLUMN_4_4_ORDINALPOS = 3; + public final static Boolean COLUMN_4_4_PRIMARY = false; + public final static String COLUMN_4_4_NAME = "Feathers"; + public final static String COLUMN_4_4_INTERNAL_NAME = "feathers"; + public final static TableColumnType COLUMN_4_4_TYPE = TableColumnType.BOOLEAN; + public final static Long COLUMN_4_4_DATE_FORMAT = null; + public final static Boolean COLUMN_4_4_NULL = true; + public final static Boolean COLUMN_4_4_UNIQUE = false; + public final static Boolean COLUMN_4_4_AUTO_GENERATED = false; + public final static String COLUMN_4_4_FOREIGN_KEY = null; + public final static String COLUMN_4_4_CHECK = null; + public final static List<String> COLUMN_4_4_ENUM_VALUES = null; + + public final static Long COLUMN_4_5_ID = 13L; + public final static Integer COLUMN_4_5_ORDINALPOS = 4; + public final static Boolean COLUMN_4_5_PRIMARY = false; + public final static String COLUMN_4_5_NAME = "Bread"; + public final static String COLUMN_4_5_INTERNAL_NAME = "bread"; + public final static TableColumnType COLUMN_4_5_TYPE = TableColumnType.BOOLEAN; + public final static Long COLUMN_4_5_DATE_FORMAT = null; + public final static Boolean COLUMN_4_5_NULL = true; + public final static Boolean COLUMN_4_5_UNIQUE = false; + public final static Boolean COLUMN_4_5_AUTO_GENERATED = false; + public final static String COLUMN_4_5_FOREIGN_KEY = null; + public final static String COLUMN_4_5_CHECK = null; + public final static List<String> COLUMN_4_5_ENUM_VALUES = null; + + public final static Long COLUMN_4_6_ID = 14L; + public final static Integer COLUMN_4_6_ORDINALPOS = 5; + public final static Boolean COLUMN_4_6_PRIMARY = false; + public final static String COLUMN_4_6_NAME = "Eggs"; + public final static String COLUMN_4_6_INTERNAL_NAME = "eggs"; + public final static TableColumnType COLUMN_4_6_TYPE = TableColumnType.BOOLEAN; + public final static Long COLUMN_4_6_DATE_FORMAT = null; + public final static Boolean COLUMN_4_6_NULL = true; + public final static Boolean COLUMN_4_6_UNIQUE = false; + public final static Boolean COLUMN_4_6_AUTO_GENERATED = false; + public final static String COLUMN_4_6_FOREIGN_KEY = null; + public final static String COLUMN_4_6_CHECK = null; + public final static List<String> COLUMN_4_6_ENUM_VALUES = null; + + public final static Long COLUMN_4_7_ID = 15L; + public final static Integer COLUMN_4_7_ORDINALPOS = 6; + public final static Boolean COLUMN_4_7_PRIMARY = false; + public final static String COLUMN_4_7_NAME = "Milk"; + public final static String COLUMN_4_7_INTERNAL_NAME = "milk"; + public final static TableColumnType COLUMN_4_7_TYPE = TableColumnType.BOOLEAN; + public final static Long COLUMN_4_7_DATE_FORMAT = null; + public final static Boolean COLUMN_4_7_NULL = true; + public final static Boolean COLUMN_4_7_UNIQUE = false; + public final static Boolean COLUMN_4_7_AUTO_GENERATED = false; + public final static String COLUMN_4_7_FOREIGN_KEY = null; + public final static String COLUMN_4_7_CHECK = null; + public final static List<String> COLUMN_4_7_ENUM_VALUES = null; + + public final static Long COLUMN_4_8_ID = 16L; + public final static Integer COLUMN_4_8_ORDINALPOS = 7; + public final static Boolean COLUMN_4_8_PRIMARY = false; + public final static String COLUMN_4_8_NAME = "Water"; + public final static String COLUMN_4_8_INTERNAL_NAME = "water"; + public final static TableColumnType COLUMN_4_8_TYPE = TableColumnType.BOOLEAN; + public final static Long COLUMN_4_8_DATE_FORMAT = null; + public final static Boolean COLUMN_4_8_NULL = true; + public final static Boolean COLUMN_4_8_UNIQUE = false; + public final static Boolean COLUMN_4_8_AUTO_GENERATED = false; + public final static String COLUMN_4_8_FOREIGN_KEY = null; + public final static String COLUMN_4_8_CHECK = null; + public final static List<String> COLUMN_4_8_ENUM_VALUES = null; + + public final static Long COLUMN_4_9_ID = 17L; + public final static Integer COLUMN_4_9_ORDINALPOS = 8; + public final static Boolean COLUMN_4_9_PRIMARY = false; + public final static String COLUMN_4_9_NAME = "Airborne"; + public final static String COLUMN_4_9_INTERNAL_NAME = "airborne"; + public final static TableColumnType COLUMN_4_9_TYPE = TableColumnType.BOOLEAN; + public final static Long COLUMN_4_9_DATE_FORMAT = null; + public final static Boolean COLUMN_4_9_NULL = true; + public final static Boolean COLUMN_4_9_UNIQUE = false; + public final static Boolean COLUMN_4_9_AUTO_GENERATED = false; + public final static String COLUMN_4_9_FOREIGN_KEY = null; + public final static String COLUMN_4_9_CHECK = null; + public final static List<String> COLUMN_4_9_ENUM_VALUES = null; + + public final static Long COLUMN_4_10_ID = 18L; + public final static Integer COLUMN_4_10_ORDINALPOS = 9; + public final static Boolean COLUMN_4_10_PRIMARY = false; + public final static String COLUMN_4_10_NAME = "Waterborne"; + public final static String COLUMN_4_10_INTERNAL_NAME = "waterborne"; + public final static TableColumnType COLUMN_4_10_TYPE = TableColumnType.BOOLEAN; + public final static Long COLUMN_4_10_DATE_FORMAT = null; + public final static Boolean COLUMN_4_10_NULL = true; + public final static Boolean COLUMN_4_10_UNIQUE = false; + public final static Boolean COLUMN_4_10_AUTO_GENERATED = false; + public final static String COLUMN_4_10_FOREIGN_KEY = null; + public final static String COLUMN_4_10_CHECK = null; + public final static List<String> COLUMN_4_10_ENUM_VALUES = null; + + public final static Long COLUMN_4_11_ID = 19L; + public final static Integer COLUMN_4_11_ORDINALPOS = 10; + public final static Boolean COLUMN_4_11_PRIMARY = false; + public final static String COLUMN_4_11_NAME = "Aquantic"; + public final static String COLUMN_4_11_INTERNAL_NAME = "aquatic"; + public final static TableColumnType COLUMN_4_11_TYPE = TableColumnType.BOOLEAN; + public final static Long COLUMN_4_11_DATE_FORMAT = null; + public final static Boolean COLUMN_4_11_NULL = true; + public final static Boolean COLUMN_4_11_UNIQUE = false; + public final static Boolean COLUMN_4_11_AUTO_GENERATED = false; + public final static String COLUMN_4_11_FOREIGN_KEY = null; + public final static String COLUMN_4_11_CHECK = null; + public final static List<String> COLUMN_4_11_ENUM_VALUES = null; + + public final static Long COLUMN_4_12_ID = 20L; + public final static Integer COLUMN_4_12_ORDINALPOS = 11; + public final static Boolean COLUMN_4_12_PRIMARY = false; + public final static String COLUMN_4_12_NAME = "Predator"; + public final static String COLUMN_4_12_INTERNAL_NAME = "predator"; + public final static TableColumnType COLUMN_4_12_TYPE = TableColumnType.BOOLEAN; + public final static Long COLUMN_4_12_DATE_FORMAT = null; + public final static Boolean COLUMN_4_12_NULL = true; + public final static Boolean COLUMN_4_12_UNIQUE = false; + public final static Boolean COLUMN_4_12_AUTO_GENERATED = false; + public final static String COLUMN_4_12_FOREIGN_KEY = null; + public final static String COLUMN_4_12_CHECK = null; + public final static List<String> COLUMN_4_12_ENUM_VALUES = null; + + public final static Long COLUMN_4_13_ID = 21L; + public final static Integer COLUMN_4_13_ORDINALPOS = 12; + public final static Boolean COLUMN_4_13_PRIMARY = false; + public final static String COLUMN_4_13_NAME = "Backbone"; + public final static String COLUMN_4_13_INTERNAL_NAME = "backbone"; + public final static TableColumnType COLUMN_4_13_TYPE = TableColumnType.BOOLEAN; + public final static Long COLUMN_4_13_DATE_FORMAT = null; + public final static Boolean COLUMN_4_13_NULL = true; + public final static Boolean COLUMN_4_13_UNIQUE = false; + public final static Boolean COLUMN_4_13_AUTO_GENERATED = false; + public final static String COLUMN_4_13_FOREIGN_KEY = null; + public final static String COLUMN_4_13_CHECK = null; + public final static List<String> COLUMN_4_13_ENUM_VALUES = null; + + public final static Long COLUMN_4_14_ID = 22L; + public final static Integer COLUMN_4_14_ORDINALPOS = 13; + public final static Boolean COLUMN_4_14_PRIMARY = false; + public final static String COLUMN_4_14_NAME = "Breathes"; + public final static String COLUMN_4_14_INTERNAL_NAME = "breathes"; + public final static TableColumnType COLUMN_4_14_TYPE = TableColumnType.BOOLEAN; + public final static Long COLUMN_4_14_DATE_FORMAT = null; + public final static Boolean COLUMN_4_14_NULL = true; + public final static Boolean COLUMN_4_14_UNIQUE = false; + public final static Boolean COLUMN_4_14_AUTO_GENERATED = false; + public final static String COLUMN_4_14_FOREIGN_KEY = null; + public final static String COLUMN_4_14_CHECK = null; + public final static List<String> COLUMN_4_14_ENUM_VALUES = null; + + public final static Long COLUMN_4_15_ID = 23L; + public final static Integer COLUMN_4_15_ORDINALPOS = 14; + public final static Boolean COLUMN_4_15_PRIMARY = false; + public final static String COLUMN_4_15_NAME = "Venomous"; + public final static String COLUMN_4_15_INTERNAL_NAME = "venomous"; + public final static TableColumnType COLUMN_4_15_TYPE = TableColumnType.BOOLEAN; + public final static Long COLUMN_4_15_DATE_FORMAT = null; + public final static Boolean COLUMN_4_15_NULL = true; + public final static Boolean COLUMN_4_15_UNIQUE = false; + public final static Boolean COLUMN_4_15_AUTO_GENERATED = false; + public final static String COLUMN_4_15_FOREIGN_KEY = null; + public final static String COLUMN_4_15_CHECK = null; + public final static List<String> COLUMN_4_15_ENUM_VALUES = null; + + public final static Long COLUMN_4_16_ID = 24L; + public final static Integer COLUMN_4_16_ORDINALPOS = 15; + public final static Boolean COLUMN_4_16_PRIMARY = false; + public final static String COLUMN_4_16_NAME = "Fin"; + public final static String COLUMN_4_16_INTERNAL_NAME = "fins"; + public final static TableColumnType COLUMN_4_16_TYPE = TableColumnType.BOOLEAN; + public final static Long COLUMN_4_16_DATE_FORMAT = null; + public final static Boolean COLUMN_4_16_NULL = true; + public final static Boolean COLUMN_4_16_UNIQUE = false; + public final static Boolean COLUMN_4_16_AUTO_GENERATED = false; + public final static String COLUMN_4_16_FOREIGN_KEY = null; + public final static String COLUMN_4_16_CHECK = null; + public final static List<String> COLUMN_4_16_ENUM_VALUES = null; + + public final static Long COLUMN_4_17_ID = 25L; + public final static Integer COLUMN_4_17_ORDINALPOS = 16; + public final static Boolean COLUMN_4_17_PRIMARY = false; + public final static String COLUMN_4_17_NAME = "Legs"; + public final static String COLUMN_4_17_INTERNAL_NAME = "legs"; + public final static TableColumnType COLUMN_4_17_TYPE = TableColumnType.NUMBER; + public final static Long COLUMN_4_17_DATE_FORMAT = null; + public final static Boolean COLUMN_4_17_NULL = true; + public final static Boolean COLUMN_4_17_UNIQUE = false; + public final static Boolean COLUMN_4_17_AUTO_GENERATED = false; + public final static String COLUMN_4_17_FOREIGN_KEY = null; + public final static String COLUMN_4_17_CHECK = null; + public final static List<String> COLUMN_4_17_ENUM_VALUES = null; + + public final static Long COLUMN_4_18_ID = 26L; + public final static Integer COLUMN_4_18_ORDINALPOS = 17; + public final static Boolean COLUMN_4_18_PRIMARY = false; + public final static String COLUMN_4_18_NAME = "Tail"; + public final static String COLUMN_4_18_INTERNAL_NAME = "tail"; + public final static TableColumnType COLUMN_4_18_TYPE = TableColumnType.DECIMAL; + public final static Long COLUMN_4_18_DATE_FORMAT = null; + public final static Boolean COLUMN_4_18_NULL = true; + public final static Boolean COLUMN_4_18_UNIQUE = false; + public final static Boolean COLUMN_4_18_AUTO_GENERATED = false; + public final static String COLUMN_4_18_FOREIGN_KEY = null; + public final static String COLUMN_4_18_CHECK = null; + public final static List<String> COLUMN_4_18_ENUM_VALUES = null; + + public final static Long COLUMN_4_19_ID = 27L; + public final static Integer COLUMN_4_19_ORDINALPOS = 18; + public final static Boolean COLUMN_4_19_PRIMARY = false; + public final static String COLUMN_4_19_NAME = "Domestic"; + public final static String COLUMN_4_19_INTERNAL_NAME = "domestic"; + public final static TableColumnType COLUMN_4_19_TYPE = TableColumnType.BOOLEAN; + public final static Long COLUMN_4_19_DATE_FORMAT = null; + public final static Boolean COLUMN_4_19_NULL = true; + public final static Boolean COLUMN_4_19_UNIQUE = false; + public final static Boolean COLUMN_4_19_AUTO_GENERATED = false; + public final static String COLUMN_4_19_FOREIGN_KEY = null; + public final static String COLUMN_4_19_CHECK = null; + public final static List<String> COLUMN_4_19_ENUM_VALUES = null; + + public final static Long COLUMN_4_20_ID = 28L; + public final static Integer COLUMN_4_20_ORDINALPOS = 19; + public final static Boolean COLUMN_4_20_PRIMARY = false; + public final static String COLUMN_4_20_NAME = "Cat Size"; + public final static String COLUMN_4_20_INTERNAL_NAME = "catsize"; + public final static TableColumnType COLUMN_4_20_TYPE = TableColumnType.BOOLEAN; + public final static Long COLUMN_4_20_DATE_FORMAT = null; + public final static Boolean COLUMN_4_20_NULL = true; + public final static Boolean COLUMN_4_20_UNIQUE = false; + public final static Boolean COLUMN_4_20_AUTO_GENERATED = false; + public final static String COLUMN_4_20_FOREIGN_KEY = null; + public final static String COLUMN_4_20_CHECK = null; + public final static List<String> COLUMN_4_20_ENUM_VALUES = null; + + public final static Long COLUMN_4_21_ID = 29L; + public final static Integer COLUMN_4_21_ORDINALPOS = 20; + public final static Boolean COLUMN_4_21_PRIMARY = false; + public final static String COLUMN_4_21_NAME = "Class Type"; + public final static String COLUMN_4_21_INTERNAL_NAME = "class_type"; + public final static TableColumnType COLUMN_4_21_TYPE = TableColumnType.DECIMAL; + public final static Long COLUMN_4_21_DATE_FORMAT = null; + public final static Boolean COLUMN_4_21_NULL = true; + public final static Boolean COLUMN_4_21_UNIQUE = false; + public final static Boolean COLUMN_4_21_AUTO_GENERATED = false; + public final static String COLUMN_4_21_FOREIGN_KEY = null; + public final static String COLUMN_4_21_CHECK = null; + public final static List<String> COLUMN_4_21_ENUM_VALUES = null; + + public final static Long COLUMN_5_1_ID = 23L; + public final static Integer COLUMN_5_1_ORDINALPOS = 0; + public final static Boolean COLUMN_5_1_PRIMARY = true; + public final static String COLUMN_5_1_NAME = "id"; + public final static String COLUMN_5_1_INTERNAL_NAME = "id"; + public final static TableColumnType COLUMN_5_1_TYPE = TableColumnType.NUMBER; + public final static ColumnTypeDto COLUMN_5_1_TYPE_DTO = ColumnTypeDto.NUMBER; + public final static Long COLUMN_5_1_DATE_FORMAT = null; + public final static Boolean COLUMN_5_1_NULL = false; + public final static Boolean COLUMN_5_1_UNIQUE = true; + public final static Boolean COLUMN_5_1_AUTO_GENERATED = true; + public final static String COLUMN_5_1_FOREIGN_KEY = null; + public final static String COLUMN_5_1_CHECK = null; + public final static List<String> COLUMN_5_1_ENUM_VALUES = null; + + public final static Long COLUMN_5_2_ID = 24L; + public final static Integer COLUMN_5_2_ORDINALPOS = 1; + public final static Boolean COLUMN_5_2_PRIMARY = false; + public final static String COLUMN_5_2_NAME = "firstname"; + public final static String COLUMN_5_2_INTERNAL_NAME = "firstname"; + public final static TableColumnType COLUMN_5_2_TYPE = TableColumnType.STRING; + public final static ColumnTypeDto COLUMN_5_2_TYPE_DTO = ColumnTypeDto.STRING; + public final static Integer COLUMN_5_2_LENGTH = 20; + public final static Long COLUMN_5_2_DATE_FORMAT = null; + public final static Boolean COLUMN_5_2_NULL = false; + public final static Boolean COLUMN_5_2_UNIQUE = false; + public final static Boolean COLUMN_5_2_AUTO_GENERATED = false; + public final static String COLUMN_5_2_FOREIGN_KEY = null; + public final static String COLUMN_5_2_CHECK = null; + public final static List<String> COLUMN_5_2_ENUM_VALUES = null; + + public final static Long COLUMN_5_3_ID = 25L; + public final static Integer COLUMN_5_3_ORDINALPOS = 2; + public final static Boolean COLUMN_5_3_PRIMARY = false; + public final static String COLUMN_5_3_NAME = "lastname"; + public final static String COLUMN_5_3_INTERNAL_NAME = "lastname"; + public final static TableColumnType COLUMN_5_3_TYPE = TableColumnType.STRING; + public final static ColumnTypeDto COLUMN_5_3_TYPE_DTO = ColumnTypeDto.STRING; + public final static Integer COLUMN_5_3_LENGTH = 40; + public final static Long COLUMN_5_3_DATE_FORMAT = null; + public final static Boolean COLUMN_5_3_NULL = false; + public final static Boolean COLUMN_5_3_UNIQUE = false; + public final static Boolean COLUMN_5_3_AUTO_GENERATED = false; + public final static String COLUMN_5_3_FOREIGN_KEY = null; + public final static String COLUMN_5_3_CHECK = null; + public final static List<String> COLUMN_5_3_ENUM_VALUES = null; + + public final static Long COLUMN_5_4_ID = 25L; + public final static Integer COLUMN_5_4_ORDINALPOS = 2; + public final static Boolean COLUMN_5_4_PRIMARY = false; + public final static String COLUMN_5_4_NAME = "ref_id"; + public final static String COLUMN_5_4_INTERNAL_NAME = "ref_id"; + public final static TableColumnType COLUMN_5_4_TYPE = TableColumnType.NUMBER; + public final static ColumnTypeDto COLUMN_5_4_TYPE_DTO = ColumnTypeDto.NUMBER; + public final static Long COLUMN_5_4_DATE_FORMAT = null; + public final static Boolean COLUMN_5_4_NULL = false; + public final static Boolean COLUMN_5_4_UNIQUE = false; + public final static Boolean COLUMN_5_4_AUTO_GENERATED = false; + public final static String COLUMN_5_4_FOREIGN_KEY = null; + public final static String COLUMN_5_4_CHECK = null; + public final static List<String> COLUMN_5_4_ENUM_VALUES = null; + + public final static List<String> CONSTRAINTS_1_UNIQUE_1 = List.of(COLUMN_1_1_NAME); + public final static List<String> CONSTRAINTS_2_UNIQUE_1 = List.of(COLUMN_2_1_NAME); + public final static List<String> CONSTRAINTS_3_UNIQUE_1 = List.of("id"); + public final static List<String> CONSTRAINTS_4_UNIQUE_1 = List.of(COLUMN_4_1_NAME); + public final static List<String> CONSTRAINTS_5_UNIQUE_1 = List.of(COLUMN_5_1_NAME); + + public final static Long CONCEPT_1_ID = 1L; + public final static String CONCEPT_1_NAME = "Temperature"; + public final static Instant CONCEPT_1_CREATED = Instant.now().minus(1, HOURS); + + public final static TableColumnConcept CONCEPT_1 = TableColumnConcept.builder() + .name(CONCEPT_1_NAME) + .created(CONCEPT_1_CREATED) + .uri("http://www.ontology-of-units-of-measure.org/resource/om-2/") + .build(); + + public final static Long QUERY_1_ID = 1L; + public final static String QUERY_1_STATEMENT = "SELECT `id`, `date`, `location`, `mintemp`, `rainfall` FROM " + + "`weather_aus`"; + public final static String QUERY_1_DOI = null; + public final static Long QUERY_1_CONTAINER_ID = CONTAINER_1_ID; + public final static Long QUERY_1_DATABASE_ID = DATABASE_1_ID; + public final static Long QUERY_1_RESULT_NUMBER = 2L; + public final static String QUERY_1_QUERY_HASH = "a3b8ac39e38167d14cf3a9c20a69e4b6954d049525390b973a2c23064953a992"; + public final static String QUERY_1_RESULT_HASH = "8358c8ade4849d2094ab5bb29127afdae57e6bb5acb1db7af603813d406c467a"; + public final static Instant QUERY_1_CREATED = Instant.ofEpochSecond(1677648377); + public final static Instant QUERY_1_EXECUTION = Instant.now(); + public final static Boolean QUERY_1_PERSISTED = false; + + public final static Query QUERY_1 = Query.builder() + .id(QUERY_1_ID) + .query(QUERY_1_STATEMENT) + .queryHash(QUERY_1_QUERY_HASH) + .resultHash(QUERY_1_RESULT_HASH) + .resultNumber(QUERY_1_RESULT_NUMBER) + .created(QUERY_1_CREATED) + .createdBy(USER_1_USERNAME) + .isPersisted(QUERY_1_PERSISTED) + .executed(QUERY_1_EXECUTION) + .created(QUERY_1_CREATED) + .build(); + + public final static QueryDto QUERY_1_DTO = QueryDto.builder() + .id(QUERY_1_ID) + .cid(QUERY_1_CONTAINER_ID) + .dbid(QUERY_1_DATABASE_ID) + .query(QUERY_1_STATEMENT) + .queryHash(QUERY_1_QUERY_HASH) + .resultHash(QUERY_1_RESULT_HASH) + .created(QUERY_1_CREATED) + .execution(QUERY_1_EXECUTION) + .createdBy(USER_1_ID) + .creator(USER_1_DTO) + .build(); + + public final static QueryBriefDto QUERY_1_BRIEF_DTO = QueryBriefDto.builder() + .id(QUERY_1_ID) + .cid(QUERY_1_CONTAINER_ID) + .dbid(QUERY_1_DATABASE_ID) + .query(QUERY_1_STATEMENT) + .queryHash(QUERY_1_QUERY_HASH) + .resultHash(QUERY_1_RESULT_HASH) + .created(QUERY_1_CREATED) + .execution(QUERY_1_EXECUTION) + .createdBy(USER_1_ID) + .creator(USER_1_DTO) + .build(); + + public final static Long QUERY_2_ID = 2L; + public final static String QUERY_2_STATEMENT = "SELECT `location` FROM `weather_aus`"; + public final static String QUERY_2_QUERY_HASH = "a2d2dd94ebc7653bb5a3b55dd8ed5e91d3d13c225c6855a1eb4eb7ca14c36ced"; + public final static Long QUERY_2_CONTAINER_ID = CONTAINER_2_ID; + public final static Long QUERY_2_DATABASE_ID = DATABASE_2_ID; + public final static Long QUERY_2_RESULT_NUMBER = 2L; + public final static String QUERY_2_RESULT_HASH = "ff3f7cbe1b96d296957f6e39e55b8b1b577fa3d205d4795af99594cfd20cb80d"; + public final static Instant QUERY_2_CREATED = Instant.now().minus(2, MINUTES); + public final static Instant QUERY_2_EXECUTION = Instant.now().minus(1, MINUTES); + public final static Instant QUERY_2_LAST_MODIFIED = Instant.ofEpochSecond(1541588352); + public final static Boolean QUERY_2_PERSISTED = false; + + public final static Query QUERY_2 = Query.builder() + .id(QUERY_2_ID) + .query(QUERY_2_STATEMENT) + .queryHash(QUERY_2_QUERY_HASH) + .resultHash(QUERY_2_RESULT_HASH) + .resultNumber(QUERY_2_RESULT_NUMBER) + .created(QUERY_2_CREATED) + .createdBy(USER_1_USERNAME) + .isPersisted(QUERY_2_PERSISTED) + .created(QUERY_2_CREATED) + .executed(QUERY_2_EXECUTION) + .build(); + + public final static QueryDto QUERY_2_DTO = QueryDto.builder() + .id(QUERY_2_ID) + .cid(QUERY_2_CONTAINER_ID) + .dbid(QUERY_2_DATABASE_ID) + .query(QUERY_2_STATEMENT) + .queryNormalized(QUERY_2_STATEMENT) + .resultNumber(QUERY_2_RESULT_NUMBER) + .resultHash(QUERY_2_RESULT_HASH) + .lastModified(QUERY_2_LAST_MODIFIED) + .created(QUERY_2_CREATED) + .queryHash(QUERY_2_QUERY_HASH) + .execution(QUERY_2_EXECUTION) + .build(); + + public final static Long QUERY_3_ID = 3L; + public final static String QUERY_3_STATEMENT = "SELECT `location`, `mintemp` FROM `weather_aus` WHERE `mintemp` > 10"; + public final static String QUERY_3_QUERY_HASH = "a3d3dd94ebc7653bb5a3b55dd8ed5e91d3d13c335c6855a1eb4eb7ca14c36ced"; + public final static Long QUERY_3_CONTAINER_ID = CONTAINER_2_ID; + public final static Long QUERY_3_DATABASE_ID = DATABASE_2_ID; + public final static String QUERY_3_RESULT_HASH = "ff3f7cbe1b96d396957f6e39e55b8b1b577fa3d305d4795af99594cfd30cb80d"; + public final static Instant QUERY_3_CREATED = Instant.now().minus(3, MINUTES); + public final static Instant QUERY_3_EXECUTION = Instant.now().minus(1, MINUTES); + public final static Instant QUERY_3_LAST_MODIFIED = Instant.ofEpochSecond(1541588353); + public final static Long QUERY_3_RESULT_NUMBER = 2L; + public final static Boolean QUERY_3_PERSISTED = true; + + public final static Query QUERY_3 = Query.builder() + .id(QUERY_3_ID) + .query(QUERY_3_STATEMENT) + .queryHash(QUERY_3_QUERY_HASH) + .resultHash(QUERY_3_RESULT_HASH) + .created(QUERY_3_CREATED) + .createdBy(USER_1_USERNAME) + .isPersisted(QUERY_3_PERSISTED) + .build(); + + public final static QueryDto QUERY_3_DTO = QueryDto.builder() + .id(QUERY_3_ID) + .cid(QUERY_3_CONTAINER_ID) + .dbid(QUERY_3_DATABASE_ID) + .query(QUERY_3_STATEMENT) + .queryNormalized(QUERY_3_STATEMENT) + .resultNumber(QUERY_3_RESULT_NUMBER) + .resultHash(QUERY_3_RESULT_HASH) + .lastModified(QUERY_3_LAST_MODIFIED) + .created(QUERY_3_CREATED) + .queryHash(QUERY_3_QUERY_HASH) + .execution(QUERY_3_EXECUTION) + .build(); + + public final static Long QUERY_4_ID = 4L; + public final static String QUERY_4_STATEMENT = "SELECT `id`, `value` FROM `mfcc`"; + public final static String QUERY_4_QUERY_HASH = "df7da3801dfb5c191ff6711d79ce6455f3c09ec8323ce1ff7208ab85387263f5"; + public final static Long QUERY_4_CONTAINER_ID = CONTAINER_3_ID; + public final static Long QUERY_4_DATABASE_ID = DATABASE_3_ID; + public final static String QUERY_4_RESULT_HASH = "ff4f7cbe1b96d496957f6e49e55b8b1b577fa4d405d4795af99594cfd40cb80d"; + public final static Instant QUERY_4_CREATED = Instant.now().minus(4, MINUTES); + public final static Instant QUERY_4_EXECUTION = Instant.now().minus(1, MINUTES); + public final static Instant QUERY_4_LAST_MODIFIED = Instant.ofEpochSecond(1541588454); + public final static Boolean QUERY_4_PERSISTED = false; + + public final static Query QUERY_4 = Query.builder() + .id(QUERY_4_ID) + .query(QUERY_4_STATEMENT) + .queryHash(QUERY_4_QUERY_HASH) + .resultHash(QUERY_4_RESULT_HASH) + .created(QUERY_4_CREATED) + .createdBy(USER_1_USERNAME) + .isPersisted(QUERY_4_PERSISTED) + .createdBy(USER_1_USERNAME) + .build(); + + public final static Long QUERY_4_RESULT_NUMBER = 6L; + public final static Long QUERY_4_RESULT_ID = 4L; + public final static List<Map<String, Object>> QUERY_4_RESULT_RESULT = List.of( + new HashMap<>() {{ + put("id", BigInteger.valueOf(1L)); + put("value", 11.2); + }}, new HashMap<>() {{ + put("id", BigInteger.valueOf(2L)); + put("value", 11.3); + }}, new HashMap<>() {{ + put("id", BigInteger.valueOf(3L)); + put("value", 11.4); + }}, new HashMap<>() {{ + put("id", BigInteger.valueOf(4L)); + put("value", 11.9); + }}, new HashMap<>() {{ + put("id", BigInteger.valueOf(5L)); + put("value", 12.3); + }}, new HashMap<>() {{ + put("id", BigInteger.valueOf(6L)); + put("value", 23.1); + }}); + + public final static QueryResultDto QUERY_4_RESULT_DTO = QueryResultDto.builder() + .id(QUERY_4_RESULT_ID) + .resultNumber(QUERY_4_RESULT_NUMBER) + .result(QUERY_4_RESULT_RESULT) + .build(); + + public final static QueryDto QUERY_4_DTO = QueryDto.builder() + .id(QUERY_4_ID) + .cid(QUERY_4_CONTAINER_ID) + .dbid(QUERY_4_DATABASE_ID) + .query(QUERY_4_STATEMENT) + .queryNormalized(QUERY_4_STATEMENT) + .resultNumber(QUERY_4_RESULT_NUMBER) + .resultHash(QUERY_4_RESULT_HASH) + .lastModified(QUERY_4_LAST_MODIFIED) + .created(QUERY_4_CREATED) + .queryHash(QUERY_4_QUERY_HASH) + .execution(QUERY_4_EXECUTION) + .build(); + + public final static Long QUERY_5_ID = 5L; + public final static String QUERY_5_STATEMENT = "SELECT `id`, `value` FROM `mfcc` WHERE `value` > 0"; + public final static String QUERY_5_QUERY_HASH = "6d6dc48b12cdfd959d39a62887334a6bbd529b93eed4f211f3f671bd9e7d6225"; + public final static Long QUERY_5_CONTAINER_ID = CONTAINER_3_ID; + public final static Long QUERY_5_DATABASE_ID = DATABASE_3_ID; + public final static String QUERY_5_RESULT_HASH = "ff5f7cbe1b96d596957f6e59e55b8b1b577fa5d505d5795af99595cfd50cb80d"; + public final static Instant QUERY_5_CREATED = Instant.now().minus(5, MINUTES); + public final static Instant QUERY_5_EXECUTION = Instant.now().minus(1, MINUTES); + public final static Instant QUERY_5_LAST_MODIFIED = Instant.ofEpochSecond(1551588555); + public final static Long QUERY_5_RESULT_NUMBER = 6L; + public final static Boolean QUERY_5_PERSISTED = true; + + public final static Query QUERY_5 = Query.builder() + .id(QUERY_5_ID) + .query(QUERY_5_STATEMENT) + .queryHash(QUERY_5_QUERY_HASH) + .resultHash(QUERY_5_RESULT_HASH) + .created(QUERY_5_CREATED) + .createdBy(USER_1_USERNAME) + .isPersisted(QUERY_5_PERSISTED) + .build(); + + public final static QueryDto QUERY_5_DTO = QueryDto.builder() + .id(QUERY_5_ID) + .cid(QUERY_5_CONTAINER_ID) + .dbid(QUERY_5_DATABASE_ID) + .query(QUERY_5_STATEMENT) + .queryNormalized(QUERY_5_STATEMENT) + .resultNumber(QUERY_5_RESULT_NUMBER) + .resultHash(QUERY_5_RESULT_HASH) + .lastModified(QUERY_5_LAST_MODIFIED) + .created(QUERY_5_CREATED) + .queryHash(QUERY_5_QUERY_HASH) + .execution(QUERY_5_EXECUTION) + .build(); + + public final static Long QUERY_6_ID = 6L; + public final static String QUERY_6_STATEMENT = "SELECT `location` FROM `weather_aus` WHERE `id` = 1"; + public final static String QUERY_6_QUERY_HASH = "6d6dc48b12cdfd959d39a62887334a6bbd529b93eed4f211f3f671bd9e7d6225"; + public final static Long QUERY_6_CONTAINER_ID = CONTAINER_2_ID; + public final static Long QUERY_6_DATABASE_ID = DATABASE_2_ID; + public final static String QUERY_6_RESULT_HASH = "ff5f7cbe1b96d596957f6e59e55b8b1b577fa5d505d5795af99595cfd50cb80d"; + public final static Instant QUERY_6_CREATED = Instant.now().minus(5, MINUTES); + public final static Instant QUERY_6_EXECUTION = Instant.now().minus(1, MINUTES); + public final static Instant QUERY_6_LAST_MODIFIED = Instant.ofEpochSecond(1551588555); + public final static Long QUERY_6_RESULT_NUMBER = 1L; + public final static Boolean QUERY_6_PERSISTED = true; + + public final static Query QUERY_6 = Query.builder() + .id(QUERY_6_ID) + .query(QUERY_6_STATEMENT) + .queryHash(QUERY_6_QUERY_HASH) + .resultHash(QUERY_6_RESULT_HASH) + .created(QUERY_6_CREATED) + .createdBy(USER_1_USERNAME) + .isPersisted(QUERY_6_PERSISTED) + .build(); + + public final static QueryDto QUERY_6_DTO = QueryDto.builder() + .id(QUERY_6_ID) + .cid(QUERY_6_CONTAINER_ID) + .dbid(QUERY_6_DATABASE_ID) + .query(QUERY_6_STATEMENT) + .queryNormalized(QUERY_6_STATEMENT) + .resultNumber(QUERY_6_RESULT_NUMBER) + .resultHash(QUERY_6_RESULT_HASH) + .lastModified(QUERY_6_LAST_MODIFIED) + .created(QUERY_6_CREATED) + .queryHash(QUERY_6_QUERY_HASH) + .execution(QUERY_6_EXECUTION) + .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) + .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) + .dateFormat(IMAGE_DATE_1) + .isNullAllowed(COLUMN_1_2_NULL) + .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) + .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) + .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) + .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) + .database(DATABASE_1) + .created(Instant.now()) + .internalName(TABLE_1_INTERNALNAME) + .description(TABLE_1_DESCRIPTION) + .name(TABLE_1_NAME) + .lastModified(TABLE_1_LAST_MODIFIED) + .tdbid(DATABASE_1_ID) + .queueName(TABLE_1_QUEUE_NAME) + .routingKey(TABLE_1_ROUTING_KEY) + .columns(TABLE_1_COLUMNS) + .constraints(null) /* TABLE_1_CONSTRAINTS */ + .creator(USER_1) + .created(TABLE_1_CREATED) + .lastModified(TABLE_1_LAST_MODIFIED) + .build(); + + public final static Table TABLE_1_NOCOLS = 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) + .tdbid(DATABASE_1_ID) + .queueName(TABLE_1_QUEUE_NAME) + .routingKey(TABLE_1_ROUTING_KEY) + .columns(List.of()) + .creator(USER_1) + .created(TABLE_1_CREATED) + .lastModified(TABLE_1_LAST_MODIFIED) + .build(); + + public final static List<TableColumn> TABLE_2_COLUMNS = List.of(TableColumn.builder() + .id(COLUMN_2_1_ID) + .ordinalPosition(COLUMN_2_1_ORDINALPOS) + .cdbid(DATABASE_1_ID) + .tid(TABLE_2_ID) + .name(COLUMN_2_1_NAME) + .internalName(COLUMN_2_1_INTERNAL_NAME) + .columnType(COLUMN_2_1_TYPE) + .dfid(COLUMN_2_1_DATE_FORMAT) + .isNullAllowed(COLUMN_2_1_NULL) + .autoGenerated(COLUMN_2_1_AUTO_GENERATED) + .isPrimaryKey(COLUMN_2_1_PRIMARY) + .enumValues(COLUMN_2_1_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_2_2_ID) + .ordinalPosition(COLUMN_2_2_ORDINALPOS) + .cdbid(DATABASE_1_ID) + .tid(TABLE_2_ID) + .name(COLUMN_2_2_NAME) + .internalName(COLUMN_2_2_INTERNAL_NAME) + .columnType(COLUMN_2_2_TYPE) + .dfid(COLUMN_2_2_DATE_FORMAT) + .isNullAllowed(COLUMN_2_2_NULL) + .autoGenerated(COLUMN_2_2_AUTO_GENERATED) + .isPrimaryKey(COLUMN_2_2_PRIMARY) + .enumValues(COLUMN_2_2_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_2_3_ID) + .ordinalPosition(COLUMN_2_3_ORDINALPOS) + .cdbid(DATABASE_1_ID) + .tid(TABLE_2_ID) + .name(COLUMN_2_3_NAME) + .internalName(COLUMN_2_3_INTERNAL_NAME) + .columnType(COLUMN_2_3_TYPE) + .dfid(COLUMN_2_3_DATE_FORMAT) + .isNullAllowed(COLUMN_2_3_NULL) + .autoGenerated(COLUMN_2_3_AUTO_GENERATED) + .isPrimaryKey(COLUMN_2_3_PRIMARY) + .enumValues(COLUMN_2_3_ENUM_VALUES) + .build()); + + public final static Table TABLE_2 = Table.builder() + .id(TABLE_2_ID) + .database(DATABASE_1) + .created(Instant.now()) + .internalName(TABLE_2_INTERNALNAME) + .description(TABLE_2_DESCRIPTION) + .name(TABLE_2_NAME) + .lastModified(TABLE_2_LAST_MODIFIED) + .tdbid(DATABASE_1_ID) + .queueName(TABLE_2_QUEUE_NAME) + .routingKey(TABLE_2_ROUTING_KEY) + .columns(TABLE_2_COLUMNS) + .creator(USER_1) + .created(TABLE_2_CREATED) + .lastModified(TABLE_2_LAST_MODIFIED) + .build(); + + public final static Table TABLE_2_NOCOLS = 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_1_ID) + .queueName(TABLE_2_QUEUE_NAME) + .routingKey(TABLE_2_ROUTING_KEY) + .columns(List.of()) + .creator(USER_1) + .created(TABLE_2_CREATED) + .lastModified(TABLE_2_LAST_MODIFIED) + .build(); + + public final static Constraints TABLE_1_CONSTRAINTS = Constraints.builder() + .foreignKeys(List.of(ForeignKey.builder() + .referencedTable(TABLE_2) + .references(List.of( + ForeignKeyReference.builder().column(TABLE_1_COLUMNS.get(2)).referencedColumn(TABLE_1_COLUMNS.get(0)).build()) + ).build() + )) + .uniques(List.of(Unique.builder().columns(List.of(TABLE_1_COLUMNS.get(1))).build())) + .checks(Set.of("`mintemp` > 0")) + .build(); + + public final static Constraints TABLE_2_CONSTRAINTS = Constraints.builder() + .uniques(List.of(Unique.builder().columns(List.of(TABLE_2_COLUMNS.get(0))).build())) + .build(); + + public final static List<TableColumn> TABLE_3_COLUMNS = List.of(TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(0) + .autoGenerated(true) + .columnType(TableColumnType.NUMBER) + .name("id") + .internalName("id") + .isNullAllowed(false) + .isPrimaryKey(true) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(1) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("linie") + .internalName("linie") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(2) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("richtung") + .internalName("richtung") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(3) + .autoGenerated(false) + .columnType(TableColumnType.DATE) + .name("betriebsdatum") + .internalName("betriebsdatum") + .isNullAllowed(true) + .isPrimaryKey(false) + .dfid(IMAGE_DATE_2_ID) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(4) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("fahrzeug") + .internalName("fahrzeug") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(5) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("kurs") + .internalName("kurs") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(6) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("seq_von") + .internalName("seq_von") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(7) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("halt_diva_von") + .internalName("halt_diva_von") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(8) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("halt_punkt_diva_von") + .internalName("halt_punkt_diva_von") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(9) + .autoGenerated(false) + .columnType(TableColumnType.STRING) + .name("halt_kurz_von1") + .internalName("halt_kurz_von1") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(10) + .autoGenerated(false) + .columnType(TableColumnType.DATE) + .name("datum_von") + .internalName("datum_von") + .isNullAllowed(true) + .isPrimaryKey(false) + .dfid(IMAGE_DATE_2_ID) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(11) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("soll_an_von") + .internalName("soll_an_von") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(12) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("ist_an_von") + .internalName("ist_an_von") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(13) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("soll_ab_von") + .internalName("soll_ab_von") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(14) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("ist_ab_von") + .internalName("ist_ab_von") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(15) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("seq_nach") + .internalName("seq_nach") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(16) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("halt_diva_nach") + .internalName("halt_diva_nach") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(17) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("halt_punkt_diva_nach") + .internalName("halt_punkt_diva_nach") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(18) + .autoGenerated(false) + .columnType(TableColumnType.STRING) + .name("halt_kurz_nach1") + .internalName("halt_kurz_nach1") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(19) + .autoGenerated(false) + .columnType(TableColumnType.DATE) + .name("datum_nach") + .internalName("datum_nach") + .isNullAllowed(true) + .isPrimaryKey(false) + .dfid(IMAGE_DATE_2_ID) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(20) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("soll_an_nach") + .internalName("soll_an_nach") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(21) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("ist_an_nach1") + .internalName("ist_an_nach1") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(22) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("soll_ab_nach") + .internalName("soll_ab_nach") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(23) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("ist_ab_nach") + .internalName("ist_ab_nach") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(24) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("fahrt_id") + .internalName("fahrt_id") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(25) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("fahrweg_id") + .internalName("fahrweg_id") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(26) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("fw_no") + .internalName("fw_no") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(27) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("fw_typ") + .internalName("fw_typ") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(28) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("fw_kurz") + .internalName("fw_kurz") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(29) + .autoGenerated(false) + .columnType(TableColumnType.STRING) + .name("fw_lang") + .internalName("fw_lang") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(30) + .autoGenerated(false) + .columnType(TableColumnType.STRING) + .name("umlauf_von") + .internalName("umlauf_von") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(31) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("halt_id_von") + .internalName("halt_id_von") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(32) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("halt_id_nach") + .internalName("halt_id_nach") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(33) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("halt_punkt_id_von") + .internalName("halt_punkt_id_von") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build(), + TableColumn.builder() + .tid(TABLE_3_ID) + .cdbid(DATABASE_1_ID) + .ordinalPosition(34) + .autoGenerated(false) + .columnType(TableColumnType.NUMBER) + .name("halt_punkt_id_nach") + .internalName("halt_punkt_id_nach") + .isNullAllowed(true) + .isPrimaryKey(false) + .dateFormat(null) + .enumValues(null) + .build()); + + public final static Constraints TABLE_3_CONSTRAINTS = Constraints.builder() + .uniques(List.of(Unique.builder().columns(List.of(TABLE_3_COLUMNS.get(0))).build())) + .build(); + + public final static Table TABLE_3 = Table.builder() + .id(TABLE_3_ID) + .database(DATABASE_1) + .created(Instant.now()) + .internalName(TABLE_3_INTERNALNAME) + .description(TABLE_3_DESCRIPTION) + .name(TABLE_3_NAME) + .lastModified(TABLE_3_LAST_MODIFIED) + .tdbid(DATABASE_1_ID) + .queueName(TABLE_3_QUEUE_NAME) + .routingKey(TABLE_3_ROUTING_KEY) + .columns(TABLE_3_COLUMNS) + .constraints(TABLE_3_CONSTRAINTS) + .creator(USER_1) + .created(TABLE_3_CREATED) + .lastModified(TABLE_3_LAST_MODIFIED) + .build(); + + public final static Table TABLE_3_NOCOLS = 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_1_ID) + .queueName(TABLE_3_QUEUE_NAME) + .routingKey(TABLE_3_ROUTING_KEY) + .columns(List.of()) + .creator(USER_1) + .created(TABLE_3_CREATED) + .lastModified(TABLE_3_LAST_MODIFIED) + .build(); + + public final static List<TableColumn> TABLE_4_COLUMNS = List.of(TableColumn.builder() + .id(COLUMN_4_1_ID) + .ordinalPosition(COLUMN_4_1_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_1_NAME) + .internalName(COLUMN_4_1_INTERNAL_NAME) + .columnType(COLUMN_4_1_TYPE) + .dfid(COLUMN_4_1_DATE_FORMAT) + .isNullAllowed(COLUMN_4_1_NULL) + .autoGenerated(COLUMN_4_1_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_1_PRIMARY) + .enumValues(COLUMN_4_1_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_2_ID) + .ordinalPosition(COLUMN_4_2_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_2_NAME) + .internalName(COLUMN_4_2_INTERNAL_NAME) + .columnType(COLUMN_4_2_TYPE) + .dfid(COLUMN_4_2_DATE_FORMAT) + .isNullAllowed(COLUMN_4_2_NULL) + .autoGenerated(COLUMN_4_2_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_2_PRIMARY) + .enumValues(COLUMN_4_2_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_3_ID) + .ordinalPosition(COLUMN_4_3_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_3_NAME) + .internalName(COLUMN_4_3_INTERNAL_NAME) + .columnType(COLUMN_4_3_TYPE) + .dfid(COLUMN_4_3_DATE_FORMAT) + .isNullAllowed(COLUMN_4_3_NULL) + .autoGenerated(COLUMN_4_3_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_3_PRIMARY) + .enumValues(COLUMN_4_3_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_4_ID) + .ordinalPosition(COLUMN_4_4_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_4_NAME) + .internalName(COLUMN_4_4_INTERNAL_NAME) + .columnType(COLUMN_4_4_TYPE) + .dfid(COLUMN_4_4_DATE_FORMAT) + .isNullAllowed(COLUMN_4_4_NULL) + .autoGenerated(COLUMN_4_4_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_4_PRIMARY) + .enumValues(COLUMN_4_4_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_5_ID) + .ordinalPosition(COLUMN_4_5_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_5_NAME) + .internalName(COLUMN_4_5_INTERNAL_NAME) + .columnType(COLUMN_4_5_TYPE) + .dfid(COLUMN_4_5_DATE_FORMAT) + .isNullAllowed(COLUMN_4_5_NULL) + .autoGenerated(COLUMN_4_5_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_5_PRIMARY) + .enumValues(COLUMN_4_5_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_6_ID) + .ordinalPosition(COLUMN_4_6_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_6_NAME) + .internalName(COLUMN_4_6_INTERNAL_NAME) + .columnType(COLUMN_4_6_TYPE) + .dfid(COLUMN_4_6_DATE_FORMAT) + .isNullAllowed(COLUMN_4_6_NULL) + .autoGenerated(COLUMN_4_6_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_6_PRIMARY) + .enumValues(COLUMN_4_6_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_7_ID) + .ordinalPosition(COLUMN_4_7_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_7_NAME) + .internalName(COLUMN_4_7_INTERNAL_NAME) + .columnType(COLUMN_4_7_TYPE) + .dfid(COLUMN_4_7_DATE_FORMAT) + .isNullAllowed(COLUMN_4_7_NULL) + .autoGenerated(COLUMN_4_7_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_7_PRIMARY) + .enumValues(COLUMN_4_7_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_8_ID) + .ordinalPosition(COLUMN_4_8_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_8_NAME) + .internalName(COLUMN_4_8_INTERNAL_NAME) + .columnType(COLUMN_4_8_TYPE) + .dfid(COLUMN_4_8_DATE_FORMAT) + .isNullAllowed(COLUMN_4_8_NULL) + .autoGenerated(COLUMN_4_8_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_8_PRIMARY) + .enumValues(COLUMN_4_8_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_9_ID) + .ordinalPosition(COLUMN_4_9_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_9_NAME) + .internalName(COLUMN_4_9_INTERNAL_NAME) + .columnType(COLUMN_4_9_TYPE) + .dfid(COLUMN_4_9_DATE_FORMAT) + .isNullAllowed(COLUMN_4_9_NULL) + .autoGenerated(COLUMN_4_9_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_9_PRIMARY) + .enumValues(COLUMN_4_9_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_10_ID) + .ordinalPosition(COLUMN_4_10_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_10_NAME) + .internalName(COLUMN_4_10_INTERNAL_NAME) + .columnType(COLUMN_4_10_TYPE) + .dfid(COLUMN_4_10_DATE_FORMAT) + .isNullAllowed(COLUMN_4_10_NULL) + .autoGenerated(COLUMN_4_10_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_10_PRIMARY) + .enumValues(COLUMN_4_10_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_11_ID) + .ordinalPosition(COLUMN_4_11_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_11_NAME) + .internalName(COLUMN_4_11_INTERNAL_NAME) + .columnType(COLUMN_4_11_TYPE) + .dfid(COLUMN_4_11_DATE_FORMAT) + .isNullAllowed(COLUMN_4_11_NULL) + .autoGenerated(COLUMN_4_11_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_11_PRIMARY) + .enumValues(COLUMN_4_11_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_12_ID) + .ordinalPosition(COLUMN_4_12_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_12_NAME) + .internalName(COLUMN_4_12_INTERNAL_NAME) + .columnType(COLUMN_4_12_TYPE) + .dfid(COLUMN_4_12_DATE_FORMAT) + .isNullAllowed(COLUMN_4_12_NULL) + .autoGenerated(COLUMN_4_12_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_12_PRIMARY) + .enumValues(COLUMN_4_12_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_13_ID) + .ordinalPosition(COLUMN_4_13_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_13_NAME) + .internalName(COLUMN_4_13_INTERNAL_NAME) + .columnType(COLUMN_4_13_TYPE) + .dfid(COLUMN_4_13_DATE_FORMAT) + .isNullAllowed(COLUMN_4_13_NULL) + .autoGenerated(COLUMN_4_13_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_13_PRIMARY) + .enumValues(COLUMN_4_13_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_14_ID) + .ordinalPosition(COLUMN_4_14_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_14_NAME) + .internalName(COLUMN_4_14_INTERNAL_NAME) + .columnType(COLUMN_4_14_TYPE) + .dfid(COLUMN_4_14_DATE_FORMAT) + .isNullAllowed(COLUMN_4_14_NULL) + .autoGenerated(COLUMN_4_14_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_14_PRIMARY) + .enumValues(COLUMN_4_14_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_15_ID) + .ordinalPosition(COLUMN_4_15_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_15_NAME) + .internalName(COLUMN_4_15_INTERNAL_NAME) + .columnType(COLUMN_4_15_TYPE) + .dfid(COLUMN_4_15_DATE_FORMAT) + .isNullAllowed(COLUMN_4_15_NULL) + .autoGenerated(COLUMN_4_15_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_15_PRIMARY) + .enumValues(COLUMN_4_15_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_16_ID) + .ordinalPosition(COLUMN_4_16_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_16_NAME) + .internalName(COLUMN_4_16_INTERNAL_NAME) + .columnType(COLUMN_4_16_TYPE) + .dfid(COLUMN_4_16_DATE_FORMAT) + .isNullAllowed(COLUMN_4_16_NULL) + .autoGenerated(COLUMN_4_16_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_16_PRIMARY) + .enumValues(COLUMN_4_16_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_17_ID) + .ordinalPosition(COLUMN_4_17_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_17_NAME) + .internalName(COLUMN_4_17_INTERNAL_NAME) + .columnType(COLUMN_4_17_TYPE) + .dfid(COLUMN_4_17_DATE_FORMAT) + .isNullAllowed(COLUMN_4_17_NULL) + .autoGenerated(COLUMN_4_17_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_17_PRIMARY) + .enumValues(COLUMN_4_17_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_18_ID) + .ordinalPosition(COLUMN_4_18_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_18_NAME) + .internalName(COLUMN_4_18_INTERNAL_NAME) + .columnType(COLUMN_4_18_TYPE) + .dfid(COLUMN_4_18_DATE_FORMAT) + .isNullAllowed(COLUMN_4_18_NULL) + .autoGenerated(COLUMN_4_18_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_18_PRIMARY) + .enumValues(COLUMN_4_18_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_19_ID) + .ordinalPosition(COLUMN_4_19_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_19_NAME) + .internalName(COLUMN_4_19_INTERNAL_NAME) + .columnType(COLUMN_4_19_TYPE) + .dfid(COLUMN_4_19_DATE_FORMAT) + .isNullAllowed(COLUMN_4_19_NULL) + .autoGenerated(COLUMN_4_19_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_19_PRIMARY) + .enumValues(COLUMN_4_19_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_20_ID) + .ordinalPosition(COLUMN_4_20_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_20_NAME) + .internalName(COLUMN_4_20_INTERNAL_NAME) + .columnType(COLUMN_4_20_TYPE) + .dfid(COLUMN_4_20_DATE_FORMAT) + .isNullAllowed(COLUMN_4_20_NULL) + .autoGenerated(COLUMN_4_20_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_20_PRIMARY) + .enumValues(COLUMN_4_20_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_4_21_ID) + .ordinalPosition(COLUMN_4_21_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_4_ID) + .name(COLUMN_4_21_NAME) + .internalName(COLUMN_4_21_INTERNAL_NAME) + .columnType(COLUMN_4_21_TYPE) + .dfid(COLUMN_4_21_DATE_FORMAT) + .isNullAllowed(COLUMN_4_21_NULL) + .autoGenerated(COLUMN_4_21_AUTO_GENERATED) + .isPrimaryKey(COLUMN_4_21_PRIMARY) + .enumValues(COLUMN_4_21_ENUM_VALUES) + .build()); + + public final static Constraints TABLE_4_CONSTRAINTS = Constraints.builder() + .uniques(List.of(Unique.builder().columns(List.of(TABLE_4_COLUMNS.get(0))).build())) + .build(); + + public final static Table TABLE_4 = Table.builder() + .id(TABLE_4_ID) + .created(Instant.now()) + .internalName(TABLE_4_INTERNALNAME) + .description(TABLE_4_DESCRIPTION) + .name(TABLE_4_NAME) + .lastModified(TABLE_4_LAST_MODIFIED) + .tdbid(DATABASE_2_ID) + .queueName(TABLE_4_QUEUE_NAME) + .routingKey(TABLE_4_ROUTING_KEY) + .columns(TABLE_4_COLUMNS) + .constraints(TABLE_4_CONSTRAINTS) + .creator(USER_1) + .build(); + + public final static Table TABLE_4_NOCOLS = Table.builder() + .id(TABLE_4_ID) + .created(Instant.now()) + .internalName(TABLE_4_INTERNALNAME) + .description(TABLE_4_DESCRIPTION) + .name(TABLE_4_NAME) + .lastModified(TABLE_4_LAST_MODIFIED) + .tdbid(DATABASE_1_ID) + .queueName(TABLE_4_QUEUE_NAME) + .routingKey(TABLE_4_ROUTING_KEY) + .columns(List.of()) + .creator(USER_1) + .created(TABLE_4_CREATED) + .lastModified(TABLE_4_LAST_MODIFIED) + .build(); + + public final static List<ForeignKeyCreateDto> TABLE_4_FOREIGN_KEYS_INVALID_CREATE = List.of(ForeignKeyCreateDto.builder() + .columns(List.of("somecolumn")) + .referencedTable("sometable") + .referencedColumns(List.of("someothercolumn")) + .build()); + + public final static ConstraintsCreateDto TABLE_4_CONSTRAINTS_INVALID_CREATE = ConstraintsCreateDto.builder() + .foreignKeys(TABLE_4_FOREIGN_KEYS_INVALID_CREATE) + .build(); + + public final static List<ColumnCreateDto> TABLE_4_COLUMNS_INVALID_CREATE = List.of(ColumnCreateDto.builder() + .name(COLUMN_4_2_NAME) + .type(COLUMN_4_2_TYPE_DTO) + .dfid(COLUMN_4_2_DATE_FORMAT) + .nullAllowed(COLUMN_4_2_NULL) + .primaryKey(COLUMN_4_2_PRIMARY) + .enumValues(COLUMN_4_2_ENUM_VALUES_ARRAY) + .build()); + + public final static List<ColumnCreateDto> TABLE_4_COLUMNS_CREATE = List.of(ColumnCreateDto.builder() + .name(COLUMN_4_1_NAME) + .type(COLUMN_4_1_TYPE_DTO) + .dfid(COLUMN_4_1_DATE_FORMAT) + .nullAllowed(COLUMN_4_1_NULL) + .primaryKey(COLUMN_4_1_PRIMARY) + .enumValues(COLUMN_4_1_ENUM_VALUES_ARRAY) + .build(), + ColumnCreateDto.builder() + .name(COLUMN_4_2_NAME) + .type(COLUMN_4_2_TYPE_DTO) + .dfid(COLUMN_4_2_DATE_FORMAT) + .nullAllowed(COLUMN_4_2_NULL) + .primaryKey(COLUMN_4_2_PRIMARY) + .enumValues(COLUMN_4_2_ENUM_VALUES_ARRAY) + .build()); + + public final static TableCreateDto TABLE_4_CREATE_DTO = TableCreateDto.builder() + .name(TABLE_4_NAME) + .description(TABLE_4_DESCRIPTION) + .columns(TABLE_4_COLUMNS_CREATE) + .constraints(null) + .build(); + + public final static TableCreateDto TABLE_4_INVALID_CREATE_DTO = TableCreateDto.builder() + .name(TABLE_4_NAME) + .description(TABLE_4_DESCRIPTION) + .columns(TABLE_4_COLUMNS_CREATE) + .constraints(TABLE_4_CONSTRAINTS_INVALID_CREATE) + .build(); + + public final static List<TableColumn> TABLE_5_COLUMNS = List.of(TableColumn.builder() + .id(COLUMN_5_1_ID) + .ordinalPosition(COLUMN_5_1_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_5_ID) + .name(COLUMN_5_1_NAME) + .internalName(COLUMN_5_1_INTERNAL_NAME) + .columnType(COLUMN_5_1_TYPE) + .dfid(COLUMN_5_1_DATE_FORMAT) + .isNullAllowed(COLUMN_5_1_NULL) + .autoGenerated(COLUMN_5_1_AUTO_GENERATED) + .isPrimaryKey(COLUMN_5_1_PRIMARY) + .enumValues(COLUMN_5_1_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_5_2_ID) + .ordinalPosition(COLUMN_5_2_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_5_ID) + .name(COLUMN_5_2_NAME) + .internalName(COLUMN_5_2_INTERNAL_NAME) + .columnType(COLUMN_5_2_TYPE) + .dfid(COLUMN_5_2_DATE_FORMAT) + .isNullAllowed(COLUMN_5_2_NULL) + .autoGenerated(COLUMN_5_2_AUTO_GENERATED) + .isPrimaryKey(COLUMN_5_2_PRIMARY) + .enumValues(COLUMN_5_2_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_5_3_ID) + .ordinalPosition(COLUMN_5_3_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_5_ID) + .name(COLUMN_5_3_NAME) + .internalName(COLUMN_5_3_INTERNAL_NAME) + .columnType(COLUMN_5_3_TYPE) + .dfid(COLUMN_5_3_DATE_FORMAT) + .isNullAllowed(COLUMN_5_3_NULL) + .autoGenerated(COLUMN_5_3_AUTO_GENERATED) + .isPrimaryKey(COLUMN_5_3_PRIMARY) + .enumValues(COLUMN_5_3_ENUM_VALUES) + .build()); + + public final static Constraints TABLE_5_CONSTRAINTS = Constraints.builder() + .uniques(List.of(Unique.builder().columns(List.of(TABLE_5_COLUMNS.get(0))).build())) + .build(); + + public final static Table TABLE_5 = Table.builder() + .id(TABLE_5_ID) + .created(Instant.now()) + .internalName(TABLE_5_INTERNALNAME) + .description(TABLE_5_DESCRIPTION) + .name(TABLE_5_NAME) + .lastModified(TABLE_5_LAST_MODIFIED) + .tdbid(DATABASE_2_ID) + .queueName(TABLE_5_QUEUE_NAME) + .routingKey(TABLE_5_ROUTING_KEY) + .columns(TABLE_5_COLUMNS) + .constraints(TABLE_5_CONSTRAINTS) + .creator(USER_1) + .created(TABLE_5_CREATED) + .lastModified(TABLE_5_LAST_MODIFIED) + .build(); + + public final static List<ColumnCreateDto> TABLE_5_COLUMNS_CREATE = List.of( + ColumnCreateDto.builder() + .name(COLUMN_5_1_NAME) + .type(COLUMN_5_1_TYPE_DTO) + .dfid(COLUMN_5_1_DATE_FORMAT) + .nullAllowed(COLUMN_5_1_NULL) + .primaryKey(COLUMN_5_1_PRIMARY) + .build(), + ColumnCreateDto.builder() + .name(COLUMN_5_2_NAME) + .type(COLUMN_5_2_TYPE_DTO) + .length(COLUMN_5_2_LENGTH) + .dfid(COLUMN_5_2_DATE_FORMAT) + .nullAllowed(COLUMN_5_2_NULL) + .primaryKey(COLUMN_5_2_PRIMARY) + .build(), + ColumnCreateDto.builder() + .name(COLUMN_5_3_NAME) + .type(COLUMN_5_3_TYPE_DTO) + .length(COLUMN_5_3_LENGTH) + .dfid(COLUMN_5_3_DATE_FORMAT) + .nullAllowed(COLUMN_5_3_NULL) + .primaryKey(COLUMN_5_3_PRIMARY) + .build(), + ColumnCreateDto.builder() + .name(COLUMN_5_4_NAME) + .type(COLUMN_5_4_TYPE_DTO) + .dfid(COLUMN_5_4_DATE_FORMAT) + .nullAllowed(COLUMN_5_4_NULL) + .primaryKey(COLUMN_5_4_PRIMARY) + .build()); + + public final static List<List<String>> TABLE_5_UNIQUES_CREATE = List.of( + List.of(COLUMN_5_1_NAME), + List.of(COLUMN_5_2_NAME, COLUMN_5_3_NAME)); + + public final static List<ForeignKeyCreateDto> TABLE_5_FOREIGN_KEYS_CREATE = List.of(ForeignKeyCreateDto.builder() + .columns(List.of(COLUMN_5_4_NAME)) + .referencedTable(TABLE_4_NAME) + .referencedColumns(List.of(COLUMN_4_1_NAME)) + .build()); + + public final static List<String> TABLE_5_CHECKS_CREATE = List.of( + COLUMN_5_2_NAME + " != " + COLUMN_5_3_NAME); + + public final static ConstraintsCreateDto TABLE_5_CONSTRAINTS_CREATE = ConstraintsCreateDto.builder() + .uniques(TABLE_5_UNIQUES_CREATE) + .foreignKeys(TABLE_5_FOREIGN_KEYS_CREATE) + .checks(TABLE_5_CHECKS_CREATE) + .build(); + + public final static TableCreateDto TABLE_5_CREATE_DTO = TableCreateDto.builder() + .name(TABLE_5_NAME) + .description(TABLE_5_DESCRIPTION) + .columns(TABLE_5_COLUMNS_CREATE) + .constraints(TABLE_5_CONSTRAINTS_CREATE) + .build(); + + public final static Long COLUMN_6_1_ID = 26L; + public final static Integer COLUMN_6_1_ORDINALPOS = 0; + public final static Boolean COLUMN_6_1_PRIMARY = true; + public final static String COLUMN_6_1_NAME = "name_id"; + public final static String COLUMN_6_1_INTERNAL_NAME = "name_id"; + public final static TableColumnType COLUMN_6_1_TYPE = TableColumnType.NUMBER; + public final static Long COLUMN_6_1_DATE_FORMAT = null; + public final static Boolean COLUMN_6_1_NULL = false; + public final static Boolean COLUMN_6_1_UNIQUE = false; + public final static Boolean COLUMN_6_1_AUTO_GENERATED = false; + public final static String COLUMN_6_1_FOREIGN_KEY = null; + public final static String COLUMN_6_1_CHECK = null; + public final static List<String> COLUMN_6_1_ENUM_VALUES = null; + + public final static Long COLUMN_6_2_ID = 27L; + public final static Integer COLUMN_6_2_ORDINALPOS = 1; + public final static Boolean COLUMN_6_2_PRIMARY = true; + public final static String COLUMN_6_2_NAME = "zoo_id"; + public final static String COLUMN_6_2_INTERNAL_NAME = "zoo_id"; + public final static TableColumnType COLUMN_6_2_TYPE = TableColumnType.NUMBER; + public final static Long COLUMN_6_2_DATE_FORMAT = null; + public final static Boolean COLUMN_6_2_NULL = false; + public final static Boolean COLUMN_6_2_UNIQUE = false; + public final static Boolean COLUMN_6_2_AUTO_GENERATED = false; + public final static String COLUMN_6_2_FOREIGN_KEY = null; + public final static String COLUMN_6_2_CHECK = null; + public final static List<String> COLUMN_6_2_ENUM_VALUES = null; + + public final static List<TableColumn> TABLE_6_COLUMNS = List.of(TableColumn.builder() + .id(COLUMN_6_1_ID) + .ordinalPosition(COLUMN_6_1_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_6_ID) + .name(COLUMN_6_1_NAME) + .internalName(COLUMN_6_1_INTERNAL_NAME) + .columnType(COLUMN_6_1_TYPE) + .dfid(COLUMN_6_1_DATE_FORMAT) + .isNullAllowed(COLUMN_6_1_NULL) + .autoGenerated(COLUMN_6_1_AUTO_GENERATED) + .isPrimaryKey(COLUMN_6_1_PRIMARY) + .enumValues(COLUMN_6_1_ENUM_VALUES) + .build(), + TableColumn.builder() + .id(COLUMN_6_2_ID) + .ordinalPosition(COLUMN_6_2_ORDINALPOS) + .cdbid(DATABASE_2_ID) + .tid(TABLE_6_ID) + .name(COLUMN_6_2_NAME) + .internalName(COLUMN_6_2_INTERNAL_NAME) + .columnType(COLUMN_6_2_TYPE) + .dfid(COLUMN_6_2_DATE_FORMAT) + .isNullAllowed(COLUMN_6_2_NULL) + .autoGenerated(COLUMN_6_2_AUTO_GENERATED) + .isPrimaryKey(COLUMN_6_2_PRIMARY) + .enumValues(COLUMN_6_2_ENUM_VALUES) + .build()); + + public final static Table TABLE_6 = Table.builder() + .id(TABLE_6_ID) + .created(Instant.now()) + .internalName(TABLE_6_INTERNAL_NAME) + .description(TABLE_6_DESCRIPTION) + .name(TABLE_6_NAME) + .lastModified(TABLE_6_LAST_MODIFIED) + .tdbid(DATABASE_2_ID) + .queueName(TABLE_6_QUEUE_NAME) + .routingKey(TABLE_6_ROUTING_KEY) + .columns(TABLE_6_COLUMNS) + .creator(USER_1) + .created(TABLE_6_CREATED) + .lastModified(TABLE_6_LAST_MODIFIED) + .build(); + + public final static Table TABLE_7_NOCOLS = Table.builder() + .id(TABLE_7_ID) + .created(Instant.now()) + .internalName(TABLE_7_INTERNAL_NAME) + .description(TABLE_7_DESCRIPTION) + .name(TABLE_7_NAME) + .lastModified(TABLE_7_LAST_MODIFIED) + .tdbid(DATABASE_1_ID) + .queueName(TABLE_7_QUEUE_NAME) + .routingKey(TABLE_7_ROUTING_KEY) + .columns(List.of()) + .creator(USER_1) + .build(); + + public final static Long VIEW_1_ID = 1L; + public final static Boolean VIEW_1_INITIAL_VIEW = false; + public final static String VIEW_1_NAME = "JUnit"; + public final static String VIEW_1_INTERNAL_NAME = "junit"; + public final static Long VIEW_1_CONTAINER_ID = CONTAINER_1_ID; + public final static Long VIEW_1_DATABASE_ID = DATABASE_1_ID; + public final static Boolean VIEW_1_PUBLIC = true; + public final static String VIEW_1_QUERY = "select `location`, `lat`, `lng` from `weather_location`"; + + public final static View VIEW_1 = View.builder() + .id(VIEW_1_ID) + .isInitialView(VIEW_1_INITIAL_VIEW) + .name(VIEW_1_NAME) + .internalName(VIEW_1_INTERNAL_NAME) + .vcid(VIEW_1_CONTAINER_ID) + .vdbid(VIEW_1_DATABASE_ID) + .isPublic(VIEW_1_PUBLIC) + .query(VIEW_1_QUERY) + .creator(USER_1) + .build(); + + public final static ViewDto VIEW_1_DTO = ViewDto.builder() + .id(VIEW_1_ID) + .isInitialView(VIEW_1_INITIAL_VIEW) + .name(VIEW_1_NAME) + .internalName(VIEW_1_INTERNAL_NAME) + .vdbid(VIEW_1_DATABASE_ID) + .isPublic(VIEW_1_PUBLIC) + .query(VIEW_1_QUERY) + .build(); + + public final static Long VIEW_2_ID = 2L; + public final static Boolean VIEW_2_INITIAL_VIEW = false; + public final static String VIEW_2_NAME = "JUnit2"; + public final static String VIEW_2_INTERNAL_NAME = "junit2"; + public final static Long VIEW_2_CONTAINER_ID = CONTAINER_1_ID; + public final static Long VIEW_2_DATABASE_ID = DATABASE_1_ID; + public final static Boolean VIEW_2_PUBLIC = true; + public final static String VIEW_2_QUERY = "select `date`, `location`, `mintemp`, `rainfall` from `weather_aus` where `location` = 'Albury'"; + + public final static View VIEW_2 = View.builder() + .id(VIEW_2_ID) + .isInitialView(VIEW_2_INITIAL_VIEW) + .name(VIEW_2_NAME) + .internalName(VIEW_2_INTERNAL_NAME) + .vcid(VIEW_2_CONTAINER_ID) + .vdbid(VIEW_2_DATABASE_ID) + .isPublic(VIEW_2_PUBLIC) + .query(VIEW_2_QUERY) + .creator(USER_1) + .build(); + + public final static ViewDto VIEW_2_DTO = ViewDto.builder() + .id(VIEW_2_ID) + .isInitialView(VIEW_2_INITIAL_VIEW) + .name(VIEW_2_NAME) + .internalName(VIEW_2_INTERNAL_NAME) + .vdbid(VIEW_2_DATABASE_ID) + .isPublic(VIEW_2_PUBLIC) + .query(VIEW_2_QUERY) + .build(); + + public final static Long VIEW_3_ID = 3L; + public final static Boolean VIEW_3_INITIAL_VIEW = false; + public final static String VIEW_3_NAME = "JUnit3"; + public final static String VIEW_3_INTERNAL_NAME = "junit3"; + public final static Long VIEW_3_CONTAINER_ID = CONTAINER_1_ID; + public final static Long VIEW_3_DATABASE_ID = DATABASE_1_ID; + public final static Boolean VIEW_3_PUBLIC = false; + public final static String VIEW_3_QUERY = "select w.`mintemp`, w.`rainfall`, w.`location`, m.`lat`, m.`lng` from `weather_aus` w join `junit2` m on m.`location` = w.`location`"; + + public final static View VIEW_3 = View.builder() + .id(VIEW_3_ID) + .isInitialView(VIEW_3_INITIAL_VIEW) + .name(VIEW_3_NAME) + .internalName(VIEW_3_INTERNAL_NAME) + .vcid(VIEW_3_CONTAINER_ID) + .vdbid(VIEW_3_DATABASE_ID) + .isPublic(VIEW_3_PUBLIC) + .query(VIEW_3_QUERY) + .creator(USER_1) + .build(); + + public final static ViewDto VIEW_3_DTO = ViewDto.builder() + .id(VIEW_3_ID) + .isInitialView(VIEW_3_INITIAL_VIEW) + .name(VIEW_3_NAME) + .internalName(VIEW_3_INTERNAL_NAME) + .vdbid(VIEW_3_DATABASE_ID) + .isPublic(VIEW_3_PUBLIC) + .query(VIEW_3_QUERY) + .build(); + + public final static Long VIEW_4_ID = 4L; + public final static Boolean VIEW_4_INITIAL_VIEW = false; + public final static String VIEW_4_NAME = "Mock View"; + public final static String VIEW_4_INTERNAL_NAME = "mock_view"; + public final static Long VIEW_4_CONTAINER_ID = CONTAINER_2_ID; + public final static Long VIEW_4_DATABASE_ID = DATABASE_2_ID; + public final static Boolean VIEW_4_PUBLIC = true; + public final static String VIEW_4_QUERY = "SELECT `animal_name`, `hair`, `feathers`, `eggs`, `milk`, `airborne`, `aquatic`, `predator`, `toothed`, `backbone`, `breathes`, `venomous`, `fins`, `legs`, `tail`, `domestic`, `catsize`, `class_type`FROM `zoo`WHERE `class_type` = 1"; + + public final static View VIEW_4 = View.builder() + .id(VIEW_4_ID) + .isInitialView(VIEW_4_INITIAL_VIEW) + .name(VIEW_4_NAME) + .internalName(VIEW_4_INTERNAL_NAME) + .vcid(VIEW_4_CONTAINER_ID) + .vdbid(VIEW_4_DATABASE_ID) + .isPublic(VIEW_4_PUBLIC) + .query(VIEW_4_QUERY) + .build(); + + public final static Long VIEW_5_ID = 5L; + public final static Boolean VIEW_5_INITIAL_VIEW = false; + public final static String VIEW_5_NAME = "Mock View"; + public final static String VIEW_5_INTERNAL_NAME = "mock_view"; + public final static Long VIEW_5_CONTAINER_ID = CONTAINER_2_ID; + public final static Long VIEW_5_DATABASE_ID = DATABASE_2_ID; + public final static Boolean VIEW_5_PUBLIC = true; + public final static String VIEW_5_QUERY = "SELECT `location`, `lat`, `lng` FROM `weather_location` WHERE `location` = 'Albury'"; + + public final static View VIEW_5 = View.builder() + .id(VIEW_5_ID) + .isInitialView(VIEW_5_INITIAL_VIEW) + .name(VIEW_5_NAME) + .internalName(VIEW_5_INTERNAL_NAME) + .vcid(VIEW_5_CONTAINER_ID) + .vdbid(VIEW_5_DATABASE_ID) + .isPublic(VIEW_5_PUBLIC) + .query(VIEW_5_QUERY) + .build(); + + public final static Long QUERY_1_RESULT_ID = 1L; + public final static List<Map<String, Object>> QUERY_1_RESULT_RESULT = List.of( + new HashMap<>() {{ + put("location", "Albury"); + put("lat", -36.0653583); + put("lng", 146.9112214); + }}, new HashMap<>() {{ + put("location", "Sydney"); + put("lat", -33.847927); + put("lng", 150.6517942); + }}); + + public final static QueryResultDto QUERY_1_RESULT_DTO = QueryResultDto.builder() + .id(QUERY_1_RESULT_ID) + .resultNumber(QUERY_1_RESULT_NUMBER) + .result(QUERY_1_RESULT_RESULT) + .build(); + + public final static TableCsvDto TABLE_1_CSV_DTO = TableCsvDto.builder() + .data(new HashMap<>() {{ + put("id", 1); + put("date", "2022-12-20"); + put("location", "Vienna"); + put("mintemp", -2.3); + put("rainfall", 34.3); + }}) + .build(); + + public final static String LICENSE_1_IDENTIFIER = "MIT"; + public final static String LICENSE_1_URI = "https://opensource.org/licenses/MIT"; + + public final static License LICENSE_1 = License.builder() + .identifier(LICENSE_1_IDENTIFIER) + .uri(LICENSE_1_URI) + .build(); + + public final static LicenseDto LICENSE_1_DTO = LicenseDto.builder() + .identifier(LICENSE_1_IDENTIFIER) + .uri(LICENSE_1_URI) + .build(); + + public final static Long CREATOR_1_ID = 1L; + public final static Long CREATOR_1_QUERY_ID = 1L; + public final static String CREATOR_1_ORCID = "00000-00000-00000"; + public final static String CREATOR_1_AFFIL = "TU Graz"; + public final static String CREATOR_1_FIRSTNAME = "Max"; + public final static String CREATOR_1_LASTNAME = "Mustermann"; + public final static Instant CREATOR_1_CREATED = Instant.ofEpochSecond(1641588352); + public final static Instant CREATOR_1_MODIFIED = Instant.ofEpochSecond(1541588352); + + public final static Long CREATOR_2_ID = 2L; + public final static Long CREATOR_2_QUERY_ID = 1L; + public final static String CREATOR_2_ORCID = "00000-00000-00000"; + public final static String CREATOR_2_AFFIL = "TU Wien"; + public final static String CREATOR_2_FIRSTNAME = "Martina"; + public final static String CREATOR_2_LASTNAME = "Mustermann"; + public final static Instant CREATOR_2_CREATED = Instant.ofEpochSecond(1641588352); + public final static Instant CREATOR_2_MODIFIED = Instant.ofEpochSecond(1541588352); + + public final static Long CREATOR_3_ID = 3L; + public final static Long CREATOR_3_QUERY_ID = 1L; + public final static String CREATOR_3_ORCID = "00000-00000-00000"; + public final static String CREATOR_3_AFFIL = "TU Graz"; + public final static String CREATOR_3_FIRSTNAME = "Max"; + public final static String CREATOR_3_LASTNAME = "Mustermann"; + public final static Instant CREATOR_3_CREATED = Instant.ofEpochSecond(1641588352); + public final static Instant CREATOR_3_MODIFIED = Instant.ofEpochSecond(1541588352); + + public final static Long CREATOR_4_ID = 4L; + public final static Long CREATOR_4_QUERY_ID = 1L; + public final static String CREATOR_4_ORCID = "00000-00000-00000"; + public final static String CREATOR_4_AFFIL = "TU Wien"; + public final static String CREATOR_4_FIRSTNAME = "Martina"; + public final static String CREATOR_4_LASTNAME = "Mustermann"; + public final static Instant CREATOR_4_CREATED = Instant.ofEpochSecond(1641588352); + public final static Instant CREATOR_4_MODIFIED = Instant.ofEpochSecond(1541588352); + + public final static Long IDENTIFIER_1_ID = 1L; + public final static Long IDENTIFIER_1_QUERY_ID = QUERY_1_ID; + public final static Long IDENTIFIER_1_CONTAINER_ID = CONTAINER_1_ID; + public final static Long IDENTIFIER_1_DATABASE_ID = DATABASE_1_ID; + public final static String IDENTIFIER_1_DESCRIPTION = "Selecting all from the weather Austrian table"; + public final static String IDENTIFIER_1_DESCRIPTION_MODIFY = "Selecting some from the weather Austrian table"; + public final static String IDENTIFIER_1_TITLE = "Austrian weather data"; + public final static String IDENTIFIER_1_TITLE_MODIFY = "Austrian weather some data"; + public final static String IDENTIFIER_1_DOI = null; + public final static String IDENTIFIER_1_DOI_NOT_NULL = "10.1000/183"; + public final static VisibilityType IDENTIFIER_1_VISIBILITY = VisibilityType.EVERYONE; + public final static VisibilityTypeDto IDENTIFIER_1_VISIBILITY_DTO = VisibilityTypeDto.EVERYONE; + public final static Instant IDENTIFIER_1_CREATED = Instant.ofEpochSecond(1641588352) /* 2022-01-07 20:45:52 */; + public final static Instant IDENTIFIER_1_MODIFIED = Instant.ofEpochSecond(1541588352) /* 2022-01-07 20:45:52 */; + public final static Instant IDENTIFIER_1_EXECUTION = Instant.ofEpochSecond(1541588352) /* 2022-01-07 20:45:52 */; + public final static Integer IDENTIFIER_1_PUBLICATION_MONTH = 5; + public final static Integer IDENTIFIER_1_PUBLICATION_YEAR = 2022; + public final static Integer IDENTIFIER_1_PUBLICATION_DAY = null; + public final static String IDENTIFIER_1_QUERY_HASH = QUERY_1_QUERY_HASH; + public final static String IDENTIFIER_1_RESULT_HASH = QUERY_1_RESULT_HASH; + public final static String IDENTIFIER_1_QUERY = QUERY_1_STATEMENT; + public final static String IDENTIFIER_1_NORMALIZED = QUERY_1_STATEMENT; + public final static Long IDENTIFIER_1_RESULT_NUMBER = QUERY_1_RESULT_NUMBER; + public final static String IDENTIFIER_1_PUBLISHER = "Austrian Government"; + public final static IdentifierType IDENTIFIER_1_TYPE = IdentifierType.SUBSET; + public final static IdentifierTypeDto IDENTIFIER_1_TYPE_DTO = IdentifierTypeDto.DATABASE; + + public final static Creator IDENTIFIER_1_CREATOR_1 = Creator.builder() + .id(CREATOR_1_ID) + .pid(IDENTIFIER_1_ID) + .firstname(CREATOR_1_FIRSTNAME) + .lastname(CREATOR_1_LASTNAME) + .orcid(CREATOR_1_ORCID) + .affiliation(CREATOR_1_AFFIL) + .build(); + + public final static CreatorDto IDENTIFIER_1_CREATOR_1_DTO = CreatorDto.builder() + .id(CREATOR_1_ID) + .firstname(CREATOR_1_FIRSTNAME) + .lastname(CREATOR_1_LASTNAME) + .orcid(CREATOR_1_ORCID) + .affiliation(CREATOR_1_AFFIL) + .build(); + + public final static Identifier IDENTIFIER_1 = Identifier.builder() + .id(IDENTIFIER_1_ID) + .containerId(IDENTIFIER_1_CONTAINER_ID) + .databaseId(IDENTIFIER_1_DATABASE_ID) + .queryId(IDENTIFIER_1_QUERY_ID) + .description(IDENTIFIER_1_DESCRIPTION) + .title(IDENTIFIER_1_TITLE) + .doi(IDENTIFIER_1_DOI) + .visibility(IDENTIFIER_1_VISIBILITY) + .created(IDENTIFIER_1_CREATED) + .lastModified(IDENTIFIER_1_MODIFIED) + .execution(IDENTIFIER_1_EXECUTION) + .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) + .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) + .queryHash(IDENTIFIER_1_QUERY_HASH) + .resultHash(IDENTIFIER_1_RESULT_HASH) + .query(IDENTIFIER_1_QUERY) + .queryNormalized(IDENTIFIER_1_NORMALIZED) + .resultNumber(IDENTIFIER_1_RESULT_NUMBER) + .publisher(IDENTIFIER_1_PUBLISHER) + .type(IDENTIFIER_1_TYPE) + .creators(List.of(IDENTIFIER_1_CREATOR_1)) + .build(); + + public final static Identifier IDENTIFIER_1_WITH_DOI = Identifier.builder() + .id(IDENTIFIER_1_ID) + .containerId(IDENTIFIER_1_CONTAINER_ID) + .databaseId(IDENTIFIER_1_DATABASE_ID) + .queryId(IDENTIFIER_1_QUERY_ID) + .description(IDENTIFIER_1_DESCRIPTION) + .title(IDENTIFIER_1_TITLE) + .doi(IDENTIFIER_1_DOI_NOT_NULL) + .visibility(IDENTIFIER_1_VISIBILITY) + .created(IDENTIFIER_1_CREATED) + .lastModified(IDENTIFIER_1_MODIFIED) + .execution(IDENTIFIER_1_EXECUTION) + .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) + .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) + .queryHash(IDENTIFIER_1_QUERY_HASH) + .resultHash(IDENTIFIER_1_RESULT_HASH) + .query(IDENTIFIER_1_QUERY) + .queryNormalized(IDENTIFIER_1_NORMALIZED) + .resultNumber(IDENTIFIER_1_RESULT_NUMBER) + .publisher(IDENTIFIER_1_PUBLISHER) + .type(IDENTIFIER_1_TYPE) + .creators(List.of(IDENTIFIER_1_CREATOR_1)) + .build(); + + public final static IdentifierDto IDENTIFIER_1_DTO = IdentifierDto.builder() + .id(IDENTIFIER_1_ID) + .containerId(IDENTIFIER_1_CONTAINER_ID) + .databaseId(IDENTIFIER_1_DATABASE_ID) + .queryId(IDENTIFIER_1_QUERY_ID) + .description(IDENTIFIER_1_DESCRIPTION) + .title(IDENTIFIER_1_TITLE) + .doi(IDENTIFIER_1_DOI) + .visibility(IDENTIFIER_1_VISIBILITY_DTO) + .created(IDENTIFIER_1_CREATED) + .lastModified(IDENTIFIER_1_MODIFIED) + .execution(IDENTIFIER_1_EXECUTION) + .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) + .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) + .queryHash(IDENTIFIER_1_QUERY_HASH) + .resultHash(IDENTIFIER_1_RESULT_HASH) + .query(IDENTIFIER_1_QUERY) + .queryNormalized(IDENTIFIER_1_NORMALIZED) + .resultNumber(IDENTIFIER_1_RESULT_NUMBER) + .publisher(IDENTIFIER_1_PUBLISHER) + .type(IDENTIFIER_1_TYPE_DTO) + .creator(USER_1_DTO) + .creators(List.of(IDENTIFIER_1_CREATOR_1_DTO)) + .build(); + + public final static IdentifierDto IDENTIFIER_1_WITH_DOI_DTO = IdentifierDto.builder() + .id(IDENTIFIER_1_ID) + .containerId(IDENTIFIER_1_CONTAINER_ID) + .databaseId(IDENTIFIER_1_DATABASE_ID) + .queryId(IDENTIFIER_1_QUERY_ID) + .description(IDENTIFIER_1_DESCRIPTION) + .title(IDENTIFIER_1_TITLE) + .doi(IDENTIFIER_1_DOI_NOT_NULL) + .visibility(IDENTIFIER_1_VISIBILITY_DTO) + .created(IDENTIFIER_1_CREATED) + .lastModified(IDENTIFIER_1_MODIFIED) + .execution(IDENTIFIER_1_EXECUTION) + .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) + .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) + .queryHash(IDENTIFIER_1_QUERY_HASH) + .resultHash(IDENTIFIER_1_RESULT_HASH) + .query(IDENTIFIER_1_QUERY) + .queryNormalized(IDENTIFIER_1_NORMALIZED) + .resultNumber(IDENTIFIER_1_RESULT_NUMBER) + .publisher(IDENTIFIER_1_PUBLISHER) + .type(IDENTIFIER_1_TYPE_DTO) + .creator(USER_1_DTO) + .creators(List.of(IDENTIFIER_1_CREATOR_1_DTO)) + .build(); + + public final static Long IDENTIFIER_2_ID = 2L; + public final static Long IDENTIFIER_2_QUERY_ID = QUERY_2_ID; + public final static Long IDENTIFIER_2_CONTAINER_ID = CONTAINER_2_ID; + public final static Long IDENTIFIER_2_DATABASE_ID = DATABASE_2_ID; + public final static String IDENTIFIER_2_DESCRIPTION = "Selecting all from the weather Austria table"; + public final static String IDENTIFIER_2_TITLE = "Australian weather data"; + public final static String IDENTIFIER_2_DOI = null; + public final static VisibilityType IDENTIFIER_2_VISIBILITY = VisibilityType.EVERYONE; + public final static VisibilityTypeDto IDENTIFIER_2_VISIBILITY_DTO = VisibilityTypeDto.EVERYONE; + public final static Instant IDENTIFIER_2_CREATED = Instant.ofEpochSecond(1641588352); + public final static Instant IDENTIFIER_2_MODIFIED = Instant.ofEpochSecond(1541588352); + public final static Instant IDENTIFIER_2_EXECUTION = Instant.ofEpochSecond(1541588352); + public final static Integer IDENTIFIER_2_PUBLICATION_DAY = 14; + public final static Integer IDENTIFIER_2_PUBLICATION_MONTH = 7; + public final static Integer IDENTIFIER_2_PUBLICATION_YEAR = 2022; + public final static String IDENTIFIER_2_QUERY_HASH = QUERY_2_QUERY_HASH; + public final static String IDENTIFIER_2_RESULT_HASH = QUERY_2_RESULT_HASH; + public final static String IDENTIFIER_2_QUERY = QUERY_2_STATEMENT; + public final static String IDENTIFIER_2_NORMALIZED = QUERY_2_STATEMENT; + public final static Long IDENTIFIER_2_RESULT_NUMBER = QUERY_2_RESULT_NUMBER; + public final static String IDENTIFIER_2_PUBLISHER = "Australian Government"; + public final static IdentifierType IDENTIFIER_2_TYPE = IdentifierType.SUBSET; + public final static IdentifierTypeDto IDENTIFIER_2_TYPE_DTO = IdentifierTypeDto.SUBSET; + + public final static Creator IDENTIFIER_2_CREATOR_1 = Creator.builder() + .id(CREATOR_1_ID) + .pid(IDENTIFIER_2_ID) + .firstname(CREATOR_1_FIRSTNAME) + .lastname(CREATOR_1_LASTNAME) + .orcid(CREATOR_1_ORCID) + .affiliation(CREATOR_1_AFFIL) + .build(); + + public final static CreatorDto IDENTIFIER_2_CREATOR_1_DTO = CreatorDto.builder() + .id(CREATOR_1_ID) + .firstname(CREATOR_1_FIRSTNAME) + .lastname(CREATOR_1_LASTNAME) + .orcid(CREATOR_1_ORCID) + .affiliation(CREATOR_1_AFFIL) + .build(); + + public final static Creator IDENTIFIER_2_CREATOR_2 = Creator.builder() + .id(CREATOR_2_ID) + .pid(IDENTIFIER_2_ID) + .firstname(CREATOR_2_FIRSTNAME) + .lastname(CREATOR_2_LASTNAME) + .orcid(CREATOR_2_ORCID) + .affiliation(CREATOR_2_AFFIL) + .build(); + + public final static CreatorDto IDENTIFIER_2_CREATOR_2_DTO = CreatorDto.builder() + .id(CREATOR_2_ID) + .firstname(CREATOR_2_FIRSTNAME) + .lastname(CREATOR_2_LASTNAME) + .orcid(CREATOR_2_ORCID) + .affiliation(CREATOR_2_AFFIL) + .build(); + + public final static Identifier IDENTIFIER_2 = Identifier.builder() + .id(IDENTIFIER_2_ID) + .containerId(IDENTIFIER_2_CONTAINER_ID) + .databaseId(IDENTIFIER_2_DATABASE_ID) + .queryId(IDENTIFIER_2_QUERY_ID) + .description(IDENTIFIER_2_DESCRIPTION) + .title(IDENTIFIER_2_TITLE) + .doi(IDENTIFIER_2_DOI) + .visibility(IDENTIFIER_2_VISIBILITY) + .created(IDENTIFIER_2_CREATED) + .lastModified(IDENTIFIER_2_MODIFIED) + .execution(IDENTIFIER_2_EXECUTION) + .publicationDay(IDENTIFIER_2_PUBLICATION_DAY) + .publicationMonth(IDENTIFIER_2_PUBLICATION_MONTH) + .publicationYear(IDENTIFIER_2_PUBLICATION_YEAR) + .queryHash(IDENTIFIER_2_QUERY_HASH) + .resultHash(IDENTIFIER_2_RESULT_HASH) + .query(IDENTIFIER_2_QUERY) + .queryNormalized(IDENTIFIER_2_NORMALIZED) + .resultNumber(IDENTIFIER_2_RESULT_NUMBER) + .publisher(IDENTIFIER_2_PUBLISHER) + .type(IDENTIFIER_2_TYPE) + .creator(USER_2) + .creators(List.of(IDENTIFIER_2_CREATOR_1, IDENTIFIER_2_CREATOR_2)) + .build(); + + public final static IdentifierDto IDENTIFIER_2_DTO = IdentifierDto.builder() + .id(IDENTIFIER_2_ID) + .containerId(IDENTIFIER_2_CONTAINER_ID) + .databaseId(IDENTIFIER_2_DATABASE_ID) + .queryId(IDENTIFIER_2_QUERY_ID) + .description(IDENTIFIER_2_DESCRIPTION) + .title(IDENTIFIER_2_TITLE) + .doi(IDENTIFIER_2_DOI) + .visibility(IDENTIFIER_2_VISIBILITY_DTO) + .created(IDENTIFIER_2_CREATED) + .lastModified(IDENTIFIER_2_MODIFIED) + .execution(IDENTIFIER_2_EXECUTION) + .publicationDay(IDENTIFIER_2_PUBLICATION_DAY) + .publicationMonth(IDENTIFIER_2_PUBLICATION_MONTH) + .publicationYear(IDENTIFIER_2_PUBLICATION_YEAR) + .queryHash(IDENTIFIER_2_QUERY_HASH) + .resultHash(IDENTIFIER_2_RESULT_HASH) + .query(IDENTIFIER_2_QUERY) + .queryNormalized(IDENTIFIER_2_NORMALIZED) + .resultNumber(IDENTIFIER_2_RESULT_NUMBER) + .publisher(IDENTIFIER_2_PUBLISHER) + .type(IDENTIFIER_2_TYPE_DTO) + .creator(USER_2_DTO) + .creators(List.of(IDENTIFIER_2_CREATOR_1_DTO, IDENTIFIER_2_CREATOR_2_DTO)) + .build(); + + public final static Creator CREATOR_1 = Creator.builder() + .id(CREATOR_1_ID) + .pid(IDENTIFIER_1_ID) + .orcid(CREATOR_1_ORCID) + .firstname(CREATOR_1_FIRSTNAME) + .lastname(CREATOR_1_LASTNAME) + .orcid(CREATOR_1_ORCID) + .created(CREATOR_1_CREATED) + .affiliation(CREATOR_1_AFFIL) + .lastModified(CREATOR_1_MODIFIED) + .build(); + + public final static Creator CREATOR_2 = Creator.builder() + .id(CREATOR_2_ID) + .pid(IDENTIFIER_1_ID) + .orcid(CREATOR_2_ORCID) + .firstname(CREATOR_2_FIRSTNAME) + .lastname(CREATOR_2_LASTNAME) + .orcid(CREATOR_1_ORCID) + .created(CREATOR_2_CREATED) + .affiliation(CREATOR_2_AFFIL) + .lastModified(CREATOR_2_MODIFIED) + .build(); + + public final static Creator CREATOR_3 = Creator.builder() + .id(CREATOR_3_ID) + .pid(IDENTIFIER_1_ID) + .orcid(CREATOR_3_ORCID) + .firstname(CREATOR_3_FIRSTNAME) + .lastname(CREATOR_3_LASTNAME) + .created(CREATOR_3_CREATED) + .affiliation(CREATOR_3_AFFIL) + .lastModified(CREATOR_3_MODIFIED) + .build(); + + public final static CreatorDto CREATOR_1_DTO = CreatorDto.builder() + .id(CREATOR_1_ID) + .affiliation(CREATOR_1_AFFIL) + .orcid(CREATOR_1_ORCID) + .firstname(CREATOR_1_FIRSTNAME) + .lastname(CREATOR_1_LASTNAME) + .build(); + + public final static CreatorCreateDto CREATOR_1_CREATE_DTO = CreatorCreateDto.builder() + .affiliation(CREATOR_1_AFFIL) + .orcid(CREATOR_1_ORCID) + .firstname(CREATOR_1_FIRSTNAME) + .lastname(CREATOR_1_LASTNAME) + .build(); + + public final static CreatorDto CREATOR_2_DTO = CreatorDto.builder() + .id(CREATOR_2_ID) + .affiliation(CREATOR_2_AFFIL) + .orcid(CREATOR_2_ORCID) + .firstname(CREATOR_2_FIRSTNAME) + .lastname(CREATOR_2_LASTNAME) + .build(); + + public final static CreatorCreateDto CREATOR_2_CREATE_DTO = CreatorCreateDto.builder() + .affiliation(CREATOR_2_AFFIL) + .orcid(CREATOR_2_ORCID) + .firstname(CREATOR_2_FIRSTNAME) + .lastname(CREATOR_2_LASTNAME) + .build(); + + public final static IdentifierDto IDENTIFIER_1_MODIFY_DTO = IdentifierDto.builder() + .id(IDENTIFIER_1_ID) + .containerId(CONTAINER_1_ID) + .databaseId(DATABASE_1_ID) + .queryId(IDENTIFIER_1_QUERY_ID) + .databaseId(IDENTIFIER_1_DATABASE_ID) + .description(IDENTIFIER_1_DESCRIPTION_MODIFY) + .title(IDENTIFIER_1_TITLE_MODIFY) + .doi(IDENTIFIER_1_DOI) + .publisher(IDENTIFIER_1_PUBLISHER) + .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) + .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) + .type(IDENTIFIER_1_TYPE_DTO) + .visibility(IDENTIFIER_1_VISIBILITY_DTO) + .created(IDENTIFIER_1_CREATED) + .lastModified(IDENTIFIER_1_MODIFIED) + .creators(List.of(CREATOR_1_DTO)) + .build(); + + public final static IdentifierCreateDto IDENTIFIER_1_DTO_REQUEST = IdentifierCreateDto.builder() + .cid(IDENTIFIER_1_CONTAINER_ID) + .dbid(IDENTIFIER_1_DATABASE_ID) + .description(IDENTIFIER_1_DESCRIPTION) + .title(IDENTIFIER_1_TITLE) + .relatedIdentifiers(List.of()) + .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) + .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) + .creators(List.of(CREATOR_1_CREATE_DTO)) + .publisher(IDENTIFIER_1_PUBLISHER) + .type(IDENTIFIER_1_TYPE_DTO) + .build(); + + public final static IdentifierCreateDto IDENTIFIER_1_DTO_TRUSTED_REQUEST = IdentifierCreateDto.builder() + .cid(IDENTIFIER_1_CONTAINER_ID) + .dbid(IDENTIFIER_1_DATABASE_ID) + .description(IDENTIFIER_1_DESCRIPTION) + .title(IDENTIFIER_1_TITLE) + .relatedIdentifiers(List.of()) + .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) + .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) + .creators(List.of(CREATOR_1_CREATE_DTO)) + .publisher(IDENTIFIER_1_PUBLISHER) + .type(IDENTIFIER_1_TYPE_DTO) + .build(); + + public final static IdentifierCreateDto IDENTIFIER_1_DTO_SELF_REQUEST = IdentifierCreateDto.builder() + .cid(IDENTIFIER_1_CONTAINER_ID) + .dbid(IDENTIFIER_1_DATABASE_ID) + .description(IDENTIFIER_1_DESCRIPTION) + .title(IDENTIFIER_1_TITLE) + .relatedIdentifiers(List.of()) + .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) + .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) + .creators(List.of(CREATOR_1_CREATE_DTO)) + .publisher(IDENTIFIER_1_PUBLISHER) + .type(IDENTIFIER_1_TYPE_DTO) + .build(); + + public final static Long RELATED_IDENTIFIER_2_ID = 1L; + public final static Long RELATED_IDENTIFIER_2_IDENTIFIER_ID = 2L; + public final static String RELATED_IDENTIFIER_2_VALUE = "10.5281/zenodo.6637333"; + public final static RelatedType RELATED_IDENTIFIER_2_TYPE = RelatedType.DOI; + public final static RelatedTypeDto RELATED_IDENTIFIER_2_TYPE_DTO = RelatedTypeDto.DOI; + public final static RelationType RELATED_IDENTIFIER_2_RELATION_TYPE = RelationType.CITES; + public final static RelationTypeDto RELATED_IDENTIFIER_2_RELATION = RelationTypeDto.CITES; + + public final static RelatedIdentifier IDENTIFIER_1_RELATED_IDENTIFIER_1 = RelatedIdentifier.builder() + .id(RELATED_IDENTIFIER_2_ID) + .iid(RELATED_IDENTIFIER_2_IDENTIFIER_ID) + .type(RELATED_IDENTIFIER_2_TYPE) + .relation(RELATED_IDENTIFIER_2_RELATION_TYPE) + .value(RELATED_IDENTIFIER_2_VALUE) + .build(); + + public final static RelatedIdentifierCreateDto IDENTIFIER_1_RELATED_IDENTIFIER_2_CREATE_DTO = RelatedIdentifierCreateDto.builder() + .value(RELATED_IDENTIFIER_2_VALUE) + .type(RELATED_IDENTIFIER_2_TYPE_DTO) + .relation(RELATED_IDENTIFIER_2_RELATION) + .build(); + + public final static IdentifierCreateDto IDENTIFIER_2_DTO_REQUEST = IdentifierCreateDto.builder() + .qid(IDENTIFIER_2_QUERY_ID) + .cid(IDENTIFIER_2_CONTAINER_ID) + .dbid(IDENTIFIER_2_DATABASE_ID) + .description(IDENTIFIER_2_DESCRIPTION) + .title(IDENTIFIER_2_TITLE) + .relatedIdentifiers(List.of(IDENTIFIER_1_RELATED_IDENTIFIER_2_CREATE_DTO)) + .publicationDay(IDENTIFIER_2_PUBLICATION_DAY) + .publicationMonth(IDENTIFIER_2_PUBLICATION_MONTH) + .publicationYear(IDENTIFIER_2_PUBLICATION_YEAR) + .creators(List.of(CREATOR_1_CREATE_DTO, CREATOR_2_CREATE_DTO)) + .publisher(IDENTIFIER_2_PUBLISHER) + .type(IDENTIFIER_2_TYPE_DTO) + .build(); + + public final static Long IDENTIFIER_3_ID = 3L; + public final static Long IDENTIFIER_3_QUERY_ID = QUERY_3_ID; + public final static Long IDENTIFIER_3_CONTAINER_ID = CONTAINER_3_ID; + public final static Long IDENTIFIER_3_DATABASE_ID = DATABASE_3_ID; + public final static String IDENTIFIER_3_DESCRIPTION = "Selecting all from the weather Norwegian table"; + public final static String IDENTIFIER_3_TITLE = "Norwegian weather data"; + public final static String IDENTIFIER_3_DOI = null; + public final static VisibilityType IDENTIFIER_3_VISIBILITY = VisibilityType.EVERYONE; + public final static VisibilityTypeDto IDENTIFIER_3_VISIBILITY_DTO = VisibilityTypeDto.EVERYONE; + public final static Instant IDENTIFIER_3_CREATED = Instant.ofEpochSecond(1641588352); + public final static Instant IDENTIFIER_3_MODIFIED = Instant.ofEpochSecond(1541588352); + public final static Instant IDENTIFIER_3_EXECUTION = Instant.ofEpochSecond(1541588352); + public final static Integer IDENTIFIER_3_PUBLICATION_DAY = 14; + public final static Integer IDENTIFIER_3_PUBLICATION_MONTH = 7; + public final static Integer IDENTIFIER_3_PUBLICATION_YEAR = 2022; + public final static String IDENTIFIER_3_QUERY_HASH = QUERY_3_QUERY_HASH; + public final static String IDENTIFIER_3_RESULT_HASH = QUERY_3_RESULT_HASH; + public final static String IDENTIFIER_3_QUERY = QUERY_3_STATEMENT; + public final static String IDENTIFIER_3_NORMALIZED = QUERY_3_STATEMENT; + public final static Long IDENTIFIER_3_RESULT_NUMBER = QUERY_3_RESULT_NUMBER; + public final static String IDENTIFIER_3_PUBLISHER = "Norwegian Government"; + public final static IdentifierType IDENTIFIER_3_TYPE = IdentifierType.SUBSET; + public final static IdentifierTypeDto IDENTIFIER_3_TYPE_DTO = IdentifierTypeDto.SUBSET; + + public final static Creator IDENTIFIER_3_CREATOR_1 = Creator.builder() + .id(CREATOR_1_ID) + .pid(IDENTIFIER_3_ID) + .firstname(CREATOR_1_FIRSTNAME) + .lastname(CREATOR_1_LASTNAME) + .orcid(CREATOR_1_ORCID) + .affiliation(CREATOR_1_AFFIL) + .build(); + + public final static CreatorDto IDENTIFIER_3_CREATOR_1_DTO = CreatorDto.builder() + .id(CREATOR_1_ID) + .firstname(CREATOR_1_FIRSTNAME) + .lastname(CREATOR_1_LASTNAME) + .orcid(CREATOR_1_ORCID) + .affiliation(CREATOR_1_AFFIL) + .build(); + + public final static Creator IDENTIFIER_3_CREATOR_2 = Creator.builder() + .id(CREATOR_2_ID) + .pid(IDENTIFIER_3_ID) + .firstname(CREATOR_2_FIRSTNAME) + .lastname(CREATOR_2_LASTNAME) + .orcid(CREATOR_2_ORCID) + .affiliation(CREATOR_2_AFFIL) + .build(); + + public final static CreatorDto IDENTIFIER_3_CREATOR_2_DTO = CreatorDto.builder() + .id(CREATOR_2_ID) + .firstname(CREATOR_2_FIRSTNAME) + .lastname(CREATOR_2_LASTNAME) + .orcid(CREATOR_2_ORCID) + .affiliation(CREATOR_2_AFFIL) + .build(); + + public final static Creator IDENTIFIER_3_CREATOR_3 = Creator.builder() + .id(CREATOR_3_ID) + .pid(IDENTIFIER_3_ID) + .firstname(CREATOR_3_FIRSTNAME) + .lastname(CREATOR_3_LASTNAME) + .orcid(CREATOR_3_ORCID) + .affiliation(CREATOR_3_AFFIL) + .build(); + + public final static CreatorDto IDENTIFIER_3_CREATOR_3_DTO = CreatorDto.builder() + .id(CREATOR_3_ID) + .firstname(CREATOR_3_FIRSTNAME) + .lastname(CREATOR_3_LASTNAME) + .orcid(CREATOR_3_ORCID) + .affiliation(CREATOR_3_AFFIL) + .build(); + + public final static Identifier IDENTIFIER_3 = Identifier.builder() + .id(IDENTIFIER_3_ID) + .containerId(IDENTIFIER_3_CONTAINER_ID) + .databaseId(IDENTIFIER_3_DATABASE_ID) + .queryId(IDENTIFIER_3_QUERY_ID) + .description(IDENTIFIER_3_DESCRIPTION) + .title(IDENTIFIER_3_TITLE) + .doi(IDENTIFIER_3_DOI) + .visibility(IDENTIFIER_3_VISIBILITY) + .created(IDENTIFIER_3_CREATED) + .lastModified(IDENTIFIER_3_MODIFIED) + .execution(IDENTIFIER_3_EXECUTION) + .publicationDay(IDENTIFIER_3_PUBLICATION_DAY) + .publicationMonth(IDENTIFIER_3_PUBLICATION_MONTH) + .publicationYear(IDENTIFIER_3_PUBLICATION_YEAR) + .queryHash(IDENTIFIER_3_QUERY_HASH) + .resultHash(IDENTIFIER_3_RESULT_HASH) + .query(IDENTIFIER_3_QUERY) + .queryNormalized(IDENTIFIER_3_NORMALIZED) + .resultNumber(IDENTIFIER_3_RESULT_NUMBER) + .publisher(IDENTIFIER_3_PUBLISHER) + .type(IDENTIFIER_3_TYPE) + .creator(USER_3) + .creators(List.of(IDENTIFIER_3_CREATOR_1, IDENTIFIER_3_CREATOR_2, IDENTIFIER_3_CREATOR_3)) + .build(); + + public final static IdentifierDto IDENTIFIER_3_DTO = IdentifierDto.builder() + .id(IDENTIFIER_3_ID) + .containerId(IDENTIFIER_3_CONTAINER_ID) + .databaseId(IDENTIFIER_3_DATABASE_ID) + .queryId(IDENTIFIER_3_QUERY_ID) + .description(IDENTIFIER_3_DESCRIPTION) + .title(IDENTIFIER_3_TITLE) + .doi(IDENTIFIER_3_DOI) + .visibility(IDENTIFIER_3_VISIBILITY_DTO) + .created(IDENTIFIER_3_CREATED) + .lastModified(IDENTIFIER_3_MODIFIED) + .execution(IDENTIFIER_3_EXECUTION) + .publicationDay(IDENTIFIER_3_PUBLICATION_DAY) + .publicationMonth(IDENTIFIER_3_PUBLICATION_MONTH) + .publicationYear(IDENTIFIER_3_PUBLICATION_YEAR) + .queryHash(IDENTIFIER_3_QUERY_HASH) + .resultHash(IDENTIFIER_3_RESULT_HASH) + .query(IDENTIFIER_3_QUERY) + .queryNormalized(IDENTIFIER_3_NORMALIZED) + .resultNumber(IDENTIFIER_3_RESULT_NUMBER) + .publisher(IDENTIFIER_3_PUBLISHER) + .type(IDENTIFIER_3_TYPE_DTO) + .creator(USER_3_DTO) + .creators(List.of(IDENTIFIER_3_CREATOR_1_DTO, IDENTIFIER_3_CREATOR_2_DTO, IDENTIFIER_3_CREATOR_3_DTO)) + .build(); + + public final static IdentifierCreateDto IDENTIFIER_3_DTO_REQUEST = IdentifierCreateDto.builder() + .cid(IDENTIFIER_3_CONTAINER_ID) + .dbid(IDENTIFIER_3_DATABASE_ID) + .description(IDENTIFIER_3_DESCRIPTION) + .title(IDENTIFIER_3_TITLE) + .relatedIdentifiers(List.of()) + .publicationMonth(IDENTIFIER_3_PUBLICATION_MONTH) + .publicationYear(IDENTIFIER_3_PUBLICATION_YEAR) + .creators(List.of(CREATOR_1_CREATE_DTO)) + .publisher(IDENTIFIER_3_PUBLISHER) + .type(IDENTIFIER_3_TYPE_DTO) + .build(); + + public final static IdentifierCreateDto IDENTIFIER_3_DTO_TRUSTED_REQUEST = IdentifierCreateDto.builder() + .cid(IDENTIFIER_3_CONTAINER_ID) + .dbid(IDENTIFIER_3_DATABASE_ID) + .description(IDENTIFIER_3_DESCRIPTION) + .title(IDENTIFIER_3_TITLE) + .relatedIdentifiers(List.of()) + .publicationMonth(IDENTIFIER_3_PUBLICATION_MONTH) + .publicationYear(IDENTIFIER_3_PUBLICATION_YEAR) + .creators(List.of(CREATOR_1_CREATE_DTO)) + .publisher(IDENTIFIER_3_PUBLISHER) + .type(IDENTIFIER_3_TYPE_DTO) + .build(); + + public final static IdentifierCreateDto IDENTIFIER_3_DTO_SELF_REQUEST = IdentifierCreateDto.builder() + .cid(IDENTIFIER_3_CONTAINER_ID) + .dbid(IDENTIFIER_3_DATABASE_ID) + .description(IDENTIFIER_3_DESCRIPTION) + .title(IDENTIFIER_3_TITLE) + .relatedIdentifiers(List.of()) + .publicationMonth(IDENTIFIER_3_PUBLICATION_MONTH) + .publicationYear(IDENTIFIER_3_PUBLICATION_YEAR) + .creators(List.of(CREATOR_1_CREATE_DTO)) + .publisher(IDENTIFIER_3_PUBLISHER) + .type(IDENTIFIER_3_TYPE_DTO) + .build(); + + public final static Long IDENTIFIER_4_ID = 4L; + public final static Long IDENTIFIER_4_CONTAINER_ID = CONTAINER_4_ID; + public final static Long IDENTIFIER_4_DATABASE_ID = DATABASE_4_ID; + public final static String IDENTIFIER_4_DESCRIPTION = "Selecting all from the weather Sweden table"; + public final static String IDENTIFIER_4_TITLE = "Sweden weather data"; + public final static String IDENTIFIER_4_DOI = null; + public final static VisibilityType IDENTIFIER_4_VISIBILITY = VisibilityType.EVERYONE; + public final static Instant IDENTIFIER_4_CREATED = Instant.ofEpochSecond(1641588352); + public final static Instant IDENTIFIER_4_MODIFIED = Instant.ofEpochSecond(1541588352); + public final static Instant IDENTIFIER_4_EXECUTION = Instant.ofEpochSecond(1541588352); + public final static Integer IDENTIFIER_4_PUBLICATION_DAY = 14; + public final static Integer IDENTIFIER_4_PUBLICATION_MONTH = 7; + public final static Integer IDENTIFIER_4_PUBLICATION_YEAR = 2022; + public final static String IDENTIFIER_4_QUERY_HASH = "abc"; + public final static String IDENTIFIER_4_RESULT_HASH = "def"; + public final static String IDENTIFIER_4_QUERY = "SELECT `id` FROM `foobar`"; + public final static String IDENTIFIER_4_NORMALIZED = "SELECT `id` FROM `foobar`"; + public final static Long IDENTIFIER_4_RESULT_NUMBER = 2L; + public final static String IDENTIFIER_4_PUBLISHER = "Swedish Government"; + public final static IdentifierType IDENTIFIER_4_TYPE = IdentifierType.DATABASE; + + public final static Identifier IDENTIFIER_4 = Identifier.builder() + .id(IDENTIFIER_4_ID) + .containerId(IDENTIFIER_4_CONTAINER_ID) + .databaseId(IDENTIFIER_4_DATABASE_ID) + .description(IDENTIFIER_4_DESCRIPTION) + .title(IDENTIFIER_4_TITLE) + .doi(IDENTIFIER_4_DOI) + .visibility(IDENTIFIER_4_VISIBILITY) + .created(IDENTIFIER_4_CREATED) + .lastModified(IDENTIFIER_4_MODIFIED) + .execution(IDENTIFIER_4_EXECUTION) + .publicationDay(IDENTIFIER_4_PUBLICATION_DAY) + .publicationMonth(IDENTIFIER_4_PUBLICATION_MONTH) + .publicationYear(IDENTIFIER_4_PUBLICATION_YEAR) + .queryHash(IDENTIFIER_4_QUERY_HASH) + .resultHash(IDENTIFIER_4_RESULT_HASH) + .query(IDENTIFIER_4_QUERY) + .queryNormalized(IDENTIFIER_4_NORMALIZED) + .resultNumber(IDENTIFIER_4_RESULT_NUMBER) + .publisher(IDENTIFIER_4_PUBLISHER) + .type(IDENTIFIER_4_TYPE) + .creator(USER_3) + .creators(List.of()) + .build(); + + public final static String VIRTUAL_HOST_NAME = "fda"; + public final static String VIRTUAL_HOST_DESCRIPTION = "FAIR Data Austria"; + public final static String VIRTUAL_HOST_TAGS = ""; + + public final static CreateVirtualHostDto VIRTUAL_HOST_CREATE_DTO = CreateVirtualHostDto.builder() + .name(VIRTUAL_HOST_NAME) + .description(VIRTUAL_HOST_DESCRIPTION) + .tags(VIRTUAL_HOST_TAGS) + .build(); + + public final static ExchangeUpdatePermissionsDto VIRTUAL_HOST_EXCHANGE_UPDATE_DTO = ExchangeUpdatePermissionsDto.builder() + .exchange(DATABASE_1_EXCHANGE) + .read(".*") + .write(".*") + .build(); + + public final static GrantVirtualHostPermissionsDto VIRTUAL_HOST_GRANT_DTO = GrantVirtualHostPermissionsDto.builder() + .read(".*") + .write(".*") + .configure(".*") + .build(); + +} diff --git a/dbrepo-metadata-db/test/src/main/java/at/tuwien/utils/AmqpUtils.java b/dbrepo-metadata-db/test/src/main/java/at/tuwien/utils/AmqpUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..9c5fe67cb2c1429f7e55f2c024fbc72bf7d851aa --- /dev/null +++ b/dbrepo-metadata-db/test/src/main/java/at/tuwien/utils/AmqpUtils.java @@ -0,0 +1,46 @@ +package at.tuwien.utils; + +import at.tuwien.api.amqp.ExchangeDto; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +@Log4j2 +@Service +public class AmqpUtils { + + private final RestTemplate restTemplate; + + @Autowired + public AmqpUtils(@Qualifier("brokerRestTemplate") RestTemplate restTemplate) { + this.restTemplate = restTemplate; + } + + public boolean exchangeExists(String exchange) { + final ResponseEntity<ExchangeDto[]> response = restTemplate.exchange("/api/exchanges", HttpMethod.GET, null, ExchangeDto[].class); + if (!response.getStatusCode().equals(HttpStatus.OK)) { + log.error("Failed to retrieve exchanges, code is {}", response.getStatusCode()); + throw new RuntimeException("Failed to retrieve exchanges"); + } + assert response.getBody() != null; + final List<String> names = Arrays.stream(response.getBody()) + .map(ExchangeDto::getName) + .collect(Collectors.toList()); + if (names.stream().filter(n -> n.equals(exchange)).count() != 1) { + log.error("Failed to find exchange {} in exchanges {}", exchange, names); + return false; + } + log.info("Found exchange {} in exchanges {}", exchange, names); + return true; + } + +} diff --git a/dbrepo-metadata-db/test/src/test/resources/musicology/1_querystore.sql b/dbrepo-metadata-db/test/src/test/resources/musicology/1_querystore.sql new file mode 100644 index 0000000000000000000000000000000000000000..2762d130a0044c439b41c0215b0d87924bc8f072 --- /dev/null +++ b/dbrepo-metadata-db/test/src/test/resources/musicology/1_querystore.sql @@ -0,0 +1,75 @@ +CREATE SEQUENCE `qs_queries_seq`; +CREATE TABLE `qs_queries` +( + `id` bigint not null primary key default nextval(`qs_queries_seq`), + `created` datetime not null default now(), + `executed` datetime not null default now(), + `created_by` varchar(255) not null, + `query` text not null, + `query_normalized` text not null, + `is_persisted` boolean not null, + `query_hash` varchar(255) not null, + `result_hash` varchar(255), + `result_number` bigint +); +DELIMITER $$ +CREATE PROCEDURE hash_table(IN name VARCHAR(255), OUT hash VARCHAR(255)) +BEGIN + DECLARE _sql TEXT; + SELECT CONCAT('SELECT SHA2(GROUP_CONCAT(CONCAT_WS(\'\',', + GROUP_CONCAT(CONCAT('`', column_name, '`') ORDER BY column_name), + ') SEPARATOR \',\'), 256) AS hash FROM `', name, '` INTO @hash;') + FROM `information_schema`.`columns` + WHERE `table_schema` = DATABASE() + AND `table_name` = name + INTO _sql; + PREPARE stmt FROM _sql; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; + SET hash = @hash; +END $$ +DELIMITER $$ +CREATE PROCEDURE store_query(IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) +BEGIN + DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); + DECLARE _username varchar(255) DEFAULT REGEXP_REPLACE(current_user(), '@.*', ''); + DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); + PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); + SELECT COUNT(*) FROM _tmp INTO @count; + IF @hash IS NULL THEN + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + ELSE + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + END IF; +END $$ +DELIMITER $$ +CREATE + DEFINER = 'root' PROCEDURE _store_query(IN _username VARCHAR(255), IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) +BEGIN + DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); + DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); + PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); + SELECT COUNT(*) FROM _tmp INTO @count; + IF @hash IS NULL THEN + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + ELSE + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + END IF; +END $$ +DELIMITER ; \ No newline at end of file diff --git a/dbrepo-metadata-db/test/src/test/resources/musicology/2_schema_data.sql b/dbrepo-metadata-db/test/src/test/resources/musicology/2_schema_data.sql new file mode 100644 index 0000000000000000000000000000000000000000..91324167ad169987c0beda255612b1a620fcb93e --- /dev/null +++ b/dbrepo-metadata-db/test/src/test/resources/musicology/2_schema_data.sql @@ -0,0 +1,15 @@ +CREATE SEQUENCE seq_mfcc; + +CREATE TABLE mfcc +( + id BIGINT PRIMARY KEY NOT NULL DEFAULT nextval(`seq_mfcc`), + value DECIMAL NOT NULL +) WITH SYSTEM VERSIONING; + +INSERT INTO `mfcc` (`value`) +VALUES (11.2), + (11.3), + (11.4), + (11.9), + (12.3), + (23.1); \ No newline at end of file diff --git a/dbrepo-metadata-db/test/src/test/resources/musicology/3_users.sql b/dbrepo-metadata-db/test/src/test/resources/musicology/3_users.sql new file mode 100644 index 0000000000000000000000000000000000000000..6a4244967779a981e2d23241d147bced80ba8b69 --- /dev/null +++ b/dbrepo-metadata-db/test/src/test/resources/musicology/3_users.sql @@ -0,0 +1,4 @@ +CREATE USER junit1 IDENTIFIED BY PASSWORD '*440BA4FD1A87A0999647DB67C0EE258198B247BA'; +CREATE USER junit2 IDENTIFIED BY PASSWORD '*9AA70A8B0EEFAFCB5BED5BDEF6EE264D5DA915AE'; +CREATE USER junit3 IDENTIFIED BY PASSWORD '*D65FCA043964B63E849DD6334699ECB065905DA4'; +CREATE USER junit4 IDENTIFIED BY PASSWORD '*C20EF5C6875857DEFA9BE6E9B62DD76AAAE51882'; \ No newline at end of file diff --git a/dbrepo-metadata-db/test/src/test/resources/schema.sql b/dbrepo-metadata-db/test/src/test/resources/schema.sql new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/dbrepo-metadata-db/test/src/test/resources/sensor/1_querystore.sql b/dbrepo-metadata-db/test/src/test/resources/sensor/1_querystore.sql new file mode 100644 index 0000000000000000000000000000000000000000..2762d130a0044c439b41c0215b0d87924bc8f072 --- /dev/null +++ b/dbrepo-metadata-db/test/src/test/resources/sensor/1_querystore.sql @@ -0,0 +1,75 @@ +CREATE SEQUENCE `qs_queries_seq`; +CREATE TABLE `qs_queries` +( + `id` bigint not null primary key default nextval(`qs_queries_seq`), + `created` datetime not null default now(), + `executed` datetime not null default now(), + `created_by` varchar(255) not null, + `query` text not null, + `query_normalized` text not null, + `is_persisted` boolean not null, + `query_hash` varchar(255) not null, + `result_hash` varchar(255), + `result_number` bigint +); +DELIMITER $$ +CREATE PROCEDURE hash_table(IN name VARCHAR(255), OUT hash VARCHAR(255)) +BEGIN + DECLARE _sql TEXT; + SELECT CONCAT('SELECT SHA2(GROUP_CONCAT(CONCAT_WS(\'\',', + GROUP_CONCAT(CONCAT('`', column_name, '`') ORDER BY column_name), + ') SEPARATOR \',\'), 256) AS hash FROM `', name, '` INTO @hash;') + FROM `information_schema`.`columns` + WHERE `table_schema` = DATABASE() + AND `table_name` = name + INTO _sql; + PREPARE stmt FROM _sql; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; + SET hash = @hash; +END $$ +DELIMITER $$ +CREATE PROCEDURE store_query(IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) +BEGIN + DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); + DECLARE _username varchar(255) DEFAULT REGEXP_REPLACE(current_user(), '@.*', ''); + DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); + PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); + SELECT COUNT(*) FROM _tmp INTO @count; + IF @hash IS NULL THEN + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + ELSE + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + END IF; +END $$ +DELIMITER $$ +CREATE + DEFINER = 'root' PROCEDURE _store_query(IN _username VARCHAR(255), IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) +BEGIN + DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); + DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); + PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); + SELECT COUNT(*) FROM _tmp INTO @count; + IF @hash IS NULL THEN + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + ELSE + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + END IF; +END $$ +DELIMITER ; \ No newline at end of file diff --git a/dbrepo-metadata-db/test/src/test/resources/sensor/2_traffic.sql b/dbrepo-metadata-db/test/src/test/resources/sensor/2_traffic.sql new file mode 100644 index 0000000000000000000000000000000000000000..93d293a6fe9ee11cbd662208a85089ac3f9fab99 --- /dev/null +++ b/dbrepo-metadata-db/test/src/test/resources/sensor/2_traffic.sql @@ -0,0 +1,8 @@ +CREATE SEQUENCE seq_sensor + START 1; + +CREATE TABLE sensor +( + `timestamp` TIMESTAMP NULL, + primary key (`timestamp`) +) with system versioning; \ No newline at end of file diff --git a/dbrepo-metadata-db/test/src/test/resources/sensor/3_users.sql b/dbrepo-metadata-db/test/src/test/resources/sensor/3_users.sql new file mode 100644 index 0000000000000000000000000000000000000000..6a4244967779a981e2d23241d147bced80ba8b69 --- /dev/null +++ b/dbrepo-metadata-db/test/src/test/resources/sensor/3_users.sql @@ -0,0 +1,4 @@ +CREATE USER junit1 IDENTIFIED BY PASSWORD '*440BA4FD1A87A0999647DB67C0EE258198B247BA'; +CREATE USER junit2 IDENTIFIED BY PASSWORD '*9AA70A8B0EEFAFCB5BED5BDEF6EE264D5DA915AE'; +CREATE USER junit3 IDENTIFIED BY PASSWORD '*D65FCA043964B63E849DD6334699ECB065905DA4'; +CREATE USER junit4 IDENTIFIED BY PASSWORD '*C20EF5C6875857DEFA9BE6E9B62DD76AAAE51882'; \ No newline at end of file diff --git a/dbrepo-metadata-db/test/src/test/resources/species/1_querystore.sql b/dbrepo-metadata-db/test/src/test/resources/species/1_querystore.sql new file mode 100644 index 0000000000000000000000000000000000000000..2762d130a0044c439b41c0215b0d87924bc8f072 --- /dev/null +++ b/dbrepo-metadata-db/test/src/test/resources/species/1_querystore.sql @@ -0,0 +1,75 @@ +CREATE SEQUENCE `qs_queries_seq`; +CREATE TABLE `qs_queries` +( + `id` bigint not null primary key default nextval(`qs_queries_seq`), + `created` datetime not null default now(), + `executed` datetime not null default now(), + `created_by` varchar(255) not null, + `query` text not null, + `query_normalized` text not null, + `is_persisted` boolean not null, + `query_hash` varchar(255) not null, + `result_hash` varchar(255), + `result_number` bigint +); +DELIMITER $$ +CREATE PROCEDURE hash_table(IN name VARCHAR(255), OUT hash VARCHAR(255)) +BEGIN + DECLARE _sql TEXT; + SELECT CONCAT('SELECT SHA2(GROUP_CONCAT(CONCAT_WS(\'\',', + GROUP_CONCAT(CONCAT('`', column_name, '`') ORDER BY column_name), + ') SEPARATOR \',\'), 256) AS hash FROM `', name, '` INTO @hash;') + FROM `information_schema`.`columns` + WHERE `table_schema` = DATABASE() + AND `table_name` = name + INTO _sql; + PREPARE stmt FROM _sql; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; + SET hash = @hash; +END $$ +DELIMITER $$ +CREATE PROCEDURE store_query(IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) +BEGIN + DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); + DECLARE _username varchar(255) DEFAULT REGEXP_REPLACE(current_user(), '@.*', ''); + DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); + PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); + SELECT COUNT(*) FROM _tmp INTO @count; + IF @hash IS NULL THEN + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + ELSE + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + END IF; +END $$ +DELIMITER $$ +CREATE + DEFINER = 'root' PROCEDURE _store_query(IN _username VARCHAR(255), IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) +BEGIN + DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); + DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); + PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); + SELECT COUNT(*) FROM _tmp INTO @count; + IF @hash IS NULL THEN + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + ELSE + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + END IF; +END $$ +DELIMITER ; \ No newline at end of file diff --git a/dbrepo-metadata-db/test/src/test/resources/species/2_schema_data.sql b/dbrepo-metadata-db/test/src/test/resources/species/2_schema_data.sql new file mode 100644 index 0000000000000000000000000000000000000000..957368fcc773ecf22f419585b50206ad56359bc9 --- /dev/null +++ b/dbrepo-metadata-db/test/src/test/resources/species/2_schema_data.sql @@ -0,0 +1,7 @@ +/* https://sandbox.zenodo.org/api/files/6aca3421-add3-489b-8c4a-35228fe5c683/species_id.csv */ +CREATE TABLE maldi_ms_data +( + qu VARCHAR(255) NOT NULL, + species VARCHAR(255) NOT NULL, + score VARCHAR(255) NOT NULL +) WITH SYSTEM VERSIONING; \ No newline at end of file diff --git a/dbrepo-metadata-db/test/src/test/resources/species/3_users.sql b/dbrepo-metadata-db/test/src/test/resources/species/3_users.sql new file mode 100644 index 0000000000000000000000000000000000000000..6a4244967779a981e2d23241d147bced80ba8b69 --- /dev/null +++ b/dbrepo-metadata-db/test/src/test/resources/species/3_users.sql @@ -0,0 +1,4 @@ +CREATE USER junit1 IDENTIFIED BY PASSWORD '*440BA4FD1A87A0999647DB67C0EE258198B247BA'; +CREATE USER junit2 IDENTIFIED BY PASSWORD '*9AA70A8B0EEFAFCB5BED5BDEF6EE264D5DA915AE'; +CREATE USER junit3 IDENTIFIED BY PASSWORD '*D65FCA043964B63E849DD6334699ECB065905DA4'; +CREATE USER junit4 IDENTIFIED BY PASSWORD '*C20EF5C6875857DEFA9BE6E9B62DD76AAAE51882'; \ No newline at end of file diff --git a/dbrepo-metadata-db/test/src/test/resources/weather/1_querystore.sql b/dbrepo-metadata-db/test/src/test/resources/weather/1_querystore.sql new file mode 100644 index 0000000000000000000000000000000000000000..2762d130a0044c439b41c0215b0d87924bc8f072 --- /dev/null +++ b/dbrepo-metadata-db/test/src/test/resources/weather/1_querystore.sql @@ -0,0 +1,75 @@ +CREATE SEQUENCE `qs_queries_seq`; +CREATE TABLE `qs_queries` +( + `id` bigint not null primary key default nextval(`qs_queries_seq`), + `created` datetime not null default now(), + `executed` datetime not null default now(), + `created_by` varchar(255) not null, + `query` text not null, + `query_normalized` text not null, + `is_persisted` boolean not null, + `query_hash` varchar(255) not null, + `result_hash` varchar(255), + `result_number` bigint +); +DELIMITER $$ +CREATE PROCEDURE hash_table(IN name VARCHAR(255), OUT hash VARCHAR(255)) +BEGIN + DECLARE _sql TEXT; + SELECT CONCAT('SELECT SHA2(GROUP_CONCAT(CONCAT_WS(\'\',', + GROUP_CONCAT(CONCAT('`', column_name, '`') ORDER BY column_name), + ') SEPARATOR \',\'), 256) AS hash FROM `', name, '` INTO @hash;') + FROM `information_schema`.`columns` + WHERE `table_schema` = DATABASE() + AND `table_name` = name + INTO _sql; + PREPARE stmt FROM _sql; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; + SET hash = @hash; +END $$ +DELIMITER $$ +CREATE PROCEDURE store_query(IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) +BEGIN + DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); + DECLARE _username varchar(255) DEFAULT REGEXP_REPLACE(current_user(), '@.*', ''); + DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); + PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); + SELECT COUNT(*) FROM _tmp INTO @count; + IF @hash IS NULL THEN + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + ELSE + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + END IF; +END $$ +DELIMITER $$ +CREATE + DEFINER = 'root' PROCEDURE _store_query(IN _username VARCHAR(255), IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) +BEGIN + DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); + DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); + PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); + SELECT COUNT(*) FROM _tmp INTO @count; + IF @hash IS NULL THEN + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + ELSE + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + END IF; +END $$ +DELIMITER ; \ No newline at end of file diff --git a/dbrepo-metadata-db/test/src/test/resources/weather/2_schema_data.sql b/dbrepo-metadata-db/test/src/test/resources/weather/2_schema_data.sql new file mode 100644 index 0000000000000000000000000000000000000000..c5d0a6a58c2169d09e92c0d5a7ebd701140672de --- /dev/null +++ b/dbrepo-metadata-db/test/src/test/resources/weather/2_schema_data.sql @@ -0,0 +1,62 @@ +/* https://www.kaggle.com/jsphyg/weather-dataset-rattle-package */ +CREATE TABLE weather_location +( + location VARCHAR(255) PRIMARY KEY, + lat DOUBLE PRECISION NULL, + lng DOUBLE PRECISION NULL +) WITH SYSTEM VERSIONING; + +CREATE TABLE weather_aus +( + id BIGINT NOT NULL PRIMARY KEY, + `date` DATE NOT NULL, + location VARCHAR(255) NULL, + mintemp DOUBLE PRECISION NULL, + rainfall DOUBLE PRECISION NULL, + FOREIGN KEY (location) REFERENCES weather_location (location), + UNIQUE (`date`), + CHECK (`mintemp` > 0) +) WITH SYSTEM VERSIONING; + +CREATE TABLE sensor +( + `timestamp` TIMESTAMP NOT NULL PRIMARY KEY, + `value` DECIMAL +) WITH SYSTEM VERSIONING; + +INSERT INTO weather_location (location, lat, lng) +VALUES ('Albury', -36.0653583, 146.9112214), + ('Sydney', -33.847927, 150.6517942), + ('Vienna', null, null); + +INSERT INTO weather_aus (id, `date`, location, mintemp, rainfall) +VALUES (1, '2008-12-01', 'Albury', 13.4, 0.6), + (2, '2008-12-02', 'Albury', 7.4, 0), + (3, '2008-12-03', 'Albury', 12.9, 0); + +INSERT INTO sensor (`timestamp`, value) +VALUES ('2022-12-24 17:00:00', 10.0), + ('2022-12-24 18:00:00', 10.2), + ('2022-12-24 19:00:00', null), + ('2022-12-24 20:00:00', 10.3), + ('2022-12-24 21:00:00', 10.0), + ('2022-12-24 22:00:00', null); + +######################################################################################################################## +## TEST CASE PRE-REQUISITE ## +######################################################################################################################## + +CREATE VIEW junit2 AS +( +SELECT `location`, `lat`, `lng` +FROM `weather_location` +WHERE `location` = 'Albury'); + +CREATE VIEW `hs_weather_aus` AS +SELECT * +FROM (SELECT `id`, ROW_START AS inserted_at, IF(ROW_END > NOW(), NULL, ROW_END) AS deleted_at, COUNT(*) as total + FROM `weather_aus` FOR SYSTEM_TIME ALL + GROUP BY inserted_at, deleted_at + ORDER BY deleted_at DESC + LIMIT 50) AS v +ORDER BY v.inserted_at, v.deleted_at ASC; diff --git a/dbrepo-metadata-db/test/src/test/resources/weather/3_users.sql b/dbrepo-metadata-db/test/src/test/resources/weather/3_users.sql new file mode 100644 index 0000000000000000000000000000000000000000..6a4244967779a981e2d23241d147bced80ba8b69 --- /dev/null +++ b/dbrepo-metadata-db/test/src/test/resources/weather/3_users.sql @@ -0,0 +1,4 @@ +CREATE USER junit1 IDENTIFIED BY PASSWORD '*440BA4FD1A87A0999647DB67C0EE258198B247BA'; +CREATE USER junit2 IDENTIFIED BY PASSWORD '*9AA70A8B0EEFAFCB5BED5BDEF6EE264D5DA915AE'; +CREATE USER junit3 IDENTIFIED BY PASSWORD '*D65FCA043964B63E849DD6334699ECB065905DA4'; +CREATE USER junit4 IDENTIFIED BY PASSWORD '*C20EF5C6875857DEFA9BE6E9B62DD76AAAE51882'; \ No newline at end of file diff --git a/dbrepo-metadata-db/test/src/test/resources/weather/location.csv b/dbrepo-metadata-db/test/src/test/resources/weather/location.csv new file mode 100644 index 0000000000000000000000000000000000000000..b9410c65c9b4169eb1a231dbe5ca04ff20c116cf --- /dev/null +++ b/dbrepo-metadata-db/test/src/test/resources/weather/location.csv @@ -0,0 +1,2 @@ +Albury,-36.0653583,146.9112214 +Sydney,-33.847927,150.6517942 \ No newline at end of file diff --git a/dbrepo-metadata-db/test/src/test/resources/zoo/1_querystore.sql b/dbrepo-metadata-db/test/src/test/resources/zoo/1_querystore.sql new file mode 100644 index 0000000000000000000000000000000000000000..2762d130a0044c439b41c0215b0d87924bc8f072 --- /dev/null +++ b/dbrepo-metadata-db/test/src/test/resources/zoo/1_querystore.sql @@ -0,0 +1,75 @@ +CREATE SEQUENCE `qs_queries_seq`; +CREATE TABLE `qs_queries` +( + `id` bigint not null primary key default nextval(`qs_queries_seq`), + `created` datetime not null default now(), + `executed` datetime not null default now(), + `created_by` varchar(255) not null, + `query` text not null, + `query_normalized` text not null, + `is_persisted` boolean not null, + `query_hash` varchar(255) not null, + `result_hash` varchar(255), + `result_number` bigint +); +DELIMITER $$ +CREATE PROCEDURE hash_table(IN name VARCHAR(255), OUT hash VARCHAR(255)) +BEGIN + DECLARE _sql TEXT; + SELECT CONCAT('SELECT SHA2(GROUP_CONCAT(CONCAT_WS(\'\',', + GROUP_CONCAT(CONCAT('`', column_name, '`') ORDER BY column_name), + ') SEPARATOR \',\'), 256) AS hash FROM `', name, '` INTO @hash;') + FROM `information_schema`.`columns` + WHERE `table_schema` = DATABASE() + AND `table_name` = name + INTO _sql; + PREPARE stmt FROM _sql; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; + SET hash = @hash; +END $$ +DELIMITER $$ +CREATE PROCEDURE store_query(IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) +BEGIN + DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); + DECLARE _username varchar(255) DEFAULT REGEXP_REPLACE(current_user(), '@.*', ''); + DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); + PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); + SELECT COUNT(*) FROM _tmp INTO @count; + IF @hash IS NULL THEN + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + ELSE + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + END IF; +END $$ +DELIMITER $$ +CREATE + DEFINER = 'root' PROCEDURE _store_query(IN _username VARCHAR(255), IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) +BEGIN + DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); + DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); + PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); + SELECT COUNT(*) FROM _tmp INTO @count; + IF @hash IS NULL THEN + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); + ELSE + INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, + `result_number`, `executed`) + SELECT _username, query, query, false, _queryhash, @hash, @count, executed + WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); + END IF; +END $$ +DELIMITER ; \ No newline at end of file diff --git a/dbrepo-metadata-db/test/src/test/resources/zoo/2_schema_data.sql b/dbrepo-metadata-db/test/src/test/resources/zoo/2_schema_data.sql new file mode 100644 index 0000000000000000000000000000000000000000..50f02ee2c53f5afc8a472b1c418225434b45d98e --- /dev/null +++ b/dbrepo-metadata-db/test/src/test/resources/zoo/2_schema_data.sql @@ -0,0 +1,191 @@ +create sequence seq_zoo_id; +create sequence seq_names_id; +create table zoo +( + id bigint not null default nextval(`seq_zoo_id`), + animal_name varchar(255) null, + hair tinyint(1) null, + feathers tinyint(1) null, + eggs tinyint(1) null, + milk tinyint(1) null, + airborne tinyint(1) null, + aquatic tinyint(1) null, + predator tinyint(1) null, + toothed tinyint(1) null, + backbone tinyint(1) null, + breathes tinyint(1) null, + venomous tinyint(1) null, + fins tinyint(1) null, + legs bigint null, + tail tinyint(1) null, + domestic tinyint(1) null, + catsize tinyint(1) null, + class_type bigint null, + primary key (id) +) with system versioning; + +create table names +( + id bigint not null default nextval(`seq_names_id`), + firstname varchar(255), + lastname varchar(255), + primary key (id), + unique key (firstname, lastname) +) with system versioning; + +create table likes +( + name_id bigint not null, + zoo_id bigint not null, + primary key (name_id, zoo_id), + foreign key (name_id) references names (id), + foreign key (zoo_id) references zoo (id) +) with system versioning; + +INSERT INTO zoo (id, animal_name, hair, feathers, eggs, milk, airborne, aquatic, predator, toothed, backbone, breathes, + venomous, fins, legs, tail, domestic, catsize, class_type) +VALUES (1, 'aardvark', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 0, 0, 1, 1), + (2, 'antelope', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (3, 'bass', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4), + (4, 'bear', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 0, 0, 1, 1), + (5, 'boar', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (6, 'buffalo', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (7, 'calf', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 1, 1, 1), + (8, 'carp', 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 4), + (9, 'catfish', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4), + (10, 'cavy', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 0, 1, 0, 1), + (11, 'cheetah', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (12, 'chicken', 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 2, 1, 1, 0, 2), + (13, 'chub', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4), + (14, 'clam', 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7), + (15, 'crab', 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 4, 0, 0, 0, 7), + (16, 'crayfish', 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 6, 0, 0, 0, 7), + (17, 'crow', 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), + (18, 'deer', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (19, 'dogfish', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 4), + (20, 'dolphin', 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1), + (21, 'dove', 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 2, 1, 1, 0, 2), + (22, 'duck', 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), + (23, 'elephant', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (24, 'flamingo', 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 2, 1, 0, 1, 2), + (25, 'flea', 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 6, 0, 0, 0, 6), + (26, 'frog', 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 4, 0, 0, 0, 5), + (27, 'frog', 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 4, 0, 0, 0, 5), + (28, 'fruitbat', 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 2, 1, 0, 0, 1), + (29, 'giraffe', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (30, 'girl', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 2, 0, 1, 1, 1), + (31, 'gnat', 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 6, 0, 0, 0, 6), + (32, 'goat', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 1, 1, 1), + (33, 'gorilla', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 2, 0, 0, 1, 1), + (34, 'gull', 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), + (35, 'haddock', 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4), + (36, 'hamster', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 1, 0, 1), + (37, 'hare', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 0, 1), + (38, 'hawk', 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), + (39, 'herring', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4), + (40, 'honeybee', 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 6, 0, 1, 0, 6), + (41, 'housefly', 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 6, 0, 0, 0, 6), + (42, 'kiwi', 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), + (43, 'ladybird', 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 6, 0, 0, 0, 6), + (44, 'lark', 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), + (45, 'leopard', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (46, 'lion', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (47, 'lobster', 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 6, 0, 0, 0, 7), + (48, 'lynx', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (49, 'mink', 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (50, 'mole', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 0, 1), + (51, 'mongoose', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (52, 'moth', 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 6, 0, 0, 0, 6), + (53, 'newt', 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 4, 1, 0, 0, 5), + (54, 'octopus', 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 8, 0, 0, 1, 7), + (55, 'opossum', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 0, 1), + (56, 'oryx', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (57, 'ostrich', 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 2, 1, 0, 1, 2), + (58, 'parakeet', 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 2, 1, 1, 0, 2), + (59, 'penguin', 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 2, 1, 0, 1, 2), + (60, 'pheasant', 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), + (61, 'pike', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 4), + (62, 'piranha', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4), + (63, 'pitviper', 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 3), + (64, 'platypus', 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (65, 'polecat', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (66, 'pony', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 1, 1, 1), + (67, 'porpoise', 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1), + (68, 'puma', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (69, 'pussycat', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 1, 1, 1), + (70, 'raccoon', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (71, 'reindeer', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 1, 1, 1), + (72, 'rhea', 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 2, 1, 0, 1, 2), + (73, 'scorpion', 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 8, 1, 0, 0, 7), + (74, 'seahorse', 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4), + (75, 'seal', 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1), + (76, 'sealion', 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 2, 1, 0, 1, 1), + (77, 'seasnake', 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 3), + (78, 'seawasp', 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 7), + (79, 'skimmer', 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), + (80, 'skua', 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), + (81, 'slowworm', 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 3), + (82, 'slug', 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 7), + (83, 'sole', 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4), + (84, 'sparrow', 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), + (85, 'squirrel', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 2, 1, 0, 0, 1), + (86, 'starfish', 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 5, 0, 0, 0, 7), + (87, 'stingray', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 4), + (88, 'swan', 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 2, 1, 0, 1, 2), + (89, 'termite', 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 6, 0, 0, 0, 6), + (90, 'toad', 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 4, 0, 0, 0, 5), + (91, 'tortoise', 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 4, 1, 0, 1, 3), + (92, 'tuatara', 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 0, 3), + (93, 'tuna', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 4), + (94, 'vampire', 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 2, 1, 0, 0, 1), + (95, 'vole', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 0, 1), + (96, 'vulture', 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 2, 1, 0, 1, 2), + (97, 'wallaby', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 2, 1, 0, 1, 1), + (98, 'wasp', 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 6, 0, 0, 0, 6), + (99, 'wolf', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), + (100, 'worm', 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 7), + (101, 'wren', 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2); + +INSERT INTO names (firstname, lastname) +VALUES ('Moritz', 'Staudinger'), + ('Martin', 'Weise'), + ('Eva', 'Gergely'), + ('Cornelia', 'Michlits'), + ('Kirill', 'Stytsenko'); + +INSERT INTO likes (name_id, zoo_id) +VALUES (1, 5), + (1, 10), + (2, 3), + (2, 80), + (3, 4), + (4, 4), + (5, 100); + +######################################################################################################################## +## TEST CASE PRE-REQUISITE ## +######################################################################################################################## + +CREATE VIEW mock_view AS +( +SELECT `id`, + `animal_name`, + `hair`, + `feathers`, + `eggs`, + `milk`, + `airborne`, + `aquatic`, + `predator`, + `toothed`, + `backbone`, + `breathes`, + `venomous`, + `fins`, + `legs`, + `tail`, + `domestic`, + `catsize`, + `class_type` +FROM `zoo` +WHERE `class_type` = 1); diff --git a/dbrepo-metadata-db/test/src/test/resources/zoo/3_users.sql b/dbrepo-metadata-db/test/src/test/resources/zoo/3_users.sql new file mode 100644 index 0000000000000000000000000000000000000000..6a4244967779a981e2d23241d147bced80ba8b69 --- /dev/null +++ b/dbrepo-metadata-db/test/src/test/resources/zoo/3_users.sql @@ -0,0 +1,4 @@ +CREATE USER junit1 IDENTIFIED BY PASSWORD '*440BA4FD1A87A0999647DB67C0EE258198B247BA'; +CREATE USER junit2 IDENTIFIED BY PASSWORD '*9AA70A8B0EEFAFCB5BED5BDEF6EE264D5DA915AE'; +CREATE USER junit3 IDENTIFIED BY PASSWORD '*D65FCA043964B63E849DD6334699ECB065905DA4'; +CREATE USER junit4 IDENTIFIED BY PASSWORD '*C20EF5C6875857DEFA9BE6E9B62DD76AAAE51882'; \ No newline at end of file diff --git a/dbrepo-metadata-service/Dockerfile b/dbrepo-metadata-service/Dockerfile index 2b3a895f37bec83d81dd65d0d59ce42fdc55bfa1..f9f4f11e7abbd933064311664f2eb51bfdbae121 100644 --- a/dbrepo-metadata-service/Dockerfile +++ b/dbrepo-metadata-service/Dockerfile @@ -1,5 +1,5 @@ ###### FIRST STAGE ###### -FROM fda-metadata-db:latest as dependency +FROM dbrepo-metadata-db:latest as dependency MAINTAINER Martin Weise <martin.weise@tuwien.ac.at> ###### SECOND STAGE ###### diff --git a/dbrepo-metadata-service/pom.xml b/dbrepo-metadata-service/pom.xml index 58f80ab82d4cab1173993f1c761f83b1b0a6da4c..ee05f0602cf9998b9ba21de61fc40d2485270b4c 100644 --- a/dbrepo-metadata-service/pom.xml +++ b/dbrepo-metadata-service/pom.xml @@ -9,10 +9,10 @@ </parent> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-service</artifactId> - <version>1.1.0-alpha</version> - <name>fda-metadata-service</name> - <description>Demo project for Spring Boot</description> + <artifactId>dbrepo-metadata-service</artifactId> + <version>1.2.0</version> + <name>dbrepo-metadata-service</name> + <description>Service that manages the metadata</description> <url>https://dbrepo-docs.ossdip.at</url> <developers> @@ -42,6 +42,7 @@ <swagger.version>2.1.7</swagger.version> <springfox.version>3.0.0</springfox.version> <jacoco.version>0.8.7</jacoco.version> + <javax-ws-rs.version>2.1.1</javax-ws-rs.version> <spring-saml.version>1.0.10.RELEASE</spring-saml.version> <javax-rs.version>2.1.1</javax-rs.version> <javax-mail.version>1.4.7</javax-mail.version> @@ -89,25 +90,25 @@ <!-- Entity and API --> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-oai</artifactId> + <artifactId>dbrepo-metadata-db-oai</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-api</artifactId> + <artifactId>dbrepo-metadata-db-api</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-entites</artifactId> + <artifactId>dbrepo-metadata-db-entites</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-querystore</artifactId> + <artifactId>dbrepo-metadata-db-querystore</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> @@ -132,7 +133,45 @@ <dependency> <groupId>javax.ws.rs</groupId> <artifactId>javax.ws.rs-api</artifactId> - <version>${javax-rs.version}</version> + <version>${javax-ws-rs.version}</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-vintage-engine</artifactId> + </exclusion> + <exclusion> + <groupId>org.junit.vintage</groupId> + <artifactId>junit-vintage-engine</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>${jacoco.version}</version> + </dependency> + <dependency> + <groupId>at.tuwien</groupId> + <artifactId>dbrepo-metadata-db-test</artifactId> + <version>${project.version}</version> </dependency> </dependencies> @@ -159,7 +198,7 @@ <exclude>at/tuwien/mapper/**/*</exclude> <exclude>at/tuwien/exception/**/*</exclude> <exclude>at/tuwien/config/**/*</exclude> - <exclude>**/FdaContainerManagingApplication.class</exclude> + <exclude>**/DbrepoContainerManagingApplication.class</exclude> </excludes> </configuration> <executions> @@ -187,9 +226,6 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> <version>3.0.0</version> -<!-- <configuration>--> -<!-- <outputDirectory>docs</outputDirectory>--> -<!-- </configuration>--> </plugin> <plugin> <groupId>com.soebes.maven.plugins</groupId> diff --git a/dbrepo-metadata-service/report/pom.xml b/dbrepo-metadata-service/report/pom.xml index dac891eff5148ef760448dc456aea672f5e110f4..a77c1599398e3795f4ecc0a0d3f554287767d010 100644 --- a/dbrepo-metadata-service/report/pom.xml +++ b/dbrepo-metadata-service/report/pom.xml @@ -4,13 +4,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> - <artifactId>fda-metadata-service</artifactId> + <artifactId>dbrepo-metadata-service</artifactId> <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </parent> <artifactId>report</artifactId> - <name>fda-metadata-service-report</name> + <name>dbrepo-metadata-service-report</name> <properties> <jacoco.version>0.8.7</jacoco.version> diff --git a/dbrepo-metadata-service/rest-service/pom.xml b/dbrepo-metadata-service/rest-service/pom.xml index e2c4a9c420b3f85908e640cc57c0a5b0fe41c30b..050c5ca7d7b172f8ae73b7d2968c6e896d8f7f49 100644 --- a/dbrepo-metadata-service/rest-service/pom.xml +++ b/dbrepo-metadata-service/rest-service/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> - <artifactId>fda-metadata-service</artifactId> + <artifactId>dbrepo-metadata-service</artifactId> <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </parent> <artifactId>rest-service</artifactId> - <version>1.1.0-alpha</version> - <name>fda-metadata-service-rest</name> + <version>1.2.0</version> + <name>dbrepo-metadata-service-rest</name> <dependencies> <dependency> diff --git a/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/IdentifierServiceApplication.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/DbrepoMetadataServiceApplication.java similarity index 87% rename from dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/IdentifierServiceApplication.java rename to dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/DbrepoMetadataServiceApplication.java index 65816e864b2ad6114dbc54cc4abf10d375504365..1b6c8a38f5dbc21dc2db7f1d3bff8aa439cd55ec 100644 --- a/dbrepo-identifier-service/rest-service/src/main/java/at/tuwien/IdentifierServiceApplication.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/DbrepoMetadataServiceApplication.java @@ -15,10 +15,10 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @EntityScan(basePackages = "at.tuwien.entities") @EnableElasticsearchRepositories(basePackages = {"at.tuwien.repository.elastic"}) @EnableJpaRepositories(basePackages = {"at.tuwien.repository.jpa"}) -public class IdentifierServiceApplication { +public class DbrepoMetadataServiceApplication { public static void main(String[] args) { - SpringApplication.run(IdentifierServiceApplication.class, args); + SpringApplication.run(DbrepoMetadataServiceApplication.class, args); } } diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java index e28dd181bca0235e14f03d0378e2338d0096bdd0..fc7efc6d7522bd21adbc1870b8106703694095b6 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java @@ -5,11 +5,14 @@ import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Contact; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.servers.Server; import org.springdoc.core.GroupedOpenApi; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import java.util.List; + @Configuration public class SwaggerConfig { @@ -30,8 +33,14 @@ public class SwaggerConfig { .name("Apache 2.0") .url("https://www.apache.org/licenses/LICENSE-2.0"))) .externalDocs(new ExternalDocumentation() - .description("Wiki Documentation") - .url("https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services/-/wikis")); + .description("Sourcecode Documentation") + .url("https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services")) + .servers(List.of(new Server() + .description("Generated server url") + .url("http://localhost:9099"), + new Server() + .description("Sandbox") + .url("https://dbrepo2.tuwien.ac.at"))); } @Bean diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/AbstractEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/AbstractEndpoint.java deleted file mode 100644 index 2a2780c59948d5289700de9a19369a9765c633f3..0000000000000000000000000000000000000000 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/AbstractEndpoint.java +++ /dev/null @@ -1,8 +0,0 @@ -package at.tuwien.endpoints; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public abstract class AbstractEndpoint { - -} diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/MetadataEndpoint.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/MetadataEndpoint.java index f4da3b51b3cf76acc3927f20cdc72bc58d10df8b..be5c02e7d1cb7a01290e2782e9e3e64fd491bd4c 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/MetadataEndpoint.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/endpoints/MetadataEndpoint.java @@ -4,11 +4,15 @@ import at.tuwien.OaiErrorType; import at.tuwien.OaiListIdentifiersParameters; import at.tuwien.OaiRecordParameters; import at.tuwien.exception.IdentifierNotFoundException; -import at.tuwien.service.IdentifierService; import at.tuwien.service.MetadataService; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import lombok.extern.log4j.Log4j2; import org.apache.commons.lang3.math.NumberUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -20,7 +24,7 @@ import org.springframework.web.bind.annotation.*; @CrossOrigin(origins = "*") @RestController @RequestMapping("/api/oai") -public class MetadataEndpoint extends AbstractEndpoint { +public class MetadataEndpoint { private final MetadataService metadataService; @@ -30,8 +34,19 @@ public class MetadataEndpoint extends AbstractEndpoint { } @GetMapping(produces = "text/xml;charset=UTF-8") + @Parameter(name = "verb", in = ParameterIn.QUERY, examples = { + @ExampleObject(value = "Identify"), + @ExampleObject(value = "ListIdentifiers"), + @ExampleObject(value = "GetRecord"), + @ExampleObject(value = "ListMetadataFormats"), + }) @Timed(value = "repository.identify", description = "Time needed to identify the repository") @Operation(summary = "Identify the repository") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "List containers", + content = {@Content(mediaType = "text/xml")}), + }) public ResponseEntity<?> identify() { log.debug("endpoint identify repository"); return identifyAlt(); @@ -40,7 +55,11 @@ public class MetadataEndpoint extends AbstractEndpoint { @GetMapping(params = "verb=Identify", produces = "text/xml;charset=UTF-8") @Timed(value = "repository.identify", description = "Time needed to identify the repository") @Operation(summary = "Identify the repository") - @Parameter(name = "verb", example = "Identify") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "List containers", + content = {@Content(mediaType = "text/xml")}), + }) public ResponseEntity<?> identifyAlt() { log.debug("endpoint identify repository, verb=Identify"); final String xml = metadataService.identify(); @@ -51,7 +70,6 @@ public class MetadataEndpoint extends AbstractEndpoint { @GetMapping(params = "verb=ListIdentifiers", produces = "text/xml;charset=UTF-8") @Timed(value = "identifiers.list", description = "Time needed to list the identifiers") @Operation(summary = "List the identifiers") - @Parameter(name = "verb", example = "ListIdentifiers") public ResponseEntity<?> listIdentifiers(OaiListIdentifiersParameters parameters) { log.debug("endpoint list identifiers, verb=ListIdentifiers, parameters={}", parameters); final String xml = metadataService.listIdentifiers(parameters); @@ -62,7 +80,6 @@ public class MetadataEndpoint extends AbstractEndpoint { @GetMapping(params = "verb=GetRecord", produces = "text/xml;charset=UTF-8") @Timed(value = "record.find", description = "Time needed to find a record") @Operation(summary = "Get the record") - @Parameter(name = "verb", example = "GetRecord") public ResponseEntity<?> getRecord(OaiRecordParameters parameters) { log.debug("endpoint get record, verb=GetRecord, parameters={}", parameters); if (!parameters.getMetadataPrefix().equals("oai_dc")) { @@ -88,7 +105,6 @@ public class MetadataEndpoint extends AbstractEndpoint { @GetMapping(params = "verb=ListMetadataFormats", produces = "text/xml;charset=UTF-8") @Timed(value = "formats.list", description = "Time needed to list the metadata formats") @Operation(summary = "List the metadata formats") - @Parameter(name = "verb", example = "ListMetadataFormats") public ResponseEntity<?> listMetadataFormats() { log.debug("endpoint list metadata formats, verb=ListMetadataFormats"); final String xml = metadataService.listMetadataFormats(); diff --git a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java index 1df4786dd76971db481e29a5a0349b72ea84946f..94bc7246f5a34cc3eb397808b8b95bdcc941a904 100644 --- a/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java +++ b/dbrepo-metadata-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java @@ -3,6 +3,7 @@ package at.tuwien.handlers; import at.tuwien.api.error.ApiErrorDto; import at.tuwien.exception.IdentifierNotFoundException; import at.tuwien.exception.InvalidPrefixException; +import io.swagger.v3.oas.annotations.Hidden; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -15,6 +16,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExcep @ControllerAdvice public class ApiExceptionHandler extends ResponseEntityExceptionHandler { + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(IdentifierNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(IdentifierNotFoundException e, WebRequest request) { @@ -26,6 +28,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(InvalidPrefixException.class) public ResponseEntity<ApiErrorDto> handle(InvalidPrefixException e, WebRequest request) { diff --git a/dbrepo-metadata-service/rest-service/src/main/resources/application-docker.yml b/dbrepo-metadata-service/rest-service/src/main/resources/application-docker.yml new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/dbrepo-gateway-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java b/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java similarity index 63% rename from dbrepo-gateway-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java rename to dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java index ea8e189a75873f7e84553ceaa0a16f0a11a0cef7..940fee6b010023a1301ec33b8aa579a503f5112e 100644 --- a/dbrepo-gateway-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java +++ b/dbrepo-metadata-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java @@ -1,7 +1,8 @@ package at.tuwien; +import at.tuwien.test.BaseTest; import org.springframework.test.context.TestPropertySource; @TestPropertySource(locations = "classpath:application.properties") -public abstract class BaseUnitTest { +public abstract class BaseUnitTest extends BaseTest { } diff --git a/dbrepo-metadata-service/rest-service/src/test/resources/application.properties b/dbrepo-metadata-service/rest-service/src/test/resources/application.properties new file mode 100644 index 0000000000000000000000000000000000000000..507921d77d8b04535ded832f91bafe10abe92d6a --- /dev/null +++ b/dbrepo-metadata-service/rest-service/src/test/resources/application.properties @@ -0,0 +1,21 @@ +# enable local spring profile +spring.profiles.active=local + +# disable discovery +spring.cloud.discovery.enabled = false + +# disable cloud config and config discovery +spring.cloud.config.discovery.enabled = false +spring.cloud.config.enabled = false + +# disable datasource +spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS FDA +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password=password +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.show-sql=false + +fda.mapping.path: /tmp +fda.table.path: /tmp \ No newline at end of file diff --git a/dbrepo-metadata-service/services/pom.xml b/dbrepo-metadata-service/services/pom.xml index 9bd1c686e95c9ca9c098f30fbe2d723d645c0d08..d112379f5c9ad5bb9673d050dac61646262d86cb 100644 --- a/dbrepo-metadata-service/services/pom.xml +++ b/dbrepo-metadata-service/services/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> - <artifactId>fda-metadata-service</artifactId> + <artifactId>dbrepo-metadata-service</artifactId> <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </parent> <artifactId>services</artifactId> - <version>1.1.0-alpha</version> - <name>fda-metadata-service-services</name> + <version>1.2.0</version> + <name>dbrepo-metadata-service-services</name> <dependencies /> diff --git a/dbrepo-metadata-service/services/src/main/java/at/tuwien/config/WebSecurityConfig.java b/dbrepo-metadata-service/services/src/main/java/at/tuwien/config/WebSecurityConfig.java index af187a70662179d1a8ac68dcffb2c509be21b0b5..83d5aa02846369114bb8c9050aed216f1ee5a382 100644 --- a/dbrepo-metadata-service/services/src/main/java/at/tuwien/config/WebSecurityConfig.java +++ b/dbrepo-metadata-service/services/src/main/java/at/tuwien/config/WebSecurityConfig.java @@ -1,19 +1,13 @@ package at.tuwien.config; -import io.swagger.v3.oas.annotations.enums.SecuritySchemeType; -import io.swagger.v3.oas.annotations.security.SecurityScheme; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.http.SessionCreationPolicy; -import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; diff --git a/dbrepo-query-service/Dockerfile b/dbrepo-query-service/Dockerfile index a4d4c52a4b50dd84bfe21a77c175f51751275da4..481a93ad52df228c3912bc91a9a8bfd54b8802bd 100644 --- a/dbrepo-query-service/Dockerfile +++ b/dbrepo-query-service/Dockerfile @@ -1,5 +1,5 @@ ###### FIRST STAGE ###### -FROM fda-metadata-db:latest as dependency +FROM dbrepo-metadata-db:latest as dependency MAINTAINER Martin Weise <martin.weise@tuwien.ac.at> ###### SECOND STAGE ###### diff --git a/dbrepo-query-service/api/pom.xml b/dbrepo-query-service/api/pom.xml index 8a1e662ec6e99ac4926bc7a3a5af0c3edac62238..a4c9dc32f9819c0b64ab11ca0d0c4f701326889c 100644 --- a/dbrepo-query-service/api/pom.xml +++ b/dbrepo-query-service/api/pom.xml @@ -4,13 +4,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> - <artifactId>fda-query-service</artifactId> + <artifactId>dbrepo-query-service</artifactId> <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </parent> <artifactId>api</artifactId> - <name>fda-query-service-api</name> + <name>dbrepo-query-service-api</name> <properties> <jacoco.version>0.8.7</jacoco.version> diff --git a/dbrepo-query-service/pom.xml b/dbrepo-query-service/pom.xml index 35ec3a29280f9b41b5d1a3170670329ef5185957..075f7d868a82cf38ca38f531263a41be8da3dda4 100644 --- a/dbrepo-query-service/pom.xml +++ b/dbrepo-query-service/pom.xml @@ -9,9 +9,9 @@ </parent> <groupId>at.tuwien</groupId> - <artifactId>fda-query-service</artifactId> - <version>1.1.0-alpha</version> - <name>fda-query-service</name> + <artifactId>dbrepo-query-service</artifactId> + <version>1.2.0</version> + <name>dbrepo-query-service</name> <description> The query service provides an interface to insert data into the tables created by the table service. It also allows for view-only (possibly paginated and versioned) query execution to the raw data and consumes @@ -91,6 +91,7 @@ <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-test</artifactId> + <version>${project.version}</version> <scope>test</scope> </dependency> <dependency> @@ -156,19 +157,19 @@ <!-- Entity, API, QueryStore --> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-api</artifactId> + <artifactId>dbrepo-metadata-db-api</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-entites</artifactId> + <artifactId>dbrepo-metadata-db-entites</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-querystore</artifactId> + <artifactId>dbrepo-metadata-db-querystore</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> @@ -204,6 +205,12 @@ <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.version}</version> </dependency> + <dependency> + <groupId>at.tuwien</groupId> + <artifactId>dbrepo-metadata-db-test</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> <!-- Mapping --> <dependency> <groupId>org.mapstruct</groupId> @@ -269,7 +276,7 @@ <exclude>at/tuwien/config/**/*</exclude> <exclude>**/RabbitMqServiceImpl.class</exclude> <exclude>**/ServiceSeeder.class</exclude> - <exclude>**/FdaQueryServiceApplication.class</exclude> + <exclude>**/DbrepoQueryServiceApplication.class</exclude> </excludes> </configuration> <executions> diff --git a/dbrepo-query-service/report/pom.xml b/dbrepo-query-service/report/pom.xml index e9db628231f3eb0cf2d35c623eb0ede54d808666..50a488e8c7f8ede488a405ade55c995d482da490 100644 --- a/dbrepo-query-service/report/pom.xml +++ b/dbrepo-query-service/report/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> - <artifactId>fda-query-service</artifactId> + <artifactId>dbrepo-query-service</artifactId> <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </parent> <artifactId>report</artifactId> - <version>1.1.0-alpha</version> - <name>fda-query-service-report</name> + <version>1.2.0</version> + <name>dbrepo-query-service-report</name> <description> This module is only intended for the pipeline coverage report. See the detailed report in the respective modules diff --git a/dbrepo-query-service/rest-service/pom.xml b/dbrepo-query-service/rest-service/pom.xml index b9b7089e9f7213c68ec8388abc2ebbfe86d004ea..9982045b839e457cc6110a566a74d4324218781b 100644 --- a/dbrepo-query-service/rest-service/pom.xml +++ b/dbrepo-query-service/rest-service/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> - <artifactId>fda-query-service</artifactId> + <artifactId>dbrepo-query-service</artifactId> <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </parent> <artifactId>rest-service</artifactId> - <version>1.1.0-alpha</version> - <name>fda-query-service-rest</name> + <version>1.2.0</version> + <name>dbrepo-query-service-rest</name> <dependencies> <dependency> diff --git a/dbrepo-query-service/rest-service/src/main/java/at/tuwien/FdaQueryServiceApplication.java b/dbrepo-query-service/rest-service/src/main/java/at/tuwien/DbrepoQueryServiceApplication.java similarity index 88% rename from dbrepo-query-service/rest-service/src/main/java/at/tuwien/FdaQueryServiceApplication.java rename to dbrepo-query-service/rest-service/src/main/java/at/tuwien/DbrepoQueryServiceApplication.java index 0f5ded190e05b56c484644447d062553898f5a70..af5e7ef22913baf7206dca51f5f9c6147bd29b27 100644 --- a/dbrepo-query-service/rest-service/src/main/java/at/tuwien/FdaQueryServiceApplication.java +++ b/dbrepo-query-service/rest-service/src/main/java/at/tuwien/DbrepoQueryServiceApplication.java @@ -16,10 +16,10 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @EntityScan(basePackages = "at.tuwien.entities") @EnableElasticsearchRepositories(basePackages = {"at.tuwien.repository.elastic"}) @EnableJpaRepositories(basePackages = {"at.tuwien.repository.jpa"}) -public class FdaQueryServiceApplication { +public class DbrepoQueryServiceApplication { public static void main(String[] args) { - SpringApplication.run(FdaQueryServiceApplication.class, args); + SpringApplication.run(DbrepoQueryServiceApplication.class, args); } } \ No newline at end of file diff --git a/dbrepo-query-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java b/dbrepo-query-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java index 1d32679e06659e7853e688d91731e7f0e1f456ce..3b18d5fc2819b868f845d6e768222f9624fd0d86 100644 --- a/dbrepo-query-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java +++ b/dbrepo-query-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java @@ -5,11 +5,14 @@ import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Contact; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.servers.Server; import org.springdoc.core.GroupedOpenApi; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import java.util.List; + @Configuration public class SwaggerConfig { @@ -30,8 +33,14 @@ public class SwaggerConfig { .name("Apache 2.0") .url("https://www.apache.org/licenses/LICENSE-2.0"))) .externalDocs(new ExternalDocumentation() - .description("Wiki Documentation") - .url("https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services/-/wikis")); + .description("Sourcecode Documentation") + .url("https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services")) + .servers(List.of(new Server() + .description("Generated server url") + .url("http://localhost:9093"), + new Server() + .description("Sandbox") + .url("https://dbrepo2.tuwien.ac.at"))); } @Bean diff --git a/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/AbstractEndpoint.java b/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/AbstractEndpoint.java new file mode 100644 index 0000000000000000000000000000000000000000..ec019289ec2fb8b8a709bdbb82bba4cc94c4701d --- /dev/null +++ b/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/AbstractEndpoint.java @@ -0,0 +1,293 @@ +package at.tuwien.endpoint; + +import at.tuwien.SortType; +import at.tuwien.api.database.query.ExecuteStatementDto; +import at.tuwien.config.QueryConfig; +import at.tuwien.entities.database.AccessType; +import at.tuwien.entities.database.Database; +import at.tuwien.entities.database.DatabaseAccess; +import at.tuwien.entities.database.table.Table; +import at.tuwien.entities.identifier.Identifier; +import at.tuwien.exception.*; +import at.tuwien.service.AccessService; +import at.tuwien.service.DatabaseService; +import at.tuwien.service.IdentifierService; +import at.tuwien.service.TableService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.Authentication; + +import java.security.Principal; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static at.tuwien.entities.identifier.VisibilityType.EVERYONE; + +@Slf4j +public abstract class AbstractEndpoint { + + private final QueryConfig queryConfig; + private final TableService tableService; + private final AccessService accessService; + private final DatabaseService databaseService; + private final IdentifierService identifierService; + + @Autowired + protected AbstractEndpoint(TableService tableService, AccessService accessService, DatabaseService databaseService, + IdentifierService identifierService, QueryConfig queryConfig) { + this.queryConfig = queryConfig; + this.tableService = tableService; + this.accessService = accessService; + this.databaseService = databaseService; + this.identifierService = identifierService; + } + + protected Boolean hasDatabasePermission(Long containerId, Long databaseId, String permissionCode, + Principal principal) throws NotAllowedException { + log.trace("validate database permission, containerId={}, databaseId={}, permissionCode={}, principal={}", + containerId, databaseId, permissionCode, principal); + final Database database; + try { + database = databaseService.find(containerId, databaseId); + } catch (DatabaseNotFoundException e) { + log.error("Failed to find database with id {}", databaseId); + return false; + } + /* view-only operations are allowed on public databases */ + if (database.getIsPublic() && List.of("DATA_VIEW", "DATA_HISTORY", "QUERY_VIEW_ALL").contains(permissionCode)) { + log.debug("grant permission {} because database is public", permissionCode); + return true; + } + if (List.of("LIST_VIEWS", "FIND_VIEW", "DATA_VIEW").contains(permissionCode)) { + log.debug("grant permission {} because it is allowed on public/private databases", permissionCode); + return true; + } + if (principal == null) { + log.error("Failed to grant permission {} because principal is null", permissionCode); + return false; + } + final DatabaseAccess access = accessService.find(databaseId, principal.getName()); + /* check view access */ + if (List.of("QUERY_EXECUTE").contains(permissionCode)) { + log.debug("grant permission {} because user has access {}", permissionCode, access.getType()); + return true; + } + if (List.of("CREATE_VIEW").contains(permissionCode) && database.getOwner().getId().equals(access.getHuserid())) { + log.debug("grant permission {} because user is owner {}", permissionCode, access.getType()); + return true; + } + /* has role researcher */ + final Authentication authentication = (Authentication) principal /* with pre-authorization this always holds */; + if (authentication.getAuthorities().stream().noneMatch(a -> a.getAuthority().equals("ROLE_RESEARCHER"))) { + log.error("Failed to grant permission {} because current user misses authority 'ROLE_RESEARCHER'", + permissionCode); + return false; + } + return false; + } + + protected void validateDataParams(Long page, Long size) throws PaginationException { + log.trace("validate data params, page={}, size={}", page, size); + if ((page == null && size != null) || (page != null && size == null)) { + log.error("Failed to validate page and/or size number, either both are present or none"); + throw new PaginationException("Failed to validate page and/or size number"); + } + if (page != null && page < 0) { + log.error("Failed to validate page number, is lower than zero"); + throw new PaginationException("Failed to validate page number"); + } + if (size != null && size <= 0) { + log.error("Failed to validate size number, is lower or equal than zero"); + throw new PaginationException("Failed to validate size number"); + } + } + + protected void validateDataParams(Long page, Long size, SortType sortDirection, String sortColumn) + throws PaginationException, SortException { + log.trace("validate data params, page={}, size={}, sortDirection={}, sortColumn={}", page, size, + sortDirection, sortColumn); + validateDataParams(page, size); + if ((sortDirection == null && sortColumn != null) || (sortDirection != null && sortColumn == null)) { + log.error("Failed to validate sort direction and/or sort column, either both are present or none"); + throw new SortException("Failed to validate sort direction and/or sort column"); + } + } + + /** + * Do not allow aggregate functions and comments + * https://mariadb.com/kb/en/aggregate-functions/ + */ + protected void validateForbiddenStatements(ExecuteStatementDto data) throws QueryMalformedException { + final List<String> words = new LinkedList<>(); + Arrays.stream(queryConfig.getNotSupportedKeywords()) + .forEach(keyword -> { + final Pattern pattern = Pattern.compile(keyword); + final Matcher matcher = pattern.matcher(data.getStatement()); + final boolean found = matcher.find(); + if (found) { + words.add(keyword); + } + }); + if (words.size() == 0) { + return; + } + log.error("Query contains forbidden keyword(s): {}", words); + log.debug("forbidden keywords: {}", words); + throw new QueryMalformedException("Query contains forbidden keyword(s): " + Arrays.toString(words.toArray())); + } + + protected Boolean hasTablePermission(Long containerId, Long databaseId, Long tableId, String permissionCode, + Principal principal) throws NotAllowedException { + log.trace("validate queue permission, containerId={}, databaseId={}, tableId={}, permissionCode={}, principal={}", + containerId, databaseId, tableId, permissionCode, principal); + final Database database; + try { + database = databaseService.find(containerId, databaseId); + } catch (DatabaseNotFoundException e) { + log.error("Failed to find database with id {}", databaseId); + return false; + } + final Table table; + try { + table = tableService.find(containerId, databaseId, tableId); + } catch (TableNotFoundException e) { + log.error("Failed to find table with id {} in database with id {}", tableId, databaseId); + return false; + } catch (DatabaseNotFoundException e) { + /* can never occur here */ + return false; + } + /* view-only operations are allowed on public databases */ + if (database.getIsPublic() && List.of("TABLE_EXPORT", "DATA_VIEW", "DATA_HISTORY").contains(permissionCode)) { + log.debug("grant permission {} because database is public", permissionCode); + return true; + } + if (principal == null) { + log.error("Failed to grant permission {} because principal is null", permissionCode); + return false; + } + final Authentication authentication = (Authentication) principal /* with pre-authorization this always holds */; + if (authentication.getAuthorities().stream().noneMatch(a -> a.getAuthority().equals("ROLE_RESEARCHER"))) { + log.error("Failed to grant permission {} because current user misses authority 'ROLE_RESEARCHER'", + permissionCode); + return false; + } + final DatabaseAccess access = accessService.find(databaseId, principal.getName()); + /* check view access */ + if (List.of("TABLE_EXPORT", "DATA_VIEW", "DATA_HISTORY", "QUERY_VIEW_ALL", "QUERY_RE_EXECUTE", "QUERY_VIEW", "FIND_VIEW").contains(permissionCode)) { + log.trace("grant permission {} because user has access {}", permissionCode, access.getType()); + return true; + } + if (List.of("DATA_INSERT", "DATA_UPDATE", "DATA_DELETE").contains(permissionCode) && access.getType().equals(AccessType.WRITE_ALL)) { + /* write own is already effective with creator check above */ + log.debug("grant permission {} because user {} is has table write permission {}", permissionCode, principal.getName(), + access.getType()); + return true; + } + if (List.of("QUERY_PERSIST").contains(permissionCode) && access != null) { + /* write own is already effective with creator check above */ + log.debug("grant permission {} because user {} is has database read/write permission {}", permissionCode, principal.getName(), + access.getType()); + return true; + } + log.debug("failed to grant permission {} because database is not owner by the current user and also has not appropriate access", permissionCode); + return false; + } + + protected Boolean hasQueryPermission(Long containerId, Long databaseId, Long queryId, String permissionCode, + Principal principal) throws NotAllowedException { + log.trace("validate query permission, containerId={}, databaseId={}, queryId={}, permissionCode={}, principal={}", + containerId, databaseId, queryId, permissionCode, principal); + final Database database; + try { + database = databaseService.find(containerId, databaseId); + } catch (DatabaseNotFoundException e) { + log.error("Failed to find database with id {}", databaseId); + return false; + } + if (hasPublicIdentifier(databaseId, queryId, permissionCode)) { + return true; + } + /* modification operations are limited to the creator */ + if (isMyPrivateIdentifier(databaseId, queryId, principal, permissionCode)) { + return true; + } + /* view-only operations are allowed on public databases */ + if (database.getIsPublic() && List.of("QUERY_VIEW_ALL", "QUERY_VIEW", "QUERY_EXPORT", "QUERY_RE_EXECUTE").contains( + permissionCode)) { + log.debug("grant permission {} because database is public", permissionCode); + return true; + } + if (principal == null) { + log.error("Failed to grant permission {} because principal is null", permissionCode); + return false; + } + final DatabaseAccess access = accessService.find(databaseId, principal.getName()); + /* check view access */ + if (List.of("DATA_VIEW", "DATA_HISTORY", "QUERY_VIEW_ALL", "QUERY_RE_EXECUTE", "QUERY_VIEW", "FIND_VIEW", "QUERY_EXPORT").contains(permissionCode)) { + log.trace("grant permission {} because user has access {}", permissionCode, access.getType()); + return true; + } + /* has role researcher */ + final Authentication authentication = (Authentication) principal /* with pre-authorization this always holds */; + if (authentication.getAuthorities().stream().noneMatch(a -> a.getAuthority().equals("ROLE_RESEARCHER"))) { + log.error("Failed to grant permission {} because current user misses authority 'ROLE_RESEARCHER'", + permissionCode); + return false; + } + if (access.getType().equals(AccessType.WRITE_ALL)) { + log.trace("grant permission {} because user has access {}", permissionCode, access.getType()); + return true; + } + log.debug("failed to grant permission {} because database is not owner by the current user and also has not appropriate access", permissionCode); + return false; + } + + protected Boolean hasPublicIdentifier(Long databaseId, Long queryId, String permissionCode) { + log.trace("validate has public identifier, databaseId={}, queryId={}, permissionCode={}", databaseId, queryId, + permissionCode); + final Identifier identifier; + try { + identifier = identifierService.findByDatabaseIdAndQueryId(databaseId, queryId); + } catch (IdentifierNotFoundException e) { + return false; + } + if (identifier.getVisibility().equals(EVERYONE)) { + log.debug("grant permission {} because identifier visibility is public", permissionCode); + return true; + } + log.error("Failed to grant permission {} because identifier visibility is not public", permissionCode); + return false; + } + + protected Boolean isMyPrivateIdentifier(Long databaseId, Long queryId, Principal principal, String permissionCode) { + log.trace("validate is my private identifier, databaseId={}, queryId={}, permissionCode={}", databaseId, queryId, + permissionCode); + final Identifier identifier; + try { + identifier = identifierService.findByDatabaseIdAndQueryId(databaseId, queryId); + } catch (IdentifierNotFoundException e) { + return false; + } + if (identifier.getDatabase().getIsPublic()) { + log.debug("grant permission {} because database is public", permissionCode); + return true; + } + if (principal == null) { + log.error("Failed to grant permission {} because database is private and principal is null", + permissionCode); + return false; + } + if (identifier.getCreator().getUsername().equals(principal.getName())) { + log.debug("grant permission {} because database is private and identifier creator is the current user", + permissionCode); + return true; + } + log.error("Failed to grant permission {} because database is private and identifier creator is not the current user", permissionCode); + return false; + } + +} diff --git a/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/StoreEndpoint.java b/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/StoreEndpoint.java index 12ef14a247b8d721e2ea101408e33af3aa49cdd9..bb2b18b343425d1e083a171df5bf8edcde86057b 100644 --- a/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/StoreEndpoint.java +++ b/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/StoreEndpoint.java @@ -2,6 +2,7 @@ package at.tuwien.endpoint; import at.tuwien.api.database.query.QueryBriefDto; import at.tuwien.api.database.query.QueryDto; +import at.tuwien.api.error.ApiErrorDto; import at.tuwien.entities.identifier.Identifier; import at.tuwien.entities.identifier.IdentifierType; import at.tuwien.entities.user.User; @@ -13,6 +14,10 @@ import at.tuwien.mapper.QueryMapper; import at.tuwien.service.*; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; @@ -56,6 +61,43 @@ public class StoreEndpoint { @Transactional(readOnly = true) @Timed(value = "store.list", description = "Time needed to list queries from the query store") @Operation(summary = "Find queries", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "List queries", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = QueryBriefDto[].class))}), + @ApiResponse(responseCode = "404", + description = "Database, container or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Find all queries is not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "423", + description = "Selection of time-versioned query resulted in an invalid query statement", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "501", + description = "Image is not supported", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "503", + description = "Connection to the database failed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "504", + description = "Query store failed to select query", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<List<QueryBriefDto>> findAll(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable("databaseId") Long databaseId, @RequestParam(value = "persisted", required = false) Boolean persisted, @@ -89,6 +131,38 @@ public class StoreEndpoint { @Transactional(readOnly = true) @Timed(value = "store.find", description = "Time needed to find a query from the query store") @Operation(summary = "Find some query", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "List queries", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = QueryDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database, query or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Find query is not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "501", + description = "Image is not supported", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "503", + description = "Connection to the database failed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "504", + description = "Query store failed to select query", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<QueryDto> find(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable Long queryId, @@ -117,6 +191,38 @@ public class StoreEndpoint { @PreAuthorize("hasAuthority('persist-query')") @Timed(value = "store.persist", description = "Time needed to persist a query in the query store") @Operation(summary = "Persist some query", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "Persist query successful", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = QueryDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database, query or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Persist query is not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "409", + description = "Query is already persisted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "501", + description = "Image is not supported", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "504", + description = "Query store failed to persist query", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<QueryDto> persist(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("queryId") Long queryId, diff --git a/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/TableHistoryEndpoint.java b/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/TableHistoryEndpoint.java index 55dcab71c1b3220dbb5b5f76cda0b45e873ebefd..b8b4f03dac74655b1f4c2749bbe809d189f8799c 100644 --- a/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/TableHistoryEndpoint.java +++ b/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/TableHistoryEndpoint.java @@ -1,11 +1,16 @@ package at.tuwien.endpoint; import at.tuwien.api.database.table.TableHistoryDto; +import at.tuwien.api.error.ApiErrorDto; import at.tuwien.config.QueryConfig; import at.tuwien.exception.*; import at.tuwien.service.*; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; @@ -35,6 +40,38 @@ public class TableHistoryEndpoint { @Transactional(readOnly = true) @Timed(value = "history.list", description = "Time needed to retrieve table history") @Operation(summary = "Find all history", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "Find table history successfully", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = TableHistoryDto[].class))}), + @ApiResponse(responseCode = "400", + description = "Table history query is malformed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Table, database or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Find table history is not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "503", + description = "Connection to the database failed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "504", + description = "Query store failed to query table history", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<List<TableHistoryDto>> getAll(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("tableId") Long tableId, diff --git a/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/ViewEndpoint.java b/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/ViewEndpoint.java index 274078d4d1090aa45a2c8e0229866cfdf28e36e4..c921c04d94dd15d6a96a130c4aa7bade0ff6b5eb 100644 --- a/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/ViewEndpoint.java +++ b/dbrepo-query-service/rest-service/src/main/java/at/tuwien/endpoint/ViewEndpoint.java @@ -4,6 +4,10 @@ import at.tuwien.api.database.ViewBriefDto; import at.tuwien.api.database.ViewCreateDto; import at.tuwien.api.database.ViewDto; import at.tuwien.api.database.query.QueryResultDto; +import at.tuwien.api.database.query.QueryTypeDto; +import at.tuwien.api.database.table.TableHistoryDto; +import at.tuwien.api.error.ApiErrorDto; +import at.tuwien.config.QueryConfig; import at.tuwien.entities.database.Database; import at.tuwien.entities.database.View; import at.tuwien.exception.*; @@ -12,6 +16,10 @@ import at.tuwien.service.*; import at.tuwien.validation.EndpointValidator; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; @@ -53,6 +61,23 @@ public class ViewEndpoint { @Transactional(readOnly = true) @Timed(value = "view.list", description = "Time needed to list all views in a database") @Operation(summary = "Find all views", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "Find views successfully", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ViewBriefDto[].class))}), + @ApiResponse(responseCode = "404", + description = "Database or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Find views is not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<List<ViewBriefDto>> findAll(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable("databaseId") Long databaseId, Principal principal) throws DatabaseNotFoundException, @@ -74,6 +99,38 @@ public class ViewEndpoint { @PreAuthorize("hasAuthority('create-database-view')") @Timed(value = "view.create", description = "Time needed to create a view") @Operation(summary = "Create a view", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "201", + description = "Create view successfully", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ViewBriefDto.class))}), + @ApiResponse(responseCode = "400", + description = "Create view query is malformed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Create view is not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "423", + description = "Create view resulted in an invalid query statement", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "503", + description = "Connection to the database failed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<ViewBriefDto> create(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @Valid @RequestBody ViewCreateDto data, @@ -96,6 +153,23 @@ public class ViewEndpoint { @Transactional(readOnly = true) @Timed(value = "view.find", description = "Time needed to find a view") @Operation(summary = "Find one view", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "Find view successfully", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ViewDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database, view or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Find view is not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<ViewDto> find(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("viewId") Long viewId, @@ -115,6 +189,36 @@ public class ViewEndpoint { @PreAuthorize("hasAuthority('delete-database-view')") @Timed(value = "view.delete", description = "Time needed to delete a view") @Operation(summary = "Delete one view", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "Delete view successfully", + content = {@Content}), + @ApiResponse(responseCode = "400", + description = "Delete view query is malformed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database, view or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Delete view is not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "423", + description = "Delete view resulted in an invalid query statement", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "503", + description = "Connection to the database failed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<?> delete(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("viewId") Long viewId, @@ -132,6 +236,53 @@ public class ViewEndpoint { @Transactional(readOnly = true) @Timed(value = "view.data", description = "Time needed to retrieve data from a view") @Operation(summary = "Find view data", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "Find data successfully", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = QueryResultDto.class))}), + @ApiResponse(responseCode = "400", + description = "Pagination not in valid range or find data query is malformed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database, view, container or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Find data is not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "417", + description = "Parsing of resulting columns failed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "423", + description = "Find data resulted in an invalid query statement", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "501", + description = "Image is not supported", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "503", + description = "Connection to the database failed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "504", + description = "Query store failed to query view data", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<QueryResultDto> data(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("viewId") Long viewId, diff --git a/dbrepo-query-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java b/dbrepo-query-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java index b5d0c1658bf704de3856a2321cdf4d2057412c66..5c05b664cad0ffef757ef68259d51923e141f7c2 100644 --- a/dbrepo-query-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java +++ b/dbrepo-query-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java @@ -2,6 +2,7 @@ package at.tuwien.handlers; import at.tuwien.api.error.ApiErrorDto; import at.tuwien.exception.*; +import io.swagger.v3.oas.annotations.Hidden; import net.sf.jsqlparser.JSQLParserException; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -15,6 +16,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExcep @ControllerAdvice public class ApiExceptionHandler extends ResponseEntityExceptionHandler { + @Hidden @ResponseStatus(HttpStatus.NOT_ACCEPTABLE) @ExceptionHandler(AmqpException.class) public ResponseEntity<ApiErrorDto> handle(AmqpException e, WebRequest request) { @@ -26,6 +28,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.EXPECTATION_FAILED) @ExceptionHandler(ColumnParseException.class) public ResponseEntity<ApiErrorDto> handle(ColumnParseException e, WebRequest request) { @@ -37,6 +40,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(ContainerNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(ContainerNotFoundException e, WebRequest request) { @@ -48,17 +52,19 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) + @Hidden + @ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE) @ExceptionHandler(DatabaseConnectionException.class) public ResponseEntity<ApiErrorDto> handle(DatabaseConnectionException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.METHOD_NOT_ALLOWED) + .status(HttpStatus.SERVICE_UNAVAILABLE) .message(e.getLocalizedMessage()) .code("error.query.databaseconnection") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(DatabaseNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(DatabaseNotFoundException e, WebRequest request) { @@ -70,17 +76,31 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.BAD_REQUEST) + @Hidden + @ResponseStatus(HttpStatus.GONE) @ExceptionHandler(FileStorageException.class) public ResponseEntity<ApiErrorDto> handle(FileStorageException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.BAD_REQUEST) + .status(HttpStatus.GONE) .message(e.getLocalizedMessage()) .code("error.query.filestore") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(HeaderInvalidException.class) + public ResponseEntity<ApiErrorDto> handle(HeaderInvalidException e, WebRequest request) { + final ApiErrorDto response = ApiErrorDto.builder() + .status(HttpStatus.BAD_REQUEST) + .message(e.getLocalizedMessage()) + .code("error.query.exportheader") + .build(); + return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); + } + + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(IdentifierNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(IdentifierNotFoundException e, WebRequest request) { @@ -92,17 +112,19 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.CONFLICT) + @Hidden + @ResponseStatus(HttpStatus.NOT_IMPLEMENTED) @ExceptionHandler(ImageNotSupportedException.class) public ResponseEntity<ApiErrorDto> handle(ImageNotSupportedException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.CONFLICT) + .status(HttpStatus.NOT_IMPLEMENTED) .message(e.getLocalizedMessage()) .code("error.query.imagenotsupported") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) @ExceptionHandler(NotAllowedException.class) public ResponseEntity<ApiErrorDto> handle(NotAllowedException e, WebRequest request) { @@ -114,6 +136,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(PaginationException.class) public ResponseEntity<ApiErrorDto> handle(PaginationException e, WebRequest request) { @@ -125,6 +148,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.CONFLICT) @ExceptionHandler(QueryAlreadyPersistedException.class) public ResponseEntity<ApiErrorDto> handle(QueryAlreadyPersistedException e, WebRequest request) { @@ -136,6 +160,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(QueryMalformedException.class) public ResponseEntity<ApiErrorDto> handle(QueryMalformedException e, WebRequest request) { @@ -147,6 +172,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(QueryNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(QueryNotFoundException e, WebRequest request) { @@ -158,6 +184,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.GATEWAY_TIMEOUT) @ExceptionHandler(QueryStoreException.class) public ResponseEntity<ApiErrorDto> handle(QueryStoreException e, WebRequest request) { @@ -169,6 +196,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(SortException.class) public ResponseEntity<ApiErrorDto> handle(SortException e, WebRequest request) { @@ -180,6 +208,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.LOCKED) @ExceptionHandler(TableMalformedException.class) public ResponseEntity<ApiErrorDto> handle(TableMalformedException e, WebRequest request) { @@ -191,6 +220,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(TableNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(TableNotFoundException e, WebRequest request) { @@ -202,6 +232,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.CONFLICT) @ExceptionHandler(TupleDeleteException.class) public ResponseEntity<ApiErrorDto> handle(TupleDeleteException e, WebRequest request) { @@ -213,6 +244,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(UserNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(UserNotFoundException e, WebRequest request) { @@ -224,6 +256,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.LOCKED) @ExceptionHandler(ViewMalformedException.class) public ResponseEntity<ApiErrorDto> handle(ViewMalformedException e, WebRequest request) { @@ -235,6 +268,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(ViewNotFoundException.class) public ResponseEntity<ApiErrorDto> handle(ViewNotFoundException e, WebRequest request) { diff --git a/dbrepo-query-service/rest-service/src/main/resources/application-docker.yml b/dbrepo-query-service/rest-service/src/main/resources/application-docker.yml new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java index c62dae93fd85df9e890c560b430cd64cee746402..01f84e12b909533314c3cc741739e02801e78ee5 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java @@ -1,2579 +1,9 @@ package at.tuwien; -import at.tuwien.api.database.ViewDto; -import at.tuwien.api.database.query.QueryBriefDto; -import at.tuwien.api.database.query.QueryDto; -import at.tuwien.api.database.query.QueryResultDto; -import at.tuwien.api.database.table.TableCsvDto; -import at.tuwien.api.identifier.IdentifierTypeDto; -import at.tuwien.api.identifier.VisibilityTypeDto; -import at.tuwien.api.user.UserDetailsDto; -import at.tuwien.api.user.UserDto; -import at.tuwien.entities.container.image.ContainerImageDate; -import at.tuwien.entities.database.AccessType; -import at.tuwien.entities.database.DatabaseAccess; -import at.tuwien.entities.database.View; -import at.tuwien.entities.database.table.columns.TableColumnConcept; -import at.tuwien.entities.database.table.constraints.Constraints; -import at.tuwien.entities.database.table.constraints.foreignKey.ForeignKey; -import at.tuwien.entities.database.table.constraints.foreignKey.ForeignKeyReference; -import at.tuwien.entities.database.table.constraints.unique.Unique; -import at.tuwien.entities.identifier.Identifier; -import at.tuwien.entities.identifier.IdentifierType; -import at.tuwien.entities.identifier.VisibilityType; -import at.tuwien.entities.user.User; -import at.tuwien.querystore.Query; -import at.tuwien.entities.container.Container; -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.entities.database.table.Table; -import at.tuwien.entities.database.table.columns.TableColumn; -import at.tuwien.entities.database.table.columns.TableColumnType; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; -import com.github.dockerjava.api.model.HealthCheck; +import at.tuwien.test.BaseTest; import org.springframework.test.context.TestPropertySource; -import java.security.Principal; -import java.time.Instant; -import java.util.*; - -import static java.time.temporal.ChronoUnit.*; - -/** - * Database 1 - * <ul> - * <li>Table 1</li> - * <li>Table 2</li> - * <li>Table 3</li> - * <li>Table 7</li> - * </ul> - * <p> - * Database 2 - * <ul> - * <li>Table 4</li> - * <li>Table 5</li> - * <li>Table 6</li> - * <li>View 4</li> - * </ul> - */ @TestPropertySource(locations = "classpath:application.properties") -public abstract class BaseUnitTest { - - public final static String JWT_1 = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJtd2Vpc2UiLCJybmQiOjk2NjIyNzAwMCwiZXhwIjoxNjczODg2MDk5LCJpYXQiOjE2NzM3OTk2OTl9.y1jqokCfZE7c_Ztt_nLQlf73jCYXPH5TZpCvo3RwS0C5azyrqLh03bphl6R8A24g6Kv_3qjzvnubNIwmO7y7pA"; - - public final static String USER_1_ID = "090dc12a-a46a-4515-b1f0-cff697d5f985"; - public final static String USER_1_USERNAME = "guest"; - public final static String USER_1_EMAIL = "junit@example.com"; - public final static String USER_1_PASSWORD = "password"; - public final static String USER_1_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - public final static Instant USER_1_CREATED = Instant.now().minus(1, HOURS); - - public final static User USER_1 = User.builder() - .id(USER_1_ID) - .username(USER_1_USERNAME) - .email(USER_1_EMAIL) - .emailVerified(true) - .databasePassword(USER_1_DATABASE_PASSWORD) - .build(); - - public final static UserDto USER_1_DTO = UserDto.builder() - .id(USER_1_ID) - .username(USER_1_USERNAME) - .email(USER_1_EMAIL) - .emailVerified(true) - .build(); - - public final static UserDetails USER_1_DETAILS = UserDetailsDto.builder() - .username(USER_1_USERNAME) - .email(USER_1_EMAIL) - .password(USER_1_PASSWORD) - .authorities(List.of(new SimpleGrantedAuthority("ROLE_RESEARCHER"))) - .build(); - - public final static Principal USER_1_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_1_DETAILS, - USER_1_PASSWORD, USER_1_DETAILS.getAuthorities()); - - public final static String USER_2_ID = "0153f998-bd4c-4154-993e-75c355499044"; - public final static String USER_2_USERNAME = "junit2"; - public final static String USER_2_EMAIL = "junit2@example.com"; - public final static String USER_2_PASSWORD = "password"; - public final static String USER_2_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - public final static Instant USER_2_CREATED = Instant.now().minus(1, HOURS); - - public final static User USER_2 = User.builder() - .id(USER_2_ID) - .username(USER_2_USERNAME) - .email(USER_2_EMAIL) - .emailVerified(true) - .databasePassword(USER_2_DATABASE_PASSWORD) - .build(); - - public final static UserDetails USER_2_DETAILS = UserDetailsDto.builder() - .username(USER_2_USERNAME) - .email(USER_2_EMAIL) - .password(USER_2_PASSWORD) - .authorities(List.of(new SimpleGrantedAuthority("ROLE_RESEARCHER"))) - .build(); - - public final static Principal USER_2_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_2_DETAILS, - USER_2_PASSWORD, USER_2_DETAILS.getAuthorities()); - - public final static String USER_3_ID = "fea123c7-1851-4e01-969a-53407fa6a451"; - public final static String USER_3_USERNAME = "system"; - public final static String USER_3_EMAIL = "system@example.com"; - public final static String USER_3_PASSWORD = "password"; - public final static String USER_3_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - public final static Instant USER_3_CREATED = Instant.now().minus(1, HOURS); - - public final static User USER_3 = User.builder() - .id(USER_3_ID) - .username(USER_3_USERNAME) - .email(USER_3_EMAIL) - .emailVerified(true) - .databasePassword(USER_3_DATABASE_PASSWORD) - .build(); - - public final static UserDetails USER_3_DETAILS = UserDetailsDto.builder() - .username(USER_3_USERNAME) - .email(USER_3_EMAIL) - .password(USER_3_PASSWORD) - .authorities(List.of(new SimpleGrantedAuthority("ROLE_DEVELOPER"))) - .build(); - - public final static Principal USER_3_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_3_DETAILS, - USER_3_PASSWORD, USER_3_DETAILS.getAuthorities()); - - public final static String USER_4_ID = "824d2c13-78d9-43c5-a4af-288120e2b44b"; - public final static String USER_4_USERNAME = "nobody"; - public final static String USER_4_EMAIL = "nobody@gmail.com"; - public final static Boolean USER_4_EMAIL_VERIFIED = false; - public final static Boolean USER_4_THEME_DARK = false; - public final static String USER_4_PASSWORD = "p455w0rdh45"; - public final static String USER_4_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - - public final static User USER_4 = User.builder() - .id(USER_4_ID) - .username(USER_4_USERNAME) - .email(USER_4_EMAIL) - .emailVerified(USER_4_EMAIL_VERIFIED) - .databasePassword(USER_4_DATABASE_PASSWORD) - .build(); - - public final static String USER_5_ID = "d2f3a8f4-c7fe-49e8-9d14-6dad0f6b9406"; - public final static String USER_5_USERNAME = "mweise"; - public final static String USER_5_EMAIL = "mweise@gmail.com"; - public final static Boolean USER_5_EMAIL_VERIFIED = false; - public final static Boolean USER_5_THEME_DARK = false; - public final static String USER_5_PASSWORD = "p455w0rdh45"; - public final static String USER_5_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - - public final static UserDetailsDto USER_5_DETAILS_DTO = UserDetailsDto.builder() - .id(USER_5_ID) - .username(USER_5_USERNAME) - .email(USER_5_EMAIL) - .password(USER_5_PASSWORD) - .authorities(List.of()) - .build(); - - 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"; - 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 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("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(), - 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()); - - 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_UNIX_FORMAT = "yyyy-MM-dd"; - public final static String IMAGE_DATE_1_DATABASE_FORMAT = "%Y-%c-%d"; - public final static String IMAGE_DATE_1_EXAMPLE = "2022-01-30"; - public final static Boolean IMAGE_DATE_1_HAS_TIME = false; - - public final static ContainerImageDate IMAGE_DATE_1 = ContainerImageDate.builder() - .id(IMAGE_DATE_1_ID) - .iid(IMAGE_DATE_1_IMAGE_ID) - .unixFormat(IMAGE_DATE_1_UNIX_FORMAT) - .databaseFormat(IMAGE_DATE_1_DATABASE_FORMAT) - .example(IMAGE_DATE_1_EXAMPLE) - .hasTime(IMAGE_DATE_1_HAS_TIME) - .build(); - - public final static Long IMAGE_DATE_2_ID = 2L; - public final static Long IMAGE_DATE_2_IMAGE_ID = IMAGE_1_ID; - public final static String IMAGE_DATE_2_UNIX_FORMAT = "dd.MM.yy"; - public final static String IMAGE_DATE_2_DATABASE_FORMAT = "%d.%c.%y"; - public final static String IMAGE_DATE_2_EXAMPLE = "30.01.2022"; - public final static Boolean IMAGE_DATE_2_HAS_TIME = false; - - public final static ContainerImageDate IMAGE_DATE_2 = ContainerImageDate.builder() - .id(IMAGE_DATE_2_ID) - .iid(IMAGE_DATE_2_IMAGE_ID) - .unixFormat(IMAGE_DATE_2_UNIX_FORMAT) - .databaseFormat(IMAGE_DATE_2_DATABASE_FORMAT) - .example(IMAGE_DATE_2_EXAMPLE) - .hasTime(IMAGE_DATE_2_HAS_TIME) - .build(); - - public final static Long IMAGE_DATE_3_ID = 3L; - public final static Long IMAGE_DATE_3_IMAGE_ID = IMAGE_1_ID; - public final static String IMAGE_DATE_3_UNIX_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"; - public final static String IMAGE_DATE_3_DATABASE_FORMAT = "%Y-%c-%dT%H:%i:%S.%f"; - public final static String IMAGE_DATE_3_EXAMPLE = "2022-01-30T13:44:25.499"; - public final static Boolean IMAGE_DATE_3_HAS_TIME = true; - - public final static ContainerImageDate IMAGE_DATE_3 = ContainerImageDate.builder() - .id(IMAGE_DATE_3_ID) - .iid(IMAGE_DATE_3_IMAGE_ID) - .unixFormat(IMAGE_DATE_3_UNIX_FORMAT) - .databaseFormat(IMAGE_DATE_3_DATABASE_FORMAT) - .example(IMAGE_DATE_3_EXAMPLE) - .hasTime(IMAGE_DATE_3_HAS_TIME) - .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) - .dateFormats(List.of(IMAGE_DATE_1, IMAGE_DATE_2, IMAGE_DATE_3)) - .build(); - - public final static Long IMAGE_BROKER_ID = 2L; - public final static String IMAGE_BROKER_REPOSITORY = "rabbitmq"; - public final static String IMAGE_BROKER_TAG = "3-management-alpine"; - public final static String IMAGE_BROKER_HASH = "d6a5e003eae42397f7ee4589e9f21e231d3721ac131970d2286bd616e7f55bb4\n"; - public final static String IMAGE_BROKER_DIALECT = "org.hibernate.dialect.MariaDBDialect"; - public final static String IMAGE_BROKER_DRIVER = "org.mariadb.jdbc.Driver"; - public final static String IMAGE_BROKER_JDBC = "mariadb"; - public final static Integer IMAGE_BROKER_PORT = 15672; - public final static Long IMAGE_BROKER_SIZE = 12000L; - public final static Instant IMAGE_BROKER_BUILT = Instant.now().minus(40, HOURS); - - public final static ContainerImage IMAGE_BROKER = ContainerImage.builder() - .id(IMAGE_BROKER_ID) - .repository(IMAGE_BROKER_REPOSITORY) - .tag(IMAGE_BROKER_TAG) - .hash(IMAGE_BROKER_HASH) - .compiled(IMAGE_BROKER_BUILT) - .dialect(IMAGE_BROKER_DIALECT) - .jdbcMethod(IMAGE_BROKER_JDBC) - .driverClass(IMAGE_BROKER_DRIVER) - .size(IMAGE_BROKER_SIZE) - .defaultPort(IMAGE_BROKER_PORT) - .build(); - - public final static Long IMAGE_ELASTIC_ID = 3L; - public final static String IMAGE_ELASTIC_REPOSITORY = "elasticsearch"; - public final static String IMAGE_ELASTIC_TAG = "7.13.4"; - public final static String[] IMAGE_ELASTIC_ENV = new String[]{"discovery.type=single-node", "ES_JAVA_OPTS=-Xms512m -Xmx512m", "logger.level=WARN"}; - public final static String IMAGE_ELASTIC_CMD = "elasticsearch"; - - public final static ContainerImage IMAGE_ELASTIC = ContainerImage.builder() - .id(IMAGE_ELASTIC_ID) - .repository(IMAGE_ELASTIC_REPOSITORY) - .tag(IMAGE_ELASTIC_TAG) - .build(); - - public final static Long IMAGE_PROXY_ID = 4L; - public final static String IMAGE_PROXY_REPOSITORY = "nginx"; - public final static String IMAGE_PROXY_TAG = "latest"; - - public final static ContainerImage IMAGE_PROXY = ContainerImage.builder() - .id(IMAGE_PROXY_ID) - .repository(IMAGE_PROXY_REPOSITORY) - .tag(IMAGE_PROXY_TAG) - .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 = "dbrepo-userdb-u01"; - public final static String CONTAINER_1_IP = "172.30.0.5"; - public final static Instant CONTAINER_1_CREATED = Instant.now().minus(1, HOURS); - public final static String[] CONTAINER_1_ENV = new String[]{"MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", - "MARIADB_DATABASE=weather"}; - public final static HealthCheck CONTAINER_1_HEALTHCHECK = new HealthCheck() - .withTest(List.of("CMD", "mysqladmin", "ping", "--host=127.0.0.1", "--password=mariadb")); - - public final static Container CONTAINER_1 = Container.builder() - .id(CONTAINER_1_ID) - .name(CONTAINER_1_NAME) - .internalName(CONTAINER_1_INTERNALNAME) - .imageId(IMAGE_1_ID) - .image(CONTAINER_1_IMAGE) - .hash(CONTAINER_1_HASH) - .ipAddress(CONTAINER_1_IP) - .created(CONTAINER_1_CREATED) - .creator(USER_1) - .build(); - - 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 = "dbrepo-userdb-u02"; - public final static String CONTAINER_2_IP = "172.30.0.6"; - public final static Instant CONTAINER_2_CREATED = Instant.now().minus(1, HOURS); - public final static String[] CONTAINER_2_ENV = new String[]{"MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", - "MARIADB_DATABASE=zoo"}; - public final static HealthCheck CONTAINER_2_HEALTHCHECK = new HealthCheck() - .withTest(List.of("CMD", "mysqladmin", "ping", "--host=127.0.0.1", "--password=mariadb")); - - public final static Container CONTAINER_2 = Container.builder() - .id(CONTAINER_2_ID) - .name(CONTAINER_2_NAME) - .internalName(CONTAINER_2_INTERNALNAME) - .imageId(IMAGE_1_ID) - .image(CONTAINER_2_IMAGE) - .hash(CONTAINER_2_HASH) - .ipAddress(CONTAINER_2_IP) - .created(CONTAINER_2_CREATED) - .creator(USER_1) - .build(); - - 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 = "dbrepo-userdb-u03"; - public final static String CONTAINER_3_IP = "172.30.0.7"; - public final static Instant CONTAINER_3_CREATED = Instant.now().minus(1, HOURS); - public final static HealthCheck CONTAINER_3_HEALTHCHECK = new HealthCheck() - .withTest(List.of("CMD", "mysqladmin", "ping", "--host=127.0.0.1", "--password=mariadb")); - - public final static Container CONTAINER_3 = Container.builder() - .id(CONTAINER_3_ID) - .name(CONTAINER_3_NAME) - .internalName(CONTAINER_3_INTERNALNAME) - .imageId(IMAGE_1_ID) - .image(CONTAINER_3_IMAGE) - .hash(CONTAINER_3_HASH) - .created(CONTAINER_3_CREATED) - .creator(USER_1) - .build(); - - public final static Long CONTAINER_4_ID = 4L; - public final static String CONTAINER_4_HASH = "deadbeef"; - public final static ContainerImage CONTAINER_4_IMAGE = IMAGE_1; - public final static String CONTAINER_4_NAME = "u04"; - public final static String CONTAINER_4_INTERNALNAME = "dbrepo-userdb-u04"; - public final static String CONTAINER_4_IP = "172.30.0.8"; - public final static Instant CONTAINER_4_CREATED = Instant.now().minus(1, HOURS); - public final static HealthCheck CONTAINER_4_HEALTHCHECK = new HealthCheck() - .withTest(List.of("CMD", "mysqladmin", "ping", "--host=127.0.0.1", "--password=mariadb")); - public final static String[] CONTAINER_4_ENV = new String[]{"MARIADB_USER=mariadb", "MARIADB_PASSWORD=mariadb", "MARIADB_ROOT_PASSWORD=mariadb", - "MARIADB_DATABASE=sensor"}; - - public final static Container CONTAINER_4 = Container.builder() - .id(CONTAINER_4_ID) - .name(CONTAINER_4_NAME) - .internalName(CONTAINER_4_INTERNALNAME) - .imageId(IMAGE_1_ID) - .image(CONTAINER_4_IMAGE) - .hash(CONTAINER_4_HASH) - .created(CONTAINER_4_CREATED) - .creator(USER_1) - .ipAddress(CONTAINER_4_IP) - .build(); - - public final static Long CONTAINER_BROKER_ID = 5L; - public final static String CONTAINER_BROKER_NAME = "dbrepo-broker-service"; - public final static String CONTAINER_BROKER_INTERNAL_NAME = "dbrepo-broker-service"; - public final static String CONTAINER_BROKER_IP = "172.31.0.2"; - public final static String CONTAINER_BROKER_HASH = "deadbeef"; - public final static Instant CONTAINER_BROKER_CREATED = Instant.now().minus(1, HOURS); - public final static HealthCheck CONTAINER_BROKER_HEALTHCHECK = new HealthCheck() - .withTest(List.of("CMD", "rabbitmq-diagnostics", "-q", "ping")); - public final static String[] CONTAINER_BROKER_ENV = new String[]{}; - - public final static Container CONTAINER_BROKER = Container.builder() - .id(CONTAINER_BROKER_ID) - .name(CONTAINER_BROKER_NAME) - .internalName(CONTAINER_BROKER_INTERNAL_NAME) - .imageId(IMAGE_BROKER_ID) - .image(IMAGE_BROKER) - .ipAddress(CONTAINER_BROKER_IP) - .hash(CONTAINER_BROKER_HASH) - .created(CONTAINER_BROKER_CREATED) - .creator(USER_1) - .build(); - - public final static Long CONTAINER_ELASTIC_ID = 6L; - public final static String CONTAINER_ELASTIC_NAME = "fda-elastic-service"; - public final static String CONTAINER_ELASTIC_INTERNAL_NAME = "search-mock-service"; - public final static String CONTAINER_ELASTIC_IP = "172.31.0.3"; - public final static String CONTAINER_ELASTIC_HASH = "deadbeef"; - public final static Instant CONTAINER_ELASTIC_CREATED = Instant.now().minus(1, HOURS); - - public final static Container CONTAINER_ELASTIC = Container.builder() - .id(CONTAINER_ELASTIC_ID) - .name(CONTAINER_ELASTIC_NAME) - .internalName(CONTAINER_ELASTIC_INTERNAL_NAME) - .imageId(IMAGE_ELASTIC_ID) - .image(IMAGE_ELASTIC) - .hash(CONTAINER_ELASTIC_HASH) - .ipAddress(CONTAINER_ELASTIC_IP) - .created(CONTAINER_ELASTIC_CREATED) - .creator(USER_1) - .build(); - - public final static Long CONTAINER_PROXY_ID = 7L; - public final static String CONTAINER_PROXY_NAME = "dbrepo-proxy"; - public final static String CONTAINER_PROXY_INTERNAL_NAME = "dbrepo-proxy"; - public final static String CONTAINER_PROXY_IP = "172.31.0.4"; - public final static String CONTAINER_PROXY_HASH = "deadbeef"; - public final static Instant CONTAINER_PROXY_CREATED = Instant.now().minus(1, HOURS); - public final static String[] CONTAINER_PROXY_ENV = new String[]{}; - public final static HealthCheck CONTAINER_PROXY_HEALTHCHECK = new HealthCheck() - .withTest(List.of("CMD", "service", "nginx", "status")); - - public final static Container CONTAINER_PROXY = Container.builder() - .id(CONTAINER_PROXY_ID) - .name(CONTAINER_PROXY_NAME) - .internalName(CONTAINER_PROXY_INTERNAL_NAME) - .imageId(IMAGE_PROXY_ID) - .image(IMAGE_PROXY) - .hash(CONTAINER_PROXY_HASH) - .ipAddress(CONTAINER_PROXY_IP) - .created(CONTAINER_PROXY_CREATED) - .creator(USER_1) - .build(); - - 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 = "dbrepo." + CONTAINER_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 = "Zoo"; - public final static String DATABASE_2_INTERNALNAME = "zoo"; - public final static String DATABASE_2_EXCHANGE = "dbrepo." + CONTAINER_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 = "dbrepo." + CONTAINER_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_QUEUE_NAME = DATABASE_1_EXCHANGE + "." + TABLE_1_INTERNALNAME; - public final static String TABLE_1_ROUTING_KEY = TABLE_1_QUEUE_NAME; - public final static Instant TABLE_1_LAST_MODIFIED = Instant.now(); - - public final static Long TABLE_2_ID = 2L; - public final static String TABLE_2_NAME = "Weather Location"; - public final static String TABLE_2_INTERNALNAME = "weather_location"; - public final static String TABLE_2_DESCRIPTION = "Weather location"; - public final static String TABLE_2_QUEUE_NAME = DATABASE_1_EXCHANGE + "." + TABLE_2_INTERNALNAME; - public final static String TABLE_2_ROUTING_KEY = TABLE_2_QUEUE_NAME; - public final static Instant TABLE_2_LAST_MODIFIED = Instant.now(); - - public final static Long TABLE_3_ID = 3L; - public final static String TABLE_3_NAME = "Traffic Zürich"; - public final static String TABLE_3_INTERNALNAME = "traffic_zurich"; - public final static String TABLE_3_DESCRIPTION = "https://www.kaggle.com/laa283/zurich-public-transport/version/2"; - public final static String TABLE_3_QUEUE_NAME = DATABASE_1_EXCHANGE + "." + TABLE_3_INTERNALNAME; - public final static String TABLE_3_ROUTING_KEY = TABLE_3_QUEUE_NAME; - public final static Instant TABLE_3_LAST_MODIFIED = Instant.now(); - - public final static Long TABLE_4_ID = 4L; - public final static String TABLE_4_NAME = "zoo"; - public final static String TABLE_4_INTERNALNAME = "zoo"; - public final static String TABLE_4_DESCRIPTION = "Some Kaggle dataset"; - public final static String TABLE_4_QUEUE_NAME = DATABASE_2_EXCHANGE + "." + TABLE_4_INTERNALNAME; - public final static String TABLE_4_ROUTING_KEY = TABLE_4_QUEUE_NAME; - public final static Instant TABLE_4_LAST_MODIFIED = Instant.now(); - - public final static Long TABLE_5_ID = 5L; - public final static String TABLE_5_NAME = "names"; - public final static String TABLE_5_INTERNALNAME = "names"; - public final static String TABLE_5_DESCRIPTION = "Some names dataset"; - public final static String TABLE_5_QUEUE_NAME = DATABASE_2_EXCHANGE + "/" + TABLE_5_INTERNALNAME; - public final static String TABLE_5_ROUTING_KEY = TABLE_5_QUEUE_NAME + "/1"; - public final static Instant TABLE_5_LAST_MODIFIED = Instant.now(); - - public final static Long TABLE_6_ID = 6L; - public final static String TABLE_6_NAME = "likes"; - public final static String TABLE_6_INTERNAL_NAME = "likes"; - public final static String TABLE_6_DESCRIPTION = "Some likes dataset"; - public final static String TABLE_6_QUEUE_NAME = DATABASE_2_EXCHANGE + "/" + TABLE_6_INTERNAL_NAME; - public final static String TABLE_6_ROUTING_KEY = TABLE_6_QUEUE_NAME + "/1"; - public final static Instant TABLE_6_LAST_MODIFIED = Instant.now(); - - public final static Long TABLE_7_ID = 7L; - public final static String TABLE_7_NAME = "Sensor"; - public final static String TABLE_7_INTERNAL_NAME = "sensor"; - public final static String TABLE_7_DESCRIPTION = "Hello sensor"; - public final static String TABLE_7_QUEUE_NAME = DATABASE_1_EXCHANGE + "/" + TABLE_7_INTERNAL_NAME; - public final static String TABLE_7_ROUTING_KEY = TABLE_7_QUEUE_NAME + "/1"; - public final static Instant TABLE_7_LAST_MODIFIED = Instant.now(); - - public final static Table TABLE_7 = Table.builder() - .id(TABLE_7_ID) - .created(Instant.now()) - .internalName(TABLE_7_INTERNAL_NAME) - .description(TABLE_7_DESCRIPTION) - .name(TABLE_7_NAME) - .lastModified(TABLE_7_LAST_MODIFIED) - .tdbid(DATABASE_1_ID) - .queueName(TABLE_7_QUEUE_NAME) - .routingKey(TABLE_7_ROUTING_KEY) - .columns(List.of(TableColumn.builder() - .id(1L) - .ordinalPosition(0) - .cdbid(DATABASE_1_ID) - .tid(TABLE_1_ID) - .name("Timestamp") - .internalName("timestamp") - .columnType(TableColumnType.TIMESTAMP) - .dfid(IMAGE_DATE_3_ID) - .isNullAllowed(false) - .autoGenerated(false) - .isPrimaryKey(true) - .build())) - .creator(USER_1) - .build(); - - 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 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 Long COLUMN_1_2_DATE_FORMAT = IMAGE_DATE_1_ID; - 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 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 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 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 COLUMN_2_1_ID = 6L; - public final static Integer COLUMN_2_1_ORDINALPOS = 0; - public final static Boolean COLUMN_2_1_PRIMARY = true; - public final static String COLUMN_2_1_NAME = "location"; - public final static String COLUMN_2_1_INTERNAL_NAME = "location"; - public final static TableColumnType COLUMN_2_1_TYPE = TableColumnType.STRING; - public final static Long COLUMN_2_1_DATE_FORMAT = null; - public final static Boolean COLUMN_2_1_NULL = false; - public final static Boolean COLUMN_2_1_UNIQUE = true; - public final static Boolean COLUMN_2_1_AUTO_GENERATED = false; - public final static String COLUMN_2_1_FOREIGN_KEY = null; - public final static String COLUMN_2_1_CHECK = null; - public final static List<String> COLUMN_2_1_ENUM_VALUES = null; - - public final static Long COLUMN_2_2_ID = 7L; - public final static Integer COLUMN_2_2_ORDINALPOS = 0; - public final static Boolean COLUMN_2_2_PRIMARY = false; - public final static String COLUMN_2_2_NAME = "lat"; - public final static String COLUMN_2_2_INTERNAL_NAME = "lat"; - public final static TableColumnType COLUMN_2_2_TYPE = TableColumnType.DECIMAL; - public final static Long COLUMN_2_2_DATE_FORMAT = null; - public final static Boolean COLUMN_2_2_NULL = true; - public final static Boolean COLUMN_2_2_UNIQUE = false; - public final static Boolean COLUMN_2_2_AUTO_GENERATED = false; - public final static String COLUMN_2_2_FOREIGN_KEY = null; - public final static String COLUMN_2_2_CHECK = null; - public final static List<String> COLUMN_2_2_ENUM_VALUES = null; - - public final static Long COLUMN_2_3_ID = 8L; - public final static Integer COLUMN_2_3_ORDINALPOS = 0; - public final static Boolean COLUMN_2_3_PRIMARY = false; - public final static String COLUMN_2_3_NAME = "lng"; - public final static String COLUMN_2_3_INTERNAL_NAME = "lng"; - public final static TableColumnType COLUMN_2_3_TYPE = TableColumnType.DECIMAL; - public final static Long COLUMN_2_3_DATE_FORMAT = null; - public final static Boolean COLUMN_2_3_NULL = true; - public final static Boolean COLUMN_2_3_UNIQUE = false; - public final static Boolean COLUMN_2_3_AUTO_GENERATED = false; - public final static String COLUMN_2_3_FOREIGN_KEY = null; - public final static String COLUMN_2_3_CHECK = null; - public final static List<String> COLUMN_2_3_ENUM_VALUES = null; - - public final static Long COLUMN_4_1_ID = 9L; - public final static Integer COLUMN_4_1_ORDINALPOS = 0; - public final static Boolean COLUMN_4_1_PRIMARY = false; - public final static String COLUMN_4_1_NAME = "id"; - public final static String COLUMN_4_1_INTERNAL_NAME = "id"; - public final static TableColumnType COLUMN_4_1_TYPE = TableColumnType.NUMBER; - public final static Long COLUMN_4_1_DATE_FORMAT = null; - public final static Boolean COLUMN_4_1_NULL = false; - public final static Boolean COLUMN_4_1_UNIQUE = true; - public final static Boolean COLUMN_4_1_AUTO_GENERATED = true; - public final static String COLUMN_4_1_FOREIGN_KEY = null; - public final static String COLUMN_4_1_CHECK = null; - public final static List<String> COLUMN_4_1_ENUM_VALUES = null; - - public final static Long COLUMN_4_2_ID = 10L; - public final static Integer COLUMN_4_2_ORDINALPOS = 1; - public final static Boolean COLUMN_4_2_PRIMARY = false; - public final static String COLUMN_4_2_NAME = "Animal Name"; - public final static String COLUMN_4_2_INTERNAL_NAME = "animal_name"; - public final static TableColumnType COLUMN_4_2_TYPE = TableColumnType.STRING; - public final static Long COLUMN_4_2_DATE_FORMAT = null; - public final static Boolean COLUMN_4_2_NULL = true; - public final static Boolean COLUMN_4_2_UNIQUE = false; - public final static Boolean COLUMN_4_2_AUTO_GENERATED = false; - public final static String COLUMN_4_2_FOREIGN_KEY = null; - public final static String COLUMN_4_2_CHECK = null; - public final static List<String> COLUMN_4_2_ENUM_VALUES = null; - - public final static Long COLUMN_4_3_ID = 11L; - public final static Integer COLUMN_4_3_ORDINALPOS = 2; - public final static Boolean COLUMN_4_3_PRIMARY = false; - public final static String COLUMN_4_3_NAME = "Hair"; - public final static String COLUMN_4_3_INTERNAL_NAME = "hair"; - public final static TableColumnType COLUMN_4_3_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_3_DATE_FORMAT = null; - public final static Boolean COLUMN_4_3_NULL = true; - public final static Boolean COLUMN_4_3_UNIQUE = false; - public final static Boolean COLUMN_4_3_AUTO_GENERATED = false; - public final static String COLUMN_4_3_FOREIGN_KEY = null; - public final static String COLUMN_4_3_CHECK = null; - public final static List<String> COLUMN_4_3_ENUM_VALUES = null; - - public final static Long COLUMN_4_4_ID = 12L; - public final static Integer COLUMN_4_4_ORDINALPOS = 3; - public final static Boolean COLUMN_4_4_PRIMARY = false; - public final static String COLUMN_4_4_NAME = "Feathers"; - public final static String COLUMN_4_4_INTERNAL_NAME = "feathers"; - public final static TableColumnType COLUMN_4_4_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_4_DATE_FORMAT = null; - public final static Boolean COLUMN_4_4_NULL = true; - public final static Boolean COLUMN_4_4_UNIQUE = false; - public final static Boolean COLUMN_4_4_AUTO_GENERATED = false; - public final static String COLUMN_4_4_FOREIGN_KEY = null; - public final static String COLUMN_4_4_CHECK = null; - public final static List<String> COLUMN_4_4_ENUM_VALUES = null; - - public final static Long COLUMN_4_5_ID = 13L; - public final static Integer COLUMN_4_5_ORDINALPOS = 4; - public final static Boolean COLUMN_4_5_PRIMARY = false; - public final static String COLUMN_4_5_NAME = "Bread"; - public final static String COLUMN_4_5_INTERNAL_NAME = "bread"; - public final static TableColumnType COLUMN_4_5_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_5_DATE_FORMAT = null; - public final static Boolean COLUMN_4_5_NULL = true; - public final static Boolean COLUMN_4_5_UNIQUE = false; - public final static Boolean COLUMN_4_5_AUTO_GENERATED = false; - public final static String COLUMN_4_5_FOREIGN_KEY = null; - public final static String COLUMN_4_5_CHECK = null; - public final static List<String> COLUMN_4_5_ENUM_VALUES = null; - - public final static Long COLUMN_4_6_ID = 14L; - public final static Integer COLUMN_4_6_ORDINALPOS = 5; - public final static Boolean COLUMN_4_6_PRIMARY = false; - public final static String COLUMN_4_6_NAME = "Eggs"; - public final static String COLUMN_4_6_INTERNAL_NAME = "eggs"; - public final static TableColumnType COLUMN_4_6_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_6_DATE_FORMAT = null; - public final static Boolean COLUMN_4_6_NULL = true; - public final static Boolean COLUMN_4_6_UNIQUE = false; - public final static Boolean COLUMN_4_6_AUTO_GENERATED = false; - public final static String COLUMN_4_6_FOREIGN_KEY = null; - public final static String COLUMN_4_6_CHECK = null; - public final static List<String> COLUMN_4_6_ENUM_VALUES = null; - - public final static Long COLUMN_4_7_ID = 15L; - public final static Integer COLUMN_4_7_ORDINALPOS = 6; - public final static Boolean COLUMN_4_7_PRIMARY = false; - public final static String COLUMN_4_7_NAME = "Milk"; - public final static String COLUMN_4_7_INTERNAL_NAME = "milk"; - public final static TableColumnType COLUMN_4_7_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_7_DATE_FORMAT = null; - public final static Boolean COLUMN_4_7_NULL = true; - public final static Boolean COLUMN_4_7_UNIQUE = false; - public final static Boolean COLUMN_4_7_AUTO_GENERATED = false; - public final static String COLUMN_4_7_FOREIGN_KEY = null; - public final static String COLUMN_4_7_CHECK = null; - public final static List<String> COLUMN_4_7_ENUM_VALUES = null; - - public final static Long COLUMN_4_8_ID = 16L; - public final static Integer COLUMN_4_8_ORDINALPOS = 7; - public final static Boolean COLUMN_4_8_PRIMARY = false; - public final static String COLUMN_4_8_NAME = "Water"; - public final static String COLUMN_4_8_INTERNAL_NAME = "water"; - public final static TableColumnType COLUMN_4_8_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_8_DATE_FORMAT = null; - public final static Boolean COLUMN_4_8_NULL = true; - public final static Boolean COLUMN_4_8_UNIQUE = false; - public final static Boolean COLUMN_4_8_AUTO_GENERATED = false; - public final static String COLUMN_4_8_FOREIGN_KEY = null; - public final static String COLUMN_4_8_CHECK = null; - public final static List<String> COLUMN_4_8_ENUM_VALUES = null; - - public final static Long COLUMN_4_9_ID = 17L; - public final static Integer COLUMN_4_9_ORDINALPOS = 8; - public final static Boolean COLUMN_4_9_PRIMARY = false; - public final static String COLUMN_4_9_NAME = "Airborne"; - public final static String COLUMN_4_9_INTERNAL_NAME = "airborne"; - public final static TableColumnType COLUMN_4_9_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_9_DATE_FORMAT = null; - public final static Boolean COLUMN_4_9_NULL = true; - public final static Boolean COLUMN_4_9_UNIQUE = false; - public final static Boolean COLUMN_4_9_AUTO_GENERATED = false; - public final static String COLUMN_4_9_FOREIGN_KEY = null; - public final static String COLUMN_4_9_CHECK = null; - public final static List<String> COLUMN_4_9_ENUM_VALUES = null; - - public final static Long COLUMN_4_10_ID = 18L; - public final static Integer COLUMN_4_10_ORDINALPOS = 9; - public final static Boolean COLUMN_4_10_PRIMARY = false; - public final static String COLUMN_4_10_NAME = "Waterborne"; - public final static String COLUMN_4_10_INTERNAL_NAME = "waterborne"; - public final static TableColumnType COLUMN_4_10_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_10_DATE_FORMAT = null; - public final static Boolean COLUMN_4_10_NULL = true; - public final static Boolean COLUMN_4_10_UNIQUE = false; - public final static Boolean COLUMN_4_10_AUTO_GENERATED = false; - public final static String COLUMN_4_10_FOREIGN_KEY = null; - public final static String COLUMN_4_10_CHECK = null; - public final static List<String> COLUMN_4_10_ENUM_VALUES = null; - - public final static Long COLUMN_4_11_ID = 19L; - public final static Integer COLUMN_4_11_ORDINALPOS = 10; - public final static Boolean COLUMN_4_11_PRIMARY = false; - public final static String COLUMN_4_11_NAME = "Aquantic"; - public final static String COLUMN_4_11_INTERNAL_NAME = "aquatic"; - public final static TableColumnType COLUMN_4_11_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_11_DATE_FORMAT = null; - public final static Boolean COLUMN_4_11_NULL = true; - public final static Boolean COLUMN_4_11_UNIQUE = false; - public final static Boolean COLUMN_4_11_AUTO_GENERATED = false; - public final static String COLUMN_4_11_FOREIGN_KEY = null; - public final static String COLUMN_4_11_CHECK = null; - public final static List<String> COLUMN_4_11_ENUM_VALUES = null; - - public final static Long COLUMN_4_12_ID = 20L; - public final static Integer COLUMN_4_12_ORDINALPOS = 11; - public final static Boolean COLUMN_4_12_PRIMARY = false; - public final static String COLUMN_4_12_NAME = "Predator"; - public final static String COLUMN_4_12_INTERNAL_NAME = "predator"; - public final static TableColumnType COLUMN_4_12_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_12_DATE_FORMAT = null; - public final static Boolean COLUMN_4_12_NULL = true; - public final static Boolean COLUMN_4_12_UNIQUE = false; - public final static Boolean COLUMN_4_12_AUTO_GENERATED = false; - public final static String COLUMN_4_12_FOREIGN_KEY = null; - public final static String COLUMN_4_12_CHECK = null; - public final static List<String> COLUMN_4_12_ENUM_VALUES = null; - - public final static Long COLUMN_4_13_ID = 21L; - public final static Integer COLUMN_4_13_ORDINALPOS = 12; - public final static Boolean COLUMN_4_13_PRIMARY = false; - public final static String COLUMN_4_13_NAME = "Backbone"; - public final static String COLUMN_4_13_INTERNAL_NAME = "backbone"; - public final static TableColumnType COLUMN_4_13_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_13_DATE_FORMAT = null; - public final static Boolean COLUMN_4_13_NULL = true; - public final static Boolean COLUMN_4_13_UNIQUE = false; - public final static Boolean COLUMN_4_13_AUTO_GENERATED = false; - public final static String COLUMN_4_13_FOREIGN_KEY = null; - public final static String COLUMN_4_13_CHECK = null; - public final static List<String> COLUMN_4_13_ENUM_VALUES = null; - - public final static Long COLUMN_4_14_ID = 22L; - public final static Integer COLUMN_4_14_ORDINALPOS = 13; - public final static Boolean COLUMN_4_14_PRIMARY = false; - public final static String COLUMN_4_14_NAME = "Breathes"; - public final static String COLUMN_4_14_INTERNAL_NAME = "breathes"; - public final static TableColumnType COLUMN_4_14_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_14_DATE_FORMAT = null; - public final static Boolean COLUMN_4_14_NULL = true; - public final static Boolean COLUMN_4_14_UNIQUE = false; - public final static Boolean COLUMN_4_14_AUTO_GENERATED = false; - public final static String COLUMN_4_14_FOREIGN_KEY = null; - public final static String COLUMN_4_14_CHECK = null; - public final static List<String> COLUMN_4_14_ENUM_VALUES = null; - - public final static Long COLUMN_4_15_ID = 23L; - public final static Integer COLUMN_4_15_ORDINALPOS = 14; - public final static Boolean COLUMN_4_15_PRIMARY = false; - public final static String COLUMN_4_15_NAME = "Venomous"; - public final static String COLUMN_4_15_INTERNAL_NAME = "venomous"; - public final static TableColumnType COLUMN_4_15_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_15_DATE_FORMAT = null; - public final static Boolean COLUMN_4_15_NULL = true; - public final static Boolean COLUMN_4_15_UNIQUE = false; - public final static Boolean COLUMN_4_15_AUTO_GENERATED = false; - public final static String COLUMN_4_15_FOREIGN_KEY = null; - public final static String COLUMN_4_15_CHECK = null; - public final static List<String> COLUMN_4_15_ENUM_VALUES = null; - - public final static Long COLUMN_4_16_ID = 24L; - public final static Integer COLUMN_4_16_ORDINALPOS = 15; - public final static Boolean COLUMN_4_16_PRIMARY = false; - public final static String COLUMN_4_16_NAME = "Fin"; - public final static String COLUMN_4_16_INTERNAL_NAME = "fins"; - public final static TableColumnType COLUMN_4_16_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_16_DATE_FORMAT = null; - public final static Boolean COLUMN_4_16_NULL = true; - public final static Boolean COLUMN_4_16_UNIQUE = false; - public final static Boolean COLUMN_4_16_AUTO_GENERATED = false; - public final static String COLUMN_4_16_FOREIGN_KEY = null; - public final static String COLUMN_4_16_CHECK = null; - public final static List<String> COLUMN_4_16_ENUM_VALUES = null; - - public final static Long COLUMN_4_17_ID = 25L; - public final static Integer COLUMN_4_17_ORDINALPOS = 16; - public final static Boolean COLUMN_4_17_PRIMARY = false; - public final static String COLUMN_4_17_NAME = "Legs"; - public final static String COLUMN_4_17_INTERNAL_NAME = "legs"; - public final static TableColumnType COLUMN_4_17_TYPE = TableColumnType.NUMBER; - public final static Long COLUMN_4_17_DATE_FORMAT = null; - public final static Boolean COLUMN_4_17_NULL = true; - public final static Boolean COLUMN_4_17_UNIQUE = false; - public final static Boolean COLUMN_4_17_AUTO_GENERATED = false; - public final static String COLUMN_4_17_FOREIGN_KEY = null; - public final static String COLUMN_4_17_CHECK = null; - public final static List<String> COLUMN_4_17_ENUM_VALUES = null; - - public final static Long COLUMN_4_18_ID = 26L; - public final static Integer COLUMN_4_18_ORDINALPOS = 17; - public final static Boolean COLUMN_4_18_PRIMARY = false; - public final static String COLUMN_4_18_NAME = "Tail"; - public final static String COLUMN_4_18_INTERNAL_NAME = "tail"; - public final static TableColumnType COLUMN_4_18_TYPE = TableColumnType.DECIMAL; - public final static Long COLUMN_4_18_DATE_FORMAT = null; - public final static Boolean COLUMN_4_18_NULL = true; - public final static Boolean COLUMN_4_18_UNIQUE = false; - public final static Boolean COLUMN_4_18_AUTO_GENERATED = false; - public final static String COLUMN_4_18_FOREIGN_KEY = null; - public final static String COLUMN_4_18_CHECK = null; - public final static List<String> COLUMN_4_18_ENUM_VALUES = null; - - public final static Long COLUMN_4_19_ID = 27L; - public final static Integer COLUMN_4_19_ORDINALPOS = 18; - public final static Boolean COLUMN_4_19_PRIMARY = false; - public final static String COLUMN_4_19_NAME = "Domestic"; - public final static String COLUMN_4_19_INTERNAL_NAME = "domestic"; - public final static TableColumnType COLUMN_4_19_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_19_DATE_FORMAT = null; - public final static Boolean COLUMN_4_19_NULL = true; - public final static Boolean COLUMN_4_19_UNIQUE = false; - public final static Boolean COLUMN_4_19_AUTO_GENERATED = false; - public final static String COLUMN_4_19_FOREIGN_KEY = null; - public final static String COLUMN_4_19_CHECK = null; - public final static List<String> COLUMN_4_19_ENUM_VALUES = null; - - public final static Long COLUMN_4_20_ID = 28L; - public final static Integer COLUMN_4_20_ORDINALPOS = 19; - public final static Boolean COLUMN_4_20_PRIMARY = false; - public final static String COLUMN_4_20_NAME = "Cat Size"; - public final static String COLUMN_4_20_INTERNAL_NAME = "catsize"; - public final static TableColumnType COLUMN_4_20_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_20_DATE_FORMAT = null; - public final static Boolean COLUMN_4_20_NULL = true; - public final static Boolean COLUMN_4_20_UNIQUE = false; - public final static Boolean COLUMN_4_20_AUTO_GENERATED = false; - public final static String COLUMN_4_20_FOREIGN_KEY = null; - public final static String COLUMN_4_20_CHECK = null; - public final static List<String> COLUMN_4_20_ENUM_VALUES = null; - - public final static Long COLUMN_4_21_ID = 29L; - public final static Integer COLUMN_4_21_ORDINALPOS = 20; - public final static Boolean COLUMN_4_21_PRIMARY = false; - public final static String COLUMN_4_21_NAME = "Class Type"; - public final static String COLUMN_4_21_INTERNAL_NAME = "class_type"; - public final static TableColumnType COLUMN_4_21_TYPE = TableColumnType.DECIMAL; - public final static Long COLUMN_4_21_DATE_FORMAT = null; - public final static Boolean COLUMN_4_21_NULL = true; - public final static Boolean COLUMN_4_21_UNIQUE = false; - public final static Boolean COLUMN_4_21_AUTO_GENERATED = false; - public final static String COLUMN_4_21_FOREIGN_KEY = null; - public final static String COLUMN_4_21_CHECK = null; - public final static List<String> COLUMN_4_21_ENUM_VALUES = null; - - public final static Long COLUMN_5_1_ID = 23L; - public final static Integer COLUMN_5_1_ORDINALPOS = 0; - public final static Boolean COLUMN_5_1_PRIMARY = true; - public final static String COLUMN_5_1_NAME = "id"; - public final static String COLUMN_5_1_INTERNAL_NAME = "id"; - public final static TableColumnType COLUMN_5_1_TYPE = TableColumnType.NUMBER; - public final static Long COLUMN_5_1_DATE_FORMAT = null; - public final static Boolean COLUMN_5_1_NULL = false; - public final static Boolean COLUMN_5_1_UNIQUE = true; - public final static Boolean COLUMN_5_1_AUTO_GENERATED = true; - public final static String COLUMN_5_1_FOREIGN_KEY = null; - public final static String COLUMN_5_1_CHECK = null; - public final static List<String> COLUMN_5_1_ENUM_VALUES = null; - - public final static Long COLUMN_5_2_ID = 24L; - public final static Integer COLUMN_5_2_ORDINALPOS = 1; - public final static Boolean COLUMN_5_2_PRIMARY = false; - public final static String COLUMN_5_2_NAME = "firstname"; - public final static String COLUMN_5_2_INTERNAL_NAME = "firstname"; - public final static TableColumnType COLUMN_5_2_TYPE = TableColumnType.STRING; - public final static Long COLUMN_5_2_DATE_FORMAT = null; - public final static Boolean COLUMN_5_2_NULL = false; - public final static Boolean COLUMN_5_2_UNIQUE = false; - public final static Boolean COLUMN_5_2_AUTO_GENERATED = false; - public final static String COLUMN_5_2_FOREIGN_KEY = null; - public final static String COLUMN_5_2_CHECK = null; - public final static List<String> COLUMN_5_2_ENUM_VALUES = null; - - public final static Long COLUMN_5_3_ID = 25L; - public final static Integer COLUMN_5_3_ORDINALPOS = 2; - public final static Boolean COLUMN_5_3_PRIMARY = false; - public final static String COLUMN_5_3_NAME = "lastname"; - public final static String COLUMN_5_3_INTERNAL_NAME = "lastname"; - public final static TableColumnType COLUMN_5_3_TYPE = TableColumnType.STRING; - public final static Long COLUMN_5_3_DATE_FORMAT = null; - public final static Boolean COLUMN_5_3_NULL = false; - public final static Boolean COLUMN_5_3_UNIQUE = false; - public final static Boolean COLUMN_5_3_AUTO_GENERATED = false; - public final static String COLUMN_5_3_FOREIGN_KEY = null; - public final static String COLUMN_5_3_CHECK = null; - public final static List<String> COLUMN_5_3_ENUM_VALUES = null; - - public final static List<String> CONSTRAINTS_1_UNIQUE_1 = List.of(COLUMN_1_1_NAME); - public final static List<String> CONSTRAINTS_2_UNIQUE_1 = List.of(COLUMN_2_1_NAME); - public final static List<String> CONSTRAINTS_3_UNIQUE_1 = List.of("id"); - public final static List<String> CONSTRAINTS_4_UNIQUE_1 = List.of(COLUMN_4_1_NAME); - public final static List<String> CONSTRAINTS_5_UNIQUE_1 = List.of(COLUMN_5_1_NAME); - - public final static Long CONCEPT_1_ID = 1L; - public final static String CONCEPT_1_NAME = "Temperature"; - public final static Instant CONCEPT_1_CREATED = Instant.now().minus(1, HOURS); - - public final static TableColumnConcept CONCEPT_1 = TableColumnConcept.builder() - .name(CONCEPT_1_NAME) - .created(CONCEPT_1_CREATED) - .uri("http://www.ontology-of-units-of-measure.org/resource/om-2/") - .build(); - - public final static Long QUERY_1_ID = 1L; - public final static String QUERY_1_STATEMENT = "SELECT `id`, `date`, `location`, `mintemp`, `rainfall` FROM " + - "`weather_aus`"; - public final static String QUERY_1_DOI = "1111/1"; - public final static Long QUERY_1_CONTAINER_ID = CONTAINER_1_ID; - public final static Long QUERY_1_DATABASE_ID = DATABASE_1_ID; - public final static Long QUERY_1_RESULT_NUMBER = 2L; - public final static String QUERY_1_QUERY_HASH = "a3b8ac39e38167d14cf3a9c20a69e4b6954d049525390b973a2c23064953a992"; - public final static String QUERY_1_RESULT_HASH = "8358c8ade4849d2094ab5bb29127afdae57e6bb5acb1db7af603813d406c467a"; - public final static Instant QUERY_1_CREATED = Instant.ofEpochSecond(1677648377); - public final static Instant QUERY_1_EXECUTION = Instant.now(); - public final static Boolean QUERY_1_PERSISTED = false; - - public final static Query QUERY_1 = Query.builder() - .id(QUERY_1_ID) - .query(QUERY_1_STATEMENT) - .queryHash(QUERY_1_QUERY_HASH) - .resultHash(QUERY_1_RESULT_HASH) - .resultNumber(QUERY_1_RESULT_NUMBER) - .created(QUERY_1_CREATED) - .createdBy(USER_1_USERNAME) - .isPersisted(QUERY_1_PERSISTED) - .executed(QUERY_1_EXECUTION) - .created(QUERY_1_CREATED) - .build(); - - public final static QueryDto QUERY_1_DTO = QueryDto.builder() - .id(QUERY_1_ID) - .cid(QUERY_1_CONTAINER_ID) - .dbid(QUERY_1_DATABASE_ID) - .query(QUERY_1_STATEMENT) - .queryHash(QUERY_1_QUERY_HASH) - .resultHash(QUERY_1_RESULT_HASH) - .created(QUERY_1_CREATED) - .execution(QUERY_1_EXECUTION) - .createdBy(USER_1_ID) - .creator(USER_1_DTO) - .build(); - - public final static QueryBriefDto QUERY_1_BRIEF_DTO = QueryBriefDto.builder() - .id(QUERY_1_ID) - .cid(QUERY_1_CONTAINER_ID) - .dbid(QUERY_1_DATABASE_ID) - .query(QUERY_1_STATEMENT) - .queryHash(QUERY_1_QUERY_HASH) - .resultHash(QUERY_1_RESULT_HASH) - .created(QUERY_1_CREATED) - .execution(QUERY_1_EXECUTION) - .createdBy(USER_1_ID) - .creator(USER_1_DTO) - .build(); - - public final static Long QUERY_2_ID = 2L; - public final static String QUERY_2_STATEMENT = "SELECT `location` FROM `weather_aus`"; - public final static String QUERY_2_QUERY_HASH = "a2d2dd94ebc7653bb5a3b55dd8ed5e91d3d13c225c6855a1eb4eb7ca14c36ced"; - public final static Long QUERY_2_CONTAINER_ID = CONTAINER_2_ID; - public final static Long QUERY_2_DATABASE_ID = DATABASE_2_ID; - public final static Long QUERY_2_RESULT_NUMBER = 2L; - public final static String QUERY_2_RESULT_HASH = "ff3f7cbe1b96d296957f6e39e55b8b1b577fa3d205d4795af99594cfd20cb80d"; - public final static Instant QUERY_2_CREATED = Instant.now().minus(2, MINUTES); - public final static Instant QUERY_2_EXECUTION = Instant.now().minus(1, MINUTES); - public final static Boolean QUERY_2_PERSISTED = true; - - public final static Query QUERY_2 = Query.builder() - .id(QUERY_2_ID) - .query(QUERY_2_STATEMENT) - .queryHash(QUERY_2_QUERY_HASH) - .resultHash(QUERY_2_RESULT_HASH) - .resultNumber(QUERY_2_RESULT_NUMBER) - .created(QUERY_2_CREATED) - .createdBy(USER_1_USERNAME) - .isPersisted(QUERY_2_PERSISTED) - .created(QUERY_2_CREATED) - .executed(QUERY_2_EXECUTION) - .build(); - - public final static List<TableColumn> TABLE_2_COLUMNS = List.of(TableColumn.builder() - .id(COLUMN_2_1_ID) - .ordinalPosition(COLUMN_2_1_ORDINALPOS) - .cdbid(DATABASE_1_ID) - .tid(TABLE_2_ID) - .name(COLUMN_2_1_NAME) - .internalName(COLUMN_2_1_INTERNAL_NAME) - .columnType(COLUMN_2_1_TYPE) - .dfid(COLUMN_2_1_DATE_FORMAT) - .isNullAllowed(COLUMN_2_1_NULL) - .autoGenerated(COLUMN_2_1_AUTO_GENERATED) - .isPrimaryKey(COLUMN_2_1_PRIMARY) - .enumValues(COLUMN_2_1_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_2_2_ID) - .ordinalPosition(COLUMN_2_2_ORDINALPOS) - .cdbid(DATABASE_1_ID) - .tid(TABLE_2_ID) - .name(COLUMN_2_2_NAME) - .internalName(COLUMN_2_2_INTERNAL_NAME) - .columnType(COLUMN_2_2_TYPE) - .dfid(COLUMN_2_2_DATE_FORMAT) - .isNullAllowed(COLUMN_2_2_NULL) - .autoGenerated(COLUMN_2_2_AUTO_GENERATED) - .isPrimaryKey(COLUMN_2_2_PRIMARY) - .enumValues(COLUMN_2_2_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_2_3_ID) - .ordinalPosition(COLUMN_2_3_ORDINALPOS) - .cdbid(DATABASE_1_ID) - .tid(TABLE_2_ID) - .name(COLUMN_2_3_NAME) - .internalName(COLUMN_2_3_INTERNAL_NAME) - .columnType(COLUMN_2_3_TYPE) - .dfid(COLUMN_2_3_DATE_FORMAT) - .isNullAllowed(COLUMN_2_3_NULL) - .autoGenerated(COLUMN_2_3_AUTO_GENERATED) - .isPrimaryKey(COLUMN_2_3_PRIMARY) - .enumValues(COLUMN_2_3_ENUM_VALUES) - .build()); - - public final static Constraints TABLE_2_CONSTRAINTS = Constraints.builder() - .uniques(List.of(Unique.builder().columns(List.of(TABLE_2_COLUMNS.get(0))).build())) - .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_1_ID) - .queueName(TABLE_2_QUEUE_NAME) - .routingKey(TABLE_2_ROUTING_KEY) - .columns(TABLE_2_COLUMNS) - .constraints(TABLE_2_CONSTRAINTS) - .creator(USER_1) - .build(); - - public final static Table TABLE_2_NOCOLS = 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_1_ID) - .queueName(TABLE_2_QUEUE_NAME) - .routingKey(TABLE_2_ROUTING_KEY) - .columns(List.of()) - .creator(USER_1) - .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) - .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) - .dateFormat(IMAGE_DATE_1) - .isNullAllowed(COLUMN_1_2_NULL) - .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) - .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) - .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) - .autoGenerated(COLUMN_1_5_AUTO_GENERATED) - .isPrimaryKey(COLUMN_1_5_PRIMARY) - .enumValues(COLUMN_1_5_ENUM_VALUES) - .build()); - - public final static Constraints TABLE_1_CONSTRAINTS = Constraints.builder() - .foreignKeys(List.of(ForeignKey.builder() - .referencedTable(TABLE_2) - .references(List.of( - ForeignKeyReference.builder().column(TABLE_1_COLUMNS.get(2)).referencedColumn(TABLE_1_COLUMNS.get(0)).build()) - ).build() - )) - .uniques(List.of(Unique.builder().columns(List.of(TABLE_1_COLUMNS.get(1))).build())) - .checks(Set.of("`mintemp` > 0")) - .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) - .tdbid(DATABASE_1_ID) - .queueName(TABLE_1_QUEUE_NAME) - .routingKey(TABLE_1_ROUTING_KEY) - .columns(TABLE_1_COLUMNS) - .constraints(TABLE_1_CONSTRAINTS) - .creator(USER_1) - .build(); - - public final static Table TABLE_1_NOCOLS = 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) - .tdbid(DATABASE_1_ID) - .queueName(TABLE_1_QUEUE_NAME) - .routingKey(TABLE_1_ROUTING_KEY) - .columns(List.of()) - .creator(USER_1) - .build(); - - public final static List<TableColumn> TABLE_3_COLUMNS = List.of(TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(0) - .autoGenerated(true) - .columnType(TableColumnType.NUMBER) - .name("id") - .internalName("id") - .isNullAllowed(false) - .isPrimaryKey(true) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(1) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("linie") - .internalName("linie") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(2) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("richtung") - .internalName("richtung") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(3) - .autoGenerated(false) - .columnType(TableColumnType.DATE) - .name("betriebsdatum") - .internalName("betriebsdatum") - .isNullAllowed(true) - .isPrimaryKey(false) - .dfid(IMAGE_DATE_2_ID) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(4) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("fahrzeug") - .internalName("fahrzeug") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(5) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("kurs") - .internalName("kurs") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(6) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("seq_von") - .internalName("seq_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(7) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("halt_diva_von") - .internalName("halt_diva_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(8) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("halt_punkt_diva_von") - .internalName("halt_punkt_diva_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(9) - .autoGenerated(false) - .columnType(TableColumnType.STRING) - .name("halt_kurz_von1") - .internalName("halt_kurz_von1") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(10) - .autoGenerated(false) - .columnType(TableColumnType.DATE) - .name("datum_von") - .internalName("datum_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dfid(IMAGE_DATE_2_ID) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(11) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("soll_an_von") - .internalName("soll_an_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(12) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("ist_an_von") - .internalName("ist_an_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(13) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("soll_ab_von") - .internalName("soll_ab_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(14) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("ist_ab_von") - .internalName("ist_ab_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(15) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("seq_nach") - .internalName("seq_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(16) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("halt_diva_nach") - .internalName("halt_diva_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(17) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("halt_punkt_diva_nach") - .internalName("halt_punkt_diva_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(18) - .autoGenerated(false) - .columnType(TableColumnType.STRING) - .name("halt_kurz_nach1") - .internalName("halt_kurz_nach1") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(19) - .autoGenerated(false) - .columnType(TableColumnType.DATE) - .name("datum_nach") - .internalName("datum_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dfid(IMAGE_DATE_2_ID) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(20) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("soll_an_nach") - .internalName("soll_an_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(21) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("ist_an_nach1") - .internalName("ist_an_nach1") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(22) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("soll_ab_nach") - .internalName("soll_ab_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(23) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("ist_ab_nach") - .internalName("ist_ab_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(24) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("fahrt_id") - .internalName("fahrt_id") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(25) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("fahrweg_id") - .internalName("fahrweg_id") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(26) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("fw_no") - .internalName("fw_no") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(27) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("fw_typ") - .internalName("fw_typ") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(28) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("fw_kurz") - .internalName("fw_kurz") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(29) - .autoGenerated(false) - .columnType(TableColumnType.STRING) - .name("fw_lang") - .internalName("fw_lang") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(30) - .autoGenerated(false) - .columnType(TableColumnType.STRING) - .name("umlauf_von") - .internalName("umlauf_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(31) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("halt_id_von") - .internalName("halt_id_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(32) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("halt_id_nach") - .internalName("halt_id_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(33) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("halt_punkt_id_von") - .internalName("halt_punkt_id_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_1_ID) - .ordinalPosition(34) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("halt_punkt_id_nach") - .internalName("halt_punkt_id_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build()); - - public final static Constraints TABLE_3_CONSTRAINTS = Constraints.builder() - .uniques(List.of(Unique.builder().columns(List.of(TABLE_3_COLUMNS.get(0))).build())) - .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_1_ID) - .queueName(TABLE_3_QUEUE_NAME) - .routingKey(TABLE_3_ROUTING_KEY) - .columns(TABLE_3_COLUMNS) - .constraints(TABLE_3_CONSTRAINTS) - .creator(USER_1) - .build(); - - public final static Table TABLE_3_NOCOLS = 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_1_ID) - .queueName(TABLE_3_QUEUE_NAME) - .routingKey(TABLE_3_ROUTING_KEY) - .columns(List.of()) - .creator(USER_1) - .build(); - - public final static List<TableColumn> TABLE_4_COLUMNS = List.of(TableColumn.builder() - .id(COLUMN_4_1_ID) - .ordinalPosition(COLUMN_4_1_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_1_NAME) - .internalName(COLUMN_4_1_INTERNAL_NAME) - .columnType(COLUMN_4_1_TYPE) - .dfid(COLUMN_4_1_DATE_FORMAT) - .isNullAllowed(COLUMN_4_1_NULL) - .autoGenerated(COLUMN_4_1_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_1_PRIMARY) - .enumValues(COLUMN_4_1_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_2_ID) - .ordinalPosition(COLUMN_4_2_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_2_NAME) - .internalName(COLUMN_4_2_INTERNAL_NAME) - .columnType(COLUMN_4_2_TYPE) - .dfid(COLUMN_4_2_DATE_FORMAT) - .isNullAllowed(COLUMN_4_2_NULL) - .autoGenerated(COLUMN_4_2_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_2_PRIMARY) - .enumValues(COLUMN_4_2_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_3_ID) - .ordinalPosition(COLUMN_4_3_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_3_NAME) - .internalName(COLUMN_4_3_INTERNAL_NAME) - .columnType(COLUMN_4_3_TYPE) - .dfid(COLUMN_4_3_DATE_FORMAT) - .isNullAllowed(COLUMN_4_3_NULL) - .autoGenerated(COLUMN_4_3_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_3_PRIMARY) - .enumValues(COLUMN_4_3_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_4_ID) - .ordinalPosition(COLUMN_4_4_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_4_NAME) - .internalName(COLUMN_4_4_INTERNAL_NAME) - .columnType(COLUMN_4_4_TYPE) - .dfid(COLUMN_4_4_DATE_FORMAT) - .isNullAllowed(COLUMN_4_4_NULL) - .autoGenerated(COLUMN_4_4_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_4_PRIMARY) - .enumValues(COLUMN_4_4_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_5_ID) - .ordinalPosition(COLUMN_4_5_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_5_NAME) - .internalName(COLUMN_4_5_INTERNAL_NAME) - .columnType(COLUMN_4_5_TYPE) - .dfid(COLUMN_4_5_DATE_FORMAT) - .isNullAllowed(COLUMN_4_5_NULL) - .autoGenerated(COLUMN_4_5_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_5_PRIMARY) - .enumValues(COLUMN_4_5_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_6_ID) - .ordinalPosition(COLUMN_4_6_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_6_NAME) - .internalName(COLUMN_4_6_INTERNAL_NAME) - .columnType(COLUMN_4_6_TYPE) - .dfid(COLUMN_4_6_DATE_FORMAT) - .isNullAllowed(COLUMN_4_6_NULL) - .autoGenerated(COLUMN_4_6_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_6_PRIMARY) - .enumValues(COLUMN_4_6_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_7_ID) - .ordinalPosition(COLUMN_4_7_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_7_NAME) - .internalName(COLUMN_4_7_INTERNAL_NAME) - .columnType(COLUMN_4_7_TYPE) - .dfid(COLUMN_4_7_DATE_FORMAT) - .isNullAllowed(COLUMN_4_7_NULL) - .autoGenerated(COLUMN_4_7_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_7_PRIMARY) - .enumValues(COLUMN_4_7_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_8_ID) - .ordinalPosition(COLUMN_4_8_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_8_NAME) - .internalName(COLUMN_4_8_INTERNAL_NAME) - .columnType(COLUMN_4_8_TYPE) - .dfid(COLUMN_4_8_DATE_FORMAT) - .isNullAllowed(COLUMN_4_8_NULL) - .autoGenerated(COLUMN_4_8_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_8_PRIMARY) - .enumValues(COLUMN_4_8_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_9_ID) - .ordinalPosition(COLUMN_4_9_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_9_NAME) - .internalName(COLUMN_4_9_INTERNAL_NAME) - .columnType(COLUMN_4_9_TYPE) - .dfid(COLUMN_4_9_DATE_FORMAT) - .isNullAllowed(COLUMN_4_9_NULL) - .autoGenerated(COLUMN_4_9_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_9_PRIMARY) - .enumValues(COLUMN_4_9_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_10_ID) - .ordinalPosition(COLUMN_4_10_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_10_NAME) - .internalName(COLUMN_4_10_INTERNAL_NAME) - .columnType(COLUMN_4_10_TYPE) - .dfid(COLUMN_4_10_DATE_FORMAT) - .isNullAllowed(COLUMN_4_10_NULL) - .autoGenerated(COLUMN_4_10_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_10_PRIMARY) - .enumValues(COLUMN_4_10_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_11_ID) - .ordinalPosition(COLUMN_4_11_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_11_NAME) - .internalName(COLUMN_4_11_INTERNAL_NAME) - .columnType(COLUMN_4_11_TYPE) - .dfid(COLUMN_4_11_DATE_FORMAT) - .isNullAllowed(COLUMN_4_11_NULL) - .autoGenerated(COLUMN_4_11_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_11_PRIMARY) - .enumValues(COLUMN_4_11_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_12_ID) - .ordinalPosition(COLUMN_4_12_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_12_NAME) - .internalName(COLUMN_4_12_INTERNAL_NAME) - .columnType(COLUMN_4_12_TYPE) - .dfid(COLUMN_4_12_DATE_FORMAT) - .isNullAllowed(COLUMN_4_12_NULL) - .autoGenerated(COLUMN_4_12_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_12_PRIMARY) - .enumValues(COLUMN_4_12_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_13_ID) - .ordinalPosition(COLUMN_4_13_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_13_NAME) - .internalName(COLUMN_4_13_INTERNAL_NAME) - .columnType(COLUMN_4_13_TYPE) - .dfid(COLUMN_4_13_DATE_FORMAT) - .isNullAllowed(COLUMN_4_13_NULL) - .autoGenerated(COLUMN_4_13_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_13_PRIMARY) - .enumValues(COLUMN_4_13_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_14_ID) - .ordinalPosition(COLUMN_4_14_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_14_NAME) - .internalName(COLUMN_4_14_INTERNAL_NAME) - .columnType(COLUMN_4_14_TYPE) - .dfid(COLUMN_4_14_DATE_FORMAT) - .isNullAllowed(COLUMN_4_14_NULL) - .autoGenerated(COLUMN_4_14_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_14_PRIMARY) - .enumValues(COLUMN_4_14_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_15_ID) - .ordinalPosition(COLUMN_4_15_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_15_NAME) - .internalName(COLUMN_4_15_INTERNAL_NAME) - .columnType(COLUMN_4_15_TYPE) - .dfid(COLUMN_4_15_DATE_FORMAT) - .isNullAllowed(COLUMN_4_15_NULL) - .autoGenerated(COLUMN_4_15_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_15_PRIMARY) - .enumValues(COLUMN_4_15_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_16_ID) - .ordinalPosition(COLUMN_4_16_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_16_NAME) - .internalName(COLUMN_4_16_INTERNAL_NAME) - .columnType(COLUMN_4_16_TYPE) - .dfid(COLUMN_4_16_DATE_FORMAT) - .isNullAllowed(COLUMN_4_16_NULL) - .autoGenerated(COLUMN_4_16_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_16_PRIMARY) - .enumValues(COLUMN_4_16_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_17_ID) - .ordinalPosition(COLUMN_4_17_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_17_NAME) - .internalName(COLUMN_4_17_INTERNAL_NAME) - .columnType(COLUMN_4_17_TYPE) - .dfid(COLUMN_4_17_DATE_FORMAT) - .isNullAllowed(COLUMN_4_17_NULL) - .autoGenerated(COLUMN_4_17_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_17_PRIMARY) - .enumValues(COLUMN_4_17_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_18_ID) - .ordinalPosition(COLUMN_4_18_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_18_NAME) - .internalName(COLUMN_4_18_INTERNAL_NAME) - .columnType(COLUMN_4_18_TYPE) - .dfid(COLUMN_4_18_DATE_FORMAT) - .isNullAllowed(COLUMN_4_18_NULL) - .autoGenerated(COLUMN_4_18_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_18_PRIMARY) - .enumValues(COLUMN_4_18_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_19_ID) - .ordinalPosition(COLUMN_4_19_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_19_NAME) - .internalName(COLUMN_4_19_INTERNAL_NAME) - .columnType(COLUMN_4_19_TYPE) - .dfid(COLUMN_4_19_DATE_FORMAT) - .isNullAllowed(COLUMN_4_19_NULL) - .autoGenerated(COLUMN_4_19_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_19_PRIMARY) - .enumValues(COLUMN_4_19_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_20_ID) - .ordinalPosition(COLUMN_4_20_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_20_NAME) - .internalName(COLUMN_4_20_INTERNAL_NAME) - .columnType(COLUMN_4_20_TYPE) - .dfid(COLUMN_4_20_DATE_FORMAT) - .isNullAllowed(COLUMN_4_20_NULL) - .autoGenerated(COLUMN_4_20_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_20_PRIMARY) - .enumValues(COLUMN_4_20_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_21_ID) - .ordinalPosition(COLUMN_4_21_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_21_NAME) - .internalName(COLUMN_4_21_INTERNAL_NAME) - .columnType(COLUMN_4_21_TYPE) - .dfid(COLUMN_4_21_DATE_FORMAT) - .isNullAllowed(COLUMN_4_21_NULL) - .autoGenerated(COLUMN_4_21_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_21_PRIMARY) - .enumValues(COLUMN_4_21_ENUM_VALUES) - .build()); - - public final static Constraints TABLE_4_CONSTRAINTS = Constraints.builder() - .uniques(List.of(Unique.builder().columns(List.of(TABLE_4_COLUMNS.get(0))).build())) - .build(); - - public final static Table TABLE_4 = Table.builder() - .id(TABLE_4_ID) - .created(Instant.now()) - .internalName(TABLE_4_INTERNALNAME) - .description(TABLE_4_DESCRIPTION) - .name(TABLE_4_NAME) - .lastModified(TABLE_4_LAST_MODIFIED) - .tdbid(DATABASE_2_ID) - .queueName(TABLE_4_QUEUE_NAME) - .routingKey(TABLE_4_ROUTING_KEY) - .columns(TABLE_4_COLUMNS) - .constraints(TABLE_4_CONSTRAINTS) - .creator(USER_1) - .build(); - - public final static Table TABLE_4_NOCOLS = Table.builder() - .id(TABLE_4_ID) - .created(Instant.now()) - .internalName(TABLE_4_INTERNALNAME) - .description(TABLE_4_DESCRIPTION) - .name(TABLE_4_NAME) - .lastModified(TABLE_4_LAST_MODIFIED) - .tdbid(DATABASE_1_ID) - .queueName(TABLE_4_QUEUE_NAME) - .routingKey(TABLE_4_ROUTING_KEY) - .columns(List.of()) - .creator(USER_1) - .build(); - - public final static List<TableColumn> TABLE_5_COLUMNS = List.of(TableColumn.builder() - .id(COLUMN_5_1_ID) - .ordinalPosition(COLUMN_5_1_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_5_ID) - .name(COLUMN_5_1_NAME) - .internalName(COLUMN_5_1_INTERNAL_NAME) - .columnType(COLUMN_5_1_TYPE) - .dfid(COLUMN_5_1_DATE_FORMAT) - .isNullAllowed(COLUMN_5_1_NULL) - .autoGenerated(COLUMN_5_1_AUTO_GENERATED) - .isPrimaryKey(COLUMN_5_1_PRIMARY) - .enumValues(COLUMN_5_1_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_5_2_ID) - .ordinalPosition(COLUMN_5_2_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_5_ID) - .name(COLUMN_5_2_NAME) - .internalName(COLUMN_5_2_INTERNAL_NAME) - .columnType(COLUMN_5_2_TYPE) - .dfid(COLUMN_5_2_DATE_FORMAT) - .isNullAllowed(COLUMN_5_2_NULL) - .autoGenerated(COLUMN_5_2_AUTO_GENERATED) - .isPrimaryKey(COLUMN_5_2_PRIMARY) - .enumValues(COLUMN_5_2_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_5_3_ID) - .ordinalPosition(COLUMN_5_3_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_5_ID) - .name(COLUMN_5_3_NAME) - .internalName(COLUMN_5_3_INTERNAL_NAME) - .columnType(COLUMN_5_3_TYPE) - .dfid(COLUMN_5_3_DATE_FORMAT) - .isNullAllowed(COLUMN_5_3_NULL) - .autoGenerated(COLUMN_5_3_AUTO_GENERATED) - .isPrimaryKey(COLUMN_5_3_PRIMARY) - .enumValues(COLUMN_5_3_ENUM_VALUES) - .build()); - - public final static Constraints TABLE_5_CONSTRAINTS = Constraints.builder() - .uniques(List.of(Unique.builder().columns(List.of(TABLE_5_COLUMNS.get(0))).build())) - .build(); - - public final static Table TABLE_5 = Table.builder() - .id(TABLE_5_ID) - .created(Instant.now()) - .internalName(TABLE_5_INTERNALNAME) - .description(TABLE_5_DESCRIPTION) - .name(TABLE_5_NAME) - .lastModified(TABLE_5_LAST_MODIFIED) - .tdbid(DATABASE_2_ID) - .queueName(TABLE_5_QUEUE_NAME) - .routingKey(TABLE_5_ROUTING_KEY) - .columns(TABLE_5_COLUMNS) - .constraints(TABLE_5_CONSTRAINTS) - .creator(USER_1) - .build(); - - public final static Long COLUMN_6_1_ID = 26L; - public final static Integer COLUMN_6_1_ORDINALPOS = 0; - public final static Boolean COLUMN_6_1_PRIMARY = true; - public final static String COLUMN_6_1_NAME = "name_id"; - public final static String COLUMN_6_1_INTERNAL_NAME = "name_id"; - public final static TableColumnType COLUMN_6_1_TYPE = TableColumnType.NUMBER; - public final static Long COLUMN_6_1_DATE_FORMAT = null; - public final static Boolean COLUMN_6_1_NULL = false; - public final static Boolean COLUMN_6_1_UNIQUE = false; - public final static Boolean COLUMN_6_1_AUTO_GENERATED = false; - public final static String COLUMN_6_1_FOREIGN_KEY = null; - public final static String COLUMN_6_1_CHECK = null; - public final static List<String> COLUMN_6_1_ENUM_VALUES = null; - - public final static Long COLUMN_6_2_ID = 27L; - public final static Integer COLUMN_6_2_ORDINALPOS = 1; - public final static Boolean COLUMN_6_2_PRIMARY = true; - public final static String COLUMN_6_2_NAME = "zoo_id"; - public final static String COLUMN_6_2_INTERNAL_NAME = "zoo_id"; - public final static TableColumnType COLUMN_6_2_TYPE = TableColumnType.NUMBER; - public final static Long COLUMN_6_2_DATE_FORMAT = null; - public final static Boolean COLUMN_6_2_NULL = false; - public final static Boolean COLUMN_6_2_UNIQUE = false; - public final static Boolean COLUMN_6_2_AUTO_GENERATED = false; - public final static String COLUMN_6_2_FOREIGN_KEY = null; - public final static String COLUMN_6_2_CHECK = null; - public final static List<String> COLUMN_6_2_ENUM_VALUES = null; - - public final static List<TableColumn> TABLE_6_COLUMNS = List.of(TableColumn.builder() - .id(COLUMN_6_1_ID) - .ordinalPosition(COLUMN_6_1_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_6_ID) - .name(COLUMN_6_1_NAME) - .internalName(COLUMN_6_1_INTERNAL_NAME) - .columnType(COLUMN_6_1_TYPE) - .dfid(COLUMN_6_1_DATE_FORMAT) - .isNullAllowed(COLUMN_6_1_NULL) - .autoGenerated(COLUMN_6_1_AUTO_GENERATED) - .isPrimaryKey(COLUMN_6_1_PRIMARY) - .enumValues(COLUMN_6_1_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_6_2_ID) - .ordinalPosition(COLUMN_6_2_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_6_ID) - .name(COLUMN_6_2_NAME) - .internalName(COLUMN_6_2_INTERNAL_NAME) - .columnType(COLUMN_6_2_TYPE) - .dfid(COLUMN_6_2_DATE_FORMAT) - .isNullAllowed(COLUMN_6_2_NULL) - .autoGenerated(COLUMN_6_2_AUTO_GENERATED) - .isPrimaryKey(COLUMN_6_2_PRIMARY) - .enumValues(COLUMN_6_2_ENUM_VALUES) - .build()); - - public final static Table TABLE_6 = Table.builder() - .id(TABLE_6_ID) - .created(Instant.now()) - .internalName(TABLE_6_INTERNAL_NAME) - .description(TABLE_6_DESCRIPTION) - .name(TABLE_6_NAME) - .lastModified(TABLE_6_LAST_MODIFIED) - .tdbid(DATABASE_2_ID) - .queueName(TABLE_6_QUEUE_NAME) - .routingKey(TABLE_6_ROUTING_KEY) - .columns(TABLE_6_COLUMNS) - .creator(USER_1) - .build(); - - public final static Table TABLE_7_NOCOLS = Table.builder() - .id(TABLE_7_ID) - .created(Instant.now()) - .internalName(TABLE_7_INTERNAL_NAME) - .description(TABLE_7_DESCRIPTION) - .name(TABLE_7_NAME) - .lastModified(TABLE_7_LAST_MODIFIED) - .tdbid(DATABASE_1_ID) - .queueName(TABLE_7_QUEUE_NAME) - .routingKey(TABLE_7_ROUTING_KEY) - .columns(List.of()) - .creator(USER_1) - .build(); - - public final static Long VIEW_1_ID = 1L; - public final static Boolean VIEW_1_INITIAL_VIEW = false; - public final static String VIEW_1_NAME = "JUnit"; - public final static String VIEW_1_INTERNAL_NAME = "junit"; - public final static Long VIEW_1_CONTAINER_ID = CONTAINER_1_ID; - public final static Long VIEW_1_DATABASE_ID = DATABASE_1_ID; - public final static Boolean VIEW_1_PUBLIC = true; - public final static String VIEW_1_QUERY = "select `location`, `lat`, `lng` from `weather_location`"; - - public final static View VIEW_1 = View.builder() - .id(VIEW_1_ID) - .isInitialView(VIEW_1_INITIAL_VIEW) - .name(VIEW_1_NAME) - .internalName(VIEW_1_INTERNAL_NAME) - .vcid(VIEW_1_CONTAINER_ID) - .vdbid(VIEW_1_DATABASE_ID) - .isPublic(VIEW_1_PUBLIC) - .query(VIEW_1_QUERY) - .creator(USER_1) - .build(); - - public final static ViewDto VIEW_1_DTO = ViewDto.builder() - .id(VIEW_1_ID) - .isInitialView(VIEW_1_INITIAL_VIEW) - .name(VIEW_1_NAME) - .internalName(VIEW_1_INTERNAL_NAME) - .vdbid(VIEW_1_DATABASE_ID) - .isPublic(VIEW_1_PUBLIC) - .query(VIEW_1_QUERY) - .build(); - - public final static Long VIEW_2_ID = 2L; - public final static Boolean VIEW_2_INITIAL_VIEW = false; - public final static String VIEW_2_NAME = "JUnit2"; - public final static String VIEW_2_INTERNAL_NAME = "junit2"; - public final static Long VIEW_2_CONTAINER_ID = CONTAINER_1_ID; - public final static Long VIEW_2_DATABASE_ID = DATABASE_1_ID; - public final static Boolean VIEW_2_PUBLIC = true; - public final static String VIEW_2_QUERY = "select `date`, `location`, `mintemp`, `rainfall` from `weather_aus` where `location` = 'Albury'"; - - public final static View VIEW_2 = View.builder() - .id(VIEW_2_ID) - .isInitialView(VIEW_2_INITIAL_VIEW) - .name(VIEW_2_NAME) - .internalName(VIEW_2_INTERNAL_NAME) - .vcid(VIEW_2_CONTAINER_ID) - .vdbid(VIEW_2_DATABASE_ID) - .isPublic(VIEW_2_PUBLIC) - .query(VIEW_2_QUERY) - .creator(USER_1) - .build(); - - public final static ViewDto VIEW_2_DTO = ViewDto.builder() - .id(VIEW_2_ID) - .isInitialView(VIEW_2_INITIAL_VIEW) - .name(VIEW_2_NAME) - .internalName(VIEW_2_INTERNAL_NAME) - .vdbid(VIEW_2_DATABASE_ID) - .isPublic(VIEW_2_PUBLIC) - .query(VIEW_2_QUERY) - .build(); - - public final static Long VIEW_3_ID = 3L; - public final static Boolean VIEW_3_INITIAL_VIEW = false; - public final static String VIEW_3_NAME = "JUnit3"; - public final static String VIEW_3_INTERNAL_NAME = "junit3"; - public final static Long VIEW_3_CONTAINER_ID = CONTAINER_1_ID; - public final static Long VIEW_3_DATABASE_ID = DATABASE_1_ID; - public final static Boolean VIEW_3_PUBLIC = false; - public final static String VIEW_3_QUERY = "select w.`mintemp`, w.`rainfall`, w.`location`, m.`lat`, m.`lng` from `weather_aus` w join `junit2` m on m.`location` = w.`location`"; - - public final static View VIEW_3 = View.builder() - .id(VIEW_3_ID) - .isInitialView(VIEW_3_INITIAL_VIEW) - .name(VIEW_3_NAME) - .internalName(VIEW_3_INTERNAL_NAME) - .vcid(VIEW_3_CONTAINER_ID) - .vdbid(VIEW_3_DATABASE_ID) - .isPublic(VIEW_3_PUBLIC) - .query(VIEW_3_QUERY) - .creator(USER_1) - .build(); - - public final static ViewDto VIEW_3_DTO = ViewDto.builder() - .id(VIEW_3_ID) - .isInitialView(VIEW_3_INITIAL_VIEW) - .name(VIEW_3_NAME) - .internalName(VIEW_3_INTERNAL_NAME) - .vdbid(VIEW_3_DATABASE_ID) - .isPublic(VIEW_3_PUBLIC) - .query(VIEW_3_QUERY) - .build(); - - public final static Long VIEW_4_ID = 4L; - public final static Boolean VIEW_4_INITIAL_VIEW = false; - public final static String VIEW_4_NAME = "Mock View"; - public final static String VIEW_4_INTERNAL_NAME = "mock_view"; - public final static Long VIEW_4_CONTAINER_ID = CONTAINER_2_ID; - public final static Long VIEW_4_DATABASE_ID = DATABASE_2_ID; - public final static Boolean VIEW_4_PUBLIC = true; - public final static String VIEW_4_QUERY = "SELECT `animal_name`, `hair`, `feathers`, `eggs`, `milk`, `airborne`, `aquatic`, `predator`, `toothed`, `backbone`, `breathes`, `venomous`, `fins`, `legs`, `tail`, `domestic`, `catsize`, `class_type`FROM `zoo`WHERE `class_type` = 1"; - - public final static View VIEW_4 = View.builder() - .id(VIEW_4_ID) - .isInitialView(VIEW_4_INITIAL_VIEW) - .name(VIEW_4_NAME) - .internalName(VIEW_4_INTERNAL_NAME) - .vcid(VIEW_4_CONTAINER_ID) - .vdbid(VIEW_4_DATABASE_ID) - .isPublic(VIEW_4_PUBLIC) - .query(VIEW_4_QUERY) - .build(); - - public final static Database DATABASE_1 = Database.builder() - .id(DATABASE_1_ID) - .created(Instant.now().minus(1, HOURS)) - .lastModified(Instant.now()) - .isPublic(true) - .name(DATABASE_1_NAME) - .container(CONTAINER_1) - .internalName(DATABASE_1_INTERNALNAME) - .exchangeName(DATABASE_1_EXCHANGE) - .creator(USER_1) - .owner(USER_1) - .tables(List.of(TABLE_1, TABLE_2, TABLE_3, TABLE_7)) - .views(List.of(VIEW_1)) - .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) - .internalName(DATABASE_2_INTERNALNAME) - .exchangeName(DATABASE_2_EXCHANGE) - .creator(USER_2) - .owner(USER_2) - .tables(List.of()) /* TABLE_4, TABLE_5, TABLE_6 */ - .views(List.of()) /* VIEW_4 */ - .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) - .internalName(DATABASE_3_INTERNALNAME) - .exchangeName(DATABASE_3_EXCHANGE) - .creator(USER_3) - .owner(USER_3) - .tables(List.of()) - .views(List.of()) - .build(); - - public final static Long QUERY_1_RESULT_ID = 1L; - public final static List<Map<String, Object>> QUERY_1_RESULT_RESULT = List.of( - new HashMap<>() {{ - put("location", "Albury"); - put("lat", -36.0653583); - put("lng", 146.9112214); - }}, new HashMap<>() {{ - put("location", "Sydney"); - put("lat", -33.847927); - put("lng", 150.6517942); - }}); - - public final static QueryResultDto QUERY_1_RESULT_DTO = QueryResultDto.builder() - .id(QUERY_1_RESULT_ID) - .resultNumber(QUERY_1_RESULT_NUMBER) - .result(QUERY_1_RESULT_RESULT) - .build(); - - public final static DatabaseAccess DATABASE_1_OWNER_ACCESS = DatabaseAccess.builder() - .type(AccessType.WRITE_ALL) - .hdbid(DATABASE_1_ID) - .huserid(USER_1_ID) - .build(); - - public final static DatabaseAccess DATABASE_1_READ_ACCESS = DatabaseAccess.builder() - .type(AccessType.READ) - .hdbid(DATABASE_1_ID) - .huserid(USER_2_ID) - .build(); - - public final static DatabaseAccess DATABASE_1_WRITE_OWN_ACCESS = DatabaseAccess.builder() - .type(AccessType.WRITE_OWN) - .hdbid(DATABASE_1_ID) - .huserid(USER_2_ID) - .build(); - - public final static DatabaseAccess DATABASE_1_WRITE_ALL_ACCESS = DatabaseAccess.builder() - .type(AccessType.WRITE_ALL) - .hdbid(DATABASE_1_ID) - .huserid(USER_2_ID) - .build(); - - public final static DatabaseAccess DATABASE_2_OWNER_ACCESS = DatabaseAccess.builder() - .type(AccessType.WRITE_ALL) - .hdbid(DATABASE_2_ID) - .huserid(USER_1_ID) - .build(); - - public final static DatabaseAccess DATABASE_2_READ_ACCESS = DatabaseAccess.builder() - .type(AccessType.READ) - .hdbid(DATABASE_2_ID) - .huserid(USER_2_ID) - .build(); - - public final static DatabaseAccess DATABASE_2_WRITE_OWN_ACCESS = DatabaseAccess.builder() - .type(AccessType.WRITE_OWN) - .hdbid(DATABASE_2_ID) - .huserid(USER_2_ID) - .build(); - - public final static DatabaseAccess DATABASE_2_WRITE_ALL_ACCESS = DatabaseAccess.builder() - .type(AccessType.WRITE_ALL) - .hdbid(DATABASE_2_ID) - .huserid(USER_2_ID) - .build(); - - public final static DatabaseAccess DATABASE_3_OWNER_ACCESS = DatabaseAccess.builder() - .type(AccessType.WRITE_ALL) - .hdbid(DATABASE_3_ID) - .huserid(USER_3_ID) - .build(); - - public final static DatabaseAccess DATABASE_3_READ_ACCESS = DatabaseAccess.builder() - .type(AccessType.READ) - .hdbid(DATABASE_3_ID) - .huserid(USER_1_ID) - .build(); - - public final static DatabaseAccess DATABASE_3_WRITE_OWN_ACCESS = DatabaseAccess.builder() - .type(AccessType.WRITE_OWN) - .hdbid(DATABASE_3_ID) - .huserid(USER_1_ID) - .build(); - - public final static DatabaseAccess DATABASE_3_WRITE_ALL_ACCESS = DatabaseAccess.builder() - .type(AccessType.WRITE_ALL) - .hdbid(DATABASE_3_ID) - .huserid(USER_1_ID) - .build(); - - public final static TableCsvDto TABLE_1_CSV_DTO = TableCsvDto.builder() - .data(new HashMap<>() {{ - put("id", 1); - put("date", "2022-12-20"); - put("location", "Vienna"); - put("mintemp", -2.3); - put("rainfall", 34.3); - }}) - .build(); - - public final static Long IDENTIFIER_1_ID = 1L; - public final static Long IDENTIFIER_1_QUERY_ID = QUERY_1_ID; - public final static Long IDENTIFIER_1_CONTAINER_ID = CONTAINER_1_ID; - public final static Long IDENTIFIER_1_DATABASE_ID = DATABASE_1_ID; - public final static String IDENTIFIER_1_DESCRIPTION = "Selecting all from the weather Australia table"; - public final static String IDENTIFIER_1_TITLE = "Australia weather data"; - public final static String IDENTIFIER_1_DOI = "10.1000/182"; - public final static VisibilityType IDENTIFIER_1_VISIBILITY = VisibilityType.EVERYONE; - public final static VisibilityTypeDto IDENTIFIER_1_VISIBILITY_DTO = VisibilityTypeDto.EVERYONE; - public final static Instant IDENTIFIER_1_CREATED = Instant.ofEpochSecond(1641588352); - public final static Instant IDENTIFIER_1_MODIFIED = Instant.ofEpochSecond(1541588352); - public final static Instant IDENTIFIER_1_EXECUTION = Instant.ofEpochSecond(1541588352); - public final static Integer IDENTIFIER_1_PUBLICATION_MONTH = 5; - public final static Integer IDENTIFIER_1_PUBLICATION_YEAR = 2022; - public final static String IDENTIFIER_1_QUERY_HASH = "abc"; - public final static String IDENTIFIER_1_RESULT_HASH = "def"; - public final static String IDENTIFIER_1_QUERY = "SELECT `id` FROM `foobar`"; - public final static String IDENTIFIER_1_NORMALIZED = "SELECT `id` FROM `foobar`"; - public final static Long IDENTIFIER_1_RESULT_NUMBER = 2L; - public final static String IDENTIFIER_1_PUBLISHER = "Australian Government"; - public final static IdentifierType IDENTIFIER_1_TYPE = IdentifierType.SUBSET; - public final static IdentifierTypeDto IDENTIFIER_1_TYPE_DTO = IdentifierTypeDto.DATABASE; - - public final static Identifier IDENTIFIER_1 = Identifier.builder() - .id(IDENTIFIER_1_ID) - .containerId(IDENTIFIER_1_CONTAINER_ID) - .databaseId(IDENTIFIER_1_DATABASE_ID) - .queryId(IDENTIFIER_1_QUERY_ID) - .description(IDENTIFIER_1_DESCRIPTION) - .title(IDENTIFIER_1_TITLE) - .doi(IDENTIFIER_1_DOI) - .visibility(IDENTIFIER_1_VISIBILITY) - .created(IDENTIFIER_1_CREATED) - .lastModified(IDENTIFIER_1_MODIFIED) - .execution(IDENTIFIER_1_EXECUTION) - .publicationYear(IDENTIFIER_1_PUBLICATION_YEAR) - .publicationMonth(IDENTIFIER_1_PUBLICATION_MONTH) - .queryHash(IDENTIFIER_1_QUERY_HASH) - .resultHash(IDENTIFIER_1_RESULT_HASH) - .query(IDENTIFIER_1_QUERY) - .queryNormalized(IDENTIFIER_1_NORMALIZED) - .resultNumber(IDENTIFIER_1_RESULT_NUMBER) - .publisher(IDENTIFIER_1_PUBLISHER) - .type(IDENTIFIER_1_TYPE) - .creators(List.of()) - .build(); +public abstract class BaseUnitTest extends BaseTest { } diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/auth/AuthTokenFilterTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/auth/AuthTokenFilterTest.java index 8b0d8be0cef229b27f02a017b0c1c66e28c7cefc..be47edffc2fe11c8203afe9746339d75015b9456 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/auth/AuthTokenFilterTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/auth/AuthTokenFilterTest.java @@ -12,20 +12,10 @@ 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.mock.web.MockFilterChain; import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.junit.jupiter.SpringExtension; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import java.io.IOException; -import java.util.Optional; - import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.when; @Log4j2 @SpringBootTest @@ -50,49 +40,6 @@ public class AuthTokenFilterTest extends BaseUnitTest { @Autowired private H2Utils h2Utils; - @Test - public void doFilterInternal_notFound_fails() throws ServletException { - final MockHttpServletRequest request = new MockHttpServletRequest(); - request.addHeader("Authorization", "Bearer " + JWT_1); - final MockHttpServletResponse response = new MockHttpServletResponse(); - final FilterChain chain = new MockFilterChain(); - - /* mock */ - when(userRepository.findByUsername("mweise")) - .thenReturn(Optional.empty()); - - /* test */ - assertThrows(ServletException.class, () -> { - authTokenFilter.doFilterInternal(request, response, chain); - }); - } - - @Test - public void doFilterInternal_succeeds() throws ServletException, IOException { - final MockHttpServletRequest request = new MockHttpServletRequest(); - request.addHeader("Authorization", "Bearer " + JWT_1); - final MockHttpServletResponse response = new MockHttpServletResponse(); - final FilterChain chain = new MockFilterChain(); - - /* mock */ - when(userRepository.findByUsername("mweise")) - .thenReturn(Optional.of(USER_1)); - - /* test */ - authTokenFilter.doFilterInternal(request, response, chain); - assertEquals(200, response.getStatus()); - } - - @Test - public void parseJwt_succeeds() { - final MockHttpServletRequest request = new MockHttpServletRequest(); - request.addHeader("Authorization", "Bearer " + JWT_1); - - /* test */ - final String response = authTokenFilter.parseJwt(request); - assertEquals(JWT_1, response); - } - @Test public void parseJwt_fails() { final MockHttpServletRequest request = new MockHttpServletRequest(); diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/config/H2Utils.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/config/H2Utils.java deleted file mode 100644 index ce2ec33c931b524f568c7cf8f5de86e3bd7484d2..0000000000000000000000000000000000000000 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/config/H2Utils.java +++ /dev/null @@ -1,38 +0,0 @@ -package at.tuwien.config; - -import lombok.extern.log4j.Log4j2; -import org.codehaus.plexus.util.FileUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -import javax.persistence.EntityManager; -import java.io.File; -import java.io.IOException; - -@Log4j2 -@Component -public class H2Utils { - - @Autowired - private EntityManager entityManager; - - @Transactional - public void runQuery(String query) { - log.debug("query={}", query); - entityManager.createNativeQuery(query) - .executeUpdate(); - } - - @Transactional - public void runScript(String scriptName) { - try { - runQuery(FileUtils.fileRead(new File("./src/test/resources/" + scriptName))); - } catch (IOException e) { - log.error("Failed to load script {}", scriptName); - throw new RuntimeException("Failed to load script", e); - } - } - -} - diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/ExportEndpointUnitTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/ExportEndpointUnitTest.java index f5126e08b48fb31b936fd2e56d4ab8ff7bd3f685..23d70ee0f41c0a2e9cd89653936fa47b731adf71 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/ExportEndpointUnitTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/ExportEndpointUnitTest.java @@ -91,7 +91,7 @@ public class ExportEndpointUnitTest extends BaseUnitTest { UserNotFoundException, IOException { /* test */ - export_generic(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, null, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_1_READ_ACCESS); + export_generic(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, null, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_1_RESEARCHER_READ_ACCESS); } @Test @@ -101,7 +101,7 @@ public class ExportEndpointUnitTest extends BaseUnitTest { UserNotFoundException, IOException { /* test */ - export_generic(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, null, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_1_WRITE_OWN_ACCESS); + export_generic(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, null, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS); } @Test @@ -111,7 +111,7 @@ public class ExportEndpointUnitTest extends BaseUnitTest { UserNotFoundException, IOException { /* test */ - export_generic(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, null, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_1_WRITE_ALL_ACCESS); + export_generic(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, null, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -121,7 +121,7 @@ public class ExportEndpointUnitTest extends BaseUnitTest { UserNotFoundException, IOException { /* test */ - export_generic(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, null, USER_1_PRINCIPAL, USER_1_USERNAME, DATABASE_1_WRITE_ALL_ACCESS); + export_generic(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, null, USER_1_PRINCIPAL, USER_1_USERNAME, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -132,7 +132,7 @@ public class ExportEndpointUnitTest extends BaseUnitTest { final Instant timestamp = Instant.now(); /* test */ - export_generic(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, timestamp, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_1_READ_ACCESS); + export_generic(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, timestamp, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_1_RESEARCHER_READ_ACCESS); } @Test @@ -143,7 +143,7 @@ public class ExportEndpointUnitTest extends BaseUnitTest { final Instant timestamp = Instant.now().plus(10, ChronoUnit.DAYS); /* test */ - export_generic(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, timestamp, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_1_READ_ACCESS); + export_generic(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, timestamp, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_1_RESEARCHER_READ_ACCESS); } /* ################################################################################################### */ @@ -166,7 +166,7 @@ public class ExportEndpointUnitTest extends BaseUnitTest { UserNotFoundException, IOException { /* test */ - export_generic(CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, null, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_2_READ_ACCESS); + export_generic(CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, null, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test @@ -176,7 +176,7 @@ public class ExportEndpointUnitTest extends BaseUnitTest { UserNotFoundException, IOException { /* test */ - export_generic(CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, null, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_2_WRITE_OWN_ACCESS); + export_generic(CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, null, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS); } @Test @@ -186,7 +186,7 @@ public class ExportEndpointUnitTest extends BaseUnitTest { UserNotFoundException, IOException { /* test */ - export_generic(CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, null, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_2_WRITE_ALL_ACCESS); + export_generic(CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, null, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -196,7 +196,7 @@ public class ExportEndpointUnitTest extends BaseUnitTest { UserNotFoundException, IOException { /* test */ - export_generic(CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, null, USER_1_PRINCIPAL, USER_1_USERNAME, DATABASE_2_WRITE_ALL_ACCESS); + export_generic(CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, null, USER_1_PRINCIPAL, USER_1_USERNAME, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -207,7 +207,7 @@ public class ExportEndpointUnitTest extends BaseUnitTest { final Instant timestamp = Instant.now(); /* test */ - export_generic(CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, timestamp, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_2_READ_ACCESS); + export_generic(CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, timestamp, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test @@ -218,7 +218,7 @@ public class ExportEndpointUnitTest extends BaseUnitTest { final Instant timestamp = Instant.now().plus(10, ChronoUnit.DAYS); /* test */ - export_generic(CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, timestamp, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_2_READ_ACCESS); + export_generic(CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, timestamp, USER_2_PRINCIPAL, USER_2_USERNAME, DATABASE_2_RESEARCHER_READ_ACCESS); } /* ################################################################################################### */ diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/QueryEndpointUnitTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/QueryEndpointUnitTest.java index 8f315d2b404e95c7e0675ef36e13f6d9a88b0485..f0cee2f8848cda1cc74e67584ab3b8fa4cd797c7 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/QueryEndpointUnitTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/QueryEndpointUnitTest.java @@ -99,7 +99,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(QueryMalformedException.class, () -> { - generic_execute(CONTAINER_1_ID, DATABASE_1_ID, statement, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_READ_ACCESS); + generic_execute(CONTAINER_1_ID, DATABASE_1_ID, statement, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_RESEARCHER_READ_ACCESS); }); } @@ -109,7 +109,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(QueryMalformedException.class, () -> { - generic_execute(CONTAINER_1_ID, DATABASE_1_ID, statement, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_READ_ACCESS); + generic_execute(CONTAINER_1_ID, DATABASE_1_ID, statement, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_RESEARCHER_READ_ACCESS); }); } @@ -140,7 +140,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { PaginationException { /* test */ - generic_execute(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_STATEMENT, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_READ_ACCESS); + generic_execute(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_STATEMENT, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_RESEARCHER_READ_ACCESS); } @Test @@ -150,7 +150,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { PaginationException { /* test */ - generic_execute(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_STATEMENT, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_WRITE_OWN_ACCESS); + generic_execute(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_STATEMENT, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS); } @Test @@ -160,7 +160,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { PaginationException { /* test */ - generic_execute(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_STATEMENT, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_WRITE_ALL_ACCESS); + generic_execute(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_STATEMENT, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -170,7 +170,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { PaginationException { /* test */ - generic_execute(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_STATEMENT, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1, DATABASE_1_OWNER_ACCESS); + generic_execute(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_STATEMENT, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -190,7 +190,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { PaginationException, QueryNotFoundException { /* test */ - generic_reExecute(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_READ_ACCESS); + generic_reExecute(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_RESEARCHER_READ_ACCESS); } @Test @@ -200,7 +200,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { PaginationException, QueryNotFoundException { /* test */ - generic_reExecute(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_WRITE_OWN_ACCESS); + generic_reExecute(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS); } @Test @@ -210,7 +210,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { PaginationException, QueryNotFoundException { /* test */ - generic_reExecute(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_WRITE_ALL_ACCESS); + generic_reExecute(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -220,7 +220,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { PaginationException, QueryNotFoundException { /* test */ - generic_reExecute(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1, DATABASE_1_OWNER_ACCESS); + generic_reExecute(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -250,7 +250,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { ContainerNotFoundException, IOException { /* test */ - export_generic(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_READ_ACCESS, null, HttpStatus.OK); + export_generic(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_RESEARCHER_READ_ACCESS, null, HttpStatus.OK); } @Test @@ -260,7 +260,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { ContainerNotFoundException, IOException { /* test */ - export_generic(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_WRITE_OWN_ACCESS, null, HttpStatus.OK); + export_generic(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS, null, HttpStatus.OK); } @Test @@ -270,7 +270,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { ContainerNotFoundException, IOException { /* test */ - export_generic(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_WRITE_ALL_ACCESS, null, HttpStatus.OK); + export_generic(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS, null, HttpStatus.OK); } @Test @@ -280,7 +280,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { ContainerNotFoundException, IOException { /* test */ - export_generic(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1, DATABASE_1_OWNER_ACCESS, null, HttpStatus.OK); + export_generic(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS, null, HttpStatus.OK); } /* ################################################################################################### */ @@ -304,7 +304,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { PaginationException { /* test */ - generic_execute(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_STATEMENT, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_READ_ACCESS); + generic_execute(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_STATEMENT, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test @@ -314,7 +314,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { PaginationException { /* test */ - generic_execute(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_STATEMENT, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_WRITE_OWN_ACCESS); + generic_execute(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_STATEMENT, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS); } @Test @@ -324,7 +324,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { PaginationException { /* test */ - generic_execute(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_STATEMENT, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_WRITE_ALL_ACCESS); + generic_execute(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_STATEMENT, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -334,7 +334,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { PaginationException { /* test */ - generic_execute(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_STATEMENT, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_2, DATABASE_2_OWNER_ACCESS); + generic_execute(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_STATEMENT, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_2, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -353,7 +353,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { PaginationException, QueryNotFoundException { /* test */ - generic_reExecute(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_READ_ACCESS); + generic_reExecute(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test @@ -363,7 +363,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { PaginationException, QueryNotFoundException { /* test */ - generic_reExecute(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_WRITE_OWN_ACCESS); + generic_reExecute(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS); } @Test @@ -373,7 +373,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { PaginationException, QueryNotFoundException { /* test */ - generic_reExecute(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_WRITE_ALL_ACCESS); + generic_reExecute(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -383,7 +383,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { PaginationException, QueryNotFoundException { /* test */ - generic_reExecute(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_ID, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_2, DATABASE_2_OWNER_ACCESS); + generic_reExecute(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_ID, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_2, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -411,7 +411,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { ContainerNotFoundException, IOException { /* test */ - export_generic(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_READ_ACCESS, null, HttpStatus.OK); + export_generic(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_RESEARCHER_READ_ACCESS, null, HttpStatus.OK); } @Test @@ -421,7 +421,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { ContainerNotFoundException, IOException { /* test */ - export_generic(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_WRITE_OWN_ACCESS, null, HttpStatus.OK); + export_generic(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS, null, HttpStatus.OK); } @Test @@ -431,7 +431,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { ContainerNotFoundException, IOException { /* test */ - export_generic(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_WRITE_ALL_ACCESS, null, HttpStatus.OK); + export_generic(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_ID, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS, null, HttpStatus.OK); } @Test @@ -441,7 +441,7 @@ public class QueryEndpointUnitTest extends BaseUnitTest { ContainerNotFoundException, IOException { /* test */ - export_generic(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_ID, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_2, DATABASE_2_OWNER_ACCESS, null, HttpStatus.OK); + export_generic(CONTAINER_2_ID, DATABASE_2_ID, QUERY_1_ID, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_2, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS, null, HttpStatus.OK); } /* ################################################################################################### */ diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/StoreEndpointUnitTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/StoreEndpointUnitTest.java index ed344f89d4b6aa8b6e50fc988d3fd704c3f77118..2a7a024b703bd373e85b4eec648c198b9500b9f3 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/StoreEndpointUnitTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/StoreEndpointUnitTest.java @@ -224,7 +224,7 @@ public class StoreEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - persist_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, QUERY_1_ID, QUERY_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_READ_ACCESS); + persist_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, QUERY_1_ID, QUERY_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_READ_ACCESS); }); } @@ -233,7 +233,7 @@ public class StoreEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - persist_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, QUERY_1_ID, QUERY_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_WRITE_OWN_ACCESS); + persist_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, QUERY_1_ID, QUERY_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS); }); } @@ -243,7 +243,7 @@ public class StoreEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException, ImageNotSupportedException { /* test */ - final QueryDto response = persist_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, QUERY_1_ID, QUERY_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_WRITE_ALL_ACCESS); + final QueryDto response = persist_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, QUERY_1_ID, QUERY_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); assertEquals(QUERY_1_ID, response.getId()); assertEquals(QUERY_1_STATEMENT, response.getQuery()); } @@ -253,7 +253,7 @@ public class StoreEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(QueryAlreadyPersistedException.class, () -> { - persist_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, QUERY_2_ID, QUERY_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_WRITE_ALL_ACCESS); + persist_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, QUERY_2_ID, QUERY_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); }); } @@ -263,7 +263,7 @@ public class StoreEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException, ImageNotSupportedException { /* test */ - final QueryDto response = persist_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, QUERY_1_ID, QUERY_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_WRITE_ALL_ACCESS); + final QueryDto response = persist_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, QUERY_1_ID, QUERY_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); assertEquals(QUERY_1_ID, response.getId()); assertEquals(QUERY_1_STATEMENT, response.getQuery()); } diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/TableDataEndpointUnitTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/TableDataEndpointUnitTest.java index 4cf2392ed0a94319043e7738151d0c86123b7cf7..c12e37a34ff9ed6c8000eab6d47d03b6ba432b86 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/TableDataEndpointUnitTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/TableDataEndpointUnitTest.java @@ -82,18 +82,18 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { TABLE_1_ID, TABLE_1, null, null, null), Arguments.arguments("public read", NotAllowedException.class, CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, TABLE_1_ID, - TABLE_1, USER_2_USERNAME, DATABASE_1_READ_ACCESS, USER_2_PRINCIPAL), + TABLE_1, USER_2_USERNAME, DATABASE_1_RESEARCHER_READ_ACCESS, USER_2_PRINCIPAL), Arguments.arguments("public write-own", NotAllowedException.class, CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, TABLE_1_ID, - TABLE_1, USER_2_USERNAME, DATABASE_1_WRITE_OWN_ACCESS, USER_2_PRINCIPAL), + TABLE_1, USER_2_USERNAME, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS, USER_2_PRINCIPAL), Arguments.arguments("private anonymous", NotAllowedException.class, CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, TABLE_1_ID, TABLE_1, null, null, null), Arguments.arguments("private read", NotAllowedException.class, CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, TABLE_1_ID, TABLE_1, USER_2_USERNAME, - DATABASE_2_READ_ACCESS, USER_2_PRINCIPAL), + DATABASE_2_RESEARCHER_READ_ACCESS, USER_2_PRINCIPAL), Arguments.arguments("private write-own", NotAllowedException.class, CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, TABLE_1_ID, TABLE_1, USER_2_USERNAME, - DATABASE_2_WRITE_OWN_ACCESS, USER_2_PRINCIPAL) + DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS, USER_2_PRINCIPAL) ); } @@ -111,16 +111,11 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { public static Stream<Arguments> import_succeeds_parameters() { return Stream.of( - Arguments.arguments("public write-all", CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, TABLE_1_ID, TABLE_1, - USER_2_USERNAME, DATABASE_1_WRITE_ALL_ACCESS, USER_2_PRINCIPAL), - Arguments.arguments("public owner", CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, TABLE_1_ID, TABLE_1, - USER_1_USERNAME, DATABASE_1_WRITE_ALL_ACCESS, USER_1_PRINCIPAL), - Arguments.arguments("private write-all", CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, TABLE_1_ID, - TABLE_1, USER_2_USERNAME, - DATABASE_2_WRITE_ALL_ACCESS, USER_2_PRINCIPAL), - Arguments.arguments("private owner", CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, TABLE_1_ID, TABLE_1, - USER_1_USERNAME, - DATABASE_2_WRITE_ALL_ACCESS, USER_1_PRINCIPAL) + Arguments.arguments("public write-all", CONTAINER_3_ID, DATABASE_3_ID, DATABASE_3, TABLE_8_ID, TABLE_8, + USER_1_USERNAME, DATABASE_3_RESEARCHER_WRITE_ALL_ACCESS, USER_1_PRINCIPAL), + Arguments.arguments("private write-all", CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, TABLE_1_ID, + TABLE_1, USER_1_USERNAME, + DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS, USER_1_PRINCIPAL) ); } @@ -140,19 +135,19 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { DATABASE_1, TABLE_1, USER_2_USERNAME, null, TABLE_1_CSV_DTO, null), Arguments.arguments("public read", NotAllowedException.class, CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, - TABLE_1, USER_2_USERNAME, DATABASE_1_READ_ACCESS, TABLE_1_CSV_DTO, USER_2_PRINCIPAL), + TABLE_1, USER_2_USERNAME, DATABASE_1_RESEARCHER_READ_ACCESS, TABLE_1_CSV_DTO, USER_2_PRINCIPAL), Arguments.arguments("public write-own", NotAllowedException.class, CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, - TABLE_1, USER_2_USERNAME, DATABASE_1_WRITE_OWN_ACCESS, TABLE_1_CSV_DTO, USER_2_PRINCIPAL), + TABLE_1, USER_2_USERNAME, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS, TABLE_1_CSV_DTO, USER_2_PRINCIPAL), Arguments.arguments("private anonymous", NotAllowedException.class, CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, TABLE_1, USER_2_USERNAME, null, TABLE_1_CSV_DTO, null), Arguments.arguments("private read", NotAllowedException.class, CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, TABLE_1, USER_2_USERNAME, - DATABASE_2_READ_ACCESS, TABLE_1_CSV_DTO, USER_2_PRINCIPAL), + DATABASE_2_RESEARCHER_READ_ACCESS, TABLE_1_CSV_DTO, USER_2_PRINCIPAL), Arguments.arguments("private write-own", NotAllowedException.class, CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, TABLE_1, USER_2_USERNAME, - DATABASE_2_WRITE_OWN_ACCESS, TABLE_1_CSV_DTO, USER_2_PRINCIPAL) + DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS, TABLE_1_CSV_DTO, USER_2_PRINCIPAL) ); } @@ -171,24 +166,18 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { public static Stream<Arguments> insert_succeeds_parameters() { return Stream.of( - Arguments.arguments("public write-all", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, - TABLE_1, USER_2_USERNAME, - DATABASE_1_WRITE_ALL_ACCESS, TABLE_1_CSV_DTO, USER_2_PRINCIPAL), - Arguments.arguments("public owner", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, TABLE_1, - USER_1_USERNAME, - DATABASE_1_WRITE_ALL_ACCESS, TABLE_1_CSV_DTO, USER_1_PRINCIPAL), - Arguments.arguments("public owner, data null", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, + Arguments.arguments("public write-all", CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID, DATABASE_3, + TABLE_8, USER_1_USERNAME, + DATABASE_3_RESEARCHER_WRITE_ALL_ACCESS, TABLE_8_CSV_DTO, USER_1_PRINCIPAL), + Arguments.arguments("private write-all", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, TABLE_1, USER_1_USERNAME, - DATABASE_1_WRITE_ALL_ACCESS, null, USER_1_PRINCIPAL), - Arguments.arguments("private write-all", CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, - TABLE_1, USER_2_USERNAME, - DATABASE_2_WRITE_ALL_ACCESS, TABLE_1_CSV_DTO, USER_2_PRINCIPAL), - Arguments.arguments("private owner", CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, TABLE_1, + DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS, TABLE_1_CSV_DTO, USER_1_PRINCIPAL), + Arguments.arguments("private owner", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, TABLE_1, USER_1_USERNAME, - DATABASE_2_WRITE_ALL_ACCESS, TABLE_1_CSV_DTO, USER_1_PRINCIPAL), - Arguments.arguments("private owner, data null", CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2 - , TABLE_1, USER_1_USERNAME, - DATABASE_2_WRITE_ALL_ACCESS, null, USER_1_PRINCIPAL) + DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS, TABLE_1_CSV_DTO, USER_1_PRINCIPAL), + Arguments.arguments("private owner, data null", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, + DATABASE_1, TABLE_1, USER_1_USERNAME, + DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS, null, USER_1_PRINCIPAL) ); } @@ -206,39 +195,39 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { public static Stream<Arguments> getAll_fails_parameters() { return Stream.of( - Arguments.arguments("public anonymous page null", PaginationException.class, CONTAINER_1_ID, - DATABASE_1_ID, TABLE_1_ID, DATABASE_1, - TABLE_1, null, null, null, null, null, 1L, null, null), - Arguments.arguments("public anonymous size null", PaginationException.class, CONTAINER_1_ID, - DATABASE_1_ID, TABLE_1_ID, DATABASE_1, - TABLE_1, null, null, null, null, 1L, null, null, null), - Arguments.arguments("public anonymous page negative", PaginationException.class, CONTAINER_1_ID, - DATABASE_1_ID, TABLE_1_ID, DATABASE_1, - TABLE_1, null, null, null, null, -1L, 1L, null, null), - Arguments.arguments("public anonymous size zero", PaginationException.class, CONTAINER_1_ID, - DATABASE_1_ID, TABLE_1_ID, DATABASE_1, - TABLE_1, null, null, null, null, 0L, 0L, null, null), - Arguments.arguments("public anonymous size negative", PaginationException.class, CONTAINER_1_ID, - DATABASE_1_ID, TABLE_1_ID, DATABASE_1, - TABLE_1, null, null, null, null, 0L, -1L, null, null), - Arguments.arguments("private anonymous", NotAllowedException.class, CONTAINER_2_ID, DATABASE_2_ID, - TABLE_1_ID, DATABASE_2, TABLE_1, null, null, null, null, + Arguments.arguments("public anonymous page null", PaginationException.class, CONTAINER_3_ID, + DATABASE_3_ID, TABLE_8_ID, DATABASE_3, + TABLE_8, null, null, null, null, null, 3L, null, null), + Arguments.arguments("public anonymous size null", PaginationException.class, CONTAINER_3_ID, + DATABASE_3_ID, TABLE_8_ID, DATABASE_3, + TABLE_8, null, null, null, null, 3L, null, null, null), + Arguments.arguments("public anonymous page negative", PaginationException.class, CONTAINER_3_ID, + DATABASE_3_ID, TABLE_8_ID, DATABASE_3, + TABLE_8, null, null, null, null, -3L, 3L, null, null), + Arguments.arguments("public anonymous size zero", PaginationException.class, CONTAINER_3_ID, + DATABASE_3_ID, TABLE_8_ID, DATABASE_3, + TABLE_8, null, null, null, null, 0L, 0L, null, null), + Arguments.arguments("public anonymous size negative", PaginationException.class, CONTAINER_3_ID, + DATABASE_3_ID, TABLE_8_ID, DATABASE_3, + TABLE_8, null, null, null, null, 0L, -3L, null, null), + Arguments.arguments("private anonymous", NotAllowedException.class, CONTAINER_1_ID, DATABASE_1_ID, + TABLE_1_ID, DATABASE_1, TABLE_1, null, null, null, null, null, null, null, null), - Arguments.arguments("private read, page null", PaginationException.class, CONTAINER_2_ID, - DATABASE_2_ID, TABLE_1_ID, DATABASE_2, TABLE_1, USER_2_USERNAME, - DATABASE_2_READ_ACCESS, USER_2_PRINCIPAL, null, null, 1L, null, null), - Arguments.arguments("private read, size null", PaginationException.class, CONTAINER_2_ID, - DATABASE_2_ID, TABLE_1_ID, DATABASE_2, TABLE_1, USER_2_USERNAME, - DATABASE_2_READ_ACCESS, USER_2_PRINCIPAL, null, 1L, null, null, null), - Arguments.arguments("private read, page negative", PaginationException.class, CONTAINER_2_ID, - DATABASE_2_ID, TABLE_1_ID, DATABASE_2, TABLE_1, USER_2_USERNAME, - DATABASE_2_READ_ACCESS, USER_2_PRINCIPAL, null, -1L, 1L, null, null), - Arguments.arguments("private read, size zero", PaginationException.class, CONTAINER_2_ID, - DATABASE_2_ID, TABLE_1_ID, DATABASE_2, TABLE_1, USER_2_USERNAME, - DATABASE_2_READ_ACCESS, USER_2_PRINCIPAL, null, 0L, 0L, null, null), - Arguments.arguments("private read, size negative", PaginationException.class, CONTAINER_2_ID, - DATABASE_2_ID, TABLE_1_ID, DATABASE_2, TABLE_1, USER_2_USERNAME, - DATABASE_2_READ_ACCESS, USER_2_PRINCIPAL, null, 0L, -1L, null, null) + Arguments.arguments("private read, page null", PaginationException.class, CONTAINER_1_ID, + DATABASE_1_ID, TABLE_1_ID, DATABASE_1, TABLE_1, USER_1_USERNAME, + DATABASE_1_RESEARCHER_READ_ACCESS, USER_1_PRINCIPAL, null, null, 1L, null, null), + Arguments.arguments("private read, size null", PaginationException.class, CONTAINER_1_ID, + DATABASE_1_ID, TABLE_1_ID, DATABASE_1, TABLE_1, USER_1_USERNAME, + DATABASE_1_RESEARCHER_READ_ACCESS, USER_1_PRINCIPAL, null, 1L, null, null, null), + Arguments.arguments("private read, page negative", PaginationException.class, CONTAINER_1_ID, + DATABASE_1_ID, TABLE_1_ID, DATABASE_1, TABLE_1, USER_1_USERNAME, + DATABASE_1_RESEARCHER_READ_ACCESS, USER_1_PRINCIPAL, null, -1L, 1L, null, null), + Arguments.arguments("private read, size zero", PaginationException.class, CONTAINER_1_ID, + DATABASE_1_ID, TABLE_1_ID, DATABASE_1, TABLE_1, USER_1_USERNAME, + DATABASE_1_RESEARCHER_READ_ACCESS, USER_1_PRINCIPAL, null, 0L, 0L, null, null), + Arguments.arguments("private read, size negative", PaginationException.class, CONTAINER_1_ID, + DATABASE_1_ID, TABLE_1_ID, DATABASE_1, TABLE_1, USER_1_USERNAME, + DATABASE_1_RESEARCHER_READ_ACCESS, USER_1_PRINCIPAL, null, 0L, -1L, null, null) ); } @@ -259,33 +248,27 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { public static Stream<Arguments> getAll_succeeds_parameters() { return Stream.of( - Arguments.arguments("public anonymous", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, - TABLE_1, null, null, null, + Arguments.arguments("public anonymous", CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID, DATABASE_3, + TABLE_8, null, null, null, null, null, null, null, null), - Arguments.arguments("public read", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, TABLE_1, - USER_2_USERNAME, - DATABASE_1_READ_ACCESS, USER_2_PRINCIPAL, null, null, null, null, null), - Arguments.arguments("public write-own", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, - TABLE_1, USER_2_USERNAME, - DATABASE_1_WRITE_OWN_ACCESS, USER_2_PRINCIPAL, null, null, null, null, null), - Arguments.arguments("public write-all", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, - TABLE_1, USER_2_USERNAME, - DATABASE_1_WRITE_ALL_ACCESS, USER_2_PRINCIPAL, null, null, null, null, null), - Arguments.arguments("public owner", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, TABLE_1, + Arguments.arguments("public read", CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID, DATABASE_3, TABLE_8, USER_1_USERNAME, - DATABASE_1_WRITE_ALL_ACCESS, USER_1_PRINCIPAL, null, null, null, null, null), - Arguments.arguments("private read", CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, TABLE_1, - USER_2_USERNAME, - DATABASE_2_READ_ACCESS, USER_2_PRINCIPAL, null, null, null, null, null), - Arguments.arguments("private write-own", CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, - TABLE_1, USER_2_USERNAME, - DATABASE_2_WRITE_OWN_ACCESS, USER_2_PRINCIPAL, null, null, null, null, null), - Arguments.arguments("private write-all", CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, - TABLE_1, USER_2_USERNAME, - DATABASE_2_WRITE_ALL_ACCESS, USER_2_PRINCIPAL, null, null, null, null, null), - Arguments.arguments("private owner", CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, TABLE_1, + DATABASE_3_RESEARCHER_READ_ACCESS, USER_1_PRINCIPAL, null, null, null, null, null), + Arguments.arguments("public write-own", CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID, DATABASE_3, + TABLE_8, USER_1_USERNAME, + DATABASE_3_RESEARCHER_WRITE_OWN_ACCESS, USER_1_PRINCIPAL, null, null, null, null, null), + Arguments.arguments("public write-all", CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID, DATABASE_3, + TABLE_8, USER_1_USERNAME, + DATABASE_3_RESEARCHER_WRITE_ALL_ACCESS, USER_1_PRINCIPAL, null, null, null, null, null), + Arguments.arguments("private read", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, TABLE_1, USER_1_USERNAME, - DATABASE_2_WRITE_ALL_ACCESS, USER_1_PRINCIPAL, null, null, null, null, null) + DATABASE_1_RESEARCHER_READ_ACCESS, USER_1_PRINCIPAL, null, null, null, null, null), + Arguments.arguments("private write-own", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, + TABLE_1, USER_1_USERNAME, + DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS, USER_1_PRINCIPAL, null, null, null, null, null), + Arguments.arguments("private write-all", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, + TABLE_1, USER_1_USERNAME, + DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS, USER_1_PRINCIPAL, null, null, null, null, null) ); } @@ -302,40 +285,34 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { public static Stream<Arguments> getCount_succeeds_parameters() { return Stream.of( - Arguments.arguments("public anonymous", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, - TABLE_1, null, null, null, null), - Arguments.arguments("public read", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, TABLE_1, - USER_2_USERNAME, - DATABASE_1_READ_ACCESS, USER_2_PRINCIPAL, null), - Arguments.arguments("public write-own", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, - TABLE_1, USER_2_USERNAME, - DATABASE_1_WRITE_OWN_ACCESS, USER_2_PRINCIPAL, null), - Arguments.arguments("public write-all", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, - TABLE_1, USER_2_USERNAME, - DATABASE_1_WRITE_ALL_ACCESS, USER_2_PRINCIPAL, null), - Arguments.arguments("public owner", CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID, DATABASE_1, TABLE_1, + Arguments.arguments("public anonymous", CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID, DATABASE_3, + TABLE_8, null, null, null, null), + Arguments.arguments("public read", CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID, DATABASE_3, TABLE_8, USER_1_USERNAME, - DATABASE_1_WRITE_ALL_ACCESS, USER_1_PRINCIPAL, null), - Arguments.arguments("private read", CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, TABLE_1, - USER_2_USERNAME, - DATABASE_2_READ_ACCESS, USER_2_PRINCIPAL, null), - Arguments.arguments("private write-own", CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, - TABLE_1, USER_2_USERNAME, - DATABASE_2_WRITE_OWN_ACCESS, USER_2_PRINCIPAL, null), - Arguments.arguments("private write-all", CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, - TABLE_1, USER_2_USERNAME, - DATABASE_2_WRITE_ALL_ACCESS, USER_2_PRINCIPAL, null), - Arguments.arguments("private owner", CONTAINER_2_ID, DATABASE_2_ID, TABLE_1_ID, DATABASE_2, TABLE_1, + DATABASE_3_RESEARCHER_READ_ACCESS, USER_1_PRINCIPAL, null), + Arguments.arguments("public write-own", CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID, DATABASE_3, + TABLE_8, USER_1_USERNAME, + DATABASE_3_RESEARCHER_WRITE_OWN_ACCESS, USER_1_PRINCIPAL, null), + Arguments.arguments("public write-all", CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID, DATABASE_3, + TABLE_8, USER_1_USERNAME, + DATABASE_3_RESEARCHER_WRITE_ALL_ACCESS, USER_1_PRINCIPAL, null), + Arguments.arguments("private read", CONTAINER_1_ID, DATABASE_2_ID, TABLE_8_ID, DATABASE_2, TABLE_8, USER_1_USERNAME, - DATABASE_2_WRITE_ALL_ACCESS, USER_1_PRINCIPAL, null) + DATABASE_2_RESEARCHER_READ_ACCESS, USER_1_PRINCIPAL, null), + Arguments.arguments("private write-own", CONTAINER_1_ID, DATABASE_2_ID, TABLE_8_ID, DATABASE_2, + TABLE_8, USER_2_USERNAME, + DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS, USER_2_PRINCIPAL, null), + Arguments.arguments("private write-all", CONTAINER_1_ID, DATABASE_2_ID, TABLE_8_ID, DATABASE_2, + TABLE_8, USER_2_USERNAME, + DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS, USER_2_PRINCIPAL, null) ); } @ParameterizedTest @MethodSource("getAll_succeeds_parameters") public void getCount_succeeds(String test, Long containerId, Long databaseId, Long tableId, Database database, - Table table, String username, DatabaseAccess access, Principal principal, - Instant timestamp) throws UserNotFoundException, TableNotFoundException, QueryStoreException, SortException, TableMalformedException, NotAllowedException, DatabaseConnectionException, QueryMalformedException, DatabaseNotFoundException, ImageNotSupportedException, PaginationException, ContainerNotFoundException { + Table table, String username, DatabaseAccess access, Principal principal, + Instant timestamp) throws UserNotFoundException, TableNotFoundException, QueryStoreException, SortException, TableMalformedException, NotAllowedException, DatabaseConnectionException, QueryMalformedException, DatabaseNotFoundException, ImageNotSupportedException, PaginationException, ContainerNotFoundException { /* test */ generic_getCount(containerId, databaseId, tableId, database, table, username, access, principal, timestamp); @@ -396,7 +373,7 @@ public class TableDataEndpointUnitTest extends BaseUnitTest { } public void generic_getCount(Long containerId, Long databaseId, Long tableId, Database database, Table table, - String username, DatabaseAccess access, Principal principal, Instant timestamp) throws UserNotFoundException, TableMalformedException, NotAllowedException, PaginationException, TableNotFoundException, QueryStoreException, SortException, DatabaseConnectionException, QueryMalformedException, DatabaseNotFoundException, ImageNotSupportedException, ContainerNotFoundException { + String username, DatabaseAccess access, Principal principal, Instant timestamp) throws UserNotFoundException, TableMalformedException, NotAllowedException, PaginationException, TableNotFoundException, QueryStoreException, SortException, DatabaseConnectionException, QueryMalformedException, DatabaseNotFoundException, ImageNotSupportedException, ContainerNotFoundException { /* mock */ when(databaseService.find(containerId, databaseId)).thenReturn(database); diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/TableHistoryEndpointUnitTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/TableHistoryEndpointUnitTest.java index 9a649b2e39f4a8978ebdf5b490f8aa70eab8c11d..30c0da68a79f98b8c7608ee08af22f0fed1af7cb 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/TableHistoryEndpointUnitTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/TableHistoryEndpointUnitTest.java @@ -1,4 +1,3 @@ - package at.tuwien.endpoint; import at.tuwien.BaseUnitTest; @@ -99,7 +98,7 @@ public class TableHistoryEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException { /* test */ - data_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, TABLE_1_ID, TABLE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_READ_ACCESS); + data_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, TABLE_1_ID, TABLE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_RESEARCHER_READ_ACCESS); } @Test diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/ViewEndpointUnitTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/ViewEndpointUnitTest.java index 5cf4aadd98085ace3f9bfe569c5d9e0a063c9103..228f1feda50d6010afa6cf576ca17a8f3d8c0456 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/ViewEndpointUnitTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/endpoint/ViewEndpointUnitTest.java @@ -98,7 +98,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException { /* test */ - findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_READ_ACCESS); + findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test @@ -107,7 +107,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException { /* test */ - findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_WRITE_OWN_ACCESS); + findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS); } @Test @@ -116,7 +116,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException { /* test */ - findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_WRITE_ALL_ACCESS); + findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -125,7 +125,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException { /* test */ - findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_WRITE_ALL_ACCESS); + findAll_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); } @@ -163,7 +163,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_READ_ACCESS); + create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); }); } @@ -173,7 +173,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_WRITE_OWN_ACCESS); + create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS); }); } @@ -183,7 +183,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_WRITE_ALL_ACCESS); + create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); }); } @@ -193,7 +193,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException, DatabaseConnectionException, ViewMalformedException, QueryMalformedException { /* test */ - create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_WRITE_ALL_ACCESS); + create_generic(CONTAINER_1_ID, DATABASE_1_ID, DATABASE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -219,7 +219,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException, ViewNotFoundException { /* test */ - find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_READ_ACCESS); + find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test @@ -228,7 +228,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException, ViewNotFoundException { /* test */ - find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_WRITE_OWN_ACCESS); + find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS); } @Test @@ -237,7 +237,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException, ViewNotFoundException { /* test */ - find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_WRITE_ALL_ACCESS); + find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -246,7 +246,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException, ViewNotFoundException { /* test */ - find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_WRITE_ALL_ACCESS); + find_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -283,7 +283,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_READ_ACCESS); + delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); }); } @@ -293,7 +293,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_WRITE_OWN_ACCESS); + delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS); }); } @@ -303,7 +303,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_WRITE_ALL_ACCESS); + delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); }); } @@ -314,7 +314,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { QueryMalformedException { /* test */ - delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_WRITE_ALL_ACCESS); + delete_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -346,7 +346,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { ContainerNotFoundException, PaginationException, ViewMalformedException { /* test */ - data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_READ_ACCESS); + data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test @@ -357,7 +357,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { ContainerNotFoundException, PaginationException, ViewMalformedException { /* test */ - data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_WRITE_OWN_ACCESS); + data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_OWN_ACCESS); } @Test @@ -368,7 +368,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { ContainerNotFoundException, PaginationException, ViewMalformedException { /* test */ - data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_WRITE_ALL_ACCESS); + data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -379,7 +379,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { ContainerNotFoundException, PaginationException, ViewMalformedException { /* test */ - data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_WRITE_ALL_ACCESS); + data_generic(CONTAINER_1_ID, DATABASE_1_ID, VIEW_1_ID, DATABASE_1, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_1_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -410,7 +410,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException { /* test */ - findAll_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_READ_ACCESS); + findAll_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test @@ -418,7 +418,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException { /* test */ - findAll_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_WRITE_OWN_ACCESS); + findAll_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS); } @Test @@ -426,7 +426,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException { /* test */ - findAll_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_WRITE_ALL_ACCESS); + findAll_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -434,7 +434,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException { /* test */ - findAll_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_2_WRITE_ALL_ACCESS); + findAll_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -451,7 +451,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - create_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_3_USERNAME, USER_3_PRINCIPAL, DATABASE_2_READ_ACCESS); + create_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_3_USERNAME, USER_3_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); }); } @@ -460,7 +460,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - create_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_3_USERNAME, USER_3_PRINCIPAL, DATABASE_2_WRITE_OWN_ACCESS); + create_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_3_USERNAME, USER_3_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS); }); } @@ -469,7 +469,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - create_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_3_WRITE_ALL_ACCESS); + create_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_3_RESEARCHER_WRITE_ALL_ACCESS); }); } @@ -478,7 +478,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException, DatabaseConnectionException, ViewMalformedException, QueryMalformedException { /* test */ - create_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_WRITE_ALL_ACCESS); + create_generic(CONTAINER_2_ID, DATABASE_2_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -494,7 +494,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException, ViewNotFoundException { /* test */ - find_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_READ_ACCESS); + find_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test @@ -502,7 +502,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException, ViewNotFoundException { /* test */ - find_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_WRITE_OWN_ACCESS); + find_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS); } @Test @@ -510,7 +510,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException, ViewNotFoundException { /* test */ - find_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_WRITE_ALL_ACCESS); + find_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -518,7 +518,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { DatabaseNotFoundException, ViewNotFoundException { /* test */ - find_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_2_WRITE_ALL_ACCESS); + find_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -535,7 +535,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - delete_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_READ_ACCESS); + delete_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); }); } @@ -544,7 +544,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - delete_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_WRITE_OWN_ACCESS); + delete_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS); }); } @@ -553,7 +553,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { /* test */ assertThrows(NotAllowedException.class, () -> { - delete_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_WRITE_ALL_ACCESS); + delete_generic(CONTAINER_3_ID, DATABASE_3_ID, VIEW_1_ID, DATABASE_3, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); }); } @@ -563,7 +563,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { QueryMalformedException { /* test */ - delete_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_WRITE_ALL_ACCESS); + delete_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -583,7 +583,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { ContainerNotFoundException, PaginationException, ViewMalformedException { /* test */ - data_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_READ_ACCESS); + data_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_READ_ACCESS); } @Test @@ -593,7 +593,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { ContainerNotFoundException, PaginationException, ViewMalformedException { /* test */ - data_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_WRITE_OWN_ACCESS); + data_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_OWN_ACCESS); } @Test @@ -603,7 +603,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { ContainerNotFoundException, PaginationException, ViewMalformedException { /* test */ - data_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_WRITE_ALL_ACCESS); + data_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_2_USERNAME, USER_2_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); } @Test @@ -613,7 +613,7 @@ public class ViewEndpointUnitTest extends BaseUnitTest { ContainerNotFoundException, PaginationException, ViewMalformedException { /* test */ - data_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_2_WRITE_ALL_ACCESS); + data_generic(CONTAINER_2_ID, DATABASE_2_ID, VIEW_1_ID, DATABASE_2, USER_1_USERNAME, USER_1_PRINCIPAL, DATABASE_2_RESEARCHER_WRITE_ALL_ACCESS); } /* ################################################################################################### */ diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/listener/RabbitMqListenerIntegrationTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/listener/RabbitMqListenerIntegrationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..84b278ad273abe5180df23c724829b0da2da14c3 --- /dev/null +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/listener/RabbitMqListenerIntegrationTest.java @@ -0,0 +1,133 @@ +package at.tuwien.listener; + +import at.tuwien.BaseUnitTest; +import at.tuwien.api.amqp.ConsumerDto; +import at.tuwien.config.*; +import at.tuwien.repository.jpa.*; +import com.rabbitmq.client.BuiltinExchangeType; +import com.rabbitmq.client.Channel; +import lombok.extern.log4j.Log4j2; +import org.junit.Rule; +import org.junit.jupiter.api.*; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.rules.Timeout; +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.ActiveProfiles; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import java.io.IOException; +import java.util.*; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.assertEquals; + + +@Log4j2 +@ActiveProfiles(profiles = "junit") +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@SpringBootTest +@ExtendWith(SpringExtension.class) +public class RabbitMqListenerIntegrationTest extends BaseUnitTest { + + @MockBean + private ReadyConfig readyConfig; + + @MockBean + private IndexConfig indexConfig; + + @Autowired + private Channel channel; + + @Autowired + private ImageRepository imageRepository; + + @Autowired + private ContainerRepository containerRepository; + + @Autowired + private DatabaseRepository databaseRepository; + + @Autowired + private TableRepository tableRepository; + + @Autowired + private H2Utils h2Utils; + + @Autowired + private RabbitMqConfig rabbitMqConfig; + + @Autowired + private AmqpConfig amqpConfig; + + @Rule + public Timeout globalTimeout = Timeout.seconds(300); + + @BeforeAll + public static void beforeAll() throws InterruptedException { + afterAll(); + /* create networks */ + DockerConfig.createAllNetworks(); + /* create containers */ + DockerConfig.createContainer(null, CONTAINER_BROKER, 15672, CONTAINER_BROKER_ENV); + DockerConfig.startContainer(CONTAINER_BROKER); + } + + @AfterAll + public static void afterAll() { + DockerConfig.removeAllContainers(); + DockerConfig.removeAllNetworks(); + } + + @BeforeEach + public void beforeEach() { + /* metadata database */ + h2Utils.runScript("schema.sql"); + imageRepository.save(IMAGE_1); + containerRepository.save(CONTAINER_1); + DATABASE_1.setTables(List.of()); + databaseRepository.save(DATABASE_1); + DATABASE_1.setTables(List.of(TABLE_1, TABLE_2, TABLE_3)); + tableRepository.save(TABLE_1_NOCOLS); + tableRepository.save(TABLE_2_NOCOLS); + tableRepository.save(TABLE_3_NOCOLS); + } + + @Test + @Disabled("Not testable") + public void updateConsumers_succeeds() throws IOException, InterruptedException { + + /* pre-condition */ + assertEquals(0, getConsumers().size()); + assertEquals(2, amqpConfig.getAmqpConsumers()); + + /* mock */ + channel.exchangeDeclare(DATABASE_1_EXCHANGE, BuiltinExchangeType.FANOUT); + channel.queueDeclare(TABLE_1_QUEUE_NAME, true, false, false, null); + channel.queueBind(TABLE_1_QUEUE_NAME, DATABASE_1_EXCHANGE, TABLE_1_ROUTING_KEY); + channel.queueDeclare(TABLE_2_QUEUE_NAME, true, false, false, null); + channel.queueBind(TABLE_2_QUEUE_NAME, DATABASE_1_EXCHANGE, TABLE_2_ROUTING_KEY); + channel.queueDeclare(TABLE_3_QUEUE_NAME, true, false, false, null); + channel.queueBind(TABLE_3_QUEUE_NAME, DATABASE_1_EXCHANGE, TABLE_3_ROUTING_KEY); + + /* test */ + Thread.sleep(30 * 1000) /* wait for scheduled insert */; + final List<ConsumerDto> response = getConsumers(); + final List<ConsumerDto> consumers1 = response.stream().filter(c -> c.getQueue().getName().equals(TABLE_1_QUEUE_NAME)).collect(Collectors.toList()); + assertEquals(2, consumers1.size()); + final List<ConsumerDto> consumers2 = response.stream().filter(c -> c.getQueue().getName().equals(TABLE_2_QUEUE_NAME)).collect(Collectors.toList()); + assertEquals(2, consumers2.size()); + final List<ConsumerDto> consumers3 = response.stream().filter(c -> c.getQueue().getName().equals(TABLE_3_QUEUE_NAME)).collect(Collectors.toList()); + assertEquals(2, consumers3.size()); + } + + private List<ConsumerDto> getConsumers() throws IOException { + return rabbitMqConfig.findAllConsumers() + .stream() + .filter(c -> List.of(TABLE_1_QUEUE_NAME, TABLE_2_QUEUE_NAME, TABLE_3_QUEUE_NAME).contains(c.getQueue().getName())) + .collect(Collectors.toList()); + } + +} diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/repository/ViewIdxRepositoryIntegrationTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/repository/ViewIdxRepositoryIntegrationTest.java index bd9644c6f5f834ccaea2249225afde6e27ec392a..292a52bdc72cf19190ea43133f6be46dd29d555d 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/repository/ViewIdxRepositoryIntegrationTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/repository/ViewIdxRepositoryIntegrationTest.java @@ -3,7 +3,6 @@ package at.tuwien.repository; import at.tuwien.BaseUnitTest; import at.tuwien.api.database.ViewCreateDto; import at.tuwien.api.database.ViewDto; -import at.tuwien.config.DockerConfig; import at.tuwien.config.ReadyConfig; import at.tuwien.entities.database.View; import at.tuwien.exception.*; @@ -13,7 +12,9 @@ import at.tuwien.listener.impl.RabbitMqListenerImpl; import at.tuwien.repository.elastic.ViewIdxRepository; import at.tuwien.repository.jpa.*; import at.tuwien.service.ViewService; +import at.tuwien.test.BaseTest; import com.rabbitmq.client.Channel; +import at.tuwien.config.DockerConfig; import lombok.extern.log4j.Log4j2; import org.junit.Rule; import org.junit.jupiter.api.AfterAll; @@ -29,7 +30,8 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringExtension; import java.io.File; -import java.util.*; +import java.util.List; +import java.util.Optional; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; @@ -74,7 +76,7 @@ public class ViewIdxRepositoryIntegrationTest extends BaseUnitTest { @Rule public Timeout globalTimeout = Timeout.seconds(60); - static final String BIND = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + static final String BIND_WEATHER = new File("../../dbrepo-metadata-db/test/src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; @BeforeAll public static void beforeAll() throws InterruptedException { @@ -82,10 +84,10 @@ public class ViewIdxRepositoryIntegrationTest extends BaseUnitTest { /* create network */ DockerConfig.createAllNetworks(); /* create elastic search */ - DockerConfig.createContainer(null, CONTAINER_ELASTIC, IMAGE_ELASTIC_ENV); + DockerConfig.createContainer(null, CONTAINER_ELASTIC, CONTAINER_ELASTIC_ENV); DockerConfig.startContainer(CONTAINER_ELASTIC); /* create container */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); DockerConfig.startContainer(CONTAINER_1); } diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/repository/ViewRepositoryIntegrationTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/repository/ViewRepositoryIntegrationTest.java index eddcffdc8e9e12dc638394e60ef7849286f684c0..c1cf0fbd1618b3615f1519ff625e7264e3498004 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/repository/ViewRepositoryIntegrationTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/repository/ViewRepositoryIntegrationTest.java @@ -6,7 +6,6 @@ import at.tuwien.config.IndexConfig; import at.tuwien.config.ReadyConfig; import at.tuwien.entities.database.View; import at.tuwien.gateway.BrokerServiceGateway; -import at.tuwien.listener.MessageQueueListener; import at.tuwien.listener.impl.RabbitMqListenerImpl; import at.tuwien.repository.jpa.*; import com.rabbitmq.client.Channel; diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/QueryServiceIntegrationTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/QueryServiceIntegrationTest.java index 32e8364efbbf3900c25225d4c20e780e22217189..3aa94579fa6bcda0b2ff8858004a569acdc67e75 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/QueryServiceIntegrationTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/QueryServiceIntegrationTest.java @@ -5,7 +5,6 @@ import at.tuwien.ExportResource; import at.tuwien.api.database.query.ExecuteStatementDto; import at.tuwien.api.database.query.QueryResultDto; import at.tuwien.api.database.table.TableCsvDto; -import at.tuwien.config.DockerConfig; import at.tuwien.config.IndexConfig; import at.tuwien.config.MariaDbConfig; import at.tuwien.config.ReadyConfig; @@ -16,6 +15,7 @@ import at.tuwien.listener.impl.RabbitMqListenerImpl; import at.tuwien.querystore.Query; import at.tuwien.repository.jpa.*; import com.rabbitmq.client.Channel; +import at.tuwien.config.DockerConfig; import lombok.SneakyThrows; import lombok.extern.log4j.Log4j2; import org.junit.Rule; @@ -81,9 +81,9 @@ public class QueryServiceIntegrationTest extends BaseUnitTest { @Rule public Timeout globalTimeout = Timeout.seconds(60); - private final static String BIND_WEATHER = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + private final static String BIND_WEATHER = new File("../../dbrepo-metadata-db/test/src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; - private final static String BIND_ZOO = new File("./src/test/resources/zoo").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + private final static String BIND_ZOO = new File("../../dbrepo-metadata-db/test/src/test/resources/zoo").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; @BeforeAll public static void beforeAll() { @@ -106,6 +106,7 @@ public class QueryServiceIntegrationTest extends BaseUnitTest { /* metadata database */ DATABASE_1.setTables(List.of(TABLE_1, TABLE_2, TABLE_3, TABLE_7)); TABLE_1.setDatabase(DATABASE_1); + TABLE_1.setColumns(TABLE_1_COLUMNS); TABLE_2.setDatabase(DATABASE_1); TABLE_3.setDatabase(DATABASE_1); TABLE_7.setDatabase(DATABASE_1); @@ -251,8 +252,10 @@ public class QueryServiceIntegrationTest extends BaseUnitTest { DatabaseConnectionException, DatabaseNotFoundException, ImageNotSupportedException, ContainerNotFoundException, InterruptedException { final TableCsvDto request = TableCsvDto.builder() - .data(Map.of("timestamp", "2023-02-10 12:15:20")) - .build(); + .data(new HashMap<>() {{ + put("timestamp", "2023-02-10 12:15:20"); + put("value", 12.3); + }}).build(); /* mock */ DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); @@ -271,8 +274,10 @@ public class QueryServiceIntegrationTest extends BaseUnitTest { DatabaseConnectionException, DatabaseNotFoundException, ImageNotSupportedException, ContainerNotFoundException, InterruptedException { final TableCsvDto request = TableCsvDto.builder() - .data(Map.of("timestamp", "2023-02-10 12:15:20.613405")) - .build(); + .data(new HashMap<>() {{ + put("timestamp", "2023-02-10 12:15:20.613405"); + put("value", null); + }}).build(); /* mock */ DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); @@ -293,7 +298,7 @@ public class QueryServiceIntegrationTest extends BaseUnitTest { final TableCsvDto request = TableCsvDto.builder() .data(Map.of("id", 4L, "date", "2008-12-04", - "location", "Melbourne", + "location", "Albury" /* the constraint -> weather_location (location) */, "mintemp", 5, "rainfall", 0)) .build(); @@ -480,7 +485,7 @@ public class QueryServiceIntegrationTest extends BaseUnitTest { assertEquals(1L, response.getResultNumber()); assertNotNull(response.getResult()); final List<Map<String, Object>> result = response.getResult(); - assertEquals("Melbourne", result.get(0).get("location")); + assertEquals("Vienna", result.get(0).get("location")); assertNull(result.get(0).get("lat")); assertNull(result.get(0).get("lng")); } @@ -507,7 +512,7 @@ public class QueryServiceIntegrationTest extends BaseUnitTest { assertEquals(1L, response.getResultNumber()); assertNotNull(response.getResult()); final List<Map<String, Object>> result = response.getResult(); - assertEquals("Melbourne", result.get(0).get("location")); + assertEquals("Vienna", result.get(0).get("location")); assertNull(result.get(0).get("lat")); assertNull(result.get(0).get("lng")); } diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/QueueServiceIntegrationTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/QueueServiceIntegrationTest.java index eed98297653d5f527f7a4604b00a68b84bff61e6..544d271a72a9d0b360a94fc55ef5c33742ab7c4d 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/QueueServiceIntegrationTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/QueueServiceIntegrationTest.java @@ -79,15 +79,15 @@ public class QueueServiceIntegrationTest extends BaseUnitTest { @Autowired private MessageQueueService messageQueueService; - private final static String BIND = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + private final static String BIND_WEATHER = new File("../../dbrepo-metadata-db/test/src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; @BeforeAll public static void beforeAll() throws InterruptedException { afterAll(); DockerConfig.createAllNetworks(); - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); - DockerConfig.startContainer(CONTAINER_1); - DockerConfig.createContainer(null, CONTAINER_BROKER, 15672, CONTAINER_BROKER_ENV); + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_3, CONTAINER_3_ENV); + DockerConfig.startContainer(CONTAINER_3); + DockerConfig.createContainer(null, CONTAINER_BROKER, CONTAINER_BROKER_ENV); DockerConfig.startContainer(CONTAINER_BROKER); } @@ -99,20 +99,20 @@ public class QueueServiceIntegrationTest extends BaseUnitTest { @BeforeEach public void beforeEach() throws IOException, TimeoutException { - TABLE_1.setDatabase(DATABASE_1); + TABLE_8.setDatabase(DATABASE_3); /* rabbitmq */ final Connection connection = amqpConfig.connectionFactory().newConnection(); this.channel = connection.createChannel(); - channel.exchangeDeclare(DATABASE_1_EXCHANGE, BuiltinExchangeType.FANOUT); - channel.queueDeclare(TABLE_1_QUEUE_NAME, true, false, false, null); - channel.queueBind(TABLE_1_QUEUE_NAME, DATABASE_1_EXCHANGE, TABLE_1_ROUTING_KEY); + channel.exchangeDeclare(DATABASE_3_EXCHANGE, BuiltinExchangeType.FANOUT); + channel.queueDeclare(TABLE_8_QUEUE_NAME, true, false, false, null); + channel.queueBind(TABLE_8_QUEUE_NAME, DATABASE_3_EXCHANGE, TABLE_8_ROUTING_KEY); } @Test public void createConsumer_succeeds() throws AmqpException { /* test */ - messageQueueService.createConsumer(TABLE_1_QUEUE_NAME, CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); + messageQueueService.createConsumer(TABLE_8_QUEUE_NAME, CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID); } @Test @@ -122,13 +122,13 @@ public class QueueServiceIntegrationTest extends BaseUnitTest { channel.close(); /* test */ - messageQueueService.createConsumer(TABLE_1_QUEUE_NAME, CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); + messageQueueService.createConsumer(TABLE_8_QUEUE_NAME, CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID); } @Test public void insert_succeeds() throws IOException, AmqpException { final AMQP.BasicProperties basicProperties = new AMQP.BasicProperties.Builder() - .userId(USER_1_USERNAME) + .userId(USER_BROKER_USERNAME) .build(); final TableCsvDto payload = TableCsvDto.builder() .data(new HashMap<>() {{ @@ -140,18 +140,18 @@ public class QueueServiceIntegrationTest extends BaseUnitTest { }}).build(); /* mock */ - when(databaseRepository.findByContainerIdAndDatabaseId(CONTAINER_1_ID, DATABASE_1_ID)) - .thenReturn(Optional.of(DATABASE_1)); - when(tableRepository.find(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID)) - .thenReturn(Optional.of(TABLE_1)); + when(databaseRepository.findByContainerIdAndDatabaseId(CONTAINER_3_ID, DATABASE_3_ID)) + .thenReturn(Optional.of(DATABASE_3)); + when(tableRepository.find(CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID)) + .thenReturn(Optional.of(TABLE_8)); doThrow(IOException.class) .when(rabbitMqConsumer) .handleDelivery(anyString(), any(Envelope.class), any(AMQP.BasicProperties.class), any()); - messageQueueService.createConsumer(TABLE_1_QUEUE_NAME, CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); + messageQueueService.createConsumer(TABLE_8_QUEUE_NAME, CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID); /* test */ - channel.basicPublish(DATABASE_1_EXCHANGE, TABLE_1_ROUTING_KEY, basicProperties, objectMapper.writeValueAsBytes(payload)); - final GetResponse response = channel.basicGet(TABLE_1_QUEUE_NAME, false); + channel.basicPublish(DATABASE_3_EXCHANGE, TABLE_8_ROUTING_KEY, basicProperties, objectMapper.writeValueAsBytes(payload)); + final GetResponse response = channel.basicGet(TABLE_8_QUEUE_NAME, false); assertNull(response) /* queue is empty */; } @@ -162,17 +162,17 @@ public class QueueServiceIntegrationTest extends BaseUnitTest { .build(); /* mock */ - when(databaseRepository.findByContainerIdAndDatabaseId(CONTAINER_1_ID, DATABASE_1_ID)) - .thenReturn(Optional.of(DATABASE_1)); - when(tableRepository.find(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID)) - .thenReturn(Optional.of(TABLE_1)); + when(databaseRepository.findByContainerIdAndDatabaseId(CONTAINER_3_ID, DATABASE_3_ID)) + .thenReturn(Optional.of(DATABASE_3)); + when(tableRepository.find(CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID)) + .thenReturn(Optional.of(TABLE_8)); doThrow(IOException.class) .when(rabbitMqConsumer) .handleDelivery(anyString(), any(Envelope.class), any(AMQP.BasicProperties.class), any()); - messageQueueService.createConsumer(TABLE_1_QUEUE_NAME, CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); + messageQueueService.createConsumer(TABLE_8_QUEUE_NAME, CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID); /* test */ - channel.basicPublish(DATABASE_1_EXCHANGE, TABLE_1_ROUTING_KEY, basicProperties, objectMapper.writeValueAsBytes(TABLE_1_CSV_DTO)); + channel.basicPublish(DATABASE_3_EXCHANGE, TABLE_8_ROUTING_KEY, basicProperties, objectMapper.writeValueAsBytes(TABLE_8_CSV_DTO)); } @Test @@ -182,17 +182,17 @@ public class QueueServiceIntegrationTest extends BaseUnitTest { .build(); /* mock */ - when(databaseRepository.findByContainerIdAndDatabaseId(CONTAINER_1_ID, DATABASE_1_ID)) - .thenReturn(Optional.of(DATABASE_1)); - when(tableRepository.find(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID)) - .thenReturn(Optional.of(TABLE_1)); + when(databaseRepository.findByContainerIdAndDatabaseId(CONTAINER_3_ID, DATABASE_3_ID)) + .thenReturn(Optional.of(DATABASE_3)); + when(tableRepository.find(CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID)) + .thenReturn(Optional.of(TABLE_8)); doThrow(IOException.class) .when(rabbitMqConsumer) .handleDelivery(anyString(), any(Envelope.class), any(AMQP.BasicProperties.class), any()); - messageQueueService.createConsumer(TABLE_1_QUEUE_NAME, CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID); + messageQueueService.createConsumer(TABLE_8_QUEUE_NAME, CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID); /* test */ - channel.basicPublish(DATABASE_1_EXCHANGE, TABLE_1_ROUTING_KEY, basicProperties, objectMapper.writeValueAsBytes(TABLE_1_CSV_DTO)); + channel.basicPublish(DATABASE_3_EXCHANGE, TABLE_8_ROUTING_KEY, basicProperties, objectMapper.writeValueAsBytes(TABLE_8_CSV_DTO)); } @Test diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationModifyTest.java similarity index 82% rename from dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationTest.java rename to dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationModifyTest.java index eb694845ebf851da701cce168c4f36a7178b1ae2..e3ce2fde0edc29217ec55ecb7d02f0ff150174e2 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationModifyTest.java @@ -3,18 +3,16 @@ package at.tuwien.service; import at.tuwien.BaseUnitTest; import at.tuwien.api.database.query.ExecuteStatementDto; import at.tuwien.api.database.query.QueryResultDto; -import at.tuwien.config.DockerConfig; import at.tuwien.config.IndexConfig; import at.tuwien.config.MariaDbConfig; import at.tuwien.config.ReadyConfig; import at.tuwien.exception.*; -import at.tuwien.entities.database.Database; import at.tuwien.gateway.BrokerServiceGateway; -import at.tuwien.listener.MessageQueueListener; import at.tuwien.listener.impl.RabbitMqListenerImpl; import at.tuwien.querystore.Query; import at.tuwien.repository.jpa.*; import com.rabbitmq.client.Channel; +import at.tuwien.config.DockerConfig; import lombok.extern.log4j.Log4j2; import org.apache.http.auth.BasicUserPrincipal; import org.junit.jupiter.api.*; @@ -34,7 +32,6 @@ import java.time.temporal.ChronoUnit; import java.util.Map; import java.util.Optional; -import static java.time.temporal.ChronoUnit.HOURS; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.when; @@ -43,7 +40,7 @@ import static org.mockito.Mockito.when; @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) @ExtendWith(SpringExtension.class) @SpringBootTest -public class StoreServiceIntegrationTest extends BaseUnitTest { +public class StoreServiceIntegrationModifyTest extends BaseUnitTest { @MockBean private ReadyConfig readyConfig; @@ -74,26 +71,11 @@ public class StoreServiceIntegrationTest extends BaseUnitTest { @Autowired private StoreService storeService; - final static String BIND = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + final static String BIND_WEATHER = new File("../../dbrepo-metadata-db/test/src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; @Autowired private QueryService queryService; - final static Database DATABASE_1 = Database.builder() /* overlaps the DATABASE_1 without tables set */ - .id(DATABASE_1_ID) - .created(Instant.now().minus(1, HOURS)) - .lastModified(Instant.now()) - .isPublic(true) - .name(DATABASE_1_NAME) - .container(CONTAINER_1) - .internalName(DATABASE_1_INTERNALNAME) - .exchangeName(DATABASE_1_EXCHANGE) - .creator(USER_1) - .owner(USER_1) - .tables(List.of(TABLE_1, TABLE_2, TABLE_3)) - .views(List.of()) - .build(); - @BeforeAll public static void beforeAll() { afterAll(); @@ -106,10 +88,12 @@ public class StoreServiceIntegrationTest extends BaseUnitTest { /* create networks */ DockerConfig.createAllNetworks(); /* create containers */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); DockerConfig.startContainer(CONTAINER_1); /* metadata database */ - TABLE_1.setDatabase(DATABASE_1); + userRepository.save(USER_5); + DATABASE_1.setTables(List.of(TABLE_1, TABLE_2, TABLE_3, TABLE_7)); + DATABASE_1.setViews(List.of(VIEW_3)); } @AfterAll @@ -124,38 +108,9 @@ public class StoreServiceIntegrationTest extends BaseUnitTest { DockerConfig.removeAllNetworks(); } - @Test - public void findAll_succeeds() throws UserNotFoundException, QueryStoreException, DatabaseConnectionException, - DatabaseNotFoundException, ImageNotSupportedException, TableMalformedException, ContainerNotFoundException, SQLException { - - /* mock */ - when(databaseRepository.findByContainerIdAndDatabaseId(CONTAINER_1_ID, DATABASE_1_ID)) - .thenReturn(Optional.of(DATABASE_1)); - MariaDbConfig.insertQueryStore(CONTAINER_1_INTERNALNAME, DATABASE_1_INTERNALNAME, QUERY_1, USER_1_USERNAME); - - /* test */ - final List<Query> queries = storeService.findAll(CONTAINER_1_ID, DATABASE_1_ID, null, USER_1_PRINCIPAL); - assertEquals(1, queries.size()); - } - - @Test - public void findAll_filterPersisted_succeeds() throws UserNotFoundException, QueryStoreException, DatabaseConnectionException, - DatabaseNotFoundException, ImageNotSupportedException, TableMalformedException, ContainerNotFoundException, SQLException { - - /* mock */ - when(databaseRepository.findByContainerIdAndDatabaseId(CONTAINER_1_ID, DATABASE_1_ID)) - .thenReturn(Optional.of(DATABASE_1)); - MariaDbConfig.insertQueryStore(CONTAINER_1_INTERNALNAME, DATABASE_1_INTERNALNAME, QUERY_1, USER_1_USERNAME); - MariaDbConfig.insertQueryStore(CONTAINER_1_INTERNALNAME, DATABASE_1_INTERNALNAME, QUERY_2, USER_1_USERNAME); - - /* test */ - final List<Query> queries = storeService.findAll(CONTAINER_1_ID, DATABASE_1_ID, true, USER_1_PRINCIPAL); - assertEquals(1, queries.size()); - } - @Test public void insert_same_succeeds() throws UserNotFoundException, QueryStoreException, - DatabaseConnectionException, TableMalformedException, DatabaseNotFoundException, ImageNotSupportedException, + DatabaseConnectionException, DatabaseNotFoundException, ImageNotSupportedException, ContainerNotFoundException, SQLException { final ExecuteStatementDto request = ExecuteStatementDto.builder() .statement(QUERY_2_STATEMENT) @@ -297,7 +252,7 @@ public class StoreServiceIntegrationTest extends BaseUnitTest { @Test public void insert_timestamp_succeeds() throws UserNotFoundException, QueryStoreException, - DatabaseConnectionException, TableMalformedException, DatabaseNotFoundException, ImageNotSupportedException, + DatabaseConnectionException, DatabaseNotFoundException, ImageNotSupportedException, ContainerNotFoundException { final ExecuteStatementDto request = ExecuteStatementDto.builder() .statement(QUERY_1_STATEMENT) @@ -316,15 +271,15 @@ public class StoreServiceIntegrationTest extends BaseUnitTest { @Test public void insert_anonymous_succeeds() throws UserNotFoundException, QueryStoreException, - DatabaseConnectionException, TableMalformedException, DatabaseNotFoundException, ImageNotSupportedException, + DatabaseConnectionException, DatabaseNotFoundException, ImageNotSupportedException, ContainerNotFoundException { final ExecuteStatementDto request = ExecuteStatementDto.builder() .statement(QUERY_1_STATEMENT) .build(); /* mock */ - when(userRepository.findByUsername(USER_3_USERNAME)) - .thenReturn(Optional.of(USER_3)); + when(userRepository.findByUsername(USER_5_USERNAME)) + .thenReturn(Optional.of(USER_5)); when(databaseRepository.findByContainerIdAndDatabaseId(CONTAINER_1_ID, DATABASE_1_ID)) .thenReturn(Optional.of(DATABASE_1)); diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationReadTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationReadTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d46ed5511838620cf06c3d156e9f8ed67bbab466 --- /dev/null +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/StoreServiceIntegrationReadTest.java @@ -0,0 +1,156 @@ +package at.tuwien.service; + +import at.tuwien.BaseUnitTest; +import at.tuwien.config.IndexConfig; +import at.tuwien.config.MariaDbConfig; +import at.tuwien.config.ReadyConfig; +import at.tuwien.exception.*; +import at.tuwien.listener.impl.RabbitMqListenerImpl; +import at.tuwien.querystore.Query; +import at.tuwien.repository.jpa.DatabaseRepository; +import at.tuwien.repository.jpa.TableRepository; +import at.tuwien.repository.jpa.UserRepository; +import com.rabbitmq.client.Channel; +import at.tuwien.config.DockerConfig; +import lombok.extern.log4j.Log4j2; +import org.apache.http.auth.BasicUserPrincipal; +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.context.junit.jupiter.SpringExtension; + +import java.io.File; +import java.security.Principal; +import java.sql.SQLException; +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.when; + +@Log4j2 +@ExtendWith(SpringExtension.class) +@SpringBootTest +public class StoreServiceIntegrationReadTest extends BaseUnitTest { + + @MockBean + private ReadyConfig readyConfig; + + @MockBean + private IndexConfig indexConfig; + + @MockBean + private Channel channel; + + @MockBean + private RabbitMqListenerImpl rabbitMqListener; + + @MockBean + private TableRepository tableRepository; + + @MockBean + private UserRepository userRepository; + + @MockBean + private DatabaseRepository databaseRepository; + + @Autowired + private StoreService storeService; + + final static String BIND_WEATHER = new File("../../dbrepo-metadata-db/test/src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + + @BeforeAll + public static void beforeAll() throws InterruptedException, SQLException { + afterAll(); + /* create networks */ + DockerConfig.createAllNetworks(); + /* create user container */ + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.startContainer(CONTAINER_1); + /* insert query */ + MariaDbConfig.insertQueryStore(CONTAINER_1_INTERNALNAME, DATABASE_1_INTERNALNAME, QUERY_1, USER_1_USERNAME); + } + + @BeforeEach + public void beforeEach() { + /* metadata database */ + userRepository.save(USER_5); + DATABASE_1.setTables(List.of(TABLE_1, TABLE_2, TABLE_3, TABLE_7)); + DATABASE_1.setViews(List.of(VIEW_3)); + } + + @AfterAll + public static void afterAll() { + DockerConfig.removeAllContainers(); + DockerConfig.removeAllNetworks(); + } + + @Test + public void findAll_succeeds() throws UserNotFoundException, QueryStoreException, DatabaseConnectionException, + DatabaseNotFoundException, ImageNotSupportedException, TableMalformedException, ContainerNotFoundException { + + /* mock */ + when(databaseRepository.findByContainerIdAndDatabaseId(CONTAINER_1_ID, DATABASE_1_ID)) + .thenReturn(Optional.of(DATABASE_1)); + + /* test */ + final List<Query> queries = storeService.findAll(CONTAINER_1_ID, DATABASE_1_ID, null, USER_1_PRINCIPAL); + assertEquals(1, queries.size()); + } + + @Test + public void findAll_filterPersisted_succeeds() throws UserNotFoundException, QueryStoreException, DatabaseConnectionException, + DatabaseNotFoundException, ImageNotSupportedException, TableMalformedException, ContainerNotFoundException { + + /* mock */ + when(databaseRepository.findByContainerIdAndDatabaseId(CONTAINER_1_ID, DATABASE_1_ID)) + .thenReturn(Optional.of(DATABASE_1)); + + /* test */ + final List<Query> queries = storeService.findAll(CONTAINER_1_ID, DATABASE_1_ID, true, USER_1_PRINCIPAL); + assertEquals(0, queries.size()); + } + + @Test + public void findOne_succeeds() throws UserNotFoundException, QueryStoreException, + DatabaseConnectionException, QueryNotFoundException, DatabaseNotFoundException, ImageNotSupportedException { + + /* mock */ + when(databaseRepository.findByContainerIdAndDatabaseId(CONTAINER_1_ID, DATABASE_1_ID)) + .thenReturn(Optional.of(DATABASE_1)); + + /* test */ + storeService.findOne(CONTAINER_1_ID, DATABASE_1_ID, QUERY_1_ID, USER_1_PRINCIPAL); + } + + @Test + public void findOne_notFound_succeeds() { + + /* mock */ + when(databaseRepository.findByContainerIdAndDatabaseId(CONTAINER_1_ID, DATABASE_1_ID)) + .thenReturn(Optional.of(DATABASE_1)); + + /* test */ + assertThrows(QueryNotFoundException.class, () -> { + storeService.findOne(CONTAINER_1_ID, DATABASE_1_ID, 9999L, USER_1_PRINCIPAL); + }); + } + + @Test + public void findOne_notFound_fails() { + final Principal principal = new BasicUserPrincipal(USER_1_USERNAME); + + /* mock */ + when(databaseRepository.findByContainerIdAndDatabaseId(CONTAINER_1_ID, DATABASE_1_ID)) + .thenReturn(Optional.of(DATABASE_1)); + + /* test */ + assertThrows(QueryNotFoundException.class, () -> { + storeService.findOne(CONTAINER_1_ID, DATABASE_1_ID, QUERY_2_ID, principal); + }); + } + +} diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationReadTest.java similarity index 93% rename from dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java rename to dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationReadTest.java index 58f28e951351115b091d8a8240a6bf75e993638f..ed559e44234a96407aaab186b5e41735fff52fa8 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationReadTest.java @@ -2,28 +2,24 @@ package at.tuwien.service; import at.tuwien.BaseUnitTest; import at.tuwien.api.database.table.TableHistoryDto; -import at.tuwien.config.DockerConfig; import at.tuwien.config.H2Utils; import at.tuwien.config.IndexConfig; import at.tuwien.config.ReadyConfig; -import at.tuwien.entities.database.table.columns.TableColumn; import at.tuwien.exception.*; import at.tuwien.gateway.BrokerServiceGateway; -import at.tuwien.listener.MessageQueueListener; import at.tuwien.listener.impl.RabbitMqListenerImpl; 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.rabbitmq.client.Channel; +import at.tuwien.config.DockerConfig; import lombok.extern.log4j.Log4j2; -import org.junit.After; 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.http.HttpStatus; import org.springframework.security.test.context.support.WithAnonymousUser; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.annotation.DirtiesContext; @@ -41,7 +37,7 @@ import static org.mockito.Mockito.when; @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) @SpringBootTest @ExtendWith(SpringExtension.class) -public class TableServiceIntegrationTest extends BaseUnitTest { +public class TableServiceIntegrationReadTest extends BaseUnitTest { @MockBean private ReadyConfig readyConfig; @@ -78,15 +74,15 @@ public class TableServiceIntegrationTest extends BaseUnitTest { @Autowired private H2Utils h2Utils; - final static String BIND = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + final static String BIND_WEATHER = new File("../../dbrepo-metadata-db/test/src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; @BeforeAll public static void beforeAll() throws InterruptedException { afterAll(); /* create networks */ DockerConfig.createAllNetworks(); - /* start containers */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); + /* user container */ + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); DockerConfig.startContainer(CONTAINER_1); } @@ -100,6 +96,7 @@ public class TableServiceIntegrationTest extends BaseUnitTest { public void beforeEach() { /* metadata db */ h2Utils.runScript("schema.sql"); + /* metadata db */ imageRepository.save(IMAGE_1); containerRepository.save(CONTAINER_1); tableRepository.save(TABLE_1_NOCOLS); diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceUnitTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceUnitTest.java index 4a523c0a2325d56636b7519368b06a0027e39f25..7cbd93be7ff914ad0ecf4f3505b2d34afb42ae40 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceUnitTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/TableServiceUnitTest.java @@ -59,18 +59,15 @@ public class TableServiceUnitTest extends BaseUnitTest { public void findAll_succeeds() throws TableNotFoundException, DatabaseNotFoundException { /* mock */ - when(tableRepository.find(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID)) - .thenReturn(Optional.of(TABLE_1)); + when(tableRepository.find(CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID)) + .thenReturn(Optional.of(TABLE_8)); /* test */ - final List<TableColumn> response = tableService.find(CONTAINER_1_ID, DATABASE_1_ID, TABLE_1_ID) + final List<TableColumn> response = tableService.find(CONTAINER_3_ID, DATABASE_3_ID, TABLE_8_ID) .getColumns(); - assertEquals(5, response.size()); + assertEquals(2, response.size()); assertEquals("id", response.get(0).getInternalName()); - assertEquals("date", response.get(1).getInternalName()); - assertEquals("location", response.get(2).getInternalName()); - assertEquals("mintemp", response.get(3).getInternalName()); - assertEquals("rainfall", response.get(4).getInternalName()); + assertEquals("value", response.get(1).getInternalName()); } } diff --git a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/ViewServiceIntegrationTest.java b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/ViewServiceIntegrationTest.java index 29e074c8f21a6dd864d6e3c1a3504a588c6d0163..0f4b2f9f3fd6cd56b2c53fa04c18553b1bceebf8 100644 --- a/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/ViewServiceIntegrationTest.java +++ b/dbrepo-query-service/rest-service/src/test/java/at/tuwien/service/ViewServiceIntegrationTest.java @@ -3,7 +3,6 @@ package at.tuwien.service; import at.tuwien.BaseUnitTest; import at.tuwien.api.database.ViewCreateDto; import at.tuwien.api.database.ViewDto; -import at.tuwien.config.DockerConfig; import at.tuwien.config.IndexConfig; import at.tuwien.config.MariaDbConfig; import at.tuwien.config.ReadyConfig; @@ -14,6 +13,7 @@ import at.tuwien.listener.impl.RabbitMqListenerImpl; import at.tuwien.repository.elastic.ViewIdxRepository; import at.tuwien.repository.jpa.*; import com.rabbitmq.client.Channel; +import at.tuwien.config.DockerConfig; import lombok.extern.log4j.Log4j2; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -76,7 +76,7 @@ public class ViewServiceIntegrationTest extends BaseUnitTest { @Autowired private ViewService viewService; - final static String BIND = new File("./src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + final static String BIND_WEATHER = new File("../../dbrepo-metadata-db/test/src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; @BeforeAll public static void beforeAll() throws InterruptedException { @@ -84,7 +84,7 @@ public class ViewServiceIntegrationTest extends BaseUnitTest { /* create network */ DockerConfig.createAllNetworks(); /* create container */ - DockerConfig.createContainer(BIND, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); DockerConfig.startContainer(CONTAINER_1); } @@ -177,13 +177,13 @@ public class ViewServiceIntegrationTest extends BaseUnitTest { assertEquals("-36.0653583", row0.get("lat")); assertEquals("146.9112214", row0.get("lng")); final Map<String, String> row1 = resultSet.get(1); - assertEquals("Melbourne", row1.get("location")); - assertNull(row1.get("lat")); - assertNull(row1.get("lng")); + assertEquals("Sydney", row1.get("location")); + assertEquals("-33.847927", row1.get("lat")); + assertEquals("150.6517942", row1.get("lng")); final Map<String, String> row2 = resultSet.get(2); - assertEquals("Sydney", row2.get("location")); - assertEquals("-33.847927", row2.get("lat")); - assertEquals("150.6517942", row2.get("lng")); + assertEquals("Vienna", row2.get("location")); + assertNull(row2.get("lat")); + assertNull(row2.get("lng")); } } diff --git a/dbrepo-query-service/rest-service/src/test/resources/sensor/1_querystore.sql b/dbrepo-query-service/rest-service/src/test/resources/sensor/1_querystore.sql index 2762d130a0044c439b41c0215b0d87924bc8f072..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-query-service/rest-service/src/test/resources/sensor/1_querystore.sql +++ b/dbrepo-query-service/rest-service/src/test/resources/sensor/1_querystore.sql @@ -1,75 +0,0 @@ -CREATE SEQUENCE `qs_queries_seq`; -CREATE TABLE `qs_queries` -( - `id` bigint not null primary key default nextval(`qs_queries_seq`), - `created` datetime not null default now(), - `executed` datetime not null default now(), - `created_by` varchar(255) not null, - `query` text not null, - `query_normalized` text not null, - `is_persisted` boolean not null, - `query_hash` varchar(255) not null, - `result_hash` varchar(255), - `result_number` bigint -); -DELIMITER $$ -CREATE PROCEDURE hash_table(IN name VARCHAR(255), OUT hash VARCHAR(255)) -BEGIN - DECLARE _sql TEXT; - SELECT CONCAT('SELECT SHA2(GROUP_CONCAT(CONCAT_WS(\'\',', - GROUP_CONCAT(CONCAT('`', column_name, '`') ORDER BY column_name), - ') SEPARATOR \',\'), 256) AS hash FROM `', name, '` INTO @hash;') - FROM `information_schema`.`columns` - WHERE `table_schema` = DATABASE() - AND `table_name` = name - INTO _sql; - PREPARE stmt FROM _sql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; - SET hash = @hash; -END $$ -DELIMITER $$ -CREATE PROCEDURE store_query(IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) -BEGIN - DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); - DECLARE _username varchar(255) DEFAULT REGEXP_REPLACE(current_user(), '@.*', ''); - DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); - PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); - SELECT COUNT(*) FROM _tmp INTO @count; - IF @hash IS NULL THEN - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`, `executed`) - SELECT _username, query, query, false, _queryhash, @hash, @count, executed - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - ELSE - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`, `executed`) - SELECT _username, query, query, false, _queryhash, @hash, @count, executed - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - END IF; -END $$ -DELIMITER $$ -CREATE - DEFINER = 'root' PROCEDURE _store_query(IN _username VARCHAR(255), IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) -BEGIN - DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); - DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); - PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); - SELECT COUNT(*) FROM _tmp INTO @count; - IF @hash IS NULL THEN - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`, `executed`) - SELECT _username, query, query, false, _queryhash, @hash, @count, executed - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - ELSE - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`, `executed`) - SELECT _username, query, query, false, _queryhash, @hash, @count, executed - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - END IF; -END $$ -DELIMITER ; \ No newline at end of file diff --git a/dbrepo-query-service/rest-service/src/test/resources/sensor/2_traffic.sql b/dbrepo-query-service/rest-service/src/test/resources/sensor/2_traffic.sql index 93d293a6fe9ee11cbd662208a85089ac3f9fab99..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-query-service/rest-service/src/test/resources/sensor/2_traffic.sql +++ b/dbrepo-query-service/rest-service/src/test/resources/sensor/2_traffic.sql @@ -1,8 +0,0 @@ -CREATE SEQUENCE seq_sensor - START 1; - -CREATE TABLE sensor -( - `timestamp` TIMESTAMP NULL, - primary key (`timestamp`) -) with system versioning; \ No newline at end of file diff --git a/dbrepo-query-service/rest-service/src/test/resources/traffic/1_querystore.sql b/dbrepo-query-service/rest-service/src/test/resources/traffic/1_querystore.sql index 2762d130a0044c439b41c0215b0d87924bc8f072..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-query-service/rest-service/src/test/resources/traffic/1_querystore.sql +++ b/dbrepo-query-service/rest-service/src/test/resources/traffic/1_querystore.sql @@ -1,75 +0,0 @@ -CREATE SEQUENCE `qs_queries_seq`; -CREATE TABLE `qs_queries` -( - `id` bigint not null primary key default nextval(`qs_queries_seq`), - `created` datetime not null default now(), - `executed` datetime not null default now(), - `created_by` varchar(255) not null, - `query` text not null, - `query_normalized` text not null, - `is_persisted` boolean not null, - `query_hash` varchar(255) not null, - `result_hash` varchar(255), - `result_number` bigint -); -DELIMITER $$ -CREATE PROCEDURE hash_table(IN name VARCHAR(255), OUT hash VARCHAR(255)) -BEGIN - DECLARE _sql TEXT; - SELECT CONCAT('SELECT SHA2(GROUP_CONCAT(CONCAT_WS(\'\',', - GROUP_CONCAT(CONCAT('`', column_name, '`') ORDER BY column_name), - ') SEPARATOR \',\'), 256) AS hash FROM `', name, '` INTO @hash;') - FROM `information_schema`.`columns` - WHERE `table_schema` = DATABASE() - AND `table_name` = name - INTO _sql; - PREPARE stmt FROM _sql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; - SET hash = @hash; -END $$ -DELIMITER $$ -CREATE PROCEDURE store_query(IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) -BEGIN - DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); - DECLARE _username varchar(255) DEFAULT REGEXP_REPLACE(current_user(), '@.*', ''); - DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); - PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); - SELECT COUNT(*) FROM _tmp INTO @count; - IF @hash IS NULL THEN - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`, `executed`) - SELECT _username, query, query, false, _queryhash, @hash, @count, executed - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - ELSE - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`, `executed`) - SELECT _username, query, query, false, _queryhash, @hash, @count, executed - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - END IF; -END $$ -DELIMITER $$ -CREATE - DEFINER = 'root' PROCEDURE _store_query(IN _username VARCHAR(255), IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) -BEGIN - DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); - DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); - PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); - SELECT COUNT(*) FROM _tmp INTO @count; - IF @hash IS NULL THEN - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`, `executed`) - SELECT _username, query, query, false, _queryhash, @hash, @count, executed - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - ELSE - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`, `executed`) - SELECT _username, query, query, false, _queryhash, @hash, @count, executed - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - END IF; -END $$ -DELIMITER ; \ No newline at end of file diff --git a/dbrepo-query-service/rest-service/src/test/resources/traffic/2_traffic.sql b/dbrepo-query-service/rest-service/src/test/resources/traffic/2_traffic.sql index 3038fe5a7a99e882504fc8382a5bf2ba7763543d..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-query-service/rest-service/src/test/resources/traffic/2_traffic.sql +++ b/dbrepo-query-service/rest-service/src/test/resources/traffic/2_traffic.sql @@ -1,43 +0,0 @@ -/* https://www.kaggle.com/laa283/zurich-public-transport/version/2 */ -CREATE SEQUENCE seq_traffic - START 1; - -CREATE TABLE traffic_zurich -( - linie bigint null, - richtung bigint null, - betriebsdatum date null, - fahrzeug bigint null, - kurs bigint null, - seq_von bigint null, - halt_diva_von bigint null, - halt_punkt_diva_von bigint null, - halt_kurz_von1 varchar(255) null, - datum_von date null, - soll_an_von bigint null, - ist_an_von bigint null, - soll_ab_von bigint null, - ist_ab_von bigint null, - seq_nach bigint null, - halt_diva_nach bigint null, - halt_punkt_diva_nach bigint null, - halt_kurz_nach1 varchar(255) null, - datum_nach DATE null, - soll_an_nach bigint null, - ist_an_nach1 bigint null, - soll_ab_nach bigint null, - ist_ab_nach bigint null, - fahrt_id bigint null, - fahrweg_id bigint null, - fw_no bigint null, - fw_typ bigint null, - fw_kurz bigint null, - fw_lang varchar(255) null, - umlauf_von varchar(255) null, - halt_id_von bigint null, - halt_id_nach bigint null, - halt_punkt_id_von bigint null, - halt_punkt_id_nach bigint null, - id bigint default nextval(`seq_traffic`) not null, - primary key (id) -) with system versioning; \ No newline at end of file diff --git a/dbrepo-query-service/rest-service/src/test/resources/weather/1_querystore.sql b/dbrepo-query-service/rest-service/src/test/resources/weather/1_querystore.sql index 2762d130a0044c439b41c0215b0d87924bc8f072..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-query-service/rest-service/src/test/resources/weather/1_querystore.sql +++ b/dbrepo-query-service/rest-service/src/test/resources/weather/1_querystore.sql @@ -1,75 +0,0 @@ -CREATE SEQUENCE `qs_queries_seq`; -CREATE TABLE `qs_queries` -( - `id` bigint not null primary key default nextval(`qs_queries_seq`), - `created` datetime not null default now(), - `executed` datetime not null default now(), - `created_by` varchar(255) not null, - `query` text not null, - `query_normalized` text not null, - `is_persisted` boolean not null, - `query_hash` varchar(255) not null, - `result_hash` varchar(255), - `result_number` bigint -); -DELIMITER $$ -CREATE PROCEDURE hash_table(IN name VARCHAR(255), OUT hash VARCHAR(255)) -BEGIN - DECLARE _sql TEXT; - SELECT CONCAT('SELECT SHA2(GROUP_CONCAT(CONCAT_WS(\'\',', - GROUP_CONCAT(CONCAT('`', column_name, '`') ORDER BY column_name), - ') SEPARATOR \',\'), 256) AS hash FROM `', name, '` INTO @hash;') - FROM `information_schema`.`columns` - WHERE `table_schema` = DATABASE() - AND `table_name` = name - INTO _sql; - PREPARE stmt FROM _sql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; - SET hash = @hash; -END $$ -DELIMITER $$ -CREATE PROCEDURE store_query(IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) -BEGIN - DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); - DECLARE _username varchar(255) DEFAULT REGEXP_REPLACE(current_user(), '@.*', ''); - DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); - PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); - SELECT COUNT(*) FROM _tmp INTO @count; - IF @hash IS NULL THEN - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`, `executed`) - SELECT _username, query, query, false, _queryhash, @hash, @count, executed - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - ELSE - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`, `executed`) - SELECT _username, query, query, false, _queryhash, @hash, @count, executed - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - END IF; -END $$ -DELIMITER $$ -CREATE - DEFINER = 'root' PROCEDURE _store_query(IN _username VARCHAR(255), IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) -BEGIN - DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); - DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); - PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); - SELECT COUNT(*) FROM _tmp INTO @count; - IF @hash IS NULL THEN - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`, `executed`) - SELECT _username, query, query, false, _queryhash, @hash, @count, executed - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - ELSE - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`, `executed`) - SELECT _username, query, query, false, _queryhash, @hash, @count, executed - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - END IF; -END $$ -DELIMITER ; \ No newline at end of file diff --git a/dbrepo-query-service/rest-service/src/test/resources/weather/2_weather.sql b/dbrepo-query-service/rest-service/src/test/resources/weather/2_weather.sql index 29967f2977ef6b6f12da00b0c218382e5c024322..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-query-service/rest-service/src/test/resources/weather/2_weather.sql +++ b/dbrepo-query-service/rest-service/src/test/resources/weather/2_weather.sql @@ -1,55 +0,0 @@ -/* https://www.kaggle.com/jsphyg/weather-dataset-rattle-package */ -CREATE TABLE weather_location -( - location VARCHAR(255) PRIMARY KEY, - lat DOUBLE PRECISION NULL, - lng DOUBLE PRECISION NULL -) WITH SYSTEM VERSIONING; - -CREATE TABLE weather_aus -( - id BIGINT NOT NULL PRIMARY KEY, - `date` DATE NOT NULL, - location VARCHAR(255) NULL, - mintemp DOUBLE PRECISION NULL, - rainfall DOUBLE PRECISION NULL, - FOREIGN KEY (location) REFERENCES weather_location (location), - UNIQUE (`date`), - CHECK (`mintemp` > 0) -) WITH SYSTEM VERSIONING; - -CREATE TABLE sensor -( - `timestamp` TIMESTAMP NOT NULL, - PRIMARY KEY (`timestamp`), - UNIQUE (`timestamp`) -) WITH SYSTEM VERSIONING; - -INSERT INTO weather_location (location, lat, lng) -VALUES ('Albury', -36.0653583, 146.9112214), - ('Melbourne', null, null), - ('Sydney', -33.847927, 150.6517942); - -INSERT INTO weather_aus (id, `date`, location, mintemp, rainfall) -VALUES (1, '2008-12-01', 'Albury', 13.4, 0.6), - (2, '2008-12-02', 'Albury', 7.4, 0), - (3, '2008-12-03', 'Albury', 12.9, 0); - -######################################################################################################################## -## TEST CASE PRE-REQUISITE ## -######################################################################################################################## - -CREATE VIEW junit2 AS -( -SELECT `location`, `lat`, `lng` -FROM `weather_location` -WHERE `location` = 'Albury'); - -CREATE VIEW `hs_weather_aus` AS -SELECT * -FROM (SELECT `id`, ROW_START AS inserted_at, IF(ROW_END > NOW(), NULL, ROW_END) AS deleted_at, COUNT(*) as total - FROM `weather_aus` FOR SYSTEM_TIME ALL - GROUP BY inserted_at, deleted_at - ORDER BY deleted_at DESC - LIMIT 50) AS v -ORDER BY v.inserted_at, v.deleted_at ASC; diff --git a/dbrepo-query-service/rest-service/src/test/resources/weather/location.csv b/dbrepo-query-service/rest-service/src/test/resources/weather/location.csv index b9410c65c9b4169eb1a231dbe5ca04ff20c116cf..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-query-service/rest-service/src/test/resources/weather/location.csv +++ b/dbrepo-query-service/rest-service/src/test/resources/weather/location.csv @@ -1,2 +0,0 @@ -Albury,-36.0653583,146.9112214 -Sydney,-33.847927,150.6517942 \ No newline at end of file diff --git a/dbrepo-query-service/rest-service/src/test/resources/zoo/1_querystore.sql b/dbrepo-query-service/rest-service/src/test/resources/zoo/1_querystore.sql index 2762d130a0044c439b41c0215b0d87924bc8f072..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-query-service/rest-service/src/test/resources/zoo/1_querystore.sql +++ b/dbrepo-query-service/rest-service/src/test/resources/zoo/1_querystore.sql @@ -1,75 +0,0 @@ -CREATE SEQUENCE `qs_queries_seq`; -CREATE TABLE `qs_queries` -( - `id` bigint not null primary key default nextval(`qs_queries_seq`), - `created` datetime not null default now(), - `executed` datetime not null default now(), - `created_by` varchar(255) not null, - `query` text not null, - `query_normalized` text not null, - `is_persisted` boolean not null, - `query_hash` varchar(255) not null, - `result_hash` varchar(255), - `result_number` bigint -); -DELIMITER $$ -CREATE PROCEDURE hash_table(IN name VARCHAR(255), OUT hash VARCHAR(255)) -BEGIN - DECLARE _sql TEXT; - SELECT CONCAT('SELECT SHA2(GROUP_CONCAT(CONCAT_WS(\'\',', - GROUP_CONCAT(CONCAT('`', column_name, '`') ORDER BY column_name), - ') SEPARATOR \',\'), 256) AS hash FROM `', name, '` INTO @hash;') - FROM `information_schema`.`columns` - WHERE `table_schema` = DATABASE() - AND `table_name` = name - INTO _sql; - PREPARE stmt FROM _sql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; - SET hash = @hash; -END $$ -DELIMITER $$ -CREATE PROCEDURE store_query(IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) -BEGIN - DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); - DECLARE _username varchar(255) DEFAULT REGEXP_REPLACE(current_user(), '@.*', ''); - DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); - PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); - SELECT COUNT(*) FROM _tmp INTO @count; - IF @hash IS NULL THEN - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`, `executed`) - SELECT _username, query, query, false, _queryhash, @hash, @count, executed - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - ELSE - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`, `executed`) - SELECT _username, query, query, false, _queryhash, @hash, @count, executed - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - END IF; -END $$ -DELIMITER $$ -CREATE - DEFINER = 'root' PROCEDURE _store_query(IN _username VARCHAR(255), IN query TEXT, IN executed DATETIME, OUT queryId BIGINT) -BEGIN - DECLARE _queryhash varchar(255) DEFAULT SHA2(query, 256); - DECLARE _query TEXT DEFAULT CONCAT('CREATE OR REPLACE TABLE _tmp AS (', query, ')'); - PREPARE stmt FROM _query; EXECUTE stmt; DEALLOCATE PREPARE stmt; CALL hash_table('_tmp', @hash); - SELECT COUNT(*) FROM _tmp INTO @count; - IF @hash IS NULL THEN - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`, `executed`) - SELECT _username, query, query, false, _queryhash, @hash, @count, executed - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` IS NULL); - ELSE - INSERT INTO `qs_queries` (`created_by`, `query`, `query_normalized`, `is_persisted`, `query_hash`, `result_hash`, - `result_number`, `executed`) - SELECT _username, query, query, false, _queryhash, @hash, @count, executed - WHERE NOT EXISTS (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - SET queryId = (SELECT `id` FROM `qs_queries` WHERE `query_hash` = _queryhash AND `result_hash` = @hash); - END IF; -END $$ -DELIMITER ; \ No newline at end of file diff --git a/dbrepo-query-service/rest-service/src/test/resources/zoo/2_zoo.sql b/dbrepo-query-service/rest-service/src/test/resources/zoo/2_zoo.sql index 50f02ee2c53f5afc8a472b1c418225434b45d98e..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-query-service/rest-service/src/test/resources/zoo/2_zoo.sql +++ b/dbrepo-query-service/rest-service/src/test/resources/zoo/2_zoo.sql @@ -1,191 +0,0 @@ -create sequence seq_zoo_id; -create sequence seq_names_id; -create table zoo -( - id bigint not null default nextval(`seq_zoo_id`), - animal_name varchar(255) null, - hair tinyint(1) null, - feathers tinyint(1) null, - eggs tinyint(1) null, - milk tinyint(1) null, - airborne tinyint(1) null, - aquatic tinyint(1) null, - predator tinyint(1) null, - toothed tinyint(1) null, - backbone tinyint(1) null, - breathes tinyint(1) null, - venomous tinyint(1) null, - fins tinyint(1) null, - legs bigint null, - tail tinyint(1) null, - domestic tinyint(1) null, - catsize tinyint(1) null, - class_type bigint null, - primary key (id) -) with system versioning; - -create table names -( - id bigint not null default nextval(`seq_names_id`), - firstname varchar(255), - lastname varchar(255), - primary key (id), - unique key (firstname, lastname) -) with system versioning; - -create table likes -( - name_id bigint not null, - zoo_id bigint not null, - primary key (name_id, zoo_id), - foreign key (name_id) references names (id), - foreign key (zoo_id) references zoo (id) -) with system versioning; - -INSERT INTO zoo (id, animal_name, hair, feathers, eggs, milk, airborne, aquatic, predator, toothed, backbone, breathes, - venomous, fins, legs, tail, domestic, catsize, class_type) -VALUES (1, 'aardvark', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 0, 0, 1, 1), - (2, 'antelope', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (3, 'bass', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4), - (4, 'bear', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 0, 0, 1, 1), - (5, 'boar', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (6, 'buffalo', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (7, 'calf', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 1, 1, 1), - (8, 'carp', 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 4), - (9, 'catfish', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4), - (10, 'cavy', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 0, 1, 0, 1), - (11, 'cheetah', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (12, 'chicken', 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 2, 1, 1, 0, 2), - (13, 'chub', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4), - (14, 'clam', 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7), - (15, 'crab', 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 4, 0, 0, 0, 7), - (16, 'crayfish', 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 6, 0, 0, 0, 7), - (17, 'crow', 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), - (18, 'deer', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (19, 'dogfish', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 4), - (20, 'dolphin', 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1), - (21, 'dove', 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 2, 1, 1, 0, 2), - (22, 'duck', 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), - (23, 'elephant', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (24, 'flamingo', 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 2, 1, 0, 1, 2), - (25, 'flea', 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 6, 0, 0, 0, 6), - (26, 'frog', 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 4, 0, 0, 0, 5), - (27, 'frog', 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 4, 0, 0, 0, 5), - (28, 'fruitbat', 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 2, 1, 0, 0, 1), - (29, 'giraffe', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (30, 'girl', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 2, 0, 1, 1, 1), - (31, 'gnat', 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 6, 0, 0, 0, 6), - (32, 'goat', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 1, 1, 1), - (33, 'gorilla', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 2, 0, 0, 1, 1), - (34, 'gull', 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), - (35, 'haddock', 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4), - (36, 'hamster', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 1, 0, 1), - (37, 'hare', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 0, 1), - (38, 'hawk', 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), - (39, 'herring', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4), - (40, 'honeybee', 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 6, 0, 1, 0, 6), - (41, 'housefly', 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 6, 0, 0, 0, 6), - (42, 'kiwi', 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), - (43, 'ladybird', 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 6, 0, 0, 0, 6), - (44, 'lark', 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), - (45, 'leopard', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (46, 'lion', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (47, 'lobster', 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 6, 0, 0, 0, 7), - (48, 'lynx', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (49, 'mink', 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (50, 'mole', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 0, 1), - (51, 'mongoose', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (52, 'moth', 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 6, 0, 0, 0, 6), - (53, 'newt', 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 4, 1, 0, 0, 5), - (54, 'octopus', 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 8, 0, 0, 1, 7), - (55, 'opossum', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 0, 1), - (56, 'oryx', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (57, 'ostrich', 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 2, 1, 0, 1, 2), - (58, 'parakeet', 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 2, 1, 1, 0, 2), - (59, 'penguin', 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 2, 1, 0, 1, 2), - (60, 'pheasant', 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), - (61, 'pike', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 4), - (62, 'piranha', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4), - (63, 'pitviper', 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 3), - (64, 'platypus', 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (65, 'polecat', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (66, 'pony', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 1, 1, 1), - (67, 'porpoise', 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1), - (68, 'puma', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (69, 'pussycat', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 1, 1, 1), - (70, 'raccoon', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (71, 'reindeer', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 1, 1, 1), - (72, 'rhea', 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 2, 1, 0, 1, 2), - (73, 'scorpion', 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 8, 1, 0, 0, 7), - (74, 'seahorse', 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4), - (75, 'seal', 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1), - (76, 'sealion', 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 2, 1, 0, 1, 1), - (77, 'seasnake', 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 3), - (78, 'seawasp', 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 7), - (79, 'skimmer', 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), - (80, 'skua', 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), - (81, 'slowworm', 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 3), - (82, 'slug', 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 7), - (83, 'sole', 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 4), - (84, 'sparrow', 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2), - (85, 'squirrel', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 2, 1, 0, 0, 1), - (86, 'starfish', 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 5, 0, 0, 0, 7), - (87, 'stingray', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 4), - (88, 'swan', 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 2, 1, 0, 1, 2), - (89, 'termite', 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 6, 0, 0, 0, 6), - (90, 'toad', 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 4, 0, 0, 0, 5), - (91, 'tortoise', 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 4, 1, 0, 1, 3), - (92, 'tuatara', 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 0, 3), - (93, 'tuna', 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 4), - (94, 'vampire', 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 2, 1, 0, 0, 1), - (95, 'vole', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 4, 1, 0, 0, 1), - (96, 'vulture', 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 2, 1, 0, 1, 2), - (97, 'wallaby', 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 2, 1, 0, 1, 1), - (98, 'wasp', 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 6, 0, 0, 0, 6), - (99, 'wolf', 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 4, 1, 0, 1, 1), - (100, 'worm', 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 7), - (101, 'wren', 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 2, 1, 0, 0, 2); - -INSERT INTO names (firstname, lastname) -VALUES ('Moritz', 'Staudinger'), - ('Martin', 'Weise'), - ('Eva', 'Gergely'), - ('Cornelia', 'Michlits'), - ('Kirill', 'Stytsenko'); - -INSERT INTO likes (name_id, zoo_id) -VALUES (1, 5), - (1, 10), - (2, 3), - (2, 80), - (3, 4), - (4, 4), - (5, 100); - -######################################################################################################################## -## TEST CASE PRE-REQUISITE ## -######################################################################################################################## - -CREATE VIEW mock_view AS -( -SELECT `id`, - `animal_name`, - `hair`, - `feathers`, - `eggs`, - `milk`, - `airborne`, - `aquatic`, - `predator`, - `toothed`, - `backbone`, - `breathes`, - `venomous`, - `fins`, - `legs`, - `tail`, - `domestic`, - `catsize`, - `class_type` -FROM `zoo` -WHERE `class_type` = 1); diff --git a/dbrepo-query-service/services/pom.xml b/dbrepo-query-service/services/pom.xml index ccb7a862374772e0b85c47919f4d9413dd5527ba..09f0b1b954ba6912c64d9490735d1de943b81a5d 100644 --- a/dbrepo-query-service/services/pom.xml +++ b/dbrepo-query-service/services/pom.xml @@ -4,20 +4,20 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> - <artifactId>fda-query-service</artifactId> + <artifactId>dbrepo-query-service</artifactId> <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </parent> <artifactId>services</artifactId> - <version>1.1.0-alpha</version> - <name>fda-query-service-services</name> + <version>1.2.0</version> + <name>dbrepo-query-service-services</name> <dependencies> <dependency> <groupId>at.tuwien</groupId> <artifactId>api</artifactId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </dependency> </dependencies> diff --git a/dbrepo-query-service/services/src/main/java/at/tuwien/exception/DatabaseConnectionException.java b/dbrepo-query-service/services/src/main/java/at/tuwien/exception/DatabaseConnectionException.java index 3c1f797647d67b4e1cb8148a4aba11b7d06aefc0..63459167f77f9f2350abfee7cdb80ef0c704fda2 100644 --- a/dbrepo-query-service/services/src/main/java/at/tuwien/exception/DatabaseConnectionException.java +++ b/dbrepo-query-service/services/src/main/java/at/tuwien/exception/DatabaseConnectionException.java @@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; import java.io.IOException; -@ResponseStatus(code = HttpStatus.METHOD_NOT_ALLOWED) +@ResponseStatus(code = HttpStatus.SERVICE_UNAVAILABLE) public class DatabaseConnectionException extends Exception { public DatabaseConnectionException(String msg) { diff --git a/dbrepo-query-service/services/src/main/java/at/tuwien/exception/FileStorageException.java b/dbrepo-query-service/services/src/main/java/at/tuwien/exception/FileStorageException.java index ab068e4245526e77b611d1c8571df867d5fc2cb6..21968a6e680f88e85ec1406936dc973c20c5c09b 100644 --- a/dbrepo-query-service/services/src/main/java/at/tuwien/exception/FileStorageException.java +++ b/dbrepo-query-service/services/src/main/java/at/tuwien/exception/FileStorageException.java @@ -3,7 +3,7 @@ package at.tuwien.exception; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; -@ResponseStatus(code = HttpStatus.BAD_REQUEST) +@ResponseStatus(code = HttpStatus.GONE) public class FileStorageException extends Exception { public FileStorageException(String msg) { diff --git a/dbrepo-query-service/services/src/main/java/at/tuwien/exception/HeaderInvalidException.java b/dbrepo-query-service/services/src/main/java/at/tuwien/exception/HeaderInvalidException.java new file mode 100644 index 0000000000000000000000000000000000000000..87b7da4e97813da498f3ce6e8fd9b8584fb72ea2 --- /dev/null +++ b/dbrepo-query-service/services/src/main/java/at/tuwien/exception/HeaderInvalidException.java @@ -0,0 +1,21 @@ +package at.tuwien.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(code = HttpStatus.BAD_REQUEST) +public class HeaderInvalidException extends Exception { + + public HeaderInvalidException(String msg) { + super(msg); + } + + public HeaderInvalidException(String msg, Throwable thr) { + super(msg, thr); + } + + public HeaderInvalidException(Throwable thr) { + super(thr); + } + +} diff --git a/dbrepo-query-service/services/src/main/java/at/tuwien/exception/ImageNotSupportedException.java b/dbrepo-query-service/services/src/main/java/at/tuwien/exception/ImageNotSupportedException.java index 70963128f8410f856029916c606efe152957f12a..1a3b0de3d3be22b2bbd8e0a7ec7a9fff44830319 100644 --- a/dbrepo-query-service/services/src/main/java/at/tuwien/exception/ImageNotSupportedException.java +++ b/dbrepo-query-service/services/src/main/java/at/tuwien/exception/ImageNotSupportedException.java @@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; import java.io.IOException; -@ResponseStatus(code = HttpStatus.CONFLICT) +@ResponseStatus(code = HttpStatus.NOT_IMPLEMENTED) public class ImageNotSupportedException extends Exception { public ImageNotSupportedException(String msg) { diff --git a/dbrepo-query-service/services/src/main/java/at/tuwien/mapper/TableMapper.java b/dbrepo-query-service/services/src/main/java/at/tuwien/mapper/TableMapper.java index 2840bc387c82540157d49c38f3758549866df52d..2309682116556e6593b279abeb2542cef7b06cf4 100644 --- a/dbrepo-query-service/services/src/main/java/at/tuwien/mapper/TableMapper.java +++ b/dbrepo-query-service/services/src/main/java/at/tuwien/mapper/TableMapper.java @@ -3,11 +3,13 @@ package at.tuwien.mapper; import at.tuwien.api.database.table.TableDto; import at.tuwien.entities.database.table.Table; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; @Mapper(componentModel = "spring") public interface TableMapper { /* keep */ + @Mapping(target = "constraints", ignore = true) TableDto tableToTableDto(Table data); } diff --git a/dbrepo-query-service/services/src/main/java/at/tuwien/service/AccessService.java b/dbrepo-query-service/services/src/main/java/at/tuwien/service/AccessService.java index f90ec06d77fa0bd2cf64ee5bb46b8ece308dc984..1498ced76da6fcdf89a86d6c9be385a40f7bd6d3 100644 --- a/dbrepo-query-service/services/src/main/java/at/tuwien/service/AccessService.java +++ b/dbrepo-query-service/services/src/main/java/at/tuwien/service/AccessService.java @@ -6,10 +6,12 @@ import at.tuwien.exception.NotAllowedException; public interface AccessService { /** + * Find the access granted to a database with given id to a user with given username. + * * @param databaseId The database id. * @param username The username. - * @return - * @throws NotAllowedException + * @return The access, if successful. + * @throws NotAllowedException The access operation is not permitted. */ DatabaseAccess find(Long databaseId, String username) throws NotAllowedException; } diff --git a/dbrepo-query-service/services/src/main/java/at/tuwien/service/DatabaseService.java b/dbrepo-query-service/services/src/main/java/at/tuwien/service/DatabaseService.java index 982871215c63bb4953fb3b68012e83c8667ce305..80694cf22f956a0d2aaae2f56d129c8bffd2fd07 100644 --- a/dbrepo-query-service/services/src/main/java/at/tuwien/service/DatabaseService.java +++ b/dbrepo-query-service/services/src/main/java/at/tuwien/service/DatabaseService.java @@ -19,7 +19,7 @@ public interface DatabaseService { Database find(Long containerId, Long databaseId) throws DatabaseNotFoundException; /** - * Finds all databases in the metadata database. + * Finds all databases stored in the metadata database. * * @return List of databases. */ diff --git a/dbrepo-query-service/services/src/main/java/at/tuwien/service/QueryService.java b/dbrepo-query-service/services/src/main/java/at/tuwien/service/QueryService.java index 01924d9fb29b8729987e5621bd6d4a4006cfa04d..b975235b5b144bcc1201083e4c1e3651e70d3d9d 100644 --- a/dbrepo-query-service/services/src/main/java/at/tuwien/service/QueryService.java +++ b/dbrepo-query-service/services/src/main/java/at/tuwien/service/QueryService.java @@ -272,12 +272,11 @@ public interface QueryService { * @throws TableMalformedException The table does not exist in the metadata database. * @throws DatabaseNotFoundException The database is not found in the metadata database. * @throws TableNotFoundException The table is not found in the metadata database. - * @throws TupleDeleteException The tuple was not deleted. * @throws QueryMalformedException The query is malformed. */ void delete(Long containerId, Long databaseId, Long tableId, TableCsvDeleteDto data, Principal principal) throws ImageNotSupportedException, TableMalformedException, DatabaseNotFoundException, - TableNotFoundException, TupleDeleteException, ContainerNotFoundException, DatabaseConnectionException, QueryMalformedException, UserNotFoundException; + TableNotFoundException, ContainerNotFoundException, DatabaseConnectionException, QueryMalformedException, UserNotFoundException; /** * Insert data from a csv into a table of a table-database id tuple, we need the "root" role for this as the diff --git a/dbrepo-query-service/services/src/main/java/at/tuwien/service/StoreService.java b/dbrepo-query-service/services/src/main/java/at/tuwien/service/StoreService.java index baebb84c4a04ad3abf8dadef00706c9ae7bc9e20..1df5336c91f4a98609d072c8a2d0bc655a2dbf89 100644 --- a/dbrepo-query-service/services/src/main/java/at/tuwien/service/StoreService.java +++ b/dbrepo-query-service/services/src/main/java/at/tuwien/service/StoreService.java @@ -59,11 +59,10 @@ public interface StoreService { * @throws ContainerNotFoundException The container was not found in the metadata database. * @throws UserNotFoundException The user was not found in the metadata database. * @throws DatabaseConnectionException The database connection to the remote container failed. - * @throws TableMalformedException The table is malformed and the tuple could not be inserted. */ Query insert(Long containerId, Long databaseId, ExecuteStatementDto metadata, Principal principal) throws QueryStoreException, DatabaseNotFoundException, ImageNotSupportedException, ContainerNotFoundException, UserNotFoundException, - DatabaseConnectionException, TableMalformedException; + DatabaseConnectionException; /** * Persists a query to be displayed in the frontend diff --git a/dbrepo-query-service/services/src/main/java/at/tuwien/service/impl/StoreServiceImpl.java b/dbrepo-query-service/services/src/main/java/at/tuwien/service/impl/StoreServiceImpl.java index b03514297f2fab2544257505a51d1272d73dfabe..4bfb01e9d4f440c041e36c195e8387edbefa1458 100644 --- a/dbrepo-query-service/services/src/main/java/at/tuwien/service/impl/StoreServiceImpl.java +++ b/dbrepo-query-service/services/src/main/java/at/tuwien/service/impl/StoreServiceImpl.java @@ -103,7 +103,7 @@ public class StoreServiceImpl extends HibernateConnector implements StoreService @Transactional(readOnly = true) public Query insert(Long containerId, Long databaseId, ExecuteStatementDto metadata, Principal principal) throws QueryStoreException, DatabaseNotFoundException, ImageNotSupportedException, - ContainerNotFoundException, UserNotFoundException, DatabaseConnectionException, TableMalformedException { + ContainerNotFoundException, UserNotFoundException, DatabaseConnectionException { /* find */ final Database database = databaseService.find(containerId, databaseId); if (!database.getContainer().getImage().getRepository().equals("mariadb")) { diff --git a/dbrepo-query-service/services/src/main/java/at/tuwien/service/impl/TableServiceImpl.java b/dbrepo-query-service/services/src/main/java/at/tuwien/service/impl/TableServiceImpl.java index 878af13006b63de9cc95eab3c42f2c67c079e127..8a6c7d4ae27e94ace364b7015de563fc0f86f5ce 100644 --- a/dbrepo-query-service/services/src/main/java/at/tuwien/service/impl/TableServiceImpl.java +++ b/dbrepo-query-service/services/src/main/java/at/tuwien/service/impl/TableServiceImpl.java @@ -78,7 +78,7 @@ public class TableServiceImpl extends HibernateConnector implements TableService return queryMapper.resultListToTableHistoryDto(resultSet); } catch (SQLException e) { log.error("Failed to map table history: {}", e.getMessage()); - throw new QueryStoreException("Failed to map table history", e); + throw new QueryStoreException("Failed to map table history: " + e.getMessage(), e); } finally { dataSource.close(); } diff --git a/dbrepo-semantics-service/app.py b/dbrepo-semantics-service/app.py index a76e6e51cb472e0fa4b542559f6122706dec567c..573e74fbf6d9c5d8dec2a90c2e21d880a6a1812e 100644 --- a/dbrepo-semantics-service/app.py +++ b/dbrepo-semantics-service/app.py @@ -32,8 +32,8 @@ dictConfig({ app = Flask(__name__) metrics = PrometheusMetrics(app) -metrics.info('app_info', 'Application info', version='1.0.3') -app.config['SWAGGER'] = {'openapi': '3.0.1', 'title': 'Swagger UI', 'uiversion': 3} +metrics.info('app_info', 'Application info', version='1.2.0') +app.config['SWAGGER'] = {'openapi': '3.0.0', 'title': 'Swagger UI', 'uiversion': 3} list = List(offline=False) @@ -57,7 +57,7 @@ template = { 'info': { 'title': 'Database Repository Unit / Ontology Service API', 'description': 'Service for assigning concepts to database tables and columns.', - 'version': '1.1.0-alpha', + 'version': '1.2.0', 'contact': { 'name': 'Prof. Andreas Rauber', 'email': 'andreas.rauber@tuwien.ac.at' @@ -67,14 +67,18 @@ template = { 'url': 'https://www.apache.org/licenses/LICENSE-2.0' } }, + "externalDocs": { + "description": "Sourcecode Documentation", + "url": "https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services" + }, 'servers': [ { 'url': 'http://localhost:5010', 'description': 'Generated server url' }, { - 'url': 'https://dbrepo1.ec.tuwien.ac.at/api/units', - 'description': 'DBRepo Production Server' + 'url': 'https://dbrepo2.ec.tuwien.ac.at', + 'description': 'Sandbox' } ] } diff --git a/dbrepo-semantics-service/build.sh b/dbrepo-semantics-service/build.sh index 4871d1b4a99fdcd2fb1802a24cb7c9c6446d1d56..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100755 --- a/dbrepo-semantics-service/build.sh +++ b/dbrepo-semantics-service/build.sh @@ -1,4 +0,0 @@ -#!/bin/bash -python3 -m venv ./fda-semantics-service/venv -source ./fda-semantics-service/venv/bin/activate -pip install -r ./fda-semantics-service/requirements.txt \ No newline at end of file diff --git a/dbrepo-table-service/Dockerfile b/dbrepo-table-service/Dockerfile index 8d3ed94d45eda4eb97ff96c4b2bdebe16595cee4..ebb3999b6243696bce5f776c8b96195af1bebbf7 100644 --- a/dbrepo-table-service/Dockerfile +++ b/dbrepo-table-service/Dockerfile @@ -1,5 +1,5 @@ ###### FIRST STAGE ###### -FROM fda-metadata-db:latest as dependency +FROM dbrepo-metadata-db:latest as dependency MAINTAINER Martin Weise <martin.weise@tuwien.ac.at> ###### SECOND STAGE ###### diff --git a/dbrepo-table-service/pom.xml b/dbrepo-table-service/pom.xml index aa490cf8124697e86b86e85a94e60b5342a214ff..60355319f10bdcb9745738a4fe41354c95b96ad0 100644 --- a/dbrepo-table-service/pom.xml +++ b/dbrepo-table-service/pom.xml @@ -9,10 +9,10 @@ </parent> <groupId>at.tuwien</groupId> - <artifactId>fda-table-service</artifactId> - <version>1.1.0-alpha</version> - <name>fda-table-service</name> - <description>Demo project for Spring Boot</description> + <artifactId>dbrepo-table-service</artifactId> + <version>1.2.0</version> + <name>dbrepo-table-service</name> + <description>Service that manages the tables</description> <packaging>pom</packaging> <modules> @@ -83,17 +83,17 @@ <!-- Entities and API --> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-entites</artifactId> + <artifactId>dbrepo-metadata-db-entites</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-api</artifactId> + <artifactId>dbrepo-metadata-db-api</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>at.tuwien</groupId> - <artifactId>fda-metadata-db-querystore</artifactId> + <artifactId>dbrepo-metadata-db-querystore</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> @@ -166,6 +166,11 @@ <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.version}</version> </dependency> + <dependency> + <groupId>at.tuwien</groupId> + <artifactId>dbrepo-metadata-db-test</artifactId> + <version>${project.version}</version> + </dependency> <!-- DTO --> <dependency> <groupId>com.opencsv</groupId> @@ -228,7 +233,7 @@ <exclude>at/tuwien/mapper/**/*</exclude> <exclude>at/tuwien/exception/**/*</exclude> <exclude>at/tuwien/config/**/*</exclude> - <exclude>**/FdaContainerManagingApplication.class</exclude> + <exclude>**/DbrepoContainerManagingApplication.class</exclude> </excludes> </configuration> <executions> diff --git a/dbrepo-table-service/report/pom.xml b/dbrepo-table-service/report/pom.xml index 1992c97aa94c5b023929ec61ba5a5764c0bf985b..8c2d1db5eae41755b2937509b54218e2d0afdf8c 100644 --- a/dbrepo-table-service/report/pom.xml +++ b/dbrepo-table-service/report/pom.xml @@ -5,13 +5,13 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>at.tuwien</groupId> - <artifactId>fda-table-service</artifactId> - <version>1.1.0-alpha</version> + <artifactId>dbrepo-table-service</artifactId> + <version>1.2.0</version> </parent> <artifactId>report</artifactId> - <version>1.1.0-alpha</version> - <name>fda-table-service-report</name> + <version>1.2.0</version> + <name>dbrepo-table-service-report</name> <description> This module is only intended for the pipeline coverage report. See the detailed report in the respective modules diff --git a/dbrepo-table-service/rest-service/pom.xml b/dbrepo-table-service/rest-service/pom.xml index 0fd761d629356adda3683ebb5d2cd2d545761234..a1de368fd29b00d2c46a24a8782e3230fb7ca138 100644 --- a/dbrepo-table-service/rest-service/pom.xml +++ b/dbrepo-table-service/rest-service/pom.xml @@ -5,13 +5,13 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>at.tuwien</groupId> - <artifactId>fda-table-service</artifactId> - <version>1.1.0-alpha</version> + <artifactId>dbrepo-table-service</artifactId> + <version>1.2.0</version> </parent> <artifactId>rest-service</artifactId> - <version>1.1.0-alpha</version> - <name>fda-table-service-rest-service</name> + <version>1.2.0</version> + <name>dbrepo-table-service-rest-service</name> <properties> <jacoco.version>0.8.7</jacoco.version> diff --git a/dbrepo-table-service/rest-service/src/main/java/at/tuwien/FdaTableServiceApplication.java b/dbrepo-table-service/rest-service/src/main/java/at/tuwien/DbrepoTableServiceApplication.java similarity index 87% rename from dbrepo-table-service/rest-service/src/main/java/at/tuwien/FdaTableServiceApplication.java rename to dbrepo-table-service/rest-service/src/main/java/at/tuwien/DbrepoTableServiceApplication.java index ebc2e892715d0fba87700fc41870bb2e95fc7126..a96e2effc7640acd1ec961656ee54d3a52fcd991 100644 --- a/dbrepo-table-service/rest-service/src/main/java/at/tuwien/FdaTableServiceApplication.java +++ b/dbrepo-table-service/rest-service/src/main/java/at/tuwien/DbrepoTableServiceApplication.java @@ -15,10 +15,10 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @EntityScan(basePackages = {"at.tuwien.entities"}) @EnableElasticsearchRepositories(basePackages = {"at.tuwien.repository.elastic"}) @EnableJpaRepositories(basePackages = {"at.tuwien.repository.jpa"}) -public class FdaTableServiceApplication { +public class DbrepoTableServiceApplication { public static void main(String[] args) { - SpringApplication.run(FdaTableServiceApplication.class, args); + SpringApplication.run(DbrepoTableServiceApplication.class, args); } } diff --git a/dbrepo-table-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java b/dbrepo-table-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java index c841ecbd15a14a4cb85268944a1c7946cda21bf9..341d4650373eb88d8fdf813499fbdfc5655dc5f6 100644 --- a/dbrepo-table-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java +++ b/dbrepo-table-service/rest-service/src/main/java/at/tuwien/config/SwaggerConfig.java @@ -5,11 +5,14 @@ import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Contact; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.servers.Server; import org.springdoc.core.GroupedOpenApi; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import java.util.List; + @Configuration public class SwaggerConfig { @@ -30,8 +33,14 @@ public class SwaggerConfig { .name("Apache 2.0") .url("https://www.apache.org/licenses/LICENSE-2.0"))) .externalDocs(new ExternalDocumentation() - .description("Wiki Documentation") - .url("https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services/-/wikis")); + .description("Sourcecode Documentation") + .url("https://gitlab.phaidra.org/fair-data-austria-db-repository/fda-services")) + .servers(List.of(new Server() + .description("Generated server url") + .url("http://localhost:9094"), + new Server() + .description("Sandbox") + .url("https://dbrepo2.tuwien.ac.at"))); } @Bean diff --git a/dbrepo-table-service/rest-service/src/main/java/at/tuwien/endpoints/AccessEndpoint.java b/dbrepo-table-service/rest-service/src/main/java/at/tuwien/endpoints/AccessEndpoint.java index cee900fc5a5cd458e03962cd8509d75a719ef24f..412ca4a947e10b2ba1f6a91b6362aeb437fdaacb 100644 --- a/dbrepo-table-service/rest-service/src/main/java/at/tuwien/endpoints/AccessEndpoint.java +++ b/dbrepo-table-service/rest-service/src/main/java/at/tuwien/endpoints/AccessEndpoint.java @@ -1,6 +1,7 @@ package at.tuwien.endpoints; import at.tuwien.api.database.DatabaseAccessDto; +import at.tuwien.api.error.ApiErrorDto; import at.tuwien.entities.database.DatabaseAccess; import at.tuwien.exception.AccessDeniedException; import at.tuwien.exception.NotAllowedException; @@ -9,6 +10,11 @@ import at.tuwien.service.AccessService; import at.tuwien.service.DatabaseService; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.headers.Header; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; @@ -41,6 +47,23 @@ public class AccessEndpoint { @Timed(value = "access.check", description = "Time needed to check access to a table") @PreAuthorize("hasAuthority('check-access')") @Operation(summary = "Check access to some table", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "Check access successfully", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = DatabaseAccessDto.class))}), + @ApiResponse(responseCode = "403", + description = "Access to the database is forbidden", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Check access not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<DatabaseAccessDto> checkAccess(@NotBlank @PathVariable("id") Long containerId, @NotBlank @PathVariable("databaseId") Long databaseId, @NotBlank @PathVariable("tableId") Long tableId, diff --git a/dbrepo-table-service/rest-service/src/main/java/at/tuwien/endpoints/TableColumnEndpoint.java b/dbrepo-table-service/rest-service/src/main/java/at/tuwien/endpoints/TableColumnEndpoint.java index b06b38e708957218a25a4b30c1852b549a8f1199..24fe7d9b93e029ec46bae35d1aa05f6d543714b8 100644 --- a/dbrepo-table-service/rest-service/src/main/java/at/tuwien/endpoints/TableColumnEndpoint.java +++ b/dbrepo-table-service/rest-service/src/main/java/at/tuwien/endpoints/TableColumnEndpoint.java @@ -1,13 +1,19 @@ package at.tuwien.endpoints; +import at.tuwien.api.database.DatabaseAccessDto; import at.tuwien.api.database.table.columns.ColumnDto; import at.tuwien.api.database.table.columns.concepts.ColumnSemanticsUpdateDto; +import at.tuwien.api.error.ApiErrorDto; import at.tuwien.entities.database.table.columns.TableColumn; import at.tuwien.exception.*; import at.tuwien.mapper.TableMapper; import at.tuwien.service.TableService; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; @@ -40,6 +46,33 @@ public class TableColumnEndpoint { @PreAuthorize("hasAuthority('modify-table-column-semantics')") @Timed(value = "semantics.column_update", description = "Time needed to update a table column semantic mapping") @Operation(summary = "Update a table column semantic mapping", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Updated column semantics successfully", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ColumnDto.class))}), + @ApiResponse(responseCode = "400", + description = "Update semantic concept query is malformed or update unit of measurement query is malformed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Access to the database is forbidden", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Table, database, semantic concept, unit of measurement or container could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Update column semantics not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ColumnDto.class))}), + }) public ResponseEntity<ColumnDto> update(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("tableId") Long tableId, diff --git a/dbrepo-table-service/rest-service/src/main/java/at/tuwien/endpoints/TableEndpoint.java b/dbrepo-table-service/rest-service/src/main/java/at/tuwien/endpoints/TableEndpoint.java index d0e56e313d7e812a2c8b74641ba5448fc95689bc..60f9de04690d74e20234aabe8071fc4de00612b0 100644 --- a/dbrepo-table-service/rest-service/src/main/java/at/tuwien/endpoints/TableEndpoint.java +++ b/dbrepo-table-service/rest-service/src/main/java/at/tuwien/endpoints/TableEndpoint.java @@ -1,15 +1,18 @@ package at.tuwien.endpoints; import at.tuwien.api.database.table.*; +import at.tuwien.api.error.ApiErrorDto; import at.tuwien.entities.database.table.Table; import at.tuwien.exception.*; import at.tuwien.mapper.TableMapper; -import at.tuwien.service.AccessService; -import at.tuwien.service.DatabaseService; import at.tuwien.service.MessageQueueService; import at.tuwien.service.TableService; import io.micrometer.core.annotation.Timed; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; @@ -46,6 +49,23 @@ public class TableEndpoint { @Transactional(readOnly = true) @Timed(value = "table.list", description = "Time needed to list the tables") @Operation(summary = "List all tables", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "List tables", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = TableBriefDto[].class))}), + @ApiResponse(responseCode = "404", + description = "Database could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "List tables not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<List<TableBriefDto>> list(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable("databaseId") Long databaseId, Principal principal) @@ -65,6 +85,43 @@ public class TableEndpoint { @PreAuthorize("hasAuthority('create-table')") @Timed(value = "table.create", description = "Time needed to create a table") @Operation(summary = "Create a table", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "201", + description = "Created a new table", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = TableBriefDto.class))}), + @ApiResponse(responseCode = "400", + description = "Create table query is malformed", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Database, container or user could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Create table not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "409", + description = "Create table conflicts with existing table name", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "501", + description = "Image is not supported", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "504", + description = "Broker service failed to create queue", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<TableBriefDto> create(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @Valid @RequestBody TableCreateDto createDto, @@ -87,6 +144,28 @@ public class TableEndpoint { @Transactional(readOnly = true) @Timed(value = "table.find", description = "Time needed to find a table") @Operation(summary = "Get information about table", security = @SecurityRequirement(name = "bearerAuth")) + @ApiResponses(value = { + @ApiResponse(responseCode = "200", + description = "Find table successfully", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = TableDto.class))}), + @ApiResponse(responseCode = "403", + description = "Access to the database is forbidden", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Table, database or container could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Find table not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) public ResponseEntity<TableDto> findById(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("tableId") Long tableId, @@ -105,8 +184,44 @@ public class TableEndpoint { @PreAuthorize("hasAuthority('delete-table')") @Timed(value = "table.delete", description = "Time needed to delete a table") @Operation(summary = "Delete a table", security = @SecurityRequirement(name = "bearerAuth")) - @ResponseStatus(HttpStatus.OK) - public void delete(@NotNull @PathVariable("id") Long containerId, + @ApiResponses(value = { + @ApiResponse(responseCode = "202", + description = "Delete table successfully", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = TableDto.class))}), + @ApiResponse(responseCode = "400", + description = "Delete table query resulted in an invalid query statement", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "403", + description = "Access to the database is forbidden", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "404", + description = "Table, database or container could not be found", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "405", + description = "Delete table not permitted", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "423", + description = "Delete table resulted in an invalid state", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + @ApiResponse(responseCode = "501", + description = "Image is not supported", + content = {@Content( + mediaType = "application/json", + schema = @Schema(implementation = ApiErrorDto.class))}), + }) + public ResponseEntity<Void> delete(@NotNull @PathVariable("id") Long containerId, @NotNull @PathVariable("databaseId") Long databaseId, @NotNull @PathVariable("tableId") Long tableId, @NotNull Principal principal) @@ -115,6 +230,8 @@ public class TableEndpoint { log.debug("endpoint delete table, containerId={}, databaseId={}, tableId={}, principal={}", containerId, databaseId, tableId, principal); tableService.deleteTable(containerId, databaseId, tableId); + return ResponseEntity.accepted() + .build(); } } diff --git a/dbrepo-table-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java b/dbrepo-table-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java index 4d4f7f1e18805eff74c48ef6e2f49fda62970ad5..bca4721e560758e40bcd23c8eb910f27b5607928 100644 --- a/dbrepo-table-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java +++ b/dbrepo-table-service/rest-service/src/main/java/at/tuwien/handlers/ApiExceptionHandler.java @@ -2,6 +2,7 @@ package at.tuwien.handlers; import at.tuwien.api.error.ApiErrorDto; import at.tuwien.exception.*; +import io.swagger.v3.oas.annotations.Hidden; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -14,17 +15,19 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExcep @ControllerAdvice public class ApiExceptionHandler extends ResponseEntityExceptionHandler { - @ResponseStatus(HttpStatus.NOT_ACCEPTABLE) + @Hidden + @ResponseStatus(HttpStatus.GATEWAY_TIMEOUT) @ExceptionHandler({AmqpException.class}) public ResponseEntity<ApiErrorDto> handle(AmqpException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.NOT_ACCEPTABLE) + .status(HttpStatus.GATEWAY_TIMEOUT) .message(e.getLocalizedMessage()) .code("error.table.amqp") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler({ArbitraryPrimaryKeysException.class}) public ResponseEntity<ApiErrorDto> handle(ArbitraryPrimaryKeysException e, WebRequest request) { @@ -36,6 +39,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler({ContainerNotFoundException.class}) public ResponseEntity<ApiErrorDto> handle(ContainerNotFoundException e, WebRequest request) { @@ -47,6 +51,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED) @ExceptionHandler({DatabaseConnectionException.class}) public ResponseEntity<ApiErrorDto> handle(DatabaseConnectionException e, WebRequest request) { @@ -58,6 +63,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler({DatabaseNotFoundException.class}) public ResponseEntity<ApiErrorDto> handle(DatabaseNotFoundException e, WebRequest request) { @@ -69,17 +75,19 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } - @ResponseStatus(HttpStatus.BAD_REQUEST) + @Hidden + @ResponseStatus(HttpStatus.LOCKED) @ExceptionHandler({DataProcessingException.class}) public ResponseEntity<ApiErrorDto> handle(DataProcessingException e, WebRequest request) { final ApiErrorDto response = ApiErrorDto.builder() - .status(HttpStatus.BAD_REQUEST) + .status(HttpStatus.LOCKED) .message(e.getLocalizedMessage()) .code("error.table.processing") .build(); return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler({FileStorageException.class}) public ResponseEntity<ApiErrorDto> handle(FileStorageException e, WebRequest request) { @@ -91,6 +99,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler({ImageNotSupportedException.class}) public ResponseEntity<ApiErrorDto> handle(ImageNotSupportedException e, WebRequest request) { @@ -102,6 +111,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler({PaginationException.class}) public ResponseEntity<ApiErrorDto> handle(PaginationException e, WebRequest request) { @@ -113,6 +123,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler({QueryMalformedException.class}) public ResponseEntity<ApiErrorDto> handle(QueryMalformedException e, WebRequest request) { @@ -124,6 +135,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler({TableMalformedException.class}) public ResponseEntity<ApiErrorDto> handle(TableMalformedException e, WebRequest request) { @@ -135,6 +147,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.CONFLICT) @ExceptionHandler({TableNameExistsException.class}) public ResponseEntity<ApiErrorDto> handle(TableNameExistsException e, WebRequest request) { @@ -146,6 +159,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler({TableNotFoundException.class}) public ResponseEntity<ApiErrorDto> handle(TableNotFoundException e, WebRequest request) { @@ -157,6 +171,7 @@ public class ApiExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity<>(response, new HttpHeaders(), response.getStatus()); } + @Hidden @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler({UserNotFoundException.class}) public ResponseEntity<ApiErrorDto> handle(UserNotFoundException e, WebRequest request) { diff --git a/dbrepo-table-service/rest-service/src/main/resources/application-local.yml b/dbrepo-table-service/rest-service/src/main/resources/application-local.yml index 363fde214f05e5c43693731bc7f4fc9afdd854fb..71eabd9ce42d70b214ebc0b7d3a957e1718a0a76 100644 --- a/dbrepo-table-service/rest-service/src/main/resources/application-local.yml +++ b/dbrepo-table-service/rest-service/src/main/resources/application-local.yml @@ -2,7 +2,7 @@ app.version: '@project.version@' spring: main.banner-mode: off datasource: - url: jdbc:mariadb://metadata-db:3306/fda + url: jdbc:mariadb://localhost:3306/fda driver-class-name: org.mariadb.jdbc.Driver username: root password: dbrepo diff --git a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java b/dbrepo-table-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java index d7b8d42bf48e98351cbb94bb7bb0a47648f0db30..01f84e12b909533314c3cc741739e02801e78ee5 100644 --- a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java +++ b/dbrepo-table-service/rest-service/src/test/java/at/tuwien/BaseUnitTest.java @@ -1,1949 +1,9 @@ package at.tuwien; -import at.tuwien.api.database.query.QueryBriefDto; -import at.tuwien.api.database.query.QueryDto; -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.api.database.table.constraints.ConstraintsCreateDto; -import at.tuwien.api.database.table.constraints.foreignKey.ForeignKeyCreateDto; -import at.tuwien.api.user.UserDto; -import at.tuwien.entities.container.image.*; -import at.tuwien.entities.database.table.columns.TableColumnConcept; -import at.tuwien.entities.user.User; -import at.tuwien.querystore.Query; -import at.tuwien.entities.container.Container; -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 at.tuwien.test.BaseTest; import org.springframework.test.context.TestPropertySource; -import java.time.Instant; -import java.util.List; - -import static java.time.temporal.ChronoUnit.*; - @TestPropertySource(locations = "classpath:application.properties") -public abstract class BaseUnitTest { - - public final static String USER_1_ID = "090dc12a-a46a-4515-b1f0-cff697d5f985"; - public final static String USER_1_USERNAME = "junit"; - public final static String USER_1_EMAIL = "junit@example.com"; - public final static String USER_1_PASSWORD = "password"; - public final static String USER_1_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - public final static Instant USER_1_CREATED = Instant.now().minus(1, HOURS); - public final static User USER_1 = User.builder() - .id(USER_1_ID) - .username(USER_1_USERNAME) - .email(USER_1_EMAIL) - .emailVerified(true) - .databasePassword(USER_1_DATABASE_PASSWORD) - .build(); - public final static UserDto USER_1_DTO = UserDto.builder() - .id(USER_1_ID) - .username(USER_1_USERNAME) - .email(USER_1_EMAIL) - .emailVerified(true) - .build(); - - public final static String USER_2_ID = "0153f998-bd4c-4154-993e-75c355499044"; - public final static String USER_2_USERNAME = "junit2"; - public final static String USER_2_EMAIL = "junit2@example.com"; - public final static String USER_2_PASSWORD = "password"; - public final static String USER_2_DATABASE_PASSWORD = "*A8C67ABBEAE837AABCF49680A157D85D44A117E9"; - public final static Instant USER_2_CREATED = Instant.now().minus(1, HOURS); - public final static User USER_2 = User.builder() - .id(USER_2_ID) - .username(USER_2_USERNAME) - .email(USER_2_EMAIL) - .emailVerified(true) - .databasePassword(USER_2_DATABASE_PASSWORD) - .build(); - public final static UserDto USER_2_DTO = UserDto.builder() - .id(USER_2_ID) - .username(USER_2_USERNAME) - .email(USER_2_EMAIL) - .emailVerified(true) - .build(); - - public final static String DATABASE_NET = "fda-userdb"; - - public final static String BROKER_NAME = "dbrepo-broker-service"; - public final static String BROKER_IP = "172.31.0.2"; - public final static String BROKER_HOSTNAME = "dbrepo-broker-service"; - public final static Integer BROKER_MANAGEMENT_PORT = 15672; - public final static String BROKER_IMAGE = "rabbitmq"; - public final static String BROKER_TAG = "3-management-alpine"; - - 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("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(), - 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()); - - 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) - .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 = "dbrepo-userdb-u01"; - public final static String CONTAINER_1_IP = "172.30.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 = "dbrepo-userdb-u02"; - public final static String CONTAINER_2_IP = "172.30.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 = "dbrepo-userdb-u03"; - public final static String CONTAINER_3_IP = "172.30.0.7"; - public final static Instant CONTAINER_3_CREATED = Instant.now().minus(1, HOURS); - - 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 = "dbrepo." + 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 = "Zoo"; - public final static String DATABASE_2_INTERNALNAME = "zoo"; - public final static String DATABASE_2_EXCHANGE = "dbrepo." + 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 = "dbrepo." + 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_QUEUE_NAME = "dbrepo." + DATABASE_1_INTERNALNAME + "." + TABLE_1_INTERNALNAME; - public final static String TABLE_1_ROUTING_KEY = TABLE_1_QUEUE_NAME; - 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 Location"; - public final static String TABLE_2_INTERNALNAME = "weather_location"; - public final static String TABLE_2_DESCRIPTION = "Weather location"; - public final static String TABLE_2_QUEUE_NAME = "dbrepo." + DATABASE_1_INTERNALNAME + "." + TABLE_2_INTERNALNAME; - public final static String TABLE_2_ROUTING_KEY = TABLE_2_QUEUE_NAME; - 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 Zürich"; - public final static String TABLE_3_INTERNALNAME = "traffic_zurich"; - public final static String TABLE_3_DESCRIPTION = "https://www.kaggle.com/laa283/zurich-public-transport/version/2"; - public final static String TABLE_3_QUEUE_NAME = "dbrepo." + DATABASE_1_INTERNALNAME + "." + TABLE_3_INTERNALNAME; - public final static String TABLE_3_ROUTING_KEY = TABLE_3_QUEUE_NAME; - 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 = null; - 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 TABLE_4_ID = 4L; - public final static String TABLE_4_NAME = "zoo"; - public final static String TABLE_4_INTERNALNAME = "zoo"; - public final static String TABLE_4_DESCRIPTION = "Some Kaggle dataset"; - public final static String TABLE_4_QUEUE_NAME = "dbrepo." + DATABASE_1_INTERNALNAME + "." + TABLE_4_INTERNALNAME; - public final static String TABLE_4_ROUTING_KEY = TABLE_4_QUEUE_NAME; - public final static Instant TABLE_4_LAST_MODIFIED = Instant.now(); - public final static Long TABLE_4_SKIP_HEADERS = 1L; - public final static String TABLE_4_NULL_ELEMENT = null; - public final static Character TABLE_4_SEPARATOR = '\t'; - public final static String TABLE_4_TRUE_ELEMENT = null; - public final static String TABLE_4_FALSE_ELEMENT = null; - - public final static Long TABLE_5_ID = 5L; - public final static String TABLE_5_NAME = "names"; - public final static String TABLE_5_INTERNALNAME = "names"; - public final static String TABLE_5_DESCRIPTION = "Some names dataset"; - public final static String TABLE_5_QUEUE_NAME = "dbrepo." + DATABASE_1_INTERNALNAME + "." + TABLE_5_INTERNALNAME; - public final static String TABLE_5_ROUTING_KEY = TABLE_5_QUEUE_NAME; - public final static Instant TABLE_5_LAST_MODIFIED = Instant.now(); - public final static Long TABLE_5_SKIP_HEADERS = 1L; - public final static String TABLE_5_NULL_ELEMENT = null; - public final static Character TABLE_5_SEPARATOR = ','; - public final static String TABLE_5_TRUE_ELEMENT = null; - public final static String TABLE_5_FALSE_ELEMENT = null; - - 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_UNIX_FORMAT = "yyyy-MM-dd"; - public final static String IMAGE_DATE_1_DATABASE_FORMAT = "%Y-%c-%d"; - public final static String IMAGE_DATE_1_EXAMPLE = "2022-01-30"; - public final static Boolean IMAGE_DATE_1_HAS_TIME = false; - - public final static ContainerImageDate IMAGE_DATE_1 = ContainerImageDate.builder() - .id(IMAGE_DATE_1_ID) - .iid(IMAGE_DATE_1_IMAGE_ID) - .unixFormat(IMAGE_DATE_1_UNIX_FORMAT) - .databaseFormat(IMAGE_DATE_1_DATABASE_FORMAT) - .example(IMAGE_DATE_1_EXAMPLE) - .hasTime(IMAGE_DATE_1_HAS_TIME) - .build(); - - public final static Long IMAGE_DATE_2_ID = 2L; - public final static Long IMAGE_DATE_2_IMAGE_ID = IMAGE_1_ID; - public final static String IMAGE_DATE_2_UNIX_FORMAT = "dd.MM.yy"; - public final static String IMAGE_DATE_2_DATABASE_FORMAT = "%d.%c.%y"; - public final static String IMAGE_DATE_2_EXAMPLE = "30.01.2022"; - public final static Boolean IMAGE_DATE_2_HAS_TIME = false; - - public final static ContainerImageDate IMAGE_DATE_2 = ContainerImageDate.builder() - .id(IMAGE_DATE_2_ID) - .iid(IMAGE_DATE_2_IMAGE_ID) - .unixFormat(IMAGE_DATE_2_UNIX_FORMAT) - .databaseFormat(IMAGE_DATE_2_DATABASE_FORMAT) - .example(IMAGE_DATE_2_EXAMPLE) - .hasTime(IMAGE_DATE_2_HAS_TIME) - .build(); - - 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 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 Long COLUMN_1_2_DATE_FORMAT = IMAGE_DATE_1_ID; - 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 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 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 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 COLUMN_2_1_ID = 6L; - public final static Integer COLUMN_2_1_ORDINALPOS = 0; - public final static Boolean COLUMN_2_1_PRIMARY = true; - public final static String COLUMN_2_1_NAME = "location"; - public final static String COLUMN_2_1_INTERNAL_NAME = "location"; - public final static TableColumnType COLUMN_2_1_TYPE = TableColumnType.STRING; - public final static Long COLUMN_2_1_DATE_FORMAT = null; - public final static Boolean COLUMN_2_1_NULL = false; - public final static Boolean COLUMN_2_1_UNIQUE = true; - public final static Boolean COLUMN_2_1_AUTO_GENERATED = false; - public final static String COLUMN_2_1_FOREIGN_KEY = null; - public final static String COLUMN_2_1_CHECK = null; - public final static List<String> COLUMN_2_1_ENUM_VALUES = null; - - public final static Long COLUMN_2_2_ID = 7L; - public final static Integer COLUMN_2_2_ORDINALPOS = 0; - public final static Boolean COLUMN_2_2_PRIMARY = false; - public final static String COLUMN_2_2_NAME = "lat"; - public final static String COLUMN_2_2_INTERNAL_NAME = "lat"; - public final static TableColumnType COLUMN_2_2_TYPE = TableColumnType.DECIMAL; - public final static Long COLUMN_2_2_DATE_FORMAT = null; - public final static Boolean COLUMN_2_2_NULL = true; - public final static Boolean COLUMN_2_2_UNIQUE = false; - public final static Boolean COLUMN_2_2_AUTO_GENERATED = false; - public final static String COLUMN_2_2_FOREIGN_KEY = null; - public final static String COLUMN_2_2_CHECK = null; - public final static List<String> COLUMN_2_2_ENUM_VALUES = null; - - public final static Long COLUMN_2_3_ID = 8L; - public final static Integer COLUMN_2_3_ORDINALPOS = 0; - public final static Boolean COLUMN_2_3_PRIMARY = false; - public final static String COLUMN_2_3_NAME = "lng"; - public final static String COLUMN_2_3_INTERNAL_NAME = "lng"; - public final static TableColumnType COLUMN_2_3_TYPE = TableColumnType.DECIMAL; - public final static Long COLUMN_2_3_DATE_FORMAT = null; - public final static Boolean COLUMN_2_3_NULL = true; - public final static Boolean COLUMN_2_3_UNIQUE = false; - public final static Boolean COLUMN_2_3_AUTO_GENERATED = false; - public final static String COLUMN_2_3_FOREIGN_KEY = null; - public final static String COLUMN_2_3_CHECK = null; - public final static List<String> COLUMN_2_3_ENUM_VALUES = null; - - public final static Long COLUMN_4_1_ID = 9L; - public final static Integer COLUMN_4_1_ORDINALPOS = 0; - public final static Boolean COLUMN_4_1_PRIMARY = true; - public final static String COLUMN_4_1_NAME = "id"; - public final static String COLUMN_4_1_INTERNAL_NAME = "id"; - public final static TableColumnType COLUMN_4_1_TYPE = TableColumnType.NUMBER; - public final static ColumnTypeDto COLUMN_4_1_TYPE_DTO = ColumnTypeDto.NUMBER; - public final static Long COLUMN_4_1_DATE_FORMAT = null; - public final static Boolean COLUMN_4_1_NULL = false; - public final static Boolean COLUMN_4_1_UNIQUE = true; - public final static Boolean COLUMN_4_1_AUTO_GENERATED = true; - public final static String COLUMN_4_1_FOREIGN_KEY = null; - public final static String COLUMN_4_1_REFERENCES = null; - public final static List<String> COLUMN_4_1_ENUM_VALUES = null; - public final static String[] COLUMN_4_1_ENUM_VALUES_ARRAY = null; - - public final static Long COLUMN_4_2_ID = 10L; - public final static Integer COLUMN_4_2_ORDINALPOS = 1; - public final static Boolean COLUMN_4_2_PRIMARY = false; - public final static String COLUMN_4_2_NAME = "Animal Name"; - public final static String COLUMN_4_2_INTERNAL_NAME = "animal_name"; - public final static TableColumnType COLUMN_4_2_TYPE = TableColumnType.STRING; - public final static ColumnTypeDto COLUMN_4_2_TYPE_DTO = ColumnTypeDto.STRING; - public final static Long COLUMN_4_2_DATE_FORMAT = null; - public final static Boolean COLUMN_4_2_NULL = true; - public final static Boolean COLUMN_4_2_UNIQUE = false; - public final static Boolean COLUMN_4_2_AUTO_GENERATED = false; - public final static String COLUMN_4_2_FOREIGN_KEY = null; - public final static String COLUMN_4_2_REFERENCES = null; - public final static String COLUMN_4_2_CHECK = null; - public final static List<String> COLUMN_4_2_ENUM_VALUES = null; - public final static String[] COLUMN_4_2_ENUM_VALUES_ARRAY = null; - - public final static Long COLUMN_4_3_ID = 11L; - public final static Integer COLUMN_4_3_ORDINALPOS = 2; - public final static Boolean COLUMN_4_3_PRIMARY = false; - public final static String COLUMN_4_3_NAME = "Hair"; - public final static String COLUMN_4_3_INTERNAL_NAME = "hair"; - public final static TableColumnType COLUMN_4_3_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_3_DATE_FORMAT = null; - public final static Boolean COLUMN_4_3_NULL = true; - public final static Boolean COLUMN_4_3_UNIQUE = false; - public final static Boolean COLUMN_4_3_AUTO_GENERATED = false; - public final static String COLUMN_4_3_FOREIGN_KEY = null; - public final static String COLUMN_4_3_CHECK = null; - public final static List<String> COLUMN_4_3_ENUM_VALUES = null; - - public final static Long COLUMN_4_4_ID = 12L; - public final static Integer COLUMN_4_4_ORDINALPOS = 3; - public final static Boolean COLUMN_4_4_PRIMARY = false; - public final static String COLUMN_4_4_NAME = "Feathers"; - public final static String COLUMN_4_4_INTERNAL_NAME = "feathers"; - public final static TableColumnType COLUMN_4_4_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_4_DATE_FORMAT = null; - public final static Boolean COLUMN_4_4_NULL = true; - public final static Boolean COLUMN_4_4_UNIQUE = false; - public final static Boolean COLUMN_4_4_AUTO_GENERATED = false; - public final static String COLUMN_4_4_FOREIGN_KEY = null; - public final static String COLUMN_4_4_CHECK = null; - public final static List<String> COLUMN_4_4_ENUM_VALUES = null; - - public final static Long COLUMN_4_5_ID = 13L; - public final static Integer COLUMN_4_5_ORDINALPOS = 4; - public final static Boolean COLUMN_4_5_PRIMARY = false; - public final static String COLUMN_4_5_NAME = "Bread"; - public final static String COLUMN_4_5_INTERNAL_NAME = "bread"; - public final static TableColumnType COLUMN_4_5_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_5_DATE_FORMAT = null; - public final static Boolean COLUMN_4_5_NULL = true; - public final static Boolean COLUMN_4_5_UNIQUE = false; - public final static Boolean COLUMN_4_5_AUTO_GENERATED = false; - public final static String COLUMN_4_5_FOREIGN_KEY = null; - public final static String COLUMN_4_5_CHECK = null; - public final static List<String> COLUMN_4_5_ENUM_VALUES = null; - - public final static Long COLUMN_4_6_ID = 14L; - public final static Integer COLUMN_4_6_ORDINALPOS = 5; - public final static Boolean COLUMN_4_6_PRIMARY = false; - public final static String COLUMN_4_6_NAME = "Eggs"; - public final static String COLUMN_4_6_INTERNAL_NAME = "eggs"; - public final static TableColumnType COLUMN_4_6_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_6_DATE_FORMAT = null; - public final static Boolean COLUMN_4_6_NULL = true; - public final static Boolean COLUMN_4_6_UNIQUE = false; - public final static Boolean COLUMN_4_6_AUTO_GENERATED = false; - public final static String COLUMN_4_6_FOREIGN_KEY = null; - public final static String COLUMN_4_6_CHECK = null; - public final static List<String> COLUMN_4_6_ENUM_VALUES = null; - - public final static Long COLUMN_4_7_ID = 15L; - public final static Integer COLUMN_4_7_ORDINALPOS = 6; - public final static Boolean COLUMN_4_7_PRIMARY = false; - public final static String COLUMN_4_7_NAME = "Milk"; - public final static String COLUMN_4_7_INTERNAL_NAME = "milk"; - public final static TableColumnType COLUMN_4_7_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_7_DATE_FORMAT = null; - public final static Boolean COLUMN_4_7_NULL = true; - public final static Boolean COLUMN_4_7_UNIQUE = false; - public final static Boolean COLUMN_4_7_AUTO_GENERATED = false; - public final static String COLUMN_4_7_FOREIGN_KEY = null; - public final static String COLUMN_4_7_CHECK = null; - public final static List<String> COLUMN_4_7_ENUM_VALUES = null; - - public final static Long COLUMN_4_8_ID = 16L; - public final static Integer COLUMN_4_8_ORDINALPOS = 7; - public final static Boolean COLUMN_4_8_PRIMARY = false; - public final static String COLUMN_4_8_NAME = "Water"; - public final static String COLUMN_4_8_INTERNAL_NAME = "water"; - public final static TableColumnType COLUMN_4_8_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_8_DATE_FORMAT = null; - public final static Boolean COLUMN_4_8_NULL = true; - public final static Boolean COLUMN_4_8_UNIQUE = false; - public final static Boolean COLUMN_4_8_AUTO_GENERATED = false; - public final static String COLUMN_4_8_FOREIGN_KEY = null; - public final static String COLUMN_4_8_CHECK = null; - public final static List<String> COLUMN_4_8_ENUM_VALUES = null; - - public final static Long COLUMN_4_9_ID = 17L; - public final static Integer COLUMN_4_9_ORDINALPOS = 8; - public final static Boolean COLUMN_4_9_PRIMARY = false; - public final static String COLUMN_4_9_NAME = "Airborne"; - public final static String COLUMN_4_9_INTERNAL_NAME = "airborne"; - public final static TableColumnType COLUMN_4_9_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_9_DATE_FORMAT = null; - public final static Boolean COLUMN_4_9_NULL = true; - public final static Boolean COLUMN_4_9_UNIQUE = false; - public final static Boolean COLUMN_4_9_AUTO_GENERATED = false; - public final static String COLUMN_4_9_FOREIGN_KEY = null; - public final static String COLUMN_4_9_CHECK = null; - public final static List<String> COLUMN_4_9_ENUM_VALUES = null; - - public final static Long COLUMN_4_10_ID = 18L; - public final static Integer COLUMN_4_10_ORDINALPOS = 9; - public final static Boolean COLUMN_4_10_PRIMARY = false; - public final static String COLUMN_4_10_NAME = "Waterborne"; - public final static String COLUMN_4_10_INTERNAL_NAME = "waterborne"; - public final static TableColumnType COLUMN_4_10_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_10_DATE_FORMAT = null; - public final static Boolean COLUMN_4_10_NULL = true; - public final static Boolean COLUMN_4_10_UNIQUE = false; - public final static Boolean COLUMN_4_10_AUTO_GENERATED = false; - public final static String COLUMN_4_10_FOREIGN_KEY = null; - public final static String COLUMN_4_10_CHECK = null; - public final static List<String> COLUMN_4_10_ENUM_VALUES = null; - - public final static Long COLUMN_4_11_ID = 19L; - public final static Integer COLUMN_4_11_ORDINALPOS = 10; - public final static Boolean COLUMN_4_11_PRIMARY = false; - public final static String COLUMN_4_11_NAME = "Aquantic"; - public final static String COLUMN_4_11_INTERNAL_NAME = "aquatic"; - public final static TableColumnType COLUMN_4_11_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_11_DATE_FORMAT = null; - public final static Boolean COLUMN_4_11_NULL = true; - public final static Boolean COLUMN_4_11_UNIQUE = false; - public final static Boolean COLUMN_4_11_AUTO_GENERATED = false; - public final static String COLUMN_4_11_FOREIGN_KEY = null; - public final static String COLUMN_4_11_CHECK = null; - public final static List<String> COLUMN_4_11_ENUM_VALUES = null; - - public final static Long COLUMN_4_12_ID = 20L; - public final static Integer COLUMN_4_12_ORDINALPOS = 11; - public final static Boolean COLUMN_4_12_PRIMARY = false; - public final static String COLUMN_4_12_NAME = "Predator"; - public final static String COLUMN_4_12_INTERNAL_NAME = "predator"; - public final static TableColumnType COLUMN_4_12_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_12_DATE_FORMAT = null; - public final static Boolean COLUMN_4_12_NULL = true; - public final static Boolean COLUMN_4_12_UNIQUE = false; - public final static Boolean COLUMN_4_12_AUTO_GENERATED = false; - public final static String COLUMN_4_12_FOREIGN_KEY = null; - public final static String COLUMN_4_12_CHECK = null; - public final static List<String> COLUMN_4_12_ENUM_VALUES = null; - - public final static Long COLUMN_4_13_ID = 21L; - public final static Integer COLUMN_4_13_ORDINALPOS = 12; - public final static Boolean COLUMN_4_13_PRIMARY = false; - public final static String COLUMN_4_13_NAME = "Backbone"; - public final static String COLUMN_4_13_INTERNAL_NAME = "backbone"; - public final static TableColumnType COLUMN_4_13_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_13_DATE_FORMAT = null; - public final static Boolean COLUMN_4_13_NULL = true; - public final static Boolean COLUMN_4_13_UNIQUE = false; - public final static Boolean COLUMN_4_13_AUTO_GENERATED = false; - public final static String COLUMN_4_13_FOREIGN_KEY = null; - public final static String COLUMN_4_13_CHECK = null; - public final static List<String> COLUMN_4_13_ENUM_VALUES = null; - - public final static Long COLUMN_4_14_ID = 22L; - public final static Integer COLUMN_4_14_ORDINALPOS = 13; - public final static Boolean COLUMN_4_14_PRIMARY = false; - public final static String COLUMN_4_14_NAME = "Breathes"; - public final static String COLUMN_4_14_INTERNAL_NAME = "breathes"; - public final static TableColumnType COLUMN_4_14_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_14_DATE_FORMAT = null; - public final static Boolean COLUMN_4_14_NULL = true; - public final static Boolean COLUMN_4_14_UNIQUE = false; - public final static Boolean COLUMN_4_14_AUTO_GENERATED = false; - public final static String COLUMN_4_14_FOREIGN_KEY = null; - public final static String COLUMN_4_14_CHECK = null; - public final static List<String> COLUMN_4_14_ENUM_VALUES = null; - - public final static Long COLUMN_4_15_ID = 23L; - public final static Integer COLUMN_4_15_ORDINALPOS = 14; - public final static Boolean COLUMN_4_15_PRIMARY = false; - public final static String COLUMN_4_15_NAME = "Venomous"; - public final static String COLUMN_4_15_INTERNAL_NAME = "venomous"; - public final static TableColumnType COLUMN_4_15_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_15_DATE_FORMAT = null; - public final static Boolean COLUMN_4_15_NULL = true; - public final static Boolean COLUMN_4_15_UNIQUE = false; - public final static Boolean COLUMN_4_15_AUTO_GENERATED = false; - public final static String COLUMN_4_15_FOREIGN_KEY = null; - public final static String COLUMN_4_15_CHECK = null; - public final static List<String> COLUMN_4_15_ENUM_VALUES = null; - - public final static Long COLUMN_4_16_ID = 24L; - public final static Integer COLUMN_4_16_ORDINALPOS = 15; - public final static Boolean COLUMN_4_16_PRIMARY = false; - public final static String COLUMN_4_16_NAME = "Fin"; - public final static String COLUMN_4_16_INTERNAL_NAME = "fins"; - public final static TableColumnType COLUMN_4_16_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_16_DATE_FORMAT = null; - public final static Boolean COLUMN_4_16_NULL = true; - public final static Boolean COLUMN_4_16_UNIQUE = false; - public final static Boolean COLUMN_4_16_AUTO_GENERATED = false; - public final static String COLUMN_4_16_FOREIGN_KEY = null; - public final static String COLUMN_4_16_CHECK = null; - public final static List<String> COLUMN_4_16_ENUM_VALUES = null; - - public final static Long COLUMN_4_17_ID = 25L; - public final static Integer COLUMN_4_17_ORDINALPOS = 16; - public final static Boolean COLUMN_4_17_PRIMARY = false; - public final static String COLUMN_4_17_NAME = "Legs"; - public final static String COLUMN_4_17_INTERNAL_NAME = "legs"; - public final static TableColumnType COLUMN_4_17_TYPE = TableColumnType.DECIMAL; - public final static Long COLUMN_4_17_DATE_FORMAT = null; - public final static Boolean COLUMN_4_17_NULL = true; - public final static Boolean COLUMN_4_17_UNIQUE = false; - public final static Boolean COLUMN_4_17_AUTO_GENERATED = false; - public final static String COLUMN_4_17_FOREIGN_KEY = null; - public final static String COLUMN_4_17_CHECK = null; - public final static List<String> COLUMN_4_17_ENUM_VALUES = null; - - public final static Long COLUMN_4_18_ID = 26L; - public final static Integer COLUMN_4_18_ORDINALPOS = 17; - public final static Boolean COLUMN_4_18_PRIMARY = false; - public final static String COLUMN_4_18_NAME = "Tail"; - public final static String COLUMN_4_18_INTERNAL_NAME = "tail"; - public final static TableColumnType COLUMN_4_18_TYPE = TableColumnType.DECIMAL; - public final static Long COLUMN_4_18_DATE_FORMAT = null; - public final static Boolean COLUMN_4_18_NULL = true; - public final static Boolean COLUMN_4_18_UNIQUE = false; - public final static Boolean COLUMN_4_18_AUTO_GENERATED = false; - public final static String COLUMN_4_18_FOREIGN_KEY = null; - public final static String COLUMN_4_18_CHECK = null; - public final static List<String> COLUMN_4_18_ENUM_VALUES = null; - - public final static Long COLUMN_4_19_ID = 27L; - public final static Integer COLUMN_4_19_ORDINALPOS = 18; - public final static Boolean COLUMN_4_19_PRIMARY = false; - public final static String COLUMN_4_19_NAME = "Domestic"; - public final static String COLUMN_4_19_INTERNAL_NAME = "domestic"; - public final static TableColumnType COLUMN_4_19_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_19_DATE_FORMAT = null; - public final static Boolean COLUMN_4_19_NULL = true; - public final static Boolean COLUMN_4_19_UNIQUE = false; - public final static Boolean COLUMN_4_19_AUTO_GENERATED = false; - public final static String COLUMN_4_19_FOREIGN_KEY = null; - public final static String COLUMN_4_19_CHECK = null; - public final static List<String> COLUMN_4_19_ENUM_VALUES = null; - - public final static Long COLUMN_4_20_ID = 28L; - public final static Integer COLUMN_4_20_ORDINALPOS = 19; - public final static Boolean COLUMN_4_20_PRIMARY = false; - public final static String COLUMN_4_20_NAME = "Cat Size"; - public final static String COLUMN_4_20_INTERNAL_NAME = "catsize"; - public final static TableColumnType COLUMN_4_20_TYPE = TableColumnType.BOOLEAN; - public final static Long COLUMN_4_20_DATE_FORMAT = null; - public final static Boolean COLUMN_4_20_NULL = true; - public final static Boolean COLUMN_4_20_UNIQUE = false; - public final static Boolean COLUMN_4_20_AUTO_GENERATED = false; - public final static String COLUMN_4_20_FOREIGN_KEY = null; - public final static String COLUMN_4_20_CHECK = null; - public final static List<String> COLUMN_4_20_ENUM_VALUES = null; - - public final static Long COLUMN_4_21_ID = 29L; - public final static Integer COLUMN_4_21_ORDINALPOS = 20; - public final static Boolean COLUMN_4_21_PRIMARY = false; - public final static String COLUMN_4_21_NAME = "Class Type"; - public final static String COLUMN_4_21_INTERNAL_NAME = "class_type"; - public final static TableColumnType COLUMN_4_21_TYPE = TableColumnType.DECIMAL; - public final static Long COLUMN_4_21_DATE_FORMAT = null; - public final static Boolean COLUMN_4_21_NULL = true; - public final static Boolean COLUMN_4_21_UNIQUE = false; - public final static Boolean COLUMN_4_21_AUTO_GENERATED = false; - public final static String COLUMN_4_21_FOREIGN_KEY = null; - public final static String COLUMN_4_21_CHECK = null; - public final static List<String> COLUMN_4_21_ENUM_VALUES = null; - - public final static Long COLUMN_5_1_ID = 23L; - public final static Integer COLUMN_5_1_ORDINALPOS = 0; - public final static Boolean COLUMN_5_1_PRIMARY = true; - public final static String COLUMN_5_1_NAME = "id"; - public final static String COLUMN_5_1_INTERNAL_NAME = "id"; - public final static TableColumnType COLUMN_5_1_TYPE = TableColumnType.NUMBER; - public final static ColumnTypeDto COLUMN_5_1_TYPE_DTO = ColumnTypeDto.NUMBER; - public final static Long COLUMN_5_1_DATE_FORMAT = null; - public final static Boolean COLUMN_5_1_NULL = false; - public final static Boolean COLUMN_5_1_UNIQUE = true; - public final static Boolean COLUMN_5_1_AUTO_GENERATED = true; - public final static String COLUMN_5_1_FOREIGN_KEY = null; - public final static String COLUMN_5_1_CHECK = null; - public final static List<String> COLUMN_5_1_ENUM_VALUES = null; - - public final static Long COLUMN_5_2_ID = 24L; - public final static Integer COLUMN_5_2_ORDINALPOS = 1; - public final static Boolean COLUMN_5_2_PRIMARY = false; - public final static String COLUMN_5_2_NAME = "firstname"; - public final static String COLUMN_5_2_INTERNAL_NAME = "firstname"; - public final static TableColumnType COLUMN_5_2_TYPE = TableColumnType.STRING; - public final static ColumnTypeDto COLUMN_5_2_TYPE_DTO = ColumnTypeDto.STRING; - public final static Integer COLUMN_5_2_LENGTH = 20; - public final static Long COLUMN_5_2_DATE_FORMAT = null; - public final static Boolean COLUMN_5_2_NULL = false; - public final static Boolean COLUMN_5_2_UNIQUE = false; - public final static Boolean COLUMN_5_2_AUTO_GENERATED = false; - public final static String COLUMN_5_2_FOREIGN_KEY = null; - public final static String COLUMN_5_2_CHECK = null; - public final static List<String> COLUMN_5_2_ENUM_VALUES = null; - - public final static Long COLUMN_5_3_ID = 25L; - public final static Integer COLUMN_5_3_ORDINALPOS = 2; - public final static Boolean COLUMN_5_3_PRIMARY = false; - public final static String COLUMN_5_3_NAME = "lastname"; - public final static String COLUMN_5_3_INTERNAL_NAME = "lastname"; - public final static TableColumnType COLUMN_5_3_TYPE = TableColumnType.STRING; - public final static ColumnTypeDto COLUMN_5_3_TYPE_DTO = ColumnTypeDto.STRING; - public final static Integer COLUMN_5_3_LENGTH = 40; - public final static Long COLUMN_5_3_DATE_FORMAT = null; - public final static Boolean COLUMN_5_3_NULL = false; - public final static Boolean COLUMN_5_3_UNIQUE = false; - public final static Boolean COLUMN_5_3_AUTO_GENERATED = false; - public final static String COLUMN_5_3_FOREIGN_KEY = null; - public final static String COLUMN_5_3_CHECK = null; - public final static List<String> COLUMN_5_3_ENUM_VALUES = null; - - public final static Long COLUMN_5_4_ID = 25L; - public final static Integer COLUMN_5_4_ORDINALPOS = 2; - public final static Boolean COLUMN_5_4_PRIMARY = false; - public final static String COLUMN_5_4_NAME = "ref_id"; - public final static String COLUMN_5_4_INTERNAL_NAME = "ref_id"; - public final static TableColumnType COLUMN_5_4_TYPE = TableColumnType.NUMBER; - public final static ColumnTypeDto COLUMN_5_4_TYPE_DTO = ColumnTypeDto.NUMBER; - public final static Long COLUMN_5_4_DATE_FORMAT = null; - public final static Boolean COLUMN_5_4_NULL = false; - public final static Boolean COLUMN_5_4_UNIQUE = false; - public final static Boolean COLUMN_5_4_AUTO_GENERATED = false; - public final static String COLUMN_5_4_FOREIGN_KEY = null; - public final static String COLUMN_5_4_CHECK = null; - public final static List<String> COLUMN_5_4_ENUM_VALUES = null; - - public final static Long CONTAINER_NGINX_ID = 4L; - public final static String CONTAINER_NGINX_HASH = "deadbeef"; - public final static String CONTAINER_NGINX_IMAGE = "nginx"; - public final static String CONTAINER_NGINX_TAG = "1.20-alpine"; - public final static String CONTAINER_NGINX_NET = "fda-public"; - public final static String CONTAINER_NGINX_NAME = "file-service"; - public final static String CONTAINER_NGINX_INTERNALNAME = "fda-test-file-service"; - public final static String CONTAINER_NGINX_IP = "172.31.0.3"; - public final static Instant CONTAINER_NGINX_CREATED = Instant.now().minus(3, HOURS); - - public final static Long CONCEPT_1_ID = 1L; - public final static String CONCEPT_1_NAME = "Temperature"; - public final static Instant CONCEPT_1_CREATED = Instant.now().minus(1, HOURS); - - public final static TableColumnConcept CONCEPT_1 = TableColumnConcept.builder() - .name(CONCEPT_1_NAME) - .created(CONCEPT_1_CREATED) - .uri("http://www.ontology-of-units-of-measure.org/resource/om-2/") - .build(); - - public final static Container CONTAINER_1 = Container.builder() - .id(CONTAINER_1_ID) - .name(CONTAINER_1_NAME) - .internalName(CONTAINER_1_INTERNALNAME) - .imageId(IMAGE_1_ID) - .image(CONTAINER_1_IMAGE) - .hash(CONTAINER_1_HASH) - .created(CONTAINER_1_CREATED) - .creator(USER_1) - .build(); - - public final static Container CONTAINER_2 = Container.builder() - .id(CONTAINER_2_ID) - .name(CONTAINER_2_NAME) - .internalName(CONTAINER_2_INTERNALNAME) - .imageId(IMAGE_1_ID) - .image(CONTAINER_2_IMAGE) - .hash(CONTAINER_2_HASH) - .created(CONTAINER_2_CREATED) - .creator(USER_2) - .build(); - - public final static Container CONTAINER_3 = Container.builder() - .id(CONTAINER_3_ID) - .name(CONTAINER_3_NAME) - .internalName(CONTAINER_3_INTERNALNAME) - .imageId(IMAGE_1_ID) - .image(CONTAINER_3_IMAGE) - .hash(CONTAINER_3_HASH) - .created(CONTAINER_3_CREATED) - .build(); - - public final static Long QUERY_1_ID = 1L; - public final static String QUERY_1_STATEMENT = "SELECT `id`, `date`, `location`, `mintemp`, `rainfall` FROM " + - "`weather_aus`"; - public final static String QUERY_1_DOI = "1111/1"; - public final static Long QUERY_1_CONTAINER_ID = CONTAINER_1_ID; - public final static Long QUERY_1_DATABASE_ID = DATABASE_1_ID; - public final static String QUERY_1_RESULT_HASH = "5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03"; - public final static Instant QUERY_1_CREATED = Instant.now(); - public final static Instant QUERY_1_EXECUTION = Instant.now(); - - public final static Long QUERY_2_ID = 2L; - public final static String QUERY_2_STATEMENT = "SELECT * FROM `weather`;"; - public final static Long QUERY_2_CONTAINER_ID = CONTAINER_2_ID; - public final static Long QUERY_2_DATABASE_ID = DATABASE_2_ID; - public final static String QUERY_2_RESULT_HASH = "ff3f7cbe1b96d296957f6e39e55b8b1b577fa3d205d4795af99594cfd20cb80d"; - public final static Instant QUERY_2_CREATED = Instant.now().minus(2, MINUTES); - public final static Instant QUERY_2_EXECUTION = Instant.now().minus(1, MINUTES); - - public final static Query QUERY_1 = Query.builder() - .id(QUERY_1_ID) - .query(QUERY_1_STATEMENT) - .resultHash(QUERY_1_RESULT_HASH) - .created(QUERY_1_CREATED) - .createdBy(USER_1_USERNAME) - .build(); - - public final static QueryDto QUERY_1_DTO = QueryDto.builder() - .id(QUERY_1_ID) - .cid(QUERY_1_CONTAINER_ID) - .dbid(QUERY_1_DATABASE_ID) - .query(QUERY_1_STATEMENT) - .resultHash(QUERY_1_RESULT_HASH) - .created(QUERY_1_CREATED) - .execution(QUERY_1_EXECUTION) - .createdBy(USER_1_ID) - .creator(USER_1_DTO) - .build(); - - public final static QueryBriefDto QUERY_1_BRIEF_DTO = QueryBriefDto.builder() - .id(QUERY_1_ID) - .cid(QUERY_1_CONTAINER_ID) - .dbid(QUERY_1_DATABASE_ID) - .query(QUERY_1_STATEMENT) - .resultHash(QUERY_1_RESULT_HASH) - .created(QUERY_1_CREATED) - .execution(QUERY_1_EXECUTION) - .createdBy(USER_1_ID) - .creator(USER_1_DTO) - .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) - .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) - .dateFormat(IMAGE_DATE_1) - .isNullAllowed(COLUMN_1_2_NULL) - .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) - .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) - .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) - .autoGenerated(COLUMN_1_5_AUTO_GENERATED) - .isPrimaryKey(COLUMN_1_5_PRIMARY) - .enumValues(COLUMN_1_5_ENUM_VALUES) - .build()); - - public final static List<TableColumn> TABLE_2_COLUMNS = List.of(TableColumn.builder() - .id(COLUMN_2_1_ID) - .ordinalPosition(COLUMN_2_1_ORDINALPOS) - .cdbid(DATABASE_1_ID) - .tid(TABLE_2_ID) - .name(COLUMN_2_1_NAME) - .internalName(COLUMN_2_1_INTERNAL_NAME) - .columnType(COLUMN_2_1_TYPE) - .dfid(COLUMN_2_1_DATE_FORMAT) - .isNullAllowed(COLUMN_2_1_NULL) - .autoGenerated(COLUMN_2_1_AUTO_GENERATED) - .isPrimaryKey(COLUMN_2_1_PRIMARY) - .enumValues(COLUMN_2_1_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_2_2_ID) - .ordinalPosition(COLUMN_2_2_ORDINALPOS) - .cdbid(DATABASE_1_ID) - .tid(TABLE_2_ID) - .name(COLUMN_2_2_NAME) - .internalName(COLUMN_2_2_INTERNAL_NAME) - .columnType(COLUMN_2_2_TYPE) - .dfid(COLUMN_2_2_DATE_FORMAT) - .isNullAllowed(COLUMN_2_2_NULL) - .autoGenerated(COLUMN_2_2_AUTO_GENERATED) - .isPrimaryKey(COLUMN_2_2_PRIMARY) - .enumValues(COLUMN_2_2_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_2_3_ID) - .ordinalPosition(COLUMN_2_3_ORDINALPOS) - .cdbid(DATABASE_1_ID) - .tid(TABLE_2_ID) - .name(COLUMN_2_3_NAME) - .internalName(COLUMN_2_3_INTERNAL_NAME) - .columnType(COLUMN_2_3_TYPE) - .dfid(COLUMN_2_3_DATE_FORMAT) - .isNullAllowed(COLUMN_2_3_NULL) - .autoGenerated(COLUMN_2_3_AUTO_GENERATED) - .isPrimaryKey(COLUMN_2_3_PRIMARY) - .enumValues(COLUMN_2_3_ENUM_VALUES) - .build()); - - public final static List<TableColumn> TABLE_3_COLUMNS = List.of(TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(0) - .autoGenerated(true) - .columnType(TableColumnType.NUMBER) - .name("id") - .internalName("id") - .isNullAllowed(false) - .isPrimaryKey(true) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(1) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("linie") - .internalName("linie") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(2) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("richtung") - .internalName("richtung") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(3) - .autoGenerated(false) - .columnType(TableColumnType.DATE) - .name("betriebsdatum") - .internalName("betriebsdatum") - .isNullAllowed(true) - .isPrimaryKey(false) - .dfid(IMAGE_DATE_2_ID) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(4) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("fahrzeug") - .internalName("fahrzeug") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(5) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("kurs") - .internalName("kurs") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(6) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("seq_von") - .internalName("seq_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(7) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("halt_diva_von") - .internalName("halt_diva_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(8) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("halt_punkt_diva_von") - .internalName("halt_punkt_diva_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(9) - .autoGenerated(false) - .columnType(TableColumnType.STRING) - .name("halt_kurz_von1") - .internalName("halt_kurz_von1") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(10) - .autoGenerated(false) - .columnType(TableColumnType.DATE) - .name("datum_von") - .internalName("datum_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dfid(IMAGE_DATE_2_ID) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(11) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("soll_an_von") - .internalName("soll_an_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(12) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("ist_an_von") - .internalName("ist_an_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(13) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("soll_ab_von") - .internalName("soll_ab_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(14) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("ist_ab_von") - .internalName("ist_ab_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(15) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("seq_nach") - .internalName("seq_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(16) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("halt_diva_nach") - .internalName("halt_diva_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(17) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("halt_punkt_diva_nach") - .internalName("halt_punkt_diva_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(18) - .autoGenerated(false) - .columnType(TableColumnType.STRING) - .name("halt_kurz_nach1") - .internalName("halt_kurz_nach1") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(19) - .autoGenerated(false) - .columnType(TableColumnType.DATE) - .name("datum_nach") - .internalName("datum_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dfid(IMAGE_DATE_2_ID) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(20) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("soll_an_nach") - .internalName("soll_an_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(21) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("ist_an_nach1") - .internalName("ist_an_nach1") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(22) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("soll_ab_nach") - .internalName("soll_ab_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(23) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("ist_ab_nach") - .internalName("ist_ab_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(24) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("fahrt_id") - .internalName("fahrt_id") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(25) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("fahrweg_id") - .internalName("fahrweg_id") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(26) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("fw_no") - .internalName("fw_no") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(27) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("fw_typ") - .internalName("fw_typ") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(28) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("fw_kurz") - .internalName("fw_kurz") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(29) - .autoGenerated(false) - .columnType(TableColumnType.STRING) - .name("fw_lang") - .internalName("fw_lang") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(30) - .autoGenerated(false) - .columnType(TableColumnType.STRING) - .name("umlauf_von") - .internalName("umlauf_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(31) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("halt_id_von") - .internalName("halt_id_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(32) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("halt_id_nach") - .internalName("halt_id_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(33) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("halt_punkt_id_von") - .internalName("halt_punkt_id_von") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build(), - TableColumn.builder() - .tid(TABLE_3_ID) - .cdbid(DATABASE_3_ID) - .ordinalPosition(34) - .autoGenerated(false) - .columnType(TableColumnType.NUMBER) - .name("halt_punkt_id_nach") - .internalName("halt_punkt_id_nach") - .isNullAllowed(true) - .isPrimaryKey(false) - .dateFormat(null) - .enumValues(null) - .build()); - - public final static List<TableColumn> TABLE_4_COLUMNS = List.of(TableColumn.builder() - .id(COLUMN_4_1_ID) - .ordinalPosition(COLUMN_4_1_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_1_NAME) - .internalName(COLUMN_4_1_INTERNAL_NAME) - .columnType(COLUMN_4_1_TYPE) - .dfid(COLUMN_4_1_DATE_FORMAT) - .isNullAllowed(COLUMN_4_1_NULL) - .autoGenerated(COLUMN_4_1_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_1_PRIMARY) - .enumValues(COLUMN_4_1_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_2_ID) - .ordinalPosition(COLUMN_4_2_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_2_NAME) - .internalName(COLUMN_4_2_INTERNAL_NAME) - .columnType(COLUMN_4_2_TYPE) - .dfid(COLUMN_4_2_DATE_FORMAT) - .isNullAllowed(COLUMN_4_2_NULL) - .autoGenerated(COLUMN_4_2_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_2_PRIMARY) - .enumValues(COLUMN_4_2_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_3_ID) - .ordinalPosition(COLUMN_4_3_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_3_NAME) - .internalName(COLUMN_4_3_INTERNAL_NAME) - .columnType(COLUMN_4_3_TYPE) - .dfid(COLUMN_4_3_DATE_FORMAT) - .isNullAllowed(COLUMN_4_3_NULL) - .autoGenerated(COLUMN_4_3_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_3_PRIMARY) - .enumValues(COLUMN_4_3_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_4_ID) - .ordinalPosition(COLUMN_4_4_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_4_NAME) - .internalName(COLUMN_4_4_INTERNAL_NAME) - .columnType(COLUMN_4_4_TYPE) - .dfid(COLUMN_4_4_DATE_FORMAT) - .isNullAllowed(COLUMN_4_4_NULL) - .autoGenerated(COLUMN_4_4_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_4_PRIMARY) - .enumValues(COLUMN_4_4_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_5_ID) - .ordinalPosition(COLUMN_4_5_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_5_NAME) - .internalName(COLUMN_4_5_INTERNAL_NAME) - .columnType(COLUMN_4_5_TYPE) - .dfid(COLUMN_4_5_DATE_FORMAT) - .isNullAllowed(COLUMN_4_5_NULL) - .autoGenerated(COLUMN_4_5_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_5_PRIMARY) - .enumValues(COLUMN_4_5_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_6_ID) - .ordinalPosition(COLUMN_4_6_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_6_NAME) - .internalName(COLUMN_4_6_INTERNAL_NAME) - .columnType(COLUMN_4_6_TYPE) - .dfid(COLUMN_4_6_DATE_FORMAT) - .isNullAllowed(COLUMN_4_6_NULL) - .autoGenerated(COLUMN_4_6_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_6_PRIMARY) - .enumValues(COLUMN_4_6_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_7_ID) - .ordinalPosition(COLUMN_4_7_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_7_NAME) - .internalName(COLUMN_4_7_INTERNAL_NAME) - .columnType(COLUMN_4_7_TYPE) - .dfid(COLUMN_4_7_DATE_FORMAT) - .isNullAllowed(COLUMN_4_7_NULL) - .autoGenerated(COLUMN_4_7_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_7_PRIMARY) - .enumValues(COLUMN_4_7_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_8_ID) - .ordinalPosition(COLUMN_4_8_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_8_NAME) - .internalName(COLUMN_4_8_INTERNAL_NAME) - .columnType(COLUMN_4_8_TYPE) - .dfid(COLUMN_4_8_DATE_FORMAT) - .isNullAllowed(COLUMN_4_8_NULL) - .autoGenerated(COLUMN_4_8_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_8_PRIMARY) - .enumValues(COLUMN_4_8_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_9_ID) - .ordinalPosition(COLUMN_4_9_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_9_NAME) - .internalName(COLUMN_4_9_INTERNAL_NAME) - .columnType(COLUMN_4_9_TYPE) - .dfid(COLUMN_4_9_DATE_FORMAT) - .isNullAllowed(COLUMN_4_9_NULL) - .autoGenerated(COLUMN_4_9_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_9_PRIMARY) - .enumValues(COLUMN_4_9_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_10_ID) - .ordinalPosition(COLUMN_4_10_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_10_NAME) - .internalName(COLUMN_4_10_INTERNAL_NAME) - .columnType(COLUMN_4_10_TYPE) - .dfid(COLUMN_4_10_DATE_FORMAT) - .isNullAllowed(COLUMN_4_10_NULL) - .autoGenerated(COLUMN_4_10_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_10_PRIMARY) - .enumValues(COLUMN_4_10_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_11_ID) - .ordinalPosition(COLUMN_4_11_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_11_NAME) - .internalName(COLUMN_4_11_INTERNAL_NAME) - .columnType(COLUMN_4_11_TYPE) - .dfid(COLUMN_4_11_DATE_FORMAT) - .isNullAllowed(COLUMN_4_11_NULL) - .autoGenerated(COLUMN_4_11_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_11_PRIMARY) - .enumValues(COLUMN_4_11_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_12_ID) - .ordinalPosition(COLUMN_4_12_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_12_NAME) - .internalName(COLUMN_4_12_INTERNAL_NAME) - .columnType(COLUMN_4_12_TYPE) - .dfid(COLUMN_4_12_DATE_FORMAT) - .isNullAllowed(COLUMN_4_12_NULL) - .autoGenerated(COLUMN_4_12_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_12_PRIMARY) - .enumValues(COLUMN_4_12_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_13_ID) - .ordinalPosition(COLUMN_4_13_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_13_NAME) - .internalName(COLUMN_4_13_INTERNAL_NAME) - .columnType(COLUMN_4_13_TYPE) - .dfid(COLUMN_4_13_DATE_FORMAT) - .isNullAllowed(COLUMN_4_13_NULL) - .autoGenerated(COLUMN_4_13_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_13_PRIMARY) - .enumValues(COLUMN_4_13_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_14_ID) - .ordinalPosition(COLUMN_4_14_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_14_NAME) - .internalName(COLUMN_4_14_INTERNAL_NAME) - .columnType(COLUMN_4_14_TYPE) - .dfid(COLUMN_4_14_DATE_FORMAT) - .isNullAllowed(COLUMN_4_14_NULL) - .autoGenerated(COLUMN_4_14_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_14_PRIMARY) - .enumValues(COLUMN_4_14_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_15_ID) - .ordinalPosition(COLUMN_4_15_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_15_NAME) - .internalName(COLUMN_4_15_INTERNAL_NAME) - .columnType(COLUMN_4_15_TYPE) - .dfid(COLUMN_4_15_DATE_FORMAT) - .isNullAllowed(COLUMN_4_15_NULL) - .autoGenerated(COLUMN_4_15_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_15_PRIMARY) - .enumValues(COLUMN_4_15_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_16_ID) - .ordinalPosition(COLUMN_4_16_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_16_NAME) - .internalName(COLUMN_4_16_INTERNAL_NAME) - .columnType(COLUMN_4_16_TYPE) - .dfid(COLUMN_4_16_DATE_FORMAT) - .isNullAllowed(COLUMN_4_16_NULL) - .autoGenerated(COLUMN_4_16_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_16_PRIMARY) - .enumValues(COLUMN_4_16_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_17_ID) - .ordinalPosition(COLUMN_4_17_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_17_NAME) - .internalName(COLUMN_4_17_INTERNAL_NAME) - .columnType(COLUMN_4_17_TYPE) - .dfid(COLUMN_4_17_DATE_FORMAT) - .isNullAllowed(COLUMN_4_17_NULL) - .autoGenerated(COLUMN_4_17_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_17_PRIMARY) - .enumValues(COLUMN_4_17_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_18_ID) - .ordinalPosition(COLUMN_4_18_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_18_NAME) - .internalName(COLUMN_4_18_INTERNAL_NAME) - .columnType(COLUMN_4_18_TYPE) - .dfid(COLUMN_4_18_DATE_FORMAT) - .isNullAllowed(COLUMN_4_18_NULL) - .autoGenerated(COLUMN_4_18_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_18_PRIMARY) - .enumValues(COLUMN_4_18_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_19_ID) - .ordinalPosition(COLUMN_4_19_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_19_NAME) - .internalName(COLUMN_4_19_INTERNAL_NAME) - .columnType(COLUMN_4_19_TYPE) - .dfid(COLUMN_4_19_DATE_FORMAT) - .isNullAllowed(COLUMN_4_19_NULL) - .autoGenerated(COLUMN_4_19_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_19_PRIMARY) - .enumValues(COLUMN_4_19_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_20_ID) - .ordinalPosition(COLUMN_4_20_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_20_NAME) - .internalName(COLUMN_4_20_INTERNAL_NAME) - .columnType(COLUMN_4_20_TYPE) - .dfid(COLUMN_4_20_DATE_FORMAT) - .isNullAllowed(COLUMN_4_20_NULL) - .autoGenerated(COLUMN_4_20_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_20_PRIMARY) - .enumValues(COLUMN_4_20_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_4_21_ID) - .ordinalPosition(COLUMN_4_21_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_4_ID) - .name(COLUMN_4_21_NAME) - .internalName(COLUMN_4_21_INTERNAL_NAME) - .columnType(COLUMN_4_21_TYPE) - .dfid(COLUMN_4_21_DATE_FORMAT) - .isNullAllowed(COLUMN_4_21_NULL) - .autoGenerated(COLUMN_4_21_AUTO_GENERATED) - .isPrimaryKey(COLUMN_4_21_PRIMARY) - .enumValues(COLUMN_4_21_ENUM_VALUES) - .build()); - - public final static List<TableColumn> TABLE_5_COLUMNS = List.of(TableColumn.builder() - .id(COLUMN_5_1_ID) - .ordinalPosition(COLUMN_5_1_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_5_ID) - .name(COLUMN_5_1_NAME) - .internalName(COLUMN_5_1_INTERNAL_NAME) - .columnType(COLUMN_5_1_TYPE) - .dfid(COLUMN_5_1_DATE_FORMAT) - .isNullAllowed(COLUMN_5_1_NULL) - .autoGenerated(COLUMN_5_1_AUTO_GENERATED) - .isPrimaryKey(COLUMN_5_1_PRIMARY) - .enumValues(COLUMN_5_1_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_5_2_ID) - .ordinalPosition(COLUMN_5_2_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_5_ID) - .name(COLUMN_5_2_NAME) - .internalName(COLUMN_5_2_INTERNAL_NAME) - .columnType(COLUMN_5_2_TYPE) - .dfid(COLUMN_5_2_DATE_FORMAT) - .isNullAllowed(COLUMN_5_2_NULL) - .autoGenerated(COLUMN_5_2_AUTO_GENERATED) - .isPrimaryKey(COLUMN_5_2_PRIMARY) - .enumValues(COLUMN_5_2_ENUM_VALUES) - .build(), - TableColumn.builder() - .id(COLUMN_5_3_ID) - .ordinalPosition(COLUMN_5_3_ORDINALPOS) - .cdbid(DATABASE_2_ID) - .tid(TABLE_5_ID) - .name(COLUMN_5_3_NAME) - .internalName(COLUMN_5_3_INTERNAL_NAME) - .columnType(COLUMN_5_3_TYPE) - .dfid(COLUMN_5_3_DATE_FORMAT) - .isNullAllowed(COLUMN_5_3_NULL) - .autoGenerated(COLUMN_5_3_AUTO_GENERATED) - .isPrimaryKey(COLUMN_5_3_PRIMARY) - .enumValues(COLUMN_5_3_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) - .tdbid(DATABASE_1_ID) - .queueName(TABLE_1_QUEUE_NAME) - .routingKey(TABLE_1_ROUTING_KEY) - .creator(USER_1) - .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_1_ID) - .queueName(TABLE_2_QUEUE_NAME) - .routingKey(TABLE_2_ROUTING_KEY) - .creator(USER_2) - .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) - .queueName(TABLE_3_QUEUE_NAME) - .routingKey(TABLE_3_ROUTING_KEY) - .creator(USER_2) - .build(); - - public final static TableCreateDto TABLE_3_CREATE_DTO = TableCreateDto.builder() - .name(TABLE_3_NAME) - .description(TABLE_3_DESCRIPTION) - .columns(List.of()) - .build(); - - public final static List<ColumnCreateDto> TABLE_4_COLUMNS_CREATE = List.of(ColumnCreateDto.builder() - .name(COLUMN_4_2_NAME) - .type(COLUMN_4_2_TYPE_DTO) - .dfid(COLUMN_4_2_DATE_FORMAT) - .nullAllowed(COLUMN_4_2_NULL) - .primaryKey(COLUMN_4_2_PRIMARY) - .enumValues(COLUMN_4_2_ENUM_VALUES_ARRAY) - .build()); - - public final static List<ForeignKeyCreateDto> TABLE_4_FOREIGN_KEYS_INVALID_CREATE = List.of(ForeignKeyCreateDto.builder() - .columns(List.of("somecolumn")) - .referencedTable("sometable") - .referencedColumns(List.of("someothercolumn")) - .build()); - - public final static ConstraintsCreateDto TABLE_4_CONSTRAINTS_INVALID_CREATE = ConstraintsCreateDto.builder() - .foreignKeys(TABLE_4_FOREIGN_KEYS_INVALID_CREATE) - .build(); - - public final static TableCreateDto TABLE_4_CREATE_DTO = TableCreateDto.builder() - .name(TABLE_4_NAME) - .description(TABLE_4_DESCRIPTION) - .columns(TABLE_4_COLUMNS_CREATE) - .build(); - - public final static TableCreateDto TABLE_4_INVALID_CREATE_DTO = TableCreateDto.builder() - .name(TABLE_4_NAME) - .description(TABLE_4_DESCRIPTION) - .columns(TABLE_4_COLUMNS_CREATE) - .constraints(TABLE_4_CONSTRAINTS_INVALID_CREATE) - .build(); - - public final static List<ColumnCreateDto> TABLE_5_COLUMNS_CREATE = List.of( - ColumnCreateDto.builder() - .name(COLUMN_5_1_NAME) - .type(COLUMN_5_1_TYPE_DTO) - .dfid(COLUMN_5_1_DATE_FORMAT) - .nullAllowed(COLUMN_5_1_NULL) - .primaryKey(COLUMN_5_1_PRIMARY) - .build(), - ColumnCreateDto.builder() - .name(COLUMN_5_2_NAME) - .type(COLUMN_5_2_TYPE_DTO) - .length(COLUMN_5_2_LENGTH) - .dfid(COLUMN_5_2_DATE_FORMAT) - .nullAllowed(COLUMN_5_2_NULL) - .primaryKey(COLUMN_5_2_PRIMARY) - .build(), - ColumnCreateDto.builder() - .name(COLUMN_5_3_NAME) - .type(COLUMN_5_3_TYPE_DTO) - .length(COLUMN_5_3_LENGTH) - .dfid(COLUMN_5_3_DATE_FORMAT) - .nullAllowed(COLUMN_5_3_NULL) - .primaryKey(COLUMN_5_3_PRIMARY) - .build(), - ColumnCreateDto.builder() - .name(COLUMN_5_4_NAME) - .type(COLUMN_5_4_TYPE_DTO) - .dfid(COLUMN_5_4_DATE_FORMAT) - .nullAllowed(COLUMN_5_4_NULL) - .primaryKey(COLUMN_5_4_PRIMARY) - .build()); - - public final static List<List<String>> TABLE_5_UNIQUES_CREATE = List.of( - List.of(COLUMN_5_1_NAME), - List.of(COLUMN_5_2_NAME, COLUMN_5_3_NAME)); - - public final static List<ForeignKeyCreateDto> TABLE_5_FOREIGN_KEYS_CREATE = List.of(ForeignKeyCreateDto.builder() - .columns(List.of(COLUMN_5_4_NAME)) - .referencedTable(TABLE_4_NAME) - .referencedColumns(List.of(COLUMN_4_1_NAME)) - .build()); - - public final static List<String> TABLE_5_CHECKS_CREATE = List.of( - COLUMN_5_2_NAME + " != " + COLUMN_5_3_NAME); - - public final static ConstraintsCreateDto TABLE_5_CONSTRAINTS_CREATE = ConstraintsCreateDto.builder() - .uniques(TABLE_5_UNIQUES_CREATE) - .foreignKeys(TABLE_5_FOREIGN_KEYS_CREATE) - .checks(TABLE_5_CHECKS_CREATE) - .build(); - - public final static TableCreateDto TABLE_5_CREATE_DTO = TableCreateDto.builder() - .name(TABLE_5_NAME) - .description(TABLE_5_DESCRIPTION) - .columns(TABLE_5_COLUMNS_CREATE) - .constraints(TABLE_5_CONSTRAINTS_CREATE) - .build(); - - public final static Table TABLE_4 = Table.builder() - .id(TABLE_4_ID) - .created(Instant.now()) - .internalName(TABLE_4_INTERNALNAME) - .description(TABLE_4_DESCRIPTION) - .name(TABLE_4_NAME) - .lastModified(TABLE_4_LAST_MODIFIED) - .tdbid(DATABASE_2_ID) - .queueName(TABLE_4_QUEUE_NAME) - .routingKey(TABLE_4_ROUTING_KEY) - .creator(USER_2) - .build(); - - public final static Table TABLE_5 = Table.builder() - .id(TABLE_5_ID) - .created(Instant.now()) - .internalName(TABLE_5_INTERNALNAME) - .description(TABLE_5_DESCRIPTION) - .name(TABLE_5_NAME) - .lastModified(TABLE_5_LAST_MODIFIED) - .tdbid(DATABASE_2_ID) - .queueName(TABLE_5_QUEUE_NAME) - .routingKey(TABLE_5_ROUTING_KEY) - .creator(USER_2) - .build(); - - public final static Database DATABASE_1 = Database.builder() - .id(DATABASE_1_ID) - .created(Instant.now().minus(1, HOURS)) - .lastModified(Instant.now()) - .isPublic(true) - .name(DATABASE_1_NAME) - .container(CONTAINER_1) - .internalName(DATABASE_1_INTERNALNAME) - .exchangeName(DATABASE_1_EXCHANGE) - .creator(USER_1) - .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) - .internalName(DATABASE_2_INTERNALNAME) - .exchangeName(DATABASE_2_EXCHANGE) - .creator(USER_2) - .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) - .internalName(DATABASE_3_INTERNALNAME) - .exchangeName(DATABASE_3_EXCHANGE) - .creator(USER_2) - .build(); +public abstract class BaseUnitTest extends BaseTest { } diff --git a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/config/DockerConfig.java b/dbrepo-table-service/rest-service/src/test/java/at/tuwien/config/DockerConfig.java deleted file mode 100644 index 81d5bc8afe4b6c2e6d509d4992517f4b9f4935cd..0000000000000000000000000000000000000000 --- a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/config/DockerConfig.java +++ /dev/null @@ -1,63 +0,0 @@ -package at.tuwien.config; - -import at.tuwien.entities.container.Container; -import com.github.dockerjava.api.DockerClient; -import com.github.dockerjava.api.command.InspectContainerResponse; -import com.github.dockerjava.api.model.HostConfig; -import com.github.dockerjava.api.model.RestartPolicy; -import com.github.dockerjava.core.DefaultDockerClientConfig; -import com.github.dockerjava.core.DockerClientBuilder; -import com.github.dockerjava.core.DockerClientConfig; -import com.github.dockerjava.httpclient5.ApacheDockerHttpClient; -import com.github.dockerjava.transport.DockerHttpClient; -import lombok.extern.log4j.Log4j2; - -import java.util.Objects; - -@Log4j2 -public class DockerConfig { - - private final static DockerClientConfig dockerClientConfig = DefaultDockerClientConfig.createDefaultConfigBuilder() - .withDockerHost("unix:///var/run/docker.sock") - .build(); - - private final static DockerHttpClient dockerHttpClient = new ApacheDockerHttpClient.Builder() - .dockerHost(dockerClientConfig.getDockerHost()) - .sslConfig(dockerClientConfig.getSSLConfig()) - .build(); - - public final static HostConfig hostConfig = HostConfig.newHostConfig() - .withRestartPolicy(RestartPolicy.alwaysRestart()); - - public final static DockerClient dockerClient = DockerClientBuilder.getInstance() - .withDockerHttpClient(dockerHttpClient) - .build(); - - public static void startContainer(Container container) throws InterruptedException { - final InspectContainerResponse inspect = dockerClient.inspectContainerCmd(container.getHash()) - .exec(); - log.trace("container {} state {}", container.getHash(), inspect.getState().getStatus()); - if (Objects.equals(inspect.getState().getStatus(), "running")) { - return; - } - log.trace("container {} needs to be started", container.getHash()); - dockerClient.startContainerCmd(container.getHash()) - .exec(); - Thread.sleep(12 * 1000L); - log.debug("container {} was started", container.getHash()); - } - - public static void stopContainer(Container container) { - final InspectContainerResponse inspect = dockerClient.inspectContainerCmd(container.getHash()) - .exec(); - log.trace("container {} state {}", container.getHash(), inspect.getState().getStatus()); - if (!Objects.equals(inspect.getState().getStatus(), "running")) { - return; - } - log.trace("container {} needs to be stopped", container.getHash()); - dockerClient.stopContainerCmd(container.getHash()) - .exec(); - log.debug("container {} was stopped", container.getHash()); - } - -} diff --git a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/config/GatewayConfig.java b/dbrepo-table-service/rest-service/src/test/java/at/tuwien/config/GatewayConfig.java index 26d1b50051997b362f19029252437e06aea44e63..659ac26ff1cbe9a09e46d794a991f112a3f60c3c 100644 --- a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/config/GatewayConfig.java +++ b/dbrepo-table-service/rest-service/src/test/java/at/tuwien/config/GatewayConfig.java @@ -12,6 +12,9 @@ import org.springframework.web.util.DefaultUriBuilderFactory; @Configuration public class GatewayConfig { + @Value("${spring.rabbitmq.host}") + private String hostname; + @Value("${spring.rabbitmq.username}") private String brokerUsername; @@ -21,7 +24,7 @@ public class GatewayConfig { @Bean("brokerRestTemplate") public RestTemplate brokerRestTemplate() { final RestTemplate restTemplate = new RestTemplate(); - restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory("http://dbrepo-broker-service:15672")); + restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory("http://" + hostname + ":15672")); restTemplate.getInterceptors() .add(new BasicAuthenticationInterceptor(brokerUsername, brokerPassword)); return restTemplate; diff --git a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java b/dbrepo-table-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java deleted file mode 100644 index 9ebb89afcf0b6656c0d4cf936effd1890cf4e5a7..0000000000000000000000000000000000000000 --- a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/config/MariaDbConfig.java +++ /dev/null @@ -1,43 +0,0 @@ -package at.tuwien.config; - -import at.tuwien.entities.database.table.Table; -import lombok.extern.log4j.Log4j2; -import org.springframework.beans.factory.annotation.Configurable; -import org.springframework.context.annotation.Bean; - -import java.sql.*; -import java.util.Properties; - -@Log4j2 -@Configurable -public class MariaDbConfig { - - @Bean - public Properties mariaDbProperties() { - final Properties properties = new Properties(); - properties.setProperty("MARIADB_USER", "mariadb"); - properties.setProperty("MARIADB_PASSWORD", "mariadb"); - return properties; - } - - public static void clearDatabase(Table table) throws SQLException { - final String jdbc = "jdbc:mariadb://" + table.getDatabase().getContainer().getInternalName() + "/" + table.getDatabase().getInternalName(); - log.trace("connect to database {}", jdbc); - final Connection connection = DriverManager.getConnection(jdbc, "mariadb", "mariadb"); - final Statement statement = connection.createStatement(); - statement.execute("DELETE FROM " + table.getInternalName() + ";"); - connection.close(); - } - - public static boolean contains(Table table, String column, Object expected) throws SQLException { - final String jdbc = "jdbc:mariadb://" + table.getDatabase().getContainer().getInternalName() + "/" + table.getDatabase().getInternalName(); - log.trace("connect to database {}", jdbc); - final Connection connection = DriverManager.getConnection(jdbc, "mariadb", "mariadb"); - final Statement statement = connection.createStatement(); - final ResultSet result = statement.executeQuery("SELECT `" + column + "` FROM " + table.getInternalName() + - " WHERE `" + column + "` = " + expected.toString() + ";"); - connection.close(); - return result.next(); - } - -} diff --git a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/hibernate/DbrepoSchemaFilter.java b/dbrepo-table-service/rest-service/src/test/java/at/tuwien/hibernate/DbrepoSchemaFilter.java deleted file mode 100644 index 6481fc09a86fbef68aaa0988d6050395f609f044..0000000000000000000000000000000000000000 --- a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/hibernate/DbrepoSchemaFilter.java +++ /dev/null @@ -1,35 +0,0 @@ -package at.tuwien.hibernate; - -import org.hibernate.boot.model.relational.Namespace; -import org.hibernate.boot.model.relational.Sequence; -import org.hibernate.mapping.Table; -import org.hibernate.tool.schema.spi.SchemaFilter; - -import java.util.List; - -/** - * Do not create table for class {@link at.tuwien.entities.database.table.columns.concepts.ColumnConcept} when using JUnit test - */ -public class DbrepoSchemaFilter implements SchemaFilter { - - public static final DbrepoSchemaFilter INSTANCE = new DbrepoSchemaFilter(); - - @Override - public boolean includeNamespace(Namespace namespace) { - return true; - } - - @Override - public boolean includeTable(Table table) { - final List<String> exclude = List.of("mdb_units", "mdb_concepts"); - if (table.getSchema().matches("fda") && exclude.contains(table.getName())) { - return false; - } - return true; - } - - @Override - public boolean includeSequence(Sequence sequence) { - return true; - } -} diff --git a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/hibernate/DbrepoSchemaProvider.java b/dbrepo-table-service/rest-service/src/test/java/at/tuwien/hibernate/DbrepoSchemaProvider.java deleted file mode 100644 index 955c1bf46231402ce07826af025b9a4799c671ed..0000000000000000000000000000000000000000 --- a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/hibernate/DbrepoSchemaProvider.java +++ /dev/null @@ -1,28 +0,0 @@ -package at.tuwien.hibernate; - -import org.hibernate.tool.schema.spi.SchemaFilter; -import org.hibernate.tool.schema.spi.SchemaFilterProvider; - -/* keep */ -public class DbrepoSchemaProvider implements SchemaFilterProvider { - - @Override - public SchemaFilter getCreateFilter() { - return DbrepoSchemaFilter.INSTANCE; - } - - @Override - public SchemaFilter getDropFilter() { - return DbrepoSchemaFilter.INSTANCE; - } - - @Override - public SchemaFilter getMigrateFilter() { - return DbrepoSchemaFilter.INSTANCE; - } - - @Override - public SchemaFilter getValidateFilter() { - return DbrepoSchemaFilter.INSTANCE; - } -} diff --git a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/service/MessageQueueServiceIntegrationTest.java b/dbrepo-table-service/rest-service/src/test/java/at/tuwien/service/MessageQueueServiceIntegrationTest.java index 1b5a0ecb183d79aa34a3aa66aafcd24aed43a49f..c5face43b7d3de010b2d56583f27ae623168e86e 100644 --- a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/service/MessageQueueServiceIntegrationTest.java +++ b/dbrepo-table-service/rest-service/src/test/java/at/tuwien/service/MessageQueueServiceIntegrationTest.java @@ -4,10 +4,12 @@ package at.tuwien.service; import at.tuwien.BaseUnitTest; import at.tuwien.config.IndexConfig; import at.tuwien.config.ReadyConfig; +import at.tuwien.config.DockerConfig; import at.tuwien.exception.*; import at.tuwien.repository.elastic.TableColumnIdxRepository; import at.tuwien.repository.elastic.TableIdxRepository; import at.tuwien.repository.jpa.TableRepository; +import at.tuwien.test.BaseTest; import at.tuwien.utils.AmqpUtils; import com.github.dockerjava.api.command.CreateContainerResponse; import com.github.dockerjava.api.exception.NotModifiedException; @@ -27,10 +29,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; 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.*; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @Log4j2 @@ -63,61 +62,17 @@ public class MessageQueueServiceIntegrationTest extends BaseUnitTest { public static void beforeAll() throws InterruptedException { afterAll(); /* create network */ - dockerClient.createNetworkCmd() - .withName("fda-userdb") - .withIpam(new Network.Ipam() - .withConfig(new Network.Ipam.Config() - .withSubnet("172.30.0.0/16"))) - .withEnableIpv6(false) - .exec(); - dockerClient.createNetworkCmd() - .withName("fda-public") - .withIpam(new Network.Ipam() - .withConfig(new Network.Ipam.Config() - .withSubnet("172.31.0.0/16"))) - .withEnableIpv6(false) - .exec(); - /* create amqp */ - final CreateContainerResponse request = dockerClient.createContainerCmd(BROKER_IMAGE + ":" + BROKER_TAG) - .withHostConfig( - hostConfig - .withNetworkMode("fda-public") - .withPortBindings(PortBinding.parse("15672:15672"), PortBinding.parse("5672:5672")) - ) - .withName(BROKER_NAME) - .withIpv4Address(BROKER_IP) - .withHostName(BROKER_HOSTNAME) - .withEnv("RABBITMQ_DEFAULT_USER=fda", "RABBITMQ_DEFAULT_PASS=fda") - .exec(); - dockerClient.startContainerCmd(request.getId()) - .exec(); - Thread.sleep(12 * 1000); + DockerConfig.createAllNetworks(); + /* create container */ + DockerConfig.createContainer(null, CONTAINER_BROKER, 15672, CONTAINER_BROKER_ENV); + DockerConfig.startContainer(CONTAINER_BROKER); } @AfterAll public static void afterAll() { /* 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(); - }); + DockerConfig.removeAllContainers(); + DockerConfig.createAllNetworks(); } @BeforeEach diff --git a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationReadTest.java b/dbrepo-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationReadTest.java new file mode 100644 index 0000000000000000000000000000000000000000..5e7bebc7f62f31696691f01a4fec28d1c40a36ca --- /dev/null +++ b/dbrepo-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationReadTest.java @@ -0,0 +1,153 @@ +package at.tuwien.service; + +import at.tuwien.BaseUnitTest; +import at.tuwien.config.DockerConfig; +import at.tuwien.config.H2Utils; +import at.tuwien.config.IndexConfig; +import at.tuwien.config.ReadyConfig; +import at.tuwien.entities.database.table.Table; +import at.tuwien.exception.*; +import at.tuwien.repository.elastic.TableColumnIdxRepository; +import at.tuwien.repository.elastic.TableIdxRepository; +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.rabbitmq.client.Channel; +import lombok.extern.log4j.Log4j2; +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 java.io.File; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@Log4j2 +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@SpringBootTest +@ExtendWith(SpringExtension.class) +public class TableServiceIntegrationReadTest extends BaseUnitTest { + + @MockBean + private ReadyConfig readyConfig; + + @MockBean + private Channel channel; + + @MockBean + private IndexConfig indexInitializer; + + @MockBean + private TableIdxRepository tableidxRepository; + + @MockBean + private TableColumnIdxRepository tableColumnidxRepository; + + @Autowired + private ImageRepository imageRepository; + + @Autowired + private ContainerRepository containerRepository; + + @Autowired + private DatabaseRepository databaseRepository; + + @Autowired + private TableRepository tableRepository; + + @Autowired + private TableService tableService; + + @Autowired + private H2Utils h2Utils; + + private static final String BIND_WEATHER = new File("../../dbrepo-metadata-db/test/src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + + @BeforeAll + public static void beforeAll() throws InterruptedException { + afterAll(); + DockerConfig.createAllNetworks(); + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); + DockerConfig.startContainer(CONTAINER_1); + } + + @AfterAll + public static void afterAll() { + DockerConfig.removeAllContainers(); + DockerConfig.removeAllNetworks(); + } + + @BeforeEach + public void beforeEach() { + h2Utils.runScript("schema.sql"); + imageRepository.save(IMAGE_1); + containerRepository.save(CONTAINER_1); + containerRepository.save(CONTAINER_2); + databaseRepository.save(DATABASE_1) /* will have 2 tables */; + tableRepository.save(TABLE_1); + tableRepository.save(TABLE_2); + } + + @Test + public void findAll_succeeds() throws DatabaseNotFoundException { + + /* test */ + final List<Table> response = tableService.findAll(CONTAINER_1_ID, DATABASE_1_ID); + assertEquals(2, response.size()); + } + + @Test + public void findAll_fails() { + + /* test */ + assertThrows(DatabaseNotFoundException.class, () -> { + tableService.findAll(CONTAINER_2_ID, DATABASE_2_ID); + }); + } + + @Test + public void findById_succeeds() throws TableNotFoundException, DatabaseNotFoundException, + ContainerNotFoundException { + + /* 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()); + assertEquals(TABLE_1_INTERNALNAME, response.getInternalName()); + } + + @Test + public void findById_tableNotFound_fails() { + + /* test */ + assertThrows(TableNotFoundException.class, () -> { + tableService.findById(CONTAINER_1_ID, DATABASE_1_ID, TABLE_3_ID); + }); + } + + @Test + public void findById_databaseNotFound_fails() { + + /* test */ + assertThrows(DatabaseNotFoundException.class, () -> { + tableService.findById(CONTAINER_2_ID, DATABASE_3_ID, TABLE_3_ID); + }); + } + + @Test + public void findById_containerNotFound_fails() { + + /* test */ + assertThrows(ContainerNotFoundException.class, () -> { + tableService.findById(CONTAINER_3_ID, DATABASE_3_ID, TABLE_3_ID); + }); + } + +} diff --git a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java b/dbrepo-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationWriteTest.java similarity index 54% rename from dbrepo-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java rename to dbrepo-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationWriteTest.java index 9d95e621ef0b22c053fc8b3c8309b77decda2b81..670b3301b3b20711a92ccf5af892d757db4bce98 100644 --- a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationTest.java +++ b/dbrepo-table-service/rest-service/src/test/java/at/tuwien/service/TableServiceIntegrationWriteTest.java @@ -1,11 +1,12 @@ + package at.tuwien.service; import at.tuwien.BaseUnitTest; import at.tuwien.api.database.table.TableDto; import at.tuwien.config.DockerConfig; +import at.tuwien.config.H2Utils; import at.tuwien.config.IndexConfig; import at.tuwien.config.ReadyConfig; -import at.tuwien.entities.database.table.Table; import at.tuwien.exception.*; import at.tuwien.repository.elastic.TableColumnIdxRepository; import at.tuwien.repository.elastic.TableIdxRepository; @@ -13,10 +14,6 @@ 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; @@ -26,17 +23,12 @@ 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.annotation.Rollback; import org.springframework.test.context.junit.jupiter.SpringExtension; -import javax.transaction.Transactional; import java.io.File; import java.security.Principal; -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.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; @@ -48,35 +40,20 @@ import static org.mockito.Mockito.when; @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) @SpringBootTest @ExtendWith(SpringExtension.class) -public class TableServiceIntegrationTest extends BaseUnitTest { +public class TableServiceIntegrationWriteTest extends BaseUnitTest { - /** - * RabbitMQ not required in this test - */ @MockBean private ReadyConfig readyConfig; - /** - * RabbitMQ not required in this test - */ @MockBean private Channel channel; - /** - * ElasticSearch not required in this test - */ @MockBean private IndexConfig indexInitializer; - /** - * ElasticSearch not required in this test - */ @MockBean private TableIdxRepository tableidxRepository; - /** - * ElasticSearch not required in this test - */ @MockBean private TableColumnIdxRepository tableColumnidxRepository; @@ -95,39 +72,21 @@ public class TableServiceIntegrationTest extends BaseUnitTest { @Autowired private TableService tableService; + @Autowired + private H2Utils h2Utils; + + private static final String BIND_WEATHER = new File("../../dbrepo-metadata-db/test/src/test/resources/weather").toPath().toAbsolutePath() + ":/docker-entrypoint-initdb.d"; + @BeforeEach public void beforeEach() throws InterruptedException { - /* create network */ - dockerClient.createNetworkCmd() - .withName("fda-userdb") - .withIpam(new Network.Ipam() - .withConfig(new Network.Ipam.Config() - .withSubnet("172.30.0.0/16"))) - .withEnableIpv6(false) - .exec(); - dockerClient.createNetworkCmd() - .withName("fda-public") - .withIpam(new Network.Ipam() - .withConfig(new Network.Ipam.Config() - .withSubnet("172.31.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").withBinds(Bind.parse(bind))) - .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") - .exec(); - /* start */ - CONTAINER_1.setHash(response.getId()); + afterEach(); + /* create networks */ + DockerConfig.createAllNetworks(); + /* create user container */ + DockerConfig.createContainer(BIND_WEATHER, CONTAINER_1, CONTAINER_1_ENV); DockerConfig.startContainer(CONTAINER_1); - + /* metadata database */ + h2Utils.runScript("schema.sql"); imageRepository.save(IMAGE_1); containerRepository.save(CONTAINER_1); containerRepository.save(CONTAINER_2); @@ -138,83 +97,8 @@ public class TableServiceIntegrationTest extends BaseUnitTest { @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 findAll_succeeds() throws DatabaseNotFoundException { - - /* test */ - final List<Table> response = tableService.findAll(CONTAINER_1_ID, DATABASE_1_ID); - assertEquals(2, response.size()); - } - - @Test - public void findAll_fails() { - - /* test */ - assertThrows(DatabaseNotFoundException.class, () -> { - tableService.findAll(CONTAINER_2_ID, DATABASE_2_ID); - }); - } - - @Test - public void findById_succeeds() throws TableNotFoundException, DatabaseNotFoundException, - ContainerNotFoundException { - - /* 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()); - assertEquals(TABLE_1_INTERNALNAME, response.getInternalName()); - } - - @Test - public void findById_tableNotFound_fails() { - - /* test */ - assertThrows(TableNotFoundException.class, () -> { - tableService.findById(CONTAINER_1_ID, DATABASE_1_ID, TABLE_3_ID); - }); - } - - @Test - public void findById_databaseNotFound_fails() { - - /* test */ - assertThrows(DatabaseNotFoundException.class, () -> { - tableService.findById(CONTAINER_2_ID, DATABASE_3_ID, TABLE_3_ID); - }); - } - - @Test - public void findById_containerNotFound_fails() { - - /* test */ - assertThrows(ContainerNotFoundException.class, () -> { - tableService.findById(CONTAINER_3_ID, DATABASE_3_ID, TABLE_3_ID); - }); + DockerConfig.removeAllContainers(); + DockerConfig.removeAllNetworks(); } @Test @@ -247,11 +131,11 @@ public class TableServiceIntegrationTest extends BaseUnitTest { /* test */ try { - tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, TABLE_4_INVALID_CREATE_DTO, principal); + tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, TABLE_3_INVALID_CREATE_DTO, principal); } catch (TableMalformedException e) { /* ignore */ } - tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, TABLE_4_CREATE_DTO, principal); + tableService.createTable(CONTAINER_1_ID, DATABASE_1_ID, TABLE_3_CREATE_DTO, principal); } @Test diff --git a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/utils/AmqpUtils.java b/dbrepo-table-service/rest-service/src/test/java/at/tuwien/utils/AmqpUtils.java index dfc90d2ea25ae4920fd2edd74a26660209190554..eb36b5e3c9d7d7764a00eaa608e9523127796700 100644 --- a/dbrepo-table-service/rest-service/src/test/java/at/tuwien/utils/AmqpUtils.java +++ b/dbrepo-table-service/rest-service/src/test/java/at/tuwien/utils/AmqpUtils.java @@ -3,8 +3,7 @@ package at.tuwien.utils; import at.tuwien.api.amqp.CreateExchangeDto; import at.tuwien.api.amqp.ExchangeDto; import at.tuwien.api.amqp.QueueDto; -import com.rabbitmq.client.BuiltinExchangeType; -import com.rabbitmq.client.Channel; +import at.tuwien.config.AmqpConfig; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -15,7 +14,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; -import java.io.IOException; import java.net.URI; import java.util.Arrays; import java.util.List; @@ -26,15 +24,17 @@ import java.util.stream.Collectors; public class AmqpUtils { private final RestTemplate restTemplate; + private final AmqpConfig amqpConfig; @Autowired - public AmqpUtils(@Qualifier("brokerRestTemplate") RestTemplate restTemplate) { + public AmqpUtils(@Qualifier("brokerRestTemplate") RestTemplate restTemplate, AmqpConfig amqpConfig) { this.restTemplate = restTemplate; + this.amqpConfig = amqpConfig; } public void createExchange(String exchange) { exchange = exchange.replace("/", "%2F"); - final URI uri = URI.create("http://dbrepo-broker-service:15672/api/exchanges/%2F/" + exchange); + final URI uri = URI.create("http://" + amqpConfig.getAmpqHost() + ":15672/api/exchanges/%2F/" + exchange); final CreateExchangeDto payload = CreateExchangeDto.builder() .type("fanout") .autoDelete(false) @@ -67,7 +67,7 @@ public class AmqpUtils { } public boolean queueExists(String queue) { - final URI uri = URI.create("http://dbrepo-broker-service:15672/api/queues/%2F/"); + final URI uri = URI.create("http://" + amqpConfig.getAmpqHost() + ":15672/api/queues/%2F/"); final ResponseEntity<QueueDto[]> response = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<>(null), QueueDto[].class); if (!response.getStatusCode().equals(HttpStatus.OK)) { log.error("Failed to find queue, code is {}", response.getStatusCode()); diff --git a/dbrepo-table-service/rest-service/src/test/resources/application.properties b/dbrepo-table-service/rest-service/src/test/resources/application.properties index 7b36261df9cae4125909802829b1b976ea649b4e..eb36bd3f1dbfd4c1c7542fe3ff08c2959f564f3b 100644 --- a/dbrepo-table-service/rest-service/src/test/resources/application.properties +++ b/dbrepo-table-service/rest-service/src/test/resources/application.properties @@ -16,8 +16,8 @@ spring.datasource.password=password spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.show-sql=false -spring.jpa.properties.hibernate.hbm2ddl.schema_filter_provider=at.tuwien.hibernate.DbrepoSchemaProvider -# additional logging -logging.level.org.hibernate.SQL=debug -logging.level.org.hibernate.type=trace \ No newline at end of file +# broker service +spring.rabbitmq.host=dbrepo-broker-service +spring.rabbitmq.username=guest +spring.rabbitmq.password=guest \ No newline at end of file diff --git a/dbrepo-table-service/rest-service/src/test/resources/weather/WeatherAus.sql b/dbrepo-table-service/rest-service/src/test/resources/weather/WeatherAus.sql index 4e1658e9f60808dcca94badc37139fc34fcdfe4d..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-table-service/rest-service/src/test/resources/weather/WeatherAus.sql +++ b/dbrepo-table-service/rest-service/src/test/resources/weather/WeatherAus.sql @@ -1,14 +0,0 @@ -/* https://www.kaggle.com/jsphyg/weather-dataset-rattle-package */ -CREATE TABLE weather_aus -( - id BIGINT NOT NULL PRIMARY KEY, - date DATE NOT NULL, - location VARCHAR(255) NULL, - mintemp DOUBLE PRECISION NULL, - rainfall DOUBLE PRECISION NULL -) WITH SYSTEM VERSIONING; - -INSERT INTO weather_aus (id, date, location, mintemp, rainfall) -VALUES (1, '2008-12-01', 'Albury', 13.4, 0.6), - (2, '2008-12-02', 'Albury', 7.4, 0), - (3, '2008-12-03', 'Albury', 12.9, 0); \ No newline at end of file diff --git a/dbrepo-table-service/services/pom.xml b/dbrepo-table-service/services/pom.xml index 8deff1d33ebe581651b23a0fe5ca05c6c9453f79..0b937f235d8771979dafb9abd4c8090f52d61ac2 100644 --- a/dbrepo-table-service/services/pom.xml +++ b/dbrepo-table-service/services/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> - <artifactId>fda-table-service</artifactId> + <artifactId>dbrepo-table-service</artifactId> <groupId>at.tuwien</groupId> - <version>1.1.0-alpha</version> + <version>1.2.0</version> </parent> <artifactId>services</artifactId> - <version>1.1.0-alpha</version> - <name>fda-table-service-services</name> + <version>1.2.0</version> + <name>dbrepo-table-service-services</name> <build> <plugins> diff --git a/dbrepo-table-service/services/src/main/java/at/tuwien/config/DockerConfig.java b/dbrepo-table-service/services/src/main/java/at/tuwien/config/DockerConfig.java deleted file mode 100644 index 25021a8dad22ec6bb27acf72cbbad9570c946472..0000000000000000000000000000000000000000 --- a/dbrepo-table-service/services/src/main/java/at/tuwien/config/DockerConfig.java +++ /dev/null @@ -1,37 +0,0 @@ -package at.tuwien.config; - -import com.github.dockerjava.api.DockerClient; -import com.github.dockerjava.api.model.HostConfig; -import com.github.dockerjava.api.model.RestartPolicy; -import com.github.dockerjava.core.DefaultDockerClientConfig; -import com.github.dockerjava.core.DockerClientBuilder; -import com.github.dockerjava.core.DockerClientConfig; -import com.github.dockerjava.httpclient5.ApacheDockerHttpClient; -import com.github.dockerjava.transport.DockerHttpClient; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class DockerConfig { - - @Bean - public HostConfig hostConfig() { - return HostConfig.newHostConfig() - .withRestartPolicy(RestartPolicy.alwaysRestart()); - } - - @Bean - public DockerClient dockerClientConfiguration() { - final DockerClientConfig dockerClientConfig = DefaultDockerClientConfig.createDefaultConfigBuilder() - .withDockerHost("unix:///var/run/docker.sock") - .build(); - final DockerHttpClient dockerHttpClient = new ApacheDockerHttpClient.Builder() - .dockerHost(dockerClientConfig.getDockerHost()) - .sslConfig(dockerClientConfig.getSSLConfig()) - .build(); - return DockerClientBuilder.getInstance() - .withDockerHttpClient(dockerHttpClient) - .build(); - } - -} diff --git a/dbrepo-table-service/services/src/main/java/at/tuwien/config/GatewayConfig.java b/dbrepo-table-service/services/src/main/java/at/tuwien/config/GatewayConfig.java index a6a8a2003ea62692634571d94edd5cc37f177d32..4dd0068634978d7fff069203febb24d69d02f845 100644 --- a/dbrepo-table-service/services/src/main/java/at/tuwien/config/GatewayConfig.java +++ b/dbrepo-table-service/services/src/main/java/at/tuwien/config/GatewayConfig.java @@ -3,6 +3,7 @@ package at.tuwien.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.support.BasicAuthenticationInterceptor; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.DefaultUriBuilderFactory; @@ -12,6 +13,12 @@ public class GatewayConfig { @Value("${fda.gateway.endpoint}") private String gatewayEndpoint; + @Value("${spring.rabbitmq.username}") + private String brokerUsername; + + @Value("${spring.rabbitmq.password}") + private String brokerPassword; + @Bean public RestTemplate restTemplate() { final RestTemplate restTemplate = new RestTemplate(); @@ -19,4 +26,13 @@ public class GatewayConfig { return restTemplate; } + @Bean("brokerRestTemplate") + public RestTemplate brokerRestTemplate() { + final RestTemplate restTemplate = new RestTemplate(); + restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(gatewayEndpoint)); + restTemplate.getInterceptors() + .add(new BasicAuthenticationInterceptor(brokerUsername, brokerPassword)); + return restTemplate; + } + } diff --git a/dbrepo-table-service/services/src/main/java/at/tuwien/exception/AmqpException.java b/dbrepo-table-service/services/src/main/java/at/tuwien/exception/AmqpException.java index 6af0750d6f5089a8442a7159eac2076462df2825..da70a16dd326cb81616e6f25a27b59151d57f33c 100644 --- a/dbrepo-table-service/services/src/main/java/at/tuwien/exception/AmqpException.java +++ b/dbrepo-table-service/services/src/main/java/at/tuwien/exception/AmqpException.java @@ -3,7 +3,7 @@ package at.tuwien.exception; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; -@ResponseStatus(code = HttpStatus.NOT_ACCEPTABLE) +@ResponseStatus(code = HttpStatus.GATEWAY_TIMEOUT) public class AmqpException extends Exception { public AmqpException(String msg) { diff --git a/dbrepo-table-service/services/src/main/java/at/tuwien/exception/DataProcessingException.java b/dbrepo-table-service/services/src/main/java/at/tuwien/exception/DataProcessingException.java index 32c96c4614be5aa4b2ba7d8dc7ff34071dc0f029..fc0555c8e3e175c5cd7aca8e4c16766d2c87a49c 100644 --- a/dbrepo-table-service/services/src/main/java/at/tuwien/exception/DataProcessingException.java +++ b/dbrepo-table-service/services/src/main/java/at/tuwien/exception/DataProcessingException.java @@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; import java.io.IOException; -@ResponseStatus(code = HttpStatus.BAD_REQUEST) +@ResponseStatus(code = HttpStatus.LOCKED) public class DataProcessingException extends Exception { public DataProcessingException(String msg) { diff --git a/dbrepo-table-service/services/src/main/java/at/tuwien/exception/DatabaseConnectionException.java b/dbrepo-table-service/services/src/main/java/at/tuwien/exception/DatabaseConnectionException.java index 3c1f797647d67b4e1cb8148a4aba11b7d06aefc0..63459167f77f9f2350abfee7cdb80ef0c704fda2 100644 --- a/dbrepo-table-service/services/src/main/java/at/tuwien/exception/DatabaseConnectionException.java +++ b/dbrepo-table-service/services/src/main/java/at/tuwien/exception/DatabaseConnectionException.java @@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; import java.io.IOException; -@ResponseStatus(code = HttpStatus.METHOD_NOT_ALLOWED) +@ResponseStatus(code = HttpStatus.SERVICE_UNAVAILABLE) public class DatabaseConnectionException extends Exception { public DatabaseConnectionException(String msg) { diff --git a/dbrepo-table-service/services/src/main/java/at/tuwien/exception/FileStorageException.java b/dbrepo-table-service/services/src/main/java/at/tuwien/exception/FileStorageException.java index ab068e4245526e77b611d1c8571df867d5fc2cb6..21968a6e680f88e85ec1406936dc973c20c5c09b 100644 --- a/dbrepo-table-service/services/src/main/java/at/tuwien/exception/FileStorageException.java +++ b/dbrepo-table-service/services/src/main/java/at/tuwien/exception/FileStorageException.java @@ -3,7 +3,7 @@ package at.tuwien.exception; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; -@ResponseStatus(code = HttpStatus.BAD_REQUEST) +@ResponseStatus(code = HttpStatus.GONE) public class FileStorageException extends Exception { public FileStorageException(String msg) { diff --git a/dbrepo-table-service/services/src/main/java/at/tuwien/mapper/TableMapper.java b/dbrepo-table-service/services/src/main/java/at/tuwien/mapper/TableMapper.java index 73af6027a2dad87ddfc74979ce0da4bd53922b01..d12f4c9e432f0cc081abca833905d6fcda59e266 100644 --- a/dbrepo-table-service/services/src/main/java/at/tuwien/mapper/TableMapper.java +++ b/dbrepo-table-service/services/src/main/java/at/tuwien/mapper/TableMapper.java @@ -9,6 +9,7 @@ import at.tuwien.api.database.table.columns.ColumnDto; import at.tuwien.api.database.table.columns.ColumnTypeDto; import at.tuwien.api.database.table.constraints.ConstraintsCreateDto; import at.tuwien.api.database.table.constraints.foreignKey.ForeignKeyCreateDto; +import at.tuwien.api.database.table.constraints.foreignKey.ForeignKeyDto; import at.tuwien.api.database.table.constraints.foreignKey.ReferenceTypeDto; import at.tuwien.entities.database.Database; import at.tuwien.entities.database.table.Table; @@ -58,6 +59,7 @@ public interface TableMapper { @Mapping(target = "routingKey", expression = "java(data.getRoutingKey())"), @Mapping(source = "description", target = "description"), @Mapping(source = "database.isPublic", target = "isPublic"), + @Mapping(source = "constraints", target = "constraints"), }) TableDto tableToTableDto(Table data); @@ -95,8 +97,17 @@ public interface TableMapper { return columns; } + default List<ColumnDto> uniqueToColumnList(Unique unique) { + return unique.getColumns().stream().map(this::tableColumnToColumnDto).collect(Collectors.toList()); + } + default Unique columnNameListToUnique(Table table, List<String> names) throws TableMalformedException { - return Unique.builder().columns(columnNameListToTableColumn(table, names)).build(); + return Unique.builder() + .tid(table.getId()) + .tdbid(table.getTdbid()) + .table(table) + .columns(columnNameListToTableColumn(table, names)) + .build(); } ReferenceType referenceTypeDtoToReferenceType(ReferenceTypeDto dto); @@ -143,6 +154,29 @@ public interface TableMapper { return foreignKey; } + ReferenceTypeDto referenceTypeDtoToReferenceType(ReferenceType data); + + default ForeignKeyDto foreignKeyCreateDtoToForeignKey(ForeignKey data) { + if (data == null) { + return null; + } + + ForeignKeyDto dto = new ForeignKeyDto( + new ArrayList<>(), + tableToTableBriefDto(data.getReferencedTable()), + new ArrayList<>(), + referenceTypeDtoToReferenceType(data.getOnUpdate()), + referenceTypeDtoToReferenceType(data.getOnDelete()) + ); + + for (ForeignKeyReference reference : data.getReferences()) { + dto.getColumns().add(tableColumnToColumnDto(reference.getColumn())); + dto.getReferencedColumns().add(tableColumnToColumnDto(reference.getReferencedColumn())); + } + + return dto; + } + default Constraints constraintsCreateDtoToConstraints(TableRepository repo, Table table, ConstraintsCreateDto data) throws TableMalformedException { if (data == null) { return null; diff --git a/dbrepo-table-service/services/src/main/java/at/tuwien/mapper/UserMapper.java b/dbrepo-table-service/services/src/main/java/at/tuwien/mapper/UserMapper.java index 56ea4ffa88bebad519c932dc52ebdf8ea94bd06e..e4fe5c286258089991df210c7099437c2670765b 100644 --- a/dbrepo-table-service/services/src/main/java/at/tuwien/mapper/UserMapper.java +++ b/dbrepo-table-service/services/src/main/java/at/tuwien/mapper/UserMapper.java @@ -1,12 +1,17 @@ package at.tuwien.mapper; +import at.tuwien.api.auth.SignupRequestDto; import at.tuwien.api.user.GrantedAuthorityDto; +import at.tuwien.api.user.UserBriefDto; import at.tuwien.api.user.UserDetailsDto; import at.tuwien.api.user.UserDto; +import at.tuwien.entities.user.User; +import at.tuwien.entities.user.UserAttribute; import org.mapstruct.Mapper; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; + @Mapper(componentModel = "spring") public interface UserMapper { @@ -14,9 +19,23 @@ public interface UserMapper { UserDetailsDto userDtoToUserDetailsDto(UserDto data); + UserDto userToUserDto(User data); + + UserBriefDto userToUserBriefDto(User data); + + User signupRequestDtoToUser(SignupRequestDto data); + default GrantedAuthority grantedAuthorityDtoToGrantedAuthority(GrantedAuthorityDto data) { final GrantedAuthority authority = new SimpleGrantedAuthority(data.getAuthority()); log.trace("mapped granted authority {} to granted authority {}", data, authority); return authority; } + + default UserAttribute tripleToUserAttribute(String userId, String name, String value) { + return UserAttribute.builder() + .userId(userId) + .name(name) + .value(value) + .build(); + } } diff --git a/dbrepo-ui/.env.example b/dbrepo-ui/.env.example index 366635afbdd0602eb9736a2ac6dfe47fefb7592e..e475d9c16d60a353b2107e70b0363ecb2078e5ae 100644 --- a/dbrepo-ui/.env.example +++ b/dbrepo-ui/.env.example @@ -1,11 +1,15 @@ -# ATTENTION: remove the last slash for the gateway url -# - CORRECT: http://localhost:9095 -# - WRONG: http://localhost:9095/ -NODE_ENV=dev API="http://localhost:9095" -BROKER_USERNAME=fda -BROKER_PASSWORD=fda +BASE_URL="http://localhost:3001" +BROKER_USERNAME="fda" +BROKER_PASSWORD="fda" +DBREPO_CLIENT_SECRET="MUwRc7yfXSJwX8AdRMWaQC3Nep1VjwgG" +DEFAULT_PID_PUBLISHER="Technische Universität Wien" +DOI_URL="https://doi.org" +ELASTIC_USERNAME="elastic" +ELASTIC_PASSWORD="elastic" +LOGO="/logo.png" +SEARCH="http://localhost:3001/retrieve" SANDBOX=false -SHARED_FILESYSTEM=/tmp -DBREPO_CLIENT_SECRET=MUwRc7yfXSJwX8AdRMWaQC3Nep1VjwgG -DEFAULT_PID_PUBLISHER= +SHARED_FILESYSTEM="/tmp" +TITLE="Database Repository" +VERSION="latest" diff --git a/dbrepo-ui/.prod/default.conf b/dbrepo-ui/.prod/default.conf new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/dbrepo-ui/Dockerfile b/dbrepo-ui/Dockerfile index 729a01636095da65efede0bbee586c81025d7db4..bc7cd4d45674387f3ca32cb535e2cb42350c7c15 100644 --- a/dbrepo-ui/Dockerfile +++ b/dbrepo-ui/Dockerfile @@ -8,7 +8,8 @@ ARG TAG=1.2 ENV NODE_ENV=production ENV HOST=0.0.0.0 -ENV API=http://:8080 +ENV API=http://:80 +ENV BASE_URL=http://:80 WORKDIR /app @@ -42,18 +43,19 @@ MAINTAINER Martin Weise <martin.weise@tuwien.ac.at> EXPOSE 3000 EXPOSE 9100 -ENV BROKER_USERNAME=fda -ENV BROKER_PASSWORD=fda +ENV BROKER_USERNAME="fda" +ENV BROKER_PASSWORD="fda" ENV SANDBOX=false -ENV SEARCH=http://search-service:9200 -ENV SHARED_FILESYSTEM=/tmp +ENV SEARCH="http://search-service:9200" +ENV SHARED_FILESYSTEM="/tmp" ENV LOGO="/logo.png" ENV MAIL_VERIFY=false -ENV ELASTIC_PASSWORD=elastic +ENV ELASTIC_USERNAME="elastic" +ENV ELASTIC_PASSWORD="elastic" ENV VERSION="${TAG}" ENV TITLE="Database Repository" ENV ICON="/favicon.ico" -ENV DBREPO_CLIENT_SECRET=client-secret +ENV DBREPO_CLIENT_SECRET="client-secret" WORKDIR /app diff --git a/dbrepo-ui/api/authentication.service.js b/dbrepo-ui/api/authentication.service.js index df567c8add375a689d7cf14ba5cdc7d74c574d6e..5c86f9cd95a9a6a005934ed7908af719e6a10a06 100644 --- a/dbrepo-ui/api/authentication.service.js +++ b/dbrepo-ui/api/authentication.service.js @@ -3,7 +3,7 @@ import store from '@/store' import qs from 'qs' import UserMapper from '@/api/user.mapper' import axios from 'axios' -import { api as endpoint, clientSecret } from '@/config' +import { baseURL, clientSecret } from '../config' /** * Service class for interaction with Authentication Service in the back end. @@ -28,13 +28,22 @@ class AuthenticationService { scope: 'roles' } if (!username) { - throw new Error('parameter username is empty') + return new Promise((resolve, reject) => { + Vue.$toast.warning('[client-error] Parameter username is empty') + reject(new Error('parameter username is empty')) + }) } if (!password) { - throw new Error('parameter password is empty') + return new Promise((resolve, reject) => { + Vue.$toast.warning('[client-error] Parameter password is empty') + reject(new Error('parameter password is empty')) + }) } - if (!clientSecret) { - throw new Error('parameter clientSecret is empty') + if (!payload.client_secret) { + return new Promise((resolve, reject) => { + Vue.$toast.warning('[client-error] Parameter clientSecret is empty') + reject(new Error('parameter clientSecret is empty')) + }) } return this._authenticate(payload) } @@ -47,10 +56,16 @@ class AuthenticationService { refresh_token: refreshToken } if (!refreshToken) { - throw new Error('parameter refreshToken is empty') + return new Promise((resolve, reject) => { + Vue.$toast.warning('[client-error] Parameter refreshToken is empty') + reject(new Error('parameter refreshToken is empty')) + }) } - if (!clientSecret) { - throw new Error('parameter clientSecret is empty') + if (!payload.client_secret) { + return new Promise((resolve, reject) => { + Vue.$toast.warning('[client-error] Parameter clientSecret is empty') + reject(new Error('parameter clientSecret is empty')) + }) } return this._authenticate(payload) } @@ -60,7 +75,7 @@ class AuthenticationService { const instance = axios.create({ timeout: 10000, params: {}, - baseURL: endpoint, + baseURL, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } diff --git a/dbrepo-ui/api/broker.service.js b/dbrepo-ui/api/broker.service.js new file mode 100644 index 0000000000000000000000000000000000000000..32a9ba2bbf7c3b97ca16b3c176f839d9772078c1 --- /dev/null +++ b/dbrepo-ui/api/broker.service.js @@ -0,0 +1,25 @@ +import Vue from 'vue' +import axios from 'axios' +import { brokerUsername, brokerPassword } from '../config' + +class BrokerService { + findConsumers () { + return new Promise((resolve, reject) => { + const basic = btoa(`${brokerUsername}:${brokerPassword}`) + axios.get('/api/broker/consumers/%2F', { headers: { Authorization: 'Basic ' + basic } }) + .then((response) => { + const consumers = response.data + console.debug('response consumers', consumers) + resolve(consumers) + }) + .catch((error) => { + const { code, message } = error + console.error('Failed to load consumers', error) + Vue.$toast.error(`[${code}] Failed to load consumers: ${message}`) + reject(error) + }) + }) + } +} + +export default new BrokerService() diff --git a/dbrepo-ui/api/container.mapper.js b/dbrepo-ui/api/container.mapper.js new file mode 100644 index 0000000000000000000000000000000000000000..828a5fbc931ef11047aeb82c5f2d7b2efdaa8722 --- /dev/null +++ b/dbrepo-ui/api/container.mapper.js @@ -0,0 +1,16 @@ +import UserMapper from '@/api/user.mapper' +import DatabaseMapper from '@/api/database.mapper' + +class ContainerMapper { + containerToCreator (container) { + if (!container) { + return null + } + if (container.database) { + return DatabaseMapper.databaseToOwner(container.database) + } + return UserMapper.userToFullName(container.creator) + } +} + +export default new ContainerMapper() diff --git a/dbrepo-ui/api/container.service.js b/dbrepo-ui/api/container.service.js index 48adb5427bad97840ba73756d9683d50f40c730c..77f56972b5e85df9c3a5a844551c349645f7c1e6 100644 --- a/dbrepo-ui/api/container.service.js +++ b/dbrepo-ui/api/container.service.js @@ -36,6 +36,23 @@ class ContainerService { }) } + findImage (id) { + return new Promise((resolve, reject) => { + api.get(`/api/image/${id}`, { headers: { Accept: 'application/json' } }) + .then((response) => { + const image = response.data + console.debug('response image', image) + resolve(image) + }) + .catch((error) => { + const { code, message } = error + console.error('Failed to load image', error) + Vue.$toast.error(`[${code}] Failed to load image: ${message}`) + reject(error) + }) + }) + } + create (data) { return new Promise((resolve, reject) => { api.post('/api/container', data, { headers: { Accept: 'application/json' } }) diff --git a/dbrepo-ui/api/database.mapper.js b/dbrepo-ui/api/database.mapper.js new file mode 100644 index 0000000000000000000000000000000000000000..4d73506822c0c7dd7c1aef3f100557ec299d8038 --- /dev/null +++ b/dbrepo-ui/api/database.mapper.js @@ -0,0 +1,23 @@ +import UserMapper from '@/api/user.mapper' +import IdentifierMapper from '@/api/identifier.mapper' + +class DatabaseMapper { + databaseToOwner (database) { + if (!database) { + return null + } + if (database.identifier) { + return IdentifierMapper.identifierToCreators(database.identifier) + } + return UserMapper.userToFullName(database.owner) + } + + databaseToContact (database) { + if (!database) { + return null + } + return UserMapper.userToFullName(database.contact) + } +} + +export default new DatabaseMapper() diff --git a/dbrepo-ui/api/database.service.js b/dbrepo-ui/api/database.service.js index 1d0273c505a988ead4dd6338065ea92f8129de9a..0b91b04637e0b39fde2fa450843f5ab7d6654290 100644 --- a/dbrepo-ui/api/database.service.js +++ b/dbrepo-ui/api/database.service.js @@ -142,6 +142,23 @@ class DatabaseService { }) }) } + + findAllLicenses (id) { + return new Promise((resolve, reject) => { + api.get(`/api/container/${id}/database/license`, { headers: { Accept: 'application/json' } }) + .then((response) => { + const licenses = response.data + console.debug('response licenses', licenses) + resolve(licenses) + }) + .catch((error) => { + const { code, message } = error + console.error('Failed to load licenses', error) + Vue.$toast.error(`[${code}] Failed to load licenses: ${message}`) + reject(error) + }) + }) + } } export default new DatabaseService() diff --git a/dbrepo-ui/api/identifier.mapper.js b/dbrepo-ui/api/identifier.mapper.js new file mode 100644 index 0000000000000000000000000000000000000000..47b111000d1a3a9fcb3051d7c32322fd92bc8306 --- /dev/null +++ b/dbrepo-ui/api/identifier.mapper.js @@ -0,0 +1,27 @@ +class IdentifierMapper { + identifierToCreators (identifier) { + if (!identifier) { + return null + } + const creators = identifier.creators + let str = '' + for (let i = 0; i < creators.length; i++) { + /* separator */ + if (creators.length > 1 && i === creators.length - 1) { + str += ', & ' + } else if (i > 0 && creators.length !== 2) { + str += ', ' + } + /* name */ + if (creators[i].firstname) { + str += (creators[i].firstname.toUpperCase().substring(0, 1) + '., ') + } + if (creators[i].lastname) { + str += creators[i].lastname + } + } + return str + } +} + +export default new IdentifierMapper() diff --git a/dbrepo-ui/api/identifier.service.js b/dbrepo-ui/api/identifier.service.js index 549cd0eabd4e9282ead1788e44fbdf2d9d780268..f35bcd886e853600cc8d731dea94970d0f0f0ece 100644 --- a/dbrepo-ui/api/identifier.service.js +++ b/dbrepo-ui/api/identifier.service.js @@ -18,6 +18,23 @@ class IdentifierService { }) }) } + + create (data) { + return new Promise((resolve, reject) => { + api.post('/api/identifier', data, { headers: { Accept: 'application/json' } }) + .then((response) => { + const identifier = response.data + console.debug('response identifier', identifier) + resolve(identifier) + }) + .catch((error) => { + const { code, message } = error + console.error('Failed to load identifier', error) + Vue.$toast.error(`[${code}] Failed to load identifier: ${message}`) + reject(error) + }) + }) + } } export default new IdentifierService() diff --git a/dbrepo-ui/api/index.js b/dbrepo-ui/api/index.js index 53c4143ccfe36402902d4ab9086c4f04a4194793..454693fd65ca2f69127472739ee8b66fab656fc3 100644 --- a/dbrepo-ui/api/index.js +++ b/dbrepo-ui/api/index.js @@ -1,13 +1,10 @@ import axios from 'axios' -import { api as endpoint } from '@/config' +import { baseURL } from '../config' const instance = axios.create({ timeout: 10000, params: {}, - baseURL: endpoint, - headers: { - 'Access-Control-Allow-Origin': '*' - } + baseURL }) export default instance diff --git a/dbrepo-ui/api/user.mapper.js b/dbrepo-ui/api/user.mapper.js index 31a690e509785299c785fc22ff116c0ab513b448..65237a5d05467e48719506eca8ce34f21f773dbd 100644 --- a/dbrepo-ui/api/user.mapper.js +++ b/dbrepo-ui/api/user.mapper.js @@ -20,6 +20,16 @@ class UserMapper { } return obj } + + userToFullName (user) { + if (!user) { + return null + } + if (!('given_name' in user) || !('family_name' in user) || user.given_name === null || user.family_name === null) { + return user?.username + } + return user.given_name + ' ' + user.family_name + } } export default new UserMapper() diff --git a/dbrepo-ui/components/DatabaseList.vue b/dbrepo-ui/components/DatabaseList.vue index 8fe1e8a0de97aa7c8b0755b71a4af4bcf1f39942..09a64f2f9a75fea3cb8ac7d26b6863379dc1f8c6 100644 --- a/dbrepo-ui/components/DatabaseList.vue +++ b/dbrepo-ui/components/DatabaseList.vue @@ -12,8 +12,7 @@ <v-card-title v-if="hasDatabase(container)"> <a :href="`/container/${container.id}/database/${container.database.id}`">{{ container.name }}</a> </v-card-title> - <v-card-subtitle v-if="!hasIdentifier(container)" class="db-subtitle" v-text="formatOwner(container)" /> - <v-card-subtitle v-if="hasIdentifier(container)" class="db-subtitle" v-text="formatCreators(container)" /> + <v-card-subtitle class="db-subtitle" v-text="formatCreators(container)" /> <v-card-text v-if="hasDatabase(container)" class="db-description"> <div class="db-tags"> <v-chip v-if="hasDatabase(container) && container.database.is_public" small color="green" outlined>Public</v-chip> @@ -59,9 +58,10 @@ </template> <script> -import { formatCreators, formatUser, formatYearUTC, isResearcher } from '@/utils' +import { formatYearUTC, isResearcher } from '@/utils' import DatabaseService from '@/api/database.service' import ContainerService from '@/api/container.service' +import ContainerMapper from '@/api/container.mapper' export default { data () { @@ -106,15 +106,8 @@ export default { this.loadContainers() }, methods: { - formatOwner (container) { - if (!('database' in container) || !container.database) { - return formatUser(container.creator) - } - return formatUser(container.database?.owner) - }, formatCreators (container) { - const creators = formatCreators(container) - return creators || this.formatUser(container.creator) + return ContainerMapper.containerToCreator(container) }, needsStart (container) { if (!this.user) { diff --git a/dbrepo-ui/components/TableList.vue b/dbrepo-ui/components/TableList.vue index f6ce9958e2f88304337a834505b31dd270e6cc72..86aed98663b9b03ce9f2f121342b87fa302a2f8c 100644 --- a/dbrepo-ui/components/TableList.vue +++ b/dbrepo-ui/components/TableList.vue @@ -24,19 +24,18 @@ <script> import { formatTimestampUTCLabel } from '@/utils' +import TableService from '@/api/table.service' export default { data () { return { loading: false, loadingDetails: false, - loadingConsumers: false, error: false, panel: null, column: null, dialogSemantic: false, mode: 'unit', - consumers: [], access: { type: null }, @@ -103,12 +102,6 @@ export default { } return this.database.tables }, - brokerConfig () { - return { - headers: { Authorization: 'Basic ' + btoa(`${this.$config.brokerUsername}:${this.$config.brokerPassword}`) }, - progress: false - } - }, createdUTC () { if (this.tableDetails.created === undefined || this.tableDetails.created === null) { return null @@ -132,9 +125,6 @@ export default { return this.database.creator.username === this.user.username } }, - mounted () { - this.pollConsumerStatus() - }, methods: { pick (item, mode) { this.column = item @@ -154,25 +144,22 @@ export default { } return column.column_type }, - async details (table) { + details (table) { /* use cache */ this.tableDetails = table /* load remaining info */ if (this.canRead) { - try { - this.loadingDetails = true - const res = await this.$axios.get(`/api/container/${this.$route.params.container_id}/database/${this.$route.params.database_id}/table/${table.id}`, this.config) - this.tableDetails = res.data - console.debug('table details', this.tableDetails) - if (table.id) { - this.openPanelByTableId(table.id) - await this.consumerDetails(this.tableDetails.queue_name) - } - } catch (err) { - this.$toast.error('Failed to load table details') - console.error('Failed to load table details', err) - } - this.loadingDetails = false + this.loadingDetails = true + TableService.findOne(this.$route.params.container_id, this.$route.params.database_id, table.id) + .then((table) => { + this.tableDetails = table + if (table.id) { + this.openPanelByTableId(table.id) + } + }) + .finally(() => { + this.loadingDetails = false + }) } }, is_owner (table) { @@ -199,28 +186,6 @@ export default { } this.dialogDelete = false }, - async consumerDetails (queueName) { - try { - this.loadingConsumers = true - const res = await this.$axios.get('/api/broker/consumers/%2F', this.brokerConfig) - const consumers = res.data.filter(c => c.queue.name === queueName) - console.debug('consumers', consumers) - this.consumers = consumers - } catch (err) { - console.error('Could not find consumers', err) - } - this.loadingConsumers = false - }, - pollConsumerStatus () { - if (this.tableDetails === undefined || this.tableDetails.queue_name === undefined) { - return - } - this.consumerDetails(this.tableDetails.queue_name) - }, - showDeleteTableDialog (id) { - this.deleteTableId = id - this.dialogDelete = true - }, /** * open up the accordion with the table that has been updated (by the ColumnUnit dialog) */ @@ -244,7 +209,4 @@ export default { .full-width { width: 100%; } -.amqp-consumer { - display: inline; -} </style> diff --git a/dbrepo-ui/components/TableSchema.vue b/dbrepo-ui/components/TableSchema.vue index 82593a90b19456a39f6d6f2a25f8ae39c0f9f69d..a70d6c7563534f8b6361b7cf00d9cf63201edfae 100644 --- a/dbrepo-ui/components/TableSchema.vue +++ b/dbrepo-ui/components/TableSchema.vue @@ -99,6 +99,7 @@ </template> <script> +import ContainerService from '@/api/container.service' export default { props: { columns: { @@ -165,7 +166,6 @@ export default { mounted () { this.localLoading = this.loading this.loadContainer() - .then(() => this.loadImage()) }, methods: { needsShift (column) { @@ -174,31 +174,19 @@ export default { } return this.columns.filter(c => c.type === 'date' || c.type === 'timestamp').length > 0 }, - async loadContainer () { - const getUrl = `/api/container/${this.$route.params.container_id}` - try { - this.localLoading = true - const res = await this.$axios.get(getUrl) - this.container = res.data - console.debug('retrieve container', this.container) - } catch (err) { - this.error = true - console.error('retrieve image date formats failed', err) - } - this.localLoading = false - }, - async loadImage () { - const getUrl = `/api/image/${this.container.image.id}` - try { - this.localLoading = true - const res = await this.$axios.get(getUrl) - this.dateFormats = res.data.date_formats - console.debug('retrieve image date formats', this.dateFormats) - } catch (err) { - this.error = true - console.error('retrieve image date formats failed', err) - } - this.localLoading = false + loadContainer () { + this.localLoading = true + ContainerService.findOne(this.$route.params.container_id) + .then((container) => { + this.container = container + ContainerService.findImage(container.image.id) + .then((image) => { + this.dateFormats = image.date_formats + }) + }) + .finally(() => { + this.localLoading = false + }) }, submit () { this.finished = true diff --git a/dbrepo-ui/components/dialogs/EditTuple.vue b/dbrepo-ui/components/dialogs/EditTuple.vue index c8407c457c417db1bc7fc73407378ba7f850d62c..8527fa95b5136e09c7264bfea10146a62fb8dc5f 100644 --- a/dbrepo-ui/components/dialogs/EditTuple.vue +++ b/dbrepo-ui/components/dialogs/EditTuple.vue @@ -152,7 +152,7 @@ export default { }, watch: { tuple (val) { - this.localTuple = val + this.localTuple = Object.assign({}, val) } }, mounted () { diff --git a/dbrepo-ui/components/dialogs/Persist.vue b/dbrepo-ui/components/dialogs/Persist.vue index 7ad914ef20d90eda49a8f9069efb5f617d44b191..1f87e7ef2d30383c52d8cdf75b6eed62af5728bb 100644 --- a/dbrepo-ui/components/dialogs/Persist.vue +++ b/dbrepo-ui/components/dialogs/Persist.vue @@ -64,19 +64,6 @@ required /> </v-col> </v-row> - <v-row dense> - <v-col> - <v-select - id="visibility" - v-model="visibility" - name="visibility" - label="Visibility *" - :items="['Public']" - disabled - :rules="[v => !!v || $t('Required')]" - required /> - </v-col> - </v-row> <v-row v-for="(creator, i) in identifier.creators" :key="`c-${i}`" dense> <v-col cols="3"> <v-text-field @@ -194,6 +181,8 @@ <script> import { formatYearUTC, formatMonthUTC, formatDayUTC } from '@/utils' +import IdentifierService from '@/api/identifier.service' +import DatabaseService from '@/api/database.service' export default { props: { type: { @@ -213,7 +202,6 @@ export default { loading: false, error: false, // XXX: `error` is never changed licenses: [], - visibility: 'Public', identifier: { cid: parseInt(this.$route.params.container_id), dbid: parseInt(this.$route.params.database_id), @@ -225,10 +213,15 @@ export default { publication_month: formatMonthUTC(Date.now()), publication_day: formatDayUTC(Date.now()), license: null, - visibility: 'everyone', type: this.type, - doi: null, - creators: [], + creators: [ + { + firstname: null, + lastname: null, + affiliation: null, + orcid: null + } + ], related_identifiers: [] }, relatedTypes: [ @@ -299,16 +292,6 @@ export default { user () { return this.$store.state.user }, - config () { - if (this.token === null) { - return { - headers: { Accept: 'application/json' } - } - } - return { - headers: { Authorization: `Bearer ${this.token}`, Accept: 'application/json' } - } - }, isSubset () { return this.type === 'subset' }, @@ -334,7 +317,6 @@ export default { }, mounted () { this.loadLicenses() - this.addCreator() this.identifier.publisher = this.$config.defaultPublisher }, methods: { @@ -366,55 +348,30 @@ export default { deleteRelatedIdentifier (index) { this.identifier.related_identifiers.splice(index, 1) }, - async persist () { + persist () { this.loading = true - let res - try { - res = await this.$axios.post('/api/identifier', this.identifier, this.config) - console.debug('persist', res.data) - await this.loadDatabase() - } catch (err) { - this.error = true - this.loading = false - this.$toast.error('Failed to persist') - console.error('persist failed', err) - return - } - this.$toast.success(this.prefix + ' successfully persisted') - this.$emit('close', { action: 'persisted' }) - this.loading = false + IdentifierService.create(this.identifier) + .then(() => { + this.$store.dispatch('reloadDatabase') + this.$toast.success(this.prefix + ' successfully persisted') + this.$emit('close', { action: 'persisted' }) + }) + .finally(() => { + this.loading = false + }) }, - async loadLicenses () { + loadLicenses () { if (!this.token) { return } this.loading = true - try { - const res = await this.$axios.get(`/api/container/${this.$route.params.container_id}/database/license`, this.config) - this.licenses = res.data - console.debug('license', this.licenses) - } catch (error) { - console.error('Failed load licenses', error) - const { data } = error.response - const { message } = data - this.$toast.error(`Failed load licenses: ${message}`) - } - this.loading = false - }, - async loadDatabase () { - if (!this.$route.params.container_id || !this.$route.params.database_id) { - return - } - try { - this.loading = true - const res = await this.$axios.get(`/api/container/${this.$route.params.container_id}/database/${this.$route.params.database_id}`, this.config) - this.$store.commit('SET_DATABASE', res.data) - console.debug('database', this.database) - } catch (err) { - console.error('Could not load database', err) - this.$toast.error('Could not load database') - } - this.loading = false + DatabaseService.findAllLicenses(this.$route.params.container_id) + .then((licenses) => { + this.licenses = licenses + }) + .finally(() => { + this.loading = false + }) } } } diff --git a/dbrepo-ui/components/identifier/Banner.vue b/dbrepo-ui/components/identifier/Banner.vue new file mode 100644 index 0000000000000000000000000000000000000000..8756962c9e9b4e3106078e603e1db4209b272fab --- /dev/null +++ b/dbrepo-ui/components/identifier/Banner.vue @@ -0,0 +1,33 @@ +<template> + <p v-if="identifier?.doi">DOI: <a :href="doiUrl(identifier.doi)">{{ identifier.doi }}</a></p> + <p v-else-if="identifier?.id"><a :href="pidUrl(identifier.id)">{{ pidUrl(identifier.id) }}</a></p> +</template> +yarn dev +<script> + +export default { + props: { + identifier: { + type: Object, + default () { + return null + } + } + }, + computed: { + baseUrl () { + return `${location.protocol}//${location.host}` + } + }, + methods: { + pidUrl (pid) { + return `${this.baseUrl}/pid/${pid}` + }, + doiUrl (doi) { + return `${this.$config.doiUrl}/${doi}` + } + } +} +</script> + +<style scoped></style> diff --git a/dbrepo-ui/config.js b/dbrepo-ui/config.js index cb738d6280ada1d091e30afab9486c8d6ae36f63..d3601fcc92496928c3989683e9ae1fc79ead5240 100644 --- a/dbrepo-ui/config.js +++ b/dbrepo-ui/config.js @@ -1,6 +1,7 @@ const config = {} config.api = process.env.API || 'http://localhost' +config.baseUrl = process.env.BASE_URL || 'http://localhost' config.search = process.env.SEARCH || 'http://localhost/retrieve' config.sandbox = process.env.SANDBOX || false config.title = process.env.TITLE || 'Database Repository' @@ -13,8 +14,7 @@ config.logo = process.env.LOGO || '/logo.png' config.mailVerify = process.env.MAIL_VERIFY || false config.tokenMax = process.env.TOKEN_MAX || 5 config.elasticPassword = process.env.ELASTIC_PASSWORD || 'elastic' -config.elasticPassword = process.env.ELASTIC_PASSWORD || 'elastic' config.clientSecret = process.env.DBREPO_CLIENT_SECRET || 'MUwRc7yfXSJwX8AdRMWaQC3Nep1VjwgG' -config.defaultPublisher = process.env.DEFAULT_PID_PUBLISHER +config.defaultPublisher = process.env.DEFAULT_PID_PUBLISHER || 'Technische Universität Wien' module.exports = config diff --git a/dbrepo-ui/layouts/default.vue b/dbrepo-ui/layouts/default.vue index ce9934fec660d00f75a1b6fcc762e1fea25e37d8..ffb5a9430e6cd2c6fb77016cd543765cd8784b99 100644 --- a/dbrepo-ui/layouts/default.vue +++ b/dbrepo-ui/layouts/default.vue @@ -173,23 +173,6 @@ export default { version () { return this.$config.version }, - config () { - if (this.token === null) { - return {} - } - return { - headers: { Authorization: `Bearer ${this.token}` } - } - }, - clientSecret () { - return this.$config.clientSecret - }, - silentConfig () { - return { - headers: this.config.headers, - progress: false - } - }, sandbox () { if (this.$config.sandbox === undefined) { console.debug('env sandbox not found, default to', false) diff --git a/dbrepo-ui/nuxt.config.js b/dbrepo-ui/nuxt.config.js index 27277ba5076a6e82f5dc30b4425d146455e1e6f8..941b0d2d714ac05355f09564e9903b4a65594ea6 100644 --- a/dbrepo-ui/nuxt.config.js +++ b/dbrepo-ui/nuxt.config.js @@ -1,6 +1,26 @@ import path from 'path' import colors from 'vuetify/es5/util/colors' -import { sandbox, title, icon, brokerUsername, brokerPassword, sharedFilesystem, version, logo, mailVerify, tokenMax, elasticPassword, clientSecret, api, search, defaultPublisher } from './config' +import { api, icon, search, clientSecret, title, sandbox, logo, version, defaultPublisher } from './config' + +const proxy = {} + +if (process.env.NODE_ENV === 'development') { + proxy['/api'] = api + proxy['/pid'] = { + target: api + '/api', + changeOrigin: true, + pathRewrite: { + '^/pid': '/pid' + } + } + proxy['/retrieve'] = { + target: search, + changeOrigin: true, + pathRewrite: { + '^/retrieve': '' + } + } +} export default { target: 'server', @@ -42,6 +62,7 @@ export default { components: true, buildModules: [ + '@nuxtjs/dotenv', '@nuxtjs/eslint-module', '@nuxtjs/vuetify' ], @@ -61,19 +82,15 @@ export default { ], axios: { - proxy: true + proxy: proxy !== {} }, + proxy, + publicRuntimeConfig: { - brokerUsername, - brokerPassword, sandbox, - sharedFilesystem, version, logo, - mailVerify, - tokenMax, - elasticPassword, clientSecret, defaultPublisher }, diff --git a/dbrepo-ui/package.json b/dbrepo-ui/package.json index 568ee827abb2ba00b51961cfac1c3110c9812147..b310403577d3b2afb6ca85ade62e2f9da892a22e 100644 --- a/dbrepo-ui/package.json +++ b/dbrepo-ui/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "private": true, "scripts": { - "dev": "nuxt --port 3001", + "dev": "NODE_ENV=development nuxt --port 3001", "docker": "nuxt > /dev/null", "build": "nuxt build", "start": "nuxt start", @@ -12,7 +12,7 @@ "ver": "nuxt --version", "lint:js": "eslint --ext .js,.vue --ignore-path .gitignore .", "lint": "yarn lint:js", - "coverage": "nyc ava test/unit/**/* test/specs/**/* > ./coverage.txt", + "coverage": "nyc ava test/unit/**/* test/specs/**/*", "test:unit": "ava test/unit/**/* test/specs/**/*", "test:watch": "ava --watch test/unit/**/* test/specs/**/*", "test:e2e": "yarn clean && cross-env PORT=3001 ava --timeout=2h --fail-fast test/e2e/**", @@ -24,6 +24,7 @@ "@mdi/js": "^5.8.55", "@nuxtjs/axios": "^5.13.6", "@nuxtjs/eslint-module": "^2.0.0", + "@nuxtjs/dotenv": "^1.4.1", "@nuxtjs/proxy": "^2.1.0", "@nuxtjs/vuetify": "^1.11.2", "axios": "^1.3.0", @@ -62,7 +63,6 @@ "@babel/preset-env": "^7.14.4", "@babel/register": "^7.13.16", "@nuxt/test-utils": "^0.2.2", - "@nuxtjs/dotenv": "^1.4.1", "@nuxtjs/eslint-config": "^3.1.0", "@vue/test-utils": "^1.2.0", "ava": "^3.15.0", diff --git a/dbrepo-ui/pages/container/_container_id/database/_database_id/info.vue b/dbrepo-ui/pages/container/_container_id/database/_database_id/info.vue index 8db247d37184d1b2393fa617e09da947cb2fbdd6..63784829417240bc3a69b2264213198044060dff 100644 --- a/dbrepo-ui/pages/container/_container_id/database/_database_id/info.vue +++ b/dbrepo-ui/pages/container/_container_id/database/_database_id/info.vue @@ -15,7 +15,7 @@ </v-list-item-title> <v-list-item-content> <v-skeleton-loader v-if="loading" type="text" class="skeleton-small" /> - <a v-if="!loading" :href="pid">{{ pid }}</a> + <Banner v-if="!loading" :identifier="database.identifier" /> </v-list-item-content> <v-list-item-title class="mt-2"> Database Title @@ -228,14 +228,17 @@ import DBToolbar from '@/components/DBToolbar' import Persist from '@/components/dialogs/Persist' import OrcidIcon from '@/components/icons/OrcidIcon' import Citation from '@/components/identifier/Citation' -import { formatTimestampUTCLabel, formatUser } from '@/utils' +import { formatTimestampUTCLabel } from '@/utils' +import Banner from '@/components/identifier/Banner' +import DatabaseMapper from '@/api/database.mapper' export default { components: { DBToolbar, Persist, OrcidIcon, - Citation + Citation, + Banner }, data () { return { @@ -260,6 +263,18 @@ export default { baseUrl () { return location.protocol + '//' + location.host }, + description () { + if (!this.hasIdentifier) { + return '' + } + return this.database.identifier.description + }, + publisher () { + if (!this.hasIdentifier) { + return '' + } + return this.database.identifier.publisher + }, token () { return this.$store.state.token }, @@ -281,16 +296,6 @@ export default { database () { return this.$store.state.database }, - config () { - if (this.token === null) { - return { - headers: { Accept: 'application/json' } - } - } - return { - headers: { Authorization: `Bearer ${this.token}`, Accept: 'application/json' } - } - }, pid () { return `${this.baseUrl}/pid/${this.database.identifier.id}` }, @@ -334,10 +339,7 @@ export default { return this.roles.includes('delete-identifier') }, contact () { - if (this.database.contact === null || this.database.contact === undefined) { - return null - } - return formatUser(this.database.contact) + return DatabaseMapper.databaseToContact(this.database) }, publication () { if (this.database.identifier.publication_year === null) { @@ -349,7 +351,7 @@ export default { } }, creator () { - return formatUser(this.database.creator) + return DatabaseMapper.databaseToOwner(this.database) }, creatorVerified () { return this.database.creator.email_verified diff --git a/dbrepo-ui/pages/container/_container_id/database/_database_id/query/_query_id/index.vue b/dbrepo-ui/pages/container/_container_id/database/_database_id/query/_query_id/index.vue index 042ef0a7f0faa3947759f1cc74748d7051eca41f..02bb472500ae4443a906eed98baa2522af925bc6 100644 --- a/dbrepo-ui/pages/container/_container_id/database/_database_id/query/_query_id/index.vue +++ b/dbrepo-ui/pages/container/_container_id/database/_database_id/query/_query_id/index.vue @@ -84,7 +84,7 @@ Persistent Identifier </v-list-item-title> <v-list-item-content> - <a :href="`${baseUrl}/pid/${query.identifier.id}`">{{ baseUrl }}/pid/{{ query.identifier.id }}</a> + <Banner :identifier="query.identifier" /> </v-list-item-content> <v-list-item-title class="mt-2"> Title @@ -220,6 +220,7 @@ <script> import Persist from '@/components/dialogs/Persist' import Citation from '@/components/identifier/Citation' +import Banner from '@/components/identifier/Banner' import { formatTimestampUTCLabel, formatDateUTC } from '@/utils' import QueryService from '@/api/query.service' @@ -227,7 +228,8 @@ export default { name: 'QueryShow', components: { Persist, - Citation + Citation, + Banner }, data () { return { diff --git a/dbrepo-ui/pages/container/_container_id/database/_database_id/table/_table_id/info.vue b/dbrepo-ui/pages/container/_container_id/database/_database_id/table/_table_id/info.vue index fdcfac698ec021c6232ba814f4d26bc0e57f0d43..8f7e4e6b53c0a7dd5594bed0fd4db8645beb72ba 100644 --- a/dbrepo-ui/pages/container/_container_id/database/_database_id/table/_table_id/info.vue +++ b/dbrepo-ui/pages/container/_container_id/database/_database_id/table/_table_id/info.vue @@ -98,7 +98,9 @@ </template> <script> import TableToolbar from '@/components/TableToolbar' -import { formatTimestampUTCLabel, formatUser } from '@/utils' +import { formatTimestampUTCLabel } from '@/utils' +import BrokerService from '@/api/broker.service' +import UserMapper from '@/api/user.mapper' export default { components: { @@ -122,17 +124,6 @@ export default { token () { return this.$store.state.token }, - config () { - if (this.token === null) { - return { - headers: {}, - progress: false - } - } - return { - headers: { Authorization: `Bearer ${this.token}` } - } - }, user () { return this.$store.state.user }, @@ -201,25 +192,19 @@ export default { return null } return this.version.substring(0, 10) + 'T' + this.version.substring(11, 19) + 'Z' - }, - brokerConfig () { - return { - headers: { Authorization: 'Basic ' + btoa(`${this.$config.brokerUsername}:${this.$config.brokerPassword}`) }, - progress: false - } } }, watch: { table () { - this.pollConsumerStatus() + this.consumerDetails() } }, mounted () { - this.pollConsumerStatus() + this.consumerDetails() }, methods: { formatCreator (creator) { - return formatUser(creator) + return UserMapper.userToFullName(creator) }, is_owner (table) { if (!this.user) { @@ -227,20 +212,18 @@ export default { } return table.creator.username === this.user.username }, - async pollConsumerStatus () { - if (this.table === null || this.table.queue_name === null) { + consumerDetails () { + if (!this.table) { return } - try { - const res = await this.$axios.get('/api/broker/consumers/%2F', this.brokerConfig) - const consumers = res.data.filter(c => c.queue.name === this.table.queue_name) - console.debug('filtered', consumers) - this.consumers = consumers - } catch (error) { - const { message } = error - console.error('Failed to find consumers', error) - this.$toast.error(`Failed to find consumers: ${message}`) - } + this.loadingConsumers = true + BrokerService.findConsumers() + .then((consumers) => { + this.consumers = consumers.filter(c => c.queue.name === this.table.queue_name) + }) + .finally(() => { + this.loadingConsumers = false + }) } } } diff --git a/dbrepo-ui/pages/container/_container_id/database/_database_id/table/_table_id/schema.vue b/dbrepo-ui/pages/container/_container_id/database/_database_id/table/_table_id/schema.vue index 3f2e2818c750cbbb587c758f4e19ec2a371736bc..f65171b8e56925a18c53b6c0e8a3a833cfb01623 100644 --- a/dbrepo-ui/pages/container/_container_id/database/_database_id/table/_table_id/schema.vue +++ b/dbrepo-ui/pages/container/_container_id/database/_database_id/table/_table_id/schema.vue @@ -13,7 +13,7 @@ <span v-if="item.is_null_allowed">●</span> {{ item.is_null_allowed }} </template> <template v-slot:item.unique="{ item }"> - <span v-if="item.unique">●</span> {{ item.unique }} + <span v-if="isUnique(item)">●</span> {{ isUnique(item) }} </template> <template v-slot:item.column_type="{ item }"> {{ columnName(item) }} @@ -170,6 +170,9 @@ export default { mounted () { }, methods: { + isUnique (column) { + return !!this.table.constraints?.uniques?.some(uniqueCols => [...uniqueCols].every(unique => unique.id === column.id)) + }, columnName (column) { const filter = this.columnTypes.filter(t => t.value === column.column_type) if (filter.length > 0) { diff --git a/dbrepo-ui/pages/container/_container_id/database/_database_id/table/create.vue b/dbrepo-ui/pages/container/_container_id/database/_database_id/table/create.vue index e85a9d20187075bf6fce24bf001da095fe8075d7..728b71f7da98533038eacc60818a209c104cbda4 100644 --- a/dbrepo-ui/pages/container/_container_id/database/_database_id/table/create.vue +++ b/dbrepo-ui/pages/container/_container_id/database/_database_id/table/create.vue @@ -153,7 +153,40 @@ export default { }, createTable () { this.loading = true - TableService.create(this.$route.params.container_id, this.$route.params.database_id, this.tableCreate) + const table = this.tableCreate.columns.reduce((table, column) => { + // eslint-disable-next-line camelcase + const { name, type, null_allowed, primary_key } = column + table.columns.push({ + name, + type, + null_allowed, + primary_key + }) + if (column.unique) { + table.constraints.uniques.push([column.name]) + } + if (column.check_expression) { + table.checks.push(column.check_expression) + } + if (column.foreign_key && column.references) { + table.foreign_keys.push({ + columns: [column.name], + referenced_table: column.foreign_key, + referenced_columns: [column.references] + }) + } + return table + }, { + name: this.tableCreate.name, + description: this.tableCreate.description, + columns: [], + constraints: { + foreign_keys: [], + uniques: [], + checks: [] + } + }) + TableService.create(this.$route.params.container_id, this.$route.params.database_id, table) .then(async (table) => { this.$toast.success('Table created') await this.$store.dispatch('reloadDatabase') diff --git a/dbrepo-ui/pages/container/index.vue b/dbrepo-ui/pages/container/index.vue index 9e4eb1ffff64834a148762b382d457b47329a09c..974b99609182d4adc824904319cb26b59fdd51b5 100644 --- a/dbrepo-ui/pages/container/index.vue +++ b/dbrepo-ui/pages/container/index.vue @@ -67,7 +67,7 @@ export default { } }, canCreateDatabase () { - if (!this.token) { + if (!this.roles) { return false } return this.roles.includes('create-container') && this.roles.includes('create-database') diff --git a/dbrepo-ui/store/index.js b/dbrepo-ui/store/index.js index 13f9e4e59be7936e970b9f272308195d785c9211..afbf765dd71d4e920978444c6f36e72c227a0cc2 100644 --- a/dbrepo-ui/store/index.js +++ b/dbrepo-ui/store/index.js @@ -28,31 +28,24 @@ const store = new Store({ }, mutations: { SET_TOKEN (state, token) { - console.debug('set state token', token) state.token = token }, SET_REFRESH_TOKEN (state, refreshToken) { - console.debug('set state refreshToken', refreshToken) state.refreshToken = refreshToken }, SET_ROLES (state, roles) { - console.debug('set state roles', roles) state.roles = roles }, SET_USER (state, user) { - console.debug('set state user', user) state.user = user }, SET_DATABASE (state, database) { - console.debug('set state database', database) state.database = database }, SET_TABLE (state, table) { - console.debug('set state table', table) state.table = table }, SET_ACCESS (state, access) { - console.debug('set state access', access) state.access = access } }, diff --git a/dbrepo-ui/test/e2e/forgot.js b/dbrepo-ui/test/e2e/forgot.js index 03c3415564e006031ec606d4be3c2b0948737b01..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-ui/test/e2e/forgot.js +++ b/dbrepo-ui/test/e2e/forgot.js @@ -1,18 +0,0 @@ -const test = require('ava') -const { pageMacro, before, after } = require('./_utils') - -test.before(before) -test.after(after) - -test('login_succeeds', pageMacro, async (t, page) => { - const email = 'ava@example.com' - const username = 'ava' - - await page.go('/forgot') - await page.fill('input[name="username"]', username) - await page.fill('input[name="email"]', email) - - /* test */ - const success = await page.waitForSelector('button[name="submit"]:not([disabled])') - t.true(!!success, 'Failed to reset user information') -}) diff --git a/dbrepo-ui/test/e2e/login.js b/dbrepo-ui/test/e2e/login.js index 1ddae6a394c3d1bccc933b8e8a6e7d1fa0e50552..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-ui/test/e2e/login.js +++ b/dbrepo-ui/test/e2e/login.js @@ -1,18 +0,0 @@ -const test = require('ava') -const { pageMacro, before, after } = require('./_utils') - -test.before(before) -test.after(after) - -test('login_succeeds', pageMacro, async (t, page) => { - const username = 'ava' - const password = Math.random().toString(36).substring(7) - - await page.go('/login') - await page.fill('input[name="username"]', username) - await page.fill('input[name="password"]', password) - - /* test */ - const success = await page.waitForSelector('button[name="submit"]:not([disabled])') - t.true(!!success, 'Failed to login') -}) diff --git a/dbrepo-ui/test/e2e/search.js b/dbrepo-ui/test/e2e/search.js index b2fbc9868e30f8ec0caa4a6d0103c0ca271c3d05..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/dbrepo-ui/test/e2e/search.js +++ b/dbrepo-ui/test/e2e/search.js @@ -1,28 +0,0 @@ -const test = require('ava') -const { pageMacro, before, after } = require('./_utils') - -test.before(before) -test.after(after) - -test('search_succeeds', pageMacro, async (t, page) => { - const query = 'dummy' - - await page.go('/') - await page.fill('input[placeholder="Search ..."]', query) - - /* test */ - const success = await page.waitForSelector('button[name="search-submit"]') - t.true(!!success, 'Failed to search') -}) - -test('search_execute_succeeds', pageMacro, async (t, page) => { - const query = 'dummy' - - await page.go('/') - await page.fill('input[placeholder="Search ..."]', query) - await page.click('button[name="search-submit"]') - - /* test */ - const success = await page.waitForSelector('button[name="search-submit"]') - t.true(!!success, 'Failed to search') -}) diff --git a/dbrepo-ui/utils/index.js b/dbrepo-ui/utils/index.js index 09b2314944314db688b7505166670251a709b461..fbf2e9b6b223f4fa9d7b089f6ca8879312dcfc6a 100644 --- a/dbrepo-ui/utils/index.js +++ b/dbrepo-ui/utils/index.js @@ -1,5 +1,4 @@ const { format } = require('date-fns') -const VueJwtDecode = require('vue-jwt-decode') function notEmpty (str) { return typeof str === 'string' && str.trim().length > 0 @@ -50,16 +49,6 @@ function isDataSteward (user) { return user.roles.filter(a => a === 'ROLE_DATA_STEWARD').length === 1 } -function formatUser (user) { - if (!user) { - return null - } - if (!('given_name' in user) || !('family_name' in user) || user.given_name === null || user.family_name === null) { - return user?.username - } - return user.given_name + ' ' + user.family_name -} - function formatDateUTC (str) { if (str === null) { return null @@ -99,33 +88,6 @@ function formatTimestamp (str) { return format(new Date(str), 'yyyy-MM-dd HH:mm:ss') } -function formatCreators (container) { - if (!container || !('database' in container) || !('identifier' in container.database) || !container.database.identifier || !('creators' in container.database.identifier) || !container.database.identifier.creators) { - return null - } - const creators = container.database.identifier.creators - if (creators.length === 0) { - return formatUser(container.database.creator) - } - let str = '' - for (let i = 0; i < creators.length; i++) { - /* separator */ - if (creators.length > 1 && i === creators.length - 1) { - str += ', & ' - } else if (i > 0 && creators.length !== 2) { - str += ', ' - } - /* name */ - if (creators[i].firstname) { - str += (creators[i].firstname.toUpperCase().substring(0, 1) + '., ') - } - if (creators[i].lastname) { - str += creators[i].lastname - } - } - return str -} - function formatTimestampUTCLabel (str) { if (str === null) { return null @@ -142,29 +104,6 @@ function formatTimestampUTC (str) { return format(new Date(date), 'yyyy-MM-dd HH:mm:ss') } -function jwtToUser (jwt) { - // eslint-disable-next-line camelcase - const { access_token } = jwt - const data = VueJwtDecode.decode(access_token) - return { - id: data.sub, - firstname: data.given_name, - lastname: data.family_name, - username: data.preferred_username, - theme_dark: data?.theme_dark, - orcid: data?.orcid, - titles_before: data?.titles_before, - titles_after: data?.titles_after, - email_verified: data.email_verified - } -} - -function isTokenExpired (accessToken) { - const data = VueJwtDecode.decode(accessToken) - const exp = new Date(data.exp) - return exp <= new Date() -} - module.exports = { notEmpty, formatTimestamp, @@ -172,14 +111,10 @@ module.exports = { formatTimestampUTCLabel, formatDateUTC, isNonNegativeInteger, - formatUser, formatYearUTC, formatMonthUTC, formatDayUTC, - formatCreators, isDeveloper, isResearcher, - isDataSteward, - jwtToUser, - isTokenExpired + isDataSteward } diff --git a/dbrepo-user-service/.mvn/wrapper/MavenWrapperDownloader.java b/dbrepo-user-service/.mvn/wrapper/MavenWrapperDownloader.java deleted file mode 100644 index a45eb6ba269cd38f8965cef786729790945d9537..0000000000000000000000000000000000000000 --- a/dbrepo-user-service/.mvn/wrapper/MavenWrapperDownloader.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2007-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.net.*; -import java.io.*; -import java.nio.channels.*; -import java.util.Properties; - -public class MavenWrapperDownloader { - - private static final String WRAPPER_VERSION = "0.5.6"; - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" - + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; - - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; - - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; - - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if (mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if (mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: " + url); - - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if (!outputFile.getParentFile().exists()) { - if (!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } - - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { - String username = System.getenv("MVNW_USERNAME"); - char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); - Authenticator.setDefault(new Authenticator() { - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(username, password); - } - }); - } - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } - -} diff --git a/dbrepo-user-service/.mvn/wrapper/maven-wrapper.jar b/dbrepo-user-service/.mvn/wrapper/maven-wrapper.jar deleted file mode 100644 index 2cc7d4a55c0cd0092912bf49ae38b3a9e3fd0054..0000000000000000000000000000000000000000 Binary files a/dbrepo-user-service/.mvn/wrapper/maven-wrapper.jar and /dev/null differ diff --git a/dbrepo-user-service/.mvn/wrapper/maven-wrapper.properties b/dbrepo-user-service/.mvn/wrapper/maven-wrapper.properties deleted file mode 100644 index 642d572ce90e5085986bdd9c9204b9404f028084..0000000000000000000000000000000000000000 --- a/dbrepo-user-service/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1,2 +0,0 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/dbrepo-user-service/mvnw b/dbrepo-user-service/mvnw deleted file mode 100755 index a16b5431b4c3cab50323a3f558003fd0abd87dad..0000000000000000000000000000000000000000 --- a/dbrepo-user-service/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/dbrepo-user-service/mvnw.cmd b/dbrepo-user-service/mvnw.cmd deleted file mode 100644 index c8d43372c986d97911cdc21bd87e0cbe3d83bdda..0000000000000000000000000000000000000000 --- a/dbrepo-user-service/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/docker-compose.dbrepo1.yml b/docker-compose.dbrepo1.yml index 01db36561d40b6d328fade93b271caa6666d750d..b85af3cd4fdd74be65d4e20685fcba9d642ef986 100644 --- a/docker-compose.dbrepo1.yml +++ b/docker-compose.dbrepo1.yml @@ -48,7 +48,7 @@ services: logging: driver: json-file - discovery-service: + dbrepo-discovery-service: restart: on-failure container_name: dbrepo-discovery-service hostname: discovery-service @@ -187,6 +187,8 @@ services: core: env_file: - .env + environment: + - SPRING_PROFILES_ACTIVE=doi depends_on: dbrepo-query-service: condition: service_healthy diff --git a/docker-compose.dbrepo2.yml b/docker-compose.dbrepo2.yml index 7c169dd1cecfd8f1c9674ea6fb5c1be5a738c07c..d02ee089f0211b09c11f5d446a60fc4690683489 100644 --- a/docker-compose.dbrepo2.yml +++ b/docker-compose.dbrepo2.yml @@ -187,6 +187,8 @@ services: core: env_file: - .env + environment: + - SPRING_PROFILES_ACTIVE=doi depends_on: dbrepo-query-service: condition: service_healthy @@ -281,6 +283,8 @@ services: depends_on: dbrepo-discovery-service: condition: service_healthy + ports: + - 9200:9200 env_file: - .env volumes: diff --git a/docker-compose.yml b/docker-compose.yml index dd6945c9c3a95257e103046157df2d33e81e310d..470e98fadfb3871f65792086bc77cdc2b238b8bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -166,6 +166,8 @@ services: volumes: - "/tmp:/tmp" depends_on: + dbrepo-broker-service: + condition: service_healthy dbrepo-table-service: condition: service_healthy dbrepo-authentication-service: