Skip to content

Commit 7edc389

Browse files
committed
Merge remote-tracking branch 'origin/sh/#872-storage-documentation' into sh/#872-storage-documentation
2 parents 96a5997 + c8b14ec commit 7edc389

File tree

10 files changed

+192
-242
lines changed

10 files changed

+192
-242
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414

1515
### Changed
1616
- Changing from comparing strings to comparing uuids in `EntitySource.findFirstEntityByUuid` [#829](https://github.com/ie3-institute/PowerSystemDataModel/issues/829)
17-
17+
- Adding JavaDoc to `EntitySource.safeMapGet` [#828](https://github.com/ie3-institute/PowerSystemDataModel/issues/828)
18+
- Abstracting some methods in `ValidationUtils` [#852](https://github.com/ie3-institute/PowerSystemDataModel/issues/852)
1819

1920
## [4.1.0] - 2023-11-02
2021

Jenkinsfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ def constantBranchesProps() {
451451
[
452452
string(defaultValue: '', description: '', name: 'deploy', trim: true)
453453
]),
454-
[$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false],
455454
[$class: 'ThrottleJobProperty', categories: [], limitOneJobWithMatchingParams: false, maxConcurrentPerNode: 0, maxConcurrentTotal: 0, paramsToUseForLimit: '', throttleEnabled: true, throttleOption: 'project']
456455
])
457456
}

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ plugins {
44
id 'maven-publish'
55
id 'signing'
66
id 'pmd' // code check, working on source code
7-
id 'com.diffplug.spotless' version '6.22.0' //code format
8-
id 'com.github.spotbugs' version '5.2.3' // code check, working on byte code
7+
id 'com.diffplug.spotless' version '6.23.2' //code format
8+
id 'com.github.spotbugs' version '5.2.5' // code check, working on byte code
99
id 'de.undercouch.download' version '5.5.0'
1010
id 'kr.motd.sphinx' version '2.10.1' // documentation generation
1111
id 'jacoco' // java code coverage plugin
@@ -17,7 +17,7 @@ ext {
1717
//version (changing these should be considered thoroughly!)
1818
javaVersion = JavaVersion.VERSION_17
1919
groovyVersion = "4.0"
20-
groovyBinaryVersion = "4.0.15"
20+
groovyBinaryVersion = "4.0.16"
2121
testcontainersVersion = '1.19.3'
2222

2323
scriptsLocation = 'gradle' + File.separator + 'scripts' + File.separator //location of script plugins
@@ -93,7 +93,7 @@ dependencies {
9393
implementation 'com.couchbase.client:java-client:3.5.0'
9494
runtimeOnly 'org.postgresql:postgresql:42.7.0' // postgresql jdbc driver required during runtime
9595

96-
implementation 'commons-io:commons-io:2.15.0' // I/O functionalities
96+
implementation 'commons-io:commons-io:2.15.1' // I/O functionalities
9797
implementation 'org.apache.commons:commons-compress:1.25.0' // I/O functionalities
9898
implementation 'org.apache.commons:commons-lang3:3.14.0'
9999
}

docs/readthedocs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
commonmark==0.9.1
22
recommonmark==0.7.1
33
Sphinx==7.2.6
4-
sphinx-rtd-theme==1.3.0
4+
sphinx-rtd-theme==2.0.0
55
myst-parser==2.0.0
66
markdown-it-py==3.0.0
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* © 2023. TU Dortmund University,
3+
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
4+
* Research group Distribution grid planning and operation
5+
*/
6+
package edu.ie3.datamodel.exceptions;
7+
8+
import edu.ie3.datamodel.models.UniqueEntity;
9+
import edu.ie3.datamodel.utils.ExceptionUtils;
10+
import java.util.Collection;
11+
12+
public class DuplicateEntitiesException extends ValidationException {
13+
14+
protected DuplicateEntitiesException(String s) {
15+
super(s);
16+
}
17+
18+
protected DuplicateEntitiesException(String s, String entities) {
19+
super(s + entities);
20+
}
21+
22+
public DuplicateEntitiesException(String fieldName, Collection<? extends UniqueEntity> entities) {
23+
this(
24+
"The following entities have duplicate '" + fieldName + "': ",
25+
ExceptionUtils.combine(entities));
26+
}
27+
}

src/main/java/edu/ie3/datamodel/io/source/EntitySource.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ protected String buildSkippingMessage(
5151
+ missingElementsString;
5252
}
5353

54+
/**
55+
* Method for retrieving an element from a map. If the map doesn't contain the key an error
56+
* message is build and returned instead.
57+
*
58+
* <p>Should not be used for other purposes than creating error messages.
59+
*
60+
* @param map with value
61+
* @param key for the value
62+
* @param mapName name of the map used for the error message
63+
* @return either the value or an error message
64+
*/
5465
protected String safeMapGet(Map<String, String> map, String key, String mapName) {
5566
return Optional.ofNullable(map.get(key))
5667
.orElse(
@@ -83,7 +94,7 @@ protected <T extends UniqueEntity> Optional<T> findFirstEntityByUuid(
8394
* the provided fields to values mapping. The provided fields to values mapping needs to have one
8495
* and only one field with key {@link #TYPE} and a corresponding UUID value. If the type can be
8596
* found in the provided collection based on the UUID it is returned wrapped in a {@link Success}.
86-
* Otherwise a {@link Failure} is returned and a warning is logged.
97+
* Otherwise, a {@link Failure} is returned and a warning is logged.
8798
*
8899
* @param types a collection of types that should be used for searching
89100
* @param fieldsToAttributes the field name to value mapping incl. the key {@link #TYPE}

src/main/java/edu/ie3/datamodel/utils/ExceptionUtils.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
*/
66
package edu.ie3.datamodel.utils;
77

8+
import edu.ie3.datamodel.models.UniqueEntity;
9+
import java.util.Collection;
810
import java.util.List;
11+
import java.util.stream.Collectors;
912

1013
public class ExceptionUtils {
1114
private ExceptionUtils() {
@@ -24,4 +27,16 @@ public static String getMessages(List<? extends Exception> exceptions) {
2427
.reduce("", (a, b) -> a + "\n " + b)
2528
.replaceFirst("\n ", "");
2629
}
30+
31+
/**
32+
* Combines multiple {@link UniqueEntity} into a string.
33+
*
34+
* @param entities to be combined
35+
* @return a string
36+
*/
37+
public static String combine(Collection<? extends UniqueEntity> entities) {
38+
return "{"
39+
+ entities.stream().map(UniqueEntity::toString).collect(Collectors.joining(", "))
40+
+ "}";
41+
}
2742
}

src/main/java/edu/ie3/datamodel/utils/validation/GridContainerValidationUtils.java

Lines changed: 39 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
*/
66
package edu.ie3.datamodel.utils.validation;
77

8-
import edu.ie3.datamodel.exceptions.InvalidEntityException;
9-
import edu.ie3.datamodel.exceptions.InvalidGridException;
10-
import edu.ie3.datamodel.exceptions.UnsafeEntityException;
11-
import edu.ie3.datamodel.exceptions.ValidationException;
8+
import edu.ie3.datamodel.exceptions.*;
9+
import edu.ie3.datamodel.models.UniqueEntity;
1210
import edu.ie3.datamodel.models.input.AssetInput;
1311
import edu.ie3.datamodel.models.input.MeasurementUnitInput;
1412
import edu.ie3.datamodel.models.input.NodeInput;
@@ -24,14 +22,6 @@
2422

2523
public class GridContainerValidationUtils extends ValidationUtils {
2624

27-
private static String duplicateUuidsString(String simpleName, Optional<String> exceptionString) {
28-
return "The provided entities in '"
29-
+ simpleName
30-
+ "' contains duplicate UUIDs. "
31-
+ "This is not allowed!\nDuplicated uuids:\n\n"
32-
+ exceptionString;
33-
}
34-
3525
/** Private Constructor as this class is not meant to be instantiated */
3626
private GridContainerValidationUtils() {
3727
throw new IllegalStateException("Don't try and instantiate a Utility class.");
@@ -52,18 +42,10 @@ private GridContainerValidationUtils() {
5242
return List.of(isNull);
5343
}
5444

55-
List<Try<Void, ? extends ValidationException>> exceptions = new ArrayList<>();
56-
5745
/* sanity check to ensure distinct UUIDs */
58-
Optional<String> exceptionString =
59-
checkForDuplicateUuids(new HashSet<>(gridContainer.allEntitiesAsList()));
60-
exceptions.add(
61-
Try.ofVoid(
62-
exceptionString.isPresent(),
63-
() ->
64-
new InvalidGridException(
65-
duplicateUuidsString(
66-
gridContainer.getClass().getSimpleName(), exceptionString))));
46+
List<Try<Void, ? extends ValidationException>> exceptions =
47+
new ArrayList<>(
48+
checkForDuplicates(gridContainer.allEntitiesAsList(), UniqueEntity::getUuid));
6749

6850
exceptions.addAll(checkRawGridElements(gridContainer.getRawGrid()));
6951
exceptions.addAll(
@@ -98,18 +80,10 @@ private GridContainerValidationUtils() {
9880
return List.of(isNull);
9981
}
10082

101-
List<Try<Void, ? extends ValidationException>> exceptions = new ArrayList<>();
102-
10383
/* sanity check to ensure distinct UUIDs */
104-
Optional<String> exceptionString =
105-
checkForDuplicateUuids(new HashSet<>(rawGridElements.allEntitiesAsList()));
106-
exceptions.add(
107-
Try.ofVoid(
108-
exceptionString.isPresent(),
109-
() ->
110-
new InvalidGridException(
111-
duplicateUuidsString(
112-
rawGridElements.getClass().getSimpleName(), exceptionString))));
84+
List<Try<Void, ? extends ValidationException>> exceptions =
85+
new ArrayList<>(
86+
checkForDuplicates(rawGridElements.allEntitiesAsList(), UniqueEntity::getUuid));
11387

11488
/* Checking nodes */
11589
Set<NodeInput> nodes = rawGridElements.getNodes();
@@ -183,18 +157,18 @@ private GridContainerValidationUtils() {
183157
* Checks the validity of type ids of every entity.
184158
*
185159
* @param rawGridElements the raw grid elements
186-
* @return a list of try objects either containing an {@link UnsafeEntityException} or an empty
187-
* Success
160+
* @return a list of try objects either containing an {@link DuplicateEntitiesException} or an
161+
* empty Success
188162
*/
189-
protected static List<Try<Void, UnsafeEntityException>> checkRawGridTypeIds(
163+
protected static List<Try<Void, DuplicateEntitiesException>> checkRawGridTypeIds(
190164
RawGridElements rawGridElements) {
191-
List<Try<Void, UnsafeEntityException>> exceptions = new ArrayList<>();
192-
exceptions.addAll(ValidationUtils.checkIds(rawGridElements.getNodes()));
193-
exceptions.addAll(ValidationUtils.checkIds(rawGridElements.getLines()));
194-
exceptions.addAll(ValidationUtils.checkIds(rawGridElements.getTransformer2Ws()));
195-
exceptions.addAll(ValidationUtils.checkIds(rawGridElements.getTransformer3Ws()));
196-
exceptions.addAll(ValidationUtils.checkIds(rawGridElements.getSwitches()));
197-
exceptions.addAll(ValidationUtils.checkIds(rawGridElements.getMeasurementUnits()));
165+
List<Try<Void, DuplicateEntitiesException>> exceptions = new ArrayList<>();
166+
exceptions.addAll(checkForDuplicates(rawGridElements.getNodes(), AssetInput::getId));
167+
exceptions.addAll(checkForDuplicates(rawGridElements.getLines(), AssetInput::getId));
168+
exceptions.addAll(checkForDuplicates(rawGridElements.getTransformer2Ws(), AssetInput::getId));
169+
exceptions.addAll(checkForDuplicates(rawGridElements.getTransformer3Ws(), AssetInput::getId));
170+
exceptions.addAll(checkForDuplicates(rawGridElements.getSwitches(), AssetInput::getId));
171+
exceptions.addAll(checkForDuplicates(rawGridElements.getMeasurementUnits(), AssetInput::getId));
198172

199173
return exceptions;
200174
}
@@ -217,19 +191,10 @@ protected static List<Try<Void, UnsafeEntityException>> checkRawGridTypeIds(
217191
return List.of(isNull);
218192
}
219193

220-
List<Try<Void, ? extends ValidationException>> exceptions = new ArrayList<>();
221-
222194
// sanity check for distinct uuids
223-
Optional<String> exceptionString =
224-
ValidationUtils.checkForDuplicateUuids(
225-
new HashSet<>(systemParticipants.allEntitiesAsList()));
226-
exceptions.add(
227-
Try.ofVoid(
228-
exceptionString.isPresent(),
229-
() ->
230-
new InvalidGridException(
231-
duplicateUuidsString(
232-
systemParticipants.getClass().getSimpleName(), exceptionString))));
195+
List<Try<Void, ? extends ValidationException>> exceptions =
196+
new ArrayList<>(
197+
checkForDuplicates(systemParticipants.allEntitiesAsList(), UniqueEntity::getUuid));
233198

234199
exceptions.addAll(checkSystemParticipants(systemParticipants.getBmPlants(), nodes));
235200
exceptions.addAll(checkSystemParticipants(systemParticipants.getChpPlants(), nodes));
@@ -274,23 +239,23 @@ protected static List<Try<Void, UnsafeEntityException>> checkRawGridTypeIds(
274239
* Checks the validity of type ids of every entity.
275240
*
276241
* @param systemParticipants the system participants
277-
* @return a list of try objects either containing an {@link UnsafeEntityException} or an empty
278-
* Success
242+
* @return a list of try objects either containing an {@link DuplicateEntitiesException} or an
243+
* empty Success
279244
*/
280-
protected static List<Try<Void, UnsafeEntityException>> checkSystemParticipantsTypeIds(
245+
protected static List<Try<Void, DuplicateEntitiesException>> checkSystemParticipantsTypeIds(
281246
SystemParticipants systemParticipants) {
282-
List<Try<Void, UnsafeEntityException>> exceptions = new ArrayList<>();
283-
exceptions.addAll(ValidationUtils.checkIds(systemParticipants.getBmPlants()));
284-
exceptions.addAll(ValidationUtils.checkIds(systemParticipants.getChpPlants()));
285-
exceptions.addAll(ValidationUtils.checkIds(systemParticipants.getEvCS()));
286-
exceptions.addAll(ValidationUtils.checkIds(systemParticipants.getEvs()));
287-
exceptions.addAll(ValidationUtils.checkIds(systemParticipants.getFixedFeedIns()));
288-
exceptions.addAll(ValidationUtils.checkIds(systemParticipants.getHeatPumps()));
289-
exceptions.addAll(ValidationUtils.checkIds(systemParticipants.getLoads()));
290-
exceptions.addAll(ValidationUtils.checkIds(systemParticipants.getPvPlants()));
291-
exceptions.addAll(ValidationUtils.checkIds(systemParticipants.getStorages()));
292-
exceptions.addAll(ValidationUtils.checkIds(systemParticipants.getWecPlants()));
293-
exceptions.addAll(ValidationUtils.checkIds(systemParticipants.getEmSystems()));
247+
List<Try<Void, DuplicateEntitiesException>> exceptions = new ArrayList<>();
248+
exceptions.addAll(checkForDuplicates(systemParticipants.getBmPlants(), AssetInput::getId));
249+
exceptions.addAll(checkForDuplicates(systemParticipants.getChpPlants(), AssetInput::getId));
250+
exceptions.addAll(checkForDuplicates(systemParticipants.getEvCS(), AssetInput::getId));
251+
exceptions.addAll(checkForDuplicates(systemParticipants.getEvs(), AssetInput::getId));
252+
exceptions.addAll(checkForDuplicates(systemParticipants.getFixedFeedIns(), AssetInput::getId));
253+
exceptions.addAll(checkForDuplicates(systemParticipants.getHeatPumps(), AssetInput::getId));
254+
exceptions.addAll(checkForDuplicates(systemParticipants.getLoads(), AssetInput::getId));
255+
exceptions.addAll(checkForDuplicates(systemParticipants.getPvPlants(), AssetInput::getId));
256+
exceptions.addAll(checkForDuplicates(systemParticipants.getStorages(), AssetInput::getId));
257+
exceptions.addAll(checkForDuplicates(systemParticipants.getWecPlants(), AssetInput::getId));
258+
exceptions.addAll(checkForDuplicates(systemParticipants.getEmSystems(), AssetInput::getId));
294259

295260
return exceptions;
296261
}
@@ -312,18 +277,10 @@ protected static List<Try<Void, UnsafeEntityException>> checkSystemParticipantsT
312277
return List.of(isNull);
313278
}
314279

315-
List<Try<Void, ? extends ValidationException>> exceptions = new ArrayList<>();
316-
317280
// sanity check for distinct uuids
318-
Optional<String> exceptionString =
319-
checkForDuplicateUuids(new HashSet<>(graphicElements.allEntitiesAsList()));
320-
exceptions.add(
321-
Try.ofVoid(
322-
exceptionString.isPresent(),
323-
() ->
324-
new InvalidGridException(
325-
duplicateUuidsString(
326-
graphicElements.getClass().getSimpleName(), exceptionString))));
281+
List<Try<Void, ? extends ValidationException>> exceptions =
282+
new ArrayList<>(
283+
checkForDuplicates(graphicElements.allEntitiesAsList(), UniqueEntity::getUuid));
327284

328285
graphicElements
329286
.getNodeGraphics()

0 commit comments

Comments
 (0)