Skip to content

Commit 0a3a6f2

Browse files
author
Dennis Labordus
authored
Merge pull request #233 from com-pas/develop
New release
2 parents 1f6979a + 1d5f867 commit 0a3a6f2

File tree

19 files changed

+256
-66
lines changed

19 files changed

+256
-66
lines changed

app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/VersionsResponse.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package org.lfenergy.compas.scl.data.rest.v1.model;
55

66
import org.eclipse.microprofile.openapi.annotations.media.Schema;
7-
import org.lfenergy.compas.scl.data.model.Item;
7+
import org.lfenergy.compas.scl.data.model.HistoryItem;
88

99
import javax.xml.bind.annotation.XmlAccessType;
1010
import javax.xml.bind.annotation.XmlAccessorType;
@@ -19,14 +19,14 @@
1919
@XmlAccessorType(XmlAccessType.FIELD)
2020
public class VersionsResponse {
2121
@Schema(description = "List of found Versions of a specific SCL in the database.")
22-
@XmlElement(name = "Item", namespace = SCL_DATA_SERVICE_V1_NS_URI)
23-
private List<Item> items;
22+
@XmlElement(name = "HistoryItem", namespace = SCL_DATA_SERVICE_V1_NS_URI)
23+
private List<HistoryItem> items;
2424

25-
public List<Item> getItems() {
25+
public List<HistoryItem> getItems() {
2626
return items;
2727
}
2828

29-
public void setItems(List<Item> items) {
29+
public void setItems(List<HistoryItem> items) {
3030
this.items = items;
3131
}
3232
}

app/src/test/java/org/lfenergy/compas/scl/data/rest/mock/CompasSclDataRepositoryMock.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package org.lfenergy.compas.scl.data.rest.mock;
55

66
import io.quarkus.test.Mock;
7+
import org.lfenergy.compas.scl.data.model.HistoryItem;
78
import org.lfenergy.compas.scl.data.model.Item;
89
import org.lfenergy.compas.scl.data.model.SclMetaInfo;
910
import org.lfenergy.compas.scl.data.model.Version;
@@ -23,7 +24,7 @@ public List<Item> list(SclFileType type) {
2324
}
2425

2526
@Override
26-
public List<Item> listVersionsByUUID(SclFileType type, UUID id) {
27+
public List<HistoryItem> listVersionsByUUID(SclFileType type, UUID id) {
2728
throw new IllegalStateException("Mock method using Mockito. Only needed to startup.");
2829
}
2930

app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsEditorTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.restassured.http.ContentType;
1313
import org.junit.jupiter.api.Test;
1414
import org.lfenergy.compas.scl.data.model.ChangeSetType;
15+
import org.lfenergy.compas.scl.data.model.HistoryItem;
1516
import org.lfenergy.compas.scl.data.model.Item;
1617
import org.lfenergy.compas.scl.data.model.Version;
1718
import org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest;
@@ -76,7 +77,7 @@ void listVersionsByUUID_WhenCalled_ThenItemResponseRetrieved() {
7677
var version = "1.0.0";
7778

7879
when(compasSclDataService.listVersionsByUUID(type, uuid))
79-
.thenReturn(Collections.singletonList(new Item(uuid.toString(), name, version)));
80+
.thenReturn(Collections.singletonList(new HistoryItem(uuid.toString(), name, version, null, null, null)));
8081

8182
var response = given()
8283
.pathParam(TYPE_PATH_PARAM, type)
@@ -88,9 +89,9 @@ void listVersionsByUUID_WhenCalled_ThenItemResponseRetrieved() {
8889
.response();
8990

9091
var xmlPath = response.xmlPath();
91-
assertEquals(uuid.toString(), xmlPath.get("ListResponse.Item[0].Id"));
92-
assertEquals(name, xmlPath.get("ListResponse.Item[0].Name"));
93-
assertEquals(version, xmlPath.get("ListResponse.Item[0].Version"));
92+
assertEquals(uuid.toString(), xmlPath.get("VersionsResponse.HistoryItem[0].Id"));
93+
assertEquals(name, xmlPath.get("VersionsResponse.HistoryItem[0].Name"));
94+
assertEquals(version, xmlPath.get("VersionsResponse.HistoryItem[0].Version"));
9495
verify(compasSclDataService, times(1)).listVersionsByUUID(type, uuid);
9596
}
9697

app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsReaderTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.restassured.http.ContentType;
1111
import org.junit.jupiter.api.Test;
1212
import org.lfenergy.compas.scl.data.model.ChangeSetType;
13+
import org.lfenergy.compas.scl.data.model.HistoryItem;
1314
import org.lfenergy.compas.scl.data.model.Item;
1415
import org.lfenergy.compas.scl.data.model.Version;
1516
import org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest;
@@ -68,7 +69,7 @@ void listVersionsByUUID_WhenCalled_ThenItemResponseRetrieved() {
6869
var version = "1.0.0";
6970

7071
when(compasSclDataService.listVersionsByUUID(type, uuid))
71-
.thenReturn(Collections.singletonList(new Item(uuid.toString(), name, version)));
72+
.thenReturn(Collections.singletonList(new HistoryItem(uuid.toString(), name, version, null, null, null)));
7273

7374
var response = given()
7475
.pathParam(TYPE_PATH_PARAM, type)
@@ -80,9 +81,9 @@ void listVersionsByUUID_WhenCalled_ThenItemResponseRetrieved() {
8081
.response();
8182

8283
var xmlPath = response.xmlPath();
83-
assertEquals(uuid.toString(), xmlPath.get("ListResponse.Item[0].Id"));
84-
assertEquals(name, xmlPath.get("ListResponse.Item[0].Name"));
85-
assertEquals(version, xmlPath.get("ListResponse.Item[0].Version"));
84+
assertEquals(uuid.toString(), xmlPath.get("VersionsResponse.HistoryItem[0].Id"));
85+
assertEquals(name, xmlPath.get("VersionsResponse.HistoryItem[0].Name"));
86+
assertEquals(version, xmlPath.get("VersionsResponse.HistoryItem[0].Version"));
8687
verify(compasSclDataService, times(1)).listVersionsByUUID(type, uuid);
8788
}
8889

doc/postgresql.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ For the SCL Data Service the following table is automatically created using FlyW
2828

2929
Table: scl_file
3030

31-
| Column | Type | Required | Description |
32-
| ----------------- | -------------------- | ----------| ------------------------------------------------------------------ |
33-
| id | uuid | True | Unique ID generated according to standards |
34-
| major_version | smallint | True | Versioning according to [Semantic Versioning](https://semver.org/) |
35-
| minor_version | smallint | True | Versioning according to [Semantic Versioning](https://semver.org/) |
36-
| patch_version | smallint | True | Versioning according to [Semantic Versioning](https://semver.org/) |
37-
| type | varchar(3) | True | The type of SCL stored |
38-
| name | varchar(255) | True | The name of the SCL File |
39-
| scl_data | text | True | The SCL XML Content |
31+
| Column | Type | Required | Description |
32+
|---------------|--------------|----------|--------------------------------------------------------------------|
33+
| id | uuid | True | Unique ID generated according to standards |
34+
| major_version | smallint | True | Versioning according to [Semantic Versioning](https://semver.org/) |
35+
| minor_version | smallint | True | Versioning according to [Semantic Versioning](https://semver.org/) |
36+
| patch_version | smallint | True | Versioning according to [Semantic Versioning](https://semver.org/) |
37+
| type | varchar(3) | True | The type of SCL stored |
38+
| name | varchar(255) | True | The name of the SCL File |
39+
| scl_data | text | True | The SCL XML Content |
4040

4141
## Development
4242

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ SPDX-License-Identifier: Apache-2.0
2121
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2222

2323
<compiler-plugin.version>3.10.1</compiler-plugin.version>
24-
<surefire-plugin.version>3.0.0-M6</surefire-plugin.version>
24+
<surefire-plugin.version>3.0.0-M7</surefire-plugin.version>
2525
<sonarqube-plugin.version>3.2.0</sonarqube-plugin.version>
2626

27-
<compas.core.version>0.9.0</compas.core.version>
27+
<compas.core.version>0.9.1</compas.core.version>
2828

29-
<quarkus.platform.version>2.9.2.Final</quarkus.platform.version>
29+
<quarkus.platform.version>2.10.1.Final</quarkus.platform.version>
3030
<jaxb-impl.version>2.3.6</jaxb-impl.version>
3131
<microprofile-openapi-api.version>3.0</microprofile-openapi-api.version>
3232
<slf4j.version>1.7.36</slf4j.version>
@@ -165,7 +165,7 @@ SPDX-License-Identifier: Apache-2.0
165165
<plugin>
166166
<groupId>org.jboss.jandex</groupId>
167167
<artifactId>jandex-maven-plugin</artifactId>
168-
<version>1.2.2</version>
168+
<version>1.2.3</version>
169169
<executions>
170170
<execution>
171171
<id>make-index</id>

repository-basex/src/main/java/org/lfenergy/compas/scl/data/basex/repository/CompasSclDataBaseXRepository.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.lfenergy.compas.scl.data.basex.client.BaseXClientFactory;
99
import org.lfenergy.compas.scl.data.exception.CompasNoDataFoundException;
1010
import org.lfenergy.compas.scl.data.exception.CompasSclDataServiceException;
11+
import org.lfenergy.compas.scl.data.model.HistoryItem;
1112
import org.lfenergy.compas.scl.data.model.Item;
1213
import org.lfenergy.compas.scl.data.model.SclMetaInfo;
1314
import org.lfenergy.compas.scl.data.model.Version;
@@ -105,7 +106,7 @@ public List<Item> list(SclFileType type) {
105106
}
106107

107108
@Override
108-
public List<Item> listVersionsByUUID(SclFileType type, UUID id) {
109+
public List<HistoryItem> listVersionsByUUID(SclFileType type, UUID id) {
109110
return executeQuery(type, DECLARE_SCL_NS_URI +
110111
DECLARE_COMPAS_NAMESPACE +
111112
format(DECLARE_DB_VARIABLE, type) +
@@ -114,13 +115,21 @@ public List<Item> listVersionsByUUID(SclFileType type, UUID id) {
114115
" let $id := $resource" + SCL_HEADER_ID_XPATH + "\n" +
115116
" let $version := $resource" + SCL_HEADER_VERSION_XPATH + "\n" +
116117
" let $name := $resource" + COMPAS_NAME_EXTENSION_XPATH + "\n" +
118+
" let $header := $resource/scl:SCL/scl:Header/scl:History/scl:Hitem[(not(@revision) or @revision=\"\") and @version=$version]\n" +
117119
" let $parts := tokenize($version, '\\.')\n" +
118120
" let $majorVersion := xs:int($parts[1])\n" +
119121
" let $minorVersion := xs:int($parts[2])\n" +
120122
" let $patchVersion := xs:int($parts[3])\n" +
121123
" order by $majorVersion, $minorVersion, $patchVersion\n" +
122-
" return '<Item xmlns=\"" + SCL_DATA_SERVICE_V1_NS_URI + "\"><Id>' || $id || '</Id><Name>' || $name || '</Name><Version>' || $version || '</Version></Item>' ",
123-
sclDataMarshaller::unmarshalItem);
124+
" return '<HistoryItem xmlns=\"" + SCL_DATA_SERVICE_V1_NS_URI + "\">'" +
125+
" || ' <Id>' || $id || '</Id>'" +
126+
" || ' <Name>' || $name || '</Name>'" +
127+
" || ' <Version>' || $version || '</Version>' " +
128+
" || ' <Who>' || $header/@who || '</Who>' " +
129+
" || ' <When>' || $header/@when || '</When>' " +
130+
" || ' <What>' || $header/@what || '</What>' " +
131+
" || '</HistoryItem>' ",
132+
sclDataMarshaller::unmarshalHistoryItem);
124133
}
125134

126135
@Override

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

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import org.lfenergy.compas.scl.data.exception.CompasNoDataFoundException;
88
import org.lfenergy.compas.scl.data.exception.CompasSclDataServiceException;
9+
import org.lfenergy.compas.scl.data.model.HistoryItem;
910
import org.lfenergy.compas.scl.data.model.Item;
1011
import org.lfenergy.compas.scl.data.model.SclMetaInfo;
1112
import org.lfenergy.compas.scl.data.model.Version;
@@ -22,23 +23,41 @@
2223
import static org.lfenergy.compas.scl.data.exception.CompasSclDataServiceErrorCode.*;
2324

2425
public class CompasSclDataPostgreSQLRepository implements CompasSclDataRepository {
25-
private static final String SELECT_METADATA_CLAUSE = "select id, name, major_version, minor_version, patch_version ";
26-
private static final String SELECT_DATA_CLAUSE = "select scl_data ";
26+
private static final String SELECT_METADATA_CLAUSE = "select scl_file.id, scl_file.name, scl_file.major_version, scl_file.minor_version, scl_file.patch_version ";
27+
private static final String SELECT_DATA_CLAUSE = "select scl_file.scl_data ";
28+
private static final String SELECT_HEADER_INFO_CLAUSE =
29+
", (xpath('/scl:Hitem/@who', scl_data.header, ARRAY[ARRAY['scl', 'http://www.iec.ch/61850/2003/SCL']]))[1] hitem_who " +
30+
", (xpath('/scl:Hitem/@when', scl_data.header, ARRAY[ARRAY['scl', 'http://www.iec.ch/61850/2003/SCL']]))[1] hitem_when " +
31+
", (xpath('/scl:Hitem/@what', scl_data.header, ARRAY[ARRAY['scl', 'http://www.iec.ch/61850/2003/SCL']]))[1] hitem_what ";
2732
private static final String FROM_CLAUSE = " from scl_file ";
33+
private static final String JOIN_HEADER_CLAUSE = " left outer join (" +
34+
"SELECT id, major_version, minor_version, patch_version," +
35+
" unnest(" +
36+
" xpath('/scl:SCL/scl:Header//scl:Hitem[(not(@revision) or @revision=\"\") and @version=\"' || major_version || '.' || minor_version || '.' || patch_version || '\"]' " +
37+
" , scl_data::xml " +
38+
" , ARRAY[ARRAY['scl', 'http://www.iec.ch/61850/2003/SCL']])) as header " +
39+
" from scl_file) scl_data " +
40+
" on scl_data.id = scl_file.id " +
41+
" and scl_data.major_version = scl_file.major_version " +
42+
" and scl_data.minor_version = scl_file.minor_version " +
43+
" and scl_data.patch_version = scl_file.patch_version ";
2844
private static final String DELETE_FROM_CLAUSE = "delete " + FROM_CLAUSE;
2945
private static final String WHERE_CLAUSE = " where ";
3046
private static final String AND_CLAUSE = " and ";
3147

32-
private static final String FILTER_ON_TYPE = "type = ?";
33-
private static final String FILTER_ON_ID = "id = ?";
34-
private static final String FILTER_ON_VERSION = "major_version = ? and minor_version = ? and patch_version = ? ";
48+
private static final String FILTER_ON_TYPE = "scl_file.type = ?";
49+
private static final String FILTER_ON_ID = "scl_file.id = ?";
50+
private static final String FILTER_ON_VERSION = "scl_file.major_version = ? and scl_file.minor_version = ? and scl_file.patch_version = ? ";
3551

3652
private static final String ID_FIELD = "id";
3753
private static final String MAJOR_VERSION_FIELD = "major_version";
3854
private static final String MINOR_VERSION_FIELD = "minor_version";
3955
private static final String PATCH_VERSION_FIELD = "patch_version";
4056
private static final String NAME_FIELD = "name";
4157
private static final String SCL_DATA_FIELD = "scl_data";
58+
private static final String HITEM_WHO_FIELD = "hitem_who";
59+
private static final String HITEM_WHEN_FIELD = "hitem_when";
60+
private static final String HITEM_WHAT_FIELD = "hitem_what";
4261

4362
private final DataSource dataSource;
4463

@@ -51,7 +70,7 @@ public List<Item> list(SclFileType type) {
5170
var sql = SELECT_METADATA_CLAUSE
5271
+ FROM_CLAUSE
5372
+ WHERE_CLAUSE + FILTER_ON_TYPE
54-
+ " and (id, major_version, minor_version, patch_version) in ("
73+
+ " and (scl_file.id, scl_file.major_version, scl_file.minor_version, scl_file.patch_version) in ("
5574
// Last select the maximum patch version with the major/minor version per id.
5675
+ " select id, major_version, minor_version, max(patch_version)"
5776
+ " from scl_file patch_scl"
@@ -72,7 +91,7 @@ public List<Item> list(SclFileType type) {
7291
+ " )"
7392
+ " group by id, major_version, minor_version"
7493
+ " )"
75-
+ " order by name, major_version, minor_version, patch_version";
94+
+ " order by scl_file.name, scl_file.major_version, scl_file.minor_version, scl_file.patch_version";
7695

7796
var items = new ArrayList<Item>();
7897
try (var connection = dataSource.getConnection();
@@ -93,24 +112,29 @@ public List<Item> list(SclFileType type) {
93112
}
94113

95114
@Override
96-
public List<Item> listVersionsByUUID(SclFileType type, UUID id) {
115+
public List<HistoryItem> listVersionsByUUID(SclFileType type, UUID id) {
97116
var sql = SELECT_METADATA_CLAUSE
117+
+ SELECT_HEADER_INFO_CLAUSE
98118
+ FROM_CLAUSE
119+
+ JOIN_HEADER_CLAUSE
99120
+ WHERE_CLAUSE + FILTER_ON_ID
100121
+ AND_CLAUSE + FILTER_ON_TYPE
101-
+ " order by major_version, minor_version, patch_version";
122+
+ " order by scl_file.major_version, scl_file.minor_version, scl_file.patch_version";
102123

103-
var items = new ArrayList<Item>();
124+
var items = new ArrayList<HistoryItem>();
104125
try (var connection = dataSource.getConnection();
105126
var stmt = connection.prepareStatement(sql)) {
106127
stmt.setObject(1, id);
107128
stmt.setString(2, type.name());
108129

109130
try (var resultSet = stmt.executeQuery()) {
110131
while (resultSet.next()) {
111-
items.add(new Item(id.toString(),
132+
items.add(new HistoryItem(id.toString(),
112133
resultSet.getString(NAME_FIELD),
113-
createVersion(resultSet)));
134+
createVersion(resultSet),
135+
resultSet.getString(HITEM_WHO_FIELD),
136+
resultSet.getString(HITEM_WHEN_FIELD),
137+
resultSet.getString(HITEM_WHAT_FIELD)));
114138
}
115139
}
116140
} catch (SQLException exp) {
@@ -157,10 +181,10 @@ public String findByUUID(SclFileType type, UUID id, Version version) {
157181

158182
@Override
159183
public boolean hasDuplicateSclName(SclFileType type, String name) {
160-
var sql = "SELECT DISTINCT ON (id) * "
184+
var sql = "SELECT DISTINCT ON (scl_file.id) * "
161185
+ FROM_CLAUSE
162-
+ "WHERE type=? "
163-
+ "ORDER BY id, major_version desc, minor_version desc, patch_version desc";
186+
+ "WHERE scl_file.type = ? "
187+
+ "ORDER BY scl_file.id, scl_file.major_version desc, scl_file.minor_version desc, scl_file.patch_version desc";
164188

165189
try (var connection = dataSource.getConnection();
166190
var stmt = connection.prepareStatement(sql)) {
@@ -184,7 +208,7 @@ public SclMetaInfo findMetaInfoByUUID(SclFileType type, UUID id) {
184208
+ FROM_CLAUSE
185209
+ WHERE_CLAUSE + FILTER_ON_ID
186210
+ AND_CLAUSE + FILTER_ON_TYPE
187-
+ " order by major_version desc, minor_version desc, patch_version desc";
211+
+ " order by scl_file.major_version desc, scl_file.minor_version desc, scl_file.patch_version desc";
188212

189213
try (var connection = dataSource.getConnection();
190214
var stmt = connection.prepareStatement(sql)) {

0 commit comments

Comments
 (0)