Skip to content

Commit 8b3e0ac

Browse files
LDEPF disturbances and faults recording: interface between the setting file reading and the SCD file (#262)
Signed-off-by: Samir Romdhani <[email protected]>
1 parent 7c2bdcd commit 8b3e0ac

File tree

5 files changed

+338
-0
lines changed

5 files changed

+338
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-FileCopyrightText: 2023 RTE FRANCE
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sct.commons.dto;
6+
7+
import java.util.List;
8+
9+
/**
10+
* Represents a list of LDEPF settings
11+
* This is a functional interface whose functional method is getLDEPFSettings
12+
* the type of the input to the operation
13+
*
14+
* @param <T> the type of the result of the LDEPFSettings
15+
*
16+
* @see org.lfenergy.compas.sct.commons.util.SettingLDEPFCsvHelper
17+
*/
18+
@FunctionalInterface
19+
public interface LDEPFSettings<T> {
20+
21+
/**
22+
* This method provides list of LDEPF settings
23+
*/
24+
List<T> getSettings();
25+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// SPDX-FileCopyrightText: 2023 RTE FRANCE
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sct.commons.util;
6+
7+
import com.opencsv.bean.CsvBindByPosition;
8+
import lombok.ToString;
9+
import org.lfenergy.compas.sct.commons.dto.LDEPFSettings;
10+
11+
import java.io.Reader;
12+
import java.util.List;
13+
14+
15+
/**
16+
* This class is an implementation example for interface LDEPFSettings.
17+
* It relies on a CSV file.
18+
*
19+
* @see CsvUtils
20+
*/
21+
public class SettingLDEPFCsvHelper implements LDEPFSettings<SettingLDEPFCsvHelper.SettingLDEPF> {
22+
23+
private final List<SettingLDEPF> settings ;
24+
25+
/**
26+
* Constructor
27+
* @param reader input
28+
*/
29+
public SettingLDEPFCsvHelper(Reader reader) {
30+
this.settings = CsvUtils.parseRows(reader, SettingLDEPF.class).stream().toList();
31+
}
32+
33+
@Override
34+
public List<SettingLDEPF> getSettings() {
35+
return this.settings;
36+
}
37+
38+
@ToString
39+
public static class SettingLDEPF {
40+
@CsvBindByPosition(position = 0)
41+
private String rteIedType;
42+
@CsvBindByPosition(position = 1)
43+
private String iedRedundancy;
44+
@CsvBindByPosition(position = 2)
45+
private String iedInstance;
46+
@CsvBindByPosition(position = 3)
47+
private String channelShortLabel;
48+
@CsvBindByPosition(position = 4)
49+
private String channelMREP;
50+
@CsvBindByPosition(position = 5)
51+
private String channelLevModQ;
52+
@CsvBindByPosition(position = 6)
53+
private String channelLevModLevMod;
54+
@CsvBindByPosition(position = 7)
55+
private String bapVariant;
56+
@CsvBindByPosition(position = 8)
57+
private String bapIgnoredValue;
58+
@CsvBindByPosition(position = 9)
59+
private String ldInst;
60+
@CsvBindByPosition(position = 10)
61+
private String lnPrefix;
62+
@CsvBindByPosition(position = 11)
63+
private String lnName;
64+
@CsvBindByPosition(position = 12)
65+
private String lnInst;
66+
@CsvBindByPosition(position = 13)
67+
private String doName;
68+
@CsvBindByPosition(position = 14)
69+
private String doInst;
70+
@CsvBindByPosition(position = 15)
71+
private String sdoName;
72+
@CsvBindByPosition(position = 16)
73+
private String daName;
74+
@CsvBindByPosition(position = 17)
75+
private String daType;
76+
@CsvBindByPosition(position = 18)
77+
private String dabType;
78+
@CsvBindByPosition(position = 19)
79+
private String bdaName;
80+
@CsvBindByPosition(position = 20)
81+
private String sbdaName;
82+
@CsvBindByPosition(position = 21)
83+
private String channelAnalogNum;
84+
@CsvBindByPosition(position = 22)
85+
private String channelDigitalNum;
86+
@CsvBindByPosition(position = 23)
87+
private String opt;
88+
}
89+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-FileCopyrightText: 2023 RTE FRANCE
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sct.commons.dto;
6+
7+
import org.junit.jupiter.api.Test;
8+
import org.lfenergy.compas.sct.commons.util.CsvUtils;
9+
import org.lfenergy.compas.sct.commons.util.SettingLDEPFCsvHelper;
10+
11+
import java.io.InputStream;
12+
import java.io.InputStreamReader;
13+
import java.util.Objects;
14+
import static org.assertj.core.api.Assertions.assertThat;
15+
16+
class LDEPFSettingsTest {
17+
18+
@Test
19+
void getLDEPFSettings_should_return_settings() {
20+
//Given
21+
String fileName = "LDEPF_Setting_file.csv";
22+
InputStream inputStream = Objects.requireNonNull(CsvUtils.class.getClassLoader().getResourceAsStream(fileName), "Resource not found: " + fileName);
23+
InputStreamReader reader = new InputStreamReader(inputStream);
24+
LDEPFSettings<SettingLDEPFCsvHelper.SettingLDEPF> ldepfSettings = new SettingLDEPFCsvHelper(reader);
25+
// When
26+
// Then
27+
assertThat(ldepfSettings.getSettings()).hasSize(161);
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-FileCopyrightText: 2023 RTE FRANCE
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sct.commons.util;
6+
7+
import org.junit.jupiter.api.Test;
8+
9+
import java.io.InputStream;
10+
import java.io.InputStreamReader;
11+
import java.util.Objects;
12+
13+
import static org.assertj.core.api.Assertions.assertThat;
14+
15+
16+
class SettingLDEPFCsvHelperTest {
17+
18+
@Test
19+
void readCsvFile_should_return_settings() {
20+
// Given
21+
String fileName = "LDEPF_Setting_file.csv";
22+
InputStream inputStream = Objects.requireNonNull(CsvUtils.class.getClassLoader().getResourceAsStream(fileName), "Resource not found: " + fileName);
23+
InputStreamReader reader = new InputStreamReader(inputStream);
24+
// When
25+
// Then
26+
SettingLDEPFCsvHelper settingLDEPFCsvHelper = new SettingLDEPFCsvHelper(reader);
27+
assertThat(settingLDEPFCsvHelper.getSettings()).hasSize(161);
28+
}
29+
}

0 commit comments

Comments
 (0)