Skip to content
New issue

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

Update Main #381

Merged
merged 8 commits into from
Feb 28, 2024
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<sonar.coverage.exclusions>sct-coverage/**</sonar.coverage.exclusions>
<aggregate.report.dir>../sct-coverage/target/site/jacoco-aggregate/jacoco.xml</aggregate.report.dir>
<sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
<compas-core.version>0.18.0</compas-core.version>
<compas-core.version>0.19.0</compas-core.version>
<compas-scl-xsd.version>0.0.4</compas-scl-xsd.version>
<maven.plugin.javadoc>3.4.1</maven.plugin.javadoc>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
Expand Down
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 All @@ -57,7 +47,7 @@ public SCL createSCD(@NonNull SCL ssd, @NonNull HeaderDTO headerDTO, List<SCL> s
sclEditor.addHistoryItem(scd, hItem.getWho(), hItem.getWhat(), hItem.getWhy());
}
substationEditor.addSubstation(scd, ssd);
sclEditor.importSTDElementsInSCD(scd, stds, SUB_NETWORK_TYPES);
sclEditor.importSTDElementsInSCD(scd, stds);
controlBlockEditor.removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(scd);
return scd;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void createSCD_without_headerHistory_should_return_generatedSCD() throws Invocat
verify(sclEditor, times(1)).initScl(headerDTO.getId(), headerDTO.getVersion(), headerDTO.getRevision());
verify(sclEditor, times(0)).addHistoryItem(any(SCL.class), anyString(), anyString(), anyString());
verify(substationEditor, times(1)).addSubstation(any(SCL.class), any(SCL.class));
verify(sclEditor, times(1)).importSTDElementsInSCD(any(SCL.class), anyList(), anyList());
verify(sclEditor, times(1)).importSTDElementsInSCD(any(SCL.class), anyList());
verify(controlBlockEditor, times(1)).removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(any(SCL.class));
}

Expand Down Expand Up @@ -112,7 +112,7 @@ void createSCD_with_headerHistory_should_return_generatedSCD() throws Invocation
verify(sclEditor, times(1)).initScl(headerDTO.getId(), headerDTO.getVersion(), headerDTO.getRevision());
verify(sclEditor, times(1)).addHistoryItem(any(SCL.class), eq(historyItem.getWho()), eq(historyItem.getWhat()), eq(historyItem.getWhy()));
verify(substationEditor, times(1)).addSubstation(any(SCL.class), any(SCL.class));
verify(sclEditor, times(1)).importSTDElementsInSCD(any(SCL.class), anyList(), anyList());
verify(sclEditor, times(1)).importSTDElementsInSCD(any(SCL.class), anyList());
verify(controlBlockEditor, times(1)).removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(any(SCL.class));
}

Expand Down Expand Up @@ -167,7 +167,7 @@ void createSCD_when_sclEditor_importSTDElementsInSCD_Fail_should_throw_exception
doNothing().when(sclEditor).addHistoryItem(any(SCL.class), any(), any(), any());
doNothing().when(substationEditor).addSubstation(any(SCL.class), any(SCL.class));
doThrow(new ScdException("importSTDElementsInSCD fail"))
.when(sclEditor).importSTDElementsInSCD(any(SCL.class), anyList(), anyList());
.when(sclEditor).importSTDElementsInSCD(any(SCL.class), anyList());
// When Then
assertThatThrownBy(() -> sclAutomationService.createSCD(ssd, headerDTO, List.of(std)))
.isInstanceOf(ScdException.class)
Expand All @@ -183,7 +183,7 @@ void createSCD_when_controlBlockEditor_removeAllControlBlocksAndDatasetsAndExtRe
when(sclEditor.initScl(any(UUID.class), anyString(), anyString())).thenReturn((SCL) BeanUtils.cloneBean(scl));
doNothing().when(sclEditor).addHistoryItem(any(SCL.class), any(), any(), any());
doNothing().when(substationEditor).addSubstation(any(SCL.class), any(SCL.class));
doNothing().when(sclEditor).importSTDElementsInSCD(any(SCL.class), anyList(), anyList());
doNothing().when(sclEditor).importSTDElementsInSCD(any(SCL.class), anyList());
doThrow(new ScdException("removeAllControlBlocksAndDatasetsAndExtRefSrcBindings fail"))
.when(controlBlockEditor).removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(any(SCL.class));
// When Then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,14 +420,11 @@ public void debindCompasFlowsAndExtRefsBasedOnVoltageLevel(SCL scd) {
.filter(TCompasFlow::isSetFlowSourceVoltageLevel)
.filter(TCompasFlow::isSetExtRefiedName)
.forEach(tCompasFlow -> {
if (flowSource == null) {
//debind all compas flow
extRefService.clearCompasFlowBinding(tCompasFlow);
} else if (!tCompasFlow.getFlowSourceVoltageLevel().equals(flowSource)) {
//debind extRef
if (!tCompasFlow.getFlowSourceVoltageLevel().equals(flowSource)) {
//debind extRefs correspondind to compas flow
extRefService.getMatchingExtRefs(tlDevice, tCompasFlow)
.forEach(extRefService::clearExtRefBinding);
//debind compas flow
//debind all compas flow
extRefService.clearCompasFlowBinding(tCompasFlow);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ public void addIED(SCL scd, String iedName, SCL icd) throws ScdException {

@Override
public void addSubnetworks(SCL scd, List<SubNetworkDTO> subNetworks, SCL icd) throws ScdException {
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
CommunicationAdapter communicationAdapter;
if (!subNetworks.isEmpty()) {
communicationAdapter = sclRootAdapter.getCommunicationAdapter(true);
CommunicationAdapter communicationAdapter = new SclRootAdapter(scd).getCommunicationAdapter(true);
for (SubNetworkDTO subNetworkDTO : subNetworks) {
String snName = subNetworkDTO.getName();
String snType = subNetworkDTO.getType();
Expand All @@ -103,6 +101,23 @@ public void addSubnetworks(SCL scd, List<SubNetworkDTO> subNetworks, SCL icd) th
}
}

@Override
public void addSubnetworks(SCL scd, SCL icd, String iedName) throws ScdException {
Optional.ofNullable(icd.getCommunication()).ifPresent(tCommunication ->
tCommunication.getSubNetwork().forEach(icdSubNetwork ->
icdSubNetwork.getConnectedAP().forEach(icdConnectedAP -> {
// init Communication if not exist
CommunicationAdapter communicationAdapter = new SclRootAdapter(scd).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
public void updateDAI(SCL scd, String iedName, String ldInst, DataAttributeRef dataAttributeRef) throws ScdException {
long startTime = System.nanoTime();
Expand Down Expand Up @@ -139,7 +154,7 @@ public void updateDAI(SCL scd, String iedName, String ldInst, DataAttributeRef d
}

@Override
public void importSTDElementsInSCD(SCL scd, List<SCL> stds, List<SubNetworkTypeDTO> subNetworkTypes) throws ScdException {
public void importSTDElementsInSCD(SCL scd, List<SCL> stds) throws ScdException {

//Check SCD and STD compatibilities
Map<String, PrivateLinkedToStds> mapICDSystemVersionUuidAndSTDFile = PrivateUtils.createMapICDSystemVersionUuidAndSTDFile(stds);
Expand Down Expand Up @@ -167,9 +182,7 @@ public void importSTDElementsInSCD(SCL scd, List<SCL> stds, List<SubNetworkTypeD
scdRootAdapter.addIED(std, iedName);

//import connectedAP and rename ConnectedAP/@iedName
TCommunication communication = stdRootAdapter.getCurrentElem().getCommunication();
List<SubNetworkDTO> subNetworkDTOSet = SubNetworkDTO.createDefaultSubnetwork(iedName, communication, subNetworkTypes);
addSubnetworks(scdRootAdapter.getCurrentElem(), subNetworkDTOSet, std);
addSubnetworks(scdRootAdapter.getCurrentElem(), std, iedName);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ public interface SclEditor {
*/
void addSubnetworks(SCL scd, List<SubNetworkDTO> subNetworks, SCL icd) throws ScdException;

/**
* Add or update SubNetworks in SCL file from ICD file and rename ConnectedAP/@iedName
* @param scd SCL file in which SubNetworks should be added
* @param std STD file from which SubNetworks functional data are copied from
* @param stdIedName Ied Name
*/
void addSubnetworks(SCL scd, SCL std, String stdIedName) throws ScdException;

/**
* Updates DAI based on given data in <em>dataAttributeRef</em>
*
Expand Down Expand Up @@ -118,7 +126,6 @@ public interface SclEditor {
*
* @param scd SCL object in which content of STD files are imported
* @param stds list of STD files contenting datas to import into SCD
* @param subNetworkTypes couple of Subnetwork name and possible corresponding ConnectedAP names
* @throws ScdException throws when inconsistency between Substation of SCL content and gien STD files as :
* <ul>
* <li>ICD_SYSTEM_VERSION_UUID in IED/Private of STD is not present in COMPAS-ICDHeader in Substation/../LNode of SCL</li>
Expand All @@ -128,7 +135,7 @@ public interface SclEditor {
* <li>COMPAS_ICDHEADER in Substation/../LNode of SCL not found in IED/Private of STD</li>
* </ul>
*/
void importSTDElementsInSCD(SCL scd, List<SCL> stds, List<SubNetworkTypeDTO> subNetworkTypes) throws ScdException;
void importSTDElementsInSCD(SCL scd, List<SCL> stds) throws ScdException;

/**
* Activate used LDevice and Deactivate unused LDevice in {@link TLNode <em><b>TLNode </b></em>}
Expand Down
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 @@ -774,7 +774,7 @@ private static Stream<Arguments> provideFlowAndExtRefForDebinding(){
return Stream.of(
Arguments.of("case known voltageLevel should debind THT flow and corresponding ExtRef", scd, tupleExtRef1, tupleFlow1, tupleExtRefDebind, tupleFlowDebind),
Arguments.of("case voltageLevel 0 should do nothing", scdVoltageLevel0, tupleExtRef1, tupleFlow1, tupleExtRef2, tupleFlow2),
Arguments.of("case unknown voltageLevel should debind all", scdVoltageLevelUnknown, tupleExtRef1, tupleFlowDebind, tupleExtRef2, tupleFlowDebind),
Arguments.of("case unknown voltageLevel should debind all CompasFlow and corresponding ExtRef", scdVoltageLevelUnknown, tupleExtRefDebind, tupleFlowDebind, tupleExtRefDebind, tupleFlowDebind),
Arguments.of("case known voltageLevel should not debind because no ExtRefIedName", scdUnsetExtRefIedName, tupleExtRef1, tupleFlow1, tupleExtRef2, tupleFlowNoExtRefIedName),
Arguments.of("case unknown voltageLevel should not debind because unset FlowSourceVoltageLevel", scdVLevelUnknownUnsetFlowSourceVoltageLevel, tupleExtRef1, tupleFlow1, tupleExtRef2, tupleFlow2)
);
Expand Down
Loading
Loading