Skip to content

Commit df8ff61

Browse files
Merge pull request #303 from com-pas/develop
Merge develop into main
2 parents 34f9263 + 3da0cc2 commit df8ff61

File tree

12 files changed

+234
-106
lines changed

12 files changed

+234
-106
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@
88
import org.lfenergy.compas.sct.commons.dto.*;
99
import org.lfenergy.compas.sct.commons.exception.ScdException;
1010
import org.lfenergy.compas.sct.commons.scl.ied.*;
11-
import org.lfenergy.compas.sct.commons.util.ControlBlockEnum;
12-
import org.lfenergy.compas.sct.commons.util.ILDEPFSettings;
11+
import org.lfenergy.compas.sct.commons.util.*;
1312
import org.lfenergy.compas.scl2007b4.model.SCL;
1413
import org.lfenergy.compas.scl2007b4.model.TCompasICDHeader;
1514
import org.lfenergy.compas.scl2007b4.model.TExtRef;
1615
import org.lfenergy.compas.scl2007b4.model.TIED;
1716
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings;
1817
import org.lfenergy.compas.sct.commons.dto.SclReport;
1918
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
20-
import org.lfenergy.compas.sct.commons.util.LDeviceStatus;
21-
import org.lfenergy.compas.sct.commons.util.PrivateEnum;
22-
import org.lfenergy.compas.sct.commons.util.Utils;
2319

2420
import java.util.*;
2521
import java.util.function.Function;
@@ -325,7 +321,7 @@ private static Optional<SclReportItem> updateVal(AbstractLNAdapter<?> lnAdapter,
325321
case DU_DA_NAME -> setting.getChannelShortLabel();
326322
case SETVAL_DA_NAME ->
327323
LN_PREFIX_B.equals(lnAdapter.getPrefix()) || LN_PREFIX_A.equals(lnAdapter.getPrefix()) ? setting.getChannelLevModQ() : setting.getChannelLevMod();
328-
case STVAL_DA_NAME -> LDeviceStatus.ON;
324+
case STVAL_DA_NAME -> LdeviceStatus.ON.getValue();
329325
case SETSRCREF_DA_NAME -> computeDaiValue(lnAdapter, extRef, setting.getDaName());
330326
default -> null;
331327
};

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import lombok.Setter;
99
import org.apache.commons.lang3.tuple.Pair;
1010
import org.lfenergy.compas.scl2007b4.model.TCompasLDeviceStatus;
11-
import org.lfenergy.compas.sct.commons.util.LDeviceStatus;
11+
import org.lfenergy.compas.sct.commons.util.LdeviceStatus;
1212

1313
import java.util.List;
1414
import java.util.Set;
@@ -38,15 +38,15 @@ public LDeviceActivation(List<Pair<String, String>> iedNameLdInstList) {
3838
* @param enumValues enum values
3939
*/
4040
public void checkLDeviceActivationStatus(String iedName, String ldInst, TCompasLDeviceStatus compasLDeviceStatus, Set<String> enumValues) {
41-
if (!enumValues.contains(LDeviceStatus.ON) && !enumValues.contains(LDeviceStatus.OFF)) {
41+
if (!enumValues.contains(LdeviceStatus.ON.getValue()) && !enumValues.contains(LdeviceStatus.OFF.getValue())) {
4242
errorMessage = "The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.";
4343
}
44-
if (!enumValues.contains(LDeviceStatus.ON) && enumValues.contains(LDeviceStatus.OFF)) {
44+
if (!enumValues.contains(LdeviceStatus.ON.getValue()) && enumValues.contains(LdeviceStatus.OFF.getValue())) {
4545
if (isDeclaredInSubstation(iedName, ldInst)) {
4646
errorMessage = "The LDevice cannot be set to 'on' but has been selected into SSD.";
4747
} else {
4848
isUpdatable = true;
49-
newVal = LDeviceStatus.OFF;
49+
newVal = LdeviceStatus.OFF.getValue();
5050
}
5151
}
5252
if(compasLDeviceStatus.equals(TCompasLDeviceStatus.ACTIVE) ||
@@ -65,20 +65,20 @@ public void checkLDeviceActivationStatus(String iedName, String ldInst, TCompasL
6565
* @param enumValues enum values
6666
*/
6767
private void checkAuthorisationToActivateLDevice(String iedName, String ldInst, Set<String> enumValues) {
68-
if (!enumValues.contains(LDeviceStatus.OFF) && enumValues.contains(LDeviceStatus.ON)) {
68+
if (!enumValues.contains(LdeviceStatus.OFF.getValue()) && enumValues.contains(LdeviceStatus.ON.getValue())) {
6969
if (isDeclaredInSubstation(iedName, ldInst)) {
7070
isUpdatable = true;
71-
newVal = LDeviceStatus.ON;
71+
newVal = LdeviceStatus.ON.getValue();
7272
} else {
7373
errorMessage = "The LDevice cannot be set to 'off' but has not been selected into SSD.";
7474
}
7575
}
76-
if (enumValues.contains(LDeviceStatus.ON) && enumValues.contains(LDeviceStatus.OFF)) {
76+
if (enumValues.contains(LdeviceStatus.ON.getValue()) && enumValues.contains(LdeviceStatus.OFF.getValue())) {
7777
isUpdatable = true;
7878
if (isDeclaredInSubstation(iedName, ldInst)) {
79-
newVal = LDeviceStatus.ON;
79+
newVal = LdeviceStatus.ON.getValue();
8080
} else {
81-
newVal = LDeviceStatus.OFF;
81+
newVal = LdeviceStatus.OFF.getValue();
8282
}
8383
}
8484

@@ -91,19 +91,19 @@ private void checkAuthorisationToActivateLDevice(String iedName, String ldInst,
9191
* @param enumValues enum values
9292
*/
9393
private void checkAuthorisationToDeactivateLDevice(String iedName, String ldInst, Set<String> enumValues) {
94-
if (!enumValues.contains(LDeviceStatus.OFF) && enumValues.contains(LDeviceStatus.ON)) {
94+
if (!enumValues.contains(LdeviceStatus.OFF.getValue()) && enumValues.contains(LdeviceStatus.ON.getValue())) {
9595
if (isDeclaredInSubstation(iedName, ldInst)) {
9696
errorMessage = "The LDevice is not qualified into STD but has been selected into SSD.";
9797
} else {
9898
errorMessage = "The LDevice cannot be set to 'off' but has not been selected into SSD.";
9999
}
100100
}
101-
if (enumValues.contains(LDeviceStatus.ON) && enumValues.contains(LDeviceStatus.OFF)) {
101+
if (enumValues.contains(LdeviceStatus.ON.getValue()) && enumValues.contains(LdeviceStatus.OFF.getValue())) {
102102
if (isDeclaredInSubstation(iedName, ldInst)) {
103103
errorMessage = "The LDevice is not qualified into STD but has been selected into SSD.";
104104
} else {
105105
isUpdatable = true;
106-
newVal = LDeviceStatus.OFF;
106+
newVal = LdeviceStatus.OFF.getValue();
107107
}
108108
}
109109
}

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

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
1818
import org.lfenergy.compas.sct.commons.util.ControlBlockEnum;
1919
import org.lfenergy.compas.sct.commons.util.FcdaCandidates;
20+
import org.lfenergy.compas.sct.commons.util.LdeviceStatus;
2021
import org.lfenergy.compas.sct.commons.util.Utils;
2122

2223
import java.util.*;
2324
import java.util.function.Predicate;
2425

2526
import static org.lfenergy.compas.sct.commons.util.CommonConstants.*;
26-
import static org.lfenergy.compas.sct.commons.util.LDeviceStatus.OFF;
27-
import static org.lfenergy.compas.sct.commons.util.LDeviceStatus.ON;
2827

2928
/**
3029
* A representation of the model object
@@ -41,17 +40,16 @@ public class InputsAdapter extends SclElementAdapter<LN0Adapter, TInputs> {
4140
private static final String MESSAGE_NO_MATCHING_COMPAS_FLOW = "The signal ExtRef has no matching compas:Flow Private";
4241
private static final String MESSAGE_TOO_MANY_MATCHING_COMPAS_FLOWS = "The signal ExtRef has more than one matching compas:Flow Private";
4342
private static final String MESSAGE_SOURCE_LDEVICE_NOT_FOUND = "The signal ExtRef ExtRefldinst does not match any " +
44-
"LDevice with same inst attribute in source IED %s";
43+
"LDevice with same inst attribute in source IED %s";
4544
private static final String MESSAGE_SOURCE_LN_NOT_FOUND = "The signal ExtRef lninst, doName or daName does not match any " +
46-
"source in LDevice %s";
45+
"source in LDevice %s";
4746
private static final String MESSAGE_SERVICE_TYPE_MISSING = "The signal ExtRef is missing ServiceType attribute";
4847
private static final String MESSAGE_INVALID_SERVICE_TYPE = "The signal ExtRef ServiceType attribute is unexpected : %s";
4948
private static final String MESSAGE_IED_MISSING_COMPAS_BAY_UUID = "IED is missing Private/compas:Bay@UUID attribute";
5049
private static final String MESSAGE_EXTREF_DESC_MALFORMED = "ExtRef.serviceType=Report but ExtRef.desc attribute is malformed";
5150
private static final String MESSAGE_LDEVICE_STATUS_UNDEFINED = "The LDevice status is undefined";
52-
private static final String MESSAGE_LDEVICE_STATUS_NEITHER_ON_NOR_OFF = "The LDevice status is neither \"on\" nor \"off\"";
5351
private static final String MESSAGE_EXTREF_IEDNAME_DOES_NOT_MATCH_ANY_SYSTEM_VERSION_UUID = "The signal ExtRef iedName does not match any " +
54-
"IED/Private/compas:ICDHeader@ICDSystemVersionUUID";
52+
"IED/Private/compas:ICDHeader@ICDSystemVersionUUID";
5553
private static final String MESSAGE_SOURCE_LDEVICE_STATUS_UNDEFINED = "The signal ExtRef source LDevice %s status is undefined";
5654
private static final String MESSAGE_SOURCE_LDEVICE_STATUS_NEITHER_ON_NOR_OFF = "The signal ExtRef source LDevice %s status is neither \"on\" nor \"off\"";
5755
private static final String MESSAGE_SOURCE_LDEVICE_STATUS_OFF = "The signal ExtRef source LDevice %s status is off";
@@ -97,33 +95,36 @@ public List<SclReportItem> updateAllExtRefIedNames(Map<String, IEDAdapter> icdSy
9795
if (optionalLDeviceStatus.isEmpty()) {
9896
return List.of(getLDeviceAdapter().buildFatalReportItem(MESSAGE_LDEVICE_STATUS_UNDEFINED));
9997
}
100-
String lDeviceStatus = optionalLDeviceStatus.get();
101-
return switch (lDeviceStatus) {
102-
case ON -> getExtRefs().stream()
103-
.filter(tExtRef -> StringUtils.isNotBlank(tExtRef.getIedName()) && StringUtils.isNotBlank(tExtRef.getDesc()))
104-
.map(extRef ->
105-
updateExtRefIedName(extRef, icdSystemVersionToIed.get(extRef.getIedName())))
106-
.flatMap(Optional::stream)
107-
.toList();
108-
case OFF -> {
109-
getExtRefs().forEach(this::clearBinding);
110-
yield Collections.emptyList();
111-
}
112-
default -> List.of(getLDeviceAdapter().buildFatalReportItem(MESSAGE_LDEVICE_STATUS_NEITHER_ON_NOR_OFF));
113-
};
98+
try {
99+
LdeviceStatus lDeviceStatus = LdeviceStatus.fromValue(optionalLDeviceStatus.get());
100+
return switch (lDeviceStatus) {
101+
case ON -> getExtRefs().stream()
102+
.filter(tExtRef -> StringUtils.isNotBlank(tExtRef.getIedName()) && StringUtils.isNotBlank(tExtRef.getDesc()))
103+
.map(extRef ->
104+
updateExtRefIedName(extRef, icdSystemVersionToIed.get(extRef.getIedName())))
105+
.flatMap(Optional::stream)
106+
.toList();
107+
case OFF -> {
108+
getExtRefs().forEach(this::clearBinding);
109+
yield Collections.emptyList();
110+
}
111+
};
112+
} catch (IllegalArgumentException e) {
113+
return List.of(getLDeviceAdapter().buildFatalReportItem(e.getMessage()));
114+
}
114115
}
115116

116117
/**
117118
* Find matching CompasFlow private and set ExtRef iedName accordingly
118119
*
119-
* @param extRef extRef whose iedName will be updated
120+
* @param extRef extRef whose iedName will be updated
120121
* @return Error if ExtRef could not be updated
121122
*/
122123
private Optional<SclReportItem> updateExtRefIedName(TExtRef extRef, IEDAdapter sourceIed) {
123124
List<TCompasFlow> matchingCompasFlows = getMatchingCompasFlows(extRef);
124125
if (!singleMatch(matchingCompasFlows)) {
125126
return fatalReportItem(extRef,
126-
matchingCompasFlows.isEmpty() ? MESSAGE_NO_MATCHING_COMPAS_FLOW : MESSAGE_TOO_MANY_MATCHING_COMPAS_FLOWS);
127+
matchingCompasFlows.isEmpty() ? MESSAGE_NO_MATCHING_COMPAS_FLOW : MESSAGE_TOO_MANY_MATCHING_COMPAS_FLOWS);
127128
}
128129
TCompasFlow compasFlow = matchingCompasFlows.get(0);
129130
if (compasFlow.getFlowStatus() == TCompasFlowStatus.INACTIVE) {
@@ -136,7 +137,7 @@ private Optional<SclReportItem> updateExtRefIedName(TExtRef extRef, IEDAdapter s
136137
return sourceValidationError;
137138
}
138139
String sourceIedName = PrivateService.extractCompasPrivate(sourceIed.getCurrentElem(), TCompasICDHeader.class)
139-
.map(TCompasICDHeader::getIEDName).orElse("");
140+
.map(TCompasICDHeader::getIEDName).orElse("");
140141
extRef.setIedName(sourceIedName);
141142
compasFlow.setExtRefiedName(sourceIedName);
142143
log.debug(String.format("extRef.desc=%s, iedName=%s%n", extRef.getDesc(), sourceIedName));
@@ -170,17 +171,19 @@ private Optional<SclReportItem> validateExtRefSource(TExtRef extRef, IEDAdapter
170171
Optional<String> optionalSourceLDeviceStatus = sourceLDevice.getLDeviceStatus();
171172
if (optionalSourceLDeviceStatus.isEmpty()) {
172173
return fatalReportItem(extRef, String.format(MESSAGE_SOURCE_LDEVICE_STATUS_UNDEFINED,
173-
sourceLDevice.getXPath()));
174-
}
175-
return optionalSourceLDeviceStatus.map(sourceLDeviceStatus ->
176-
switch (sourceLDeviceStatus) {
177-
case OFF -> SclReportItem.warning(extRefXPath(extRef.getDesc()), String.format(MESSAGE_SOURCE_LDEVICE_STATUS_OFF,
178174
sourceLDevice.getXPath()));
179-
case ON -> null;
180-
default -> SclReportItem.fatal(extRefXPath(extRef.getDesc()),
181-
String.format(MESSAGE_SOURCE_LDEVICE_STATUS_NEITHER_ON_NOR_OFF,
182-
sourceLDevice.getXPath()));
183-
});
175+
}
176+
return optionalSourceLDeviceStatus.map(sourceLDeviceStatus -> {
177+
try {
178+
LdeviceStatus lDeviceStatus = LdeviceStatus.fromValue(sourceLDeviceStatus);
179+
return switch (lDeviceStatus) {
180+
case OFF -> SclReportItem.warning(extRefXPath(extRef.getDesc()), String.format(MESSAGE_SOURCE_LDEVICE_STATUS_OFF, sourceLDevice.getXPath()));
181+
case ON -> null;
182+
};
183+
} catch (IllegalArgumentException e) {
184+
return SclReportItem.fatal(extRefXPath(extRef.getDesc()), String.format(MESSAGE_SOURCE_LDEVICE_STATUS_NEITHER_ON_NOR_OFF, sourceLDevice.getXPath()));
185+
}
186+
});
184187
}
185188

186189
private boolean singleMatch(List<TCompasFlow> matchingCompasFlows) {
@@ -213,13 +216,13 @@ private Optional<SclReportItem> fatalReportItem(TExtRef extRef, String message)
213216

214217
private String extRefXPath(String extRefDesc) {
215218
return getXPath() + String.format("/ExtRef[%s]",
216-
Utils.xpathAttributeFilter("desc", extRefDesc));
219+
Utils.xpathAttributeFilter("desc", extRefDesc));
217220
}
218221

219222
/**
220223
* Find CompasFlows that match given ExtRef
221224
*
222-
* @param extRef extRef to match
225+
* @param extRef extRef to match
223226
* @return list of matching CompasFlows
224227
*/
225228
private List<TCompasFlow> getMatchingCompasFlows(TExtRef extRef) {
@@ -239,18 +242,18 @@ private List<TCompasFlow> getMatchingCompasFlows(TExtRef extRef) {
239242
private boolean isMatchingExtRef(TCompasFlow compasFlow, TExtRef extRef) {
240243
String extRefLnClass = extRef.isSetLnClass() ? extRef.getLnClass().get(0) : null;
241244
return Utils.equalsOrBothBlank(compasFlow.getDataStreamKey(), extRef.getDesc())
242-
&& Utils.equalsOrBothBlank(compasFlow.getExtRefiedName(), extRef.getIedName())
243-
&& Utils.equalsOrBothBlank(compasFlow.getExtRefldinst(), extRef.getLdInst())
244-
&& Utils.equalsOrBothBlank(compasFlow.getExtRefprefix(), extRef.getPrefix())
245-
&& Utils.equalsOrBothBlank(compasFlow.getExtReflnClass(), extRefLnClass)
246-
&& Utils.equalsOrBothBlank(compasFlow.getExtReflnInst(), extRef.getLnInst());
245+
&& Utils.equalsOrBothBlank(compasFlow.getExtRefiedName(), extRef.getIedName())
246+
&& Utils.equalsOrBothBlank(compasFlow.getExtRefldinst(), extRef.getLdInst())
247+
&& Utils.equalsOrBothBlank(compasFlow.getExtRefprefix(), extRef.getPrefix())
248+
&& Utils.equalsOrBothBlank(compasFlow.getExtReflnClass(), extRefLnClass)
249+
&& Utils.equalsOrBothBlank(compasFlow.getExtReflnInst(), extRef.getLnInst());
247250
}
248251

249252
private LDeviceAdapter getLDeviceAdapter() {
250253
return parentAdapter.getParentAdapter();
251254
}
252255

253-
private AbstractLNAdapter<?> getLNAdapter(){
256+
private AbstractLNAdapter<?> getLNAdapter() {
254257
return parentAdapter;
255258
}
256259

@@ -260,19 +263,19 @@ public List<SclReportItem> updateAllSourceDataSetsAndControlBlocks() {
260263
return List.of(getIedAdapter().buildFatalReportItem(MESSAGE_IED_MISSING_COMPAS_BAY_UUID));
261264
}
262265
return getExtRefs().stream()
263-
.filter(this::areBindingAttributesPresent)
264-
.filter(this::isExternalBound)
265-
.filter(this::matchingCompasFlowIsActiveOrUntested)
266-
.map(extRef -> updateSourceDataSetsAndControlBlocks(extRef, currentBayUuid))
267-
.flatMap(Optional::stream)
268-
.toList();
266+
.filter(this::areBindingAttributesPresent)
267+
.filter(this::isExternalBound)
268+
.filter(this::matchingCompasFlowIsActiveOrUntested)
269+
.map(extRef -> updateSourceDataSetsAndControlBlocks(extRef, currentBayUuid))
270+
.flatMap(Optional::stream)
271+
.toList();
269272
}
270273

271274
private boolean matchingCompasFlowIsActiveOrUntested(TExtRef extRef) {
272275
return getMatchingCompasFlows(extRef).stream().findFirst()
273-
.map(TCompasFlow::getFlowStatus)
274-
.filter(flowStatus -> flowStatus == TCompasFlowStatus.ACTIVE || flowStatus == TCompasFlowStatus.UNTESTED)
275-
.isPresent();
276+
.map(TCompasFlow::getFlowStatus)
277+
.filter(flowStatus -> flowStatus == TCompasFlowStatus.ACTIVE || flowStatus == TCompasFlowStatus.UNTESTED)
278+
.isPresent();
276279
}
277280

278281
private boolean isExternalBound(TExtRef tExtRef) {
@@ -281,10 +284,10 @@ private boolean isExternalBound(TExtRef tExtRef) {
281284

282285
private boolean areBindingAttributesPresent(TExtRef tExtRef) {
283286
return StringUtils.isNotBlank(tExtRef.getIedName())
284-
&& StringUtils.isNotBlank(tExtRef.getDesc())
285-
&& StringUtils.isNotBlank(tExtRef.getLdInst())
286-
&& tExtRef.getLnClass().stream().findFirst().filter(StringUtils::isNotBlank).isPresent()
287-
&& StringUtils.isNotBlank(tExtRef.getDoName());
287+
&& StringUtils.isNotBlank(tExtRef.getDesc())
288+
&& StringUtils.isNotBlank(tExtRef.getLdInst())
289+
&& tExtRef.getLnClass().stream().findFirst().filter(StringUtils::isNotBlank).isPresent()
290+
&& StringUtils.isNotBlank(tExtRef.getDoName());
288291
}
289292

290293
private Optional<SclReportItem> updateSourceDataSetsAndControlBlocks(TExtRef extRef, String targetBayUuid) {
@@ -297,8 +300,8 @@ private Optional<SclReportItem> updateSourceDataSetsAndControlBlocks(TExtRef ext
297300
}
298301
IEDAdapter sourceIed = optionalSrcIedAdapter.get();
299302
Optional<String> sourceIedBayUuid = sourceIed.getPrivateCompasBay()
300-
.map(TCompasBay::getUUID)
301-
.filter(StringUtils::isNotBlank);
303+
.map(TCompasBay::getUUID)
304+
.filter(StringUtils::isNotBlank);
302305
if (sourceIedBayUuid.isEmpty()) {
303306
return fatalReportItem(extRef, MESSAGE_SOURCE_IED_MISSING_COMPAS_BAY_UUID);
304307
}
@@ -342,9 +345,9 @@ private void createDataSetWithFCDA(TExtRef extRef, LDeviceAdapter sourceLDevice,
342345
String fcdaDaName = extRef.getServiceType() == TServiceType.REPORT ? null : sourceDa.getDaRef();
343346
String fcdaLnClass = extRef.getLnClass().stream().findFirst().orElse(null);
344347
dataSetAdapter.createFCDAIfNotExists(extRef.getLdInst(), extRef.getPrefix(), fcdaLnClass, extRef.getLnInst(),
345-
sourceDa.getDoRef(),
346-
fcdaDaName,
347-
sourceDa.getFc());
348+
sourceDa.getDoRef(),
349+
fcdaDaName,
350+
sourceDa.getFc());
348351
}
349352

350353
private void createControlBlockWithTarget(TExtRef extRef, LDeviceAdapter sourceLDevice, DataAttributeRef sourceDa, String cbName, String datSet) {

0 commit comments

Comments
 (0)