Skip to content

Commit 06a49b2

Browse files
Fix Control Blocks matching RxtRefs (#180)
* fix(175): gets all control blocks source for DataSet for which at least FCDA match ExtRef Signed-off-by: Aliou DIAITE <[email protected]> Signed-off-by: SABATIER Philippe Ext <[email protected]> Co-authored-by: psabatierrte <[email protected]> Signed-off-by: Aliou DIAITE <[email protected]>
1 parent 97f1065 commit 06a49b2

File tree

12 files changed

+803
-223
lines changed

12 files changed

+803
-223
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,22 @@ public boolean isNull() {
163163
* @param o the object to be compared.
164164
* @return the comparaison's result (a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second)
165165
*/
166-
@Override
167166
public int compareTo(ExtRefBindingInfo o) {
168167
return EXT_REF_BINDING_INFO_COMPARATOR.compare(this, o);
169168
}
169+
170+
@Override
171+
public String toString() {
172+
String sType = serviceType != null ? serviceType.value() : null;
173+
return "ExtRefBindingInfo{" +
174+
"iedName='" + iedName + '\'' +
175+
", ldInst='" + ldInst + '\'' +
176+
", prefix='" + prefix + '\'' +
177+
", lnClass='" + lnClass + '\'' +
178+
", lnInst='" + lnInst + '\'' +
179+
", lnType='" + lnType + '\'' +
180+
", serviceType=" + sType +
181+
'}';
182+
183+
}
170184
}

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
package org.lfenergy.compas.sct.commons.dto;
66

77

8-
import lombok.Getter;
9-
import lombok.NoArgsConstructor;
10-
import lombok.NonNull;
11-
import lombok.Setter;
8+
import lombok.*;
129
import org.apache.commons.lang3.StringUtils;
1310
import org.lfenergy.compas.scl2007b4.model.TExtRef;
1411
import org.lfenergy.compas.scl2007b4.model.TFCDA;
@@ -38,6 +35,7 @@
3835
@Getter
3936
@Setter
4037
@NoArgsConstructor
38+
@AllArgsConstructor
4139
public class ExtRefInfo extends LNodeMetaDataEmbedder{
4240

4341
private ExtRefSignalInfo signalInfo;
@@ -82,9 +80,10 @@ public static ExtRefInfo from(TExtRef tExtRef, String iedName, String ldInst,
8280
* @param tfcda FCDA data object
8381
* @return match state
8482
*/
83+
//TODO this method should be checked, return if parameter tested are not present in FCDA even if two object are different
8584
public boolean matchFCDA(@NonNull TFCDA tfcda){
8685
boolean returnValue = true;
87-
if(AbstractLNAdapter.isNull(tfcda)) {
86+
if(AbstractLNAdapter.isFCDANull(tfcda)) {
8887
returnValue = false;
8988
}
9089

@@ -118,4 +117,25 @@ public boolean matchFCDA(@NonNull TFCDA tfcda){
118117
}
119118
return returnValue;
120119
}
120+
/**
121+
* Check matching between FCDA and ExtRef information (for external binding)
122+
* Check is done for parameter lDInst(mandatory), lNClass(mandatory), lNInst, prefix doName as pDO(mandatory) and daName as pDA
123+
* present in ExtRef and FCDA
124+
* @param tfcda FCDA data to check compatibilities with ExtRef
125+
* @return true if ExtRef matches FCDA for parameters ahead false otherwise
126+
*/
127+
public boolean checkMatchingFCDA(@NonNull TFCDA tfcda){
128+
if(bindingInfo == null || signalInfo == null) return false;
129+
FCDAInfo fcdaInfo = new FCDAInfo(tfcda);
130+
FCDAInfo fcdaOfBinding = FCDAInfo.builder()
131+
.ldInst(bindingInfo.getLdInst())
132+
.lnClass(bindingInfo.getLnClass())
133+
.lnInst(bindingInfo.getLnInst())
134+
.prefix(bindingInfo.getPrefix())
135+
.doName(new DoTypeName(signalInfo.getPDO()))
136+
.daName(new DaTypeName(signalInfo.getPDA()))
137+
.build();
138+
return fcdaInfo.checkFCDACompatibilitiesForBinding(fcdaOfBinding);
139+
}
140+
121141
}

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
package org.lfenergy.compas.sct.commons.dto;
66

77
import com.fasterxml.jackson.annotation.JsonIgnore;
8-
import lombok.Getter;
9-
import lombok.NoArgsConstructor;
10-
import lombok.Setter;
8+
import lombok.*;
119
import org.apache.commons.lang3.StringUtils;
1210
import org.lfenergy.compas.scl2007b4.model.TFCDA;
1311
import org.lfenergy.compas.scl2007b4.model.TFCEnum;
1412

13+
import java.util.Objects;
14+
15+
import static org.lfenergy.compas.sct.commons.util.Utils.equalsOrBothBlank;
16+
1517
/**
1618
* A representation of the model object <em><b>FCDA</b></em>.
1719
*
@@ -33,7 +35,9 @@
3335
*/
3436
@Getter
3537
@Setter
38+
@AllArgsConstructor
3639
@NoArgsConstructor
40+
@Builder
3741
public class FCDAInfo {
3842

3943
private String dataSet;
@@ -53,7 +57,11 @@ public class FCDAInfo {
5357
* @param tfcda input
5458
*/
5559
public FCDAInfo(String dataSet, TFCDA tfcda) {
60+
this(tfcda);
5661
this.dataSet = dataSet;
62+
}
63+
64+
public FCDAInfo(TFCDA tfcda) {
5765
fc = tfcda.getFc();
5866
ldInst = tfcda.getLdInst();
5967
prefix = tfcda.getPrefix();
@@ -106,4 +114,18 @@ public TFCDA getFCDA(){
106114
public boolean isValid() {
107115
return doName != null && doName.isDefined();
108116
}
117+
118+
/**
119+
* Checks if two FCDAInfo object match for ldInst, lnInst, lnClass, lnPrefix doName and daName for search of binding control blocks
120+
* @param fcdaInfo FCDA to copare with
121+
* @return true if FCDAs match for binding, otherwise false
122+
*/
123+
public boolean checkFCDACompatibilitiesForBinding(FCDAInfo fcdaInfo) {
124+
return equalsOrBothBlank(getLdInst(), fcdaInfo.getLdInst())
125+
&& equalsOrBothBlank(getPrefix(), fcdaInfo.getPrefix())
126+
&& equalsOrBothBlank(getLnClass(), fcdaInfo.getLnClass())
127+
&& equalsOrBothBlank(getLnInst(), fcdaInfo.getLnInst())
128+
&& Objects.equals(getDoName(), fcdaInfo.getDoName())
129+
&& Objects.equals(getDaName(), fcdaInfo.getDaName());
130+
}
109131
}

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

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ public static List<ExtRefBindingInfo> getExtRefBinders(SCL scd, String iedName,
265265

266266
// check for signal existence
267267
// The below throws exception if the signal doesn't exist
268+
//TODO: create method which purpose is only ckecking instead of this one
268269
abstractLNAdapter.getExtRefsBySignalInfo(signalInfo);
269270

270271
// find potential binders for the signalInfo
@@ -327,36 +328,20 @@ public static List<ControlBlock<?>> getExtRefSourceInfo(SCL scd, ExtRefInfo extR
327328
throw new ScdException("Internal binding can't have control block");
328329
}
329330

330-
String ldInst = extRefInfo.getHolderLDInst();
331-
String lnClass = extRefInfo.getHolderLnClass();
332-
String lnInst = extRefInfo.getHolderLnInst();
333-
String prefix = extRefInfo.getHolderLnPrefix();
334-
// Check holder (IED,LD,LN) exists
335331
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
336-
IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(iedName);
337-
LDeviceAdapter lDeviceAdapter = iedAdapter.getLDeviceAdapterByLdInst(ldInst)
338-
.orElseThrow(() -> new ScdException(String.format(UNKNOWN_LDEVICE_S_IN_IED_S, ldInst, iedName)));
339-
AbstractLNAdapter<?> abstractLNAdapter = AbstractLNAdapter.builder()
340-
.withLDeviceAdapter(lDeviceAdapter)
341-
.withLnClass(lnClass)
342-
.withLnInst(lnInst)
343-
.withLnPrefix(prefix)
344-
.build();
345-
346-
abstractLNAdapter.checkExtRefInfoCoherence(extRefInfo);
347332

348333
// Get CBs
349334
IEDAdapter srcIEDAdapter = sclRootAdapter.getIEDAdapterByName(bindingInfo.getIedName());
350335
LDeviceAdapter srcLDeviceAdapter = srcIEDAdapter.getLDeviceAdapterByLdInst(extRefInfo.getBindingInfo().getLdInst())
351336
.orElseThrow();
352337

353-
AbstractLNAdapter<?> srcLnAdapter = AbstractLNAdapter.builder()
354-
.withLDeviceAdapter(srcLDeviceAdapter)
355-
.withLnClass(extRefInfo.getBindingInfo().getLnClass())
356-
.withLnInst(extRefInfo.getBindingInfo().getLnInst())
357-
.withLnPrefix(extRefInfo.getBindingInfo().getPrefix())
358-
.build();
359-
return srcLnAdapter.getControlSetByExtRefInfo(extRefInfo);
338+
List<AbstractLNAdapter<?>> aLNAdapters = srcLDeviceAdapter.getLNAdaptersInclundigLN0();
339+
340+
return aLNAdapters.stream()
341+
.map(abstractLNAdapter1 -> abstractLNAdapter1.getControlBlocksForMatchingFCDA(extRefInfo))
342+
.flatMap(Collection::stream)
343+
.collect(Collectors.toList());
344+
360345
}
361346

362347
/**

0 commit comments

Comments
 (0)