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 15, 2023
1 parent 9cce141 commit 7375e87
Show file tree
Hide file tree
Showing 13 changed files with 1,077 additions and 249 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

Large diffs are not rendered by default.

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 corresponding to CompasFlow we are searching
* @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 CompasFlow
*
* @param inputs node containing CompasFlows and ExtRefs
* @param tCompasFlow corresponding to Extrefs we are searching
* @return stream of matching ExtRefs
*/
public Stream<TExtRef> getMatchingTextRef(TInputs inputs, TCompasFlow tCompasFlow) {
return getExtRefs(inputs)
.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
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.ExtRefService;
import org.lfenergy.compas.sct.commons.ExtRefEditorService;
import org.lfenergy.compas.sct.commons.dto.DataAttributeRef;
import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.ExtRefService;
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter;
Expand Down Expand Up @@ -63,6 +64,8 @@ public class InputsAdapter extends SclElementAdapter<LN0Adapter, TInputs> {

private static final int EXTREF_DESC_DA_NAME_POSITION = -2;

private final ExtRefService extRefService = new ExtRefService();

/**
* Constructor
*
Expand Down Expand Up @@ -101,13 +104,13 @@ public List<SclReportItem> updateAllExtRefIedNames(Map<String, IEDAdapter> icdSy
try {
ActiveStatus lDeviceStatus = ActiveStatus.fromValue(optionalLDeviceStatus.get());
return switch (lDeviceStatus) {
case ON -> getExtRefs().stream()
case ON -> extRefService.getExtRefs(currentElem)
.filter(tExtRef -> StringUtils.isNotBlank(tExtRef.getIedName()) && StringUtils.isNotBlank(tExtRef.getDesc()))
.map(extRef -> updateExtRefIedName(extRef, icdSystemVersionToIed.get(extRef.getIedName())))
.flatMap(Optional::stream)
.toList();
case OFF -> {
getExtRefs().forEach(this::clearBinding);
extRefService.getExtRefs(currentElem).forEach(extRefService::clearExtRefBinding);
yield Collections.emptyList();
}
};
Expand All @@ -123,19 +126,19 @@ public List<SclReportItem> updateAllExtRefIedNames(Map<String, IEDAdapter> icdSy
* @return Error if ExtRef could not be updated
*/
private Optional<SclReportItem> updateExtRefIedName(TExtRef extRef, IEDAdapter sourceIed) {
List<TCompasFlow> matchingCompasFlows = getMatchingCompasFlows(extRef);
List<TCompasFlow> matchingCompasFlows = extRefService.getMatchingCompasFlows(currentElem, extRef).toList();
if (!singleMatch(matchingCompasFlows)) {
return fatalReportItem(extRef,
matchingCompasFlows.isEmpty() ? MESSAGE_NO_MATCHING_COMPAS_FLOW : MESSAGE_TOO_MANY_MATCHING_COMPAS_FLOWS);
}
TCompasFlow compasFlow = matchingCompasFlows.get(0);
if (compasFlow.getFlowStatus() == TCompasFlowStatus.INACTIVE) {
clearBinding(extRef);
extRefService.clearExtRefBinding(extRef);
return Optional.empty();
}
Optional<SclReportItem> sourceValidationError = validateExtRefSource(extRef, sourceIed);
if (sourceValidationError.isPresent()) {
clearBinding(extRef);
extRefService.clearExtRefBinding(extRef);
return sourceValidationError;
}
String sourceIedName = PrivateUtils.extractCompasPrivate(sourceIed.getCurrentElem(), TCompasICDHeader.class)
Expand All @@ -146,18 +149,6 @@ private Optional<SclReportItem> updateExtRefIedName(TExtRef extRef, IEDAdapter s
return Optional.empty();
}

/**
* List all ExtRefs in this Inputs
*
* @return list of ExtRefs. List is modifiable.
*/
private List<TExtRef> getExtRefs() {
if (!currentElem.isSetExtRef()) {
return Collections.emptyList();
}
return currentElem.getExtRef();
}

private Optional<SclReportItem> validateExtRefSource(TExtRef extRef, IEDAdapter sourceIed) {
if (sourceIed == null) {
return warningReportItem(extRef, MESSAGE_EXTREF_IEDNAME_DOES_NOT_MATCH_ANY_SYSTEM_VERSION_UUID);
Expand Down Expand Up @@ -192,22 +183,6 @@ private boolean singleMatch(List<TCompasFlow> matchingCompasFlows) {
return matchingCompasFlows.size() == 1;
}

private void clearBinding(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();
}

private Optional<SclReportItem> warningReportItem(TExtRef extRef, String message) {
return Optional.of(SclReportItem.warning(extRefXPath(extRef.getDesc()), message));
}
Expand All @@ -221,36 +196,6 @@ private String extRefXPath(String extRefDesc) {
Utils.xpathAttributeFilter("desc", extRefDesc));
}

/**
* Find CompasFlows that match given ExtRef
*
* @param extRef extRef to match
* @return list of matching CompasFlows
*/
private List<TCompasFlow> getMatchingCompasFlows(TExtRef extRef) {
return PrivateUtils.extractCompasPrivates(currentElem, TCompasFlow.class)
.filter(compasFlow -> isMatchingExtRef(compasFlow, extRef))
.toList();
}

/**
* 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());
}

private LDeviceAdapter getLDeviceAdapter() {
return parentAdapter.getParentAdapter();
}
Expand All @@ -264,7 +209,7 @@ public List<SclReportItem> updateAllSourceDataSetsAndControlBlocks(Set<FcdaForDa
if (StringUtils.isBlank(currentBayUuid)) {
return List.of(getIedAdapter().buildFatalReportItem(MESSAGE_IED_MISSING_COMPAS_BAY_UUID));
}
return getExtRefs().stream()
return extRefService.getExtRefs(currentElem)
.filter(this::areBindingAttributesPresent)
.filter(this::isExternalBound)
.filter(this::matchingCompasFlowIsActiveOrUntested)
Expand All @@ -274,7 +219,7 @@ public List<SclReportItem> updateAllSourceDataSetsAndControlBlocks(Set<FcdaForDa
}

private boolean matchingCompasFlowIsActiveOrUntested(TExtRef extRef) {
return getMatchingCompasFlows(extRef).stream().findFirst()
return extRefService.getMatchingCompasFlows(currentElem, extRef).findFirst()
.map(TCompasFlow::getFlowStatus)
.filter(flowStatus -> flowStatus == TCompasFlowStatus.ACTIVE || flowStatus == TCompasFlowStatus.UNTESTED)
.isPresent();
Expand Down Expand Up @@ -429,7 +374,7 @@ private SclRootAdapter getSclRootAdapter() {
* @return list ExtRefs without duplication
*/
public List<TExtRef> filterDuplicatedExtRefs() {
return ExtRefService.filterDuplicatedExtRefs(getExtRefs());
return ExtRefEditorService.filterDuplicatedExtRefs(extRefService.getExtRefs(currentElem).toList());
}

}
Loading

0 comments on commit 7375e87

Please sign in to comment.