Skip to content

Commit

Permalink
review feedback
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 Aug 11, 2023
1 parent a43e611 commit 10a05da
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
package org.lfenergy.compas.sct.app;

import lombok.NonNull;
import org.apache.commons.lang3.tuple.Pair;
import org.lfenergy.compas.scl2007b4.model.SCL;
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 org.lfenergy.compas.sct.commons.scl.SclService;
import org.lfenergy.compas.sct.commons.scl.SubstationService;
Expand All @@ -27,12 +27,12 @@
public class SclAutomationService {

/**
* Possible Subnetwork and ConnectAP names which should be used in generated SCD in order a have global coherence
* 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
*/
private static final Map<Pair<String, String>, List<String>> comMap = Map.of(
Pair.of("RSPACE_PROCESS_NETWORK", SubNetworkDTO.SubnetworkType.MMS.toString()), Arrays.asList("PROCESS_AP", "TOTO_AP_GE"),
Pair.of("RSPACE_ADMIN_NETWORK", SubNetworkDTO.SubnetworkType.IP.toString()), Arrays.asList("ADMIN_AP", "TATA_AP_EFFACEC"));
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")));

private SclAutomationService() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
Expand All @@ -48,14 +48,13 @@ private SclAutomationService() {
* @throws ScdException
*/
public static SCL createSCD(@NonNull SCL ssd, @NonNull HeaderDTO headerDTO, List<SCL> stds) throws ScdException {
SCL scd = SclService.initScl(Optional.ofNullable(headerDTO.getId()),
headerDTO.getVersion(), headerDTO.getRevision());
SCL scd = SclService.initScl(headerDTO.getId(), headerDTO.getVersion(), headerDTO.getRevision());
if (!headerDTO.getHistoryItems().isEmpty()) {
HeaderDTO.HistoryItem hItem = headerDTO.getHistoryItems().get(0);
SclService.addHistoryItem(scd, hItem.getWho(), hItem.getWhat(), hItem.getWhy());
}
SubstationService.addSubstation(scd, ssd);
SclService.importSTDElementsInSCD(scd, stds, comMap);
SclService.importSTDElementsInSCD(scd, stds, SUB_NETWORK_TYPES);
SclService.removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(scd);
return scd;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand All @@ -32,12 +33,13 @@ class SclAutomationServiceTest {
@BeforeEach
void init() {
headerDTO = new HeaderDTO();
headerDTO.setId(UUID.randomUUID());
headerDTO.setRevision("hRevision");
headerDTO.setVersion("hVersion");
}

@Test
void createSCD_should_return_generatedSCD() throws Exception {
void createSCD_should_return_generatedSCD() {
// Given
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/scd.xml");
SCL std = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml");
Expand All @@ -54,7 +56,7 @@ void createSCD_should_return_generatedSCD() throws Exception {
}

@Test
void createSCD_With_HItem() throws Exception {
void createSCD_With_HItem() {
// Given
HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem();
historyItem.setWhat("what");
Expand Down Expand Up @@ -100,7 +102,7 @@ void createSCD_With_HItems() {
}

@Test
void createSCD_SSD_Without_Substation() throws Exception {
void createSCD_SSD_Without_Substation() {
// Given
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd_without_substations.xml");
// When & Then
Expand All @@ -110,7 +112,7 @@ void createSCD_SSD_Without_Substation() throws Exception {
}

@Test
void createSCD_should_throw_exception_when_null_ssd() throws Exception {
void createSCD_should_throw_exception_when_null_ssd() {
// Given
HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem();
historyItem.setWhat("what");
Expand All @@ -125,7 +127,7 @@ void createSCD_should_throw_exception_when_null_ssd() throws Exception {
}

@Test
void createSCD_should_throw_exception_when_null_headerDTO() throws Exception {
void createSCD_should_throw_exception_when_null_headerDTO() {
// Given
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd.xml");
SCL std1 = SclTestMarshaller.getSCLFromFile("/std_1.xml");
Expand All @@ -136,7 +138,7 @@ void createSCD_should_throw_exception_when_null_headerDTO() throws Exception {
}

@Test
void createSCD_should_delete_ControlBlocks_DataSet_and_ExtRef_src_attributes() throws Exception {
void createSCD_should_delete_ControlBlocks_DataSet_and_ExtRef_src_attributes() {
// Given
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/ssd.xml");
SCL std = SclTestMarshaller.getSCLFromFile("/scl-remove-controlBlocks-dataSet-extRefSrc/scl-with-control-blocks.xml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import lombok.Setter;
import org.lfenergy.compas.sct.commons.scl.com.ConnectedAPAdapter;

import java.util.Objects;

/**
* A representation of the model object <em><b>Connected AP</b></em>.
*
Expand Down Expand Up @@ -53,4 +55,16 @@ public static ConnectedApDTO from(ConnectedAPAdapter connectedAPAdapter) {

return connectedApDTO;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ConnectedApDTO that)) return false;
return Objects.equals(iedName, that.iedName) && Objects.equals(apName, that.apName);
}

@Override
public int hashCode() {
return Objects.hash(iedName, apName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

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

public record EnumTypeDTO(Integer ord, String value) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.tuple.Pair;
import org.lfenergy.compas.sct.commons.scl.com.CommunicationAdapter;
import org.lfenergy.compas.sct.commons.scl.com.ConnectedAPAdapter;
import org.lfenergy.compas.scl2007b4.model.TCommunication;
import org.lfenergy.compas.scl2007b4.model.TConnectedAP;
import org.lfenergy.compas.scl2007b4.model.TSubNetwork;
import org.lfenergy.compas.sct.commons.scl.com.SubNetworkAdapter;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.*;

/**
* A representation of the model object <em><b>Sub Network</b></em>.
Expand All @@ -39,7 +35,7 @@ public class SubNetworkDTO {

private String name;
private SubnetworkType type;
private Set<ConnectedApDTO> connectedAPs = new HashSet<>();
private final Set<ConnectedApDTO> connectedAPs = new HashSet<>();

/**
* Constructor
Expand Down Expand Up @@ -145,20 +141,21 @@ public static SubnetworkType fromValue(String text) {
}

/**
* Create default SubnetworkType in Communication node of SCL file
* @param iedName name of existing IED in SCL
* @param comAdapter Communication node Adapter object value
* @param comMap possible name of SubnetworkTypes and corresponding ConnectedAPs
* @return
* Create default Subnetwork in Communication node of SCL file
* @param iedName Name of existing IED in SCL
* @param communication Communication node in SCL
* @param subNetworkTypes Possible name of Subnetwork and corresponding ConnectedAPs
* @return List of Subnetwork
*/
public static Set<SubNetworkDTO> createDefaultSubnetwork(String iedName, CommunicationAdapter comAdapter, Map<Pair<String, String>, List<String>> comMap){
Set<SubNetworkDTO> subNetworkDTOS = new HashSet<>();
comMap.forEach((subnetworkNameType, apNames) -> {
SubNetworkDTO subNetworkDTO = new SubNetworkDTO(subnetworkNameType.getLeft(), subnetworkNameType.getRight());
apNames.forEach(s -> {
if(getStdConnectedApNames(comAdapter).contains(s)){
ConnectedApDTO connectedApDTO = new ConnectedApDTO(iedName, s);
subNetworkDTO.addConnectedAP(connectedApDTO);}
public static List<SubNetworkDTO> createDefaultSubnetwork(String iedName, TCommunication communication, List<SubNetworkTypeDTO> subNetworkTypes){
List<SubNetworkDTO> subNetworkDTOS = new ArrayList<>();
subNetworkTypes.forEach(subnetwork -> {
SubNetworkDTO subNetworkDTO = new SubNetworkDTO(subnetwork.subnetworkName(), subnetwork.subnetworkType());
subnetwork.accessPointNames().forEach(accessPointName -> {
if(getStdConnectedApNames(communication).contains(accessPointName)){
ConnectedApDTO connectedApDTO = new ConnectedApDTO(iedName, accessPointName);
subNetworkDTO.addConnectedAP(connectedApDTO);
}
});
subNetworkDTOS.add(subNetworkDTO);
});
Expand All @@ -167,13 +164,15 @@ public static Set<SubNetworkDTO> createDefaultSubnetwork(String iedName, Communi

/**
* Gets ConnectedAP name's from Communication node
* @param comAdapter Communication node object value
* @return
* @param communication Communication node object value
* @return List of ConnectedAP names
*/
private static List<String> getStdConnectedApNames(CommunicationAdapter comAdapter){
return comAdapter.getSubNetworkAdapters().stream()
.map(SubNetworkAdapter::getConnectedAPAdapters)
.flatMap(connectedAPAdapters -> connectedAPAdapters.stream().map(ConnectedAPAdapter::getApName))
.collect(Collectors.toList());
private static List<String> getStdConnectedApNames(TCommunication communication){
return communication.getSubNetwork().stream()
.map(TSubNetwork::getConnectedAP)
.flatMap(List::stream)
.map(TConnectedAP::getApName)
.toList();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

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

import java.util.List;

public record SubNetworkTypeDTO(String subnetworkName, String subnetworkType, List<String> accessPointNames) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static List<SclReportItem> updateAllExtRefIedNames(SCL scd) {
.filter(LN0Adapter::hasInputs)
.map(LN0Adapter::getInputsAdapter)
.map(inputsAdapter -> inputsAdapter.updateAllExtRefIedNames(icdSystemVersionToIed))
.flatMap(List::stream).collect(Collectors.toList());
.flatMap(List::stream).toList();
}

private static List<SclReportItem> validateIed(SclRootAdapter sclRootAdapter) {
Expand Down Expand Up @@ -152,7 +152,7 @@ private static List<SclReportItem> createDataSetAndControlBlocks(Stream<LDeviceA
return lDeviceAdapters
.map(LDeviceAdapter::createDataSetAndControlBlocks)
.flatMap(List::stream)
.collect(Collectors.toList());
.toList();
}

/**
Expand Down
Loading

0 comments on commit 10a05da

Please sign in to comment.