-
Notifications
You must be signed in to change notification settings - Fork 6
Feature/464 add soft delete feature #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
179fe32
[#464] added soft delete feature and refactored local startup
david-monichi fc68569
[#464] Added docker-compose for local keycloak
david-monichi 2c8d481
feat: [#464] added soft-delete to database (flyway file version colli…
david-monichi 0a0eed3
[#464] reduced code duplication for PR
david-monichi aa05191
[#464] added license to missing files + increasing test coverage
david-monichi 7f8098c
[#464] fixed grammatical error
david-monichi 18f3ba7
[#464] Increased code coverage
david-monichi 8d34291
[#464] Added additional unit test for code coverage
david-monichi c3a69e7
[#464] Added additional unit test for code coverage
david-monichi 9e6374d
[#464] Increased unit tests quality
david-monichi e806589
[#464] Increased developer getting started documentation
david-monichi f8c6b88
[#464] changed to lower case in sql queries
david-monichi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # SPDX-FileCopyrightText: 2025 BearingPoint GmbH | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Enable full logging for local development | ||
| # quarkus.log.level = ALL | ||
| # quarkus.log.category."org.lfenergy.compas.scl.data".level = ALL | ||
|
|
||
| quarkus.flyway.migrate-at-start = true | ||
| quarkus.flyway.locations = classpath:org/lfenergy/compas/scl/data/repository/postgresql/db/migration | ||
|
|
||
| mp.jwt.verify.issuer = ${JWT_VERIFY_ISSUER:http://127.0.0.1:8089/auth/realms/compas} | ||
|
|
||
| compas.scl-data-service.features.soft-delete-enabled = true | ||
|
|
||
| # Run with local PostgreSQL database provided by "app/src/test/resources/docker-compose.yml" | ||
| # For more details have a look at the [development documentation](doc/development.md). | ||
|
|
||
| #quarkus.datasource.devservices.enabled = false | ||
| #quarkus.datasource.db-kind = postgresql | ||
| #quarkus.datasource.jdbc.url = jdbc:postgresql://${POSTGRESQL_HOST:localhost}:${POSTGRESQL_PORT:5432}/${POSTGRESQL_DB:compas} | ||
| #quarkus.datasource.jdbc.max-size = 16 | ||
| #quarkus.datasource.username = ${POSTGRESQL_USERNAME:postgres} | ||
| #quarkus.datasource.password = ${POSTGRESQL_PASSWORD:postgres} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # SPDX-FileCopyrightText: 2025 BearingPoint GmbH | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| version: '3.8' | ||
|
|
||
| services: | ||
| keycloak: | ||
| image: ghcr.io/ase-compas/compas/compas-keycloak:main | ||
| container_name: keycloak | ||
| labels: | ||
| compas: true | ||
| ports: | ||
| - "8089:8080" | ||
| environment: | ||
| - KC_HOSTNAME=http://127.0.0.1:8089/auth/ | ||
| - KC_HTTP_RELATIVE_PATH=auth | ||
| - KC_HTTP_ENABLED=true | ||
| - KC_PROXY_HEADERS=xforwarded | ||
| - KC_BOOTSTRAP_ADMIN_USERNAME=admin | ||
| - KC_BOOTSTRAP_ADMIN_PASSWORD=admin | ||
|
|
||
| postgresql: | ||
| image: postgres:latest | ||
| container_name: compas_postgresql | ||
| environment: | ||
| POSTGRES_USER: postgres | ||
| POSTGRES_PASSWORD: postgres | ||
| POSTGRES_DB: compas | ||
| ports: | ||
| - "5432:5432" | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U postgres"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
| restart: unless-stopped |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <!-- | ||
| SPDX-FileCopyrightText: 2025 BearingPoint GmbH | ||
|
|
||
| SPDX-License-Identifier: Apache-2.0 | ||
| --> | ||
|
|
||
| # Development | ||
|
|
||
| Run application with local postgresql database in development mode: | ||
| ```bash | ||
| cd src/test/resources/docker-compose.yml | ||
| docker-compose up keycloak | ||
|
|
||
| mvn -DskipTests=true -Dquarkus.profile=local package io.quarkus:quarkus-maven-plugin::dev | ||
| ``` | ||
|
|
||
| In case of issues enable full debug logging by uncommenting the enable `ALL` logs in the `src/main/resources/application.properties` file: | ||
| ```properties | ||
| quarkus.log.level = ALL | ||
| quarkus.log.category."org.lfenergy.compas.scl.data".level = ALL | ||
| ``` | ||
|
|
||
| ## Verify setup | ||
|
|
||
| To verify that the setup is correct, you can use the following curl command to list all ICDs in the database: | ||
| ``` | ||
| curl -X GET "http://localhost:8080/scl-data-service/icd/list" -H "Authorization: Bearer <ACCESS_TOKEN>" -H "accept: application | ||
| ``` | ||
|
|
||
| The `<ACCESS_TOKEN>` should be replaced with a valid JWT token obtained from Keycloak with following command: | ||
| ```bash | ||
| curl -X POST "http://localhost:8089/auth/realms/compas/protocol/openid-connect/token" \ | ||
| -H "Content-Type: application/x-www-form-urlencoded" \ | ||
| -d "client_id=scl-data-service&username=scl-data-editor&password=editor&grant_type=password" | ||
| ``` | ||
|
|
||
| ## Connecting to local database | ||
|
|
||
| To connect to the local PostgreSQL database, you first need to start the PostgreSQL service using Docker Compose: | ||
| ``` | ||
| cd app/src/test/resources/docker-compose.yml | ||
| docker-compose up postgresql | ||
| ``` | ||
|
|
||
| then enable the postgresql configuration by uncomment following lines in file `src/main/resources/application-local.properties`: | ||
| ```properties | ||
| quarkus.datasource.devservices.enabled = false | ||
| quarkus.datasource.db-kind = postgresql | ||
| quarkus.datasource.jdbc.url = jdbc:postgresql://${POSTGRESQL_HOST:localhost}:${POSTGRESQL_PORT:5432}/${POSTGRESQL_DB:compas} | ||
| quarkus.datasource.jdbc.max-size = 16 | ||
| quarkus.datasource.username = ${POSTGRESQL_USERNAME:postgres} | ||
| quarkus.datasource.password = ${POSTGRESQL_PASSWORD:postgres} | ||
| ``` | ||
|
|
||
| Start the application in development mode with the local profile: | ||
| ```bash | ||
| mvn -DskipTests=true -Dquarkus.profile=local package io.quarkus:quarkus-maven-plugin::dev | ||
| ``` | ||
|
|
||
| You can then verify the setup described above by using the same curl commands as mentioned earlier. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...compas/scl/data/repository/postgresql/CompasSclDataPostgreSQLRepositoryConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // SPDX-FileCopyrightText: 2025 BearingPoint GmbH | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package org.lfenergy.compas.scl.data.repository.postgresql; | ||
|
|
||
| import jakarta.enterprise.context.ApplicationScoped; | ||
| import jakarta.enterprise.inject.Produces; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
| import org.lfenergy.compas.scl.data.repository.CompasSclDataRepository; | ||
|
|
||
| import javax.sql.DataSource; | ||
|
|
||
| public class CompasSclDataPostgreSQLRepositoryConfiguration { | ||
|
|
||
| private static final Logger LOGGER = LogManager.getLogger(CompasSclDataPostgreSQLRepositoryConfiguration.class); | ||
|
|
||
| @ConfigProperty(name = "compas.scl-data-service.features.soft-delete-enabled", defaultValue = "false") | ||
| private boolean softDeleteEnabled; | ||
|
|
||
| @Produces | ||
| @ApplicationScoped | ||
| CompasSclDataRepository softDeleteCompasSclDataPostgreSQLRepository(DataSource dataSource) { | ||
| if (!softDeleteEnabled) { | ||
| LOGGER.warn("Soft delete feature is disabled, using default repository."); | ||
| return new CompasSclDataPostgreSQLRepository(dataSource); | ||
| } | ||
| LOGGER.info("Soft delete feature is enabled. Using SoftDeleteCompasSclDataPostgreSQLRepository."); | ||
| return new SoftDeleteCompasSclDataPostgreSQLRepository(dataSource); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
...gy/compas/scl/data/repository/postgresql/SoftDeleteCompasSclDataPostgreSQLRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // SPDX-FileCopyrightText: 2025 BearingPoint GmbH | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package org.lfenergy.compas.scl.data.repository.postgresql; | ||
|
|
||
| import javax.sql.DataSource; | ||
|
|
||
| public class SoftDeleteCompasSclDataPostgreSQLRepository extends CompasSclDataPostgreSQLRepository { | ||
|
|
||
| private static final String SOFT_DELETE_SCL_FILE_SQL = """ | ||
| UPDATE scl_file | ||
| SET is_deleted = true | ||
| where scl_file.id = ? | ||
| and scl_file.type = ? | ||
| """; | ||
|
|
||
| private static final String SOFT_DELETE_SCL_FILE_SQL_BY_VERSION = """ | ||
| delete from scl_file | ||
| where scl_file.id = ? | ||
| and scl_file.type = ? | ||
| and scl_file.major_version = ? | ||
| and scl_file.minor_version = ? | ||
| and scl_file.patch_version = ? | ||
| """; | ||
|
|
||
| public SoftDeleteCompasSclDataPostgreSQLRepository(DataSource dataSource) { | ||
| super(dataSource); | ||
| DELETE_SCL_FILE_SQL = SOFT_DELETE_SCL_FILE_SQL; | ||
| DELETE_SCL_FILE_SQL_BY_VERSION = SOFT_DELETE_SCL_FILE_SQL_BY_VERSION; | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
...fenergy/compas/scl/data/repository/postgresql/db/migration/V1_6__add_soft_delete_flag.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2025 BearingPoint GmbH | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| -- | ||
| -- Update SCL File Table to add soft deletion | ||
| -- | ||
|
|
||
| ALTER TABLE scl_file | ||
| ADD COLUMN is_deleted BOOLEAN DEFAULT false; | ||
|
|
||
| comment on column scl_file.is_deleted is 'Flag indicating whether the SCL file is soft deleted.'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.