Skip to content

Commit 00f0461

Browse files
committed
Merge branch 'main' into docs/add-required-docs
2 parents 2bc01ab + 3b8b496 commit 00f0461

File tree

15 files changed

+359
-22
lines changed

15 files changed

+359
-22
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ There is currently one database implementations available.
2626
> **Note:** When switching between implementation it's a good practise to first execute a maven clean to remove
2727
> old dependencies from the target directory in the app module.
2828
29+
## Development
30+
31+
See [development](doc/development.md) documentation.
32+
2933
## Common Environment variables
3034

3135
Below environment variable(s) can be used to configure which claims and information are used to fill the UserInfo

app/src/main/resources/application-dev-postgresql.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ quarkus.datasource.devservices.enabled = false
1919
quarkus.datasource.db-kind = postgresql
2020
quarkus.datasource.jdbc.url = jdbc:postgresql://${POSTGRESQL_HOST:localhost}:${POSTGRESQL_PORT:5432}/${POSTGRESQL_DB:compas}
2121
quarkus.datasource.jdbc.max-size = 16
22-
quarkus.datasource.username = ${POSTGRESQL_USERNAME:postgres}
23-
quarkus.datasource.password = ${POSTGRESQL_PASSWORD:postgres}
22+
quarkus.datasource.username = ${POSTGRESQL_USERNAME:compas}
23+
quarkus.datasource.password = ${POSTGRESQL_PASSWORD:compas}
2424

2525
# Flyway configuration for PostgreSQL
2626
quarkus.flyway.migrate-at-start = true
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-FileCopyrightText: 2025 BearingPoint GmbH
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# Enable full logging for local development
6+
# quarkus.log.level = ALL
7+
# quarkus.log.category."org.lfenergy.compas.scl.data".level = ALL
8+
9+
quarkus.flyway.migrate-at-start = true
10+
quarkus.flyway.locations = classpath:org/lfenergy/compas/scl/data/repository/postgresql/db/migration
11+
12+
mp.jwt.verify.issuer = ${JWT_VERIFY_ISSUER:http://127.0.0.1:8089/auth/realms/compas}
13+
14+
compas.scl-data-service.features.soft-delete-enabled = true
15+
16+
# Run with local PostgreSQL database provided by "app/src/test/resources/docker-compose.yml"
17+
# For more details have a look at the [development documentation](doc/development.md).
18+
19+
#quarkus.datasource.devservices.enabled = false
20+
#quarkus.datasource.db-kind = postgresql
21+
#quarkus.datasource.jdbc.url = jdbc:postgresql://${POSTGRESQL_HOST:localhost}:${POSTGRESQL_PORT:5432}/${POSTGRESQL_DB:compas}
22+
#quarkus.datasource.jdbc.max-size = 16
23+
#quarkus.datasource.username = ${POSTGRESQL_USERNAME:postgres}
24+
#quarkus.datasource.password = ${POSTGRESQL_PASSWORD:postgres}

app/src/main/resources/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ quarkus.websocket.max-frame-size = 157286400
1515
quarkus.log.level = INFO
1616
quarkus.log.category."org.lfenergy.compas.scl.data".level = INFO
1717

18+
compas.scl-data-service.features.soft-delete-enabled = ${SCL_DATA_SERVICE_SOFT_DELETE_ENABLED:false}
19+
1820
# Add scanning these dependencies for scanning, also used by native compilation.
1921
quarkus.index-dependency.websocket-commons.group-id = org.lfenergy.compas.core
2022
quarkus.index-dependency.websocket-commons.artifact-id = websocket-commons
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-FileCopyrightText: 2025 BearingPoint GmbH
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
version: '3.8'
6+
7+
services:
8+
keycloak:
9+
image: ghcr.io/ase-compas/compas/compas-keycloak:main
10+
container_name: keycloak
11+
labels:
12+
compas: true
13+
ports:
14+
- "8089:8080"
15+
environment:
16+
- KC_HOSTNAME=http://127.0.0.1:8089/auth/
17+
- KC_HTTP_RELATIVE_PATH=auth
18+
- KC_HTTP_ENABLED=true
19+
- KC_PROXY_HEADERS=xforwarded
20+
- KC_BOOTSTRAP_ADMIN_USERNAME=admin
21+
- KC_BOOTSTRAP_ADMIN_PASSWORD=admin
22+
23+
postgresql:
24+
image: postgres:latest
25+
container_name: compas_postgresql
26+
environment:
27+
POSTGRES_USER: postgres
28+
POSTGRES_PASSWORD: postgres
29+
POSTGRES_DB: compas
30+
ports:
31+
- "5432:5432"
32+
healthcheck:
33+
test: ["CMD-SHELL", "pg_isready -U postgres"]
34+
interval: 10s
35+
timeout: 5s
36+
retries: 5
37+
restart: unless-stopped

doc/development.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2025 BearingPoint GmbH
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
-->
6+
7+
# Development
8+
9+
Run application with local postgresql database in development mode:
10+
```bash
11+
cd src/test/resources/docker-compose.yml
12+
docker-compose up keycloak
13+
14+
mvn -DskipTests=true -Dquarkus.profile=local package io.quarkus:quarkus-maven-plugin::dev
15+
```
16+
17+
In case of issues enable full debug logging by uncommenting the enable `ALL` logs in the `src/main/resources/application.properties` file:
18+
```properties
19+
quarkus.log.level = ALL
20+
quarkus.log.category."org.lfenergy.compas.scl.data".level = ALL
21+
```
22+
23+
## Verify setup
24+
25+
To verify that the setup is correct, you can use the following curl command to list all ICDs in the database:
26+
```
27+
curl -X GET "http://localhost:8080/scl-data-service/icd/list" -H "Authorization: Bearer <ACCESS_TOKEN>" -H "accept: application
28+
```
29+
30+
The `<ACCESS_TOKEN>` should be replaced with a valid JWT token obtained from Keycloak with following command:
31+
```bash
32+
curl -X POST "http://localhost:8089/auth/realms/compas/protocol/openid-connect/token" \
33+
-H "Content-Type: application/x-www-form-urlencoded" \
34+
-d "client_id=scl-data-service&username=scl-data-editor&password=editor&grant_type=password"
35+
```
36+
37+
## Connecting to local database
38+
39+
To connect to the local PostgreSQL database, you first need to start the PostgreSQL service using Docker Compose:
40+
```
41+
cd app/src/test/resources/docker-compose.yml
42+
docker-compose up postgresql
43+
```
44+
45+
then enable the postgresql configuration by uncomment following lines in file `src/main/resources/application-local.properties`:
46+
```properties
47+
quarkus.datasource.devservices.enabled = false
48+
quarkus.datasource.db-kind = postgresql
49+
quarkus.datasource.jdbc.url = jdbc:postgresql://${POSTGRESQL_HOST:localhost}:${POSTGRESQL_PORT:5432}/${POSTGRESQL_DB:compas}
50+
quarkus.datasource.jdbc.max-size = 16
51+
quarkus.datasource.username = ${POSTGRESQL_USERNAME:postgres}
52+
quarkus.datasource.password = ${POSTGRESQL_PASSWORD:postgres}
53+
```
54+
55+
Start the application in development mode with the local profile:
56+
```bash
57+
mvn -DskipTests=true -Dquarkus.profile=local package io.quarkus:quarkus-maven-plugin::dev
58+
```
59+
60+
You can then verify the setup described above by using the same curl commands as mentioned earlier.

doc/postgresql.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Table: scl_file
3737
| type | varchar(3) | True | The type of SCL stored |
3838
| name | varchar(255) | True | The name of the SCL File |
3939
| scl_data | text | True | The SCL XML Content |
40+
| is_deleted | boolean | False | Flag indicating whether the record is marked as deleted |
4041

4142
## Development
4243

repository-postgresql/src/main/java/org/lfenergy/compas/scl/data/repository/postgresql/CompasSclDataPostgreSQLRepository.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import org.lfenergy.compas.scl.data.repository.CompasSclDataRepository;
1111
import org.lfenergy.compas.scl.extensions.model.SclFileType;
1212

13-
import jakarta.enterprise.context.ApplicationScoped;
14-
import jakarta.inject.Inject;
1513
import javax.sql.DataSource;
1614
import jakarta.transaction.Transactional;
1715
import java.sql.Array;
@@ -27,7 +25,6 @@
2725
import static jakarta.transaction.Transactional.TxType.SUPPORTS;
2826
import static org.lfenergy.compas.scl.data.exception.CompasSclDataServiceErrorCode.*;
2927

30-
@ApplicationScoped
3128
public class CompasSclDataPostgreSQLRepository implements CompasSclDataRepository {
3229
private static final String ID_FIELD = "id";
3330
private static final String MAJOR_VERSION_FIELD = "major_version";
@@ -39,9 +36,23 @@ public class CompasSclDataPostgreSQLRepository implements CompasSclDataRepositor
3936
private static final String HITEM_WHEN_FIELD = "hitem_when";
4037
private static final String HITEM_WHAT_FIELD = "hitem_what";
4138

42-
private final DataSource dataSource;
39+
protected final DataSource dataSource;
40+
41+
protected static String DELETE_SCL_FILE_SQL = """
42+
delete from scl_file
43+
where scl_file.id = ?
44+
and scl_file.type = ?
45+
""";
46+
47+
protected static String DELETE_SCL_FILE_SQL_BY_VERSION = """
48+
delete from scl_file
49+
where scl_file.id = ?
50+
and scl_file.type = ?
51+
and scl_file.major_version = ?
52+
and scl_file.minor_version = ?
53+
and scl_file.patch_version = ?
54+
""";
4355

44-
@Inject
4556
public CompasSclDataPostgreSQLRepository(DataSource dataSource) {
4657
this.dataSource = dataSource;
4758
}
@@ -56,6 +67,7 @@ public List<IItem> list(SclFileType type) {
5667
from (select distinct on (scl_file.id) *
5768
from scl_file
5869
where scl_file.type = ?
70+
and scl_file.is_deleted = false
5971
order by scl_file.id
6072
, scl_file.major_version desc
6173
, scl_file.minor_version desc
@@ -115,6 +127,7 @@ left outer join (
115127
and scl_data.patch_version = scl_file.patch_version
116128
where scl_file.id = ?
117129
and scl_file.type = ?
130+
and scl_file.is_deleted = false
118131
order by scl_file.major_version
119132
, scl_file.minor_version
120133
, scl_file.patch_version
@@ -162,6 +175,7 @@ public String findByUUID(SclFileType type, UUID id, Version version) {
162175
and scl_file.major_version = ?
163176
and scl_file.minor_version = ?
164177
and scl_file.patch_version = ?
178+
and scl_file.is_deleted = false
165179
""";
166180

167181
try (var connection = dataSource.getConnection();
@@ -191,6 +205,7 @@ public boolean hasDuplicateSclName(SclFileType type, String name) {
191205
select distinct on (scl_file.id) scl_file.name
192206
from scl_file
193207
where scl_file.type = ?
208+
and scl_file.is_deleted = false
194209
order by scl_file.id
195210
, scl_file.major_version desc
196211
, scl_file.minor_version desc
@@ -221,6 +236,7 @@ public IAbstractItem findMetaInfoByUUID(SclFileType type, UUID id) {
221236
from scl_file
222237
where scl_file.id = ?
223238
and scl_file.type = ?
239+
and scl_file.is_deleted = false
224240
order by scl_file.major_version desc, scl_file.minor_version desc, scl_file.patch_version desc
225241
""";
226242

@@ -304,14 +320,9 @@ insert into scl_label(scl_id, major_version, minor_version, patch_version, label
304320
@Override
305321
@Transactional(REQUIRED)
306322
public void delete(SclFileType type, UUID id) {
307-
var sql = """
308-
delete from scl_file
309-
where scl_file.id = ?
310-
and scl_file.type = ?
311-
""";
312323

313324
try (var connection = dataSource.getConnection();
314-
var stmt = connection.prepareStatement(sql)) {
325+
var stmt = connection.prepareStatement(DELETE_SCL_FILE_SQL)) {
315326
stmt.setObject(1, id);
316327
stmt.setString(2, type.name());
317328
stmt.executeUpdate();
@@ -323,17 +334,9 @@ public void delete(SclFileType type, UUID id) {
323334
@Override
324335
@Transactional(REQUIRED)
325336
public void delete(SclFileType type, UUID id, Version version) {
326-
var sql = """
327-
delete from scl_file
328-
where scl_file.id = ?
329-
and scl_file.type = ?
330-
and scl_file.major_version = ?
331-
and scl_file.minor_version = ?
332-
and scl_file.patch_version = ?
333-
""";
334337

335338
try (var connection = dataSource.getConnection();
336-
var stmt = connection.prepareStatement(sql)) {
339+
var stmt = connection.prepareStatement(DELETE_SCL_FILE_SQL_BY_VERSION)) {
337340
stmt.setObject(1, id);
338341
stmt.setString(2, type.name());
339342
stmt.setInt(3, version.getMajorVersion());
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-FileCopyrightText: 2025 BearingPoint GmbH
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.scl.data.repository.postgresql;
6+
7+
import jakarta.enterprise.context.ApplicationScoped;
8+
import jakarta.enterprise.inject.Produces;
9+
import org.apache.logging.log4j.LogManager;
10+
import org.apache.logging.log4j.Logger;
11+
import org.eclipse.microprofile.config.inject.ConfigProperty;
12+
import org.lfenergy.compas.scl.data.repository.CompasSclDataRepository;
13+
14+
import javax.sql.DataSource;
15+
16+
public class CompasSclDataPostgreSQLRepositoryConfiguration {
17+
18+
private static final Logger LOGGER = LogManager.getLogger(CompasSclDataPostgreSQLRepositoryConfiguration.class);
19+
20+
@ConfigProperty(name = "compas.scl-data-service.features.soft-delete-enabled", defaultValue = "false")
21+
private boolean softDeleteEnabled;
22+
23+
@Produces
24+
@ApplicationScoped
25+
CompasSclDataRepository softDeleteCompasSclDataPostgreSQLRepository(DataSource dataSource) {
26+
if (!softDeleteEnabled) {
27+
LOGGER.warn("Soft delete feature is disabled, using default repository.");
28+
return new CompasSclDataPostgreSQLRepository(dataSource);
29+
}
30+
LOGGER.info("Soft delete feature is enabled. Using SoftDeleteCompasSclDataPostgreSQLRepository.");
31+
return new SoftDeleteCompasSclDataPostgreSQLRepository(dataSource);
32+
}
33+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-FileCopyrightText: 2025 BearingPoint GmbH
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.scl.data.repository.postgresql;
6+
7+
import javax.sql.DataSource;
8+
9+
public class SoftDeleteCompasSclDataPostgreSQLRepository extends CompasSclDataPostgreSQLRepository {
10+
11+
private static final String SOFT_DELETE_SCL_FILE_SQL = """
12+
update scl_file
13+
set is_deleted = true
14+
where scl_file.id = ?
15+
and scl_file.type = ?
16+
""";
17+
18+
private static final String SOFT_DELETE_SCL_FILE_SQL_BY_VERSION = """
19+
delete from scl_file
20+
where scl_file.id = ?
21+
and scl_file.type = ?
22+
and scl_file.major_version = ?
23+
and scl_file.minor_version = ?
24+
and scl_file.patch_version = ?
25+
""";
26+
27+
public SoftDeleteCompasSclDataPostgreSQLRepository(DataSource dataSource) {
28+
super(dataSource);
29+
DELETE_SCL_FILE_SQL = SOFT_DELETE_SCL_FILE_SQL;
30+
DELETE_SCL_FILE_SQL_BY_VERSION = SOFT_DELETE_SCL_FILE_SQL_BY_VERSION;
31+
}
32+
}

0 commit comments

Comments
 (0)