Skip to content

Commit

Permalink
feat(#352): remove compasflow and extref bindings
Browse files Browse the repository at this point in the history
Signed-off-by: Aliou DIAITE <aliou.diaite@rte-france.com>
  • Loading branch information
AliouDIAITE committed Dec 12, 2023
1 parent 9cce141 commit 3d14926
Show file tree
Hide file tree
Showing 10 changed files with 623 additions and 98 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<sonar.coverage.exclusions>sct-coverage/**</sonar.coverage.exclusions>
<aggregate.report.dir>../sct-coverage/target/site/jacoco-aggregate/jacoco.xml</aggregate.report.dir>
<sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
<compas-core.version>0.17.0</compas-core.version>
<compas-core.version>0.18.0</compas-core.version>
<compas-scl-xsd.version>0.0.4</compas-scl-xsd.version>
<maven.plugin.javadoc>3.4.1</maven.plugin.javadoc>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package org.lfenergy.compas.sct.commons;

import lombok.RequiredArgsConstructor;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.api.ExtRefEditor;
import org.lfenergy.compas.sct.commons.dto.*;
Expand All @@ -12,6 +13,7 @@
import org.lfenergy.compas.sct.commons.model.epf.TCBscopeType;
import org.lfenergy.compas.sct.commons.model.epf.TChannel;
import org.lfenergy.compas.sct.commons.model.epf.TChannelType;
import org.lfenergy.compas.sct.commons.scl.ExtRefService;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;
import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter;
Expand All @@ -30,8 +32,10 @@
import static org.lfenergy.compas.sct.commons.util.CommonConstants.*;
import static org.lfenergy.compas.sct.commons.util.Utils.isExtRefFeedBySameControlBlock;

public class ExtRefService implements ExtRefEditor {
@RequiredArgsConstructor
public class ExtRefEditorService implements ExtRefEditor {
private static final String INVALID_OR_MISSING_ATTRIBUTES_IN_EXT_REF_BINDING_INFO = "Invalid or missing attributes in ExtRef binding info";
private final ExtRefService extRefService;

@Override
public void updateExtRefBinders(SCL scd, ExtRefInfo extRefInfo) throws ScdException {
Expand Down Expand Up @@ -399,4 +403,74 @@ private String computeDaiValue(AbstractLNAdapter<?> lnAdapter, TExtRef extRef, S
}
}

@Override
public void debindCompasFlowsAndExtRefsBasedOnVoltageLevel(SCL scd) {
LdeviceService ldeviceService = new LdeviceService();
ExtRefService extRefService = new ExtRefService();
scd.getSubstation()
.stream()
.flatMap(tSubstation -> tSubstation.getVoltageLevel().stream())
.forEach(tVoltageLevel -> {
String flowSource = voltageCodification.get(tVoltageLevel.getName());
scd.getIED().stream()
.flatMap(ldeviceService::getLdevices)
.forEach(tlDevice -> {
TInputs tInputs = tlDevice.getLN0().getInputs();
List<TCompasFlow> compasFlows = PrivateUtils.getPrivateStream(tInputs.getPrivate(), TCompasFlow.class).toList();
compasFlows.forEach(tCompasFlow -> {
if (flowSource == null && tCompasFlow.isSetFlowSourceVoltageLevel() && tCompasFlow.isSetExtRefiedName()) {
//debind all compas flow
extRefService.clearCompasFlowBinding(tCompasFlow);
}
if (flowSource != null && tCompasFlow.isSetExtRefiedName() && tCompasFlow.isSetFlowSourceVoltageLevel() && !tCompasFlow.getFlowSourceVoltageLevel().equals(flowSource)) {
//debind extRef
extRefService.getMatchingTextRef(tInputs, tCompasFlow)
.forEach(extRefService::clearExtRefBinding);
//debind compas flow
extRefService.clearCompasFlowBinding(tCompasFlow);

}
});
});
});
}


public void debindCompasFlowsAndExtRefsBasedOnVoltageLevel_(SCL scd) {
LdeviceService ldeviceService = new LdeviceService();
ExtRefService extRefService = new ExtRefService();
scd.getSubstation()
.stream()
.flatMap(tSubstation -> tSubstation.getVoltageLevel().stream())
.map(tVoltageLevel -> voltageCodification.get(tVoltageLevel.getName()))
.forEach(flowSource -> scd.getIED().stream()
.flatMap(ldeviceService::getLdevices)
.forEach(tlDevice -> {
TInputs tInputs = tlDevice.getLN0().getInputs();
PrivateUtils.extractCompasPrivates(tInputs, TCompasFlow.class)
.forEach(tCompasFlow -> {
if (flowSource == null && !tCompasFlow.isSetFlowSourceVoltageLevel() && !tCompasFlow.isSetExtRefiedName()) {
//debind all
extRefService.getMatchingTextRef(tInputs, tCompasFlow).forEach(extRefService::clearExtRefBinding);
}
if (flowSource != null && tCompasFlow.isSetExtRefiedName() && Objects.equals(tCompasFlow.getFlowSourceVoltageLevel(), flowSource)) {
//debind compas flow
extRefService.clearCompasFlowBinding(tCompasFlow);
//debind extRef
extRefService.getMatchingTextRef(tInputs, tCompasFlow).forEach(extRefService::clearExtRefBinding);
}
});
})
);
}


private static final Map<String, String> voltageCodification = new HashMap<>() {{
put("3", "HT");
put("4", "HT");
put("5", "THT");
put("6", "THT");
put("7", "THT");
}};

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,18 @@ public interface ExtRefEditor {

/**
* ExtRef Binding For LDevice (inst=LDEPF) that matching EPF configuration
*
* @param scd SCL
* @param epf EPF
* @return list of encountered errors
*/
List<SclReportItem> manageBindingForLDEPF(SCL scd, EPF epf);

/**
* Debinding of Private CompasFlows and ExtRef signals based on voltageLevel
*
* @param scd SCL file in which ExtRef and Private CompasFlow should be debind
*/
void debindCompasFlowsAndExtRefsBasedOnVoltageLevel(SCL scd);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* // SPDX-FileCopyrightText: 2023 RTE FRANCE
* //
* // SPDX-License-Identifier: Apache-2.0
*/

package org.lfenergy.compas.sct.commons.scl;

import org.lfenergy.compas.scl2007b4.model.TCompasFlow;
import org.lfenergy.compas.scl2007b4.model.TExtRef;
import org.lfenergy.compas.scl2007b4.model.TInputs;
import org.lfenergy.compas.sct.commons.util.PrivateUtils;
import org.lfenergy.compas.sct.commons.util.Utils;

import java.util.stream.Stream;

public class ExtRefService {

/**
* List all ExtRefs in this Inputs
*
* @return list of ExtRefs. List is modifiable.
*/
public Stream<TExtRef> getExtRefs(TInputs inputs) {
if (inputs == null || !inputs.isSetExtRef()) {
return Stream.empty();
}
return inputs.getExtRef().stream();
}

/**
* Find CompasFlows that match given ExtRef
*
* @param inputs inputs containing Privates CompasFlow and TExtRefs
* @param tExtRef extRef to match
* @return list of matching CompasFlows
*/
public Stream<TCompasFlow> getMatchingCompasFlows(TInputs inputs, TExtRef tExtRef) {
return PrivateUtils.extractCompasPrivates(inputs, TCompasFlow.class)
.filter(compasFlow -> isMatchingExtRef(compasFlow, tExtRef));
}

/**
* Retrieves ExtRefs corresponding to given
*
* @param inputs node containing CompasFlows and ExtRefs
* @param tCompasFlow for which Extrefs are searched
* @return stream of matching ExtRefs
*/
public Stream<TExtRef> getMatchingTextRef(TInputs inputs, TCompasFlow tCompasFlow) {
return inputs.getExtRef().stream()
.filter(tExtRef -> isMatchingExtRef(tCompasFlow, tExtRef));
}

/**
* Debind ExtRef
*
* @param extRef to debind
*/
public void clearExtRefBinding(TExtRef extRef) {
extRef.setIedName(null);
extRef.setLdInst(null);
extRef.setPrefix(null);
extRef.setLnInst(null);
extRef.setDoName(null);
extRef.setDaName(null);
extRef.setServiceType(null);
extRef.setSrcLDInst(null);
extRef.setSrcPrefix(null);
extRef.setSrcLNInst(null);
extRef.setSrcCBName(null);
extRef.unsetLnClass();
extRef.unsetSrcLNClass();
}

/**
* Debind CompasFlow
*
* @param tCompasFlow to debind
*/
public void clearCompasFlowBinding(TCompasFlow tCompasFlow) {
tCompasFlow.setExtRefiedName(null);
tCompasFlow.setExtRefldinst(null);
tCompasFlow.setExtReflnClass(null);
tCompasFlow.setExtReflnInst(null);
tCompasFlow.setExtRefprefix(null);
}

/**
* Check if extRef matches CompasFlow
*
* @param compasFlow compasFlow
* @param extRef extRef
* @return true if all required attributes matches. Note that empty string, whitespaces only string and null values are considered as matching
* (missing attributes matches attribute with empty string value or whitespaces only). Return false otherwise.
*/
private boolean isMatchingExtRef(TCompasFlow compasFlow, TExtRef extRef) {
String extRefLnClass = extRef.isSetLnClass() ? extRef.getLnClass().get(0) : null;
return Utils.equalsOrBothBlank(compasFlow.getDataStreamKey(), extRef.getDesc())
&& Utils.equalsOrBothBlank(compasFlow.getExtRefiedName(), extRef.getIedName())
&& Utils.equalsOrBothBlank(compasFlow.getExtRefldinst(), extRef.getLdInst())
&& Utils.equalsOrBothBlank(compasFlow.getExtRefprefix(), extRef.getPrefix())
&& Utils.equalsOrBothBlank(compasFlow.getExtReflnClass(), extRefLnClass)
&& Utils.equalsOrBothBlank(compasFlow.getExtReflnInst(), extRef.getLnInst());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.lfenergy.compas.sct.commons.ExtRefService.filterDuplicatedExtRefs;
import static org.lfenergy.compas.sct.commons.ExtRefEditorService.filterDuplicatedExtRefs;

/**
* A representation of the model object
Expand Down
Loading

0 comments on commit 3d14926

Please sign in to comment.