Skip to content

Commit

Permalink
[WIP] Create interface for Services and replace static methods with i…
Browse files Browse the repository at this point in the history
…nstance methods closes #110

Signed-off-by: Samir Romdhani <[email protected]>
  • Loading branch information
samirromdhani committed Aug 22, 2023
1 parent 985b66e commit 0cc11f0
Show file tree
Hide file tree
Showing 23 changed files with 1,651 additions and 1,141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
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;
import org.lfenergy.compas.sct.commons.scl.impl.SclService;
import org.lfenergy.compas.sct.commons.scl.impl.SubstationService;

import java.util.*;

Expand All @@ -26,6 +26,9 @@
*/
public class SclAutomationService {

SclService sclService = new SclService();
SubstationService substationService = new SubstationService();

/**
* 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
Expand All @@ -34,10 +37,6 @@ public class SclAutomationService {
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");
}

/**
* 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 All @@ -47,15 +46,15 @@ private SclAutomationService() {
* @return an SCD object
* @throws ScdException
*/
public static SCL createSCD(@NonNull SCL ssd, @NonNull HeaderDTO headerDTO, List<SCL> stds) throws ScdException {
SCL scd = SclService.initScl(headerDTO.getId(), headerDTO.getVersion(), headerDTO.getRevision());
public SCL createSCD(@NonNull SCL ssd, @NonNull HeaderDTO headerDTO, List<SCL> stds) throws ScdException {
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());
sclService.addHistoryItem(scd, hItem.getWho(), hItem.getWhat(), hItem.getWhy());
}
SubstationService.addSubstation(scd, ssd);
SclService.importSTDElementsInSCD(scd, stds, SUB_NETWORK_TYPES);
SclService.removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(scd);
substationService.addSubstation(scd, ssd);
sclService.importSTDElementsInSCD(scd, stds, SUB_NETWORK_TYPES);
sclService.removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(scd);
return scd;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter;
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller;

import java.lang.reflect.Constructor;
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;
import static org.junit.jupiter.api.Assertions.*;
import static org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller.assertIsMarshallable;

class SclAutomationServiceTest {

SclAutomationService sclAutomationService = new SclAutomationService();

private HeaderDTO headerDTO;

@BeforeEach
Expand All @@ -44,7 +43,7 @@ void createSCD_should_return_generatedSCD() {
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/scd.xml");
SCL std = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml");
// When
SCL scd = SclAutomationService.createSCD(ssd, headerDTO, List.of(std));
SCL scd = sclAutomationService.createSCD(ssd, headerDTO, List.of(std));
// Then
assertNotNull(scd.getHeader().getId());
assertNull(scd.getHeader().getHistory());
Expand All @@ -68,7 +67,7 @@ void createSCD_With_HItem() {
SCL std2 = SclTestMarshaller.getSCLFromFile("/std_2.xml");
SCL std3 = SclTestMarshaller.getSCLFromFile("/std_3.xml");
// When
SCL scd = SclAutomationService.createSCD(ssd, headerDTO, List.of(std1, std2, std3));
SCL scd = sclAutomationService.createSCD(ssd, headerDTO, List.of(std1, std2, std3));
// Then
assertNotNull(scd.getHeader().getId());
assertEquals(1, scd.getHeader().getHistory().getHitem().size());
Expand All @@ -93,7 +92,7 @@ void createSCD_With_HItems() {
SCL std2 = SclTestMarshaller.getSCLFromFile("/std_2.xml");
SCL std3 = SclTestMarshaller.getSCLFromFile("/std_3.xml");
// When
SCL scd = SclAutomationService.createSCD(ssd, headerDTO, List.of(std1, std2, std3));
SCL scd = sclAutomationService.createSCD(ssd, headerDTO, List.of(std1, std2, std3));
// Then
assertNotNull(scd.getHeader().getId());
assertEquals(1, scd.getHeader().getHistory().getHitem().size());
Expand All @@ -108,7 +107,7 @@ void createSCD_SSD_Without_Substation() {
// When & Then
List<SCL> stdListEmpty = List.of();
assertThrows(ScdException.class,
() -> SclAutomationService.createSCD(ssd, headerDTO, stdListEmpty));
() -> sclAutomationService.createSCD(ssd, headerDTO, stdListEmpty));
}

@Test
Expand All @@ -123,7 +122,7 @@ void createSCD_should_throw_exception_when_null_ssd() {
List<SCL> stdList = List.of(std1);

// When & Then
assertThrows(NullPointerException.class, () -> SclAutomationService.createSCD(null, headerDTO, stdList));
assertThrows(NullPointerException.class, () -> sclAutomationService.createSCD(null, headerDTO, stdList));
}

@Test
Expand All @@ -134,7 +133,7 @@ void createSCD_should_throw_exception_when_null_headerDTO() {
List<SCL> stdList = List.of(std1);

// When & Then
assertThrows(NullPointerException.class, () -> SclAutomationService.createSCD(ssd, null, stdList));
assertThrows(NullPointerException.class, () -> sclAutomationService.createSCD(ssd, null, stdList));
}

@Test
Expand All @@ -143,7 +142,7 @@ void createSCD_should_delete_ControlBlocks_DataSet_and_ExtRef_src_attributes() {
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");
// When
SCL scd = SclAutomationService.createSCD(ssd, headerDTO, List.of(std));
SCL scd = sclAutomationService.createSCD(ssd, headerDTO, List.of(std));
// Then
LN0 ln0 = new SclRootAdapter(scd).streamIEDAdapters()
.findFirst()
Expand All @@ -158,16 +157,4 @@ void createSCD_should_delete_ControlBlocks_DataSet_and_ExtRef_src_attributes() {
assertIsMarshallable(scd);
}

@Test
void class_should_not_be_instantiable() {
// Given
Constructor<?>[] constructors = SclAutomationService.class.getDeclaredConstructors();
assertThat(constructors).hasSize(1);
Constructor<?> constructor = constructors[0];
constructor.setAccessible(true);
// When & Then
assertThatThrownBy(constructor::newInstance)
.isInstanceOf(InvocationTargetException.class)
.getCause().isInstanceOf(UnsupportedOperationException.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

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

import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TPrivate;

import java.util.List;

public record PrivateLinkedToSTDs(TPrivate tPrivate, List<SCL> stdList) {

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


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

import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TExtRef;
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.util.ILDEPFSettings;
import org.lfenergy.compas.sct.commons.util.Utils;

import java.util.List;

public interface IExtRefService {

/**
* Updates iedName attribute of all ExtRefs in the Scd.
*
* @return list of encountered errors
*/
List<SclReportItem> updateAllExtRefIedNames(SCL scd);

/**
* Create All DataSet and ControlBlock in the SCL based on the ExtRef
*
* @param scd input SCD object. It could be modified by adding new DataSet and ControlBlocks
* @return list of encountered errors
*/
List<SclReportItem> createDataSetAndControlBlocks(SCL scd);

/**
* Create All DataSet and ControlBlock for the ExtRef in given IED
*
* @param scd input SCD object. The object will be modified with the new DataSet and ControlBlocks
* @param targetIedName the name of the IED where the ExtRef are
* @return list of encountered errors
*/
List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName);

/**
* Create All DataSet and ControlBlock for the ExtRef in this LDevice
*
* @param scd input SCD object. The object will be modified with the new DataSet and ControlBlocks
* @param targetIedName the name of the IED where the ExtRef are
* @param targetLDeviceInst the name of the LDevice where the ExtRef are
* @return list of encountered errors
*/
List<SclReportItem> createDataSetAndControlBlocks(SCL scd, String targetIedName, String targetLDeviceInst);

/**
* Configure the network for all the ControlBlocks.
* Create (or update if already existing) these elements
* - the Communication/SubNetwork/ConnectedAP/GSE element, for the GSEControl blocks
* - the Communication/SubNetwork/ConnectedAP/SMV element, for the SampledValueControl blocks
*
* @param scd input SCD object. The object will be modified with the new DataGSESet and SMV elements
* @param controlBlockNetworkSettings a method tha gives the network configuration information for a given ControlBlock
* @param rangesPerCbType provide NetworkRanges for GSEControl and SampledValueControl. NetworkRanges contains :
* start-end app APPID range (long value), start-end MAC-Addresses (Mac-Addresses values: Ex: "01-0C-CD-01-01-FF")
* @return list of encountered errors
* @see Utils#macAddressToLong(String) for the expected MAC address format
* @see ControlBlockNetworkSettings
* @see ControlBlockNetworkSettings.RangesPerCbType
* @see ControlBlockNetworkSettings.NetworkRanges
*/
List<SclReportItem> configureNetworkForAllControlBlocks(SCL scd, ControlBlockNetworkSettings controlBlockNetworkSettings,
ControlBlockNetworkSettings.RangesPerCbType rangesPerCbType);

/**
* ExtRef Binding For LDevice (inst=LDEPF) that matching LDEPF configuration
* @param scd SCL
* @param settings ILDEPFSettings
* @return list of encountered errors
*/
List<SclReportItem> manageBindingForLDEPF(SCL scd, ILDEPFSettings settings);

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

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

import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TFCDA;

import java.util.List;

public interface IHmiService {

/**
* Create the DataSet and ReportControl Blocks for the HMI with the given FCDAs.
*
* @param fcdas List of FCDA for which we must create the DataSet and ReportControl Blocks
*/
void createAllHmiReportControlBlocks(SCL scd, List<TFCDA> fcdas);
}
Loading

0 comments on commit 0cc11f0

Please sign in to comment.