Skip to content

Commit

Permalink
feat: rename SclReportItem#fatal to SclReportItem#error
Browse files Browse the repository at this point in the history
Signed-off-by: Samir Romdhani <samir.romdhani@rte-france.com>
  • Loading branch information
samirromdhani committed Aug 14, 2023
1 parent a02d8b0 commit 7b0d799
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
// SPDX-FileCopyrightText: 2022 RTE FRANCE
// SPDX-FileCopyrightText: 2022 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

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

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
public record SclReportItem(String xpath, String message, boolean isError) {

@Getter
@EqualsAndHashCode
@AllArgsConstructor
@ToString
public final class SclReportItem {
private final String xpath;
private final String message;
private final boolean isFatal;

public static SclReportItem fatal(String xpath, String message) {
public static SclReportItem error(String xpath, String message) {
return new SclReportItem(xpath, message, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static List<SclReportItem> checkIedUnityOfIcdSystemVersionUuid(SclRootAd
return systemVersionToIedList.entrySet().stream()
.filter(entry -> StringUtils.isNotBlank(entry.getKey()))
.filter(entry -> entry.getValue().size() > 1)
.map(entry -> SclReportItem.fatal(entry.getValue().stream()
.map(entry -> SclReportItem.error(entry.getValue().stream()
.map(tied -> new IEDAdapter(sclRootAdapter, tied))
.map(IEDAdapter::getXPath)
.collect(Collectors.joining(", ")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ public String getXPath(){
* @return error description with message and current element xpath
*/
public SclReportItem buildFatalReportItem(String message){
return SclReportItem.fatal(getXPath(), message);
return SclReportItem.error(getXPath(), message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public List<SclReportItem> checkFCDALimitations() {
.map(abstractLNAdapter -> abstractLNAdapter.getCurrentElem().getDataSet())
.flatMap(Collection::stream)
.filter(tDataSet -> tDataSet.getFCDA().size() > max)
.map(tDataSet -> SclReportItem.fatal(getXPath(), String.format("There are too much FCDA for the DataSet %s for the LDevice %s"
.map(tDataSet -> SclReportItem.error(getXPath(), String.format("There are too much FCDA for the DataSet %s for the LDevice %s"
+ " in IED %s: %d > %d max", tDataSet.getName(), lDeviceAdapter.getInst(), parentAdapter.getName(),
tDataSet.getFCDA().size(), max))
).toList()
Expand All @@ -106,7 +106,7 @@ public List<SclReportItem> checkFCDALimitations() {
public Optional<SclReportItem> checkControlsLimitation(ServicesConfigEnum servicesConfigEnum) {
long max = getMaxInstanceAuthorized(servicesConfigEnum);
long value = getNumberOfItems(servicesConfigEnum);
return max == MAX_OCCURRENCE_NO_LIMIT_VALUE || value <= max ? Optional.empty() : Optional.of(SclReportItem.fatal(getXPath(),
return max == MAX_OCCURRENCE_NO_LIMIT_VALUE || value <= max ? Optional.empty() : Optional.of(SclReportItem.error(getXPath(),
String.format("There are too much %ss for the IED %s: %d > %d max", servicesConfigEnum.getDisplayName(), parentAdapter.getName(), value, max)));
}

Expand Down Expand Up @@ -212,7 +212,7 @@ public Optional<SclReportItem> checkLimitationForBoundIedFcdas(List<TExtRef> tEx
.size();

return value <= max ? Optional.empty() :
Optional.of(SclReportItem.fatal(getParentAdapter().getXPath(),
Optional.of(SclReportItem.error(getParentAdapter().getXPath(),
"The Client IED %s subscribes to too much FCDA: %d > %d max".formatted(getParentAdapter().getName(), value, max)));
}

Expand Down Expand Up @@ -256,7 +256,7 @@ private List<SclReportItem> checkExtRefWithoutServiceType(List<TExtRef> tExtRefs
return tExtRefs.stream()
.filter(tExtRef -> !tExtRef.isSetServiceType())
.map(tExtRef ->
SclReportItem.fatal("%s/Inputs/ExtRef[%s]".formatted(xPath,
SclReportItem.error("%s/Inputs/ExtRef[%s]".formatted(xPath,
Utils.xpathAttributeFilter("desc", tExtRef.getDesc())),
"ExtRef is missing ServiceType attribute"))
.toList();
Expand Down Expand Up @@ -288,7 +288,7 @@ private Optional<SclReportItem> checkLimitationForOneControlType(Set<TExtRef> tE
long max = getMaxInstanceAuthorizedForBoundIED(servicesConfigEnum);
long value = tExtRefs.size();
return max == AccessPointAdapter.MAX_OCCURRENCE_NO_LIMIT_VALUE || value <= max ? Optional.empty() :
Optional.of(SclReportItem.fatal(getParentAdapter().getXPath(),
Optional.of(SclReportItem.error(getParentAdapter().getXPath(),
"The Client IED %s subscribes to too much %ss: %d > %d max".formatted(getParentAdapter().getName(), servicesConfigEnum.getDisplayName(),
value, max)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private Optional<SclReportItem> validateExtRefSource(TExtRef extRef, IEDAdapter
case ON -> null;
};
} catch (IllegalArgumentException e) {
return SclReportItem.fatal(extRefXPath(extRef.getDesc()), String.format(MESSAGE_SOURCE_LDEVICE_STATUS_NEITHER_ON_NOR_OFF, sourceLDevice.getXPath()));
return SclReportItem.error(extRefXPath(extRef.getDesc()), String.format(MESSAGE_SOURCE_LDEVICE_STATUS_NEITHER_ON_NOR_OFF, sourceLDevice.getXPath()));
}
});
}
Expand Down Expand Up @@ -211,7 +211,7 @@ private Optional<SclReportItem> warningReportItem(TExtRef extRef, String message
}

private Optional<SclReportItem> fatalReportItem(TExtRef extRef, String message) {
return Optional.of(SclReportItem.fatal(extRefXPath(extRef.getDesc()), message));
return Optional.of(SclReportItem.error(extRefXPath(extRef.getDesc()), message));
}

private String extRefXPath(String extRefDesc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,9 @@ public List<ExtRefInfo.ExtRefBayReference> getExtRefBayReferenceForActifLDEPF(fi
List<ExtRefInfo.ExtRefBayReference> extRefBayReferenceList = new ArrayList<>();
IEDAdapter parentIedAdapter = getParentAdapter();
if (parentIedAdapter.getPrivateCompasBay().isEmpty()) {
sclReportItems.add(SclReportItem.fatal(getXPath(), "The IED has no Private Bay"));
sclReportItems.add(SclReportItem.error(getXPath(), "The IED has no Private Bay"));
if (parentIedAdapter.getCompasICDHeader().isEmpty()) {
sclReportItems.add(SclReportItem.fatal(getXPath(), "The IED has no Private compas:ICDHeader"));
sclReportItems.add(SclReportItem.error(getXPath(), "The IED has no Private compas:ICDHeader"));
}
return Collections.emptyList();
}
Expand All @@ -504,7 +504,7 @@ public List<ExtRefInfo.ExtRefBayReference> getExtRefBayReferenceForActifLDEPF(fi
if (LdeviceStatus.ON.equals(s)) {
extRefBayReferenceList.addAll(getLN0Adapter().getInputsAdapter().getCurrentElem().getExtRef().stream().map(extRef -> new ExtRefInfo.ExtRefBayReference(parentIedAdapter.getName(), parentIedAdapter.getPrivateCompasBay().get(), extRef)).toList());
}
}, () -> sclReportItems.add(SclReportItem.fatal(getXPath(), "There is no DOI@name=" + MOD_DO_TYPE_NAME + "/DAI@name=" + STVAL_DA_TYPE_NAME + "/Val for LDevice@inst" + LDEVICE_LDEPF)));
}, () -> sclReportItems.add(SclReportItem.error(getXPath(), "There is no DOI@name=" + MOD_DO_TYPE_NAME + "/DAI@name=" + STVAL_DA_TYPE_NAME + "/Val for LDevice@inst" + LDEVICE_LDEPF)));
return extRefBayReferenceList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void updateAllExtRefIedNames_should_return_success_status() {
// When
List<SclReportItem> sclReportItems = ExtRefService.updateAllExtRefIedNames(scd);
// Then
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isFatal))
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError))
.overridingErrorMessage(String.valueOf(sclReportItems))
.isTrue();
}
Expand All @@ -90,7 +90,7 @@ void updateAllExtRefIedNames_should_report_errors(String testCase, SCL scl, SclR
List<SclReportItem> sclReportItems = ExtRefService.updateAllExtRefIedNames(scl);
// Then : the sclReport should report all errors described in the comments in the SCD file
assertThat(sclReportItems).isNotNull();
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isFatal)).isFalse();
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isFalse();
assertThat(sclReportItems).containsExactlyInAnyOrder(errors);
}

Expand All @@ -100,18 +100,18 @@ public static Stream<Arguments> updateAllExtRefIedNamesErrors() {
"Errors on ExtRefs",
SclTestMarshaller.getSCLFromFile("/scd-extref-iedname/scd_set_extref_iedname_with_extref_errors.xml"),
new SclReportItem[]{
SclReportItem.fatal(
SclReportItem.error(
"/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST11\"]" +
"/LN0/Inputs/ExtRef[@desc=\"No matching compas:Flow\"]",
"The signal ExtRef has no matching compas:Flow Private"),
SclReportItem.fatal(
SclReportItem.error(
"/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST11\"]" +
"/LN0/Inputs/ExtRef[@desc=\"Matching two compas:Flow\"]",
"The signal ExtRef has more than one matching compas:Flow Private"),
SclReportItem.fatal(
SclReportItem.error(
"/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST13\"]",
"The Ldevice status test does not exist. It should be among [on, off]"),
SclReportItem.fatal(
SclReportItem.error(
"/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST14\"]",
"The LDevice status is undefined"),
SclReportItem.warning(
Expand All @@ -131,12 +131,12 @@ public static Stream<Arguments> updateAllExtRefIedNamesErrors() {
"/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST11\"]" +
"/LN0/Inputs/ExtRef[@desc=\"Source LDevice is off for this ExtRef\"]",
"The signal ExtRef source LDevice /SCL/IED[@name=\"IED_NAME2\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST22\"] status is off"),
SclReportItem.fatal(
SclReportItem.error(
"/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST11\"]" +
"/LN0/Inputs/ExtRef[@desc=\"Source LDevice is undefined for this ExtRef\"]",
"The signal ExtRef source LDevice /SCL/IED[@name=\"IED_NAME2\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST23\"] status is " +
"undefined"),
SclReportItem.fatal(
SclReportItem.error(
"/SCL/IED[@name=\"IED_NAME1\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST11\"]" +
"/LN0/Inputs/ExtRef[@desc=\"Source LDevice is neither on nor off for this ExtRef\"]",
"The signal ExtRef source LDevice /SCL/IED[@name=\"IED_NAME2\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST24\"] " +
Expand All @@ -146,12 +146,12 @@ public static Stream<Arguments> updateAllExtRefIedNamesErrors() {
"Errors on IEDs",
SclTestMarshaller.getSCLFromFile("/scd-extref-iedname/scd_set_extref_iedname_with_ied_errors.xml"),
new SclReportItem[]{
SclReportItem.fatal(
SclReportItem.error(
"/SCL/IED[@name=\"IED_NAME1\"], /SCL/IED[@name=\"IED_NAME2\"]",
"/IED/Private/compas:ICDHeader[@ICDSystemVersionUUID] must be unique but the same ICDSystemVersionUUID was found on several IED."),
SclReportItem.fatal("/SCL/IED[@name=\"IED_NAME3\"]", "IED has no Private COMPAS-ICDHeader element"),
SclReportItem.fatal("/SCL/IED[@name=\"IED_NAME4\"]", "IED private COMPAS-ICDHeader as no icdSystemVersionUUID or iedName attribute"),
SclReportItem.fatal("/SCL/IED[@name=\"IED_NAME5\"]", "IED private COMPAS-ICDHeader as no icdSystemVersionUUID or iedName attribute")
SclReportItem.error("/SCL/IED[@name=\"IED_NAME3\"]", "IED has no Private COMPAS-ICDHeader element"),
SclReportItem.error("/SCL/IED[@name=\"IED_NAME4\"]", "IED private COMPAS-ICDHeader as no icdSystemVersionUUID or iedName attribute"),
SclReportItem.error("/SCL/IED[@name=\"IED_NAME5\"]", "IED private COMPAS-ICDHeader as no icdSystemVersionUUID or iedName attribute")
})
);
}
Expand Down Expand Up @@ -420,7 +420,7 @@ void configureNetworkForAllControlBlocks_should_create_GSE_and_SMV_elements() {
// When
List<SclReportItem> sclReportItems = ExtRefService.configureNetworkForAllControlBlocks(scd, controlBlockNetworkSettings, RANGES_PER_CB_TYPE);
// Then
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isFatal)).isTrue();
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isTrue();
TConnectedAP connectedAP = new SclRootAdapter(scd).findConnectedApAdapter("IED_NAME2", "AP_NAME").get().getCurrentElem();
TGSE gse = connectedAP.getGSE().stream()
.filter(tgse -> "CB_LD_INST21_GSI".equals(tgse.getCbName()))
Expand Down Expand Up @@ -462,7 +462,7 @@ void configureNetworkForAllControlBlocks_should_create_GSE_with_incremental_appi
// When
List<SclReportItem> sclReportItems = ExtRefService.configureNetworkForAllControlBlocks(scd, controlBlockNetworkSettings, RANGES_PER_CB_TYPE);
// Then
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isFatal)).isTrue();
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isTrue();
assertThat(streamAllConnectedApGseP(scd, "APPID"))
.containsExactlyInAnyOrder("0009", "000A", "000B");
assertThat(streamAllConnectedApGseP(scd, "MAC-Address"))
Expand All @@ -479,9 +479,9 @@ void configureNetworkForAllControlBlocks_should_fail_when_no_settings_for_this_c
// When
List<SclReportItem> sclReportItems = ExtRefService.configureNetworkForAllControlBlocks(scd, controlBlockNetworkSettings, rangesPerCbType);
// Then
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isFatal)).isFalse();
assertThat(sclReportItems.stream().noneMatch(SclReportItem::isError)).isFalse();
assertThat(sclReportItems)
.extracting(SclReportItem::getMessage, SclReportItem::getXpath)
.extracting(SclReportItem::message, SclReportItem::xpath)
.contains(Tuple.tuple(expectedMessage,
"/SCL/IED[@name=\"IED_NAME2\"]/AccessPoint/Server/LDevice[@inst=\"LD_INST21\"]/LN0/GSEControl[@name=\"CB_LD_INST21_GMI\"]"));
}
Expand Down Expand Up @@ -704,7 +704,7 @@ void manageBindingForLDEPF_should_return_report_when_manyIedSourceFound() {
List<SclReportItem> sclReportItems = ExtRefService.manageBindingForLDEPF(scd, settings);
// Then
assertThat(sclReportItems).hasSize(2)
.extracting(SclReportItem::getMessage)
.extracting(SclReportItem::message)
.isEqualTo(List.of("There is more than one IED source to bind the signal /IED@name=IED_NAME2/LDevice@inst=LDEPF/LN0/ExtRef@desc=DYN_LDEPF_DIGITAL CHANNEL 1_1_BOOLEEN_1_general_1",
"There is more than one IED source to bind the signal /IED@name=IED_NAME3/LDevice@inst=LDEPF/LN0/ExtRef@desc=DYN_LDEPF_DIGITAL CHANNEL 1_1_BOOLEEN_1_general_1"));
TExtRef extRef1 = findExtRef(scd, "IED_NAME1", "LDEPF", "DYN_LDEPF_DIGITAL CHANNEL 1_1_BOOLEEN_1_general_1");
Expand Down
Loading

0 comments on commit 7b0d799

Please sign in to comment.