Skip to content

Commit

Permalink
feat(#373): review note
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 Jan 18, 2024
1 parent 36abe59 commit e682b26
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import org.lfenergy.compas.sct.commons.api.SclEditor;
import org.lfenergy.compas.sct.commons.api.SubstationEditor;
import org.lfenergy.compas.sct.commons.dto.HeaderDTO;
import org.lfenergy.compas.sct.commons.dto.SubNetworkDTO;
import org.lfenergy.compas.sct.commons.dto.SubNetworkTypeDTO;
import org.lfenergy.compas.sct.commons.exception.ScdException;

import java.util.*;
Expand All @@ -33,14 +31,6 @@ public class SclAutomationService {
private final SubstationEditor substationEditor;
private final ControlBlockEditor controlBlockEditor;

/**
* Possible Subnetwork and ConnectedAP names which should be used in generated SCD in order a have global coherence
* Configuration based on used framework can be used to externalize this datas
*/
public static final List<SubNetworkTypeDTO> SUB_NETWORK_TYPES = List.of(
new SubNetworkTypeDTO("RSPACE_PROCESS_NETWORK", SubNetworkDTO.SubnetworkType.MMS.toString(), List.of("PROCESS_AP", "TOTO_AP_GE")),
new SubNetworkTypeDTO("RSPACE_ADMIN_NETWORK", SubNetworkDTO.SubnetworkType.IP.toString(), List.of("ADMIN_AP", "TATA_AP_EFFACEC")));

/**
* Create an SCD file from specified parameters, it calls all functions defined in the process one by one, every step
* return an SCD file which will be used by the next step.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,54 +104,21 @@ public void addSubnetworks(SCL scd, List<SubNetworkDTO> subNetworks, SCL icd) th
}

@Override
public void addSubnetworks(SCL scd, SCL std, String iedName) throws ScdException {
Optional.ofNullable(std.getCommunication()).ifPresent(tCommunication ->
tCommunication.getSubNetwork().forEach(stdSubNetwork ->
stdSubNetwork.getConnectedAP().forEach(stdConnectedAP -> {
// verify if exist SCD/IED/ConnectedAP/apName equal to STD/Communication/SubNetwork/ConnectedAP/apName
if (scd.getIED().stream().filter(ied -> Objects.equals(ied.getName(), iedName))
.flatMap(tied -> tied.getAccessPoint().stream())
.noneMatch(tAccessPoint -> tAccessPoint.getName().equals(stdConnectedAP.getApName()))) {
throw new ScdException("Unknown AccessPoint :" + stdConnectedAP.getApName() + " in IED :" + iedName);
}
// add SubNetwork if not exist
if(scd.getCommunication() == null) {
scd.setCommunication(new TCommunication());
}
TSubNetwork tSubNetwork = scd.getCommunication().getSubNetwork().stream()
.filter(subNetwork -> subNetwork.getName().equals(stdSubNetwork.getName()))
.findFirst()
.orElseGet(() -> {
TSubNetwork newSubNetwork = new TSubNetwork();
newSubNetwork.setName(stdSubNetwork.getName());
newSubNetwork.setType(stdSubNetwork.getType());
scd.getCommunication().getSubNetwork().add(newSubNetwork);
return newSubNetwork;
});
// add ConnectedAP to SubNetwork if not exist
String apName = stdConnectedAP.getApName();
TConnectedAP tConnectedAP = tSubNetwork.getConnectedAP().stream()
.filter(connectedAP -> Objects.equals(connectedAP.getIedName(), iedName)
&& Objects.equals(connectedAP.getApName(), apName))
.findFirst()
.orElseGet(() -> {
TConnectedAP newConnectedAP = new TConnectedAP();
newConnectedAP.setIedName(iedName);
newConnectedAP.setApName(apName);
tSubNetwork.getConnectedAP().add(newConnectedAP);
return newConnectedAP;
});
//copy Address And PhysConn From Icd to Scd
std.getCommunication().getSubNetwork().stream()
.flatMap(subNetwork -> subNetwork.getConnectedAP().stream())
.filter(connectedAP -> connectedAP.getApName().equals(tConnectedAP.getApName()))
.findFirst()
.ifPresent(connectedAP -> {
Optional.ofNullable(connectedAP.getAddress()).ifPresent(tConnectedAP::setAddress);
tConnectedAP.getPhysConn().addAll(connectedAP.getPhysConn());
});
}))
);
public void addSubnetworks(SCL scd, SCL icd, String iedName) throws ScdException {
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
Optional.ofNullable(icd.getCommunication()).ifPresent(tCommunication ->
tCommunication.getSubNetwork().forEach(icdSubNetwork ->
icdSubNetwork.getConnectedAP().forEach(icdConnectedAP -> {
// init Communication if not exist
CommunicationAdapter communicationAdapter = sclRootAdapter.getCommunicationAdapter(true);
// add SubNetwork if not exist, add ConnectedAP to SubNetwork if not exist
SubNetworkAdapter subNetworkAdapter = communicationAdapter
.addSubnetwork(icdSubNetwork.getName(), icdSubNetwork.getType(), iedName, icdConnectedAP.getApName());
// copy Address And PhysConn From Icd to Scd
subNetworkAdapter.getConnectedAPAdapter(iedName, icdConnectedAP.getApName())
.copyAddressAndPhysConnFromIcd(icd);
})
));
}

@Override
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.lfenergy.compas.sct.commons.dto;

import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;

@Builder(toBuilder = true)
@Getter
public class SCDRoot {

@NonNull
final SclRootAdapter scdRootAdapter ;

// public static SCDRootBuilder builder(final SclRootAdapter scdRootAdapter) {
// return new SCDRoot(scdRootAdapter);
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void copyAddressAndPhysConnFromIcd(SCL icd) {
.filter(connectedAP -> connectedAP.getApName().equals(currentElem.getApName()))
.findFirst()
.ifPresent(connectedAP -> {
currentElem.setAddress(connectedAP.getAddress());
Optional.ofNullable(connectedAP.getAddress()).ifPresent(currentElem::setAddress);
currentElem.getPhysConn().addAll(connectedAP.getPhysConn());
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ void addSubnetworks_whenNoCommunicationTagInIcd_should_not_add_subnetwork() {
}

@Test
void addSubnetworks_shouldNotUpdateScd_when_noCommunicationInICDExist() {
void addSubnetworks_shouldNotUpdateScd_when_noCommunicationInSTDExist() {
//Givens
SCL initial = SclTestMarshaller.getSCLFromFile("/scl_update_communication/scd_without_communication.xml");
SCL scd = SclTestMarshaller.getSCLFromFile("/scl_update_communication/scd_without_communication.xml");
SCL icd = SclTestMarshaller.getSCLFromFile("/scl_update_communication/std_without_communication.xml");
assertThat(scd.getCommunication()).isNull();
Expand Down Expand Up @@ -211,8 +212,8 @@ void addSubnetworks_shouldAddSubNetwork_and_ConnectedAp_and_updateConnectedApIED


@Test
void addSubnetworks_shouldCopyAddressAndPhysConnFromIcd() {
//Givens
void addSubnetworks_shouldCopyAddressAndPhysConnFromStd() {
//Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scl_update_communication/scd_without_communication.xml");
SCL std = SclTestMarshaller.getSCLFromFile("/scl_update_communication/std_with_full_filled_communication.xml");
assertThat(scd.getCommunication()).isNull();
Expand Down Expand Up @@ -246,15 +247,14 @@ void addSubnetworks_shouldDoNothing_when_subNetworkAlreadyExist() {

@Test
void addSubnetworks_shouldThrowError_When_IedNameNotExistInScd() {
//Givens
//Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scl_update_communication/scd_without_communication.xml");
SCL icd = SclTestMarshaller.getSCLFromFile("/scl_update_communication/std_with_communication.xml");
//When
//Then
assertThatCode(() -> sclService.addSubnetworks(scd, icd, "UnknownIedName"))
.isInstanceOf(ScdException.class)
.hasMessage("Unknown AccessPoint :ConnectedAP_Name in IED :UnknownIedName");
assertIsMarshallable(scd);
.hasMessage("IED.name 'UnknownIedName' not found in SCD");
}

@Test
Expand Down

0 comments on commit e682b26

Please sign in to comment.