Skip to content

Commit

Permalink
Merge pull request #39 from com-pas/create-scd-with-header
Browse files Browse the repository at this point in the history
Create scd with header and import ICD
  • Loading branch information
AliouDIAITE authored Nov 18, 2021
2 parents 0ade614 + 452ca41 commit e356c04
Show file tree
Hide file tree
Showing 137 changed files with 10,168 additions and 13 deletions.
48 changes: 47 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,57 @@
<sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.2</version>
</dependency>
<dependency>
<groupId>org.lfenergy.compas.core</groupId>
<artifactId>scl2007b4</artifactId>
<version>0.2.1</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.6</version>
</dependency>
<!--<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.32</version>
<scope>test</scope>
</dependency>-->
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.lfenergy.compas.core</groupId>
<artifactId>scl2007b4</artifactId>
<version>0.2.1</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
<modules>
<module>sct-commons</module>
<module>sct-coverage</module>
<module>sct-data</module>
<module>sct-data-pg</module>
<module>sct-service</module>
</modules>

<build>
Expand All @@ -55,6 +96,11 @@
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</pluginManagement>

Expand Down
70 changes: 60 additions & 10 deletions sct-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@
<groupId>org.lfenergy.compas</groupId>
<artifactId>sct-commons</artifactId>
<version>local-SNAPSHOT</version>
<name>SCT-COMMONS</name>


<properties>
<sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.3</version>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
Expand All @@ -38,21 +45,19 @@
<version>2.3.3</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>5.3.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -67,6 +72,12 @@
<version>3.6.28</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>4.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
Expand All @@ -86,6 +97,45 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>initialize</phase>
<goals>
<goal>unpack</goal>
</goals>

<configuration>
<artifactItems>
<artifactItem>
<groupId>org.lfenergy.compas.xsd</groupId>
<artifactId>compas-scl-xsd</artifactId>
<version>0.0.4</version>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-FileCopyrightText: 2021 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons;

import lombok.extern.slf4j.Slf4j;
import org.lfenergy.compas.core.commons.exception.CompasErrorCode;
import org.lfenergy.compas.core.commons.exception.CompasException;

import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.*;

@Slf4j
public class MarshallerWrapper {
private final Unmarshaller unmarshaller;
private final Marshaller marshaller;

protected MarshallerWrapper(Unmarshaller unmarshaller, Marshaller marshaller) {
this.unmarshaller = unmarshaller;
this.marshaller = marshaller;
}

public static SclMarshallerBuilder builder(){
return new SclMarshallerBuilder();
}

public <T> String marshall(final T obj) {
try {
StringWriter sw = new StringWriter();
Result result = new StreamResult(sw);
marshaller.marshal(obj, result);

return sw.toString();
} catch (JAXBException exp) {
String message = String.format("Error marshalling the Class: %s", exp);
log.error(message);
throw new CompasException(CompasErrorCode.MARSHAL_ERROR_CODE, message);
}
}

public <T> T unmarshall(final byte[] xml, Class<T> cls) {
ByteArrayInputStream input = new ByteArrayInputStream(xml);
return unmarshall(input, cls);
}

public <T> T unmarshall(final InputStream xml, Class<T> cls) {
try {
Object result = unmarshaller.unmarshal(new StreamSource(xml));
if (!result.getClass().isAssignableFrom(cls)) {
throw new CompasException(CompasErrorCode.UNMARSHAL_ERROR_CODE,
"Error unmarshalling to the Class. Invalid class");
}
return cls.cast(result);
} catch (JAXBException exp) {
String message = String.format("Error unmarshalling to the Class: %s", exp.getLocalizedMessage());
log.error(message);
throw new CompasException(CompasErrorCode.UNMARSHAL_ERROR_CODE, message);
}
}
}
Loading

0 comments on commit e356c04

Please sign in to comment.