From 8e3f10c0c875c55dce05ab0f3da5b050422de081 Mon Sep 17 00:00:00 2001 From: Michael Junkin Date: Tue, 3 Dec 2024 16:53:09 -0800 Subject: [PATCH] Parameter validation - completed --- .../ProjectionRequestValidationException.java | 10 +- .../nrs/vdyp/backend/model/v1/Parameters.java | 383 +++++++++---- .../backend/model/v1/ProgressFrequency.java | 28 +- .../model/v1/UtilizationParameter.java | 56 +- .../backend/model/v1/ValidationMessage.java | 36 ++ .../model/v1/ValidationMessageKind.java | 46 ++ .../backend/projection/LoggingParameters.java | 23 +- .../ProjectionRequestValidator.java | 247 ++++---- .../backend/projection/ProjectionState.java | 2 +- .../projection/ValidatedParameters.java | 87 ++- .../ValidatedUtilizationParameter.java | 83 +-- .../vdyp/backend/services/HelpService.java | 54 +- .../backend/services/ProjectionService.java | 4 +- .../ca/bc/gov/nrs/api/helpers/TestHelper.java | 10 +- .../api/v1/exceptions/ExceptionsTest.java | 4 - .../v1/DcsvProjectionEndpointTest.java | 1 - .../v1/HcsvProjectionEndpointTest.java | 11 +- .../endpoints/v1/ParameterNamesTest.java | 2 - .../v1/ScsvProjectionEndpointTest.java | 1 - .../vdyp/backend/model/v1/ParametersTest.java | 138 +++-- .../projection/ParameterValidationTest.java | 525 +++++++++++++++++- 21 files changed, 1223 insertions(+), 528 deletions(-) create mode 100644 backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ValidationMessage.java create mode 100644 backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ValidationMessageKind.java rename backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/{model/v1 => projection}/ValidatedUtilizationParameter.java (60%) diff --git a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/api/v1/exceptions/ProjectionRequestValidationException.java b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/api/v1/exceptions/ProjectionRequestValidationException.java index 85428aaea..a1609f26e 100644 --- a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/api/v1/exceptions/ProjectionRequestValidationException.java +++ b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/api/v1/exceptions/ProjectionRequestValidationException.java @@ -2,17 +2,19 @@ import java.util.List; +import ca.bc.gov.nrs.vdyp.backend.model.v1.ValidationMessage; + public class ProjectionRequestValidationException extends Exception { private static final long serialVersionUID = 5172661648677695483L; - private final List validationMessages; + private final List validationMessages; - public ProjectionRequestValidationException(List validationMessages) { + public ProjectionRequestValidationException(List validationMessages) { this.validationMessages = validationMessages; } - - public List getValidationMessages() { + + public List getValidationMessages() { return validationMessages; } } diff --git a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/Parameters.java b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/Parameters.java index 5408998ce..0367110bf 100644 --- a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/Parameters.java +++ b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/Parameters.java @@ -16,6 +16,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.annotation.JsonValue; +import ca.bc.gov.nrs.vdyp.backend.projection.ValidatedUtilizationParameter; import io.quarkus.runtime.annotations.RegisterForReflection; /** @@ -93,7 +94,7 @@ public class Parameters { @JsonProperty(JSON_PROPERTY_UTILS) private List utils = new ArrayList<>(); - public enum OutputFormatEnum { + public enum OutputFormat { YIELD_TABLE("YieldTable"), CSV_YIELD_TABLE("CSVYieldTable"), @@ -102,27 +103,31 @@ public enum OutputFormatEnum { private String value; - OutputFormatEnum(String value) { + OutputFormat(String value) { this.value = value; } @Override - @JsonValue public String toString() { - return String.valueOf(value); + return getValue(); + } + + @JsonValue + public String getValue() { + return value; } /** * Converts value in a value from this enumeration, throwing an * IllegalArgumentException when there's no match. * - * @param value the corresponding to a value of this enumeration + * @param value the corresponding to a value of this enumeration * @return the enumeration value * @throws IllegalArgumentException when conversion cannot be performed */ @JsonCreator - public static OutputFormatEnum fromValue(String value) { - for (OutputFormatEnum b : OutputFormatEnum.values()) { + public static OutputFormat fromValue(String value) { + for (OutputFormat b : OutputFormat.values()) { if (b.value.equals(value)) { return b; } @@ -131,7 +136,7 @@ public static OutputFormatEnum fromValue(String value) { } } - public enum SelectedExecutionOptionsEnum { + public enum ExecutionOption { BACK_GROW_ENABLED("backGrowEnabled"), // FORWARD_GROW_ENABLED("forwardGrowEnabled"), // @@ -163,13 +168,17 @@ public enum SelectedExecutionOptionsEnum { private String value; - SelectedExecutionOptionsEnum(String value) { + ExecutionOption(String value) { this.value = value; } @Override - @JsonValue public String toString() { + return getValue(); + } + + @JsonValue + public String getValue() { return value; } @@ -177,13 +186,13 @@ public String toString() { * Converts value in a value from this enumeration, throwing an * IllegalArgumentException when there's no match. * - * @param value the corresponding to a value of this enumeration + * @param value the corresponding to a value of this enumeration * @return the enumeration value * @throws IllegalArgumentException when conversion cannot be performed */ @JsonCreator - public static SelectedExecutionOptionsEnum fromValue(String value) { - for (SelectedExecutionOptionsEnum b : SelectedExecutionOptionsEnum.values()) { + public static ExecutionOption fromValue(String value) { + for (ExecutionOption b : ExecutionOption.values()) { if (b.value.equals(value)) { return b; } @@ -197,7 +206,7 @@ public static SelectedExecutionOptionsEnum fromValue(String value) { /** * Determines how the Age Range and Year Range are to be combined when producing yield tables. */ - public enum CombineAgeYearRangeEnum { + public enum AgeYearRangeCombinationKind { UNION("union"), INTERSECT("intersect"), @@ -206,27 +215,31 @@ public enum CombineAgeYearRangeEnum { private String value; - CombineAgeYearRangeEnum(String value) { + AgeYearRangeCombinationKind(String value) { this.value = value; } @Override - @JsonValue public String toString() { - return String.valueOf(value); + return getValue(); + } + + @JsonValue + public String getValue() { + return value; } /** * Converts value in a value from this enumeration, throwing an * IllegalArgumentException when there's no match. * - * @param value the corresponding to a value of this enumeration + * @param value the corresponding to a value of this enumeration * @return the enumeration value * @throws IllegalArgumentException when conversion cannot be performed */ @JsonCreator - public static CombineAgeYearRangeEnum fromValue(String value) { - for (CombineAgeYearRangeEnum b : CombineAgeYearRangeEnum.values()) { + public static AgeYearRangeCombinationKind fromValue(String value) { + for (AgeYearRangeCombinationKind b : AgeYearRangeCombinationKind.values()) { if (b.value.equals(value)) { return b; } @@ -237,7 +250,7 @@ public static CombineAgeYearRangeEnum fromValue(String value) { } } - public enum SelectedDebugOptionsEnum { + public enum DebugOption { DO_INCLUDE_DEBUG_TIMESTAMPS("doIncludeDebugTimestamps"), DO_INCLUDE_DEBUG_ROUTINE_NAMES("doIncludeDebugRoutineNames"), DO_INCLUDE_DEBUG_ENTRY_EXIT("doIncludeDebugEntryExit"), @@ -245,27 +258,31 @@ public enum SelectedDebugOptionsEnum { private String value; - SelectedDebugOptionsEnum(String value) { + DebugOption(String value) { this.value = value; } @Override - @JsonValue public String toString() { - return String.valueOf(value); + return getValue(); + } + + @JsonValue + public String getValue() { + return value; } /** * Converts value in a value from this enumeration, throwing an * IllegalArgumentException when there's no match. * - * @param value the corresponding to a value of this enumeration + * @param value the corresponding to a value of this enumeration * @return the enumeration value * @throws IllegalArgumentException when conversion cannot be performed */ @JsonCreator - public static SelectedDebugOptionsEnum fromValue(String value) { - for (SelectedDebugOptionsEnum b : SelectedDebugOptionsEnum.values()) { + public static DebugOption fromValue(String value) { + for (DebugOption b : DebugOption.values()) { if (b.value.equals(value)) { return b; } @@ -279,32 +296,36 @@ public static SelectedDebugOptionsEnum fromValue(String value) { /** * Controls how much metadata is displayed in the Output and Error Logs. */ - public enum MetadataToOutputEnum { + public enum MetadataToOutputDirective { ALL("ALL"), MAIN("MAIN"), VERSION("VERSION"), MIN_IDENT("MIN_IDENT"), NONE("NONE"); private String value; - MetadataToOutputEnum(String value) { + MetadataToOutputDirective(String value) { this.value = value; } @Override - @JsonValue public String toString() { - return String.valueOf(value); + return getValue(); + } + + @JsonValue + public String getValue() { + return value; } /** * Converts value in a value from this enumeration, throwing an * IllegalArgumentException when there's no match. * - * @param value the corresponding to a value of this enumeration + * @param value the corresponding to a value of this enumeration * @return the enumeration value * @throws IllegalArgumentException when conversion cannot be performed */ @JsonCreator - public static MetadataToOutputEnum fromValue(String value) { - for (MetadataToOutputEnum b : MetadataToOutputEnum.values()) { + public static MetadataToOutputDirective fromValue(String value) { + for (MetadataToOutputDirective b : MetadataToOutputDirective.values()) { if (b.value.equals(value)) { return b; } @@ -315,11 +336,6 @@ public static MetadataToOutputEnum fromValue(String value) { } } - public Parameters outputFormat(String outputFormat) { - this.outputFormat = outputFormat; - return this; - } - /** * Identifies the output file format. Default: YieldTable * @@ -330,20 +346,24 @@ public String getOutputFormat() { return outputFormat; } - public void setOutputFormat(String outputFormat) { - this.outputFormat = outputFormat; + public Parameters outputFormat(OutputFormat outputFormat) { + setOutputFormat(outputFormat); + return this; } - public Parameters selectedExecutionOptions(List selectedExecutionOptions) { - setSelectedExecutionOptions(selectedExecutionOptions); - return this; + public void setOutputFormat(OutputFormat outputFormat) { + this.outputFormat = outputFormat.value; } - public Parameters addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum selectedExecutionOptionsItem) { - this.selectedExecutionOptions.add(selectedExecutionOptionsItem.name()); + public Parameters outputFormat(String outputFormatText) { + setOutputFormat(outputFormatText); return this; } + public void setOutputFormat(String outputFormatText) { + this.outputFormat = outputFormatText; + } + /** * Get selectedExecutionOptions * @@ -355,21 +375,29 @@ public List getSelectedExecutionOptions() { return selectedExecutionOptions; } - public void setSelectedExecutionOptions(List selectedExecutionOptions) { + public void setSelectedExecutionOptions(List selectedExecutionOptions) { if (selectedExecutionOptions == null) { this.selectedExecutionOptions.clear(); } else { - this.selectedExecutionOptions = selectedExecutionOptions; + this.selectedExecutionOptions = new ArrayList(); + selectedExecutionOptions.stream().forEach(o -> this.selectedExecutionOptions.add(o.getValue())); } } - public Parameters selectedDebugOptions(List selectedDebugOptions) { - setSelectedDebugOptions(selectedDebugOptions); + public Parameters selectedExecutionOptions(List selectedExecutionOptions) { + setSelectedExecutionOptions(selectedExecutionOptions); + return this; + } + + public Parameters addSelectedExecutionOptionsItem(ExecutionOption selectedExecutionOptionsItem) { + this.selectedExecutionOptions.add(selectedExecutionOptionsItem.getValue()); return this; } - public Parameters addSelectedDebugOptionsItem(SelectedDebugOptionsEnum selectedDebugOptionsItem) { - this.selectedDebugOptions.add(selectedDebugOptionsItem.name()); + public Parameters addSelectedExecutionOptionsItem(String selectedExecutionOptionsItemText) { + if (selectedExecutionOptionsItemText != null) { + this.selectedExecutionOptions.add(selectedExecutionOptionsItemText); + } return this; } @@ -383,16 +411,29 @@ public List getSelectedDebugOptions() { return selectedDebugOptions; } - public void setSelectedDebugOptions(List selectedDebugOptions) { + public void setSelectedDebugOptions(List selectedDebugOptions) { if (selectedDebugOptions == null) { - this.selectedDebugOptions.clear(); + this.selectedDebugOptions = null; } else { - this.selectedDebugOptions = selectedDebugOptions; + this.selectedDebugOptions = new ArrayList<>(); + selectedDebugOptions.stream().forEach(o -> this.selectedDebugOptions.add(o.getValue())); } } - public Parameters ageStart(String ageStart) { - this.ageStart = ageStart; + public Parameters selectedDebugOptions(List selectedDebugOptions) { + setSelectedDebugOptions(selectedDebugOptions); + return this; + } + + public Parameters addSelectedDebugOptionsItem(DebugOption selectedDebugOptionsItem) { + this.selectedDebugOptions.add(selectedDebugOptionsItem.getValue()); + return this; + } + + public Parameters addSelectedDebugOptionsItem(String selectedDebugOptionsItemText) { + if (selectedDebugOptionsItemText != null) { + this.selectedDebugOptions.add(selectedDebugOptionsItemText); + } return this; } @@ -406,15 +447,24 @@ public String getAgeStart() { return ageStart; } - public void setAgeStart(String ageStart) { - this.ageStart = ageStart; + public Parameters ageStart(Integer ageStart) { + setAgeStart(ageStart); + return this; + } + + public void setAgeStart(Integer ageStart) { + this.ageStart = ageStart == null ? null : ageStart.toString(); } - public Parameters ageEnd(String ageEnd) { - this.ageEnd = ageEnd; + public Parameters ageStart(String ageStartText) { + setAgeStart(ageStartText); return this; } + public void setAgeStart(String ageStartText) { + this.ageStart = ageStartText; + } + /** * The ending age value for the Age Range for generated yield tables. * @@ -425,15 +475,24 @@ public String getAgeEnd() { return ageEnd; } - public void setAgeEnd(String ageEnd) { - this.ageEnd = ageEnd; + public Parameters ageEnd(Integer ageEnd) { + setAgeEnd(ageEnd); + return this; + } + + public void setAgeEnd(Integer ageEnd) { + this.ageEnd = ageEnd == null ? null : ageEnd.toString(); } - public Parameters yearStart(String yearStart) { - this.yearStart = yearStart; + public Parameters ageEnd(String ageEndText) { + setAgeEnd(ageEnd); return this; } + public void setAgeEnd(String ageEndText) { + this.ageEnd = ageEndText; + } + /** * The starting year for the Year Range for generated yield tables. * @@ -444,15 +503,24 @@ public String getYearStart() { return yearStart; } - public void setYearStart(String yearStart) { - this.yearStart = yearStart; + public Parameters yearStart(Integer yearStart) { + setYearStart(yearStart); + return this; + } + + public void setYearStart(Integer yearStart) { + this.yearStart = yearStart == null ? null : yearStart.toString(); } - public Parameters yearEnd(String yearEnd) { - this.yearEnd = yearEnd; + public Parameters yearStart(String yearStartText) { + setYearStart(yearStartText); return this; } + public void setYearStart(String yearStartText) { + this.yearStart = yearStartText; + } + /** * The ending year for the Year Range for generated yield tables. * @@ -463,15 +531,24 @@ public String getYearEnd() { return yearEnd; } - public void setYearEnd(String yearEnd) { - this.yearEnd = yearEnd; + public Parameters yearEnd(Integer yearEnd) { + setYearEnd(yearEnd); + return this; + } + + public void setYearEnd(Integer yearEnd) { + this.yearEnd = yearEnd == null ? null : yearEnd.toString(); } - public Parameters forceYear(String forceYear) { - this.forceYear = forceYear; + public Parameters yearEnd(String yearEndText) { + setYearEnd(yearEndText); return this; } + public void setYearEnd(String yearEndText) { + this.yearEnd = yearEndText == null ? null : yearEndText.toString(); + } + /** * Forces the inclusion of the specified calendar year in Yield tables. * @@ -482,15 +559,24 @@ public String getForceYear() { return forceYear; } - public void setForceYear(String forceYear) { - this.forceYear = forceYear; + public Parameters forceYear(Integer forceYear) { + setForceYear(forceYear); + return this; + } + + public void setForceYear(Integer forceYear) { + this.forceYear = forceYear == null ? null : forceYear.toString(); } - public Parameters ageIncrement(String ageIncrement) { - this.ageIncrement = ageIncrement; + public Parameters forceYear(String forceYearText) { + setForceYear(forceYearText); return this; } + public void setForceYear(String forceYearText) { + this.forceYear = forceYearText; + } + /** * The number of years to increment the current value for the Age and Year ranges. * @@ -501,15 +587,24 @@ public String getAgeIncrement() { return ageIncrement; } - public void setAgeIncrement(String ageIncrement) { - this.ageIncrement = ageIncrement; + public Parameters ageIncrement(Integer ageIncrement) { + setAgeIncrement(ageIncrement); + return this; + } + + public void setAgeIncrement(Integer ageIncrement) { + this.ageIncrement = ageIncrement == null ? null : ageIncrement.toString(); } - public Parameters combineAgeYearRange(String combineAgeYearRange) { - this.combineAgeYearRange = combineAgeYearRange; + public Parameters ageIncrement(String ageIncrementText) { + setAgeIncrement(ageIncrementText); return this; } + public void setAgeIncrement(String ageIncrementText) { + this.ageIncrement = ageIncrementText; + } + /** * Determines how the Age Range and Year Range are to be combined when producing yield tables. * @@ -520,15 +615,24 @@ public String getCombineAgeYearRange() { return combineAgeYearRange; } - public void setCombineAgeYearRange(String combineAgeYearRange) { - this.combineAgeYearRange = combineAgeYearRange; + public Parameters combineAgeYearRange(AgeYearRangeCombinationKind combineAgeYearRange) { + setCombineAgeYearRange(combineAgeYearRange); + return this; + } + + public void setCombineAgeYearRange(AgeYearRangeCombinationKind combineAgeYearRange) { + this.combineAgeYearRange = combineAgeYearRange == null ? null : combineAgeYearRange.getValue(); } - public Parameters progressFrequency(String progressFrequency) { - this.progressFrequency = progressFrequency; + public Parameters combineAgeYearRange(String combineAgeYearRangeText) { + setCombineAgeYearRange(combineAgeYearRangeText); return this; } + public void setCombineAgeYearRange(String combineAgeYearRangeText) { + this.combineAgeYearRange = combineAgeYearRangeText; + } + /** * Get progressFrequency * @@ -539,15 +643,39 @@ public String getProgressFrequency() { return progressFrequency; } - public void setProgressFrequency(String progressFrequency) { - this.progressFrequency = progressFrequency; + public Parameters progressFrequency(ProgressFrequency.FrequencyKind progressFrequency) { + setProgressFrequency(progressFrequency); + return this; + } + + public void setProgressFrequency(ProgressFrequency.FrequencyKind progressFrequency) { + if (progressFrequency != null) { + this.progressFrequency = progressFrequency.getValue(); + } + } + + public Parameters progressFrequency(Integer progressFrequency) { + setProgressFrequency(progressFrequency); + return this; } - public Parameters metadataToOutput(String metadataToOutput) { - this.metadataToOutput = metadataToOutput; + public void setProgressFrequency(Integer progressFrequency) { + if (progressFrequency != null) { + this.progressFrequency = progressFrequency.toString(); + } + } + + public Parameters progressFrequency(String progressFrequency) { + setProgressFrequency(progressFrequency); return this; } + public void setProgressFrequency(String progressFrequency) { + if (progressFrequency != null) { + this.progressFrequency = progressFrequency; + } + } + /** * Controls how much metadata is displayed in the Output and Error Logs. * @@ -558,15 +686,24 @@ public String getMetadataToOutput() { return metadataToOutput; } - public void setMetadataToOutput(String metadataToOutput) { - this.metadataToOutput = metadataToOutput; + public Parameters metadataToOutput(MetadataToOutputDirective metadataToOutput) { + setMetadataToOutput(metadataToOutput); + return this; } - public Parameters filters(Filters filters) { - this.filters = filters; + public void setMetadataToOutput(MetadataToOutputDirective metadataToOutput) { + this.metadataToOutput = metadataToOutput == null ? null : metadataToOutput.getValue(); + } + + public Parameters metadataToOutput(String metadataToOutputText) { + setMetadataToOutput(metadataToOutputText); return this; } + public void setMetadataToOutput(String metadataToOutputText) { + this.metadataToOutput = metadataToOutputText; + } + /** * Get filters * @@ -577,21 +714,13 @@ public Filters getFilters() { return filters; } - public void setFilters(Filters filters) { + public Parameters filters(Filters filters) { this.filters = filters; - } - - public Parameters utils(List utils) { - setUtils(utils); return this; } - public Parameters addUtilsItem(ValidatedUtilizationParameter utilsItem) { - this.utils.add( - new UtilizationParameter().speciesName(utilsItem.getSpeciesName()) - .value(utilsItem.getValue().name()) - ); - return this; + public void setFilters(Filters filters) { + this.filters = filters; } /** @@ -604,14 +733,40 @@ public List getUtils() { return utils; } - public void setUtils(List utils) { + public Parameters utils(List utils) { + setUtils(utils); + return this; + } + + public Parameters addUtilsItem(ValidatedUtilizationParameter utilsItem) { + this.utils.add( + new UtilizationParameter().speciesName(utilsItem.getSpeciesName()).utilizationClass(utilsItem.getUtilizationClass().getValue()) + ); + return this; + } + + public void setUtils(List utils) { if (utils == null) { - this.utils.clear(); + this.utils = null; } else { - this.utils = utils; + this.utils = new ArrayList<>(); + utils.stream() + .forEach( + u -> this.utils.add( + new UtilizationParameter().speciesName(u.getSpeciesName()) + .utilizationClass(u.getUtilizationClass().getValue()) + ) + ); } } + public Parameters addUtilsItem(UtilizationParameter utilsItem) { + if (utilsItem != null) { + this.utils.add(utilsItem); + } + return this; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -624,8 +779,7 @@ public boolean equals(Object o) { return Objects.equals(this.outputFormat, parameters.outputFormat) && Objects.equals(this.selectedExecutionOptions, parameters.selectedExecutionOptions) && Objects.equals(this.selectedDebugOptions, parameters.selectedDebugOptions) - && Objects.equals(this.ageStart, parameters.ageStart) - && Objects.equals(this.ageEnd, parameters.ageEnd) + && Objects.equals(this.ageStart, parameters.ageStart) && Objects.equals(this.ageEnd, parameters.ageEnd) && Objects.equals(this.yearStart, parameters.yearStart) && Objects.equals(this.yearEnd, parameters.yearEnd) && Objects.equals(this.forceYear, parameters.forceYear) @@ -633,16 +787,14 @@ public boolean equals(Object o) { && Objects.equals(this.combineAgeYearRange, parameters.combineAgeYearRange) && Objects.equals(this.progressFrequency, parameters.progressFrequency) && Objects.equals(this.metadataToOutput, parameters.metadataToOutput) - && Objects.equals(this.filters, parameters.filters) - && Objects.equals(this.utils, parameters.utils); + && Objects.equals(this.filters, parameters.filters) && Objects.equals(this.utils, parameters.utils); } @Override public int hashCode() { return Objects.hash( - outputFormat, selectedExecutionOptions, selectedDebugOptions, ageStart, ageEnd, - yearStart, yearEnd, forceYear, ageIncrement, combineAgeYearRange, - progressFrequency, metadataToOutput, filters, utils + outputFormat, selectedExecutionOptions, selectedDebugOptions, ageStart, ageEnd, yearStart, yearEnd, + forceYear, ageIncrement, combineAgeYearRange, progressFrequency, metadataToOutput, filters, utils ); } @@ -652,8 +804,7 @@ public String toString() { sb.append("class Parameters {\n"); sb.append(" outputFormat: ").append(toIndentedString(outputFormat)).append("\n"); - sb.append(" selectedExecutionOptions: ").append(toIndentedString(selectedExecutionOptions)) - .append("\n"); + sb.append(" selectedExecutionOptions: ").append(toIndentedString(selectedExecutionOptions)).append("\n"); sb.append(" selectedDebugOptions: ").append(toIndentedString(selectedDebugOptions)).append("\n"); sb.append(" ageStart: ").append(toIndentedString(ageStart)).append("\n"); sb.append(" ageEnd: ").append(toIndentedString(ageEnd)).append("\n"); diff --git a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ProgressFrequency.java b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ProgressFrequency.java index 479cfaca2..d37c65c36 100644 --- a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ProgressFrequency.java +++ b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ProgressFrequency.java @@ -35,24 +35,28 @@ public class ProgressFrequency { public static final String JSON_PROPERTY_ENUM_VALUE_NAME = "enumValue"; @JsonProperty(JSON_PROPERTY_ENUM_VALUE_NAME) - private EnumValue enumValue; + private FrequencyKind enumValue; /** * Gets or Sets value */ - public enum EnumValue { + public enum FrequencyKind { NEVER("never"), POLYGON("polygon"), MAPSHEET("mapsheet"); private String value; - EnumValue(String value) { + FrequencyKind(String value) { this.value = value; } @Override - @JsonValue public String toString() { - return String.valueOf(value); + return getValue(); + } + + @JsonValue + public String getValue() { + return value; } /** @@ -64,8 +68,8 @@ public String toString() { * @throws IllegalArgumentException when conversion cannot be performed */ @JsonCreator - public static EnumValue fromValue(String value) { - for (EnumValue b : EnumValue.values()) { + public static FrequencyKind fromValue(String value) { + for (FrequencyKind b : FrequencyKind.values()) { if (b.value.equals(value)) { return b; } @@ -79,7 +83,7 @@ public ProgressFrequency() { this.enumValue = null; } - public ProgressFrequency(EnumValue enumValue) { + public ProgressFrequency(FrequencyKind enumValue) { setEnumValue(enumValue); } @@ -90,7 +94,7 @@ public ProgressFrequency(int intValue) { public ProgressFrequency(String text) { text = text.trim(); try { - setEnumValue(EnumValue.fromValue(text)); + setEnumValue(FrequencyKind.fromValue(text)); } catch (IllegalArgumentException iae) { try { setIntValue(Integer.parseInt(text)); @@ -117,18 +121,18 @@ public Integer getIntValue() { return intValue; } - public ProgressFrequency enumValue(EnumValue enumValue) { + public ProgressFrequency enumValue(FrequencyKind enumValue) { setEnumValue(enumValue); return this; } - public void setEnumValue(EnumValue enumValue) { + public void setEnumValue(FrequencyKind enumValue) { this.intValue = null; this.enumValue = enumValue; } @JsonProperty(JSON_PROPERTY_ENUM_VALUE_NAME) - public EnumValue getEnumValue() { + public FrequencyKind getEnumValue() { return enumValue; } diff --git a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/UtilizationParameter.java b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/UtilizationParameter.java index 5ae0e6f7c..70c56260a 100644 --- a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/UtilizationParameter.java +++ b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/UtilizationParameter.java @@ -24,9 +24,7 @@ /** * This class records a utilization class for a given sp0 (species group) name. */ -@JsonPropertyOrder( - { UtilizationParameter.JSON_PROPERTY_SPECIES_NAME, UtilizationParameter.JSON_PROPERTY_VALUE } -) +@JsonPropertyOrder({ UtilizationParameter.JSON_PROPERTY_SPECIES_NAME, UtilizationParameter.JSON_PROPERTY_VALUE }) @RegisterForReflection public class UtilizationParameter { public static final String JSON_PROPERTY_SPECIES_NAME = "speciesName"; @@ -35,12 +33,12 @@ public class UtilizationParameter { public static final String JSON_PROPERTY_VALUE = "value"; @JsonProperty(JSON_PROPERTY_VALUE) - private String value; + private String utilizationClass; /** * Gets or Sets value */ - public enum ValueEnum { + public enum UtilizationClass { EXCL("Excl"), _4_0("4.0"), @@ -55,19 +53,23 @@ public enum ValueEnum { private String value; - ValueEnum(String value) { + UtilizationClass(String value) { this.value = value; } @Override - @JsonValue public String toString() { - return String.valueOf(value); + return getValue(); + } + + @JsonValue + public String getValue() { + return value; } @JsonCreator - public static ValueEnum fromValue(String value) { - for (ValueEnum b : ValueEnum.values()) { + public static UtilizationClass fromValue(String value) { + for (UtilizationClass b : UtilizationClass.values()) { if (b.value.equals(value)) { return b; } @@ -96,24 +98,32 @@ public void setSpeciesName(String speciesName) { this.speciesName = speciesName; } - public UtilizationParameter value(String value) { - this.value = value; - return this; - } - /** * Get value * * @return value **/ - @JsonProperty(value = "value") + @JsonProperty(value = "utilizationClass") + public String getUtilizationClass() { + return utilizationClass; + } - public String getValue() { - return value; + public UtilizationParameter utilizationClass(String utilizationClassText) { + setUtilizationClass(utilizationClassText); + return this; + } + + public void setUtilizationClass(String utilizationClassText) { + this.utilizationClass = utilizationClassText; + } + + public UtilizationParameter utilizationClass(UtilizationClass uc) { + setUtilizationClass(uc); + return this; } - public void setValue(String value) { - this.value = value; + public void setUtilizationClass(UtilizationClass uc) { + this.utilizationClass = uc.getValue(); } @Override @@ -125,12 +135,12 @@ public boolean equals(Object o) { return false; } UtilizationParameter up = (UtilizationParameter) o; - return Objects.equals(this.speciesName, up.speciesName) && Objects.equals(this.value, up.value); + return Objects.equals(this.speciesName, up.speciesName) && Objects.equals(this.utilizationClass, up.utilizationClass); } @Override public int hashCode() { - return Objects.hash(speciesName, value); + return Objects.hash(speciesName, utilizationClass); } @Override @@ -139,7 +149,7 @@ public String toString() { sb.append("class "); sb.append(UtilizationParameter.class.getSimpleName()); sb.append(" {\n speciesName: ").append(toIndentedString(speciesName)).append("\n"); - sb.append(" value: ").append(toIndentedString(value)).append("\n"); + sb.append(" value: ").append(toIndentedString(utilizationClass)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ValidationMessage.java b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ValidationMessage.java new file mode 100644 index 000000000..73606e424 --- /dev/null +++ b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ValidationMessage.java @@ -0,0 +1,36 @@ +package ca.bc.gov.nrs.vdyp.backend.model.v1; + +import java.text.MessageFormat; + +public class ValidationMessage { + + /** the kind of this ValidationMessage - an enum value and a template */ + private final ValidationMessageKind kind; + /** the arguments that, when applied to the template of kind, produce the message */ + private final Object[] args; + + /** the resultion message, calculated from kind and args */ + private final String message; + + public ValidationMessage(ValidationMessageKind kind, Object[] args) { + this.kind = kind; + this.args = args; + + this.message = MessageFormat.format(kind.template, args); + } + + /** the kind of this ValidationMessage - an enum value and a template */ + public ValidationMessageKind getKind() { + return kind; + } + + /** the arguments that, when applied to the template of kind, produce the message */ + public Object[] getArgs() { + return args; + } + + /** the resultion message, calculated from kind and args */ + public String getMessage() { + return message; + } +} diff --git a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ValidationMessageKind.java b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ValidationMessageKind.java new file mode 100644 index 000000000..2f76f8bda --- /dev/null +++ b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ValidationMessageKind.java @@ -0,0 +1,46 @@ +package ca.bc.gov.nrs.vdyp.backend.model.v1; + +public enum ValidationMessageKind { + UNRECOGNIZED_OUTPUT_FORMAT("{0} is not a recognized output format", Category.ERROR), + UNRECOGNIZED_EXECUTION_OPTION("{0} is not a recognized execution option", Category.ERROR), + UNRECOGNIZED_DEBUG_OPTION("{0} is not a recognized debug option", Category.ERROR), + UNRECOGNIZED_COMBINE_AGE_YEAR_RANGE_OPTION("{0} is not a recognized CombineAgeYearRangeEnum value", Category.ERROR), + INVALID_PROCESS_FREQUENCY_VALUE("{0} is not a recognized CombineAgeYearRangeEnum value", Category.ERROR), + INVALID_METADATA_TO_OUTPUT_VALUE("{0} is not a recognized MetadataToOutputEnum value", Category.ERROR), + UNKNOWN_SPECIES_GROUP_NAME("Species Group name \"{0}\" is not a known Species Group name", Category.ERROR), + UNKNOWN_UTILIZATION_CLASS_NAME("Utilization Class \"{0}\" is not a known Utilization Class name", Category.ERROR), + MISSING_START_CRITERIA("At least one of \"ageStart\" or \"yearStart\" must be given", Category.ERROR), + MISSING_END_CRITERIA("At least one of \"ageEnd\" or \"yearEnd\" must be given", Category.ERROR), + MISMATCHED_INPUT_OUTPUT_TYPES( + "DCSV output Format can be selected when, and only when, the input format is DCSV", Category.ERROR + ), + AGE_RANGES_IGNORED_WHEN_DCSV_OUTPUT( + "Age range yield table parameters are ignored when DCSV output format is requested", Category.WARNING + ), + MUST_BE_EXACTLY_ONE_FORCE_PARAM_WHEN_DCSV_OUTPUT( + "Exactly one of \"{0}\", \"{1}\" and \"{2}\" must be specified with the DCSV Output Format", Category.ERROR + ), + INVALID_CFS_BIOMASS_OUTPUT_FORMAT( + "CFS Biomass output is only supported for {0} and {1} output formats", Category.ERROR + ), + CANNOT_SPECIFY_BOTH_CFS_AND_MOF_BIOMASS_OUTPUT( + "MoF and CFS Biomass Output can not be selected at the same time", Category.ERROR + ), + CANNOT_SPECIFY_BOTH_CFS_BIOMASS_AND_EITHER_MOF_OPTIONS( + "For CSV Yield Table of CFS Biomass, neither MoF Volume or Biomass may also be selected.", Category.ERROR + ), INVALID_INTEGER_VALUE("Field {1}''s value \"{0}\" is not an integer", Category.ERROR), + INTEGER_VALUE_TOO_LOW("Field {1}''s value \"{0}\" is not an integer", Category.ERROR), + INTEGER_VALUE_TOO_HIGH("Field {1}''s value \"{0}\" is not an integer", Category.ERROR),; + + public enum Category { + ERROR, WARNING, INFO + }; + + public final String template; + public final Category category; + + ValidationMessageKind(String template, Category category) { + this.template = template; + this.category = category; + } +} diff --git a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/LoggingParameters.java b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/LoggingParameters.java index b46ec5dc0..032beb5fa 100644 --- a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/LoggingParameters.java +++ b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/LoggingParameters.java @@ -4,8 +4,8 @@ import java.util.Objects; import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedDebugOptionsEnum; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedExecutionOptionsEnum; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.DebugOption; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.ExecutionOption; /** * The class represents a Parameter class instance whose logging related parameters have been validated and presents @@ -27,54 +27,55 @@ public class LoggingParameters { private LoggingParameters(Parameters params) { if (params == null) { - params = new Parameters().selectedExecutionOptions(new ArrayList()) - .selectedDebugOptions(new ArrayList()); + params = new Parameters() // + .selectedExecutionOptions(new ArrayList()) // + .selectedDebugOptions(new ArrayList()); } if (params.getSelectedExecutionOptions() - .contains(SelectedExecutionOptionsEnum.DO_ENABLE_ERROR_LOGGING.toString())) { + .contains(ExecutionOption.DO_ENABLE_ERROR_LOGGING.toString())) { doEnableErrorLogging = true; } else { doEnableErrorLogging = LoggingParameters.DEFAULT.doEnableErrorLogging; } if (params.getSelectedExecutionOptions() - .contains(SelectedExecutionOptionsEnum.DO_ENABLE_PROGRESS_LOGGING.toString())) { + .contains(ExecutionOption.DO_ENABLE_PROGRESS_LOGGING.toString())) { doEnableProgressLogging = true; } else { doEnableProgressLogging = LoggingParameters.DEFAULT.doEnableProgressLogging; } if (params.getSelectedExecutionOptions() - .contains(SelectedExecutionOptionsEnum.DO_ENABLE_DEBUG_LOGGING.toString())) { + .contains(ExecutionOption.DO_ENABLE_DEBUG_LOGGING.toString())) { doEnableDebugLogging = true; } else { doEnableDebugLogging = LoggingParameters.DEFAULT.doEnableDebugLogging; } if (params.getSelectedDebugOptions() - .contains(SelectedDebugOptionsEnum.DO_INCLUDE_DEBUG_ENTRY_EXIT.toString())) { + .contains(DebugOption.DO_INCLUDE_DEBUG_ENTRY_EXIT.toString())) { doIncludeDebugEntryExit = true; } else { doIncludeDebugEntryExit = LoggingParameters.DEFAULT.doIncludeDebugEntryExit; } if (params.getSelectedDebugOptions() - .contains(SelectedDebugOptionsEnum.DO_INCLUDE_DEBUG_INDENT_BLOCKS.toString())) { + .contains(DebugOption.DO_INCLUDE_DEBUG_INDENT_BLOCKS.toString())) { doIncludeDebugIndentBlocks = true; } else { doIncludeDebugIndentBlocks = LoggingParameters.DEFAULT.doIncludeDebugIndentBlocks; } if (params.getSelectedDebugOptions() - .contains(SelectedDebugOptionsEnum.DO_INCLUDE_DEBUG_ROUTINE_NAMES.toString())) { + .contains(DebugOption.DO_INCLUDE_DEBUG_ROUTINE_NAMES.toString())) { doIncludeDebugRoutineNames = true; } else { doIncludeDebugRoutineNames = LoggingParameters.DEFAULT.doIncludeDebugRoutineNames; } if (params.getSelectedDebugOptions() - .contains(SelectedDebugOptionsEnum.DO_INCLUDE_DEBUG_TIMESTAMPS.toString())) { + .contains(DebugOption.DO_INCLUDE_DEBUG_TIMESTAMPS.toString())) { doIncludeDebugTimestamps = true; } else { doIncludeDebugTimestamps = LoggingParameters.DEFAULT.doIncludeDebugTimestamps; diff --git a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/ProjectionRequestValidator.java b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/ProjectionRequestValidator.java index 7a44b0d1c..76f3351ea 100644 --- a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/ProjectionRequestValidator.java +++ b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/ProjectionRequestValidator.java @@ -1,5 +1,6 @@ package ca.bc.gov.nrs.vdyp.backend.projection; +import static ca.bc.gov.nrs.vdyp.backend.model.v1.ValidationMessageKind.*; import static ca.bc.gov.nrs.vdyp.backend.projection.ValidatedParameters.DEFAULT; import java.io.InputStream; @@ -10,17 +11,19 @@ import ca.bc.gov.nrs.vdyp.backend.api.v1.exceptions.ProjectionRequestValidationException; import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.DebugOption; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.ExecutionOption; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.OutputFormat; import ca.bc.gov.nrs.vdyp.backend.model.v1.ProgressFrequency; import ca.bc.gov.nrs.vdyp.backend.model.v1.ProjectionRequestKind; -import ca.bc.gov.nrs.vdyp.backend.model.v1.ValidatedUtilizationParameter; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.OutputFormatEnum; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedDebugOptionsEnum; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedExecutionOptionsEnum; +import ca.bc.gov.nrs.vdyp.backend.model.v1.UtilizationParameter; +import ca.bc.gov.nrs.vdyp.backend.model.v1.ValidationMessage; +import ca.bc.gov.nrs.vdyp.backend.model.v1.ValidationMessageKind; import ca.bc.gov.nrs.vdyp.si32.vdyp.SP0Name; public class ProjectionRequestValidator { - private List validationErrorMessages = new ArrayList<>(); + private List validationErrorMessages = new ArrayList<>(); public static void validate(ProjectionState state, Map streams) throws ProjectionRequestValidationException { @@ -35,17 +38,20 @@ public static void validate(ProjectionState state, Map stre } } - private void validateStreams(Map streams) throws ProjectionRequestValidationException { + void validateStreams(Map streams) throws ProjectionRequestValidationException { } - private void validateState(ProjectionState state) throws ProjectionRequestValidationException { + public List getValidationMessages() { + return validationErrorMessages; + } + + void validateState(ProjectionState state) { validateRequestParametersIndividually(state); validateRequestParametersCollectively(state); } - private void validateRequestParametersIndividually(ProjectionState state) - throws ProjectionRequestValidationException { + private void validateRequestParametersIndividually(ProjectionState state) { Parameters params = state.getParams(); ValidatedParameters vparams = new ValidatedParameters(); @@ -56,10 +62,10 @@ private void validateRequestParametersIndividually(ProjectionState state) vparams.outputFormat(DEFAULT.getOutputFormat()); } else { try { - var outputFormat = OutputFormatEnum.fromValue(params.getOutputFormat()); + var outputFormat = OutputFormat.fromValue(params.getOutputFormat()); vparams.setOutputFormat(outputFormat); } catch (IllegalArgumentException e) { - recordValidationError("{0} is not a recognized output format", params.getOutputFormat()); + recordValidationMessage(UNRECOGNIZED_OUTPUT_FORMAT, params.getOutputFormat()); } } @@ -68,13 +74,13 @@ private void validateRequestParametersIndividually(ProjectionState state) if (params.getSelectedExecutionOptions() == null) { vparams.selectedExecutionOptions(DEFAULT.getSelectedExecutionOptions()); } else { - List selectedOptions = new ArrayList<>(); + List selectedOptions = new ArrayList<>(); for (String optionText : params.getSelectedExecutionOptions()) { try { - var e = Parameters.SelectedExecutionOptionsEnum.fromValue(optionText); + var e = Parameters.ExecutionOption.fromValue(optionText); selectedOptions.add(e); } catch (IllegalArgumentException e) { - recordValidationError("{0} is not a recognized execution option", optionText); + recordValidationMessage(UNRECOGNIZED_EXECUTION_OPTION, optionText); } } vparams.selectedExecutionOptions(selectedOptions); @@ -85,13 +91,13 @@ private void validateRequestParametersIndividually(ProjectionState state) if (params.getSelectedDebugOptions() == null) { vparams.selectedDebugOptions(DEFAULT.getSelectedDebugOptions()); } else { - List selectedOptions = new ArrayList<>(); + List selectedOptions = new ArrayList<>(); for (String optionText : params.getSelectedDebugOptions()) { try { - var e = Parameters.SelectedDebugOptionsEnum.fromValue(optionText); + var e = Parameters.DebugOption.fromValue(optionText); selectedOptions.add(e); } catch (IllegalArgumentException e) { - recordValidationError("{0} is not a recognized debug option", optionText); + recordValidationMessage(UNRECOGNIZED_DEBUG_OPTION, optionText); } } vparams.selectedDebugOptions(selectedOptions); @@ -103,8 +109,8 @@ private void validateRequestParametersIndividually(ProjectionState state) // Parameters.JSON_PROPERTY_AGE_START vparams.setAgeStart( getIntegerValue( - params.getAgeStart(), DEFAULT.getAgeStart(), vparams.getMinAgeStart(), - vparams.getMinAgeEnd(), "ageEnd" + params.getAgeStart(), DEFAULT.getAgeStart(), vparams.getMinAgeStart(), vparams.getMaxAgeStart(), + "ageEnd" ) ); @@ -153,9 +159,7 @@ private void validateRequestParametersIndividually(ProjectionState state) ); // Parameters.JSON_PROPERTY_FORCE_YEAR - vparams.setForceYear( - getIntegerValue(params.getForceYear(), DEFAULT.getForceYear(), null, null, "forceYear") - ); + vparams.setForceYear(getIntegerValue(params.getForceYear(), DEFAULT.getForceYear(), null, null, "forceYear")); // Parameters.JSON_PROPERTY_COMBINE_AGE_YEAR_RANGE if (params.getCombineAgeYearRange() == null) { @@ -163,10 +167,10 @@ private void validateRequestParametersIndividually(ProjectionState state) } else { String rangeValue = params.getCombineAgeYearRange(); try { - var e = Parameters.CombineAgeYearRangeEnum.fromValue(rangeValue); + var e = Parameters.AgeYearRangeCombinationKind.fromValue(rangeValue); vparams.setCombineAgeYearRange(e); } catch (IllegalArgumentException e) { - recordValidationError("{0} is not a recognized CombineAgeYearRangeEnum value", rangeValue); + recordValidationMessage(UNRECOGNIZED_COMBINE_AGE_YEAR_RANGE_OPTION, rangeValue); } } @@ -179,11 +183,7 @@ private void validateRequestParametersIndividually(ProjectionState state) var frequency = new ProgressFrequency(text); vparams.setProgressFrequency(frequency); } catch (IllegalArgumentException e) { - recordValidationError( - "\"{0}\" is not a valid ProgressFrequency value - must be one of" - + " \"never\", \"polygon\", \"mapsheet\", or an integer", - text - ); + recordValidationMessage(INVALID_PROCESS_FREQUENCY_VALUE, text); } } @@ -193,10 +193,10 @@ private void validateRequestParametersIndividually(ProjectionState state) } else { String text = params.getMetadataToOutput(); try { - var e = Parameters.MetadataToOutputEnum.fromValue(text); + var e = Parameters.MetadataToOutputDirective.fromValue(text); vparams.setMetadataToOutput(e); } catch (IllegalArgumentException e) { - recordValidationError("{0} is not a recognized MetadataToOutputEnum value", text); + recordValidationMessage(INVALID_METADATA_TO_OUTPUT_VALUE, text); } } @@ -214,24 +214,22 @@ private void validateRequestParametersIndividually(ProjectionState state) boolean isValidUtilizationParameter = true; if (SP0Name.forText(up.getSpeciesName()).equals(SP0Name.UNKNOWN)) { - recordValidationError( - "Species Group name \"{0}\" is not a known Species Group name", up.getSpeciesName() - ); + recordValidationMessage(UNKNOWN_SPECIES_GROUP_NAME, up.getSpeciesName()); isValidUtilizationParameter = false; } - ValidatedUtilizationParameter.ValueEnum value = null; + UtilizationParameter.UtilizationClass uc = null; try { - ValidatedUtilizationParameter.ValueEnum.fromValue(up.getValue()); + uc = UtilizationParameter.UtilizationClass.fromValue(up.getUtilizationClass()); } catch (IllegalArgumentException e) { - recordValidationError( - "Utilization Class \"{0}\" is not a known Utilization Class name", up.getValue() - ); + recordValidationMessage(UNKNOWN_UTILIZATION_CLASS_NAME, up.getUtilizationClass()); isValidUtilizationParameter = false; } if (isValidUtilizationParameter) { - upList.add(new ValidatedUtilizationParameter().speciesName(up.getSpeciesName()).value(value)); + upList.add( + new ValidatedUtilizationParameter().speciesName(up.getSpeciesName()).utilizationClass(uc) + ); } } } @@ -239,87 +237,92 @@ private void validateRequestParametersIndividually(ProjectionState state) state.setValidatedParams(vparams); } - private void validateRequestParametersCollectively(ProjectionState state) - throws ProjectionRequestValidationException { + private void validateRequestParametersCollectively(ProjectionState state) { if (state.getValidatedParams() == null) { - throw new IllegalStateException(MessageFormat.format("{0}: parameters have not yet been individually validated.", state.getProjectionId())); + throw new IllegalStateException( + MessageFormat.format( + "{0}: parameters have not yet been individually validated.", state.getProjectionId() + ) + ); } - ValidatedParameters vparams = state.getValidatedParams(); - if (!vparams.getOutputFormat().equals(OutputFormatEnum.DCSV) // - && vparams.getAgeStart() == null && vparams.getYearStart() == null // - && vparams.getForceYear() == null // - && !vparams.containsOption( - SelectedExecutionOptionsEnum.DO_FORCE_CURRENT_YEAR_INCLUSION_IN_YIELD_TABLES - ) // - && !vparams.containsOption( - SelectedExecutionOptionsEnum.DO_FORCE_REFERENCE_YEAR_INCLUSION_IN_YIELD_TABLES - )) { - - recordValidationError("At least one of \"ageStart\" or \"yearStart\" must be given"); - } + ValidatedParameters vparams = state.getValidatedParams(); + if (vparams.getOutputFormat() != null) { - if (!vparams.getOutputFormat().equals(OutputFormatEnum.DCSV) // - && vparams.getAgeEnd() == null && vparams.getYearEnd() == null // - && vparams.getForceYear() == null // - && !vparams.containsOption( - SelectedExecutionOptionsEnum.DO_FORCE_CURRENT_YEAR_INCLUSION_IN_YIELD_TABLES - ) // - && !vparams.containsOption( - SelectedExecutionOptionsEnum.DO_FORCE_REFERENCE_YEAR_INCLUSION_IN_YIELD_TABLES - )) { - - recordValidationError("At least one of \"ageEnd\" or \"yearEnd\" must be given"); - } + if (!vparams.getOutputFormat().equals(OutputFormat.DCSV) // + && vparams.getAgeStart() == null // + && vparams.getYearStart() == null // + && vparams.getForceYear() == null // + && !vparams.containsOption(ExecutionOption.DO_FORCE_CURRENT_YEAR_INCLUSION_IN_YIELD_TABLES) // + && !vparams.containsOption(ExecutionOption.DO_FORCE_REFERENCE_YEAR_INCLUSION_IN_YIELD_TABLES)) { - if (state.getKind() == ProjectionRequestKind.DCSV && vparams.getOutputFormat() != OutputFormatEnum.DCSV) { - recordValidationError( - "DCSV output Format can be selected when, and only when, the input format is DCSV .\n" - ); - } + recordValidationMessage(MISSING_START_CRITERIA); + } - if (vparams.getOutputFormat() == OutputFormatEnum.DCSV) { - if (vparams.getAgeStart() != null || vparams.getAgeEnd() != null // - || vparams.getYearStart() != null || vparams.getYearEnd() != null) { + if (!vparams.getOutputFormat().equals(OutputFormat.DCSV) // + && vparams.getAgeEnd() == null // + && vparams.getYearEnd() == null // + && vparams.getForceYear() == null // + && !vparams.containsOption(ExecutionOption.DO_FORCE_CURRENT_YEAR_INCLUSION_IN_YIELD_TABLES) // + && !vparams.containsOption(ExecutionOption.DO_FORCE_REFERENCE_YEAR_INCLUSION_IN_YIELD_TABLES)) { - recordValidationWarning( - "Age range yield table parameters are ignored when DCSV output format is requested" - ); - vparams.ageStart(null).ageEnd(null).yearStart(null).yearEnd(null).ageIncrement(null); + recordValidationMessage(MISSING_END_CRITERIA); } - int forceParamCount = 0; - if (vparams.getForceYear() != null) { - forceParamCount += 1; - } - if (vparams - .containsOption(SelectedExecutionOptionsEnum.DO_FORCE_CURRENT_YEAR_INCLUSION_IN_YIELD_TABLES)) { - forceParamCount += 1; + if (state.getKind() == ProjectionRequestKind.DCSV && vparams.getOutputFormat() != OutputFormat.DCSV + || state.getKind() != ProjectionRequestKind.DCSV + && vparams.getOutputFormat() == OutputFormat.DCSV) { + recordValidationMessage(MISMATCHED_INPUT_OUTPUT_TYPES); } - if (vparams.containsOption( - SelectedExecutionOptionsEnum.DO_FORCE_REFERENCE_YEAR_INCLUSION_IN_YIELD_TABLES - )) { - forceParamCount += 1; + + if (vparams.getOutputFormat() == OutputFormat.DCSV) { + if (vparams.getAgeStart() != null || vparams.getAgeEnd() != null // + || vparams.getYearStart() != null || vparams.getYearEnd() != null) { + + recordValidationMessage(AGE_RANGES_IGNORED_WHEN_DCSV_OUTPUT); + vparams.ageStart(null).ageEnd(null).yearStart(null).yearEnd(null).ageIncrement(null); + } + + int forceParamCount = 0; + if (vparams.getForceYear() != null) { + forceParamCount += 1; + } + if (vparams.containsOption(ExecutionOption.DO_FORCE_CURRENT_YEAR_INCLUSION_IN_YIELD_TABLES)) { + forceParamCount += 1; + } + if (vparams.containsOption(ExecutionOption.DO_FORCE_REFERENCE_YEAR_INCLUSION_IN_YIELD_TABLES)) { + forceParamCount += 1; + } + + if (forceParamCount != 1) { + recordValidationMessage(MUST_BE_EXACTLY_ONE_FORCE_PARAM_WHEN_DCSV_OUTPUT // + , ExecutionOption.DO_FORCE_CURRENT_YEAR_INCLUSION_IN_YIELD_TABLES // + , ExecutionOption.DO_FORCE_REFERENCE_YEAR_INCLUSION_IN_YIELD_TABLES // + , "forceYear" + ); + } } - if (forceParamCount != 1) { - recordValidationError( - "Exactly one of \"{0}\", \"{1}\" and \"{2}\" must be specified with the DCSV Output Format." // - , SelectedExecutionOptionsEnum.DO_FORCE_CURRENT_YEAR_INCLUSION_IN_YIELD_TABLES // - , SelectedExecutionOptionsEnum.DO_FORCE_REFERENCE_YEAR_INCLUSION_IN_YIELD_TABLES // - , "forceYear" - ); + // When selecting CSV Output for CFS Biomass, ensure neither of the MoF Volume + // nor MoF Biomass have also been selected as the CFS Biomass has different + // output columns than for MoF Volume/Biomass. + + if (vparams.getOutputFormat() == OutputFormat.CSV_YIELD_TABLE // + && vparams.containsOption(ExecutionOption.DO_INCLUDE_PROJECTED_CFS_BIOMASS) // + && (vparams.containsOption(ExecutionOption.DO_INCLUDE_PROJECTED_MOF_BIOMASS) + || vparams.containsOption(ExecutionOption.DO_INCLUDE_PROJECTED_MOF_VOLUMES))) { + + recordValidationMessage(CANNOT_SPECIFY_BOTH_CFS_BIOMASS_AND_EITHER_MOF_OPTIONS); } } - if (vparams.containsOption(SelectedExecutionOptionsEnum.DO_INCLUDE_PROJECTED_CFS_BIOMASS) // - && vparams.getOutputFormat() != OutputFormatEnum.CSV_YIELD_TABLE // - && vparams.getOutputFormat() != OutputFormatEnum.YIELD_TABLE) { + if (vparams.containsOption(ExecutionOption.DO_INCLUDE_PROJECTED_CFS_BIOMASS) // + && vparams.getOutputFormat() != OutputFormat.CSV_YIELD_TABLE // + && vparams.getOutputFormat() != OutputFormat.YIELD_TABLE) { - recordValidationError( - "CFS Biomass output is only supported for {0} and {1} output formats", - OutputFormatEnum.CSV_YIELD_TABLE, OutputFormatEnum.YIELD_TABLE + recordValidationMessage( + INVALID_CFS_BIOMASS_OUTPUT_FORMAT, OutputFormat.CSV_YIELD_TABLE, OutputFormat.YIELD_TABLE ); } @@ -329,34 +332,16 @@ private void validateRequestParametersCollectively(ProjectionState state) // on the same projection, then we will be able to select both // MoF and CFS Biomass output selections. - if (vparams.containsOption(SelectedExecutionOptionsEnum.DO_INCLUDE_PROJECTED_CFS_BIOMASS) // - && vparams.containsOption(SelectedExecutionOptionsEnum.DO_INCLUDE_PROJECTED_MOF_BIOMASS)) { - - recordValidationError("MoF and CFS Biomass Output can not be selected at the same time."); - } - - // When selecting CSV Output for CFS Biomass, ensure neither of the MoF Volume - // nor MoF Biomass have also been selected as the CFS Biomass has different - // output columns than for MoF Volume/Biomass. + if (vparams.containsOption(ExecutionOption.DO_INCLUDE_PROJECTED_CFS_BIOMASS) // + && vparams.containsOption(ExecutionOption.DO_INCLUDE_PROJECTED_MOF_BIOMASS)) { - if (vparams.getOutputFormat() == OutputFormatEnum.CSV_YIELD_TABLE // - && vparams.containsOption(SelectedExecutionOptionsEnum.DO_INCLUDE_PROJECTED_CFS_BIOMASS) // - && vparams.containsOption(SelectedExecutionOptionsEnum.DO_INCLUDE_PROJECTED_MOF_BIOMASS)) { - - recordValidationError( - "For CSV Yield Table of CFS Biomass, neither MoF Volume or Biomass may also be selected." - ); + recordValidationMessage(CANNOT_SPECIFY_BOTH_CFS_AND_MOF_BIOMASS_OUTPUT); } } - private void recordValidationError(String message, Object... args) { - String formattedMessage = MessageFormat.format("Error: " + message, args); - validationErrorMessages.add(formattedMessage); - } - - private void recordValidationWarning(String message, Object... args) { - String formattedMessage = MessageFormat.format("Warning: " + message, args); - validationErrorMessages.add(formattedMessage); + private void recordValidationMessage(ValidationMessageKind kind, Object... args) { + ValidationMessage message = new ValidationMessage(kind, args); + validationErrorMessages.add(message); } private Integer @@ -374,17 +359,17 @@ private void recordValidationWarning(String message, Object... args) { } } } catch (NumberFormatException e) { - recordValidationError("Field {1}''s value \"{0}\" is not an integer", text, fieldName); + recordValidationMessage(INVALID_INTEGER_VALUE, text, fieldName); return null; } if (value != null && minValue != null && value < minValue) { - recordValidationError("Field {1}''s value \"{0}\" must be at least {2}", text, fieldName, minValue); + recordValidationMessage(INTEGER_VALUE_TOO_LOW, text, fieldName, minValue); return null; } if (value != null && maxValue != null && value > maxValue) { - recordValidationError("Field {1}''s value \"{0}\" must be no more than {2}", text, fieldName, maxValue); + recordValidationMessage(INTEGER_VALUE_TOO_HIGH, text, fieldName, maxValue); return null; } diff --git a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/ProjectionState.java b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/ProjectionState.java index 2e3bd2092..bc44d8175 100644 --- a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/ProjectionState.java +++ b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/ProjectionState.java @@ -15,7 +15,7 @@ public class ProjectionState { private Parameters params; private ValidatedParameters vparams; - + private final IMessageLog progressLog; private final IMessageLog errorLog; diff --git a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/ValidatedParameters.java b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/ValidatedParameters.java index ecfb044d1..793c27a18 100644 --- a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/ValidatedParameters.java +++ b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/ValidatedParameters.java @@ -12,15 +12,15 @@ package ca.bc.gov.nrs.vdyp.backend.projection; -import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedExecutionOptionsEnum.DO_ALLOW_BASAL_AREA_AND_TREES_PER_HECTARE_VALUE_SUBSTITUTION; -import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_AGE_ROWS_IN_YIELD_TABLE; -import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_COLUMN_HEADERS_IN_YIELD_TABLE; -import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_FILE_HEADER; -import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_PROJECTED_MOF_VOLUMES; -import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_PROJECTION_MODE_IN_YIELD_TABLE; -import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_YEAR_ROWS_IN_YIELD_TABLE; -import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedExecutionOptionsEnum.DO_SUMMARIZE_PROJECTION_BY_LAYER; -import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedExecutionOptionsEnum.FORWARD_GROW_ENABLED; +import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.ExecutionOption.DO_ALLOW_BASAL_AREA_AND_TREES_PER_HECTARE_VALUE_SUBSTITUTION; +import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.ExecutionOption.DO_INCLUDE_AGE_ROWS_IN_YIELD_TABLE; +import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.ExecutionOption.DO_INCLUDE_COLUMN_HEADERS_IN_YIELD_TABLE; +import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.ExecutionOption.DO_INCLUDE_FILE_HEADER; +import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.ExecutionOption.DO_INCLUDE_PROJECTED_MOF_VOLUMES; +import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.ExecutionOption.DO_INCLUDE_PROJECTION_MODE_IN_YIELD_TABLE; +import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.ExecutionOption.DO_INCLUDE_YEAR_ROWS_IN_YIELD_TABLE; +import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.ExecutionOption.DO_SUMMARIZE_PROJECTION_BY_LAYER; +import static ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.ExecutionOption.FORWARD_GROW_ENABLED; import java.util.ArrayList; import java.util.Collections; @@ -29,26 +29,25 @@ import ca.bc.gov.nrs.vdyp.backend.model.v1.Filters; import ca.bc.gov.nrs.vdyp.backend.model.v1.ProgressFrequency; -import ca.bc.gov.nrs.vdyp.backend.model.v1.ValidatedUtilizationParameter; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.CombineAgeYearRangeEnum; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.MetadataToOutputEnum; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.OutputFormatEnum; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedDebugOptionsEnum; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedExecutionOptionsEnum; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.AgeYearRangeCombinationKind; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.MetadataToOutputDirective; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.OutputFormat; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.DebugOption; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.ExecutionOption; import io.quarkus.runtime.annotations.RegisterForReflection; /** - * This class represents a Parameters instance that has been validated. All fields are - * converted to their internal data type (if not String). All defaults have been applied. + * This class represents a Parameters instance that has been validated. All fields are converted to their internal data + * type (if not String). All defaults have been applied. */ @RegisterForReflection public class ValidatedParameters { public static final ValidatedParameters DEFAULT; - private OutputFormatEnum outputFormat; - private List selectedExecutionOptions = new ArrayList<>(); - private List selectedDebugOptions = new ArrayList<>(); + private OutputFormat outputFormat; + private List selectedExecutionOptions = new ArrayList<>(); + private List selectedDebugOptions = new ArrayList<>(); private Integer ageStart; private Integer minAgeStart; private Integer maxAgeStart; @@ -65,9 +64,9 @@ public class ValidatedParameters { private Integer ageIncrement; private Integer minAgeIncrement; private Integer maxAgeIncrement; - private CombineAgeYearRangeEnum combineAgeYearRange; + private AgeYearRangeCombinationKind combineAgeYearRange; private ProgressFrequency progressFrequency; - private MetadataToOutputEnum metadataToOutput; + private MetadataToOutputDirective metadataToOutput; private Filters filters; private List utils = new ArrayList<>(); @@ -77,7 +76,7 @@ public class ValidatedParameters { * @param option the option whose presence is determined * @return as described */ - public boolean containsOption(SelectedExecutionOptionsEnum option) { + public boolean containsOption(ExecutionOption option) { return selectedExecutionOptions.contains(option); } @@ -87,11 +86,11 @@ public boolean containsOption(SelectedExecutionOptionsEnum option) { * @param option the option whose presence is determined * @return as described */ - public boolean containsOption(SelectedDebugOptionsEnum option) { + public boolean containsOption(DebugOption option) { return selectedDebugOptions.contains(option); } - public ValidatedParameters outputFormat(OutputFormatEnum outputFormat) { + public ValidatedParameters outputFormat(OutputFormat outputFormat) { this.outputFormat = outputFormat; return this; } @@ -101,21 +100,21 @@ public ValidatedParameters outputFormat(OutputFormatEnum outputFormat) { * * @return outputFormat */ - public OutputFormatEnum getOutputFormat() { + public OutputFormat getOutputFormat() { return outputFormat; } - public void setOutputFormat(OutputFormatEnum outputFormat) { + public void setOutputFormat(OutputFormat outputFormat) { this.outputFormat = outputFormat; } - public ValidatedParameters selectedExecutionOptions(List selectedExecutionOptions) { + public ValidatedParameters selectedExecutionOptions(List selectedExecutionOptions) { this.selectedExecutionOptions = selectedExecutionOptions; return this; } public ValidatedParameters - addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum selectedExecutionOptionsItem) { + addSelectedExecutionOptionsItem(ExecutionOption selectedExecutionOptionsItem) { if (this.selectedExecutionOptions == null) { this.selectedExecutionOptions = new ArrayList<>(); } @@ -128,20 +127,20 @@ public ValidatedParameters selectedExecutionOptions(List getSelectedExecutionOptions() { + public List getSelectedExecutionOptions() { return Collections.unmodifiableList(selectedExecutionOptions); } - public void setSelectedExecutionOptions(List selectedExecutionOptions) { + public void setSelectedExecutionOptions(List selectedExecutionOptions) { this.selectedExecutionOptions = selectedExecutionOptions; } - public ValidatedParameters selectedDebugOptions(List selectedDebugOptions) { + public ValidatedParameters selectedDebugOptions(List selectedDebugOptions) { this.selectedDebugOptions = selectedDebugOptions; return this; } - public ValidatedParameters addSelectedDebugOptionsItem(SelectedDebugOptionsEnum selectedDebugOptionsItem) { + public ValidatedParameters addSelectedDebugOptionsItem(DebugOption selectedDebugOptionsItem) { if (this.selectedDebugOptions == null) { this.selectedDebugOptions = new ArrayList<>(); } @@ -154,11 +153,11 @@ public ValidatedParameters addSelectedDebugOptionsItem(SelectedDebugOptionsEnum * * @return selectedDebugOptions */ - public List getSelectedDebugOptions() { + public List getSelectedDebugOptions() { return Collections.unmodifiableList(selectedDebugOptions); } - public void setSelectedDebugOptions(List selectedDebugOptions) { + public void setSelectedDebugOptions(List selectedDebugOptions) { this.selectedDebugOptions = selectedDebugOptions; } @@ -410,7 +409,7 @@ public void setMaxAgeIncrement(Integer maxAgeIncrement) { this.maxAgeIncrement = maxAgeIncrement; } - public ValidatedParameters combineAgeYearRange(CombineAgeYearRangeEnum combineAgeYearRange) { + public ValidatedParameters combineAgeYearRange(AgeYearRangeCombinationKind combineAgeYearRange) { this.combineAgeYearRange = combineAgeYearRange; return this; } @@ -420,11 +419,11 @@ public ValidatedParameters combineAgeYearRange(CombineAgeYearRangeEnum combineAg * * @return combineAgeYearRange */ - public CombineAgeYearRangeEnum getCombineAgeYearRange() { + public AgeYearRangeCombinationKind getCombineAgeYearRange() { return combineAgeYearRange; } - public void setCombineAgeYearRange(CombineAgeYearRangeEnum combineAgeYearRange) { + public void setCombineAgeYearRange(AgeYearRangeCombinationKind combineAgeYearRange) { this.combineAgeYearRange = combineAgeYearRange; } @@ -446,7 +445,7 @@ public void setProgressFrequency(ProgressFrequency progressFrequency) { this.progressFrequency = progressFrequency.copy(); } - public ValidatedParameters metadataToOutput(MetadataToOutputEnum metadataToOutput) { + public ValidatedParameters metadataToOutput(MetadataToOutputDirective metadataToOutput) { this.metadataToOutput = metadataToOutput; return this; } @@ -456,11 +455,11 @@ public ValidatedParameters metadataToOutput(MetadataToOutputEnum metadataToOutpu * * @return metadataToOutput */ - public MetadataToOutputEnum getMetadataToOutput() { + public MetadataToOutputDirective getMetadataToOutput() { return metadataToOutput; } - public void setMetadataToOutput(MetadataToOutputEnum metadataToOutput) { + public void setMetadataToOutput(MetadataToOutputDirective metadataToOutput) { this.metadataToOutput = metadataToOutput; } @@ -596,7 +595,7 @@ private String toIndentedString(Object o) { DEFAULT.yearEnd = null; DEFAULT.ageIncrement = null; - DEFAULT.outputFormat = OutputFormatEnum.CSV_YIELD_TABLE; + DEFAULT.outputFormat = OutputFormat.CSV_YIELD_TABLE; DEFAULT.selectedExecutionOptions = new ArrayList<>(); // exclude since false: BACK_GROW_ENABLED @@ -641,9 +640,9 @@ private String toIndentedString(Object o) { DEFAULT.minAgeIncrement = 1; DEFAULT.maxAgeIncrement = 350; DEFAULT.forceYear = null; - DEFAULT.combineAgeYearRange = CombineAgeYearRangeEnum.INTERSECT; + DEFAULT.combineAgeYearRange = AgeYearRangeCombinationKind.INTERSECT; DEFAULT.progressFrequency = new ProgressFrequency().intValue(1000); - DEFAULT.metadataToOutput = MetadataToOutputEnum.VERSION; + DEFAULT.metadataToOutput = MetadataToOutputDirective.VERSION; DEFAULT.filters = new Filters(); DEFAULT.utils = new ArrayList<>(); } diff --git a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ValidatedUtilizationParameter.java b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/ValidatedUtilizationParameter.java similarity index 60% rename from backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ValidatedUtilizationParameter.java rename to backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/ValidatedUtilizationParameter.java index 263847653..946e1aeeb 100644 --- a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ValidatedUtilizationParameter.java +++ b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/projection/ValidatedUtilizationParameter.java @@ -10,69 +10,31 @@ * Do not edit the class manually. */ -package ca.bc.gov.nrs.vdyp.backend.model.v1; +package ca.bc.gov.nrs.vdyp.backend.projection; import java.util.Objects; -import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.annotation.JsonValue; +import ca.bc.gov.nrs.vdyp.backend.model.v1.UtilizationParameter; import io.quarkus.runtime.annotations.RegisterForReflection; /** * This class records a utilization class for a given sp0 (species group) name. */ -@JsonPropertyOrder({ ValidatedUtilizationParameter.JSON_PROPERTY_SPECIES_NAME, ValidatedUtilizationParameter.JSON_PROPERTY_VALUE }) +@JsonPropertyOrder( + { ValidatedUtilizationParameter.JSON_PROPERTY_SPECIES_NAME, ValidatedUtilizationParameter.JSON_PROPERTY_UTILIZATION_CLASS } +) @RegisterForReflection public class ValidatedUtilizationParameter { public static final String JSON_PROPERTY_SPECIES_NAME = "speciesName"; @JsonProperty(JSON_PROPERTY_SPECIES_NAME) private String speciesName; - /** - * Gets or Sets value - */ - public enum ValueEnum { - EXCL("Excl"), - - _4_0("4.0"), - - _7_5("7.5"), - - _12_5("12.5"), - - _17_5("17.5"), - - _22_5("22.5"); - - private String value; - - ValueEnum(String value) { - this.value = value; - } - - @Override - @JsonValue - public String toString() { - return String.valueOf(value); - } - - @JsonCreator - public static ValueEnum fromValue(String value) { - for (ValueEnum b : ValueEnum.values()) { - if (b.value.equals(value)) { - return b; - } - } - throw new IllegalArgumentException("Unexpected value '" + value + "'"); - } - } - - public static final String JSON_PROPERTY_VALUE = "value"; - @JsonProperty(JSON_PROPERTY_VALUE) - private ValueEnum value; + public static final String JSON_PROPERTY_UTILIZATION_CLASS = "utilizationClass"; + @JsonProperty(JSON_PROPERTY_UTILIZATION_CLASS) + private UtilizationParameter.UtilizationClass utilizationClass; public ValidatedUtilizationParameter speciesName(String speciesName) { this.speciesName = speciesName; @@ -94,24 +56,23 @@ public void setSpeciesName(String speciesName) { this.speciesName = speciesName; } - public ValidatedUtilizationParameter value(ValueEnum value) { - this.value = value; - return this; - } - /** - * Get value + * Get utilizationClass * - * @return value + * @return utilizationClass **/ - @JsonProperty(value = "value") + @JsonProperty(value = "utilizationClass") + public UtilizationParameter.UtilizationClass getUtilizationClass() { + return utilizationClass; + } - public ValueEnum getValue() { - return value; + public ValidatedUtilizationParameter utilizationClass(UtilizationParameter.UtilizationClass utilizationClass) { + setUtilizationClass(utilizationClass); + return this; } - public void setValue(ValueEnum value) { - this.value = value; + public void setUtilizationClass(UtilizationParameter.UtilizationClass utilizationClass) { + this.utilizationClass = utilizationClass; } @Override @@ -123,12 +84,12 @@ public boolean equals(Object o) { return false; } ValidatedUtilizationParameter up = (ValidatedUtilizationParameter) o; - return Objects.equals(this.speciesName, up.speciesName) && Objects.equals(this.value, up.value); + return Objects.equals(this.speciesName, up.speciesName) && Objects.equals(this.utilizationClass, up.utilizationClass); } @Override public int hashCode() { - return Objects.hash(speciesName, value); + return Objects.hash(speciesName, utilizationClass); } @Override @@ -137,7 +98,7 @@ public String toString() { sb.append("class "); sb.append(ValidatedUtilizationParameter.class.getSimpleName()); sb.append(" {\n speciesName: ").append(toIndentedString(speciesName)).append("\n"); - sb.append(" value: ").append(toIndentedString(value)).append("\n"); + sb.append(" utilizationClass: ").append(toIndentedString(utilizationClass)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/services/HelpService.java b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/services/HelpService.java index 623f01f59..9ca18810d 100644 --- a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/services/HelpService.java +++ b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/services/HelpService.java @@ -35,7 +35,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Output Data Format", // "YieldTable | CSVYieldTable | DCSV", // "Identifies the output file format. One of (YieldTable default): YieldTable, CSVYieldTable, DCSV", // - ValidatedParameters.DEFAULT.getOutputFormat().name() + ValidatedParameters.DEFAULT.getOutputFormat().getValue() ) ); @@ -48,7 +48,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Enables or disables the use of the Back Grow feature of VDYP7.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions() - .contains(Parameters.SelectedExecutionOptionsEnum.BACK_GROW_ENABLED) + .contains(Parameters.ExecutionOption.BACK_GROW_ENABLED) ) ) ); @@ -62,7 +62,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Enables or disables the use of the Forward Grow feature of VDYP7.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions() - .contains(Parameters.SelectedExecutionOptionsEnum.FORWARD_GROW_ENABLED) + .contains(Parameters.ExecutionOption.FORWARD_GROW_ENABLED) ) ) ); @@ -76,7 +76,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Includes or suppresses Debug Log File Timestamps.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedDebugOptions() - .contains(Parameters.SelectedDebugOptionsEnum.DO_INCLUDE_DEBUG_TIMESTAMPS) + .contains(Parameters.DebugOption.DO_INCLUDE_DEBUG_TIMESTAMPS) ) ) ); @@ -90,7 +90,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Includes or suppresses Debug Log File Routine Names.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedDebugOptions() - .contains(Parameters.SelectedDebugOptionsEnum.DO_INCLUDE_DEBUG_ROUTINE_NAMES) + .contains(Parameters.DebugOption.DO_INCLUDE_DEBUG_ROUTINE_NAMES) ) ) ); @@ -104,7 +104,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Includes or suppresses Debug Log Block Entry and Exit.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedDebugOptions() - .contains(Parameters.SelectedDebugOptionsEnum.DO_INCLUDE_DEBUG_ENTRY_EXIT) + .contains(Parameters.DebugOption.DO_INCLUDE_DEBUG_ENTRY_EXIT) ) ) ); @@ -118,7 +118,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Indents Logging Blocks as they are Entered and Exited.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedDebugOptions() - .contains(Parameters.SelectedDebugOptionsEnum.DO_INCLUDE_DEBUG_INDENT_BLOCKS) + .contains(Parameters.DebugOption.DO_INCLUDE_DEBUG_INDENT_BLOCKS) ) ) ); @@ -199,7 +199,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Enables or disables the forced inclusion of the Reference Year in Yield Tables.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions().contains( - Parameters.SelectedExecutionOptionsEnum.DO_FORCE_REFERENCE_YEAR_INCLUSION_IN_YIELD_TABLES + Parameters.ExecutionOption.DO_FORCE_REFERENCE_YEAR_INCLUSION_IN_YIELD_TABLES ) ) ) @@ -214,7 +214,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Enables or disables the forced inclusion of the Current Year in Yield Tables.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions().contains( - Parameters.SelectedExecutionOptionsEnum.DO_FORCE_CURRENT_YEAR_INCLUSION_IN_YIELD_TABLES + Parameters.ExecutionOption.DO_FORCE_CURRENT_YEAR_INCLUSION_IN_YIELD_TABLES ) ) ) @@ -240,7 +240,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "In file formats where a file header is optional, this option will display or suppress the file header.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions() - .contains(Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_FILE_HEADER) + .contains(Parameters.ExecutionOption.DO_INCLUDE_FILE_HEADER) ) ) ); @@ -252,7 +252,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Metadata to Include (default: VERSION )", // "ALL | MAIN | VERSION | MIN_IDENT | NONE", // "Controls how much metadata is displayed in the Output and Error Logs.", // - ValidatedParameters.DEFAULT.getMetadataToOutput().name() + ValidatedParameters.DEFAULT.getMetadataToOutput().getValue() ) ); @@ -265,7 +265,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "If present, a column indicating how the yield table row was projected is included in Yield Tables.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions().contains( - Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_PROJECTION_MODE_IN_YIELD_TABLE + Parameters.ExecutionOption.DO_INCLUDE_PROJECTION_MODE_IN_YIELD_TABLE ) ) ) @@ -280,7 +280,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Includes or excludes age rows of the Age Range in the Yield Table.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions().contains( - Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_AGE_ROWS_IN_YIELD_TABLE + Parameters.ExecutionOption.DO_INCLUDE_AGE_ROWS_IN_YIELD_TABLE ) ) ) @@ -295,7 +295,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "If true, the year rows of the Year Range are included in the Yield Table.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions().contains( - Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_YEAR_ROWS_IN_YIELD_TABLE + Parameters.ExecutionOption.DO_INCLUDE_YEAR_ROWS_IN_YIELD_TABLE ) ) ) @@ -369,7 +369,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Include the POLYGON_RCRD_ID in the header of yield tables.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions().contains( - Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_POLYGON_RECORD_ID_IN_YIELD_TABLE + Parameters.ExecutionOption.DO_INCLUDE_POLYGON_RECORD_ID_IN_YIELD_TABLE ) ) ) @@ -384,7 +384,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "If present, the substitution of Supplied BA/TPH as Projected Values is allowed.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions().contains( - Parameters.SelectedExecutionOptionsEnum.DO_ALLOW_BASAL_AREA_AND_TREES_PER_HECTARE_VALUE_SUBSTITUTION + Parameters.ExecutionOption.DO_ALLOW_BASAL_AREA_AND_TREES_PER_HECTARE_VALUE_SUBSTITUTION ) ) ) @@ -399,7 +399,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Display/Suppress the Secondary Species Dominant Height column in Yield Tables.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions().contains( - Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_SECONDARY_SPECIES_DOMINANT_HEIGHT_IN_YIELD_TABLE + Parameters.ExecutionOption.DO_INCLUDE_SECONDARY_SPECIES_DOMINANT_HEIGHT_IN_YIELD_TABLE ) ) ) @@ -414,7 +414,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "If present, projected values are summarized at the polygon level.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions().contains( - Parameters.SelectedExecutionOptionsEnum.DO_SUMMARIZE_PROJECTION_BY_POLYGON + Parameters.ExecutionOption.DO_SUMMARIZE_PROJECTION_BY_POLYGON ) ) ) @@ -429,7 +429,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "If present, projected values are summarized at the layer level.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions().contains( - Parameters.SelectedExecutionOptionsEnum.DO_SUMMARIZE_PROJECTION_BY_LAYER + Parameters.ExecutionOption.DO_SUMMARIZE_PROJECTION_BY_LAYER ) ) ) @@ -444,7 +444,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "If present, projected values are produced for each species.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions() - .contains(Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_SPECIES_PROJECTION) + .contains(Parameters.ExecutionOption.DO_INCLUDE_SPECIES_PROJECTION) ) ) ); @@ -458,7 +458,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Indicate whether MoF projected volumes are included in the output.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions().contains( - Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_PROJECTED_MOF_VOLUMES + Parameters.ExecutionOption.DO_INCLUDE_PROJECTED_MOF_VOLUMES ) ) ) @@ -473,7 +473,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Indicate whether projected MoF biomass is included in the output.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions().contains( - Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_PROJECTED_MOF_BIOMASS + Parameters.ExecutionOption.DO_INCLUDE_PROJECTED_MOF_BIOMASS ) ) ) @@ -488,7 +488,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Indicate whether projected CFS biomass is included in the output.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions().contains( - Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_PROJECTED_CFS_BIOMASS + Parameters.ExecutionOption.DO_INCLUDE_PROJECTED_CFS_BIOMASS ) ) ) @@ -503,7 +503,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Indicate whether formatted yield tables will include column headers or not.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions().contains( - Parameters.SelectedExecutionOptionsEnum.DO_INCLUDE_COLUMN_HEADERS_IN_YIELD_TABLE + Parameters.ExecutionOption.DO_INCLUDE_COLUMN_HEADERS_IN_YIELD_TABLE ) ) ) @@ -519,7 +519,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Enables or disables the logging of progress messages during projections.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions() - .contains(Parameters.SelectedExecutionOptionsEnum.DO_ENABLE_DEBUG_LOGGING) + .contains(Parameters.ExecutionOption.DO_ENABLE_DEBUG_LOGGING) ) ) ); @@ -532,7 +532,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Enables or disables the logging of error messages during projections.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions() - .contains(Parameters.SelectedExecutionOptionsEnum.DO_ENABLE_ERROR_LOGGING) + .contains(Parameters.ExecutionOption.DO_ENABLE_ERROR_LOGGING) ) ) ); @@ -545,7 +545,7 @@ public HelpResource helpGet(UriInfo uriInfo, SecurityContext securityContext) th "Enables or disables the logging of debug messages during projections.", // Boolean.toString( ValidatedParameters.DEFAULT.getSelectedExecutionOptions() - .contains(Parameters.SelectedExecutionOptionsEnum.DO_ENABLE_PROGRESS_LOGGING) + .contains(Parameters.ExecutionOption.DO_ENABLE_PROGRESS_LOGGING) ) ) ); diff --git a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/services/ProjectionService.java b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/services/ProjectionService.java index 9f92b7ce5..0702ea88e 100644 --- a/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/services/ProjectionService.java +++ b/backend/src/main/java/ca/bc/gov/nrs/vdyp/backend/services/ProjectionService.java @@ -118,7 +118,7 @@ private Response runProjection( logger.info("(); - for (var e : executionOptions) { - options.add(e.toString()); - } - params.setSelectedExecutionOptions(options); + params.setSelectedExecutionOptions(List.of(executionOptions)); return params; } diff --git a/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/api/v1/exceptions/ExceptionsTest.java b/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/api/v1/exceptions/ExceptionsTest.java index c9d5c56df..f81a33ae0 100644 --- a/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/api/v1/exceptions/ExceptionsTest.java +++ b/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/api/v1/exceptions/ExceptionsTest.java @@ -3,10 +3,6 @@ import org.junit.Assert; import org.junit.jupiter.api.Test; -import ca.bc.gov.nrs.vdyp.backend.api.v1.exceptions.Exceptions; -import ca.bc.gov.nrs.vdyp.backend.api.v1.exceptions.NotFoundException; -import ca.bc.gov.nrs.vdyp.backend.api.v1.exceptions.ProjectionExecutionException; - public class ExceptionsTest { @Test diff --git a/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/DcsvProjectionEndpointTest.java b/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/DcsvProjectionEndpointTest.java index 793ef0677..89d566edd 100644 --- a/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/DcsvProjectionEndpointTest.java +++ b/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/DcsvProjectionEndpointTest.java @@ -8,7 +8,6 @@ import org.junit.jupiter.api.Test; import ca.bc.gov.nrs.api.helpers.TestHelper; -import ca.bc.gov.nrs.vdyp.backend.endpoints.v1.ParameterNames; import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters; import io.quarkus.test.junit.QuarkusTest; import io.smallrye.common.constraint.Assert; diff --git a/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/HcsvProjectionEndpointTest.java b/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/HcsvProjectionEndpointTest.java index 444f5df84..8de98050a 100644 --- a/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/HcsvProjectionEndpointTest.java +++ b/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/HcsvProjectionEndpointTest.java @@ -18,7 +18,6 @@ import org.junit.jupiter.api.Test; import ca.bc.gov.nrs.api.helpers.TestHelper; -import ca.bc.gov.nrs.vdyp.backend.endpoints.v1.ParameterNames; import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters; import io.quarkus.test.junit.QuarkusTest; import jakarta.inject.Inject; @@ -45,11 +44,11 @@ void testProjectionHscv_shouldReturnStatusOK() throws IOException { Parameters parameters = testHelper.addSelectedOptions( new Parameters(), // - Parameters.SelectedExecutionOptionsEnum.DO_ENABLE_DEBUG_LOGGING, - Parameters.SelectedExecutionOptionsEnum.DO_ENABLE_PROGRESS_LOGGING, - Parameters.SelectedExecutionOptionsEnum.DO_ENABLE_ERROR_LOGGING + Parameters.ExecutionOption.DO_ENABLE_DEBUG_LOGGING, + Parameters.ExecutionOption.DO_ENABLE_PROGRESS_LOGGING, + Parameters.ExecutionOption.DO_ENABLE_ERROR_LOGGING ); - parameters.ageStart("100").ageEnd("400"); + parameters.ageStart(100).ageEnd(400); // Included to generate JSON text of parameters as needed // ObjectMapper mapper = new ObjectMapper(); @@ -97,7 +96,7 @@ void testProjectionHscv_testNoProgressLogging() throws IOException { Path resourceFolderPath = Path.of("VDYP7Console-sample-files", "hcsv", "vdyp-240"); Parameters parameters = new Parameters(); - parameters.ageStart("100").ageEnd("400"); + parameters.ageStart(100).ageEnd(400); InputStream zipInputStream = given().basePath(TestHelper.ROOT_PATH).when() // .multiPart(ParameterNames.PROJECTION_PARAMETERS, parameters, MediaType.APPLICATION_JSON) // diff --git a/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/ParameterNamesTest.java b/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/ParameterNamesTest.java index b25d3d443..8ad5cfc4c 100644 --- a/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/ParameterNamesTest.java +++ b/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/ParameterNamesTest.java @@ -3,8 +3,6 @@ import org.junit.Assert; import org.junit.jupiter.api.Test; -import ca.bc.gov.nrs.vdyp.backend.endpoints.v1.ParameterNames; - /** test ParameterNamesTest for Sonar coverage purposes only */ public class ParameterNamesTest { diff --git a/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/ScsvProjectionEndpointTest.java b/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/ScsvProjectionEndpointTest.java index 25dc6d9e3..191265094 100644 --- a/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/ScsvProjectionEndpointTest.java +++ b/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/endpoints/v1/ScsvProjectionEndpointTest.java @@ -8,7 +8,6 @@ import org.junit.jupiter.api.Test; import ca.bc.gov.nrs.api.helpers.TestHelper; -import ca.bc.gov.nrs.vdyp.backend.endpoints.v1.ParameterNames; import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters; import io.quarkus.test.junit.QuarkusTest; import jakarta.inject.Inject; diff --git a/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ParametersTest.java b/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ParametersTest.java index ffcec1d95..547cea9bf 100644 --- a/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ParametersTest.java +++ b/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/model/v1/ParametersTest.java @@ -9,17 +9,14 @@ import com.fasterxml.jackson.databind.ObjectMapper; import ca.bc.gov.nrs.vdyp.backend.endpoints.v1.impl.ParametersProvider; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Filters; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters; -import ca.bc.gov.nrs.vdyp.backend.model.v1.ProgressFrequency; -import ca.bc.gov.nrs.vdyp.backend.model.v1.ValidatedUtilizationParameter; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.CombineAgeYearRangeEnum; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.MetadataToOutputEnum; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.OutputFormatEnum; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedDebugOptionsEnum; -import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.SelectedExecutionOptionsEnum; -import ca.bc.gov.nrs.vdyp.backend.model.v1.ProgressFrequency.EnumValue; -import ca.bc.gov.nrs.vdyp.backend.model.v1.ValidatedUtilizationParameter.ValueEnum; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.AgeYearRangeCombinationKind; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.DebugOption; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.ExecutionOption; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.MetadataToOutputDirective; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.OutputFormat; +import ca.bc.gov.nrs.vdyp.backend.model.v1.ProgressFrequency.FrequencyKind; +import ca.bc.gov.nrs.vdyp.backend.model.v1.UtilizationParameter.UtilizationClass; +import ca.bc.gov.nrs.vdyp.backend.projection.ValidatedUtilizationParameter; import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.MediaType; @@ -29,68 +26,68 @@ public class ParametersTest { public void testParametersProvider() throws WebApplicationException, IOException { Parameters op = new Parameters(); - op.addSelectedDebugOptionsItem(SelectedDebugOptionsEnum.DO_INCLUDE_DEBUG_ENTRY_EXIT); - op.addSelectedDebugOptionsItem(SelectedDebugOptionsEnum.DO_INCLUDE_DEBUG_INDENT_BLOCKS); - op.addSelectedDebugOptionsItem(SelectedDebugOptionsEnum.DO_INCLUDE_DEBUG_ROUTINE_NAMES); - op.addSelectedDebugOptionsItem(SelectedDebugOptionsEnum.DO_INCLUDE_DEBUG_TIMESTAMPS); + op.addSelectedDebugOptionsItem(DebugOption.DO_INCLUDE_DEBUG_ENTRY_EXIT); + op.addSelectedDebugOptionsItem(DebugOption.DO_INCLUDE_DEBUG_INDENT_BLOCKS); + op.addSelectedDebugOptionsItem(DebugOption.DO_INCLUDE_DEBUG_ROUTINE_NAMES); + op.addSelectedDebugOptionsItem(DebugOption.DO_INCLUDE_DEBUG_TIMESTAMPS); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.BACK_GROW_ENABLED); + op.addSelectedExecutionOptionsItem(ExecutionOption.BACK_GROW_ENABLED); op.addSelectedExecutionOptionsItem( - SelectedExecutionOptionsEnum.DO_ALLOW_BASAL_AREA_AND_TREES_PER_HECTARE_VALUE_SUBSTITUTION + ExecutionOption.DO_ALLOW_BASAL_AREA_AND_TREES_PER_HECTARE_VALUE_SUBSTITUTION ); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.DO_ENABLE_DEBUG_LOGGING); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.DO_ENABLE_ERROR_LOGGING); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.DO_ENABLE_PROGRESS_LOGGING); + op.addSelectedExecutionOptionsItem(ExecutionOption.DO_ENABLE_DEBUG_LOGGING); + op.addSelectedExecutionOptionsItem(ExecutionOption.DO_ENABLE_ERROR_LOGGING); + op.addSelectedExecutionOptionsItem(ExecutionOption.DO_ENABLE_PROGRESS_LOGGING); op.addSelectedExecutionOptionsItem( - SelectedExecutionOptionsEnum.DO_FORCE_CALENDAR_YEAR_INCLUSION_IN_YIELD_TABLES + ExecutionOption.DO_FORCE_CALENDAR_YEAR_INCLUSION_IN_YIELD_TABLES ); op.addSelectedExecutionOptionsItem( - SelectedExecutionOptionsEnum.DO_FORCE_CURRENT_YEAR_INCLUSION_IN_YIELD_TABLES + ExecutionOption.DO_FORCE_CURRENT_YEAR_INCLUSION_IN_YIELD_TABLES ); op.addSelectedExecutionOptionsItem( - SelectedExecutionOptionsEnum.DO_FORCE_REFERENCE_YEAR_INCLUSION_IN_YIELD_TABLES + ExecutionOption.DO_FORCE_REFERENCE_YEAR_INCLUSION_IN_YIELD_TABLES ); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.DO_INCLUDE_AGE_ROWS_IN_YIELD_TABLE); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.DO_INCLUDE_COLUMN_HEADERS_IN_YIELD_TABLE); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.DO_INCLUDE_FILE_HEADER); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.DO_INCLUDE_POLYGON_RECORD_ID_IN_YIELD_TABLE); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.DO_INCLUDE_PROJECTED_CFS_BIOMASS); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.DO_INCLUDE_PROJECTED_MOF_BIOMASS); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.DO_INCLUDE_PROJECTED_MOF_VOLUMES); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.DO_INCLUDE_PROJECTION_MODE_IN_YIELD_TABLE); + op.addSelectedExecutionOptionsItem(ExecutionOption.DO_INCLUDE_AGE_ROWS_IN_YIELD_TABLE); + op.addSelectedExecutionOptionsItem(ExecutionOption.DO_INCLUDE_COLUMN_HEADERS_IN_YIELD_TABLE); + op.addSelectedExecutionOptionsItem(ExecutionOption.DO_INCLUDE_FILE_HEADER); + op.addSelectedExecutionOptionsItem(ExecutionOption.DO_INCLUDE_POLYGON_RECORD_ID_IN_YIELD_TABLE); + op.addSelectedExecutionOptionsItem(ExecutionOption.DO_INCLUDE_PROJECTED_CFS_BIOMASS); + op.addSelectedExecutionOptionsItem(ExecutionOption.DO_INCLUDE_PROJECTED_MOF_BIOMASS); + op.addSelectedExecutionOptionsItem(ExecutionOption.DO_INCLUDE_PROJECTED_MOF_VOLUMES); + op.addSelectedExecutionOptionsItem(ExecutionOption.DO_INCLUDE_PROJECTION_MODE_IN_YIELD_TABLE); op.addSelectedExecutionOptionsItem( - SelectedExecutionOptionsEnum.DO_INCLUDE_SECONDARY_SPECIES_DOMINANT_HEIGHT_IN_YIELD_TABLE + ExecutionOption.DO_INCLUDE_SECONDARY_SPECIES_DOMINANT_HEIGHT_IN_YIELD_TABLE ); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.DO_INCLUDE_SPECIES_PROJECTION); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.DO_INCLUDE_YEAR_ROWS_IN_YIELD_TABLE); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.DO_SAVE_INTERMEDIATE_FILES); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.DO_SUMMARIZE_PROJECTION_BY_LAYER); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.DO_SUMMARIZE_PROJECTION_BY_POLYGON); - op.addSelectedExecutionOptionsItem(SelectedExecutionOptionsEnum.FORWARD_GROW_ENABLED); - - op.addUtilsItem(new ValidatedUtilizationParameter().speciesName("AL").value(ValueEnum._12_5)); - op.addUtilsItem(new ValidatedUtilizationParameter().speciesName("C").value(ValueEnum._17_5)); - op.addUtilsItem(new ValidatedUtilizationParameter().speciesName("D").value(ValueEnum._22_5)); - op.addUtilsItem(new ValidatedUtilizationParameter().speciesName("E").value(ValueEnum._4_0)); - op.addUtilsItem(new ValidatedUtilizationParameter().speciesName("F").value(ValueEnum._7_5)); - op.addUtilsItem(new ValidatedUtilizationParameter().speciesName("H").value(ValueEnum.EXCL)); - - op.ageEnd("2030") // - .ageIncrement("1") // - .ageStart("2020") // - .combineAgeYearRange(CombineAgeYearRangeEnum.DIFFERENCE.name()) // - .forceYear("2020"); + op.addSelectedExecutionOptionsItem(ExecutionOption.DO_INCLUDE_SPECIES_PROJECTION); + op.addSelectedExecutionOptionsItem(ExecutionOption.DO_INCLUDE_YEAR_ROWS_IN_YIELD_TABLE); + op.addSelectedExecutionOptionsItem(ExecutionOption.DO_SAVE_INTERMEDIATE_FILES); + op.addSelectedExecutionOptionsItem(ExecutionOption.DO_SUMMARIZE_PROJECTION_BY_LAYER); + op.addSelectedExecutionOptionsItem(ExecutionOption.DO_SUMMARIZE_PROJECTION_BY_POLYGON); + op.addSelectedExecutionOptionsItem(ExecutionOption.FORWARD_GROW_ENABLED); + + op.addUtilsItem(new ValidatedUtilizationParameter().speciesName("AL").utilizationClass(UtilizationClass._12_5)); + op.addUtilsItem(new ValidatedUtilizationParameter().speciesName("C").utilizationClass(UtilizationClass._17_5)); + op.addUtilsItem(new ValidatedUtilizationParameter().speciesName("D").utilizationClass(UtilizationClass._22_5)); + op.addUtilsItem(new ValidatedUtilizationParameter().speciesName("E").utilizationClass(UtilizationClass._4_0)); + op.addUtilsItem(new ValidatedUtilizationParameter().speciesName("F").utilizationClass(UtilizationClass._7_5)); + op.addUtilsItem(new ValidatedUtilizationParameter().speciesName("H").utilizationClass(UtilizationClass.EXCL)); + + op.ageEnd(2030) // + .ageIncrement(1) // + .ageStart(2020) // + .combineAgeYearRange(AgeYearRangeCombinationKind.DIFFERENCE) // + .forceYear(2020); var filters = new Filters().maintainer("maintainer").mapsheet("mapsheet").polygon("polygon") .polygonId("polygonId"); op.filters(filters); - op.progressFrequency(ProgressFrequency.EnumValue.MAPSHEET.name()); + op.progressFrequency(ProgressFrequency.FrequencyKind.MAPSHEET); - op.metadataToOutput(MetadataToOutputEnum.ALL.name()) // - .outputFormat(OutputFormatEnum.CSV_YIELD_TABLE.name()) // - .yearEnd("2030") // - .yearStart("2020"); + op.metadataToOutput(MetadataToOutputDirective.ALL) // + .outputFormat(OutputFormat.CSV_YIELD_TABLE) // + .yearEnd(2030) // + .yearStart(2020); var objectMapper = new ObjectMapper(); byte[] json = objectMapper.writeValueAsBytes(op); @@ -111,7 +108,7 @@ public void testParametersProvider() throws WebApplicationException, IOException Assert.assertFalse(provider.isReadable(Object.class, null, null, MediaType.APPLICATION_JSON_TYPE)); Assert.assertFalse(provider.isReadable(Parameters.class, null, null, MediaType.APPLICATION_OCTET_STREAM_TYPE)); - np.setProgressFrequency(EnumValue.POLYGON.name()); + np.setProgressFrequency(FrequencyKind.POLYGON.getValue()); Assert.assertFalse(op.equals(np)); } @@ -123,19 +120,19 @@ void testProgressFrequency() { Assert.assertNull(new ProgressFrequency().getEnumValue()); Assert.assertEquals(Integer.valueOf(12), new ProgressFrequency(12).getIntValue()); Assert.assertNull(new ProgressFrequency(12).getEnumValue()); - Assert.assertNull(new ProgressFrequency(ProgressFrequency.EnumValue.MAPSHEET).getIntValue()); + Assert.assertNull(new ProgressFrequency(ProgressFrequency.FrequencyKind.MAPSHEET).getIntValue()); Assert.assertEquals( - ProgressFrequency.EnumValue.MAPSHEET, - new ProgressFrequency(ProgressFrequency.EnumValue.MAPSHEET).getEnumValue() + ProgressFrequency.FrequencyKind.MAPSHEET, + new ProgressFrequency(ProgressFrequency.FrequencyKind.MAPSHEET).getEnumValue() ); - Assert.assertThrows(IllegalArgumentException.class, () -> ProgressFrequency.EnumValue.fromValue("not a value")); + Assert.assertThrows(IllegalArgumentException.class, () -> ProgressFrequency.FrequencyKind.fromValue("not a value")); ProgressFrequency pf1 = new ProgressFrequency(12); - ProgressFrequency pf2 = new ProgressFrequency(ProgressFrequency.EnumValue.MAPSHEET); + ProgressFrequency pf2 = new ProgressFrequency(ProgressFrequency.FrequencyKind.MAPSHEET); Assert.assertTrue(pf1.equals(pf1)); Assert.assertEquals(Integer.valueOf(12).hashCode(), pf1.hashCode()); - Assert.assertEquals(ProgressFrequency.EnumValue.MAPSHEET.hashCode(), pf2.hashCode()); + Assert.assertEquals(ProgressFrequency.FrequencyKind.MAPSHEET.hashCode(), pf2.hashCode()); Assert.assertEquals(17, new ProgressFrequency().hashCode()); Assert.assertTrue(pf1.toString().indexOf("12") != -1); @@ -146,18 +143,19 @@ void testProgressFrequency() { @Test void testUtilizationParameter() { Assert.assertEquals( - "AL", new ValidatedUtilizationParameter().speciesName("AL").value(ValueEnum._12_5).getSpeciesName() + "AL", new ValidatedUtilizationParameter().speciesName("AL").utilizationClass(UtilizationClass._12_5).getSpeciesName() ); Assert.assertEquals( - ValueEnum._17_5, - new ValidatedUtilizationParameter().speciesName("AL").value(ValueEnum._17_5).getValue() + UtilizationClass._17_5, new ValidatedUtilizationParameter().speciesName("AL").utilizationClass(UtilizationClass._17_5).getUtilizationClass() ); - Assert.assertThrows(IllegalArgumentException.class, () -> ValidatedUtilizationParameter.ValueEnum.fromValue("ZZZ")); + Assert.assertThrows( + IllegalArgumentException.class, () -> UtilizationClass.fromValue("ZZZ") + ); - var up1 = new ValidatedUtilizationParameter().speciesName("AL").value(ValueEnum._12_5); - var up2 = new ValidatedUtilizationParameter().speciesName("C").value(ValueEnum._12_5); - var up3 = new ValidatedUtilizationParameter().speciesName("C").value(ValueEnum._22_5); + var up1 = new ValidatedUtilizationParameter().speciesName("AL").utilizationClass(UtilizationClass._12_5); + var up2 = new ValidatedUtilizationParameter().speciesName("C").utilizationClass(UtilizationClass._12_5); + var up3 = new ValidatedUtilizationParameter().speciesName("C").utilizationClass(UtilizationClass._22_5); Assert.assertTrue(up1.equals(up1)); Assert.assertTrue(up1.hashCode() == up1.hashCode()); diff --git a/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/projection/ParameterValidationTest.java b/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/projection/ParameterValidationTest.java index a5059f4f7..8d4fb0ba6 100644 --- a/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/projection/ParameterValidationTest.java +++ b/backend/src/test/java/ca/bc/gov/nrs/vdyp/backend/projection/ParameterValidationTest.java @@ -1,19 +1,534 @@ package ca.bc.gov.nrs.vdyp.backend.projection; +import static ca.bc.gov.nrs.vdyp.backend.model.v1.ValidationMessageKind.*; + import java.io.IOException; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.junit.Assert; import org.junit.jupiter.api.Test; import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters; -import ca.bc.gov.nrs.vdyp.backend.projection.ProjectionRequestValidator; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.DebugOption; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.ExecutionOption; +import ca.bc.gov.nrs.vdyp.backend.model.v1.Parameters.OutputFormat; +import ca.bc.gov.nrs.vdyp.backend.model.v1.ProgressFrequency; +import ca.bc.gov.nrs.vdyp.backend.model.v1.ProjectionRequestKind; +import ca.bc.gov.nrs.vdyp.backend.model.v1.UtilizationParameter; +import ca.bc.gov.nrs.vdyp.backend.model.v1.UtilizationParameter.UtilizationClass; +import ca.bc.gov.nrs.vdyp.backend.model.v1.ValidationMessage; +import ca.bc.gov.nrs.vdyp.backend.model.v1.ValidationMessageKind; import jakarta.ws.rs.WebApplicationException; public class ParameterValidationTest { @Test - public void testParametersProvider() throws WebApplicationException, IOException { - Parameters op = new Parameters(); - - ProjectionRequestValidator r; + public void testNoParametersSupplied() throws WebApplicationException, IOException { + + Parameters p1 = new Parameters(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), MISSING_START_CRITERIA, MISSING_END_CRITERIA); + } + + @Test + public void testOnlyAgeStartParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = new Parameters().ageStart(1); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), MISSING_END_CRITERIA); + } + + @Test + public void testAgeStartTooLowParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = new Parameters().ageEnd(400).ageStart(ValidatedParameters.DEFAULT.getMinAgeStart() - 1); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), MISSING_START_CRITERIA, INTEGER_VALUE_TOO_LOW); + } + + @Test + public void testAgeStartTooHighParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = new Parameters().ageEnd(400).ageStart(ValidatedParameters.DEFAULT.getMaxAgeStart() + 1); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), MISSING_START_CRITERIA, INTEGER_VALUE_TOO_HIGH); + } + + @Test + public void testOnlyYearStartParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = new Parameters().yearStart(ValidatedParameters.DEFAULT.getMinYearStart()); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), MISSING_END_CRITERIA); + } + + @Test + public void testYearStartTooLowParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = new Parameters().ageEnd(400).yearStart(ValidatedParameters.DEFAULT.getMinYearStart() - 1); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), MISSING_START_CRITERIA, INTEGER_VALUE_TOO_LOW); + } + + @Test + public void testYearStartTooHighParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = new Parameters().ageEnd(400).yearStart(ValidatedParameters.DEFAULT.getMaxYearStart() + 1); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), MISSING_START_CRITERIA, INTEGER_VALUE_TOO_HIGH); + } + + @Test + public void testOnlyAgeEndParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = new Parameters().ageEnd(400); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), MISSING_START_CRITERIA); + } + + @Test + public void testAgeEndTooLowParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = new Parameters().ageStart(1).ageEnd(ValidatedParameters.DEFAULT.getMinAgeEnd() - 1); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), MISSING_END_CRITERIA, INTEGER_VALUE_TOO_LOW); + } + + @Test + public void testAgeEndTooHighParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = new Parameters().ageStart(1).ageEnd(ValidatedParameters.DEFAULT.getMaxAgeEnd() + 1); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), MISSING_END_CRITERIA, INTEGER_VALUE_TOO_HIGH); + } + + @Test + public void testOnlyYearEndParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = new Parameters().yearEnd(1500); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), MISSING_START_CRITERIA); + } + + @Test + public void testYearEndTooLowParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = new Parameters().yearStart(1500).yearEnd(ValidatedParameters.DEFAULT.getMinYearEnd() - 1); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), MISSING_END_CRITERIA, INTEGER_VALUE_TOO_LOW); + } + + @Test + public void testYearEndTooHighParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = new Parameters().yearStart(1500).yearEnd(ValidatedParameters.DEFAULT.getMaxYearEnd() + 1); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), MISSING_END_CRITERIA, INTEGER_VALUE_TOO_HIGH); + } + + @Test + public void testAgeIncrementTooLowParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject().ageIncrement(ValidatedParameters.DEFAULT.getMinAgeIncrement() - 1); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), INTEGER_VALUE_TOO_LOW); + } + + @Test + public void testAgeIncrementTooHighParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject().ageIncrement(ValidatedParameters.DEFAULT.getMaxAgeIncrement() + 1); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), INTEGER_VALUE_TOO_HIGH); + } + + @Test + public void testValidAgeIncrementSupplied() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject().ageIncrement(ValidatedParameters.DEFAULT.getMaxAgeIncrement()); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages()); + } + + @Test + public void testValidAgeStartAndEndParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages()); + } + + @Test + public void testValidYearStartAndEndParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = new Parameters().yearStart(1600).yearEnd(2100); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages()); + } + + @Test + public void testInvalidOutputFormatOptionSupplied() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + p1.setOutputFormat("bad output format"); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), UNRECOGNIZED_OUTPUT_FORMAT); + } + + @Test + public void testValidOutputFormatOptionSupplied() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + p1.setOutputFormat(Parameters.OutputFormat.CSV_YIELD_TABLE); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages()); + } + + @Test + public void testInvalidCombineAgeYearRangeOptionSupplied() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + p1.setCombineAgeYearRange("bad option"); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), UNRECOGNIZED_COMBINE_AGE_YEAR_RANGE_OPTION); + } + + @Test + public void testValidCombineAgeYearRangeOptionSupplied() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + p1.setCombineAgeYearRange(Parameters.AgeYearRangeCombinationKind.INTERSECT); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages()); + } + + @Test + public void testInvalidProcessFrequencySupplied() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + p1.setProgressFrequency("bad option"); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), INVALID_PROCESS_FREQUENCY_VALUE); + } + + @Test + public void testValidProcessFrequencySupplied1() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + p1.setProgressFrequency(ProgressFrequency.FrequencyKind.MAPSHEET); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages()); + } + + @Test + public void testValidProcessFrequencySupplied2() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + p1.setProgressFrequency(100); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages()); + } + + @Test + public void testInvalidMetadataToOutputValueSupplied() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + p1.setMetadataToOutput("bad option"); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), INVALID_METADATA_TO_OUTPUT_VALUE); + } + + @Test + public void testInvalidExecutionOptionSupplied() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + p1.addSelectedExecutionOptionsItem(ExecutionOption.BACK_GROW_ENABLED) + .addSelectedExecutionOptionsItem("bad option"); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), UNRECOGNIZED_EXECUTION_OPTION); + } + + @Test + public void testInvalidDebugOptionSupplied() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + p1.addSelectedDebugOptionsItem(DebugOption.DO_INCLUDE_DEBUG_ENTRY_EXIT) + .addSelectedDebugOptionsItem("bad option"); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), UNRECOGNIZED_DEBUG_OPTION); + } + + @Test + public void testBadUtilizationParameterSpeciesSupplied() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var up = new UtilizationParameter().speciesName("bad species name") + .utilizationClass(UtilizationParameter.UtilizationClass._12_5.getValue()); + p1.addUtilsItem(up); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), UNKNOWN_SPECIES_GROUP_NAME); + } + + @Test + public void testBadUtilizationParameterUtilizationClassSupplied() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var up = new UtilizationParameter().speciesName("D").utilizationClass("bad utilization class"); + p1.addUtilsItem(up); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), UNKNOWN_UTILIZATION_CLASS_NAME); + } + + @Test + public void testBadUtilizationParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var up = new UtilizationParameter().speciesName("bad species name").utilizationClass("bad utilization class"); + p1.addUtilsItem(up); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs( + validator.getValidationMessages(), UNKNOWN_SPECIES_GROUP_NAME, UNKNOWN_UTILIZATION_CLASS_NAME + ); + } + + @Test + public void testValidUtilizationParameterSupplied() throws WebApplicationException, IOException { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + var up = new UtilizationParameter().speciesName("D").utilizationClass(UtilizationClass._12_5); + p1.addUtilsItem(up); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages()); + } + + @Test + public void testInvalidForceYear() { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + p1.forceYear("bad year"); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), INVALID_INTEGER_VALUE); + } + + @Test + public void testValidForceYear() { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + p1.forceYear(2020); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages()); + } + + @Test + public void testDCSVIssues() { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + p1.outputFormat(OutputFormat.DCSV); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs( + validator.getValidationMessages(), AGE_RANGES_IGNORED_WHEN_DCSV_OUTPUT, + MUST_BE_EXACTLY_ONE_FORCE_PARAM_WHEN_DCSV_OUTPUT, MISMATCHED_INPUT_OUTPUT_TYPES + ); + } + + @Test + public void testDCSVIssues2() { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + p1.outputFormat(OutputFormat.DCSV).forceYear(2020); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs( + validator.getValidationMessages(), AGE_RANGES_IGNORED_WHEN_DCSV_OUTPUT, MISMATCHED_INPUT_OUTPUT_TYPES + ); + } + + @Test + public void testCSFBiomassIssues1() { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + p1.addSelectedExecutionOptionsItem(ExecutionOption.DO_INCLUDE_PROJECTED_CFS_BIOMASS) + .addSelectedExecutionOptionsItem(ExecutionOption.DO_INCLUDE_PROJECTED_MOF_BIOMASS); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs( + validator.getValidationMessages(), CANNOT_SPECIFY_BOTH_CFS_AND_MOF_BIOMASS_OUTPUT, + CANNOT_SPECIFY_BOTH_CFS_BIOMASS_AND_EITHER_MOF_OPTIONS + ); + } + + @Test + public void testCSFBiomassIssues2() { + + Parameters p1 = buildValidParametersObject(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.HCSV, "id", p1); + + p1.addSelectedExecutionOptionsItem(ExecutionOption.DO_INCLUDE_PROJECTED_CFS_BIOMASS) + .addSelectedExecutionOptionsItem(ExecutionOption.DO_INCLUDE_PROJECTED_MOF_VOLUMES); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), CANNOT_SPECIFY_BOTH_CFS_BIOMASS_AND_EITHER_MOF_OPTIONS); + } + + @Test + public void testCSFBiomassIssues3() { + + Parameters p1 = new Parameters(); + ProjectionState s1 = new ProjectionState(ProjectionRequestKind.DCSV, "id", p1); + + p1.addSelectedExecutionOptionsItem(ExecutionOption.DO_INCLUDE_PROJECTED_CFS_BIOMASS) + .outputFormat(OutputFormat.DCSV).forceYear(2020); + + var validator = new ProjectionRequestValidator(); + validator.validateState(s1); + verifyMessageSetIs(validator.getValidationMessages(), INVALID_CFS_BIOMASS_OUTPUT_FORMAT); + } + + // Helpers + + private void verifyMessageSetIs(List validationMessages, ValidationMessageKind... kinds) { + Set expectedKinds = Set.of(kinds); + Set presentKinds = new HashSet<>(); + + for (var message : validationMessages) { + presentKinds.add(message.getKind()); + } + + Assert.assertEquals(expectedKinds, presentKinds); + } + + private Parameters buildValidParametersObject() { + return new Parameters().ageEnd(400).ageStart(1); } }