8000 Update SCL communication import method to allow the import of the att… by SaintierFr · Pull Request #91 · com-pas/compas-sct · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Update SCL communication import method to allow the import of the att… #91

New issue < 8000 button aria-label="Close dialog" data-close-dialog="" type="button" data-view-component="true" class="Link--muted btn-link position-absolute p-4 right-0">

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

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
8 changes: 7 additions & 1 deletion sct-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
<version>local-SNAPSHOT</version>
</parent>

<groupId>org.lfenergy.compas</groupId>
<artifactId>sct-commons</artifactId>
<version>local-SNAPSHOT</version>
<name>SCT-COMMONS</name>


<properties>
<sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
<assertJ.version>3.22.0</assertJ.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -105,6 +105,12 @@
<version>2.3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertJ.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
112 changes: 63 additions & 49 deletions sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/SclService.java
10000
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.lfenergy.compas.sct.commons.dto.*;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.com.CommunicationAdapter;
import org.lfenergy.compas.sct.commons.scl.com.ConnectedAPAdapter;
import org.lfenergy.compas.sct.commons.scl.com.SubNetworkAdapter;
import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter;
import org.lfenergy.compas.sct.commons.scl.dtt.EnumTypeAdapter;
import org.lfenergy.compas.sct.commons.scl.dtt.LNodeTypeAdapter;
Expand All @@ -32,19 +34,22 @@ public class SclService {
public static final String UNKNOWN_LDEVICE_S_IN_IED_S = "Unknown LDevice (%s) in IED (%s)";
public static final String INVALID_OR_MISSING_ATTRIBUTES_IN_EXT_REF_BINDING_INFO = "Invalid or missing attributes in ExtRef binding info";

private SclService(){ throw new IllegalStateException("SclService class"); }
private SclService() {
throw new IllegalStateException("SclService class");
}

public static SclRootAdapter initScl(Optional<UUID> hId, String hVersion, String hRevision) throws ScdException {
UUID headerId = hId.orElseGet(UUID::randomUUID);
return new SclRootAdapter(headerId.toString(), hVersion, hRevision);
}

public static SclRootAdapter addHistoryItem(SCL scd, String who, String what, String why){
public static SclRootAdapter addHistoryItem(SCL scd, String who, String what, String why) {
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
HeaderAdapter headerAdapter = sclRootAdapter.getHeaderAdapter();
headerAdapter.addHistoryItem(who,what,why);
headerAdapter.addHistoryItem(who, what, why);
return sclRootAdapter;
}

public static SclRootAdapter updateHeader(@NonNull SCL scd, @NonNull HeaderDTO headerDTO) {

SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
Expand All @@ -53,17 +58,17 @@ public static SclRootAdapter updateHeader(@NonNull SCL scd, @NonNull HeaderDTO h
boolean hUpdated = false;
String hVersion = headerDTO.getVersion();
String hRevision = headerDTO.getRevision();
if(hVersion != null && !hVersion.equals(headerAdapter.getHeaderVersion())){
if (hVersion != null && !hVersion.equals(headerAdapter.getHeaderVersion())) {
headerAdapter.updateVersion(hVersion);
hUpdated = true;
}

if(hRevision != null && !hRevision.equals(headerAdapter.getHeaderRevision())){
if (hRevision != null && !hRevision.equals(headerAdapter.getHeaderRevision())) {
headerAdapter.updateRevision(hRevision);
hUpdated = true;
}

if(hUpdated && !headerDTO.getHistoryItems().isEmpty()){
if (hUpdated && !headerDTO.getHistoryItems().isEmpty()) {
headerAdapter.addHistoryItem(
headerDTO.getHistoryItems().get(0).getWho(),
headerDTO.getHistoryItems().get(0).getWhat(),
Expand All @@ -74,24 +79,32 @@ public static SclRootAdapter updateHeader(@NonNull SCL scd, @NonNull HeaderDTO h
return sclRootAdapter;
}


public static IEDAdapter addIED(SCL scd, String iedName, SCL icd) throws ScdException {
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
return sclRootAdapter.addIED(icd,iedName);
return sclRootAdapter.addIED(icd, iedName);
}

public static Optional<CommunicationAdapter> addSubnetworks(SCL scd, Set<SubNetworkDTO> subNetworks) throws ScdException {
public static Optional<CommunicationAdapter> addSubnetworks(SCL scd, Set<SubNetworkDTO> subNetworks, Optional<SCL> icd) throws ScdException {
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
CommunicationAdapter communicationAdapter = null;
if(!subNetworks.isEmpty()) {
CommunicationAdapter communicationAdapter;
if (!subNetworks.isEmpty()) {
communicationAdapter = sclRootAdapter.getCommunicationAdapter(true);

for (SubNetworkDTO subNetworkDTO : subNetworks) {
String snName = subNetworkDTO.getName();
String snType = subNetworkDTO.getType();
for (ConnectedApDTO accessPoint : subNetworkDTO.getConnectedAPs()) {
communicationAdapter.addSubnetwork(snName, snType,
accessPoint.getIedName(), accessPoint.getApName());
String iedName = accessPoint.getIedName();
String apName = accessPoint.getApName();
communicationAdapter.addSubnetwork(snName, snType, iedName, apName);

Optional<SubNetworkAdapter> subNetworkAdapter = communicationAdapter.getSubnetworkByName(snName);
if (subNetworkAdapter.isPresent()) {
ConnectedAPAdapter connectedAPAdapter = subNetworkAdapter.get()
.getConnectedAPAdapter(iedName, apName);
connectedAPAdapter.copyAddressAndPhysConnFromIcd(icd);
}

}
}
return Optional.of(communicationAdapter);
Expand Down Expand Up @@ -121,7 +134,7 @@ public static List<ExtRefInfo> getExtRefInfo(SCL scd, String iedName, String ldI


public static List<ExtRefBindingInfo> getExtRefBinders(SCL scd, String iedName, String ldInst,
String lnClass, String lnInst, String prefix, ExtRefSignalInfo signalInfo) throws ScdException {
String lnClass, String lnInst, String prefix, ExtRefSignalInfo signalInfo) throws ScdException {
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(iedName);
LDeviceAdapter lDeviceAdapter = iedAdapter.getLDeviceAdapterByLdInst(ldInst)
Expand All @@ -141,14 +154,14 @@ public static List<ExtRefBindingInfo> getExtRefBinders(SCL scd, String iedName,

// find potential binders for the signalInfo
List<ExtRefBindingInfo> potentialBinders = new ArrayList<>();
for(IEDAdapter iedA : sclRootAdapter.getIEDAdapters()){
for (IEDAdapter iedA : sclRootAdapter.getIEDAdapters()) {
potentialBinders.addAll(iedA.getExtRefBinders(signalInfo));
}
return potentialBinders;
}

public static void updateExtRefBinders(SCL scd, ExtRefInfo extRefInfo) throws ScdException {
if(extRefInfo.getBindingInfo() == null || extRefInfo.getSignalInfo() == null){
if (extRefInfo.getBindingInfo() == null || extRefInfo.getSignalInfo() == null) {
throw new ScdException("ExtRef Signal and/or Binding information are missing");
}
String iedName = extRefInfo.getHolderIEDName();
Expand All @@ -157,11 +170,11 @@ public static void updateExtRefBinders(SCL scd, ExtRefInfo extRefInfo) throws Sc
IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName(iedName);
LDeviceAdapter lDeviceAdapter = iedAdapter.getLDeviceAdapterByLdInst(ldInst)
.orElseThrow(
() -> new ScdException(
String.format(
UNKNOWN_LDEVICE_S_IN_IED_S, ldInst, iedName
)
)
() -> new ScdException(
String.format(
UNKNOWN_LDEVICE_S_IN_IED_S, ldInst, iedName
)
)
);

AbstractLNAdapter<?> abstractLNAdapter = AbstractLNAdapter.builder()
Expand All @@ -179,16 +192,16 @@ public static List<ControlBlock<?>> getExtRefSourceInfo(SCL scd, ExtRefInfo extR


ExtRefSignalInfo signalInfo = extRefInfo.getSignalInfo();
if(!signalInfo.isValid()){
if (!signalInfo.isValid()) {
throw new ScdException("Invalid or missing attributes in ExtRef signal info");
}
ExtRefBindingInfo bindingInfo = extRefInfo.getBindingInfo();
if(!bindingInfo.isValid()){
if (!bindingInfo.isValid()) {
throw new ScdException(INVALID_OR_MISSING_ATTRIBUTES_IN_EXT_REF_BINDING_INFO);
}

String iedName = extRefInfo.getHolderIEDName();
if(bindingInfo.getIedName().equals(iedName)){
if (bindingInfo.getIedName().equals(iedName)) {
throw new ScdException("Internal binding can't have control block");
}

Expand Down Expand Up @@ -234,18 +247,18 @@ public static TExtRef updateExtRefSource(SCL scd, ExtRefInfo extRefInfo) throws
String prefix = extRefInfo.getHolderLnPrefix();

ExtRefSignalInfo signalInfo = extRefInfo.getSignalInfo();
if(signalInfo == null || !signalInfo.isValid()){
if (signalInfo == null || !signalInfo.isValid()) {
throw new ScdException("Invalid or missing attributes in ExtRef signal info");
}
ExtRefBindingInfo bindingInfo = extRefInfo.getBindingInfo();
if(bindingInfo == null || !bindingInfo.isValid()){
if (bindingInfo == null || !bindingInfo.isValid()) {
throw new ScdException(INVALID_OR_MISSING_ATTRIBUTES_IN_EXT_REF_BINDING_INFO);
}
if(bindingInfo.getIedName().equals(iedName)){
if (bindingInfo.getIedName().equals(iedName)) {
throw new ScdException("Internal binding can't have control block");
}
ExtRefSourceInfo sourceInfo = extRefInfo.getSourceInfo();
if(sourceInfo == null || !sourceInfo.isValid()){
if (sourceInfo == null || !sourceInfo.isValid()) {
throw new ScdException(INVALID_OR_MISSING_ATTRIBUTES_IN_EXT_REF_BINDING_INFO);
}

Expand All @@ -265,9 +278,9 @@ public static TExtRef updateExtRefSource(SCL scd, ExtRefInfo extRefInfo) throws
}

public static Set<ResumedDataTemplate> getDAI(SCL scd, String iedName, String ldInst,
ResumedDataTemplate rDtt, boolean updatable) throws ScdException {
ResumedDataTemplate rDtt, boolean updatable) throws ScdException {
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
IEDAdapter iedAdapter = new IEDAdapter(sclRootAdapter,iedName);
IEDAdapter iedAdapter = new IEDAdapter(sclRootAdapter, iedName);
LDeviceAdapter lDeviceAdapter = iedAdapter.getLDeviceAdapterByLdInst(ldInst)
.orElseThrow(
() -> new ScdException(String.format(UNKNOWN_LDEVICE_S_IN_IED_S, ldInst, iedName))
Expand All @@ -284,9 +297,9 @@ public static void updateDAI(SCL scd, String iedName, String ldInst, ResumedData
DataTypeTemplateAdapter dttAdapter = sclRootAdapter.getDataTypeTemplateAdapter();
LNodeTypeAdapter lNodeTypeAdapter = dttAdapter.getLNodeTypeAdapterById(rDtt.getLnType())
.orElseThrow(() -> new ScdException("Unknown LNodeType : " + rDtt.getLnType()));
lNodeTypeAdapter.check(rDtt.getDoName(),rDtt.getDaName());
lNodeTypeAdapter.check(rDtt.getDoName(), rDtt.getDaName());

if(TPredefinedBasicTypeEnum.OBJ_REF == rDtt.getBType()){
if (TPredefinedBasicTypeEnum.OBJ_REF == rDtt.getBType()) {
Long sGroup = rDtt.getDaName().getDaiValues().keySet().stream().findFirst().orElse(-1L);
String val = sGroup < 0 ? null : rDtt.getDaName().getDaiValues().get(sGroup);
sclRootAdapter.checkObjRef(val);
Expand All @@ -306,8 +319,8 @@ public static void updateDAI(SCL scd, String iedName, String ldInst, ResumedData
.withLnPrefix(rDtt.getPrefix())
.build();

if(TPredefinedCDCEnum.ING == rDtt.getCdc() || TPredefinedCDCEnum.ASG == rDtt.getCdc() ){
DAITracker daiTracker = new DAITracker(lnAdapter,rDtt.getDoName(),rDtt.getDaName());
if (TPredefinedCDCEnum.ING == rDtt.getCdc() || TPredefinedCDCEnum.ASG == rDtt.getCdc()) {
DAITracker daiTracker = new DAITracker(lnAdapter, rDtt.getDoName(), rDtt.getDaName());
daiTracker.validateBoundedDAI();
}
lnAdapter.updateDAI(rDtt);
Expand All @@ -316,44 +329,45 @@ public static void updateDAI(SCL scd, String iedName, String ldInst, ResumedData

public static Set<Pair<Integer, String>> getEnumTypeElements(SCL scd, String idEnum) throws ScdException {
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
DataTypeTemplateAdapter dataTypeTemplateAdapter = sclRootAdapter.getDataTypeTemplateAdapter();
DataTypeTemplateAdapter dataTypeTemplateAdapter = sclRootAdapter.getDataTypeTemplateAdapter();
EnumTypeAdapter enumTypeAdapter = dataTypeTemplateAdapter.getEnumTypeAdapterById(idEnum)
.orElseThrow(() -> new ScdException("Unknown EnumType Id: " + idEnum));
.orElseThrow(() -> new ScdException("Unknown EnumType Id: " + idEnum));
return enumTypeAdapter.getCurrentElem().getEnumVal().stream()
.map(tEnumVal -> Pair.of(tEnumVal.getOrd(),tEnumVal.getValue()))
.map(tEnumVal -> Pair.of(tEnumVal.getOrd(), tEnumVal.getValue()))
.collect(Collectors.toSet());
}

public static SclRootAdapter addSubstation(@NonNull SCL scd, @NonNull SCL ssd) throws ScdException {
SclRootAdapter scdRootAdapter = new SclRootAdapter(scd);
SclRootAdapter ssdRootAdapter = new SclRootAdapter(ssd);
if(scdRootAdapter.getCurrentElem().getSubstation().size() > 1
|| ssdRootAdapter.currentElem.getSubstation().size() != 1) {
if (scdRootAdapter.getCurrentElem().getSubstation().size() > 1
|| ssdRootAdapter.currentElem.getSubstation().size() != 1) {
throw new ScdException("SCD file must have one or zero Substation and " +
"SCD file must have one Substation. The files are rejected.");
}
TSubstation ssdTSubstation = ssdRootAdapter.currentElem.getSubstation().get(0);
if(scdRootAdapter.getCurrentElem().getSubstation().isEmpty()) {
if (scdRootAdapter.getCurrentElem().getSubstation().isEmpty()) {
scdRootAdapter.getCurrentElem().getSubstation().add(ssdTSubstation);
return scdRootAdapter;
} else {
TSubstation scdTSubstation = scdRootAdapter.currentElem.getSubstation().get(0);
if(scdTSubstation.getName().equalsIgnoreCase(ssdTSubstation.getName())) {
if (scdTSubstation.getName().equalsIgnoreCase(ssdTSubstation.getName())) {
SubstationAdapter scdSubstationAdapter = scdRootAdapter.getSubstationAdapter(scdTSubstation.getName());
for(TVoltageLevel tvl : ssdTSubstation.getVoltageLevel()){
for (TVoltageLevel tvl : ssdTSubstation.getVoltageLevel()) {
updateVoltageLevel(scdSubstationAdapter, tvl);
}
} else throw new ScdException("SCD file must have only one Substation and the Substation name from SSD file is" +
" different from the one in SCD file. The files are rejected.");
} else
throw new ScdException("SCD file must have only one Substation and the Substation name from SSD file is" +
" different from the one in SCD file. The files are rejected.");
}
return scdRootAdapter;
}

private static void updateVoltageLevel(@NonNull SubstationAdapter scdSubstationAdapter, TVoltageLevel vl) throws ScdException {
if(scdSubstationAdapter.getVoltageLevelAdapter(vl.getName()).isPresent()) {
if (scdSubstationAdapter.getVoltageLevelAdapter(vl.getName()).isPresent()) {
VoltageLevelAdapter scdVoltageLevelAdapter = scdSubstationAdapter.getVoltageLevelAdapter(vl.getName())
.orElseThrow(() -> new ScdException("Unable to create VoltageLevelAdapter"));
for (TBay tbay: vl.getBay()) {
for (TBay tbay : vl.getBay()) {
updateBay(scdVoltageLevelAdapter, tbay);
}
} else {
Expand All @@ -362,9 +376,9 @@ private static void updateVoltageLevel(@NonNull SubstationAdapter scdSubstationA
}

private static void updateBay(@NonNull VoltageLevelAdapter scdVoltageLevelAdapter, TBay tBay) {
if(scdVoltageLevelAdapter.getBayAdapter(tBay.getName()).isPresent()){
scdVoltageLevelAdapter.getCurrentElem().getBay()
.removeIf(t -> t.getName().equalsIgnoreCase(tBay.getName()));
if (scdVoltageLevelAdapter.getBayAdapter(tBay.getName()).isPresent()) {
scdVoltageLevelAdapter.getCurrentElem().getBay()
.removeIf(t -> t.getName().equalsIgnoreCase(tBay.getName()));
scdVoltageLevelAdapter.getCurrentElem().getBay().add(tBay);
} else {
scdVoltageLevelAdapter.getCurrentElem().getBay().add(tBay);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// SPDX-FileCopyrightText: 2021 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -43,16 +42,16 @@ public SubNetworkAdapter addSubnetwork(String snName, String snType,
String iedName, String apName) throws ScdException {

IEDAdapter iedAdapter = parentAdapter.getIEDAdapterByName(iedName);
if(!iedAdapter.findAccessPointByName(apName)){
if (!iedAdapter.findAccessPointByName(apName)) {
throw new ScdException("Unknown AccessPoint :" + apName + " in IED :" + iedName);
}
Optional<SubNetworkAdapter> opSubNetworkAdapter = getSubnetworkByName(snName);
if(!opSubNetworkAdapter.isPresent()){ // create new subnetwork
if (opSubNetworkAdapter.isEmpty()) { // create new subnetwork
TSubNetwork subNetwork = new TSubNetwork();
subNetwork.setName(snName);
subNetwork.setType(snType);
currentElem.getSubNetwork().add(subNetwork);
opSubNetworkAdapter = Optional.of(new SubNetworkAdapter(this,subNetwork));
opSubNetworkAdapter = Optional.of(new SubNetworkAdapter(this, subNetwork));
}

opSubNetworkAdapter.get().addConnectedAP(iedName,apName);
Expand All @@ -65,13 +64,13 @@ public Optional<SubNetworkAdapter> getSubnetworkByName(String snName) {
.stream()
.filter(tSubNetwork -> tSubNetwork.getName().equals(snName))
.findFirst()
.map(tSubNetwork -> new SubNetworkAdapter(this,tSubNetwork));
.map(tSubNetwork -> new SubNetworkAdapter(this, tSubNetwork));
}

public List<SubNetworkAdapter> getSubNetworkAdapters() {
return currentElem.getSubNetwork()
.stream()
.map(tSubNetwork -> new SubNetworkAdapter(this,tSubNetwork))
.map(tSubNetwork -> new SubNetworkAdapter(this, tSubNetwork))
.collect(Collectors.toList());

}
Expand Down
Loading
0