Skip to content

Commit

Permalink
AER-3210 Added ProjectCategory enum (#304)
Browse files Browse the repository at this point in the history
- Added ProjectCategory enum
- Added ProjectCategory to NCACalculationOptions
- Added ProjectCategory to OptionsMetadataUtil and -test
  • Loading branch information
MichielJanssen-DAT authored Oct 10, 2024
1 parent ab072e9 commit c28e6cd
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class NCACalculationOptions implements Serializable {

private static final long serialVersionUID = 1L;

private ProjectCategory projectCategory;

/**
* Regional area for which a permit calculation would apply to.
*/
Expand Down Expand Up @@ -67,6 +69,15 @@ public class NCACalculationOptions implements Serializable {
*/
private Double roadLocalFractionNO2;


public ProjectCategory getProjectCategory() {
return projectCategory;
}

public void setProjectCategory(final ProjectCategory projectCategory) {
this.projectCategory = projectCategory;
}

public String getPermitArea() {
return permitArea;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright the State of the Netherlands
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package nl.overheid.aerius.shared.domain.calculation;

import java.util.Locale;

/**
* The project category the calculation is for.
*/
public enum ProjectCategory {
AGRICULTURE,
COMBUSTION_PLANT,
ROADS;

public static ProjectCategory safeValueOf(final String value) {
try {
return value == null ? null : valueOf(value.toUpperCase(Locale.ROOT));
} catch (final IllegalArgumentException e) {
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import nl.overheid.aerius.shared.domain.calculation.NCACalculationOptions;
import nl.overheid.aerius.shared.domain.calculation.OPSOptions;
import nl.overheid.aerius.shared.domain.calculation.OwN2000CalculationOptions;
import nl.overheid.aerius.shared.domain.calculation.ProjectCategory;
import nl.overheid.aerius.shared.domain.calculation.RoadLocalFractionNO2Option;

/**
Expand Down Expand Up @@ -90,6 +91,7 @@ public enum Option {

/* ADMS options related */
ADMS_VERSION,
ADMS_PROJECT_CATEGORY,
ADMS_PERMIT_AREA,
ADMS_MIN_MONIN_OBUKHOV_LENGTH,
ADMS_SURFACE_ALBEDO,
Expand Down Expand Up @@ -238,6 +240,7 @@ private static void opsOptionsToMap(final OPSOptions options, final Map<String,

private static void ncaOptionsFromMap(final NCACalculationOptions options, final Map<Option, String> map,
final Map<String, Map<Option, String>> prefixedOptionsMap) {
options.setProjectCategory(ProjectCategory.safeValueOf(map.get(Option.ADMS_PROJECT_CATEGORY)));
options.setPermitArea(map.get(Option.ADMS_PERMIT_AREA));
options.setRoadLocalFractionNO2ReceptorsOption(RoadLocalFractionNO2Option.safeValueOf(map.get(Option.ROAD_LOCAL_FRACTION_NO2_RECEPTORS_OPTION)));
options.setRoadLocalFractionNO2PointsOption(RoadLocalFractionNO2Option.safeValueOf(map.get(Option.ROAD_LOCAL_FRACTION_NO2_POINTS_OPTION)));
Expand Down Expand Up @@ -315,6 +318,7 @@ private static void ncaParseMetYears(final ADMSOptions admsOptions, final Map<Op
private static void ncaOptionsToMap(final Map<String, String> mapToAddTo, final NCACalculationOptions options, final boolean addDefaults) {
if (options != null) {
addValue(mapToAddTo, Option.ADMS_VERSION, options.getAdmsVersion(), addDefaults);
addValue(mapToAddTo, Option.ADMS_PROJECT_CATEGORY, options.getProjectCategory(), addDefaults);
addValue(mapToAddTo, Option.ADMS_PERMIT_AREA, options.getPermitArea(), addDefaults);
addValue(mapToAddTo, Option.ROAD_LOCAL_FRACTION_NO2_RECEPTORS_OPTION, options.getRoadLocalFractionNO2ReceptorsOption(), addDefaults);
addValue(mapToAddTo, Option.ROAD_LOCAL_FRACTION_NO2_POINTS_OPTION, options.getRoadLocalFractionNO2PointsOption(), addDefaults);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import nl.overheid.aerius.shared.domain.calculation.NCACalculationOptions;
import nl.overheid.aerius.shared.domain.calculation.OPSOptions;
import nl.overheid.aerius.shared.domain.calculation.OwN2000CalculationOptions;
import nl.overheid.aerius.shared.domain.calculation.ProjectCategory;
import nl.overheid.aerius.shared.domain.calculation.RoadLocalFractionNO2Option;
import nl.overheid.aerius.shared.domain.calculation.SubReceptorsMode;
import nl.overheid.aerius.shared.domain.meteo.Meteo;
Expand Down Expand Up @@ -198,6 +199,7 @@ void testNcaOptions() {
final NCACalculationOptions ncaOptions = options.getNcaCalculationOptions();

ncaOptions.setAdmsVersion("5.0.0.1");
ncaOptions.setProjectCategory(ProjectCategory.AGRICULTURE);
ncaOptions.setPermitArea("London");
ncaOptions.setRoadLocalFractionNO2ReceptorsOption(RoadLocalFractionNO2Option.ONE_CUSTOM_VALUE);
ncaOptions.setRoadLocalFractionNO2PointsOption(RoadLocalFractionNO2Option.ONE_CUSTOM_VALUE);
Expand Down Expand Up @@ -225,6 +227,7 @@ void testNcaOptions() {
final Map<String, String> result = OptionsMetadataUtil.optionsToMap(Theme.NCA, options, false);

assertEquals("5.0.0.1", result.get("adms_version"), "adms_version should be set");
assertEquals("AGRICULTURE", result.get("adms_project_category"), "project_category should be set");
assertEquals("London", result.get("adms_permit_area"), "adms_permit_area should be set");
assertEquals("12.3", result.get("adms_min_monin_obukhov_length"), "adms_min_monin_obukhov_length should be set");
assertEquals("23.4", result.get("adms_surface_albedo"), "adms_surface_albedo should be set");
Expand Down Expand Up @@ -281,6 +284,7 @@ void testNcaOptionsRoundtrip() {
final NCACalculationOptions ncaOptions = options.getNcaCalculationOptions();

ncaOptions.setPermitArea("London");
ncaOptions.setProjectCategory(ProjectCategory.ROADS);
ncaOptions.setRoadLocalFractionNO2ReceptorsOption(RoadLocalFractionNO2Option.ONE_CUSTOM_VALUE);
ncaOptions.setRoadLocalFractionNO2PointsOption(RoadLocalFractionNO2Option.ONE_CUSTOM_VALUE);
ncaOptions.setRoadLocalFractionNO2(0.4);
Expand Down

0 comments on commit c28e6cd

Please sign in to comment.