-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#386): Add Compas IED type PrivateEnum
Signed-off-by: gleizesDor <115622893+gleizesDor@users.noreply.github.com>
- Loading branch information
1 parent
76189be
commit 2a8c6f2
Showing
7 changed files
with
304 additions
and
9 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DaiService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-FileCopyrightText: 2024 RTE FRANCE | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package org.lfenergy.compas.sct.commons; | ||
|
||
import org.lfenergy.compas.scl2007b4.model.*; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Stream; | ||
|
||
public class DaiService { | ||
|
||
public Stream<TDAI> getDais(TDOI tdoi) { | ||
return tdoi.getSDIOrDAI() | ||
.stream() | ||
.filter(dai -> dai.getClass().equals(TDAI.class)) | ||
.map(TDAI.class::cast); | ||
} | ||
|
||
public Stream<TDAI> getFilteredDais(TDOI tdoi, Predicate<TDAI> tdaiPredicate) { | ||
return getDais(tdoi).filter(tdaiPredicate); | ||
} | ||
|
||
public Optional<TDAI> findDai(TDOI tdoi, Predicate<TDAI> tdaiPredicate) { | ||
return getFilteredDais(tdoi, tdaiPredicate).findFirst(); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
sct-commons/src/main/java/org/lfenergy/compas/sct/commons/DoiService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-FileCopyrightText: 2024 RTE FRANCE | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package org.lfenergy.compas.sct.commons; | ||
|
||
import org.lfenergy.compas.scl2007b4.model.TAnyLN; | ||
import org.lfenergy.compas.scl2007b4.model.TDOI; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Stream; | ||
|
||
public class DoiService { | ||
|
||
public Stream<TDOI> getDois(TAnyLN tAnyLN) { | ||
return tAnyLN.getDOI().stream(); | ||
} | ||
|
||
public Stream<TDOI> getFilteredDois(TAnyLN tAnyLN, Predicate<TDOI> tdoiPredicate) { | ||
return getDois(tAnyLN).filter(tdoiPredicate); | ||
} | ||
|
||
public Optional<TDOI> findDoi(TAnyLN tAnyLN, Predicate<TDOI> tdoiPredicate) { | ||
return getFilteredDois(tAnyLN, tdoiPredicate).findFirst(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DaiServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-FileCopyrightText: 2024 RTE FRANCE | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package org.lfenergy.compas.sct.commons; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.lfenergy.compas.scl2007b4.model.SCL; | ||
import org.lfenergy.compas.scl2007b4.model.TDAI; | ||
import org.lfenergy.compas.scl2007b4.model.TDOI; | ||
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class DaiServiceTest { | ||
|
||
private final DaiService daiService = new DaiService(); | ||
|
||
@Test | ||
void getDais() { | ||
//Given | ||
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std"); | ||
TDOI tdoi = std.getIED().get(0).getAccessPoint().get(0).getServer().getLDevice().get(0).getLN0().getDOI().get(3); | ||
|
||
//When | ||
List<TDAI> tdais = daiService.getDais(tdoi).toList(); | ||
|
||
//Then | ||
assertThat(tdais) | ||
.hasSize(5) | ||
.extracting(TDAI::getName) | ||
.containsExactly("paramRev", "valRev", "d", "configRev", "swRev"); | ||
} | ||
|
||
@Test | ||
void getFilteredDais() { | ||
//Given | ||
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std"); | ||
TDOI tdoi = std.getIED().get(0).getAccessPoint().get(0).getServer().getLDevice().get(0).getLN0().getDOI().get(3); | ||
|
||
//When | ||
List<TDAI> tdais = daiService.getFilteredDais(tdoi, tdai -> tdai.getName().equals("configRev")).toList(); | ||
|
||
//Then | ||
assertThat(tdais) | ||
.hasSize(1) | ||
.extracting(TDAI::getName) | ||
.containsExactly("configRev"); | ||
} | ||
|
||
@Test | ||
void findDai() { | ||
//Given | ||
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std"); | ||
TDOI tdoi = std.getIED().get(0).getAccessPoint().get(0).getServer().getLDevice().get(0).getLN0().getDOI().get(3); | ||
|
||
//When | ||
Optional<TDAI> dai = daiService.findDai(tdoi, tdai -> tdai.getName().equals("configRev")); | ||
|
||
//Then | ||
assertThat(dai.orElseThrow()) | ||
.extracting(TDAI::getName, tdai -> tdai.getVal().size()) | ||
.containsExactly("configRev", 1); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
sct-commons/src/test/java/org/lfenergy/compas/sct/commons/DoiServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-FileCopyrightText: 2024 RTE FRANCE | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package org.lfenergy.compas.sct.commons; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.lfenergy.compas.scl2007b4.model.LN0; | ||
import org.lfenergy.compas.scl2007b4.model.SCL; | ||
import org.lfenergy.compas.scl2007b4.model.TDOI; | ||
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class DoiServiceTest { | ||
|
||
private final DoiService doiService = new DoiService(); | ||
|
||
@Test | ||
void getDois() { | ||
//Given | ||
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std"); | ||
LN0 ln0 = std.getIED().get(0).getAccessPoint().get(0).getServer().getLDevice().get(0).getLN0(); | ||
|
||
//When | ||
List<TDOI> tdois = doiService.getDois(ln0).toList(); | ||
|
||
//Then | ||
assertThat(tdois) | ||
.hasSize(4) | ||
.extracting(TDOI::getName) | ||
.containsExactly("Beh", "Health", "Mod", "NamPlt"); | ||
} | ||
|
||
@Test | ||
void getFilteredDois() { | ||
//Given | ||
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std"); | ||
LN0 ln0 = std.getIED().get(0).getAccessPoint().get(0).getServer().getLDevice().get(0).getLN0(); | ||
|
||
//When | ||
List<TDOI> tdois = doiService.getFilteredDois(ln0, tdoi -> tdoi.getName().equals("Beh")).toList(); | ||
|
||
//Then | ||
assertThat(tdois) | ||
.hasSize(1) | ||
.extracting(TDOI::getName) | ||
.containsExactly("Beh"); | ||
} | ||
|
||
@Test | ||
void findDoi() { | ||
//Given | ||
SCL std = SclTestMarshaller.getSCLFromFile("/std/std_sample.std"); | ||
LN0 ln0 = std.getIED().get(0).getAccessPoint().get(0).getServer().getLDevice().get(0).getLN0(); | ||
|
||
//When | ||
Optional<TDOI> doi = doiService.findDoi(ln0, tdoi -> tdoi.getName().equals("Beh")); | ||
|
||
//Then | ||
assertThat(doi.orElseThrow()) | ||
.extracting(TDOI::getName, tdoi -> tdoi.getSDIOrDAI().size()) | ||
.containsExactly("Beh", 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters