Skip to content

Commit adebd26

Browse files
authored
Merge pull request #265 from com-pas/develop
Merge develop into main
2 parents 2258b1a + 7c2bdcd commit adebd26

25 files changed

+1057
-657
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public interface ControlBlockNetworkSettings {
2424
* vlanPriority will be ignored when vlanId is null.
2525
*
2626
* @param controlBlockAdapter ControlBlock for which we want to configure the communication section
27-
* @return network settings : All fields are optional (meaning fields can be null).
28-
* When the return value itself is null, the communication section will not be configured for this ControlBlock.
27+
* @return network settings to use for configuring Communication section for this ControlBlock.
28+
* An error message can be provided (i.e. errorMessage not null) or a null settings, in order to avoid configuring the ControlBlock.
2929
*/
30-
Settings getNetworkSettings(ControlBlockAdapter controlBlockAdapter);
30+
SettingsOrError getNetworkSettings(ControlBlockAdapter controlBlockAdapter);
3131

3232
/**
3333
* Network settings for ControlBlock communication
@@ -40,6 +40,15 @@ public interface ControlBlockNetworkSettings {
4040
record Settings(Integer vlanId, Byte vlanPriority, TDurationInMilliSec minTime, TDurationInMilliSec maxTime) {
4141
}
4242

43+
/**
44+
* Network settings for ControlBlock communication or Error message
45+
*
46+
* @param settings Network settings for ControlBlock communication. Can be null when errorMessage is provided
47+
* @param errorMessage should be null if settings is provided
48+
*/
49+
record SettingsOrError(Settings settings, String errorMessage) {
50+
}
51+
4352
/**
4453
* NetworkRanges for GSEControl and SampledValueControl
4554
*

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.fasterxml.jackson.annotation.JsonIgnore;
88
import lombok.*;
99
import org.lfenergy.compas.scl2007b4.model.*;
10+
import org.lfenergy.compas.sct.commons.util.SclConstructorHelper;
1011

1112
import java.util.ArrayList;
1213
import java.util.List;
@@ -50,7 +51,7 @@ public class ResumedDataTemplate {
5051
private DaTypeName daName = new DaTypeName("");
5152

5253
/**
53-
* Copies sumarized DataTypeTemplate informations to another one
54+
* Copies summarized DataTypeTemplate information to another one
5455
* @param dtt input
5556
* @return Updated ResumedDataTemplate object
5657
*/
@@ -89,7 +90,7 @@ public String getObjRef(String iedName, String ldInst){
8990
}
9091

9192
/**
92-
* Gets LNode reference informations
93+
* Gets LNode reference information
9394
* @return String LNode information concatenated
9495
*/
9596
@JsonIgnore
@@ -335,10 +336,13 @@ public boolean isValImport(){
335336
return daName.isValImport();
336337
}
337338

339+
/**
340+
* Set Val of DA
341+
* @param daiValue daiValue to set
342+
* @return this
343+
*/
338344
public ResumedDataTemplate setVal(String daiValue) {
339-
TVal newDaiVal = new TVal();
340-
newDaiVal.setValue(daiValue);
341-
this.setDaiValues(List.of(newDaiVal));
345+
this.setDaiValues(List.of(SclConstructorHelper.newVal(daiValue)));
342346
return this;
343347
}
344348

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.lfenergy.compas.scl2007b4.model.TCompasICDHeader;
1111
import org.lfenergy.compas.scl2007b4.model.TIED;
1212
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings;
13-
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.Settings;
1413
import org.lfenergy.compas.sct.commons.dto.SclReport;
1514
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
1615
import org.lfenergy.compas.sct.commons.exception.ScdException;
@@ -27,8 +26,7 @@
2726
import java.util.stream.Collectors;
2827
import java.util.stream.Stream;
2928

30-
import static org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.NetworkRanges;
31-
import static org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.RangesPerCbType;
29+
import static org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.*;
3230

3331
@UtilityClass
3432
public class ExtRefService {
@@ -202,8 +200,12 @@ private static List<SclReportItem> configureNetworkForControlBlocks(SCL scd, Con
202200
}
203201

204202
private static Optional<SclReportItem> configureControlBlockNetwork(ControlBlockNetworkSettings controlBlockNetworkSettings, PrimitiveIterator.OfLong appIdIterator, Iterator<String> macAddressIterator, ControlBlockAdapter controlBlockAdapter) {
205-
Settings settings = controlBlockNetworkSettings.getNetworkSettings(controlBlockAdapter);
206-
203+
SettingsOrError settingsOrError = controlBlockNetworkSettings.getNetworkSettings(controlBlockAdapter);
204+
if (settingsOrError.errorMessage() != null){
205+
return Optional.of(controlBlockAdapter.buildFatalReportItem(
206+
"Cannot configure network for this ControlBlock because: " + settingsOrError.errorMessage()));
207+
}
208+
Settings settings = settingsOrError.settings();
207209
if (settings == null) {
208210
return Optional.of(controlBlockAdapter.buildFatalReportItem(
209211
"Cannot configure network for this ControlBlock because no settings was provided"));

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

Lines changed: 17 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,23 @@
77
import org.lfenergy.compas.scl2007b4.model.TDAI;
88
import org.lfenergy.compas.scl2007b4.model.TDOI;
99
import org.lfenergy.compas.scl2007b4.model.TPrivate;
10-
import org.lfenergy.compas.scl2007b4.model.TVal;
1110
import org.lfenergy.compas.sct.commons.exception.ScdException;
1211
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
1312
import org.lfenergy.compas.sct.commons.util.CommonConstants;
1413

1514
import java.util.Map;
1615

16+
import static org.lfenergy.compas.sct.commons.util.SclConstructorHelper.newVal;
17+
1718
/**
1819
* A representation of the model object
1920
* <em><b>{@link org.lfenergy.compas.sct.commons.scl.ied.AbstractDAIAdapter AbstractDAIAdapter}</b></em>.
2021
* <p>
2122
* The following features are supported:
2223
* </p>
2324
* <ol>
24-
* <li>Adapter</li>
25-
* <ul>
26-
* <li>{@link AbstractDAIAdapter#getStructuredDataAdapterByName(String) <em>Returns the value of the <b>Child Adapter </b>object reference</em>}</li>
27-
* <li>{@link AbstractDAIAdapter#getDataAdapterByName(String) <em>Returns the value of the <b>Child Adapter </b>object reference By Name</em>}</li>
28-
* </ul>
2925
* <li>Principal functions</li>
3026
* <ul>
31-
* <li>{@link AbstractDAIAdapter#addDAI(String) <em>Add <b>TDAI </b> under this object</em>}</li>
32-
* <li>{@link AbstractDAIAdapter#addSDOI(String) <em>Add <b>TSDI </b> under this object</em>}</li>
3327
* <li>{@link AbstractDAIAdapter#update(Long, String) <em>Update <b>TDAI</b> (sGroup, value)</em>}</li>
3428
* <li>{@link AbstractDAIAdapter#update(Map) <em>Update Many <b>TDAI</b> (sGroup, value)</em>}</li>
3529
* <li>{@link AbstractDAIAdapter#addPrivate(TPrivate) <em>Add <b>TPrivate </b> under this object</em>}</li>
@@ -52,30 +46,6 @@ protected AbstractDAIAdapter(P parentAdapter, TDAI currentElem) {
5246
super(parentAdapter, currentElem);
5347
}
5448

55-
/**
56-
* Gets SDI from DAI by name
57-
*
58-
* @param sName SDI name
59-
* @param <S> expected class type
60-
* @return <em>IDataAdapter</em> related object
61-
* @throws ScdException throws when specified SDI not present in DAI
62-
*/
63-
public <S extends IDataAdapter> S getStructuredDataAdapterByName(String sName) throws ScdException {
64-
throw new UnsupportedOperationException("DAI doesn't have any SDI");
65-
}
66-
67-
/**
68-
* Gets DataAdapter by DAI
69-
*
70-
* @param sName DAI name
71-
* @param <S> expected class type
72-
* @return <em>IDataAdapter</em> related object
73-
* @throws ScdException throws when specified DAI unknown
74-
*/
75-
public <S extends IDataAdapter> S getDataAdapterByName(String sName) throws ScdException {
76-
throw new UnsupportedOperationException("DAI doesn't have any DAI");
77-
}
78-
7949
/**
8050
* Sets <em>ValImport</em> value
8151
*
@@ -104,7 +74,7 @@ public AbstractDAIAdapter<? extends SclElementAdapter> update(Map<Long, String>
10474
}
10575

10676
/**
107-
* Updates DAI SGroup value
77+
* Updates DAI SGroup value. This method checks if DAI is updatable.
10878
*
10979
* @param sGroup SGroup to update
11080
* @param val value
@@ -118,42 +88,31 @@ public void update(Long sGroup, String val) throws ScdException {
11888
throw new ScdException(msg);
11989
}
12090
if (sGroup != null && sGroup != 0) {
121-
updateSGroupVal(sGroup, val);
91+
setSGroupVal(sGroup, val);
12292
} else {
123-
updateVal(val);
93+
setVal(val);
12494
}
12595
}
12696

127-
private void updateSGroupVal(Long sGroup, String val) {
97+
private void setSGroupVal(Long sGroup, String value) {
12898
currentElem.getVal().stream()
12999
.filter(tValElem -> tValElem.isSetSGroup() && sGroup.equals(tValElem.getSGroup()))
130100
.findFirst()
131-
.orElseGet(
132-
() -> {
133-
TVal newTVal = new TVal();
134-
newTVal.setSGroup(sGroup);
135-
currentElem.getVal().add(newTVal);
136-
return newTVal;
137-
})
138-
.setValue(val);
101+
.ifPresentOrElse(
102+
tVal -> tVal.setValue(value),
103+
() -> currentElem.getVal().add(newVal(value, sGroup)));
139104
}
140105

141-
public void updateVal(String s) {
106+
/**
107+
* Set Val (without sGroup) for DAI without checking if DAI is updatable
108+
* @param value new value
109+
*/
110+
public void setVal(String value) {
142111
currentElem.getVal().stream().findFirst()
143-
.orElseGet(
144-
() -> {
145-
TVal newTVal = new TVal();
146-
currentElem.getVal().add(newTVal);
147-
return newTVal;
148-
})
149-
.setValue(s);
150-
}
112+
.ifPresentOrElse(
113+
tVal -> tVal.setValue(value),
114+
() -> currentElem.getVal().add(newVal(value)));
151115

152-
public IDataAdapter addDAI(String name) {
153-
throw new UnsupportedOperationException("DAI cannot contain an SDI");
154116
}
155117

156-
public IDataAdapter addSDOI(String sdoName) {
157-
throw new UnsupportedOperationException("DAI cannot contain an DAI");
158-
}
159118
}

0 commit comments

Comments
 (0)