Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop into main #303

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
import org.lfenergy.compas.sct.commons.dto.*;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.ied.*;
import org.lfenergy.compas.sct.commons.util.ControlBlockEnum;
import org.lfenergy.compas.sct.commons.util.ILDEPFSettings;
import org.lfenergy.compas.sct.commons.util.*;
import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TCompasICDHeader;
import org.lfenergy.compas.scl2007b4.model.TExtRef;
import org.lfenergy.compas.scl2007b4.model.TIED;
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings;
import org.lfenergy.compas.sct.commons.dto.SclReport;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.util.LDeviceStatus;
import org.lfenergy.compas.sct.commons.util.PrivateEnum;
import org.lfenergy.compas.sct.commons.util.Utils;

import java.util.*;
import java.util.function.Function;
Expand Down Expand Up @@ -325,7 +321,7 @@ private static Optional<SclReportItem> updateVal(AbstractLNAdapter<?> lnAdapter,
case DU_DA_NAME -> setting.getChannelShortLabel();
case SETVAL_DA_NAME ->
LN_PREFIX_B.equals(lnAdapter.getPrefix()) || LN_PREFIX_A.equals(lnAdapter.getPrefix()) ? setting.getChannelLevModQ() : setting.getChannelLevMod();
case STVAL_DA_NAME -> LDeviceStatus.ON;
case STVAL_DA_NAME -> LdeviceStatus.ON.getValue();
case SETSRCREF_DA_NAME -> computeDaiValue(lnAdapter, extRef, setting.getDaName());
default -> null;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import lombok.Setter;
import org.apache.commons.lang3.tuple.Pair;
import org.lfenergy.compas.scl2007b4.model.TCompasLDeviceStatus;
import org.lfenergy.compas.sct.commons.util.LDeviceStatus;
import org.lfenergy.compas.sct.commons.util.LdeviceStatus;

import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -38,15 +38,15 @@ public LDeviceActivation(List<Pair<String, String>> iedNameLdInstList) {
* @param enumValues enum values
*/
public void checkLDeviceActivationStatus(String iedName, String ldInst, TCompasLDeviceStatus compasLDeviceStatus, Set<String> enumValues) {
if (!enumValues.contains(LDeviceStatus.ON) && !enumValues.contains(LDeviceStatus.OFF)) {
if (!enumValues.contains(LdeviceStatus.ON.getValue()) && !enumValues.contains(LdeviceStatus.OFF.getValue())) {
errorMessage = "The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.";
}
if (!enumValues.contains(LDeviceStatus.ON) && enumValues.contains(LDeviceStatus.OFF)) {
if (!enumValues.contains(LdeviceStatus.ON.getValue()) && enumValues.contains(LdeviceStatus.OFF.getValue())) {
if (isDeclaredInSubstation(iedName, ldInst)) {
errorMessage = "The LDevice cannot be set to 'on' but has been selected into SSD.";
} else {
isUpdatable = true;
newVal = LDeviceStatus.OFF;
newVal = LdeviceStatus.OFF.getValue();
}
}
if(compasLDeviceStatus.equals(TCompasLDeviceStatus.ACTIVE) ||
Expand All @@ -65,20 +65,20 @@ public void checkLDeviceActivationStatus(String iedName, String ldInst, TCompasL
* @param enumValues enum values
*/
private void checkAuthorisationToActivateLDevice(String iedName, String ldInst, Set<String> enumValues) {
if (!enumValues.contains(LDeviceStatus.OFF) && enumValues.contains(LDeviceStatus.ON)) {
if (!enumValues.contains(LdeviceStatus.OFF.getValue()) && enumValues.contains(LdeviceStatus.ON.getValue())) {
if (isDeclaredInSubstation(iedName, ldInst)) {
isUpdatable = true;
newVal = LDeviceStatus.ON;
newVal = LdeviceStatus.ON.getValue();
} else {
errorMessage = "The LDevice cannot be set to 'off' but has not been selected into SSD.";
}
}
if (enumValues.contains(LDeviceStatus.ON) && enumValues.contains(LDeviceStatus.OFF)) {
if (enumValues.contains(LdeviceStatus.ON.getValue()) && enumValues.contains(LdeviceStatus.OFF.getValue())) {
isUpdatable = true;
if (isDeclaredInSubstation(iedName, ldInst)) {
newVal = LDeviceStatus.ON;
newVal = LdeviceStatus.ON.getValue();
} else {
newVal = LDeviceStatus.OFF;
newVal = LdeviceStatus.OFF.getValue();
}
}

Expand All @@ -91,19 +91,19 @@ private void checkAuthorisationToActivateLDevice(String iedName, String ldInst,
* @param enumValues enum values
*/
private void checkAuthorisationToDeactivateLDevice(String iedName, String ldInst, Set<String> enumValues) {
if (!enumValues.contains(LDeviceStatus.OFF) && enumValues.contains(LDeviceStatus.ON)) {
if (!enumValues.contains(LdeviceStatus.OFF.getValue()) && enumValues.contains(LdeviceStatus.ON.getValue())) {
if (isDeclaredInSubstation(iedName, ldInst)) {
errorMessage = "The LDevice is not qualified into STD but has been selected into SSD.";
} else {
errorMessage = "The LDevice cannot be set to 'off' but has not been selected into SSD.";
}
}
if (enumValues.contains(LDeviceStatus.ON) && enumValues.contains(LDeviceStatus.OFF)) {
if (enumValues.contains(LdeviceStatus.ON.getValue()) && enumValues.contains(LdeviceStatus.OFF.getValue())) {
if (isDeclaredInSubstation(iedName, ldInst)) {
errorMessage = "The LDevice is not qualified into STD but has been selected into SSD.";
} else {
isUpdatable = true;
newVal = LDeviceStatus.OFF;
newVal = LdeviceStatus.OFF.getValue();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.util.ControlBlockEnum;
import org.lfenergy.compas.sct.commons.util.FcdaCandidates;
import org.lfenergy.compas.sct.commons.util.LdeviceStatus;
import org.lfenergy.compas.sct.commons.util.Utils;

import java.util.*;
import java.util.function.Predicate;

import static org.lfenergy.compas.sct.commons.util.CommonConstants.*;
import static org.lfenergy.compas.sct.commons.util.LDeviceStatus.OFF;
import static org.lfenergy.compas.sct.commons.util.LDeviceStatus.ON;

/**
* A representation of the model object
Expand All @@ -41,17 +40,16 @@ public class InputsAdapter extends SclElementAdapter<LN0Adapter, TInputs> {
private static final String MESSAGE_NO_MATCHING_COMPAS_FLOW = "The signal ExtRef has no matching compas:Flow Private";
private static final String MESSAGE_TOO_MANY_MATCHING_COMPAS_FLOWS = "The signal ExtRef has more than one matching compas:Flow Private";
private static final String MESSAGE_SOURCE_LDEVICE_NOT_FOUND = "The signal ExtRef ExtRefldinst does not match any " +
"LDevice with same inst attribute in source IED %s";
"LDevice with same inst attribute in source IED %s";
private static final String MESSAGE_SOURCE_LN_NOT_FOUND = "The signal ExtRef lninst, doName or daName does not match any " +
"source in LDevice %s";
"source in LDevice %s";
private static final String MESSAGE_SERVICE_TYPE_MISSING = "The signal ExtRef is missing ServiceType attribute";
private static final String MESSAGE_INVALID_SERVICE_TYPE = "The signal ExtRef ServiceType attribute is unexpected : %s";
private static final String MESSAGE_IED_MISSING_COMPAS_BAY_UUID = "IED is missing Private/compas:Bay@UUID attribute";
private static final String MESSAGE_EXTREF_DESC_MALFORMED = "ExtRef.serviceType=Report but ExtRef.desc attribute is malformed";
private static final String MESSAGE_LDEVICE_STATUS_UNDEFINED = "The LDevice status is undefined";
private static final String MESSAGE_LDEVICE_STATUS_NEITHER_ON_NOR_OFF = "The LDevice status is neither \"on\" nor \"off\"";
private static final String MESSAGE_EXTREF_IEDNAME_DOES_NOT_MATCH_ANY_SYSTEM_VERSION_UUID = "The signal ExtRef iedName does not match any " +
"IED/Private/compas:ICDHeader@ICDSystemVersionUUID";
"IED/Private/compas:ICDHeader@ICDSystemVersionUUID";
private static final String MESSAGE_SOURCE_LDEVICE_STATUS_UNDEFINED = "The signal ExtRef source LDevice %s status is undefined";
private static final String MESSAGE_SOURCE_LDEVICE_STATUS_NEITHER_ON_NOR_OFF = "The signal ExtRef source LDevice %s status is neither \"on\" nor \"off\"";
private static final String MESSAGE_SOURCE_LDEVICE_STATUS_OFF = "The signal ExtRef source LDevice %s status is off";
Expand Down Expand Up @@ -97,33 +95,36 @@ public List<SclReportItem> updateAllExtRefIedNames(Map<String, IEDAdapter> icdSy
if (optionalLDeviceStatus.isEmpty()) {
return List.of(getLDeviceAdapter().buildFatalReportItem(MESSAGE_LDEVICE_STATUS_UNDEFINED));
}
String lDeviceStatus = optionalLDeviceStatus.get();
return switch (lDeviceStatus) {
case ON -> getExtRefs().stream()
.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);
yield Collections.emptyList();
}
default -> List.of(getLDeviceAdapter().buildFatalReportItem(MESSAGE_LDEVICE_STATUS_NEITHER_ON_NOR_OFF));
};
try {
LdeviceStatus lDeviceStatus = LdeviceStatus.fromValue(optionalLDeviceStatus.get());
return switch (lDeviceStatus) {
case ON -> getExtRefs().stream()
.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);
yield Collections.emptyList();
}
};
} catch (IllegalArgumentException e) {
return List.of(getLDeviceAdapter().buildFatalReportItem(e.getMessage()));
}
}

/**
* Find matching CompasFlow private and set ExtRef iedName accordingly
*
* @param extRef extRef whose iedName will be updated
* @param extRef extRef whose iedName will be updated
* @return Error if ExtRef could not be updated
*/
private Optional<SclReportItem> updateExtRefIedName(TExtRef extRef, IEDAdapter sourceIed) {
List<TCompasFlow> matchingCompasFlows = getMatchingCompasFlows(extRef);
if (!singleMatch(matchingCompasFlows)) {
return fatalReportItem(extRef,
matchingCompasFlows.isEmpty() ? MESSAGE_NO_MATCHING_COMPAS_FLOW : MESSAGE_TOO_MANY_MATCHING_COMPAS_FLOWS);
matchingCompasFlows.isEmpty() ? MESSAGE_NO_MATCHING_COMPAS_FLOW : MESSAGE_TOO_MANY_MATCHING_COMPAS_FLOWS);
}
TCompasFlow compasFlow = matchingCompasFlows.get(0);
if (compasFlow.getFlowStatus() == TCompasFlowStatus.INACTIVE) {
Expand All @@ -136,7 +137,7 @@ private Optional<SclReportItem> updateExtRefIedName(TExtRef extRef, IEDAdapter s
return sourceValidationError;
}
String sourceIedName = PrivateService.extractCompasPrivate(sourceIed.getCurrentElem(), TCompasICDHeader.class)
.map(TCompasICDHeader::getIEDName).orElse("");
.map(TCompasICDHeader::getIEDName).orElse("");
extRef.setIedName(sourceIedName);
compasFlow.setExtRefiedName(sourceIedName);
log.debug(String.format("extRef.desc=%s, iedName=%s%n", extRef.getDesc(), sourceIedName));
Expand Down Expand Up @@ -170,17 +171,19 @@ private Optional<SclReportItem> validateExtRefSource(TExtRef extRef, IEDAdapter
Optional<String> optionalSourceLDeviceStatus = sourceLDevice.getLDeviceStatus();
if (optionalSourceLDeviceStatus.isEmpty()) {
return fatalReportItem(extRef, String.format(MESSAGE_SOURCE_LDEVICE_STATUS_UNDEFINED,
sourceLDevice.getXPath()));
}
return optionalSourceLDeviceStatus.map(sourceLDeviceStatus ->
switch (sourceLDeviceStatus) {
case OFF -> SclReportItem.warning(extRefXPath(extRef.getDesc()), String.format(MESSAGE_SOURCE_LDEVICE_STATUS_OFF,
sourceLDevice.getXPath()));
case ON -> null;
default -> SclReportItem.fatal(extRefXPath(extRef.getDesc()),
String.format(MESSAGE_SOURCE_LDEVICE_STATUS_NEITHER_ON_NOR_OFF,
sourceLDevice.getXPath()));
});
}
return optionalSourceLDeviceStatus.map(sourceLDeviceStatus -> {
try {
LdeviceStatus lDeviceStatus = LdeviceStatus.fromValue(sourceLDeviceStatus);
return switch (lDeviceStatus) {
case OFF -> SclReportItem.warning(extRefXPath(extRef.getDesc()), String.format(MESSAGE_SOURCE_LDEVICE_STATUS_OFF, sourceLDevice.getXPath()));
case ON -> null;
};
} catch (IllegalArgumentException e) {
return SclReportItem.fatal(extRefXPath(extRef.getDesc()), String.format(MESSAGE_SOURCE_LDEVICE_STATUS_NEITHER_ON_NOR_OFF, sourceLDevice.getXPath()));
}
});
}

private boolean singleMatch(List<TCompasFlow> matchingCompasFlows) {
Expand Down Expand Up @@ -213,13 +216,13 @@ private Optional<SclReportItem> fatalReportItem(TExtRef extRef, String message)

private String extRefXPath(String extRefDesc) {
return getXPath() + String.format("/ExtRef[%s]",
Utils.xpathAttributeFilter("desc", extRefDesc));
Utils.xpathAttributeFilter("desc", extRefDesc));
}

/**
* Find CompasFlows that match given ExtRef
*
* @param extRef extRef to match
* @param extRef extRef to match
* @return list of matching CompasFlows
*/
private List<TCompasFlow> getMatchingCompasFlows(TExtRef extRef) {
Expand All @@ -239,18 +242,18 @@ private List<TCompasFlow> getMatchingCompasFlows(TExtRef extRef) {
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());
&& 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();
}

private AbstractLNAdapter<?> getLNAdapter(){
private AbstractLNAdapter<?> getLNAdapter() {
return parentAdapter;
}

Expand All @@ -260,19 +263,19 @@ public List<SclReportItem> updateAllSourceDataSetsAndControlBlocks() {
return List.of(getIedAdapter().buildFatalReportItem(MESSAGE_IED_MISSING_COMPAS_BAY_UUID));
}
return getExtRefs().stream()
.filter(this::areBindingAttributesPresent)
.filter(this::isExternalBound)
.filter(this::matchingCompasFlowIsActiveOrUntested)
.map(extRef -> updateSourceDataSetsAndControlBlocks(extRef, currentBayUuid))
.flatMap(Optional::stream)
.toList();
.filter(this::areBindingAttributesPresent)
.filter(this::isExternalBound)
.filter(this::matchingCompasFlowIsActiveOrUntested)
.map(extRef -> updateSourceDataSetsAndControlBlocks(extRef, currentBayUuid))
.flatMap(Optional::stream)
.toList();
}

private boolean matchingCompasFlowIsActiveOrUntested(TExtRef extRef) {
return getMatchingCompasFlows(extRef).stream().findFirst()
.map(TCompasFlow::getFlowStatus)
.filter(flowStatus -> flowStatus == TCompasFlowStatus.ACTIVE || flowStatus == TCompasFlowStatus.UNTESTED)
.isPresent();
.map(TCompasFlow::getFlowStatus)
.filter(flowStatus -> flowStatus == TCompasFlowStatus.ACTIVE || flowStatus == TCompasFlowStatus.UNTESTED)
.isPresent();
}

private boolean isExternalBound(TExtRef tExtRef) {
Expand All @@ -281,10 +284,10 @@ private boolean isExternalBound(TExtRef tExtRef) {

private boolean areBindingAttributesPresent(TExtRef tExtRef) {
return StringUtils.isNotBlank(tExtRef.getIedName())
&& StringUtils.isNotBlank(tExtRef.getDesc())
&& StringUtils.isNotBlank(tExtRef.getLdInst())
&& tExtRef.getLnClass().stream().findFirst().filter(StringUtils::isNotBlank).isPresent()
&& StringUtils.isNotBlank(tExtRef.getDoName());
&& StringUtils.isNotBlank(tExtRef.getDesc())
&& StringUtils.isNotBlank(tExtRef.getLdInst())
&& tExtRef.getLnClass().stream().findFirst().filter(StringUtils::isNotBlank).isPresent()
&& StringUtils.isNotBlank(tExtRef.getDoName());
}

private Optional<SclReportItem> updateSourceDataSetsAndControlBlocks(TExtRef extRef, String targetBayUuid) {
Expand All @@ -297,8 +300,8 @@ private Optional<SclReportItem> updateSourceDataSetsAndControlBlocks(TExtRef ext
}
IEDAdapter sourceIed = optionalSrcIedAdapter.get();
Optional<String> sourceIedBayUuid = sourceIed.getPrivateCompasBay()
.map(TCompasBay::getUUID)
.filter(StringUtils::isNotBlank);
.map(TCompasBay::getUUID)
.filter(StringUtils::isNotBlank);
if (sourceIedBayUuid.isEmpty()) {
return fatalReportItem(extRef, MESSAGE_SOURCE_IED_MISSING_COMPAS_BAY_UUID);
}
Expand Down Expand Up @@ -342,9 +345,9 @@ private void createDataSetWithFCDA(TExtRef extRef, LDeviceAdapter sourceLDevice,
String fcdaDaName = extRef.getServiceType() == TServiceType.REPORT ? null : sourceDa.getDaRef();
String fcdaLnClass = extRef.getLnClass().stream().findFirst().orElse(null);
dataSetAdapter.createFCDAIfNotExists(extRef.getLdInst(), extRef.getPrefix(), fcdaLnClass, extRef.getLnInst(),
sourceDa.getDoRef(),
fcdaDaName,
sourceDa.getFc());
sourceDa.getDoRef(),
fcdaDaName,
sourceDa.getFc());
}

private void createControlBlockWithTarget(TExtRef extRef, LDeviceAdapter sourceLDevice, DataAttributeRef sourceDa, String cbName, String datSet) {
Expand Down
Loading
Loading