Skip to content

Commit

Permalink
Merge pull request #209 from com-pas/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
Dennis Labordus authored May 2, 2022
2 parents 5b7579c + c7430ed commit 82769ef
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker Register
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('**/Dockerfile') }}
- name: Cache Maven packages
uses: actions/cache@v2.1.6
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Cache Docker Register
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('**/Dockerfile') }}
- name: Cache Maven packages
uses: actions/cache@v2.1.6
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sonarcloud-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ jobs:
distribution: 'zulu'
java-version: '11'
- name: Cache SonarCloud packages
uses: actions/cache@v2.1.6
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v2.1.6
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
package org.lfenergy.compas.scl.data.rest;

import io.quarkus.runtime.annotations.RegisterForReflection;
import org.lfenergy.compas.core.commons.ElementConverter;
import org.lfenergy.compas.scl.data.repository.CompasSclDataRepository;
import org.lfenergy.compas.scl.data.service.CompasSclDataService;
Expand All @@ -16,6 +17,10 @@
/**
* Create Beans from other dependencies that are used in the application.
*/
@RegisterForReflection(targets = {
org.lfenergy.compas.core.jaxrs.model.ErrorResponse.class,
org.lfenergy.compas.core.jaxrs.model.ErrorMessage.class
})
public class CompasSclDataServiceCommonConfiguration {
@Produces
@ApplicationScoped
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ compas.userinfo.session.warning = ${USERINFO_SESSION_WARNING:10}
compas.userinfo.session.expires = ${USERINFO_SESSION_EXPIRES:15}

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

quarkus.log.level = INFO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,33 @@ void create_WhenCalled_ThenServiceCalledAndUUIDRetrieved() throws IOException {
verify(compasSclDataService, times(1)).create(type, name, USERNAME, comment, scl);
}

@Test
void create_WhenCalledWithInvalidName_ThenErrorReturned() throws IOException {
var type = SclFileType.SCD;
var invalidName = "tes/*.ssd.";
var comment = "Some comments";
var scl = readSCL();

var request = new CreateRequest();
request.setName(invalidName);
request.setComment(comment);
request.setSclData(scl);

var response = given()
.pathParam(TYPE_PATH_PARAM, type)
.contentType(ContentType.XML)
.body(request)
.when().post()
.then()
.statusCode(400)
.extract()
.response();

var xpath = response.xmlPath();
assertEquals("CORE-8000", xpath.getString("ErrorResponse.ErrorMessage.Code"));
assertEquals("create.request.name", xpath.getString("ErrorResponse.ErrorMessage.Property"));
}

@Test
void update_WhenCalled_ThenServiceCalledAndNewUUIDRetrieved() throws IOException {
var uuid = UUID.randomUUID();
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ SPDX-License-Identifier: Apache-2.0
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<compiler-plugin.version>3.10.1</compiler-plugin.version>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
<surefire-plugin.version>3.0.0-M6</surefire-plugin.version>
<sonarqube-plugin.version>3.2.0</sonarqube-plugin.version>

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

<quarkus.platform.version>2.7.5.Final</quarkus.platform.version>
<quarkus.platform.version>2.8.2.Final</quarkus.platform.version>
<jaxb-impl.version>2.3.6</jaxb-impl.version>
<microprofile-openapi-api.version>3.0</microprofile-openapi-api.version>
<slf4j.version>1.7.36</slf4j.version>
Expand Down Expand Up @@ -200,7 +200,7 @@ SPDX-License-Identifier: Apache-2.0
<sonar.language>java</sonar.language>

<!-- JaCoCo Properties -->
<jacoco.version>0.8.7</jacoco.version>
<jacoco.version>0.8.8</jacoco.version>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.coverage.jacoco.xmlReportPaths>
target/site/jacoco/jacoco.xml,
Expand Down Expand Up @@ -268,7 +268,7 @@ SPDX-License-Identifier: Apache-2.0
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.2</version>
<version>3.4.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down
2 changes: 1 addition & 1 deletion repository-postgresql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ SPDX-License-Identifier: Apache-2.0
<dependency>
<groupId>com.opentable.components</groupId>
<artifactId>otj-pg-embedded</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class CompasSclDataPostgreSQLRepository implements CompasSclDataRepositor
private static final String DELETE_FROM_CLAUSE = "delete " + FROM_CLAUSE;
private static final String WHERE_CLAUSE = " where ";
private static final String AND_CLAUSE = " and ";
private static final String ORDER_BY_CLAUSE = " order by id, major_version, minor_version, patch_version";

private static final String FILTER_ON_TYPE = "type = ?";
private static final String FILTER_ON_ID = "id = ?";
Expand Down Expand Up @@ -73,7 +72,7 @@ public List<Item> list(SclFileType type) {
+ " )"
+ " group by id, major_version, minor_version"
+ " )"
+ ORDER_BY_CLAUSE;
+ " order by name, major_version, minor_version, patch_version";

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

var items = new ArrayList<Item>();
try (var connection = dataSource.getConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public String create(SclFileType type, String name, String who, String comment,
createHistoryItem(header, "SCL created", who, comment, version);

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

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

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

var newSclData = converter.convertToString(scl);
repository.create(type, id, currentSclMetaInfo.getName(), newSclData, version, who);
repository.create(type, id, newSclName, newSclData, version, who);
return newSclData;
}

Expand Down Expand Up @@ -216,24 +217,37 @@ private Element createOrUpdateHeader(Element scl, UUID id, Version version) {
return header;
}

/**
* Retrieve the CoMPAS SCL Filename from the private element of CoMPAS.
*
* @param scl The SCL file to edit.
* @return If there was a private SclName the value of this tag.
*/
private Optional<String> getFilenameFromXML(Element scl) {
return sclElementProcessor.getCompasPrivate(scl)
.stream()
.map(compasPrivate -> sclElementProcessor.getChildNodeByName(compasPrivate, COMPAS_SCL_NAME_EXTENSION))
.flatMap(Optional::stream)
.map(Element::getTextContent)
.findFirst();
}

/**
* Create/update the CoMPAS private element on the SCL Element for the given file.
*
* @param scl The SCL file to edit.
* @param name The name to add.
* @param fileType The file type to add.
*/
private void setSclCompasPrivateElement(Element scl, Optional<String> name, SclFileType fileType) {
private void setSclCompasPrivateElement(Element scl, String name, SclFileType fileType) {
var compasPrivate = sclElementProcessor.getCompasPrivate(scl)
.orElseGet(() -> sclElementProcessor.addCompasPrivate(scl));

sclElementProcessor.getChildNodeByName(compasPrivate, COMPAS_SCL_NAME_EXTENSION)
.ifPresentOrElse(
// Override the value of the element with the name passed.
element -> name.ifPresent(element::setTextContent),
() -> name.ifPresent(
// Add the Compas Element and give it a value with the name passed.
value -> sclElementProcessor.addCompasElement(compasPrivate, COMPAS_SCL_NAME_EXTENSION, value))
element -> element.setTextContent(name),
() -> sclElementProcessor.addCompasElement(compasPrivate, COMPAS_SCL_NAME_EXTENSION, name)
);

// Always set the file type as private element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,49 +163,74 @@ void create_WhenCalledWithXMLStringWithoutSCL_ThenCompasExceptionThrown() {
}

@Test
void update_WhenCalledWithCompasElements_ThenSCLReturnedWithCorrectCompasExtensionAndHistory() throws IOException {
var name = "JUSTSOMENAME";
void update_WhenCalledWithoutCompasElements_ThenSCLReturnedWithCorrectCompasExtensionAndHistory() throws IOException {
var previousName = "Previous SCL Filename";
var uuid = UUID.randomUUID();
var changeSet = ChangeSetType.MAJOR;
var who = "User A";
var nextVersion = INITIAL_VERSION.getNextVersion(changeSet);

var scl = readSCL();
scl = createCompasPrivate(scl, name);

var sclMetaInfo = new SclMetaInfo(uuid.toString(), name, INITIAL_VERSION.toString());
var sclMetaInfo = new SclMetaInfo(uuid.toString(), previousName, INITIAL_VERSION.toString());
when(compasSclDataRepository.findMetaInfoByUUID(SCL_TYPE, uuid)).thenReturn(sclMetaInfo);
doNothing().when(compasSclDataRepository).create(eq(SCL_TYPE), eq(uuid), eq(name), anyString(), eq(nextVersion), eq(who));
doNothing().when(compasSclDataRepository).create(eq(SCL_TYPE), eq(uuid), eq(previousName), anyString(), eq(nextVersion), eq(who));

scl = compasSclDataService.update(SCL_TYPE, uuid, changeSet, who, null, scl);

assertNotNull(scl);
assertCompasExtenions(scl, name);
assertCompasExtenions(scl, previousName);
assertHistoryItem(scl, nextVersion, null);
verify(compasSclDataRepository, times(1)).create(eq(SCL_TYPE), eq(uuid), eq(name), anyString(), eq(nextVersion), eq(who));
verify(compasSclDataRepository, times(1)).create(eq(SCL_TYPE), eq(uuid), eq(previousName), anyString(), eq(nextVersion), eq(who));
verify(compasSclDataRepository, times(1)).findMetaInfoByUUID(SCL_TYPE, uuid);
}

@Test
void update_WhenCalledWithoutCompasElements_ThenSCLReturnedWithCorrectCompasExtensionAndHistory() throws IOException {
var name = "JUSTSOMENAME";
void update_WhenCalledWithCompasElementsAndNewName_ThenSCLReturnedWithCorrectCompasExtensionWithNewNameAndHistory() throws IOException {
var previousName = "Previous SCL Filename";
var newName = "New SCL Filename";
var uuid = UUID.randomUUID();
var changeSet = ChangeSetType.MAJOR;
var who = "User A";
var nextVersion = INITIAL_VERSION.getNextVersion(changeSet);

var scl = readSCL();
scl = createCompasPrivate(scl, newName);

var sclMetaInfo = new SclMetaInfo(uuid.toString(), name, INITIAL_VERSION.toString());
var sclMetaInfo = new SclMetaInfo(uuid.toString(), previousName, INITIAL_VERSION.toString());
when(compasSclDataRepository.findMetaInfoByUUID(SCL_TYPE, uuid)).thenReturn(sclMetaInfo);
doNothing().when(compasSclDataRepository).create(eq(SCL_TYPE), eq(uuid), eq(name), anyString(), eq(nextVersion), eq(who));
doNothing().when(compasSclDataRepository).create(eq(SCL_TYPE), eq(uuid), eq(newName), anyString(), eq(nextVersion), eq(who));

scl = compasSclDataService.update(SCL_TYPE, uuid, changeSet, who, null, scl);

assertNotNull(scl);
assertCompasExtenions(scl, name);
assertCompasExtenions(scl, newName);
assertHistoryItem(scl, nextVersion, null);
verify(compasSclDataRepository, times(1)).create(eq(SCL_TYPE), eq(uuid), eq(newName), anyString(), eq(nextVersion), eq(who));
verify(compasSclDataRepository, times(1)).findMetaInfoByUUID(SCL_TYPE, uuid);
}

@Test
void update_WhenCalledWithCompasElementsAndSameName_ThenSCLReturnedWithCorrectCompasExtensionWithSameNameAndHistory() throws IOException {
var previousName = "Previous SCL Filename";
var uuid = UUID.randomUUID();
var changeSet = ChangeSetType.MAJOR;
var who = "User A";
var nextVersion = INITIAL_VERSION.getNextVersion(changeSet);

var scl = readSCL();
scl = createCompasPrivate(scl, previousName);

var sclMetaInfo = new SclMetaInfo(uuid.toString(), previousName, INITIAL_VERSION.toString());
when(compasSclDataRepository.findMetaInfoByUUID(SCL_TYPE, uuid)).thenReturn(sclMetaInfo);
doNothing().when(compasSclDataRepository).create(eq(SCL_TYPE), eq(uuid), eq(previousName), anyString(), eq(nextVersion), eq(who));

scl = compasSclDataService.update(SCL_TYPE, uuid, changeSet, who, null, scl);

assertNotNull(scl);
assertCompasExtenions(scl, previousName);
assertHistoryItem(scl, nextVersion, null);
verify(compasSclDataRepository, times(1)).create(eq(SCL_TYPE), eq(uuid), eq(name), anyString(), eq(nextVersion), eq(who));
verify(compasSclDataRepository, times(1)).create(eq(SCL_TYPE), eq(uuid), eq(previousName), anyString(), eq(nextVersion), eq(who));
verify(compasSclDataRepository, times(1)).findMetaInfoByUUID(SCL_TYPE, uuid);
}

Expand Down

0 comments on commit 82769ef

Please sign in to comment.