Skip to content

Commit 8d312a1

Browse files
Merge pull request #1044 from ie3-institute/ms/#981-abstract-commonly-used-functionality-from-EntitySource
Abstract commonly used functionality from `EntitySource`.
2 parents 227ce33 + 756f807 commit 8d312a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1481
-1689
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
### Changed
2121
- Improvements to the search for corner points in `IdCoordinateSource` [#1016](https://github.com/ie3-institute/PowerSystemDataModel/issues/1016)
2222
- Refactor `CsvFileConnector` and `CsvDataSource` [#1007](https://github.com/ie3-institute/PowerSystemDataModel/issues/1007)
23-
23+
- Make `EntitySource` completely static [#975](https://github.com/ie3-institute/PowerSystemDataModel/issues/975)
24+
- Abstract commonly used functionality from `EntitySource` [#981](https://github.com/ie3-institute/PowerSystemDataModel/issues/981)
2425

2526
## [5.0.1] - 2024-03-07
2627

docs/uml/main/EntitySourceClassDiagram.puml

Lines changed: 140 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,38 @@
33
note "Assuming all classes to implement \nthe abstract methods of their interfaces\n\n" as generalNotes
44

55
abstract class EntitySource {
6-
# DataSource dataSource
7-
# {static} <E extends EntityData, T extends UniqueEntity, R extends E> Try<R, SourceException> enrichEntityData(E, String, Map<UUID, T>, BiFunction<E, T, R>)
8-
# {static} <E extends EntityData, T1 extends UniqueEntity, T2 extends UniqueEntity, R extends E> Try<R, SourceException> enrichEntityData(E, String, Map<UUID, T1>, String, Map<UUID, T2>, TriFunction<E, T1, T2, R>)
9-
# {static} <T extends UniqueEntity> Try<T, SourceException> getLinkedEntity(EntityData, String, Map<UUID, T>)
10-
# {static} <E extends EntityData, T extends UniqueEntity, R extends E> Try<R, SourceException> optionallyEnrichEntityData(E, String, Map<UUID, T>, T, BiFunction<E, T, R>)
11-
# Stream<Try<NodeAssetInputEntityData, SourceException>> buildNodeAssetEntities(Class<T>, Map<UUID, OperatorInput>, Map<UUID, NodeInput>)
12-
# {static} Stream<Try<NodeAssetInputEntityData, SourceException>> nodeAssetInputEntityDataStream(Stream<Try<AssetInputEntityData, SourceException>>, Map<UUID, NodeInput>)
13-
# Stream<Try<AssetInputEntityData, SourceException>> buildAssetInputEntities(Class<? extends AssetInput>, Map<UUID, OperatorInput>)
14-
# {static} Stream<Try<AssetInputEntityData, SourceException>> assetInputEntityDataStream(Stream<Try<EntityData, SourceException>>, Map<UUID, OperatorInput>)
15-
# Stream<Try<EntityData, SourceException>> buildEntityData(Class<? extends UniqueEntity>)
16-
# {static} <S extends UniqueEntity> Map<UUID, S> unpackMap(Stream<Try<S, FactoryException>>, Class<S>) throws SourceException
17-
# {static} <S extends UniqueEntity> Set<S> unpackSet(Stream<Try<S, FactoryException>>, Class<S>) throws SourceException
18-
# {static} <S, E extends Exception> Stream<S> unpackSet(Stream<Try<S, E>>, Class<S>) throws SourceException
6+
+ void validate() throws ValidationException
197
}
208

9+
EntitySource <|-- EnergyManagementSource
2110
EntitySource <|-- GraphicSource
11+
EntitySource <|-- IdCoordinateSource
12+
IdCoordinateSource <|-- CsvIdCoordinateSource
13+
IdCoordinateSource <|-- SqlIdCoordinateSource
2214
EntitySource <|-- RawGridSource
2315
EntitySource <|-- ResultEntitySource
2416
EntitySource <|-- SystemParticipantSource
2517
EntitySource <|-- ThermalSource
18+
EntitySource <|-- TimeSeriesMappingSource
19+
TimeSeriesMappingSource <|-- CsvTimeSeriesMappingSource
20+
TimeSeriesMappingSource <|-- SqlTimeSeriesMappingSource
21+
EntitySource <|-- TimeSeriesSource
22+
TimeSeriesSource <|-- CsvTimeSeriesSource
23+
TimeSeriesSource <|-- SqlTimeSeriesSource
2624
EntitySource <|-- TypeSource
25+
EntitySource <|-- WeatherSource
26+
WeatherSource <|-- CouchbaseWeatherSource
27+
WeatherSource <|-- CsvWeatherSource
28+
WeatherSource <|-- InfluxDbWeatherSource
29+
WeatherSource <|-- SqlWeatherSource
30+
31+
class EnergyManagementSource {
32+
- TypeSource typeSource
33+
- EmInputFactory emInputFactory
34+
+ EnergyManagementSource(TypeSource, DataSource)
35+
+ Map<UUID, EmInput> getEmUnits() throws SourceException
36+
+ Map<UUID, EmInput> getEmUnits(Map<UUID, OperatorInput>) throws SourceException
37+
}
2738

2839
class GraphicSource {
2940
- TypeSource typeSource
@@ -39,6 +50,34 @@ class GraphicSource {
3950
+ Set<LineGraphicInput> getLineGraphicInput(Map<UUID, LineInput>) throws SourceException
4051
}
4152

53+
abstract class IdCoordinateSource {
54+
+ Optional<Set<String>> getSourceFields() throws SourceException
55+
+ Optional<Point> getCoordinate(int)
56+
+ Collection<Point> getCoordinates(int[])
57+
+ Optional<Integer> getId(Point)
58+
+ Collection<Point> getAllCoordinates()
59+
+ List<CoordinateDistance> getNearestCoordinates(Point, int)
60+
+ List<CoordinateDistance> getClosestCoordinates(Point, int, ComparableQuantity<Length>)
61+
+ List<CoordinateDistance> calculateCoordinateDistances(Point, int, Collection<Point>)
62+
+ List<CoordinateDistance> findCornerPoints(Point, ComparableQuantity<Length>)
63+
+ List<CoordinateDistance> findCornerPoints(Point, Collection<CoordinateDistance>)
64+
}
65+
66+
class CsvIdCoordinateSource {
67+
- Map<Integer, Point> idToCoordinate;
68+
- Map<Point, Integer> coordinateToId;
69+
- CsvDataSource dataSource;
70+
- IdCoordinateFactory factory;
71+
+ CsvIdCoordinateSource(IdCoordinateFactory, CsvDataSource) throws SourceException
72+
+ int getCoordinateCount()
73+
}
74+
75+
class SqlIdCoordinateSource {
76+
- SqlDataSource dataSource
77+
- SqlIdCoordinateFactory factory
78+
+ SqlIdCoordinateSource(SqlIdCoordinateFactory, String, SqlDataSource)
79+
}
80+
4281
class RawGridSource {
4382
- TypeSource typeSource
4483
- NodeInputFactory nodeInputFactory
@@ -70,9 +109,10 @@ class ResultEntitySource {
70109
- SwitchResultFactory switchResultFactory
71110
- NodeResultFactory nodeResultFactory
72111
- ConnectorResultFactory connectorResultFactory
112+
- CongestionResultFactory congestionResultFactory
73113
- FlexOptionsResultFactory flexOptionsResultFactory
74114
+ ResultEntitySource(DataSource)
75-
+ ResultEntitySource(DataSource, String)
115+
+ ResultEntitySource(DataSource, DateTimeFormatter)
76116
+ Set<NodeResult> getNodeResults() throws SourceException
77117
+ Set<SwitchResult> getSwitchResults() throws SourceException
78118
+ Set<LineResult> getLineResults() throws SourceException
@@ -92,12 +132,14 @@ class ResultEntitySource {
92132
+ Set<CylindricalStorageResult> getCylindricalStorageResult() throws SourceException
93133
+ Set<ThermalHouseResult> getThermalHouseResults() throws SourceException
94134
+ Set<EmResult> getEmResults() throws SourceException
135+
+ Set<CongestionResult> getCongestionResults() throws SourceException
95136
}
96137

97138
class SystemParticipantSource{
98139
- TypeSource typeSource
99140
- RawGridSource rawGridSource
100141
- ThermalSource thermalSource
142+
- EnergyManagementSource energyManagementSource
101143
- BmInputFactory bmInputFactory
102144
- ChpInputFactory chpInputFactory
103145
- EvInputFactory evInputFactory
@@ -108,7 +150,7 @@ class SystemParticipantSource{
108150
- StorageInputFactory storageInputFactory
109151
- WecInputFactory wecInputFactory
110152
- EvcsInputFactory evcsInputFactory
111-
+ SystemParticipantSource(TypeSource, ThermalSource, RawGridSource, DataSource)
153+
+ SystemParticipantSource(TypeSource, ThermalSource, RawGridSource, EnergyManagementSource, DataSource)
112154
+ SystemParticipants getSystemParticipants() throws SourceException
113155
+ SystemParticipants getSystemParticipants(Map<UUID, OperatorInput>, Map<UUID, NodeInput>) throws SourceException
114156
+ Set<BmInput> getBmPlants() throws SourceException
@@ -141,20 +183,65 @@ class ThermalSource {
141183
+ ThermalSource(TypeSource, DataSource)
142184
+ Map<UUID, ThermalBusInput> getThermalBuses() throws SourceException
143185
+ Map<UUID, ThermalBusInput> getThermalBuses(Map<UUID, OperatorInput>) throws SourceException
144-
+ Set<ThermalStorageInput> getThermalStorages() throws SourceException
145-
+ Set<ThermalStorageInput> getThermalStorages(Map<UUID, OperatorInput>, Map<UUID, ThermalBusInput>) throws SourceException
146-
+ Set<ThermalHouseInput> getThermalHouses() throws SourceException
147-
+ Set<ThermalHouseInput> getThermalHouses(Map<UUID, OperatorInput>, Map<UUID, ThermalBusInput>) throws SourceException
186+
+ Map<UUID, ThermalStorageInput> getThermalStorages() throws SourceException
187+
+ Map<UUID, ThermalStorageInput> getThermalStorages(Map<UUID, OperatorInput>, Map<UUID, ThermalBusInput>) throws SourceException
188+
+ Map<UUID, ThermalHouseInput> getThermalHouses() throws SourceException
189+
+ Map<UUID, ThermalHouseInput> getThermalHouses(Map<UUID, OperatorInput>, Map<UUID, ThermalBusInput>) throws SourceException
148190
+ Set<CylindricalStorageInput> getCylindricStorages() throws SourceException
149191
+ Set<CylindricalStorageInput> getCylindricStorages(Map<UUID, OperatorInput>, Map<UUID, ThermalBusInput>) throws SourceException
150192
}
151193

194+
abstract class TimeSeriesMappingSource {
195+
- TimeSeriesMappingFactory mappingFactory
196+
+ Map<UUID, UUID> getMapping() throws SourceException
197+
+ Optional<UUID> getTimeSeriesUuid(UUID) throws SourceException
198+
+ Stream<Map<String, String>> getMappingSourceData() throws SourceException
199+
+ Optional<Set<String>> getSourceFields() throws SourceException
200+
}
201+
202+
class CsvTimeSeriesMappingSource {
203+
- CsvDataSource dataSource
204+
+ CsvTimeSeriesMappingSource(String, Path, FileNamingStrategy)
205+
}
206+
207+
class SqlTimeSeriesMappingSource {
208+
- EntityPersistenceNamingStrategy entityPersistenceNamingStrategy
209+
- SqlDataSource dataSource
210+
+ SqlTimeSeriesMappingSource(SqlConnector, String, EntityPersistenceNamingStrategy)
211+
}
212+
213+
abstract class TimeSeriesSource {
214+
- Class<V> valueClass
215+
- TimeBasedSimpleValueFactory<V> valueFactory
216+
+ TimeSeriesSource(Class<V>, TimeBasedSimpleValueFactory<V>)
217+
+ IndividualTimeSeries<V> getTimeSeries()
218+
+ IndividualTimeSeries<V> getTimeSeries(ClosedInterval<ZonedDateTime>) throws SourceException
219+
+ Optional<V> getValue(ZonedDateTime) throws SourceException
220+
}
221+
222+
class CsvTimeSeriesSource {
223+
- IndividualTimeSeries<V> timeSeries
224+
- CsvDataSource dataSource
225+
- Path filePath
226+
+ {static} CsvTimeSeriesSource<? extends Value> getSource(String, Path, FileNamingStrategy, CsvIndividualTimeSeriesMetaInformation)
227+
+ CsvTimeSeriesSource(String, Path, FileNamingStrategy, UUID, Path, Class<V>, TimeBasedSimpleValueFactory<V>)
228+
}
229+
230+
class SqlTimeSeriesSource {
231+
- SqlDataSource dataSource
232+
- UUID timeSeriesUuid
233+
+ SqlTimeSeriesSource(SqlDataSource, UUID, Class<V>, TimeBasedSimpleValueFactory<V>)
234+
+ SqlTimeSeriesSource(SqlConnector, String, DatabaseNamingStrategy, UUID, Class<V>, TimeBasedSimpleValueFactory<V>)
235+
+ SqlTimeSeriesSource<? extends Value> createSource(SqlConnector, String, DatabaseNamingStrategy, IndividualTimeSeriesMetaInformation, DateTimeFormatter) throws SourceException
236+
}
237+
152238
class TypeSource {
153239
- OperatorInputFactory operatorInputFactory
154240
- Transformer2WTypeInputFactory transformer2WTypeInputFactory
155241
- LineTypeInputFactory lineTypeInputFactory
156242
- Transformer3WTypeInputFactory transformer3WTypeInputFactory
157243
- SystemParticipantTypeInputFactory systemParticipantTypeInputFactory
244+
- DataSource dataSource
158245
+ TypeSource(DataSource)
159246
+ Map<UUID, Transformer2WTypeInput> getTransformer2WTypes() throws SourceException
160247
+ Map<UUID, Transformer3WTypeInput> getTransformer3WTypes() throws SourceException
@@ -167,4 +254,38 @@ class TypeSource {
167254
+ Map<UUID, WecTypeInput> getWecTypes() throws SourceException
168255
+ Map<UUID, EvTypeInput> getEvTypes() throws SourceException
169256
}
257+
258+
abstract class WeatherSource {
259+
- TimeBasedWeatherValueFactory weatherFactory
260+
- IdCoordinateSource idCoordinateSource
261+
+ WeatherSource(IdCoordinateSource, TimeBasedWeatherValueFactory)
262+
+ Optional<Set<String>> getSourceFields() throws SourceException
263+
+ Map<Point, IndividualTimeSeries<WeatherValue>> getWeather(ClosedInterval<ZonedDateTime>) throws SourceException
264+
+ Map<Point, IndividualTimeSeries<WeatherValue>> getWeather(ClosedInterval<ZonedDateTime>, Collection<Point>) throws SourceException
265+
+ Optional<TimeBasedValue<WeatherValue>> getWeather(ZonedDateTime, Point) throws SourceException
266+
}
267+
268+
class CouchbaseWeatherSource {
269+
- CouchbaseConnector connector
270+
+ CouchbaseWeatherSource(CouchbaseConnector, IdCoordinateSource, String, TimeBasedWeatherValueFactory, String)
271+
+ CouchbaseWeatherSource(CouchbaseConnector, IdCoordinateSource, String, String, TimeBasedWeatherValueFactory, String)
272+
}
273+
274+
class CsvWeatherSource {
275+
- CsvDataSource dataSource
276+
- Map<Point, IndividualTimeSeries<WeatherValue>> coordinateToTimeSeries
277+
+ CsvWeatherSource(String, Path, FileNamingStrategy, IdCoordinateSource, TimeBasedWeatherValueFactory) throws SourceException
278+
}
279+
280+
class InfluxDbWeatherSource {
281+
- InfluxDbConnector connector
282+
+ InfluxDbWeatherSource(InfluxDbConnector, IdCoordinateSource, TimeBasedWeatherValueFactory)
283+
+ IndividualTimeSeries<WeatherValue> getWeather(ClosedInterval<ZonedDateTime>, Point)
284+
}
285+
286+
class SqlWeatherSource {
287+
- SqlDataSource dataSource
288+
+ SqlWeatherSource(SqlConnector, IdCoordinateSource, String, String, TimeBasedWeatherValueFactory)
289+
}
290+
170291
@enduml

src/main/java/edu/ie3/datamodel/io/factory/input/AssetInputEntityFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public abstract class AssetInputEntityFactory<T extends AssetInput, D extends As
2727
private static final String OPERATES_FROM = "operatesFrom";
2828
private static final String OPERATES_UNTIL = "operatesUntil";
2929

30+
@SafeVarargs
3031
protected AssetInputEntityFactory(Class<? extends T>... allowedClasses) {
3132
super(allowedClasses);
3233
}

src/main/java/edu/ie3/datamodel/io/factory/input/ConnectorInputEntityFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @param <D> Type of data class that is required for entity creation
2121
* @since 19.02.20
2222
*/
23-
abstract class ConnectorInputEntityFactory<
23+
public abstract class ConnectorInputEntityFactory<
2424
T extends ConnectorInput, D extends ConnectorInputEntityData>
2525
extends AssetInputEntityFactory<T, D> {
2626

@@ -31,6 +31,7 @@ abstract class ConnectorInputEntityFactory<
3131
*/
3232
protected static final String PARALLEL_DEVICES = "parallelDevices";
3333

34+
@SafeVarargs
3435
protected ConnectorInputEntityFactory(Class<? extends T>... allowedClasses) {
3536
super(allowedClasses);
3637
}

src/main/java/edu/ie3/datamodel/io/factory/input/Transformer3WInputEntityData.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ public Transformer3WInputEntityData(
3939
this.nodeC = nodeC;
4040
}
4141

42+
/**
43+
* Creates a new Transformer3WInputEntityData object based on a given {@link
44+
* ConnectorInputEntityData} object, a given third node as well as a given {@link
45+
* Transformer3WTypeInput}.
46+
*
47+
* @param entityData The TypedConnectorInputEntityData object to enhance
48+
* @param nodeC The third node
49+
* @param type of the transformer
50+
*/
51+
public Transformer3WInputEntityData(
52+
ConnectorInputEntityData entityData, NodeInput nodeC, Transformer3WTypeInput type) {
53+
super(entityData, type);
54+
this.nodeC = nodeC;
55+
}
56+
4257
/**
4358
* Creates a new Transformer3WInputEntityData object based on a given {@link
4459
* TypedConnectorInputEntityData} object and given third node

src/main/java/edu/ie3/datamodel/io/factory/result/ResultEntityFactory.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@
1818
* @version 0.1
1919
* @since 11.02.20
2020
*/
21-
abstract class ResultEntityFactory<T extends ResultEntity> extends EntityFactory<T, EntityData> {
21+
public abstract class ResultEntityFactory<T extends ResultEntity>
22+
extends EntityFactory<T, EntityData> {
2223

2324
protected static final String TIME = "time";
2425

2526
protected final TimeUtil timeUtil;
2627

28+
@SafeVarargs
2729
protected ResultEntityFactory(Class<? extends T>... allowedClasses) {
2830
super(allowedClasses);
2931
timeUtil = TimeUtil.withDefaults;
3032
}
3133

34+
@SafeVarargs
3235
protected ResultEntityFactory(
3336
DateTimeFormatter dateTimeFormatter, Class<? extends T>... allowedClasses) {
3437
super(allowedClasses);

0 commit comments

Comments
 (0)