Skip to content

Commit

Permalink
apply correction after code review
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 Sep 30, 2022
1 parent 36f8d9d commit 71ebbd5
Show file tree
Hide file tree
Showing 29 changed files with 300 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public boolean isValImport(){
return daName.isValImport();
}

public ResumedDataTemplate setNewVal(String daiValue) {
public ResumedDataTemplate setVal(String daiValue) {
TVal newDaiVal = new TVal();
newDaiVal.setValue(daiValue);
this.setDaiValues(List.of(newDaiVal));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@Builder
public class SclReport {

private SclRootAdapter scdFile;
private SclRootAdapter sclRootAdapter;

private List<ErrorDescription> errorDescriptionList = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.lfenergy.compas.scl2007b4.model.TCompasLDeviceStatus;
import org.lfenergy.compas.sct.commons.util.STValEnum;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

Expand All @@ -23,11 +22,9 @@
public class LDeviceActivation {

private final List<Pair<String, String>> iedNameLdInstList;

private TCompasLDeviceStatus compasLDeviceStatus;
private boolean isUpdatable;
private String newVal;
private List<String> errorMessages = new ArrayList<>();
private String errorMessage;

public LDeviceActivation(List<Pair<String, String>> iedNameLdInstList) {
this.iedNameLdInstList = iedNameLdInstList;
Expand All @@ -42,24 +39,22 @@ public LDeviceActivation(List<Pair<String, String>> iedNameLdInstList) {
*/
public void checkLDeviceActivationStatus(String iedName, String ldInst, TCompasLDeviceStatus compasLDeviceStatus, Set<String> enumValues) {
if (!enumValues.contains(STValEnum.ON.value) && !enumValues.contains(STValEnum.OFF.value)) {
errorMessages.add(String.format("Unexpected error: The IED@%s/LDevice@%s cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.",
iedName, ldInst));
errorMessage = "The LDevice cannot be activated or desactivated because its BehaviourKind Enum contains NOT 'on' AND NOT 'off'.";
}
if (!enumValues.contains(STValEnum.ON.value) && enumValues.contains(STValEnum.OFF.value)) {
if (isAuthorized(iedName, ldInst)) {
errorMessages.add(String.format("Unexpected error: The IED@%s/LDevice@%s cannot be set to 'on' but has been selected into SSD: this case should not occur.",
iedName, ldInst));
if (isDeclaredInSubstation(iedName, ldInst)) {
errorMessage = "The LDevice cannot be set to 'on' but has been selected into SSD.";
} else {
isUpdatable = true;
newVal = STValEnum.OFF.value;
}
}
if(compasLDeviceStatus.equals(TCompasLDeviceStatus.ACTIVE) ||
compasLDeviceStatus.equals(TCompasLDeviceStatus.UNTESTED)){
isAuthorizedToActivateLDevice(iedName, ldInst, enumValues);
checkAuthorisationToActivateLDevice(iedName, ldInst, enumValues);
}
if(compasLDeviceStatus.equals(TCompasLDeviceStatus.INACTIVE)){
isAuthorizedToDeactivateLDevice(iedName, ldInst, enumValues);
checkAuthorisationToDeactivateLDevice(iedName, ldInst, enumValues);
}
}

Expand All @@ -69,19 +64,18 @@ public void checkLDeviceActivationStatus(String iedName, String ldInst, TCompasL
* @param ldInst LDevice inst value
* @param enumValues enum values
*/
private void isAuthorizedToActivateLDevice(String iedName, String ldInst, Set<String> enumValues) {
private void checkAuthorisationToActivateLDevice(String iedName, String ldInst, Set<String> enumValues) {
if (!enumValues.contains(STValEnum.OFF.value) && enumValues.contains(STValEnum.ON.value)) {
if (isAuthorized(iedName, ldInst)) {
if (isDeclaredInSubstation(iedName, ldInst)) {
isUpdatable = true;
newVal = STValEnum.ON.value;
} else {
errorMessages.add(String.format("Unexpected error: The IED@%s/LDevice@%s cannot be set to 'off' but has not been selected into SSD: this case should not occur.",
iedName, ldInst));
errorMessage = "The LDevice cannot be set to 'off' but has not been selected into SSD.";
}
}
if (enumValues.contains(STValEnum.ON.value) && enumValues.contains(STValEnum.OFF.value)) {
isUpdatable = true;
if (isAuthorized(iedName, ldInst)) {
if (isDeclaredInSubstation(iedName, ldInst)) {
newVal = STValEnum.ON.value;
} else {
newVal = STValEnum.OFF.value;
Expand All @@ -96,20 +90,17 @@ private void isAuthorizedToActivateLDevice(String iedName, String ldInst, Set<St
* @param ldInst LDevice inst value
* @param enumValues enum values
*/
private void isAuthorizedToDeactivateLDevice(String iedName, String ldInst, Set<String> enumValues) {
private void checkAuthorisationToDeactivateLDevice(String iedName, String ldInst, Set<String> enumValues) {
if (!enumValues.contains(STValEnum.OFF.value) && enumValues.contains(STValEnum.ON.value)) {
if (isAuthorized(iedName, ldInst)) {
errorMessages.add(String.format("Unexpected error: The IED@%s/LDevice@%s is not qualified into STD but has been selected into SSD: this case should not occur.",
iedName, ldInst));
if (isDeclaredInSubstation(iedName, ldInst)) {
errorMessage = "The LDevice is not qualified into STD but has been selected into SSD.";
} else {
errorMessages.add(String.format("Unexpected error: The IED@%s/LDevice@%s cannot be set to 'off' but has not been selected into SSD: this case should not occur.",
iedName, ldInst));
errorMessage = "The LDevice cannot be set to 'off' but has not been selected into SSD.";
}
}
if (enumValues.contains(STValEnum.ON.value) && enumValues.contains(STValEnum.OFF.value)) {
if (isAuthorized(iedName, ldInst)) {
errorMessages.add(String.format("Unexpected error: The IED@%s/LDevice@%s is not qualified into STD but has been selected into SSD: this case should not occur.",
iedName, ldInst));
if (isDeclaredInSubstation(iedName, ldInst)) {
errorMessage = "The LDevice is not qualified into STD but has been selected into SSD.";
} else {
isUpdatable = true;
newVal = STValEnum.OFF.value;
Expand All @@ -123,7 +114,7 @@ private void isAuthorizedToDeactivateLDevice(String iedName, String ldInst, Set<
* @param ldInst LDevice inst value
* @return Returns whether a pair of IED name and LDevice inst are referenced in Substation...LNode list
*/
private boolean isAuthorized(String iedName, String ldInst){
private boolean isDeclaredInSubstation(String iedName, String ldInst){
return iedNameLdInstList.contains(Pair.of(iedName, ldInst));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ public static void removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(final S
public static SclReport updateLDeviceStatus(SCL scd) {
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
SubstationAdapter substationAdapter = sclRootAdapter.getSubstationAdapter();
final List<Pair<String, String>> iedNameLdInstList = substationAdapter.getLDevicesFromLNode(true);
final List<Pair<String, String>> iedNameLdInstList = substationAdapter.getIedAndLDeviceNamesForLN0FromLNode();
List<SclReport.ErrorDescription> errors = sclRootAdapter.getIEDAdapters().stream()
.map(IEDAdapter::getLDeviceAdapters)
.flatMap(Collection::stream)
Expand All @@ -701,7 +701,7 @@ public static SclReport updateLDeviceStatus(SCL scd) {
});
SclReport sclReport = new SclReport();
sclReport.getErrorDescriptionList().addAll(errors);
sclReport.setScdFile(sclRootAdapter);
sclReport.setSclRootAdapter(sclRootAdapter);
return sclReport;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ protected boolean amChildElementRef() {

@Override
protected String elementXPath() {
return String.format("BDA[name=%s]",
return String.format("BDA[%s]",
Utils.xpathAttributeFilter("name", currentElem.isSetName() ? currentElem.getName() : null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected boolean amChildElementRef() {

@Override
protected String elementXPath() {
return String.format("DO[name=%s and type=%s]",
return String.format("DO[%s and %s]",
Utils.xpathAttributeFilter("name", currentElem.isSetName() ? currentElem.getName() : null),
Utils.xpathAttributeFilter("type", currentElem.isSetType() ? currentElem.getType() : null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected boolean amChildElementRef() {

@Override
protected String elementXPath() {
return String.format("LNodeType[id=%s and lnClass=%s]",
return String.format("LNodeType[%s and %s]",
Utils.xpathAttributeFilter("id", currentElem.isSetId() ? currentElem.getId() : null),
Utils.xpathAttributeFilter("lnClass", currentElem.isSetLnClass() ? currentElem.getLnClass() : null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ public static LNAdapterBuilder builder(){
* @param enumType enum Type
* @return Enum value list
*/
public Set<String> getEnumValue(String enumType) {
public Set<String> getEnumValues(String enumType) {
Optional<EnumTypeAdapter> enumTypeAdapter = parentAdapter
.getParentAdapter().getParentAdapter().getDataTypeTemplateAdapter()
.getEnumTypeAdapterById(enumType);

if(enumTypeAdapter.isEmpty()){
return new HashSet<>();
return Collections.emptySet();
}
return enumTypeAdapter.get().getCurrentElem().getEnumVal()
.stream().map(TEnumVal::getValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected boolean amChildElementRef() {

@Override
protected String elementXPath() {
return String.format("DOI[name=%s]",
return String.format("DOI[%s]",
Utils.xpathAttributeFilter("name", currentElem.isSetName() ? currentElem.getName() : null));
}

Expand Down Expand Up @@ -170,7 +170,7 @@ protected boolean amChildElementRef() {

@Override
protected String elementXPath() {
return String.format("DAI[name=%s]",
return String.format("DAI[%s]",
Utils.xpathAttributeFilter("name", currentElem.isSetName() ? currentElem.getName() : null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

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

/**
* A representation of the model object
Expand Down Expand Up @@ -88,7 +89,7 @@ protected boolean amChildElementRef() {

@Override
protected String elementXPath() {
return String.format("LN[lnClass=LLN0 and %s and %s]",
return String.format("LN[lnClass=\"LLN0\" and %s and %s]",
Utils.xpathAttributeFilter("inst", currentElem.isSetInst() ? currentElem.getInst() : null),
Utils.xpathAttributeFilter("lnType", currentElem.isSetLnType() ? currentElem.getLnType() : null));
}
Expand Down Expand Up @@ -176,81 +177,57 @@ public List<SclReport.ErrorDescription> checkAndUpdateLDeviceStatus(List<Pair<St
LDeviceActivation lDeviceActivation = new LDeviceActivation(iedNameLDeviceInstList);
final String iedName = getParentAdapter().getParentAdapter().getName();
final String ldInst = getParentAdapter().getInst();
final String behaviourDoName = "Beh";
final String targetDoName = "Mod";
final String targetDaName = "stVal";
DaTypeName daTypeNameBeh = new DaTypeName();
daTypeNameBeh.setName(targetDaName);
daTypeNameBeh.setName(STVAL);
daTypeNameBeh.setBType(TPredefinedBasicTypeEnum.ENUM);
daTypeNameBeh.setFc(TFCEnum.ST);
ResumedDataTemplate daiBehFilter = getResumedDataTemplate(behaviourDoName, daTypeNameBeh);
ResumedDataTemplate daiBehFilter = getResumedDataTemplate(BEHAVIOUR_DO_NAME, daTypeNameBeh);
List<ResumedDataTemplate> daiBehList = getDAI(daiBehFilter, false);
if (daiBehList.isEmpty()) {
buildErrorMessage(errors, getXPath(),
"The IED@%s/LDevice@%s doesn't have a DO @name='Beh' OR its associated DA@fc='ST' AND DA@name='stVal'",
iedName, ldInst);
errors.add(buildErrorDescriptionMessage("The LDevice doesn't have a DO @name='Beh' OR its associated DA@fc='ST' AND DA@name='stVal'"));
return errors;
}
Set<String> enumValues = getEnumValue(daiBehList.get(0).getDaName().getType());
Set<String> enumValues = getEnumValues(daiBehList.get(0).getDaName().getType());
List<TCompasLDevice> compasLDevicePrivateList = PrivateService.getCompasPrivates(getParentAdapter().getCurrentElem(), TCompasLDevice.class);
if (compasLDevicePrivateList.isEmpty()) {
buildErrorMessage(errors, getXPath(),
"The IED@%s/LDevice@%s doesn't have a Private compas:LDevice.",
iedName, ldInst);
errors.add(buildErrorDescriptionMessage("The LDevice doesn't have a Private compas:LDevice."));
return errors;
}
if (!compasLDevicePrivateList.get(0).isSetLDeviceStatus()) {
buildErrorMessage(errors, getXPath(),
"The IED@%s/LDevice@%s Private compas:LDevice doesn't have the attribute 'LDeviceStatus'",
iedName, ldInst);
errors.add(buildErrorDescriptionMessage("The Private compas:LDevice doesn't have the attribute 'LDeviceStatus'"));
return errors;
}
TCompasLDeviceStatus compasLDeviceStatus = compasLDevicePrivateList.get(0).getLDeviceStatus();
DaTypeName daTypeNameMod = new DaTypeName();
daTypeNameMod.setName(targetDaName);
ResumedDataTemplate daiModFilter = getResumedDataTemplate(targetDoName, daTypeNameMod);
daTypeNameMod.setName(STVAL);
ResumedDataTemplate daiModFilter = getResumedDataTemplate(MOD_DO_NAME, daTypeNameMod);
List<ResumedDataTemplate> daiModList = getDAI(daiModFilter, false);
if (daiModList.isEmpty()) {
buildErrorMessage(errors, getXPath(),
"The IED@%s/LDevice@%s doesn't have a DO @name='Mod'",
iedName, ldInst);
errors.add(buildErrorDescriptionMessage("The LDevice doesn't have a DO @name='Mod'"));
return errors;
}
ResumedDataTemplate newDaModToSetInLN0 = daiModList.get(0);
String initialValue = newDaModToSetInLN0.getDaName().getDaiValues().isEmpty() ? "" : newDaModToSetInLN0.getDaName().getDaiValues().values().toArray()[0].toString();
lDeviceActivation.checkLDeviceActivationStatus(iedName, ldInst, compasLDeviceStatus, enumValues);
if(lDeviceActivation.isUpdatable()){
if(!initialValue.equals(lDeviceActivation.getNewVal())) {
newDaModToSetInLN0.setNewVal(lDeviceActivation.getNewVal());
newDaModToSetInLN0.setVal(lDeviceActivation.getNewVal());
updateDAI(newDaModToSetInLN0);
}
}else {
List<SclReport.ErrorDescription> errorDescriptionList = lDeviceActivation.getErrorMessages()
.stream()
.map(errorMessage -> SclReport.ErrorDescription.builder()
.xpath(getXPath())
.message(errorMessage)
.build())
.collect(Collectors.toList());
errors.addAll(errorDescriptionList);
if(lDeviceActivation.getErrorMessage() != null) {
errors.add(buildErrorDescriptionMessage(lDeviceActivation.getErrorMessage()));}
}
return errors;
}

/**
* Update ErrorDescription list of SclReport object with given xpath and message
* @param errors input parameter
* @param xpath input parameter
* @param message input parameter
* @param iedName input parameter
* @param ldInst input parameter
* builds message with message content and xpath
* @param message message to return
* @return error description with message and xpath as SclReport.ErrorDescription object
*/
private void buildErrorMessage(List<SclReport.ErrorDescription> errors, String xpath, String message, String iedName, String ldInst) {
String msg = String.format(message, iedName, ldInst);
errors.add(SclReport.ErrorDescription.builder()
.message(msg)
.xpath(xpath)
.build());
private SclReport.ErrorDescription buildErrorDescriptionMessage(String message){
return SclReport.ErrorDescription.builder().message(message).xpath(getXPath()).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected boolean amChildElementRef() {

@Override
protected String elementXPath() {
return String.format("SDI[name=%s]",
return String.format("SDI[%s]",
Utils.xpathAttributeFilter("name", currentElem.isSetName() ? currentElem.getName() : null));
}

Expand Down Expand Up @@ -162,7 +162,7 @@ protected boolean amChildElementRef() {

@Override
protected String elementXPath() {
return String.format("DAI[name=%s]",
return String.format("DAI[%s]",
Utils.xpathAttributeFilter("name", currentElem.isSetName() ? currentElem.getName() : null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected boolean amChildElementRef() {

@Override
protected String elementXPath() {
return String.format("SDI[name=%s]",
return String.format("SDI[%s]",
Utils.xpathAttributeFilter("name", currentElem.isSetName() ? currentElem.getName() : null));
}

Expand Down Expand Up @@ -171,7 +171,7 @@ protected boolean amChildElementRef() {

@Override
protected String elementXPath() {
return String.format("DAI[name=%s]",
return String.format("DAI[%s]",
Utils.xpathAttributeFilter("name", currentElem.isSetName() ? currentElem.getName() : null));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,15 @@ public Stream<VoltageLevelAdapter> streamVoltageLevelAdapters() {
}

/**
* Gets a pair of IedName and LDevice inst from Substation LNodes for given LN type object
* @param isLN0 filter for LN type
* Gets a pair of IedName and LDevice inst from Substation LNodes for LN0 type object
* @return a pair of Ied name and LDevice inst attributes
*/
public List<Pair<String, String>> getLDevicesFromLNode(boolean isLN0) {
public List<Pair<String, String>> getIedAndLDeviceNamesForLN0FromLNode() {
return streamVoltageLevelAdapters()
.flatMap(VoltageLevelAdapter::streamBayAdapters)
.flatMap(BayAdapter::streamFunctionAdapters)
.flatMap(functionAdapter -> functionAdapter.getCurrentElem().getLNode().stream())
.filter(tlNode -> !isLN0 || tlNode.getLnClass().contains(TLLN0Enum.LLN_0.value()))
.filter(tlNode -> tlNode.getLnClass().contains(TLLN0Enum.LLN_0.value()))
.map(tlNode -> Pair.of(tlNode.getIedName(), tlNode.getLdInst()))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public final class CommonConstants {
public static final String HEADER_ID = "headerId";
public static final String HEADER_VERSION = "headerVersion";
public static final String HEADER_REVISION = "headerRevision";
public static String BEHAVIOUR_DO_NAME = "Beh";
public static String MOD_DO_NAME = "Mod";
public static String STVAL = "stVal";

/**
* Private Controlller, should not be instanced
Expand Down
Loading

0 comments on commit 71ebbd5

Please sign in to comment.