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 29, 2022
1 parent 36f8d9d commit bea0422
Show file tree
Hide file tree
Showing 29 changed files with 178 additions and 183 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 @@ -23,8 +23,6 @@
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<>();
Expand All @@ -42,24 +40,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));
errorMessages.add("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)) {
errorMessages.add("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 +65,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));
errorMessages.add("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 +91,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)) {
errorMessages.add("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));
errorMessages.add("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)) {
errorMessages.add("The LDevice is not qualified into STD but has been selected into SSD.");
} else {
isUpdatable = true;
newVal = STValEnum.OFF.value;
Expand All @@ -123,7 +115,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 @@ -18,6 +18,8 @@
import java.util.Set;
import java.util.stream.Collectors;

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

/**
* A representation of the model object
* <em><b>{@link org.lfenergy.compas.sct.commons.scl.ied.LN0Adapter LN0Adapter}</b></em>.
Expand Down Expand Up @@ -88,7 +90,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,43 +178,40 @@ 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'",
"The LDevice doesn't have a DO @name='Beh' OR its associated DA@fc='ST' AND DA@name='stVal'",
iedName, ldInst);
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.",
"The LDevice doesn't have a Private compas:LDevice.",
iedName, ldInst);
return errors;
}
if (!compasLDevicePrivateList.get(0).isSetLDeviceStatus()) {
buildErrorMessage(errors, getXPath(),
"The IED@%s/LDevice@%s Private compas:LDevice doesn't have the attribute 'LDeviceStatus'",
"The Private compas:LDevice doesn't have the attribute 'LDeviceStatus'",
iedName, ldInst);
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'",
"The LDevice doesn't have a DO @name='Mod'",
iedName, ldInst);
return errors;
}
Expand All @@ -221,7 +220,7 @@ public List<SclReport.ErrorDescription> checkAndUpdateLDeviceStatus(List<Pair<St
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 {
Expand Down
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 bea0422

Please sign in to comment.