Skip to content

Commit 82769ef

Browse files
author
Dennis Labordus
authored
Merge pull request #209 from com-pas/develop
New release
2 parents 5b7579c + c7430ed commit 82769ef

File tree

11 files changed

+106
-36
lines changed

11 files changed

+106
-36
lines changed

.github/workflows/build-project.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ jobs:
2626
id: buildx
2727
uses: docker/setup-buildx-action@v1
2828
- name: Cache Docker Register
29-
uses: actions/cache@v2
29+
uses: actions/cache@v3
3030
with:
3131
path: /tmp/.buildx-cache
3232
key: ${{ runner.os }}-buildx-${{ hashFiles('**/Dockerfile') }}
3333
- name: Cache Maven packages
34-
uses: actions/cache@v2.1.6
34+
uses: actions/cache@v3
3535
with:
3636
path: ~/.m2
3737
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}

.github/workflows/release-project.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ jobs:
2626
username: ${{ secrets.DOCKER_HUB_USERNAME }}
2727
password: ${{ secrets.DOCKER_HUB_TOKEN }}
2828
- name: Cache Docker Register
29-
uses: actions/cache@v2
29+
uses: actions/cache@v3
3030
with:
3131
path: /tmp/.buildx-cache
3232
key: ${{ runner.os }}-buildx-${{ hashFiles('**/Dockerfile') }}
3333
- name: Cache Maven packages
34-
uses: actions/cache@v2.1.6
34+
uses: actions/cache@v3
3535
with:
3636
path: ~/.m2
3737
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}

.github/workflows/sonarcloud-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ jobs:
3636
distribution: 'zulu'
3737
java-version: '11'
3838
- name: Cache SonarCloud packages
39-
uses: actions/cache@v2.1.6
39+
uses: actions/cache@v3
4040
with:
4141
path: ~/.sonar/cache
4242
key: ${{ runner.os }}-sonar
4343
restore-keys: ${{ runner.os }}-sonar
4444
- name: Cache Maven packages
45-
uses: actions/cache@v2.1.6
45+
uses: actions/cache@v3
4646
with:
4747
path: ~/.m2
4848
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}

app/src/main/java/org/lfenergy/compas/scl/data/rest/CompasSclDataServiceCommonConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0
44
package org.lfenergy.compas.scl.data.rest;
55

6+
import io.quarkus.runtime.annotations.RegisterForReflection;
67
import org.lfenergy.compas.core.commons.ElementConverter;
78
import org.lfenergy.compas.scl.data.repository.CompasSclDataRepository;
89
import org.lfenergy.compas.scl.data.service.CompasSclDataService;
@@ -16,6 +17,10 @@
1617
/**
1718
* Create Beans from other dependencies that are used in the application.
1819
*/
20+
@RegisterForReflection(targets = {
21+
org.lfenergy.compas.core.jaxrs.model.ErrorResponse.class,
22+
org.lfenergy.compas.core.jaxrs.model.ErrorMessage.class
23+
})
1924
public class CompasSclDataServiceCommonConfiguration {
2025
@Produces
2126
@ApplicationScoped

app/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ compas.userinfo.session.warning = ${USERINFO_SESSION_WARNING:10}
88
compas.userinfo.session.expires = ${USERINFO_SESSION_EXPIRES:15}
99

1010
quarkus.http.cors = false
11-
quarkus.http.root-path = /compas-scl-data-service/
11+
quarkus.http.root-path = /compas-scl-data-service
1212
quarkus.http.limits.max-body-size = 150M
1313

1414
quarkus.log.level = INFO

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,33 @@ void create_WhenCalled_ThenServiceCalledAndUUIDRetrieved() throws IOException {
170170
verify(compasSclDataService, times(1)).create(type, name, USERNAME, comment, scl);
171171
}
172172

173+
@Test
174+
void create_WhenCalledWithInvalidName_ThenErrorReturned() throws IOException {
175+
var type = SclFileType.SCD;
176+
var invalidName = "tes/*.ssd.";
177+
var comment = "Some comments";
178+
var scl = readSCL();
179+
180+
var request = new CreateRequest();
181+
request.setName(invalidName);
182+
request.setComment(comment);
183+
request.setSclData(scl);
184+
185+
var response = given()
186+
.pathParam(TYPE_PATH_PARAM, type)
187+
.contentType(ContentType.XML)
188+
.body(request)
189+
.when().post()
190+
.then()
191+
.statusCode(400)
192+
.extract()
193+
.response();
194+
195+
var xpath = response.xmlPath();
196+
assertEquals("CORE-8000", xpath.getString("ErrorResponse.ErrorMessage.Code"));
197+
assertEquals("create.request.name", xpath.getString("ErrorResponse.ErrorMessage.Property"));
198+
}
199+
173200
@Test
174201
void update_WhenCalled_ThenServiceCalledAndNewUUIDRetrieved() throws IOException {
175202
var uuid = UUID.randomUUID();

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-M5</surefire-plugin.version>
24+
<surefire-plugin.version>3.0.0-M6</surefire-plugin.version>
2525
<sonarqube-plugin.version>3.2.0</sonarqube-plugin.version>
2626

2727
<compas.core.version>0.8.0</compas.core.version>
2828

29-
<quarkus.platform.version>2.7.5.Final</quarkus.platform.version>
29+
<quarkus.platform.version>2.8.2.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>
@@ -200,7 +200,7 @@ SPDX-License-Identifier: Apache-2.0
200200
<sonar.language>java</sonar.language>
201201

202202
<!-- JaCoCo Properties -->
203-
<jacoco.version>0.8.7</jacoco.version>
203+
<jacoco.version>0.8.8</jacoco.version>
204204
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
205205
<sonar.coverage.jacoco.xmlReportPaths>
206206
target/site/jacoco/jacoco.xml,
@@ -268,7 +268,7 @@ SPDX-License-Identifier: Apache-2.0
268268
<plugin>
269269
<groupId>org.apache.maven.plugins</groupId>
270270
<artifactId>maven-javadoc-plugin</artifactId>
271-
<version>3.3.2</version>
271+
<version>3.4.0</version>
272272
<executions>
273273
<execution>
274274
<id>attach-javadocs</id>

repository-postgresql/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ SPDX-License-Identifier: Apache-2.0
4444
<dependency>
4545
<groupId>com.opentable.components</groupId>
4646
<artifactId>otj-pg-embedded</artifactId>
47-
<version>1.0.0</version>
47+
<version>1.0.1</version>
4848
<scope>test</scope>
4949
</dependency>
5050

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public class CompasSclDataPostgreSQLRepository implements CompasSclDataRepositor
2828
private static final String DELETE_FROM_CLAUSE = "delete " + FROM_CLAUSE;
2929
private static final String WHERE_CLAUSE = " where ";
3030
private static final String AND_CLAUSE = " and ";
31-
private static final String ORDER_BY_CLAUSE = " order by id, major_version, minor_version, patch_version";
3231

3332
private static final String FILTER_ON_TYPE = "type = ?";
3433
private static final String FILTER_ON_ID = "id = ?";
@@ -73,7 +72,7 @@ public List<Item> list(SclFileType type) {
7372
+ " )"
7473
+ " group by id, major_version, minor_version"
7574
+ " )"
76-
+ ORDER_BY_CLAUSE;
75+
+ " order by name, major_version, minor_version, patch_version";
7776

7877
var items = new ArrayList<Item>();
7978
try (var connection = dataSource.getConnection();
@@ -99,7 +98,7 @@ public List<Item> listVersionsByUUID(SclFileType type, UUID id) {
9998
+ FROM_CLAUSE
10099
+ WHERE_CLAUSE + FILTER_ON_ID
101100
+ AND_CLAUSE + FILTER_ON_TYPE
102-
+ ORDER_BY_CLAUSE;
101+
+ " order by major_version, minor_version, patch_version";
103102

104103
var items = new ArrayList<Item>();
105104
try (var connection = dataSource.getConnection();

service/src/main/java/org/lfenergy/compas/scl/data/service/impl/CompasSclDataServiceImpl.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public String create(SclFileType type, String name, String who, String comment,
130130
createHistoryItem(header, "SCL created", who, comment, version);
131131

132132
// Update or add the Compas Private Element to the SCL File.
133-
setSclCompasPrivateElement(scl, Optional.of(name), type);
133+
setSclCompasPrivateElement(scl, name, type);
134134

135135
var newSclData = converter.convertToString(scl);
136136
repository.create(type, id, name, newSclData, version, who);
@@ -167,10 +167,11 @@ public String update(SclFileType type, UUID id, ChangeSetType changeSetType, Str
167167
createHistoryItem(header, "SCL updated", who, comment, version);
168168

169169
// Update or add the Compas Private Element to the SCL File.
170-
setSclCompasPrivateElement(scl, Optional.ofNullable(currentSclMetaInfo.getName()), type);
170+
var newSclName = getFilenameFromXML(scl).orElse(currentSclMetaInfo.getName());
171+
setSclCompasPrivateElement(scl, newSclName, type);
171172

172173
var newSclData = converter.convertToString(scl);
173-
repository.create(type, id, currentSclMetaInfo.getName(), newSclData, version, who);
174+
repository.create(type, id, newSclName, newSclData, version, who);
174175
return newSclData;
175176
}
176177

@@ -216,24 +217,37 @@ private Element createOrUpdateHeader(Element scl, UUID id, Version version) {
216217
return header;
217218
}
218219

220+
/**
221+
* Retrieve the CoMPAS SCL Filename from the private element of CoMPAS.
222+
*
223+
* @param scl The SCL file to edit.
224+
* @return If there was a private SclName the value of this tag.
225+
*/
226+
private Optional<String> getFilenameFromXML(Element scl) {
227+
return sclElementProcessor.getCompasPrivate(scl)
228+
.stream()
229+
.map(compasPrivate -> sclElementProcessor.getChildNodeByName(compasPrivate, COMPAS_SCL_NAME_EXTENSION))
230+
.flatMap(Optional::stream)
231+
.map(Element::getTextContent)
232+
.findFirst();
233+
}
234+
219235
/**
220236
* Create/update the CoMPAS private element on the SCL Element for the given file.
221237
*
222238
* @param scl The SCL file to edit.
223239
* @param name The name to add.
224240
* @param fileType The file type to add.
225241
*/
226-
private void setSclCompasPrivateElement(Element scl, Optional<String> name, SclFileType fileType) {
242+
private void setSclCompasPrivateElement(Element scl, String name, SclFileType fileType) {
227243
var compasPrivate = sclElementProcessor.getCompasPrivate(scl)
228244
.orElseGet(() -> sclElementProcessor.addCompasPrivate(scl));
229245

230246
sclElementProcessor.getChildNodeByName(compasPrivate, COMPAS_SCL_NAME_EXTENSION)
231247
.ifPresentOrElse(
232248
// Override the value of the element with the name passed.
233-
element -> name.ifPresent(element::setTextContent),
234-
() -> name.ifPresent(
235-
// Add the Compas Element and give it a value with the name passed.
236-
value -> sclElementProcessor.addCompasElement(compasPrivate, COMPAS_SCL_NAME_EXTENSION, value))
249+
element -> element.setTextContent(name),
250+
() -> sclElementProcessor.addCompasElement(compasPrivate, COMPAS_SCL_NAME_EXTENSION, name)
237251
);
238252

239253
// Always set the file type as private element.

0 commit comments

Comments
 (0)