Skip to content

Commit

Permalink
Merge pull request #360 from com-pas/feat/359_update_cb_report_for_hm…
Browse files Browse the repository at this point in the history
…i_creation_sonfig_file

feat(#359): use a POJO for allowed FCDA list in CB Report for HMI cre…
  • Loading branch information
AliouDIAITE authored Dec 7, 2023
2 parents b4d97c6 + 5804ec2 commit 9cce141
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 112 deletions.
19 changes: 19 additions & 0 deletions sct-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,25 @@
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
<execution>
<id>cb_po</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<sources>
<source>
${project.basedir}/src/main/resources/xsd/CB_REPORT_SUPERVISION_Config_file.xsd
</source>
</sources>
<xjbSources>
<xjbSource>${project.basedir}/src/main/resources/binding_configuration.xjb</xjbSource>
</xjbSources>
<packageName>org.lfenergy.compas.sct.commons.model.cb_po</packageName>
<noPackageLevelAnnotations>true</noPackageLevelAnnotations>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@
package org.lfenergy.compas.sct.commons;

import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TFCDA;
import org.lfenergy.compas.sct.commons.api.HmiEditor;
import org.lfenergy.compas.sct.commons.model.cb_po.PO;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;

import java.util.List;

public class HmiService implements HmiEditor {

@Override
public void createAllHmiReportControlBlocks(SCL scd, List<TFCDA> fcdas) {
public void createAllHmiReportControlBlocks(SCL scd, PO po) {
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
sclRootAdapter.streamIEDAdapters()
.flatMap(IEDAdapter::streamLDeviceAdapters)
.forEach(lDeviceAdapter -> lDeviceAdapter.createHmiReportControlBlocks(fcdas));
.forEach(lDeviceAdapter -> lDeviceAdapter.createHmiReportControlBlocks(po));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
package org.lfenergy.compas.sct.commons.api;

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

import java.util.List;
import org.lfenergy.compas.sct.commons.model.cb_po.PO;

/**
* Service class that will be used to manage elements related to the HMI {@link TReportControl <em>Report Control Blocks</em>}.
Expand All @@ -20,7 +18,7 @@ public interface HmiEditor {
/**
* 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
* @param po object containing list of FCDA for which we must create the DataSet and ReportControl Blocks
*/
void createAllHmiReportControlBlocks(SCL scd, List<TFCDA> fcdas);
void createAllHmiReportControlBlocks(SCL scd, PO po);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.dto.*;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.model.cb_po.PO;
import org.lfenergy.compas.sct.commons.model.cb_po.TFCDAFilter;
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.ControlBlockAdapter;
Expand Down Expand Up @@ -81,20 +83,20 @@ public LDeviceAdapter(IEDAdapter parentAdapter, TLDevice currentElem) {
* Create DataSet and ReportControl Blocks for the HMI with the given FCDAs.
* DataSet and ReportControl are created in LN0, even if FCDA refers to another LN.
*
* @param fcdas List of FCDA for which we must create the DataSet and ReportControl
* @param po object containing list of FCDA for which we must create the DataSet and ReportControl
*/
public void createHmiReportControlBlocks(List<TFCDA> fcdas) {
public void createHmiReportControlBlocks(PO po) {
LN0Adapter ln0 = getLN0Adapter();
if (!ln0.getDaiModStValValue().map(ActiveStatus::fromValue).map(ActiveStatus.ON::equals).orElse(false)) return;
fcdas.stream()
.filter(fcda -> getInst().equals(fcda.getLdInst()) && fcda.isSetLnClass())
.forEach(fcda -> (fcda.getLnClass().get(0).equals(TLLN0Enum.LLN_0.value()) ?
po.getFCDAs().getFCDA().stream()
.filter(tfcdaFilter -> getInst().equals(tfcdaFilter.getLdInst()) && tfcdaFilter.isSetLnClass())
.forEach(tfcdaFilter -> (tfcdaFilter.getLnClass().equals(TLLN0Enum.LLN_0.value()) ?
Optional.of(ln0) // ln0 Mod stVal "ON" has already been checked, no need to check it again
:
findLnAdapter(fcda.getLnClass().get(0), fcda.getLnInst(), fcda.getPrefix()).filter(lnAdapter -> lnAdapter.getDaiModStValValue().map(ActiveStatus::fromValue).map(ActiveStatus.ON::equals).orElse(true)))
.map(sourceLn -> sourceLn.getDAI(new DataAttributeRef(fcda), false))
.filter(das -> das.stream().anyMatch(da -> fcda.getFc() == da.getFc())) // getDAI does not filter on DA.
.ifPresent(dataAttributeRefs -> createHmiReportCB(ln0, fcda)));
findLnAdapter(tfcdaFilter.getLnClass(), tfcdaFilter.getLnInst(), tfcdaFilter.getPrefix()).filter(lnAdapter -> lnAdapter.getDaiModStValValue().map(ActiveStatus::fromValue).map(ActiveStatus.ON::equals).orElse(true)))
.map(sourceLn -> sourceLn.getDAI(new DataAttributeRef(toFCDA(tfcdaFilter)), false))
.filter(das -> das.stream().anyMatch(da -> TFCEnum.fromValue(tfcdaFilter.getFc().value()) == da.getFc())) // getDAI does not filter on DA.
.ifPresent(dataAttributeRefs -> createHmiReportCB(ln0, toFCDA(tfcdaFilter))));
}

private void createHmiReportCB(LN0Adapter ln0, TFCDA fcda) {
Expand Down Expand Up @@ -514,4 +516,15 @@ public List<ExtRefInfo.ExtRefBayReference> getExtRefBayReferenceForActifLDEPF(fi
return extRefBayReferenceList;
}

private TFCDA toFCDA(TFCDAFilter tfcdaFilter) {
TFCDA tfcda = new TFCDA();
tfcda.setLdInst(tfcdaFilter.getLdInst());
tfcda.getLnClass().add(tfcdaFilter.getLnClass());
tfcda.setPrefix(tfcdaFilter.getPrefix());
tfcda.setLnInst(tfcdaFilter.getLnInst());
tfcda.setDoName(tfcdaFilter.getDoName());
tfcda.setFc(TFCEnum.fromValue(tfcdaFilter.getFc().value()));
return tfcda;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,25 @@

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

import com.opencsv.bean.CsvBindByPosition;
import lombok.Getter;
import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TFCDA;
import org.lfenergy.compas.scl2007b4.model.TFCEnum;
import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;

import java.io.Reader;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* This class is a helper method to load FCDA from a CSV files for use with
* {@link org.lfenergy.compas.sct.commons.HmiService#createAllHmiReportControlBlocks(SCL, List)}
* {@link org.lfenergy.compas.sct.commons.ExtRefService#createDataSetAndControlBlocks(SCL, Set)}
* {@link org.lfenergy.compas.sct.commons.ExtRefService#createDataSetAndControlBlocks(SCL, String, Set)}
* {@link org.lfenergy.compas.sct.commons.ExtRefService#createDataSetAndControlBlocks(SCL, String, String, Set)}
* {@link org.lfenergy.compas.sct.commons.ControlBlockService#createDataSetAndControlBlocks(SCL, Set)}
* {@link org.lfenergy.compas.sct.commons.ControlBlockService#createDataSetAndControlBlocks(SCL, String, Set)}
* {@link org.lfenergy.compas.sct.commons.ControlBlockService#createDataSetAndControlBlocks(SCL, String, String, Set)}
* Use the getter to access the list of parsed FCDA.
*
* @see CsvUtils
*/
public class FcdaCsvHelper {

@Getter
private final List<TFCDA> fcdaForHmiReportControls;

@Getter
private final Set<FcdaForDataSetsCreation> fcdaForDataSets;

Expand All @@ -39,46 +31,11 @@ public class FcdaCsvHelper {
* Provide the CSV files as a Reader. For example, you can create a reader like this :
* <code>new InputStreamReader(getClass().getClassLoader().getResourceAsStream(fileName), StandardCharsets.UTF_8);</code>
*
* @param csvSourceForHmiReportControl a reader that provides the FCDA datas for HMI ReportControl Blocks as CSV
* @param csvSourceForDataSetAndControlBlocks a reader that provides the FCDA datas for DataSets and Control Blocks creation as CSV
*/
public FcdaCsvHelper(Reader csvSourceForHmiReportControl, Reader csvSourceForDataSetAndControlBlocks) {
fcdaForHmiReportControls = CsvUtils.parseRows(csvSourceForHmiReportControl, FcdaForHmiReportControl.class).stream()
.map(fcdaForHmiReportControl ->
SclConstructorHelper.newFcda(fcdaForHmiReportControl.ldInst, fcdaForHmiReportControl.lnClass, fcdaForHmiReportControl.lnInst, fcdaForHmiReportControl.prefix, fcdaForHmiReportControl.doName, null, fcdaForHmiReportControl.fc)
)
.toList();
public FcdaCsvHelper(Reader csvSourceForDataSetAndControlBlocks) {
fcdaForDataSets = new HashSet<>(CsvUtils.parseRows(csvSourceForDataSetAndControlBlocks, FcdaForDataSetsCreation.class));
}

public static class FcdaForHmiReportControl {
@CsvBindByPosition(position = 0)
private String ldInst;
@CsvBindByPosition(position = 1)
private String prefix;
@CsvBindByPosition(position = 2)
private String lnClass;
@CsvBindByPosition(position = 3)
private String lnInst;
@CsvBindByPosition(position = 4)
private String doName;
@CsvBindByPosition(position = 5)
private TFCEnum fc;
}

/* @NoArgsConstructor
@AllArgsConstructor
@Getter
@EqualsAndHashCode
public static class FcdaForDataSets {
@CsvBindByPosition(position = 0)
private String lnClass;
@CsvBindByPosition(position = 1)
private String doName;
@CsvBindByPosition(position = 2)
private String daName;
@CsvBindByPosition(position = 3)
private String fc;
} */

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
SPDX-FileCopyrightText: 2023 RTE FRANCE
SPDX-License-Identifier: Apache-2.0
-->
<xs:schema xmlns="http://www.rte-france.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.rte-france.com" elementFormDefault="qualified" attributeFormDefault="unqualified"
version="1">

<xs:element name="PO">
<xs:complexType>
<xs:sequence>
<xs:element ref="History"/>
<xs:element ref="Version"/>
<xs:element ref="FCDAs"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="History">
<xs:complexType>
<xs:sequence>
<xs:element name="Hitem" type="tHitem" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="tHitem" mixed="true">
<xs:attribute name="version" type="xs:normalizedString" use="required"/>
<xs:attribute name="when" type="xs:normalizedString" use="required"/>
<xs:attribute name="who" type="xs:normalizedString"/>
<xs:attribute name="what" type="xs:normalizedString"/>
</xs:complexType>

<xs:element name="Version">
<xs:complexType>
<xs:sequence>
<xs:element name="SystemVersion" type="tSystemVersion" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="tSystemVersion" mixed="true">
<xs:attribute name="MainSystemVersion" type="xs:normalizedString" use="required"/>
</xs:complexType>

<xs:element name="FCDAs">
<xs:complexType>
<xs:sequence>
<xs:element name="FCDA" type="tFCDAFilter" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="tFCDAFilter">
<xs:attribute name="ldInst" type="xs:string" use="required"/>
<xs:attribute name="prefix" type="xs:string" use="optional"/>
<xs:attribute name="lnClass" type="xs:string" use="required"/>
<xs:attribute name="lnInst" type="xs:string" use="required"/>
<xs:attribute name="doName" type="xs:string" use="required"/>
<xs:attribute name="fc" type="tfc" use="required"/>
</xs:complexType>

<xs:simpleType name="tfc">
<xs:restriction base="xs:string">
<xs:enumeration value="ST"/>
<xs:enumeration value="MX"/>
</xs:restriction>
</xs:simpleType>

</xs:schema>
Loading

0 comments on commit 9cce141

Please sign in to comment.