diff --git a/pom.xml b/pom.xml
index 769f09f99..691f13b8b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,6 +36,8 @@
sct-coverage/**
../sct-coverage/target/site/jacoco-aggregate/jacoco.xml
${basedir}/${aggregate.report.dir}
+ 0.9.1
+ 0.0.4
@@ -71,7 +73,12 @@
org.lfenergy.compas.core
scl-extension
- 0.8.0
+ ${scl-extension.version}
+
+
+ org.lfenergy.compas.xsd
+ compas-scl-xsd
+ ${compas-scl-xsd.version}
ch.qos.logback
@@ -104,6 +111,16 @@
+
+ org.lfenergy.compas.xsd
+ compas-scl-xsd
+ ${compas-scl-xsd.version}
+
+
+ org.lfenergy.compas.core
+ scl-extension
+ ${scl-extension.version}
+
org.apache.maven.plugins
maven-compiler-plugin
@@ -119,6 +136,11 @@
maven-surefire-plugin
2.22.2
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 3.2.2
+
diff --git a/sct-app/pom.xml b/sct-app/pom.xml
index d8a715842..286393e04 100644
--- a/sct-app/pom.xml
+++ b/sct-app/pom.xml
@@ -13,7 +13,6 @@
local-SNAPSHOT
- org.lfenergy.compas
sct-app
local-SNAPSHOT
SCT-APP
@@ -112,7 +111,10 @@
org.lfenergy.compas.xsd
compas-scl-xsd
- 0.0.4
+
+
+ org.lfenergy.compas.core
+ scl-extension
org.lfenergy.compas.core
diff --git a/sct-app/src/main/java/org/lfenergy/compas/sct/app/SclAutomationService.java b/sct-app/src/main/java/org/lfenergy/compas/sct/app/SclAutomationService.java
index b8840930a..3abd95ebf 100644
--- a/sct-app/src/main/java/org/lfenergy/compas/sct/app/SclAutomationService.java
+++ b/sct-app/src/main/java/org/lfenergy/compas/sct/app/SclAutomationService.java
@@ -13,6 +13,7 @@
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.scl.SclService;
+import org.lfenergy.compas.sct.commons.scl.SubstationService;
import java.util.*;
@@ -32,7 +33,7 @@ public static SclRootAdapter createSCD(@NonNull SCL ssd, @NonNull HeaderDTO head
HeaderDTO.HistoryItem hItem = headerDTO.getHistoryItems().get(0);
SclService.addHistoryItem(scdAdapter.getCurrentElem(), hItem.getWho(), hItem.getWhat(), hItem.getWhy());
}
- SclService.addSubstation(scdAdapter.getCurrentElem(), ssd);
+ SubstationService.addSubstation(scdAdapter.getCurrentElem(), ssd);
SclService.importSTDElementsInSCD(scdAdapter, stds, comMap);
return scdAdapter;
}
diff --git a/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceTest.java b/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceTest.java
index 6aecfd219..84e413104 100644
--- a/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceTest.java
+++ b/sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceTest.java
@@ -17,6 +17,7 @@
import java.util.Set;
import static org.junit.jupiter.api.Assertions.*;
+import static org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller.assertIsMarshallable;
class SclAutomationServiceTest {
@@ -30,20 +31,25 @@ void init(){
}
@Test
- void createSCD() throws Exception {
+ void createSCD_should_return_generatedSCD() throws Exception {
+ // Given
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/scd.xml");
SCL std = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml");
+ // When
SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO, Set.of(std));
+ // Then
assertNotNull(expectedSCD.getCurrentElem().getHeader().getId());
assertNull(expectedSCD.getCurrentElem().getHeader().getHistory());
assertEquals(1, expectedSCD.getCurrentElem().getSubstation().size());
assertEquals(1, expectedSCD.getCurrentElem().getIED().size());
assertNotNull(expectedSCD.getCurrentElem().getDataTypeTemplates());
assertEquals(2, expectedSCD.getCurrentElem().getCommunication().getSubNetwork().size());
+ assertIsMarshallable(expectedSCD.getCurrentElem());
}
@Test
void createSCD_With_HItem() throws Exception {
+ // Given
HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem();
historyItem.setWhat("what");
historyItem.setWho("me");
@@ -53,14 +59,18 @@ void createSCD_With_HItem() throws Exception {
SCL std1 = SclTestMarshaller.getSCLFromFile("/std_1.xml");
SCL std2 = SclTestMarshaller.getSCLFromFile("/std_2.xml");
SCL std3 = SclTestMarshaller.getSCLFromFile("/std_3.xml");
+ // When
SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO, Set.of(std1, std2, std3));
+ // Then
assertNotNull(expectedSCD.getCurrentElem().getHeader().getId());
assertEquals(1 ,expectedSCD.getCurrentElem().getHeader().getHistory().getHitem().size());
assertEquals(1, expectedSCD.getCurrentElem().getSubstation().size());
+ assertIsMarshallable(expectedSCD.getCurrentElem());
}
@Test
void createSCD_With_HItems() throws Exception {
+ // Given
HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem();
historyItem.setWhat("what");
historyItem.setWho("me");
@@ -74,17 +84,22 @@ void createSCD_With_HItems() throws Exception {
SCL std1 = SclTestMarshaller.getSCLFromFile("/std_1.xml");
SCL std2 = SclTestMarshaller.getSCLFromFile("/std_2.xml");
SCL std3 = SclTestMarshaller.getSCLFromFile("/std_3.xml");
+ // When
SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO,Set.of(std1, std2, std3));
+ // Then
assertNotNull(expectedSCD.getCurrentElem().getHeader().getId());
assertEquals(1, expectedSCD.getCurrentElem().getHeader().getHistory().getHitem().size());
assertEquals("what", expectedSCD.getCurrentElem().getHeader().getHistory().getHitem().get(0).getWhat());
+ assertIsMarshallable(expectedSCD.getCurrentElem());
}
@Test
void createSCD_SSD_Without_Substation() throws Exception {
+ // Given
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd_without_substations.xml");
+ // When & Then
assertThrows(ScdException.class,
() -> SclAutomationService.createSCD(ssd, headerDTO, new HashSet<>()) );
}
-}
\ No newline at end of file
+}
diff --git a/sct-commons/pom.xml b/sct-commons/pom.xml
index 1eaf5f727..f47ecc126 100644
--- a/sct-commons/pom.xml
+++ b/sct-commons/pom.xml
@@ -32,7 +32,7 @@
org.apache.commons
commons-lang3
- 3.11
+ 3.12.0
jakarta.xml.bind
@@ -112,6 +112,7 @@
test
+
@@ -166,7 +167,10 @@
org.lfenergy.compas.xsd
compas-scl-xsd
- 0.0.4
+
+
+ org.lfenergy.compas.core
+ scl-extension
org.lfenergy.compas.core
@@ -196,6 +200,9 @@
+
+ ${project.basedir}/src/main/resources/binding_configuration.xjb
+
org.lfenergy.compas.scl2007b4.model
true
@@ -214,4 +221,4 @@
-
\ No newline at end of file
+
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/CommonConstants.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/CommonConstants.java
deleted file mode 100644
index 90dcd01b9..000000000
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/CommonConstants.java
+++ /dev/null
@@ -1,31 +0,0 @@
-// SPDX-FileCopyrightText: 2021 RTE FRANCE
-//
-// SPDX-License-Identifier: Apache-2.0
-
-package org.lfenergy.compas.sct.commons;
-
-public class CommonConstants {
- CommonConstants() {
- throw new UnsupportedOperationException("CommonConstants class");
- }
-
- public static final String XML_DEFAULT_NS_PREFIX = "scl";
- public static final String XML_DEFAULT_NS_URI = "http://www.iec.ch/61850/2003/SCL";
- public static final String XML_DEFAULT_XSD_PATH = "classpath:schema/SCL.xsd";
-
- public static final String COMPAS_SCL_FILE_TYPE = "COMPAS-SclFileType";
- public static final String SCL_FILE_TYPE = "SclFileType";
- public static final String COMPAS_ICDHEADER = "COMPAS-ICDHeader";
- public static final String ICD_SYSTEM_VERSION_UUID = "ICDSystemVersionUUID";
- public static final String IED_NAME = "IEDName";
- public static final String HEADER_ID = "headerId";
- public static final String HEADER_VERSION = "headerVersion";
- public static final String HEADER_REVISION = "headerRevision";
- public static final String IED_TYPE = "IEDType";
- public static final String VENDOR_NAME = "VendorName";
- public static final String IED_REDUNDANCY = "IEDredundancy";
- public static final String IED_MODEL = "IEDmodel";
- public static final String HW_REV = "hwRev";
- public static final String SW_REV = "swRev";
-
-}
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/Utils.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/Utils.java
deleted file mode 100644
index 91703eb81..000000000
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/Utils.java
+++ /dev/null
@@ -1,83 +0,0 @@
-// SPDX-FileCopyrightText: 2021 RTE FRANCE
-//
-// SPDX-License-Identifier: Apache-2.0
-
-package org.lfenergy.compas.sct.commons;
-
-import lombok.extern.slf4j.Slf4j;
-
-import java.lang.reflect.Field;
-
-@Slf4j
-public class Utils {
-
- private Utils() {
- throw new IllegalStateException("Utils class");
- }
-
- public static String entering(){
- return ">>> " +
- "Entering: " +
- "-::" +
- getMethodName();
- }
-
- public static String leaving(Long startTime){
- if(startTime == null || startTime <= 0){
- return leaving();
- }
- return "<<< " +
- "Leaving: " +
- "-::" +
- getMethodName() +
- " - Timer duration: " +
- (System.nanoTime() - startTime) / Math.pow(10, 9) +
- " sec.";
- }
-
- public static String getMethodName() {
- try {
- return (new Throwable()).getStackTrace()[2].getMethodName();
- } catch (Exception e){
- return "-";
- }
- }
-
- public static String leaving(){
- return "<<< " +
- "Leaving: " +
- "::" +
- getMethodName();
- }
-
- /**
- * Returns the first {@link Field} in the hierarchy for the specified name
- */
- public static Field getField(Class> clazz, String name) {
- Field field = null;
- while (clazz != null && field == null) {
- try {
- field = clazz.getDeclaredField(name);
- } catch (Exception e) {
- log.error("Cannot find field name {}", name, e);
- }
- clazz = clazz.getSuperclass();
- }
- return field;
- }
-
- /**
- * Sets {@code value} to the first {@link Field} in the {@code object} hierarchy, for the specified name
- */
- public static void setField(Object object, String fieldName, Object value) {
- try {
- Field field = getField(object.getClass(), fieldName);
- if(field != null){
- field.setAccessible(true);
- field.set(object, value);
- }
- } catch (Exception e) {
- log.error("Cannot nullify {} : ",fieldName, e);
- }
- }
-}
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ControlBlock.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ControlBlock.java
index 5d3352fdc..ca09a625a 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ControlBlock.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ControlBlock.java
@@ -7,14 +7,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
-import org.lfenergy.compas.scl2007b4.model.TClientLN;
-import org.lfenergy.compas.scl2007b4.model.TControl;
-import org.lfenergy.compas.scl2007b4.model.TControlWithIEDName;
-import org.lfenergy.compas.scl2007b4.model.TPredefinedTypeOfSecurityEnum;
-import org.lfenergy.compas.scl2007b4.model.TServiceSettingsNoDynEnum;
-import org.lfenergy.compas.scl2007b4.model.TServiceType;
-import org.lfenergy.compas.scl2007b4.model.TServices;
-import org.lfenergy.compas.sct.commons.Utils;
+import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;
@@ -79,14 +72,12 @@ public void validateDestination(SclRootAdapter sclRootAdapter) throws ScdExcepti
)
)
);
- if(!iedName.getLnClass().isEmpty()) {
+ if (iedName.isSetLnClass()) {
try {
lDeviceAdapter.getLNAdapter(iedName.getLnClass().get(0), iedName.getLnInst(), iedName.getPrefix());
- } catch (ScdException e){
+ } catch (ScdException e) {
throw new ScdException("Control block destination: " + e.getMessage());
}
- } else {
- Utils.setField(iedName,"lnClass",null);
}
}
}
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/DaTypeName.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/DaTypeName.java
index ce5166612..a775c1e0e 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/DaTypeName.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/DaTypeName.java
@@ -75,7 +75,7 @@ public void addDaiValues(List vals) {
}
public void addDaiValue(TVal val) {
- if(val.getSGroup() == null){
+ if(!val.isSetSGroup()){
daiValues.put(0L,val.getValue());
} else {
daiValues.put(val.getSGroup(), val.getValue());
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/FCDAInfo.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/FCDAInfo.java
index e62d3c3d7..de23eb520 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/FCDAInfo.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/FCDAInfo.java
@@ -39,10 +39,9 @@ public FCDAInfo(String dataSet, TFCDA tfcda) {
lnInst = tfcda.getLnInst();
doName = new DoTypeName(tfcda.getDoName());
daName = new DaTypeName(tfcda.getDaName());
- ix = tfcda.getIx();
+ ix = tfcda.isSetIx() ? tfcda.getIx() : null;
}
-
@JsonIgnore
public TFCDA getFCDA(){
TFCDA tfcda = new TFCDA();
@@ -75,4 +74,4 @@ public TFCDA getFCDA(){
public boolean isValid() {
return doName != null && doName.isDefined();
}
-}
\ No newline at end of file
+}
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/GooseControlBlock.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/GooseControlBlock.java
index d1d447ba1..ad683442c 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/GooseControlBlock.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/GooseControlBlock.java
@@ -7,12 +7,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
-import org.lfenergy.compas.scl2007b4.model.TGSEControl;
-import org.lfenergy.compas.scl2007b4.model.TMcSecurity;
-import org.lfenergy.compas.scl2007b4.model.TPredefinedTypeOfSecurityEnum;
-import org.lfenergy.compas.scl2007b4.model.TProtocol;
-import org.lfenergy.compas.scl2007b4.model.TServiceType;
-import org.lfenergy.compas.scl2007b4.model.TServices;
+import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.exception.ScdException;
@@ -27,7 +22,7 @@ public GooseControlBlock(TGSEControl tgseControl) {
super();
this.id = tgseControl.getAppID();
this.name = tgseControl.getName();
- if(tgseControl.getConfRev() != null) {
+ if(tgseControl.isSetConfRev()) {
this.confRev = tgseControl.getConfRev();
}
this.desc = tgseControl.getDesc();
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTO.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTO.java
index fbc91364f..22873f50a 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTO.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTO.java
@@ -6,12 +6,10 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
-
import lombok.extern.slf4j.Slf4j;
-import org.lfenergy.compas.sct.commons.Utils;
import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.LNAdapter;
-
+import org.lfenergy.compas.sct.commons.util.Utils;
import java.util.HashSet;
import java.util.List;
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeDTO.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeDTO.java
index 3892277b9..5cd8707d4 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeDTO.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeDTO.java
@@ -9,12 +9,12 @@
import lombok.extern.slf4j.Slf4j;
import org.lfenergy.compas.scl2007b4.model.TAnyLN;
import org.lfenergy.compas.scl2007b4.model.TExtRef;
-import org.lfenergy.compas.sct.commons.Utils;
import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter;
import org.lfenergy.compas.sct.commons.scl.dtt.LNodeTypeAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.LNAdapter;
+import org.lfenergy.compas.sct.commons.util.Utils;
import java.util.HashSet;
import java.util.List;
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SMVControlBlock.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SMVControlBlock.java
index 51c2469ff..13abc6425 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SMVControlBlock.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SMVControlBlock.java
@@ -7,13 +7,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
-import org.lfenergy.compas.scl2007b4.model.TMcSecurity;
-import org.lfenergy.compas.scl2007b4.model.TPredefinedTypeOfSecurityEnum;
-import org.lfenergy.compas.scl2007b4.model.TProtocol;
-import org.lfenergy.compas.scl2007b4.model.TSampledValueControl;
-import org.lfenergy.compas.scl2007b4.model.TServiceType;
-import org.lfenergy.compas.scl2007b4.model.TServices;
-import org.lfenergy.compas.scl2007b4.model.TSmpMod;
+import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import java.util.Collections;
@@ -36,9 +30,7 @@ public SMVControlBlock(TSampledValueControl tSampledValueControl) {
super();
this.id = tSampledValueControl.getSmvID();
this.name = tSampledValueControl.getName();
- if(tSampledValueControl.getConfRev() != null) {
- this.confRev = tSampledValueControl.getConfRev();
- }
+ this.confRev = tSampledValueControl.isSetConfRev() ? tSampledValueControl.getConfRev() : null;
this.desc = tSampledValueControl.getDesc();
this.dataSetRef = tSampledValueControl.getDatSet();
Collections.copy(iedNames, tSampledValueControl.getIEDName());
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/exception/ScdException.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/exception/ScdException.java
index dcf62624d..5dd039631 100644
--- a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/exception/ScdException.java
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/exception/ScdException.java
@@ -4,7 +4,10 @@
package org.lfenergy.compas.sct.commons.exception;
-public class ScdException extends Exception {
+/**
+ * Thrown when SCD is inconsistent
+ */
+public class ScdException extends RuntimeException {
public ScdException(String message) {
super(message);
}
diff --git a/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/PrivateService.java b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/PrivateService.java
new file mode 100644
index 000000000..3a8aa96de
--- /dev/null
+++ b/sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/PrivateService.java
@@ -0,0 +1,133 @@
+// SPDX-FileCopyrightText: 2022 RTE FRANCE
+//
+// SPDX-License-Identifier: Apache-2.0
+
+package org.lfenergy.compas.sct.commons.scl;
+
+import lombok.NonNull;
+import lombok.extern.slf4j.Slf4j;
+import org.lfenergy.compas.scl2007b4.model.*;
+import org.lfenergy.compas.sct.commons.exception.ScdException;
+import org.lfenergy.compas.sct.commons.util.PrivateEnum;
+
+import javax.xml.bind.JAXBElement;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+@Slf4j
+public final class PrivateService {
+
+ private PrivateService() {
+ throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
+ }
+
+ private static final ObjectFactory objectFactory = new ObjectFactory();
+
+ public static List getCompasPrivates(List tPrivates, Class compasClass) throws ScdException {
+ PrivateEnum privateEnum = PrivateEnum.fromClass(compasClass);
+ List