Skip to content

Commit

Permalink
[68][164] Activation used LDevice and Deactivation unused LDevice (#163)
Browse files Browse the repository at this point in the history
Signed-off-by: Aliou DIAITE <[email protected]>
Signed-off-by: Samir Romdhani <[email protected]>
Signed-off-by: Aliou DIAITE <[email protected]>
  • Loading branch information
samirromdhani authored and AliouDIAITE committed Oct 3, 2022
1 parent aa054b1 commit 4074d64
Show file tree
Hide file tree
Showing 63 changed files with 3,111 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,11 @@ public void setValImport(boolean valImport) {
public boolean isValImport(){
return daName.isValImport();
}

public ResumedDataTemplate setVal(String daiValue) {
TVal newDaiVal = new TVal();
newDaiVal.setValue(daiValue);
this.setDaiValues(List.of(newDaiVal));
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* // SPDX-FileCopyrightText: 2022 RTE FRANCE
* //
* // SPDX-License-Identifier: Apache-2.0
*/

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

import lombok.*;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;

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

@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
@Builder
public class SclReport {

private SclRootAdapter sclRootAdapter;

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

public boolean isSuccess() {
return errorDescriptionList.isEmpty();
}

@Getter
@Setter
@AllArgsConstructor
@ToString
@EqualsAndHashCode
@Builder
public static class ErrorDescription{
private String xpath;
private String message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// SPDX-FileCopyrightText: 2022 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

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

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.tuple.Pair;
import org.lfenergy.compas.scl2007b4.model.TCompasLDeviceStatus;
import org.lfenergy.compas.sct.commons.util.STValEnum;

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

/**
* Common class for all states that define if LDevice should be activated or not
* regardless of the CompasLDeviceStatus Private, Enum Values of DO 'Beh' and if it's referenced in Substation...LNode or not
*/
@Getter
@Setter
public class LDeviceActivation {

private final List<Pair<String, String>> iedNameLdInstList;
private boolean isUpdatable;
private String newVal;
private String errorMessage;

public LDeviceActivation(List<Pair<String, String>> iedNameLdInstList) {
this.iedNameLdInstList = iedNameLdInstList;
}

/**
* checks whether LDevice status is authorized to be activated or Not
* @param iedName Ied name value which LDevice appear
* @param ldInst LDevice inst value
* @param compasLDeviceStatus Private value
* @param enumValues enum values
*/
public void checkLDeviceActivationStatus(String iedName, String ldInst, TCompasLDeviceStatus compasLDeviceStatus, Set<String> enumValues) {
if (!enumValues.contains(STValEnum.ON.value) && !enumValues.contains(STValEnum.OFF.value)) {
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 (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)){
checkAuthorisationToActivateLDevice(iedName, ldInst, enumValues);
}
if(compasLDeviceStatus.equals(TCompasLDeviceStatus.INACTIVE)){
checkAuthorisationToDeactivateLDevice(iedName, ldInst, enumValues);
}
}

/**
* checks whether LDevice status is authorized to be activated when CompasLDeviceStatus Private is ACTIVE or UNTESTED
* @param iedName Ied name value which contains LDevice
* @param ldInst LDevice inst value
* @param enumValues enum values
*/
private void checkAuthorisationToActivateLDevice(String iedName, String ldInst, Set<String> enumValues) {
if (!enumValues.contains(STValEnum.OFF.value) && enumValues.contains(STValEnum.ON.value)) {
if (isDeclaredInSubstation(iedName, ldInst)) {
isUpdatable = true;
newVal = STValEnum.ON.value;
} else {
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 (isDeclaredInSubstation(iedName, ldInst)) {
newVal = STValEnum.ON.value;
} else {
newVal = STValEnum.OFF.value;
}
}

}

/**
* checks whether LDevice Status is authorized to be deactivated when CompasLDeviceStatus Private is INACTIVE
* @param iedName Ied name value which contains LDevice
* @param ldInst LDevice inst value
* @param enumValues enum values
*/
private void checkAuthorisationToDeactivateLDevice(String iedName, String ldInst, Set<String> enumValues) {
if (!enumValues.contains(STValEnum.OFF.value) && enumValues.contains(STValEnum.ON.value)) {
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(STValEnum.ON.value) && enumValues.contains(STValEnum.OFF.value)) {
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;
}
}
}

/**
* checks whether a pair of IED name and LDevice inst are referenced in Substation...LNode list
* @param iedName Ied name value
* @param ldInst LDevice inst value
* @return Returns whether a pair of IED name and LDevice inst are referenced in Substation...LNode list
*/
private boolean isDeclaredInSubstation(String iedName, String ldInst){
return iedNameLdInstList.contains(Pair.of(iedName, ldInst));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ protected boolean amRootElement(){
return parentAdapter == null;
}

/**
* Returns XPath path to current element
* @return message as <em>undefined</em>
*/
protected abstract String elementXPath();

protected void customInit() {
// do nothing
}
Expand Down Expand Up @@ -109,12 +115,4 @@ public String getXPath(){
return parentXpath + "/" + elementXPath();
}

/**
* Returns XPath path to current element
* @return message as <em>undefined</em>
*/
protected String elementXPath(){
return String.format("undefined(%s)", currentElem.getClass().getSimpleName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.lfenergy.compas.sct.commons.scl.sstation.SubstationAdapter;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -140,6 +141,19 @@ public SubstationAdapter getSubstationAdapter(String ssName) throws ScdException
return new SubstationAdapter(this,ssName);
}

/**
* Gets the first Substation from SCL root node
* @return <em>SubstationAdapter</em> object
* @throws ScdException throws when unknown Substation
*/
public SubstationAdapter getSubstationAdapter() throws ScdException {
TSubstation tSubstation = currentElem.getSubstation()
.stream()
.findFirst()
.orElseThrow(() -> new ScdException("No Substation in SCL file"));
return new SubstationAdapter(this, tSubstation);
}

/**
* Add Header to SCL root node
* @param hId SCL Header ID
Expand Down Expand Up @@ -275,4 +289,5 @@ public IEDAdapter checkObjRef(String val) throws ScdException {
}
throw new ScdException("Invalid ObjRef: " + val);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.lfenergy.compas.sct.commons.scl.dtt.LNodeTypeAdapter;
import org.lfenergy.compas.sct.commons.scl.header.HeaderAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.*;
import org.lfenergy.compas.sct.commons.scl.sstation.SubstationAdapter;
import org.lfenergy.compas.sct.commons.util.Utils;

import java.util.*;
Expand Down Expand Up @@ -680,4 +681,27 @@ public static void removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(final S
.forEach(LNAdapter::removeAllControlBlocksAndDatasets);
}

/**
* Activate used LDevice and Deactivate unused LDevice in {@link TLNode <em><b>TLNode </b></em>}
* @param scd SCL file for which LDevice should be activated or deactivated
* @return SclReport Object that contain SCL file and set of errors
*/
public static SclReport updateLDeviceStatus(SCL scd) {
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
SubstationAdapter substationAdapter = sclRootAdapter.getSubstationAdapter();
final List<Pair<String, String>> iedNameLdInstList = substationAdapter.getIedAndLDeviceNamesForLN0FromLNode();
List<SclReport.ErrorDescription> errors = sclRootAdapter.getIEDAdapters().stream()
.map(IEDAdapter::getLDeviceAdapters)
.flatMap(Collection::stream)
.map(LDeviceAdapter::getLN0Adapter)
.map(ln0Adapter -> ln0Adapter.checkAndUpdateLDeviceStatus(iedNameLdInstList))
.reduce(new ArrayList<>(),(sclReportErrors, partialSclReportErrors) -> {
sclReportErrors.addAll(partialSclReportErrors);
return sclReportErrors;
});
SclReport sclReport = new SclReport();
sclReport.getErrorDescriptionList().addAll(errors);
sclReport.setSclRootAdapter(sclRootAdapter);
return sclReport;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.lfenergy.compas.sct.commons.scl.sstation.SubstationAdapter;
import org.lfenergy.compas.sct.commons.scl.sstation.VoltageLevelAdapter;


/**
* A representation of the <em><b>{@link SubstationService SubstationService}</b></em>.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public boolean amChildElementRef() {
return currentElem == parentAdapter.getCurrentElem().getCommunication();
}

@Override
protected String elementXPath() {
return "Communication";
}

/**
* Add Subnetwork node in Communication one.
* For that :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TConnectedAP;
import org.lfenergy.compas.scl2007b4.model.TPrivate;
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
import org.lfenergy.compas.sct.commons.util.Utils;

import java.util.Optional;

Expand Down Expand Up @@ -45,6 +45,13 @@ protected boolean amChildElementRef() {
return parentAdapter.getCurrentElem().getConnectedAP().contains(currentElem);
}

@Override
protected String elementXPath() {
return String.format("ConnectedAP[%s and %s]",
Utils.xpathAttributeFilter("apName", currentElem.isSetApName() ? currentElem.getApName() : null),
Utils.xpathAttributeFilter("iedName", currentElem.isSetIedName() ? currentElem.getApName() : null));
}

/**
* Returns the value of the <em><b>iedName</b></em> attribute.
* @return the value of the <em><b>iedName</b></em> attribute.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.lfenergy.compas.scl2007b4.model.TSubNetwork;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
import org.lfenergy.compas.sct.commons.util.Utils;

import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -48,6 +49,12 @@ protected boolean amChildElementRef() {
return parentAdapter.getCurrentElem().getSubNetwork().contains(currentElem);
}

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

/**
* Create a Connected Access Point for this subnetwork.<br/>
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.lfenergy.compas.scl2007b4.model.TDA;
import org.lfenergy.compas.sct.commons.dto.DaTypeName;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.util.Utils;

/**
* A representation of the model object <em><b>{@link org.lfenergy.compas.scl2007b4.model.TDA DA}</b></em>.
Expand Down Expand Up @@ -57,6 +58,13 @@ protected boolean amChildElementRef() {
return parentAdapter.getCurrentElem().getSDOOrDA().contains(currentElem);
}

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

/**
* Updates DA Type Name
* @param daTypeName DA Type Name to update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.lfenergy.compas.sct.commons.dto.DaTypeName;
import org.lfenergy.compas.sct.commons.dto.ResumedDataTemplate;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.util.Utils;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -154,6 +155,12 @@ protected boolean amChildElementRef() {
return parentAdapter.getCurrentElem().getDAType().contains(currentElem);
}

@Override
protected String elementXPath() {
return String.format("DAType[%s]",
Utils.xpathAttributeFilter("id", currentElem.isSetId() ? currentElem.getId() : null));
}

/**
* Gets all BDAs from current DAType
* @return list of linked BDA as <em>BDAAdapter</em> object
Expand Down Expand Up @@ -390,5 +397,11 @@ protected boolean amChildElementRef() {
return parentAdapter.getCurrentElem().getBDA().contains(currentElem);
}

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

}
}
Loading

0 comments on commit 4074d64

Please sign in to comment.