Skip to content

Commit 14b6fbf

Browse files
authored
AER-3873 - Make heat content validation more specific (#353)
* Implement heat content validation in OPSSourceCharacteristics class Added a new method to validate heat content based on its type, ensuring that for non-forced heat content types, the heat content is present and falls within the defined limits. Removed the previous min/max annotations from the getHeatContent method to streamline validation logic. * Make comment more specific
1 parent e21e2f7 commit 14b6fbf

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

source/imaer-shared/src/main/java/nl/overheid/aerius/shared/domain/v2/characteristics/OPSSourceCharacteristics.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import jakarta.validation.constraints.Max;
2121
import jakarta.validation.constraints.Min;
22+
import jakarta.validation.constraints.AssertTrue;
2223

2324
import com.fasterxml.jackson.annotation.JsonIgnore;
2425

@@ -96,8 +97,6 @@ public void setHeatContentType(final HeatContentType heatContentType) {
9697
this.heatContentType = heatContentType;
9798
}
9899

99-
@Min(value = OPSLimits.SOURCE_HEAT_CONTENT_MINIMUM, message = "ops heat_content > " + OPSLimits.SOURCE_HEAT_CONTENT_MINIMUM)
100-
@Max(value = OPSLimits.SOURCE_HEAT_CONTENT_MAXIMUM, message = "ops heat_content < " + OPSLimits.SOURCE_HEAT_CONTENT_MAXIMUM)
101100
public Double getHeatContent() {
102101
return heatContent;
103102
}
@@ -106,6 +105,21 @@ public void setHeatContent(final Double heatContent) {
106105
this.heatContent = heatContent;
107106
}
108107

108+
@JsonIgnore
109+
@AssertTrue(message = "for NOT_FORCED heat content types, ops heat_content must be present and between "
110+
+ OPSLimits.SOURCE_HEAT_CONTENT_MINIMUM + " and " + OPSLimits.SOURCE_HEAT_CONTENT_MAXIMUM + " (both inclusive)")
111+
public boolean isHeatContentValid() {
112+
if (heatContentType == HeatContentType.FORCED) {
113+
return true;
114+
}
115+
if (heatContent == null) {
116+
return false;
117+
}
118+
final boolean withinMinimum = heatContent >= OPSLimits.SOURCE_HEAT_CONTENT_MINIMUM;
119+
final boolean withinMaximum = heatContent <= OPSLimits.SOURCE_HEAT_CONTENT_MAXIMUM;
120+
return withinMinimum && withinMaximum;
121+
}
122+
109123
public Double getEmissionTemperature() {
110124
return emissionTemperature;
111125
}

0 commit comments

Comments
 (0)