-
Notifications
You must be signed in to change notification settings - Fork 5
/
NodeValidationUtils.java
88 lines (80 loc) · 3.49 KB
/
NodeValidationUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* © 2021. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
package edu.ie3.datamodel.utils.validation;
import edu.ie3.datamodel.exceptions.*;
import edu.ie3.datamodel.models.StandardUnits;
import edu.ie3.datamodel.models.input.NodeInput;
import edu.ie3.datamodel.models.voltagelevels.VoltageLevel;
import edu.ie3.datamodel.utils.options.Failure;
import edu.ie3.datamodel.utils.options.Success;
import edu.ie3.datamodel.utils.options.Try;
import tech.units.indriya.quantity.Quantities;
import tech.units.indriya.unit.Units;
public class NodeValidationUtils extends ValidationUtils {
/** Private Constructor as this class is not meant to be instantiated */
private NodeValidationUtils() {
throw new IllegalStateException("Don't try and instantiate a Utility class.");
}
/**
* Validates a node if: <br>
* - it is not null <br>
* - voltage level is not null and valid <br>
* - target voltage is larger than zero and smaller than two <br>
* - subnet number is larger than zero <br>
* - geoPosition is not null
*
* @param node Node to validate
* @return a try object either containing an {@link ValidationException} or an empty Success
*/
protected static Try<Void, ValidationException> check(NodeInput node) {
try {
checkNonNull(node, "a node");
} catch (InvalidEntityException e) {
return new Failure<>(
new InvalidEntityException(
"Validation not possible because received object {" + node + "} was null", e));
}
try {
checkVoltageLevel(node.getVoltLvl());
} catch (VoltageLevelException e) {
return new Failure<>(new InvalidEntityException("Node has invalid voltage level", node));
} catch (InvalidEntityException invalidEntityException) {
return new Failure<>(invalidEntityException);
}
if (node.getvTarget()
.isLessThanOrEqualTo(Quantities.getQuantity(0, StandardUnits.TARGET_VOLTAGE_MAGNITUDE))) {
return new Failure<>(
new InvalidEntityException("Target voltage (p.u.) is not a positive value", node));
} else if (node.getvTarget()
.isGreaterThan(Quantities.getQuantity(2, StandardUnits.TARGET_VOLTAGE_MAGNITUDE))) {
return new Failure<>(
new UnsafeEntityException("Target voltage (p.u.) might be too high", node));
}
if (node.getSubnet() <= 0)
return new Failure<>(new InvalidEntityException("Subnet can't be zero or negative", node));
if (node.getGeoPosition() == null) {
return new Failure<>(new InvalidEntityException("GeoPosition of node is null", node));
}
return Success.empty();
}
/**
* Validates a voltage level
*
* @param voltageLevel Element to validate
* @throws InvalidEntityException If the given voltage level is null
* @throws VoltageLevelException If nominal voltage is not apparent or not a positive value
*/
private static void checkVoltageLevel(VoltageLevel voltageLevel)
throws InvalidEntityException, VoltageLevelException {
checkNonNull(voltageLevel, "a voltage level");
if (voltageLevel.getNominalVoltage() == null)
throw new VoltageLevelException(
"The nominal voltage of voltage level " + voltageLevel + " is null");
if (voltageLevel.getNominalVoltage().isLessThanOrEqualTo(Quantities.getQuantity(0, Units.VOLT)))
throw new VoltageLevelException(
"The nominal voltage of voltage level " + voltageLevel + " must be positive!");
}
}