Skip to content

Commit

Permalink
Merge pull request #116 from com-pas/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
Dennis Labordus authored Oct 13, 2021
2 parents 57abfdb + 8e963d5 commit 0cec0ea
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 103 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ environment variables that can be set in the container to configure the validati
| JWT_GROUPS_PATH | smallrye.jwt.path.groups | The JSON Path where to find the roles of the user. | resource_access/cim-mapping/roles |

There are no roles defined in this service, only need to be authenticated.

2 changes: 1 addition & 1 deletion app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SPDX-License-Identifier: Apache-2.0
<packaging>jar</packaging>

<properties>
<quarkus.platform.version>2.2.3.Final</quarkus.platform.version>
<quarkus.platform.version>2.3.0.Final</quarkus.platform.version>

<quarkus.container-image.group>lfenergycompas</quarkus.container-image.group>
<quarkus.container-image.name>compas-cim-mapping</quarkus.container-image.name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@
package org.lfenergy.compas.cim.mapping.rest;

import org.lfenergy.compas.cim.mapping.mapper.CimToSclMapper;
import org.lfenergy.compas.core.commons.ElementConverter;

import javax.enterprise.inject.Produces;

/**
* Create Beans from other dependencies that are used in the application.
*/
public class CompasCimMappingConfiguration {
@Produces
public ElementConverter createElementConverter() {
return new ElementConverter();
}

@Produces
public CimToSclMapper createCimToSclMapper() {
return CimToSclMapper.INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-FileCopyrightText: 2021 Alliander N.V.
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.cim.mapping.rest.v1.model;

import org.eclipse.microprofile.openapi.annotations.media.Schema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
class CompasCimMappingConfigurationTest {
private CompasCimMappingConfiguration configuration = new CompasCimMappingConfiguration();

@Test
void createElementConverter_WhenCalled_ThenObjectReturned() {
assertNotNull(configuration.createElementConverter());
}

@Test
void createCimToSclMapper_WhenCalled_ThenObjectReturned() {
assertNotNull(configuration.createCimToSclMapper());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.lfenergy.compas.cim.mapping.model.CimData;
import org.lfenergy.compas.cim.mapping.rest.v1.model.MapRequest;
import org.lfenergy.compas.cim.mapping.service.CompasCimMappingService;
import org.lfenergy.compas.core.commons.ElementConverter;
import org.lfenergy.compas.scl2007b4.model.SCL;

import java.io.IOException;
Expand All @@ -27,7 +26,8 @@
import static java.util.Objects.requireNonNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.lfenergy.compas.cim.mapping.CimMappingConstants.*;
import static org.lfenergy.compas.cim.mapping.CimMappingConstants.CIM_MAPPING_SERVICE_V1_NS_URI;
import static org.lfenergy.compas.cim.mapping.CimMappingConstants.SCL_NS_URI;
import static org.mockito.Mockito.*;

@QuarkusTest
Expand All @@ -43,10 +43,9 @@ class CompasCimMappingResourceTest {

@Test
void mapCimToScl_WhenCalled_ThenCorrectMessageIsRetrieved() throws IOException {
var converter = new ElementConverter();
var cimDate = new CimData();
cimDate.setName("MiniGridTestConfiguration_BC_EQ_v3.0.0.xml");
cimDate.setRdf(List.of(converter.convertToElement(readFile(), "RDF", RDF_NS_URI)));
cimDate.setRdfData(readFile());
var request = new MapRequest();
request.setCimData(List.of(cimDate));

Expand Down
18 changes: 10 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ SPDX-License-Identifier: Apache-2.0

<compas.core.version>0.5.0</compas.core.version>
<jakarta-cdi-api.version>2.0.2</jakarta-cdi-api.version>
<apache.commons-io.version>2.11.0</apache.commons-io.version>
<slf4j.version>1.7.32</slf4j.version>
<powsybl.version>4.4.0</powsybl.version>
<mapstruct.version>1.4.2.Final</mapstruct.version>

<!-- Test -->
<junit-jupiter.version>5.7.2</junit-jupiter.version>
<mockito-junit-jupiter.version>3.12.4</mockito-junit-jupiter.version>
<junit-jupiter.version>5.8.1</junit-jupiter.version>
<mockito-junit-jupiter.version>4.0.0</mockito-junit-jupiter.version>
<openpojo.version>0.9.1</openpojo.version>
</properties>

Expand Down Expand Up @@ -70,11 +71,6 @@ SPDX-License-Identifier: Apache-2.0
<artifactId>scl2007b4</artifactId>
<version>${compas.core.version}</version>
</dependency>
<dependency>
<groupId>org.lfenergy.compas.core</groupId>
<artifactId>commons</artifactId>
<version>${compas.core.version}</version>
</dependency>
<dependency>
<groupId>org.lfenergy.compas.core</groupId>
<artifactId>jaxrs-commons</artifactId>
Expand All @@ -98,6 +94,12 @@ SPDX-License-Identifier: Apache-2.0
<version>${mapstruct.version}</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${apache.commons-io.version}</version>
</dependency>

<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
Expand Down Expand Up @@ -183,7 +185,7 @@ SPDX-License-Identifier: Apache-2.0
<plugin>
<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<version>1.1.1</version>
<version>1.2.1</version>
<executions>
<execution>
<id>make-index</id>
Expand Down
9 changes: 5 additions & 4 deletions service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ SPDX-License-Identifier: Apache-2.0
<groupId>org.lfenergy.compas.core</groupId>
<artifactId>scl2007b4</artifactId>
</dependency>
<dependency>
<groupId>org.lfenergy.compas.core</groupId>
<artifactId>commons</artifactId>
</dependency>

<dependency>
<groupId>com.powsybl</groupId>
Expand All @@ -41,6 +37,11 @@ SPDX-License-Identifier: Apache-2.0
<artifactId>mapstruct</artifactId>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>

<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import com.powsybl.cgmes.model.CgmesModelFactory;
import com.powsybl.commons.datasource.ReadOnlyMemDataSource;
import com.powsybl.triplestore.api.TripleStoreFactory;
import org.apache.commons.io.input.ReaderInputStream;
import org.lfenergy.compas.cim.mapping.model.CimData;
import org.lfenergy.compas.core.commons.ElementConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
Expand All @@ -28,13 +27,6 @@
public class CgmesCimReader {
private static final Logger LOGGER = LoggerFactory.getLogger(CgmesCimReader.class);

private final ElementConverter converter;

@Inject
public CgmesCimReader(ElementConverter converter) {
this.converter = converter;
}

/**
* Use PowSyBl to convert a CIM XML InputStream to the PowSyBl Cgmes Model.
* Multiple InputStream Objects can be passed if needed.
Expand All @@ -55,14 +47,11 @@ public CgmesModel readModel(List<CimData> cimData) {

Map<String, InputStream> convertCimDataToMap(List<CimData> cimData) {
return cimData.stream()
.filter(cimRecord -> cimRecord.getRdf() != null && cimRecord.getRdf().size() == 1)
.collect(
Collectors.toMap(
CimData::getName,
cimRecord -> {
var xml = converter.convertToString(cimRecord.getRdf().get(0), false);
return new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
})
cimRecord -> new ReaderInputStream(
new StringReader(cimRecord.getRdfData()), StandardCharsets.UTF_8))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@

import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.lfenergy.compas.cim.mapping.constraint.CimDataNamePattern;
import org.lfenergy.compas.core.commons.constraint.XmlAnyElementValid;
import org.w3c.dom.Element;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

import static org.lfenergy.compas.cim.mapping.CimMappingConstants.CIM_MAPPING_SERVICE_V1_NS_URI;
import static org.lfenergy.compas.cim.mapping.CimMappingConstants.RDF_NS_URI;

/**
* Simple Pojo Class to hold a source entry of Cim XML. PowSyBl needs to have a (file)name and of
Expand All @@ -30,11 +27,10 @@ public class CimData {
@XmlElement(name = "Name", namespace = CIM_MAPPING_SERVICE_V1_NS_URI, required = true)
private String name;

@Size(min = 1, max = 1, message = "{org.lfenergy.compas.XmlAnyElementValid.moreElements.message}")
@XmlAnyElementValid(elementName = "RDF", elementNamespace = RDF_NS_URI)
@Schema(example = "RDF XML...", implementation = String.class)
@XmlAnyElement
protected List<Element> rdf = new ArrayList<>();
@NotBlank
@XmlElement(name = "RdfData", namespace = CIM_MAPPING_SERVICE_V1_NS_URI, required = true)
@Schema(example = "RDF XML", implementation = String.class)
private String rdfData;

public String getName() {
return name;
Expand All @@ -44,11 +40,11 @@ public void setName(String name) {
this.name = name;
}

public List<Element> getRdf() {
return rdf;
public String getRdfData() {
return rdfData;
}

public void setRdf(List<Element> rdf) {
this.rdf = rdf;
public void setRdfData(String rdfData) {
this.rdfData = rdfData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.lfenergy.compas.cim.mapping.model.CimData;
import org.lfenergy.compas.core.commons.ElementConverter;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.io.IOException;
Expand All @@ -19,29 +17,22 @@

import static java.util.Objects.requireNonNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
class CgmesCimReaderTest {
@Mock
private ElementConverter converter;

@InjectMocks
private CgmesCimReader cgmesCimReader;

@Test
void readModel_WhenReadingCimModel_ThenCgmesModelReturnedWithSubstations() throws IOException {
var cimData = new CimData();
cimData.setName("MiniGridTestConfiguration_BC_EQ_v3.0.0.xml");
cimData.getRdf().add(null); // Fake added an Element, will be fixed bij mocking below.
cimData.setRdfData(readFile());
var cimDataList = List.of(cimData);

when(converter.convertToString(any(), eq(false))).thenReturn(readFile());

var result = cgmesCimReader.readModel(cimDataList);

assertEquals(5, result.substations().size());
verifyNoMoreInteractions(converter);
}

@Test
Expand All @@ -51,34 +42,6 @@ void readModel_WhenReadingWithoutCimModel_ThenCgmesModelReturnedWithoutSubstatio
var result = cgmesCimReader.readModel(cimDataList);

assertEquals(0, result.substations().size());
verifyNoMoreInteractions(converter);
}

@Test
void readModel_WhenReadingWithoutRdfElement_ThenCgmesModelReturnedWithoutSubstations() {
var cimData = new CimData();
cimData.setName("MiniGridTestConfiguration_BC_EQ_v3.0.0.xml");
cimData.setRdf(null);
var cimDataList = List.of(cimData);

var result = cgmesCimReader.readModel(cimDataList);

assertEquals(0, result.substations().size());
verifyNoMoreInteractions(converter);
}

@Test
void readModel_WhenReadingWithTooManyRdfElement_ThenCgmesModelReturnedWithoutSubstations() {
var cimData = new CimData();
cimData.setName("MiniGridTestConfiguration_BC_EQ_v3.0.0.xml");
cimData.getRdf().add(null); // Fake added an Element
cimData.getRdf().add(null); // Fake added an Element
var cimDataList = List.of(cimData);

var result = cgmesCimReader.readModel(cimDataList);

assertEquals(0, result.substations().size());
verifyNoMoreInteractions(converter);
}

private String readFile() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.lfenergy.compas.cim.mapping.cgmes.CgmesCimReader;
import org.lfenergy.compas.cim.mapping.model.*;
import org.lfenergy.compas.core.commons.ElementConverter;
import org.lfenergy.compas.scl2007b4.model.*;
import org.mapstruct.factory.Mappers;
import org.mockito.Mock;
Expand All @@ -25,7 +24,6 @@
import static java.util.Objects.requireNonNull;
import static org.junit.jupiter.api.Assertions.*;
import static org.lfenergy.compas.cim.mapping.CimMappingConstants.DC_LINE_SEGMENT_TYPE;
import static org.lfenergy.compas.cim.mapping.CimMappingConstants.RDF_NS_URI;
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
Expand All @@ -43,11 +41,10 @@ void setup() {
@Test
void map_WhenWithCimData_ThenSclMapped() throws IOException {
// This is an overall test to see the whole mapping working with a test CIM File.
var converter = new ElementConverter();
var reader = new CgmesCimReader(converter);
var reader = new CgmesCimReader();
var cimData = new CimData();
cimData.setName("MiniGridTestConfiguration_BC_EQ_v3.0.0.xml");
cimData.setRdf(List.of(converter.convertToElement(readFile(), "RDF", RDF_NS_URI)));
cimData.setRdfData(readFile());
var cgmesModel = reader.readModel(List.of(cimData));

var result = new SCL();
Expand Down

0 comments on commit 0cec0ea

Please sign in to comment.