Skip to content

Commit ccf47a3

Browse files
committed
feat(#541): RSR-1368 Remove empty prefix
Signed-off-by: massifben <[email protected]>
1 parent 6baa47b commit ccf47a3

File tree

5 files changed

+58
-62
lines changed

5 files changed

+58
-62
lines changed

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

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@
77
import lombok.Getter;
88
import lombok.RequiredArgsConstructor;
99
import lombok.extern.slf4j.Slf4j;
10+
import org.apache.commons.lang3.StringUtils;
1011
import org.lfenergy.compas.scl2007b4.model.*;
1112
import org.lfenergy.compas.sct.commons.api.ExtRefEditor;
1213
import org.lfenergy.compas.sct.commons.api.LnEditor;
1314
import org.lfenergy.compas.sct.commons.domain.*;
1415
import org.lfenergy.compas.sct.commons.dto.*;
1516
import org.lfenergy.compas.sct.commons.exception.ScdException;
16-
import org.lfenergy.compas.sct.commons.model.epf.EPF;
17-
import org.lfenergy.compas.sct.commons.model.epf.TCBScopeType;
18-
import org.lfenergy.compas.sct.commons.model.epf.TChannel;
19-
import org.lfenergy.compas.sct.commons.model.epf.TChannelType;
20-
import org.lfenergy.compas.sct.commons.model.epf.TChannelLevMod;
17+
import org.lfenergy.compas.sct.commons.model.epf.*;
2118
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
2219
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;
2320
import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter;
@@ -65,9 +62,9 @@ public class ExtRefEditorService implements ExtRefEditor {
6562
* 4. Active LNode source object that should match the provided parameters<br/>
6663
* 5. Valid DataTypeTemplate Object hierarchy that should match the DO/DA/BDA parameters<br/>
6764
*
68-
* @param scl SCL object
69-
* @param compasBay TCompasBay represent Bay Private
70-
* @param channel TChannel represent parameters
65+
* @param scl SCL object
66+
* @param compasBay TCompasBay represent Bay Private
67+
* @param channel TChannel represent parameters
7168
* @return the IED sources matching the LDEPF parameters
7269
*/
7370
private List<TIED> getIedSources(SCL scl, TCompasBay compasBay, TChannel channel) {
@@ -77,8 +74,8 @@ private List<TIED> getIedSources(SCL scl, TCompasBay compasBay, TChannel channel
7774
Optional<TCompasBay> tCompasBay = PrivateUtils.extractCompasPrivate(tied, TCompasBay.class);
7875
return (channel.getBayScope().equals(TCBScopeType.BAY_EXTERNAL)
7976
&& tCompasBay.stream().noneMatch(bay -> bay.getUUID().equals(compasBay.getUUID())))
80-
|| (channel.getBayScope().equals(TCBScopeType.BAY_INTERNAL)
81-
&& tCompasBay.stream().anyMatch(bay -> bay.getUUID().equals(compasBay.getUUID())));
77+
|| (channel.getBayScope().equals(TCBScopeType.BAY_INTERNAL)
78+
&& tCompasBay.stream().anyMatch(bay -> bay.getUUID().equals(compasBay.getUUID())));
8279
}).filter(tied -> doesIcdHeaderMatchLDEPFChannel(tied, channel))
8380
.filter(tied -> ldeviceService.findLdevice(tied, channel.getLDInst())
8481
.filter(tlDevice -> PrivateUtils.extractStringPrivate(tlDevice.getLN0(), COMPAS_LNODE_STATUS).map(status -> status.equals(ActiveStatus.ON.getValue())).orElse(false))
@@ -121,36 +118,36 @@ private List<ExtRefInfo.ExtRefWithBayReference> getExtRefWithBayReferenceInLDEPF
121118
*/
122119
private static Boolean doesExtRefMatchLDEPFChannel(TExtRef extRef, TChannel tChannel) {
123120
Boolean doesExtRefDescMatchAnalogChannel = tChannel.getChannelType().equals(TChannelType.ANALOG)
124-
&& extRef.getDesc().startsWith("DYN_LDEPF_ANALOG CHANNEL " + tChannel.getChannelNum() + "_1_AnalogueValue")
125-
&& extRef.getDesc().endsWith("_" + tChannel.getDAName() + "_1");
121+
&& extRef.getDesc().startsWith("DYN_LDEPF_ANALOG CHANNEL " + tChannel.getChannelNum() + "_1_AnalogueValue")
122+
&& extRef.getDesc().endsWith("_" + tChannel.getDAName() + "_1");
126123
Boolean doesExtRefDescMatchDigitalChannel = tChannel.getChannelType().equals(TChannelType.DIGITAL)
127-
&& extRef.getDesc().startsWith("DYN_LDEPF_DIGITAL CHANNEL " + tChannel.getChannelNum() + "_1_BOOLEAN")
128-
&& extRef.getDesc().endsWith("_" + tChannel.getDAName() + "_1");
124+
&& extRef.getDesc().startsWith("DYN_LDEPF_DIGITAL CHANNEL " + tChannel.getChannelNum() + "_1_BOOLEAN")
125+
&& extRef.getDesc().endsWith("_" + tChannel.getDAName() + "_1");
129126
return extRef.isSetDesc() && (doesExtRefDescMatchAnalogChannel || doesExtRefDescMatchDigitalChannel)
130-
&& extRef.isSetPLN() && Utils.lnClassEquals(extRef.getPLN(), tChannel.getLNClass())
131-
&& extRef.isSetPDO() && extRef.getPDO().equals(tChannel.getDOName());
127+
&& extRef.isSetPLN() && Utils.lnClassEquals(extRef.getPLN(), tChannel.getLNClass())
128+
&& extRef.isSetPDO() && extRef.getPDO().equals(tChannel.getDOName());
132129
}
133130

134131
/**
135132
* Verify whether the IED satisfies the EPF channel for the private element `TCompasICDHeader`
136133
*
137-
* @param tied TIED
138-
* @param channel TChannel
134+
* @param tied TIED
135+
* @param channel TChannel
139136
* @return true if the TCompasICDHeader matches the EPF channel
140137
*/
141138
private static boolean doesIcdHeaderMatchLDEPFChannel(TIED tied, TChannel channel) {
142139
Optional<TCompasICDHeader> tCompasICDHeader = PrivateUtils.extractCompasPrivate(tied, TCompasICDHeader.class);
143140
return tCompasICDHeader.map(compasICDHeader -> compasICDHeader.getIEDType().value().equals(channel.getIEDType())
144-
&& compasICDHeader.getIEDredundancy().value().equals(channel.getIEDRedundancy().value())
145-
&& compasICDHeader.getIEDSystemVersioninstance().toString().equals(channel.getIEDSystemVersionInstance()))
141+
&& compasICDHeader.getIEDredundancy().value().equals(channel.getIEDRedundancy().value())
142+
&& compasICDHeader.getIEDSystemVersioninstance().toString().equals(channel.getIEDSystemVersionInstance()))
146143
.orElse(false);
147144
}
148145

149146
/**
150147
* Provides Active LN Object that satisfies the EPF channel attributes (lnClass, lnInst, prefix)
151148
*
152149
* @param tlDevice TLDevice
153-
* @param channel TChannel
150+
* @param channel TChannel
154151
* @return AnyLN object that matches the EPF channel
155152
*/
156153
private Optional<TAnyLN> getActiveLNSourceByLDEPFChannel(TLDevice tlDevice, TChannel channel) {
@@ -163,9 +160,9 @@ private Optional<TAnyLN> getActiveLNSourceByLDEPFChannel(TLDevice tlDevice, TCha
163160
/**
164161
* Verify whether the LN satisfies the EPF channel parameters for Data Type Template elements.
165162
*
166-
* @param dtt TDataTypeTemplates
167-
* @param tAnyLN TAnyLN
168-
* @param channel TChannel
163+
* @param dtt TDataTypeTemplates
164+
* @param tAnyLN TAnyLN
165+
* @param channel TChannel
169166
* @return true if the LN matches the EPF channel
170167
*/
171168
private boolean isValidDataTypeTemplate(TDataTypeTemplates dtt, TAnyLN tAnyLN, TChannel channel) {
@@ -185,7 +182,7 @@ private boolean isValidDataTypeTemplate(TDataTypeTemplates dtt, TAnyLN tAnyLN, T
185182
if (isNotBlank(channel.getSBDAName())) {
186183
bdaNames.add(channel.getSBDAName());
187184
}
188-
return dataTypeTemplatesService.findDoLinkedToDa(dtt, tAnyLN.getLnType(), new DoLinkedToDaFilter(doName, sdoNames, daName, bdaNames)).isPresent();
185+
return dataTypeTemplatesService.findDoLinkedToDa(dtt, tAnyLN.getLnType(), new DoLinkedToDaFilter(doName, sdoNames, daName, bdaNames)).isPresent();
189186
}
190187

191188
@Override
@@ -265,8 +262,8 @@ public List<SclReportItem> manageBindingForLDEPF(SCL scd, EPF epf) {
265262
} else {
266263
if (iedSources.size() > 1) {
267264
errorHandler.get().add(SclReportItem.warning(null, "There is more than one IED source to bind the signal " +
268-
"/IED@name=" + extRefBayRef.iedName() + "/LDevice@inst=LDEPF/LN0" +
269-
"/ExtRef@desc=" + extRefBayRef.extRef().getDesc()));
265+
"/IED@name=" + extRefBayRef.iedName() + "/LDevice@inst=LDEPF/LN0" +
266+
"/ExtRef@desc=" + extRefBayRef.extRef().getDesc()));
270267
}
271268
}
272269
}))));
@@ -291,19 +288,19 @@ public void epfPostProcessing(SCL scd) {
291288
Optional<TDAI> purPoseDAI = lnEditor.getDOAndDAInstances(ln0, doLinkedPurPose);
292289

293290
boolean isSetSrcRefExistAndEmpty = setSrcRefDAI.isPresent()
294-
&& (!setSrcRefDAI.get().isSetVal()
295-
|| (setSrcRefDAI.get().isSetVal()
296-
&& setSrcRefDAI.get().getVal().getFirst().getValue().isEmpty()));
291+
&& (!setSrcRefDAI.get().isSetVal()
292+
|| (setSrcRefDAI.get().isSetVal()
293+
&& setSrcRefDAI.get().getVal().getFirst().getValue().isEmpty()));
297294
boolean isPurposeExistAndMatchChannel = purPoseDAI.isPresent()
298-
&& purPoseDAI.get().isSetVal()
299-
&& (purPoseDAI.get().getVal().getFirst().getValue().startsWith("DYN_LDEPF_DIGITAL CHANNEL")
300-
|| purPoseDAI.get().getVal().getFirst().getValue().startsWith("DYN_LDEPF_ANALOG CHANNEL"));
301-
if(isSetSrcRefExistAndEmpty && isPurposeExistAndMatchChannel) {
295+
&& purPoseDAI.get().isSetVal()
296+
&& (purPoseDAI.get().getVal().getFirst().getValue().startsWith("DYN_LDEPF_DIGITAL CHANNEL")
297+
|| purPoseDAI.get().getVal().getFirst().getValue().startsWith("DYN_LDEPF_ANALOG CHANNEL"));
298+
if (isSetSrcRefExistAndEmpty && isPurposeExistAndMatchChannel) {
302299
DataObject dataObject = new DataObject();
303300
dataObject.setDoName(tdoi.getName());
304301
DataAttribute dataAttribute = new DataAttribute();
305302
dataAttribute.setDaName(SETSRCREF_DA_NAME);
306-
dataAttribute.setDaiValues(List.of(new DaVal(null, ldepfLdevice.getLdName()+"/"+LPHD0_PROXY)));
303+
dataAttribute.setDaiValues(List.of(new DaVal(null, ldepfLdevice.getLdName() + "/" + LPHD0_PROXY)));
307304
DoLinkedToDa doLinkedToDa = new DoLinkedToDa(dataObject, dataAttribute);
308305
lnEditor.updateOrCreateDOAndDAInstances(ln0, doLinkedToDa);
309306
}
@@ -316,9 +313,7 @@ private void updateLDEPFExtRefBinding(ExtRefInfo.ExtRefWithBayReference extRefWi
316313
tExtRef.setLdInst(setting.getLDInst());
317314
tExtRef.getLnClass().add(setting.getLNClass());
318315
tExtRef.setLnInst(setting.getLNInst());
319-
if (!isBlank(setting.getLNPrefix())) {
320-
tExtRef.setPrefix(setting.getLNPrefix());
321-
}
316+
tExtRef.setPrefix(StringUtils.trimToNull(setting.getLNPrefix()));
322317
String doName = isBlank(setting.getDOInst()) || setting.getDOInst().equals("0") ? setting.getDOName() : setting.getDOName() + setting.getDOInst();
323318
tExtRef.setDoName(doName);
324319
// This is true for External Binding
@@ -334,31 +329,31 @@ private void updateLDEPFExtRefBinding(ExtRefInfo.ExtRefWithBayReference extRefWi
334329
private String computeDaiValue(String lnPrefix, TExtRef extRef, String daName) {
335330
if (LN_PREFIX_B.equals(lnPrefix) || LN_PREFIX_A.equals(lnPrefix)) {
336331
return extRef.getIedName() +
337-
extRef.getLdInst() + "/" +
338-
trimToEmpty(extRef.getPrefix()) +
339-
extRef.getLnClass().getFirst() +
340-
trimToEmpty(extRef.getLnInst()) + "." +
341-
extRef.getDoName() + "." + Q_DA_NAME;
332+
extRef.getLdInst() + "/" +
333+
trimToEmpty(extRef.getPrefix()) +
334+
extRef.getLnClass().getFirst() +
335+
trimToEmpty(extRef.getLnInst()) + "." +
336+
extRef.getDoName() + "." + Q_DA_NAME;
342337
} else {
343338
return extRef.getIedName() +
344-
extRef.getLdInst() + "/" +
345-
trimToEmpty(extRef.getPrefix()) +
346-
extRef.getLnClass().getFirst() +
347-
trimToEmpty(extRef.getLnInst()) + "." +
348-
extRef.getDoName() + "." +
349-
daName;
339+
extRef.getLdInst() + "/" +
340+
trimToEmpty(extRef.getPrefix()) +
341+
extRef.getLnClass().getFirst() +
342+
trimToEmpty(extRef.getLnInst()) + "." +
343+
extRef.getDoName() + "." +
344+
daName;
350345
}
351346
}
352347

353-
private void updateLDEPFDos(TDataTypeTemplates dtt, TIED tied, TLDevice tlDevice, TExtRef tExtRef, TChannel setting) {
354-
// Digital
348+
private void updateLDEPFDos(TDataTypeTemplates dtt, TIED tied, TLDevice tlDevice, TExtRef tExtRef, TChannel setting) {
349+
// Digital
355350
if (setting.getChannelType().equals(TChannelType.DIGITAL)) {
356351
lnEditor.findLn(tlDevice, tAnyLN -> lnEditor.matchesLn(tAnyLN, LN_RBDR, setting.getChannelNum(), null))
357352
.ifPresent(tln -> updateDaiValue(dtt, tied, tlDevice, tln, tExtRef, setting));
358353
lnEditor.findLn(tlDevice, tAnyLN -> lnEditor.matchesLn(tAnyLN, LN_RBDR, setting.getChannelNum(), LN_PREFIX_B))
359354
.ifPresent(tln -> updateDaiValue(dtt, tied, tlDevice, tln, tExtRef, setting));
360355
}
361-
// Analog
356+
// Analog
362357
if (setting.getChannelType().equals(TChannelType.ANALOG)) {
363358
lnEditor.findLn(tlDevice, tAnyLN -> lnEditor.matchesLn(tAnyLN, LN_RADR, setting.getChannelNum(), null))
364359
.ifPresent(tln -> updateDaiValue(dtt, tied, tlDevice, tln, tExtRef, setting));
@@ -374,12 +369,12 @@ private void updateDaiValue(TDataTypeTemplates dtt, TIED tied, TLDevice tlDevice
374369

375370
private String getNewDaiValue(String daName, String lnPrefix, TExtRef extRef, TChannel setting) {
376371
return switch (daName) {
377-
case DU_DA_NAME -> setting.isSetChannelShortLabel() ? setting.getChannelShortLabel(): null;
372+
case DU_DA_NAME -> setting.isSetChannelShortLabel() ? setting.getChannelShortLabel() : null;
378373
case SETVAL_DA_NAME -> {
379-
if(LN_PREFIX_B.equals(lnPrefix) || LN_PREFIX_A.equals(lnPrefix)){
380-
yield setting.isSetChannelLevModQ() && !setting.getChannelLevModQ().equals(TChannelLevMod.NA) ? setting.getChannelLevModQ().value(): null;
374+
if (LN_PREFIX_B.equals(lnPrefix) || LN_PREFIX_A.equals(lnPrefix)) {
375+
yield setting.isSetChannelLevModQ() && !setting.getChannelLevModQ().equals(TChannelLevMod.NA) ? setting.getChannelLevModQ().value() : null;
381376
} else {
382-
yield setting.isSetChannelLevMod() && !setting.getChannelLevMod().equals(TChannelLevMod.NA) ? setting.getChannelLevMod().value(): null;
377+
yield setting.isSetChannelLevMod() && !setting.getChannelLevMod().equals(TChannelLevMod.NA) ? setting.getChannelLevMod().value() : null;
383378
}
384379
}
385380
case STVAL_DA_NAME -> ActiveStatus.ON.getValue();
@@ -393,7 +388,7 @@ private void updateDaiVal(TDataTypeTemplates dtt, TIED tied, TLDevice tlDevice,
393388
.map(doLinkedToDa1 -> lnEditor.getDoLinkedToDaCompletedFromDAI(tied, tlDevice.getInst(), tln, doLinkedToDa1))
394389
.findFirst()
395390
.filter(doLinkedToDa1 -> {
396-
if (!doLinkedToDa1.isUpdatable()){
391+
if (!doLinkedToDa1.isUpdatable()) {
397392
errorHandler.get().add(SclReportItem.warning(tied.getName() + "/" + LDEVICE_LDSUIED + "/" + LnId.from(tln).lnClass() + "/DOI@name=\"" + doLinkedToDaFilter.doName() + "\"/DAI@name=\"" + doLinkedToDaFilter.daName() + "\"/Val", "The DAI cannot be updated"));
398393
}
399394
return doLinkedToDa1.isUpdatable();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ protected void updateExtRefBindingInfo(TExtRef extRef, ExtRefInfo extRefInfo) {
293293
extRef.setDoName(bindingInfo.getDoName().toString());
294294
}
295295

296-
extRef.setPrefix(bindingInfo.getPrefix());
296+
extRef.setPrefix(StringUtils.trimToNull(bindingInfo.getPrefix()));
297297
// invalid source info
298298
removeExtRefSourceBinding(extRef);
299299
isSrcReset = true;
@@ -306,7 +306,7 @@ protected void updateExtRefBindingInfo(TExtRef extRef, ExtRefInfo extRefInfo) {
306306
extRef.getSrcLNClass().add(sourceInfo.getSrcLNClass());
307307
}
308308
extRef.setSrcLDInst(sourceInfo.getSrcLDInst());
309-
extRef.setSrcPrefix(sourceInfo.getSrcPrefix());
309+
extRef.setSrcPrefix(StringUtils.trimToNull(sourceInfo.getSrcPrefix()));
310310
extRef.setSrcCBName(sourceInfo.getSrcCBName());
311311
}
312312
}

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

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

55
package org.lfenergy.compas.sct.commons.scl.sstation;
66

7+
import org.apache.commons.lang3.StringUtils;
78
import org.lfenergy.compas.scl2007b4.model.TFunction;
89
import org.lfenergy.compas.scl2007b4.model.TLNode;
910
import org.lfenergy.compas.scl2007b4.model.TText;
@@ -65,7 +66,7 @@ public TLNode deepCopy() {
6566
newLNode.setLdInst(currentElem.getLdInst());
6667
newLNode.setLnInst(currentElem.getLnInst());
6768
newLNode.setLnType(currentElem.getLnType());
68-
newLNode.setPrefix(currentElem.getPrefix());
69+
newLNode.setPrefix(StringUtils.trimToNull(currentElem.getPrefix()));
6970
if (currentElem.isSetText()) {
7071
TText newText = new TText();
7172
newText.setSource(currentElem.getText().getSource());

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/SclConstructorHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public static TFCDA newFcda(String ldInst, String lnClass, String lnInst, String
139139
tfcda.setLdInst(ldInst);
140140
if (StringUtils.isNotBlank(lnClass)) tfcda.getLnClass().add(lnClass);
141141
tfcda.setLnInst(lnInst);
142-
tfcda.setPrefix(prefix);
142+
tfcda.setPrefix(StringUtils.trimToNull(prefix));
143143
tfcda.setDoName(doName);
144144
tfcda.setDaName(daName);
145145
tfcda.setFc(fc);

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ public static TLN copyLn(TLN tln) {
347347
newLn.getLnClass().addAll(tln.getLnClass());
348348
newLn.setInst(tln.getInst());
349349
newLn.setLnType(tln.getLnType());
350-
newLn.setPrefix(tln.getPrefix());
350+
newLn.setPrefix(StringUtils.trimToNull(tln.getPrefix()));
351351
newLn.setDesc(tln.getDesc());
352352
newLn.setInputs(tln.getInputs());
353353
newLn.setText(tln.getText());

0 commit comments

Comments
 (0)