Skip to content

Commit b2a9cc8

Browse files
authored
Merge pull request #233 from com-pas/231-automated-binding-edit-inref
feat(231): Automatic binding: Edit InRef from ExtRef
2 parents 9e3b4e1 + de1a01d commit b2a9cc8

File tree

15 files changed

+1303
-230
lines changed

15 files changed

+1303
-230
lines changed

.github/workflows/sonarcloud-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
id: sonar_env
3838
run: |
3939
echo "##[set-output name=sonar_opts;]$(echo -Dsonar.host.url=https://sonarcloud.io \
40-
-Dsonar.projectKey=com-pas_compas-core \
40+
-Dsonar.projectKey=com-pas_compas-sct \
4141
-Dsonar.organization=com-pas )"
4242
- name: Create custom Maven Settings.xml
4343
uses: whelk-io/maven-settings-xml-action@v21
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-FileCopyrightText: 2023 RTE FRANCE
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sct.commons.dto;
6+
7+
public enum ExtrefTarget {
8+
SRC_REF, SRC_CB
9+
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,4 @@ public class SclReport {
3939
public boolean isSuccess() {
4040
return sclReportItems.stream().noneMatch(SclReportItem::isFatal);
4141
}
42-
4342
}

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
import lombok.Getter;
88
import org.apache.commons.lang3.StringUtils;
9-
9+
import org.lfenergy.compas.scl2007b4.model.TExtRef;
10+
import org.lfenergy.compas.scl2007b4.model.TLLN0Enum;
11+
import org.lfenergy.compas.sct.commons.dto.ExtrefTarget;
12+
import org.lfenergy.compas.sct.commons.util.Utils;
1013

1114
/**
1215
* A representation of the model object
@@ -38,7 +41,7 @@ public class ObjectReference {
3841
private static final String MALFORMED_OBJ_REF = "Malformed ObjRef : %s" ;
3942

4043
private final String reference;
41-
//IEDName.LDInst
44+
//IEDNameLDInst
4245
private String ldName;
4346
//LNPrefixLNClassLNInst
4447
private String lNodeName;
@@ -49,14 +52,30 @@ public ObjectReference(String reference) {
4952
init();
5053
}
5154

55+
public ObjectReference(TExtRef extRef, ExtrefTarget target) {
56+
this.ldName = extRef.getIedName() + extRef.getLdInst();
57+
if(target.equals(ExtrefTarget.SRC_REF)) {
58+
this.lNodeName = Utils.emptyIfBlank(extRef.getPrefix())
59+
+ (extRef.isSetLnClass() ? extRef.getLnClass().get(0): TLLN0Enum.LLN_0.value())
60+
+ Utils.emptyIfBlank(extRef.getLnInst());
61+
this.dataAttributes = Utils.emptyIfBlank(extRef.getDoName());
62+
}
63+
if(target.equals(ExtrefTarget.SRC_CB)) {
64+
this.lNodeName = Utils.emptyIfBlank(extRef.getSrcPrefix())
65+
+ (extRef.isSetSrcLNClass() ? extRef.getSrcLNClass().get(0): TLLN0Enum.LLN_0.value())
66+
+ Utils.emptyIfBlank(extRef.getSrcLNInst());
67+
this.dataAttributes = Utils.emptyIfBlank(extRef.getSrcCBName());
68+
}
69+
this.reference = this.ldName + "/" + this.lNodeName + "." + this.dataAttributes;
70+
}
71+
5272
public final void init(){
53-
String refCopy = reference;
54-
String[] objRefPart = reference.split("[/]");
73+
String[] objRefPart = reference.split("/");
5574
if(objRefPart.length != 2 || StringUtils.isBlank(objRefPart[0]) || StringUtils.isBlank(objRefPart[1])){
5675
throw new IllegalArgumentException(String.format(MALFORMED_OBJ_REF, reference));
5776
}
5877
ldName = objRefPart[0];
59-
refCopy = objRefPart[1];
78+
String refCopy = objRefPart[1];
6079
objRefPart = refCopy.split("[.]", 2);
6180
if(objRefPart.length != 2 || StringUtils.isBlank(objRefPart[0]) || StringUtils.isBlank(objRefPart[1])){
6281
throw new IllegalArgumentException(String.format(MALFORMED_OBJ_REF, reference));

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,10 @@ public static List<ExtRefInfo> getExtRefInfo(SCL scd, String iedName, String ldI
234234

235235
/**
236236
* Create LDevice
237-
* @param scd SCL file in which LDevice should be found
237+
*
238+
* @param scd SCL file in which LDevice should be found
238239
* @param iedName name of IED in which LDevice is localized
239-
* @param ldInst LdInst of LDevice for which adapter is created
240+
* @param ldInst LdInst of LDevice for which adapter is created
240241
* @return created LDevice adapter
241242
*/
242243
private static LDeviceAdapter createLDeviceAdapter(SCL scd, String iedName, String ldInst) {
@@ -504,8 +505,8 @@ public static SclRootAdapter importSTDElementsInSCD(@NonNull SclRootAdapter scdR
504505
PrivateService.createMapIEDNameAndPrivate(scdRootAdapter).forEach(tPrivate -> {
505506
String iedName = PrivateService.extractCompasICDHeader(tPrivate).get().getIEDName();
506507
String icdSysVerUuid = PrivateService.extractCompasICDHeader(tPrivate).map(TCompasICDHeader::getICDSystemVersionUUID)
507-
.orElseThrow(() -> new ScdException(ICD_SYSTEM_VERSION_UUID + " is not present in COMPAS-ICDHeader in LNode")
508-
);
508+
.orElseThrow(() -> new ScdException(ICD_SYSTEM_VERSION_UUID + " is not present in COMPAS-ICDHeader in LNode")
509+
);
509510
if (!mapICDSystemVersionUuidAndSTDFile.containsKey(icdSysVerUuid))
510511
throw new ScdException("There is no STD file found corresponding to " + PrivateService.stdCheckFormatExceptionMessage(tPrivate));
511512
// import /ied /dtt in Scd
@@ -575,6 +576,7 @@ public static SclReport updateLDeviceStatus(SCL scd) {
575576

576577
/**
577578
* Checks Control Blocks, DataSets and FCDA number limitation into Access Points
579+
*
578580
* @param scd SCL file for which LDevice should be activated or deactivated
579581
* @return SclReport Object that contain SCL file and set of errors
580582
*/
@@ -590,4 +592,21 @@ public static SclReport analyzeDataGroups(SCL scd) {
590592

591593
return new SclReport(sclRootAdapter, sclReportItems);
592594
}
595+
596+
/**
597+
* Update DAIs of DO InRef in all LN0 of the SCD using matching ExtRef information.
598+
*
599+
* @param scd SCL file for which DOs InRef should be updated with matching ExtRef information
600+
* @return SclReport Object that contain SCL file and set of errors
601+
*/
602+
public static SclReport updateDoInRef(SCL scd) {
603+
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
604+
List<SclReportItem> sclReportItems = sclRootAdapter.streamIEDAdapters()
605+
.flatMap(IEDAdapter::streamLDeviceAdapters)
606+
.map(LDeviceAdapter::getLN0Adapter)
607+
.map(LN0Adapter::updateDoInRef)
608+
.flatMap(List::stream)
609+
.toList();
610+
return new SclReport(sclRootAdapter, sclReportItems);
611+
}
593612
}

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

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,24 @@
4343
* @see org.lfenergy.compas.scl2007b4.model.TDAI
4444
* @see <a href="https://github.com/com-pas/compas-sct/issues/70" target="_blank">Issue !70</a>
4545
*/
46-
public abstract class AbstractDAIAdapter<P extends SclElementAdapter> extends SclElementAdapter<P, TDAI> implements IDataAdapter{
46+
public abstract class AbstractDAIAdapter<P extends SclElementAdapter> extends SclElementAdapter<P, TDAI> implements IDataAdapter {
4747

4848
/**
4949
* Constructor
50+
*
5051
* @param parentAdapter Parent container reference
51-
* @param currentElem Current reference
52+
* @param currentElem Current reference
5253
*/
5354
protected AbstractDAIAdapter(P parentAdapter, TDAI currentElem) {
5455
super(parentAdapter, currentElem);
5556
}
5657

5758
/**
5859
* Gets SDI from DAI by name
60+
*
5961
* @param sName SDI name
62+
* @param <S> expected class type
6063
* @return <em>IDataAdapter</em> related object
61-
* @param <S> expected class type
6264
* @throws ScdException throws when specified SDI not present in DAI
6365
*/
6466
public <S extends IDataAdapter> S getStructuredDataAdapterByName(String sName) throws ScdException {
@@ -67,33 +69,36 @@ public <S extends IDataAdapter> S getStructuredDataAdapterByName(String sName) t
6769

6870
/**
6971
* Gets DataAdapter by DAI
72+
*
7073
* @param sName DAI name
74+
* @param <S> expected class type
7175
* @return <em>IDataAdapter</em> related object
72-
* @param <S> expected class type
7376
* @throws ScdException throws when specified DAI unknown
7477
*/
75-
public <S extends IDataAdapter> S getDataAdapterByName(String sName) throws ScdException {
78+
public <S extends IDataAdapter> S getDataAdapterByName(String sName) throws ScdException {
7679
throw new UnsupportedOperationException("DAI doesn't have any DAI");
7780
}
7881

7982
/**
8083
* Sets <em>ValImport</em> value
84+
*
8185
* @param b value
8286
*/
83-
public void setValImport(boolean b){
87+
public void setValImport(boolean b) {
8488
currentElem.setValImport(b);
8589
}
8690

8791
/**
8892
* Cheks <em>ValImport</em> boolean value
93+
*
8994
* @return <em>Boolean</em> value of <em>ValImport</em> if define or <em>null</em>
9095
*/
91-
public Boolean isValImport(){
96+
public Boolean isValImport() {
9297
return currentElem.isSetValImport() ? currentElem.isValImport() : null;
9398
}
9499

95100
public AbstractDAIAdapter<? extends SclElementAdapter> update(Map<Long, String> daiValues) throws ScdException {
96-
if(daiValues.size() > 1 && daiValues.containsKey(0L)){
101+
if (daiValues.size() > 1 && daiValues.containsKey(0L)) {
97102
update(0L, daiValues.get(0L)); // to be refined (with COMPAS TEAMS)
98103
} else {
99104
for (Map.Entry<Long, String> mapVal : daiValues.entrySet()) {
@@ -105,23 +110,24 @@ public AbstractDAIAdapter<? extends SclElementAdapter> update(Map<Long, String>
105110

106111
/**
107112
* Updates DAI SGroup value
113+
*
108114
* @param sGroup SGroup to update
109-
* @param val value
115+
* @param val value
110116
* @throws ScdException throws when DAI for which SGroup should be updated is not updatable
111117
*/
112118
public void update(Long sGroup, String val) throws ScdException {
113-
if(currentElem.isSetValImport() && !currentElem.isValImport()){
119+
if (currentElem.isSetValImport() && !currentElem.isValImport()) {
114120
String msg = String.format(
115-
"DAI(%s) cannot be updated : valImport(false)",currentElem.getName()
121+
"DAI(%s) cannot be updated : valImport(false)", currentElem.getName()
116122
);
117123
throw new ScdException(msg);
118124
}
119125
Stream<TVal> tValStream = currentElem.getVal().stream();
120126
if (sGroup != null && sGroup != 0) {
121127
Optional<TVal> tVal = tValStream.filter(tValElem -> tValElem.isSetSGroup() &&
122-
sGroup.equals(tValElem.getSGroup()))
128+
sGroup.equals(tValElem.getSGroup()))
123129
.findFirst();
124-
if(tVal.isPresent()){
130+
if (tVal.isPresent()) {
125131
tVal.get().setValue(val);
126132
} else {
127133
TVal newTVal = new TVal();
@@ -130,22 +136,26 @@ public void update(Long sGroup, String val) throws ScdException {
130136
currentElem.getVal().add(newTVal);
131137
}
132138
} else {
133-
Optional<TVal> tVal = tValStream.findFirst();
134-
if(tVal.isPresent()){
135-
tVal.get().setValue(val);
136-
}else {
137-
TVal newTVal = new TVal();
138-
newTVal.setValue(val);
139-
currentElem.getVal().add(newTVal);
140-
}
139+
updateVal(val);
141140
}
142141
}
143142

144-
public IDataAdapter addDAI(String name){
143+
public void updateVal(String s) {
144+
currentElem.getVal().stream().findFirst()
145+
.orElseGet(
146+
() -> {
147+
TVal newTVal = new TVal();
148+
currentElem.getVal().add(newTVal);
149+
return newTVal;
150+
})
151+
.setValue(s);
152+
}
153+
154+
public IDataAdapter addDAI(String name) {
145155
throw new UnsupportedOperationException("DAI cannot contain an SDI");
146156
}
147157

148-
public IDataAdapter addSDOI(String sdoName){
158+
public IDataAdapter addSDOI(String sdoName) {
149159
throw new UnsupportedOperationException("DAI cannot contain an DAI");
150160
}
151161
}

0 commit comments

Comments
 (0)