Skip to content

Commit

Permalink
Fix Control Blocks matching RxtRefs (#180)
Browse files Browse the repository at this point in the history
* fix(175): gets all control blocks source for DataSet for which at least FCDA match ExtRef

Signed-off-by: Aliou DIAITE <aliou.diaite@rte-france.com>
Signed-off-by: SABATIER Philippe Ext <philippe.sabatier@rte-france.com>
Co-authored-by: psabatierrte <98765347+psabatierrte@users.noreply.github.com>
Signed-off-by: Aliou DIAITE <aliou.diaite@rte-france.com>
  • Loading branch information
AliouDIAITE and psabatierrte committed Oct 24, 2022
1 parent 97f1065 commit 06a49b2
Show file tree
Hide file tree
Showing 12 changed files with 803 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,22 @@ public boolean isNull() {
* @param o the object to be compared.
* @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)
*/
@Override
public int compareTo(ExtRefBindingInfo o) {
return EXT_REF_BINDING_INFO_COMPARATOR.compare(this, o);
}

@Override
public String toString() {
String sType = serviceType != null ? serviceType.value() : null;
return "ExtRefBindingInfo{" +
"iedName='" + iedName + '\'' +
", ldInst='" + ldInst + '\'' +
", prefix='" + prefix + '\'' +
", lnClass='" + lnClass + '\'' +
", lnInst='" + lnInst + '\'' +
", lnType='" + lnType + '\'' +
", serviceType=" + sType +
'}';

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
package org.lfenergy.compas.sct.commons.dto;


import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.*;
import org.apache.commons.lang3.StringUtils;
import org.lfenergy.compas.scl2007b4.model.TExtRef;
import org.lfenergy.compas.scl2007b4.model.TFCDA;
Expand Down Expand Up @@ -38,6 +35,7 @@
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ExtRefInfo extends LNodeMetaDataEmbedder{

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

Expand Down Expand Up @@ -118,4 +117,25 @@ public boolean matchFCDA(@NonNull TFCDA tfcda){
}
return returnValue;
}
/**
* Check matching between FCDA and ExtRef information (for external binding)
* Check is done for parameter lDInst(mandatory), lNClass(mandatory), lNInst, prefix doName as pDO(mandatory) and daName as pDA
* present in ExtRef and FCDA
* @param tfcda FCDA data to check compatibilities with ExtRef
* @return true if ExtRef matches FCDA for parameters ahead false otherwise
*/
public boolean checkMatchingFCDA(@NonNull TFCDA tfcda){
if(bindingInfo == null || signalInfo == null) return false;
FCDAInfo fcdaInfo = new FCDAInfo(tfcda);
FCDAInfo fcdaOfBinding = FCDAInfo.builder()
.ldInst(bindingInfo.getLdInst())
.lnClass(bindingInfo.getLnClass())
.lnInst(bindingInfo.getLnInst())
.prefix(bindingInfo.getPrefix())
.doName(new DoTypeName(signalInfo.getPDO()))
.daName(new DaTypeName(signalInfo.getPDA()))
.build();
return fcdaInfo.checkFCDACompatibilitiesForBinding(fcdaOfBinding);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
package org.lfenergy.compas.sct.commons.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;
import org.apache.commons.lang3.StringUtils;
import org.lfenergy.compas.scl2007b4.model.TFCDA;
import org.lfenergy.compas.scl2007b4.model.TFCEnum;

import java.util.Objects;

import static org.lfenergy.compas.sct.commons.util.Utils.equalsOrBothBlank;

/**
* A representation of the model object <em><b>FCDA</b></em>.
*
Expand All @@ -33,7 +35,9 @@
*/
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class FCDAInfo {

private String dataSet;
Expand All @@ -53,7 +57,11 @@ public class FCDAInfo {
* @param tfcda input
*/
public FCDAInfo(String dataSet, TFCDA tfcda) {
this(tfcda);
this.dataSet = dataSet;
}

public FCDAInfo(TFCDA tfcda) {
fc = tfcda.getFc();
ldInst = tfcda.getLdInst();
prefix = tfcda.getPrefix();
Expand Down Expand Up @@ -106,4 +114,18 @@ public TFCDA getFCDA(){
public boolean isValid() {
return doName != null && doName.isDefined();
}

/**
* Checks if two FCDAInfo object match for ldInst, lnInst, lnClass, lnPrefix doName and daName for search of binding control blocks
* @param fcdaInfo FCDA to copare with
* @return true if FCDAs match for binding, otherwise false
*/
public boolean checkFCDACompatibilitiesForBinding(FCDAInfo fcdaInfo) {
return equalsOrBothBlank(getLdInst(), fcdaInfo.getLdInst())
&& equalsOrBothBlank(getPrefix(), fcdaInfo.getPrefix())
&& equalsOrBothBlank(getLnClass(), fcdaInfo.getLnClass())
&& equalsOrBothBlank(getLnInst(), fcdaInfo.getLnInst())
&& Objects.equals(getDoName(), fcdaInfo.getDoName())
&& Objects.equals(getDaName(), fcdaInfo.getDaName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public static List<ExtRefBindingInfo> getExtRefBinders(SCL scd, String iedName,

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

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

String ldInst = extRefInfo.getHolderLDInst();
String lnClass = extRefInfo.getHolderLnClass();
String lnInst = extRefInfo.getHolderLnInst();
String prefix = extRefInfo.getHolderLnPrefix();
// Check holder (IED,LD,LN) exists
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(iedName);
LDeviceAdapter lDeviceAdapter = iedAdapter.getLDeviceAdapterByLdInst(ldInst)
.orElseThrow(() -> new ScdException(String.format(UNKNOWN_LDEVICE_S_IN_IED_S, ldInst, iedName)));
AbstractLNAdapter<?> abstractLNAdapter = AbstractLNAdapter.builder()
.withLDeviceAdapter(lDeviceAdapter)
.withLnClass(lnClass)
.withLnInst(lnInst)
.withLnPrefix(prefix)
.build();

abstractLNAdapter.checkExtRefInfoCoherence(extRefInfo);

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

AbstractLNAdapter<?> srcLnAdapter = AbstractLNAdapter.builder()
.withLDeviceAdapter(srcLDeviceAdapter)
.withLnClass(extRefInfo.getBindingInfo().getLnClass())
.withLnInst(extRefInfo.getBindingInfo().getLnInst())
.withLnPrefix(extRefInfo.getBindingInfo().getPrefix())
.build();
return srcLnAdapter.getControlSetByExtRefInfo(extRefInfo);
List<AbstractLNAdapter<?>> aLNAdapters = srcLDeviceAdapter.getLNAdaptersInclundigLN0();

return aLNAdapters.stream()
.map(abstractLNAdapter1 -> abstractLNAdapter1.getControlBlocksForMatchingFCDA(extRefInfo))
.flatMap(Collection::stream)
.collect(Collectors.toList());

}

/**
Expand Down
Loading

0 comments on commit 06a49b2

Please sign in to comment.