Skip to content

Commit 09acc2b

Browse files
authored
[#67] : update LNode iedName (#124)
* [#67] : update /Substation/VoltageLevel/Bay/Function/LNode.iedName Signed-off-by: massifben <[email protected]> * [#67] : take comments into account Signed-off-by: massifben <[email protected]> * [#67] : add XPath in error message Signed-off-by: massifben <[email protected]> Signed-off-by: massifben <[email protected]>
1 parent e8964e2 commit 09acc2b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1457
-374
lines changed

sct-app/src/main/java/org/lfenergy/compas/sct/app/SclAutomationService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.lfenergy.compas.sct.commons.exception.ScdException;
1414
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
1515
import org.lfenergy.compas.sct.commons.scl.SclService;
16+
import org.lfenergy.compas.sct.commons.scl.SubstationService;
1617

1718
import java.util.*;
1819

@@ -32,7 +33,7 @@ public static SclRootAdapter createSCD(@NonNull SCL ssd, @NonNull HeaderDTO head
3233
HeaderDTO.HistoryItem hItem = headerDTO.getHistoryItems().get(0);
3334
SclService.addHistoryItem(scdAdapter.getCurrentElem(), hItem.getWho(), hItem.getWhat(), hItem.getWhy());
3435
}
35-
SclService.addSubstation(scdAdapter.getCurrentElem(), ssd);
36+
SubstationService.addSubstation(scdAdapter.getCurrentElem(), ssd);
3637
SclService.importSTDElementsInSCD(scdAdapter, stds, comMap);
3738
return scdAdapter;
3839
}

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/CommonConstants.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ControlBlock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void validateDestination(SclRootAdapter sclRootAdapter) throws ScdExcepti
7272
)
7373
)
7474
);
75-
if (iedName.isSetLnClass() && !iedName.getLnClass().isEmpty()) {
75+
if (iedName.isSetLnClass()) {
7676
try {
7777
lDeviceAdapter.getLNAdapter(iedName.getLnClass().get(0), iedName.getLnInst(), iedName.getPrefix());
7878
} catch (ScdException e) {

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LDeviceDTO.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66

77
import lombok.Getter;
88
import lombok.NoArgsConstructor;
9-
109
import lombok.extern.slf4j.Slf4j;
11-
import org.lfenergy.compas.sct.commons.Utils;
1210
import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter;
1311
import org.lfenergy.compas.sct.commons.scl.ied.LNAdapter;
14-
12+
import org.lfenergy.compas.sct.commons.util.Utils;
1513

1614
import java.util.HashSet;
1715
import java.util.List;

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/LNodeDTO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
import lombok.extern.slf4j.Slf4j;
1010
import org.lfenergy.compas.scl2007b4.model.TAnyLN;
1111
import org.lfenergy.compas.scl2007b4.model.TExtRef;
12-
import org.lfenergy.compas.sct.commons.Utils;
1312
import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter;
1413
import org.lfenergy.compas.sct.commons.scl.dtt.LNodeTypeAdapter;
1514
import org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter;
1615
import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter;
1716
import org.lfenergy.compas.sct.commons.scl.ied.LNAdapter;
17+
import org.lfenergy.compas.sct.commons.util.Utils;
1818

1919
import java.util.HashSet;
2020
import java.util.List;

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/exception/ScdException.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
package org.lfenergy.compas.sct.commons.exception;
66

7-
public class ScdException extends Exception {
7+
/**
8+
* Thrown when SCD is inconsistent
9+
*/
10+
public class ScdException extends RuntimeException {
811
public ScdException(String message) {
912
super(message);
1013
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
// SPDX-FileCopyrightText: 2022 RTE FRANCE
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sct.commons.scl;
6+
7+
import lombok.NonNull;
8+
import lombok.extern.slf4j.Slf4j;
9+
import org.lfenergy.compas.scl2007b4.model.*;
10+
import org.lfenergy.compas.sct.commons.exception.ScdException;
11+
import org.lfenergy.compas.sct.commons.util.PrivateEnum;
12+
13+
import javax.xml.bind.JAXBElement;
14+
import java.util.ArrayList;
15+
import java.util.Collections;
16+
import java.util.List;
17+
import java.util.Optional;
18+
import java.util.function.Predicate;
19+
import java.util.stream.Collectors;
20+
21+
@Slf4j
22+
public final class PrivateService {
23+
24+
private PrivateService() {
25+
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
26+
}
27+
28+
private static final ObjectFactory objectFactory = new ObjectFactory();
29+
30+
public static <T> List<T> getCompasPrivates(List<TPrivate> tPrivates, Class<T> compasClass) throws ScdException {
31+
PrivateEnum privateEnum = PrivateEnum.fromClass(compasClass);
32+
List<Object> compasElements = tPrivates.stream().filter(tPrivate -> privateEnum.getPrivateType().equals(tPrivate.getType()))
33+
.map(TAnyContentFromOtherNamespace::getContent).flatMap(List::stream)
34+
.filter(JAXBElement.class::isInstance).map(JAXBElement.class::cast)
35+
.filter(Predicate.not(JAXBElement::isNil))
36+
.map(JAXBElement::getValue).collect(Collectors.toList());
37+
38+
List<T> result = new ArrayList<>();
39+
for (Object compasElement : compasElements) {
40+
if (compasClass.isInstance(compasElement)) {
41+
result.add(compasClass.cast(compasElement));
42+
} else {
43+
throw new ScdException(String.format("Private is inconsistent. It has type=%s which expect JAXBElement<%s> content, " +
44+
"but got JAXBElement<%s>",
45+
privateEnum.getPrivateType(), privateEnum.getCompasClass().getName(), compasElement.getClass().getName()));
46+
}
47+
}
48+
return result;
49+
}
50+
51+
public static <T> List<T> getCompasPrivates(TBaseElement baseElement, Class<T> compasClass) throws ScdException {
52+
if (!baseElement.isSetPrivate()) {
53+
return Collections.emptyList();
54+
}
55+
return getCompasPrivates(baseElement.getPrivate(), compasClass);
56+
}
57+
58+
public static <T> Optional<T> getCompasPrivate(TPrivate tPrivate, Class<T> compasClass) throws ScdException {
59+
List<T> compasPrivates = getCompasPrivates(Collections.singletonList(tPrivate), compasClass);
60+
if (compasPrivates.size() > 1) {
61+
throw new ScdException(String.format("Expecting maximum 1 element of type %s in private %s, but got %d",
62+
compasClass.getName(), tPrivate.getType(), compasPrivates.size()));
63+
}
64+
if (compasPrivates.isEmpty()) {
65+
return Optional.empty();
66+
}
67+
return Optional.of(compasPrivates.get(0));
68+
}
69+
70+
public static Optional<TCompasICDHeader> getCompasICDHeader(TPrivate tPrivate) throws ScdException {
71+
return getCompasPrivate(tPrivate, TCompasICDHeader.class);
72+
}
73+
74+
public static void removePrivates(TBaseElement baseElement, @NonNull PrivateEnum privateEnum) {
75+
if (baseElement.isSetPrivate()) {
76+
baseElement.getPrivate().removeIf(tPrivate -> privateEnum.getPrivateType().equals(tPrivate.getType()));
77+
if (baseElement.getPrivate().isEmpty()) {
78+
baseElement.unsetPrivate();
79+
}
80+
}
81+
}
82+
83+
public static TPrivate createPrivate(TCompasBay compasBay) {
84+
return createPrivate(objectFactory.createBay(compasBay));
85+
}
86+
87+
public static TPrivate createPrivate(TCompasCriteria compasCriteria) {
88+
return createPrivate(objectFactory.createCriteria(compasCriteria));
89+
}
90+
91+
public static TPrivate createPrivate(TCompasFlow compasFlow) {
92+
return createPrivate(objectFactory.createFlow(compasFlow));
93+
}
94+
95+
public static TPrivate createPrivate(TCompasFunction compasFunction) {
96+
return createPrivate(objectFactory.createFunction(compasFunction));
97+
}
98+
99+
public static TPrivate createPrivate(TCompasICDHeader compasICDHeader) {
100+
return createPrivate(objectFactory.createICDHeader(compasICDHeader));
101+
}
102+
103+
public static TPrivate createPrivate(TCompasLDevice compasLDevice) {
104+
return createPrivate(objectFactory.createLDevice(compasLDevice));
105+
}
106+
107+
public static TPrivate createPrivate(TCompasSclFileType compasSclFileType) {
108+
return createPrivate(objectFactory.createSclFileType(compasSclFileType));
109+
}
110+
111+
public static TPrivate createPrivate(TCompasSystemVersion compasSystemVersion) {
112+
return createPrivate(objectFactory.createSystemVersion(compasSystemVersion));
113+
}
114+
115+
private static TPrivate createPrivate(JAXBElement<?> jaxbElement) {
116+
PrivateEnum privateEnum = PrivateEnum.fromClass(jaxbElement.getDeclaredType());
117+
TPrivate tPrivate = new TPrivate();
118+
tPrivate.setType(privateEnum.getPrivateType());
119+
tPrivate.getContent().add(jaxbElement);
120+
return tPrivate;
121+
}
122+
123+
124+
125+
126+
127+
128+
129+
130+
131+
132+
133+
}

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SclElementAdapter.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package org.lfenergy.compas.sct.commons.scl;
66

77
import lombok.Getter;
8+
import org.lfenergy.compas.scl2007b4.model.TBaseElement;
89
import org.lfenergy.compas.scl2007b4.model.TPrivate;
910

1011

@@ -43,7 +44,21 @@ public final void setCurrentElem(T currentElem){
4344

4445
protected abstract boolean amChildElementRef();
4546

46-
protected abstract void addPrivate(TPrivate tPrivate);
47+
public void addPrivate(TPrivate tPrivate){
48+
if (currentElem instanceof TBaseElement){
49+
((TBaseElement) currentElem).getPrivate().add(tPrivate);
50+
} else {
51+
throw new UnsupportedOperationException("Not implemented for class " + this.getClass().getName());
52+
}
53+
}
4754

48-
}
55+
public String getXPath(){
56+
String parentXpath = (parentAdapter != null) ? parentAdapter.getXPath() : "";
57+
return parentXpath + "/" + elementXPath();
58+
}
4959

60+
protected String elementXPath(){
61+
return String.format("undefined(%s)", currentElem.getClass().getSimpleName());
62+
}
63+
64+
}

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SclRootAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ protected boolean amChildElementRef() {
5454
}
5555

5656
@Override
57-
protected void addPrivate(TPrivate tPrivate) {
58-
currentElem.getPrivate().add(tPrivate);
57+
protected String elementXPath() {
58+
return "SCL";
5959
}
6060

6161
public Short getSclRelease(){

0 commit comments

Comments
 (0)