Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,14 @@ public List<UUID> getAssets(DataType dataType) {

} else {
List<UUID> 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();
Expand Down
109 changes: 63 additions & 46 deletions src/test/groovy/edu/ie3/simona/api/mapping/ExtEntityMappingTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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"() {
Expand All @@ -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<AssetInput> gridAssets = [node]
List<SystemParticipantInput> 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")]

}
}