Skip to content

Commit 93bfb7d

Browse files
committed
[#464] added soft delete feature and refactored local startup
1 parent 2869a3b commit 93bfb7d

File tree

8 files changed

+142
-8
lines changed

8 files changed

+142
-8
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ 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+
Run application with local postgresql database in development mode:
32+
```bash
33+
docker run --rm -d --name compas-db -p 5432:5432 -e POSTGRES_USER=compas \
34+
-e POSTGRES_PASSWORD=compas -e POSTGRES_DB=compas postgres:14 -d
35+
36+
mvn -DskipTests=true -Dquarkus.profile=dev-postgresql,local package io.quarkus:quarkus-maven-plugin::dev
37+
```
38+
2939
## Common Environment variables
3040

3141
Below environment variable(s) can be used to configure which claims and information are used to fill the UserInfo
@@ -86,4 +96,3 @@ configured as needed.
8696
- STD_DELETE
8797
- STD_READ
8898
- STD_UPDATE
89-

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-FileCopyrightText: 2025 BearingPoint GmbH
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
quarkus.http.auth.permission.deny-default.paths=/*
6+
quarkus.http.auth.permission.deny-default.policy=permit

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

Lines changed: 6 additions & 5 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,8 @@ 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;
4340

44-
@Inject
4541
public CompasSclDataPostgreSQLRepository(DataSource dataSource) {
4642
this.dataSource = dataSource;
4743
}
@@ -56,6 +52,7 @@ public List<IItem> list(SclFileType type) {
5652
from (select distinct on (scl_file.id) *
5753
from scl_file
5854
where scl_file.type = ?
55+
AND scl_file.is_deleted = false
5956
order by scl_file.id
6057
, scl_file.major_version desc
6158
, scl_file.minor_version desc
@@ -115,6 +112,7 @@ left outer join (
115112
and scl_data.patch_version = scl_file.patch_version
116113
where scl_file.id = ?
117114
and scl_file.type = ?
115+
and scl_file.is_deleted = false
118116
order by scl_file.major_version
119117
, scl_file.minor_version
120118
, scl_file.patch_version
@@ -162,6 +160,7 @@ public String findByUUID(SclFileType type, UUID id, Version version) {
162160
and scl_file.major_version = ?
163161
and scl_file.minor_version = ?
164162
and scl_file.patch_version = ?
163+
and scl_file.is_deleted = false
165164
""";
166165

167166
try (var connection = dataSource.getConnection();
@@ -191,6 +190,7 @@ public boolean hasDuplicateSclName(SclFileType type, String name) {
191190
select distinct on (scl_file.id) scl_file.name
192191
from scl_file
193192
where scl_file.type = ?
193+
and scl_file.is_deleted = false
194194
order by scl_file.id
195195
, scl_file.major_version desc
196196
, scl_file.minor_version desc
@@ -221,6 +221,7 @@ public IAbstractItem findMetaInfoByUUID(SclFileType type, UUID id) {
221221
from scl_file
222222
where scl_file.id = ?
223223
and scl_file.type = ?
224+
and scl_file.is_deleted = false
224225
order by scl_file.major_version desc, scl_file.minor_version desc, scl_file.patch_version desc
225226
""";
226227

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 io.quarkus.arc.DefaultBean;
8+
import io.quarkus.arc.lookup.LookupIfProperty;
9+
import jakarta.enterprise.context.ApplicationScoped;
10+
import jakarta.enterprise.inject.Produces;
11+
import org.lfenergy.compas.scl.data.repository.CompasSclDataRepository;
12+
13+
import javax.sql.DataSource;
14+
15+
public class CompasSclDataPostgreSQLRepositoryConfiguration {
16+
17+
@Produces
18+
@ApplicationScoped
19+
@LookupIfProperty(name = "compas.scl-data-service.features.soft-delete-enabled", stringValue = "true")
20+
CompasSclDataRepository softDeleteCompasSclDataPostgreSQLRepository(DataSource dataSource) {
21+
return new SoftDeleteCompasSclDataPostgreSQLRepository(dataSource);
22+
}
23+
24+
@Produces
25+
@ApplicationScoped
26+
@DefaultBean
27+
CompasSclDataRepository defaultCompasSclDataPostgreSQLRepository(DataSource dataSource) {
28+
return new CompasSclDataPostgreSQLRepository(dataSource);
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.transaction.Transactional;
8+
import org.lfenergy.compas.scl.data.exception.CompasSclDataServiceException;
9+
import org.lfenergy.compas.scl.data.model.*;
10+
import org.lfenergy.compas.scl.extensions.model.SclFileType;
11+
12+
import javax.sql.DataSource;
13+
import java.sql.SQLException;
14+
import java.util.UUID;
15+
16+
import static jakarta.transaction.Transactional.TxType.REQUIRED;
17+
import static org.lfenergy.compas.scl.data.exception.CompasSclDataServiceErrorCode.*;
18+
19+
public class SoftDeleteCompasSclDataPostgreSQLRepository extends CompasSclDataPostgreSQLRepository {
20+
21+
public SoftDeleteCompasSclDataPostgreSQLRepository(DataSource dataSource) {
22+
super(dataSource);
23+
}
24+
25+
@Override
26+
@Transactional(REQUIRED)
27+
public void delete(SclFileType type, UUID id) {
28+
var sql = """
29+
UPDATE scl_file
30+
SET scl_file.is_deleted = true
31+
where scl_file.id = ?
32+
and scl_file.type = ?
33+
""";
34+
35+
try (var connection = dataSource.getConnection();
36+
var stmt = connection.prepareStatement(sql)) {
37+
stmt.setObject(1, id);
38+
stmt.setString(2, type.name());
39+
stmt.executeUpdate();
40+
} catch (SQLException exp) {
41+
throw new CompasSclDataServiceException(POSTGRES_DELETE_ERROR_CODE, "Error removing SCL from database!", exp);
42+
}
43+
}
44+
45+
@Override
46+
@Transactional(REQUIRED)
47+
public void delete(SclFileType type, UUID id, Version version) {
48+
var sql = """
49+
UPDATE scl_file
50+
SET scl_file.is_deleted = true
51+
where scl_file.id = ?
52+
and scl_file.type = ?
53+
and scl_file.major_version = ?
54+
and scl_file.minor_version = ?
55+
and scl_file.patch_version = ?
56+
""";
57+
58+
try (var connection = dataSource.getConnection();
59+
var stmt = connection.prepareStatement(sql)) {
60+
stmt.setObject(1, id);
61+
stmt.setString(2, type.name());
62+
stmt.setInt(3, version.getMajorVersion());
63+
stmt.setInt(4, version.getMinorVersion());
64+
stmt.setInt(5, version.getPatchVersion());
65+
stmt.executeUpdate();
66+
} catch (SQLException exp) {
67+
throw new CompasSclDataServiceException(POSTGRES_DELETE_ERROR_CODE, "Error removing SCL (version) from database!", exp);
68+
}
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2025 BearingPoint GmbH
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
--
8+
-- Update SCL File Table to add soft deletion
9+
--
10+
11+
ALTER TABLE scl_file
12+
ADD COLUMN is_deleted BOOLEAN DEFAULT false;
13+
14+
comment on column scl_file.is_deleted is 'Flag is the SCL File is deleted.';

repository/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ SPDX-License-Identifier: Apache-2.0
2424
<groupId>org.lfenergy.compas.core</groupId>
2525
<artifactId>scl-extension</artifactId>
2626
</dependency>
27+
<dependency>
28+
<groupId>io.quarkus</groupId>
29+
<artifactId>quarkus-arc</artifactId>
30+
</dependency>
2731

2832
<dependency>
2933
<groupId>jakarta.xml.bind</groupId>

0 commit comments

Comments
 (0)