From 78c5f13e5a3c88ab4e55118f3f16d59be437ca9a Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Mon, 17 Nov 2025 11:14:12 +0100 Subject: [PATCH 1/2] Fix considered data in `ExtEntityMapping.getAssets()` --- CHANGELOG.md | 1 + .../edu/ie3/simona/api/mapping/ExtEntityMapping.java | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fafbc3..ce47705 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Issues related to em data [#366](https://github.com/ie3-institute/simonaAPI/issues/366) - `Fixed bugs in `ExtEntityMapping` [#373](https://github.com/ie3-institute/simonaAPI/issues/373) - Fixed changelog entry #366 [#378](https://github.com/ie3-institute/simonaAPI/issues/366) +- Fix considered data in `ExtEntityMapping.getAssets()` [#384](https://github.com/ie3-institute/simonaAPI/issues/384) ## [0.11.0] - 2025-10-23 diff --git a/src/main/java/edu/ie3/simona/api/mapping/ExtEntityMapping.java b/src/main/java/edu/ie3/simona/api/mapping/ExtEntityMapping.java index 54bfacf..2965a69 100644 --- a/src/main/java/edu/ie3/simona/api/mapping/ExtEntityMapping.java +++ b/src/main/java/edu/ie3/simona/api/mapping/ExtEntityMapping.java @@ -274,9 +274,14 @@ public List getAssets(DataType dataType) { } else { List ext = new ArrayList<>(); - extAssets.values().forEach(ext::addAll); - if (extAssets.isEmpty()) { + if (dataType == DataType.PRIMARY_RESULT) { + ext.addAll(extAssets.getOrDefault(DataType.PRIMARY, Collections.emptySet())); + ext.addAll(extAssets.getOrDefault(DataType.RESULT, Collections.emptySet())); + } else { + ext.addAll(extAssets.getOrDefault(dataType, Collections.emptySet())); + } + if (ext.isEmpty()) { return uuids; } else { return uuids.stream().filter(ext::contains).toList(); From 4e4f5f78f857fd2262fb3187f2e8a74ebb10e6c9 Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Mon, 17 Nov 2025 13:53:47 +0100 Subject: [PATCH 2/2] Include reviewer's comments. --- .../api/mapping/ExtEntityMappingTest.groovy | 109 ++++++++++-------- 1 file changed, 63 insertions(+), 46 deletions(-) diff --git a/src/test/groovy/edu/ie3/simona/api/mapping/ExtEntityMappingTest.groovy b/src/test/groovy/edu/ie3/simona/api/mapping/ExtEntityMappingTest.groovy index 6c66c88..877fa48 100644 --- a/src/test/groovy/edu/ie3/simona/api/mapping/ExtEntityMappingTest.groovy +++ b/src/test/groovy/edu/ie3/simona/api/mapping/ExtEntityMappingTest.groovy @@ -16,6 +16,8 @@ import spock.lang.Shared import spock.lang.Specification import tech.units.indriya.quantity.Quantities +import static edu.ie3.simona.api.mapping.DataType.* + class ExtEntityMappingTest extends Specification { @Shared UUID loadUuid = UUID.fromString("22bea5fc-2cb2-4c61-beb9-b476e0107f52") @@ -30,36 +32,17 @@ class ExtEntityMappingTest extends Specification { UUID emUuid = UUID.fromString("60dbc7e4-9718-4bbd-913a-dd26925e68a3") @Shared - ExtEntityEntry extResultEntry = new ExtEntityEntry( - loadUuid, - "Load", - Optional.empty(), - DataType.RESULT - ) + ExtEntityEntry extResultEntry = new ExtEntityEntry(loadUuid, "Load", Optional.empty(), RESULT) @Shared - ExtEntityEntry extInputEntry = new ExtEntityEntry( - pvUuid, - "PV", - ColumnScheme.parse("p"), - DataType.PRIMARY - ) + ExtEntityEntry extInputEntry = new ExtEntityEntry(pvUuid, "PV", ColumnScheme.parse("p"), PRIMARY) @Shared - ExtEntityEntry extPrimaryResultEntry = new ExtEntityEntry( - prUuid, - "PR", - ColumnScheme.parse("p"), - DataType.PRIMARY_RESULT - ) + ExtEntityEntry extPrimaryResultEntry = new ExtEntityEntry(prUuid, "PR", ColumnScheme.parse("p"), PRIMARY_RESULT) @Shared - ExtEntityEntry extEmInputEntry = new ExtEntityEntry( - emUuid, - "Em", - Optional.empty(), - DataType.EM - ) + ExtEntityEntry extEmInputEntry = new ExtEntityEntry(emUuid, "Em", Optional.empty(), EM) + def "ExtEntityMapping can be created from a grid container correctly"() { given: @@ -118,15 +101,14 @@ class ExtEntityMappingTest extends Specification { def mapping = new ExtEntityMapping(grid) when: - def updated = mapping.include(DataType.RESULT, ["ffi"], Optional.empty()) + def updated = mapping.include(RESULT, ["ffi"], Optional.empty()) then: // only the included ids will be returned, other grid ids will be ignored - mapping.getAssets(DataType.RESULT) == [node.uuid, participant.uuid, em.uuid] - updated.getAssets(DataType.RESULT) == [participant.uuid] + mapping.getAssets(RESULT) == [node.uuid, participant.uuid, em.uuid] + updated.getAssets(RESULT) == [participant.uuid] } - def "ExtEntityMapping should return the data types correctly"() { when: def extEntryMapping = new ExtEntityMapping(assets) @@ -137,13 +119,13 @@ class ExtEntityMappingTest extends Specification { where: assets | expectedTypes - [extResultEntry] | [DataType.RESULT] - [extInputEntry] | [DataType.PRIMARY] - [extPrimaryResultEntry] | [DataType.PRIMARY_RESULT] - [extEmInputEntry] | [DataType.EM] - [extResultEntry, extInputEntry] | [DataType.RESULT, DataType.PRIMARY] - [extInputEntry, extEmInputEntry] | [DataType.PRIMARY, DataType.EM] - [extResultEntry, extInputEntry, extPrimaryResultEntry, extEmInputEntry] | [DataType.RESULT, DataType.PRIMARY, DataType.PRIMARY_RESULT, DataType.EM] + [extResultEntry] | [RESULT] + [extInputEntry] | [PRIMARY] + [extPrimaryResultEntry] | [PRIMARY_RESULT] + [extEmInputEntry] | [EM] + [extResultEntry, extInputEntry] | [RESULT, PRIMARY] + [extInputEntry, extEmInputEntry] | [PRIMARY, EM] + [extResultEntry, extInputEntry, extPrimaryResultEntry, extEmInputEntry] | [RESULT, PRIMARY, PRIMARY_RESULT, EM] } def "ExtEntityMapping should return all SIMONA uuid mapping correctly"() { @@ -162,32 +144,67 @@ class ExtEntityMappingTest extends Specification { inputMap.get("Em") == emUuid } - def "ExtEntityMapping should return SIMONA uuid mapping correctly"() { + def "ExtEntityMapping should return all external id mapping correctly"() { given: def extAssetList = List.of(extResultEntry, extInputEntry, extPrimaryResultEntry, extEmInputEntry) def extEntryMapping = new ExtEntityMapping(extAssetList) when: - def actual = extEntryMapping.getAssets(DataType.PRIMARY) + def inputMap = extEntryMapping.getExtUuid2IdMapping() + + then: + inputMap.size() == 4 + inputMap.get(loadUuid) == "Load" + inputMap.get(pvUuid) == "PV" + inputMap.get(prUuid) == "PR" + inputMap.get(emUuid) == "Em" + } + + def "ExtEntityMapping should return SIMONA uuid mapping correctly"() { + given: + def extAssetList = [extResultEntry, extInputEntry, extPrimaryResultEntry, extEmInputEntry] + def extEntryMapping = new ExtEntityMapping(extAssetList) + + when: + def actual = extEntryMapping.getAssets(PRIMARY) then: actual.size() == 1 actual.getFirst() == pvUuid } - def "ExtEntityMapping should return all external id mapping correctly"() { + def "ExtEntityMapping should return assets uuids correctly"() { given: - def extAssetList = List.of(extResultEntry, extInputEntry, extPrimaryResultEntry, extEmInputEntry) - def extEntryMapping = new ExtEntityMapping(extAssetList) + def node = new NodeInput(UUID.fromString("4476402e-d0e7-4975-935b-6861a00a2a5e"), "node", Quantities.getQuantity(1d, PowerSystemUnits.PU), false, NodeInput.DEFAULT_GEO_POSITION, GermanVoltageLevelUtils.LV, 1) + def em = new EmInput(UUID.fromString("d7c054b2-f5a8-4f88-99e1-59c734fc4655"), "em", "", null) + def participant = new FixedFeedInInput(UUID.fromString("4392e420-dc91-4867-a85f-b05d53896dd2"), "ffi", node, null, em, Quantities.getQuantity(10, PowerSystemUnits.KILOVOLTAMPERE), 0.9) + + List gridAssets = [node] + List participantInputs = [participant] + + def grid = new SubGridContainer( + "test grid", + 1, + new RawGridElements(gridAssets), + new SystemParticipants(participantInputs), + new GraphicElements([]) + ) when: - def inputMap = extEntryMapping.getExtUuid2IdMapping() + def mapping = new ExtEntityMapping(grid).include(includedType, includedExtAssets, Optional.empty()) + def actual = mapping.getAssets(requestedType) then: - inputMap.size() == 4 - inputMap.get(loadUuid) == "Load" - inputMap.get(pvUuid) == "PV" - inputMap.get(prUuid) == "PR" - inputMap.get(emUuid) == "Em" + actual.size() == expectedSize + actual == expectedUuids + + where: + includedType | includedExtAssets | requestedType | expectedSize | expectedUuids + PRIMARY | [] | PRIMARY | 1 | [UUID.fromString("4392e420-dc91-4867-a85f-b05d53896dd2")] + PRIMARY_RESULT | ["ffi"] | RESULT | 1 | [UUID.fromString("4392e420-dc91-4867-a85f-b05d53896dd2")] + RESULT | [] | RESULT | 3 | [UUID.fromString("4476402e-d0e7-4975-935b-6861a00a2a5e"), UUID.fromString("4392e420-dc91-4867-a85f-b05d53896dd2"), UUID.fromString("d7c054b2-f5a8-4f88-99e1-59c734fc4655")] + RESULT | [] | PRIMARY_RESULT | 1 | [UUID.fromString("4392e420-dc91-4867-a85f-b05d53896dd2")] + RESULT | ["ffi", "node"] | RESULT | 2 | [UUID.fromString("4476402e-d0e7-4975-935b-6861a00a2a5e"), UUID.fromString("4392e420-dc91-4867-a85f-b05d53896dd2")] + } } \ No newline at end of file