From 915f8a60ca8d8b7fe7a168805c8d38fadceb7b71 Mon Sep 17 00:00:00 2001 From: Bert Scholten Date: Wed, 5 Jun 2024 14:35:53 +0200 Subject: [PATCH 1/2] AER-2858 description when farm lodging could not be converted Instead of an empty description, the description should now contain the main codes used in the old lodging definition. Only the main one, not any of the additional stuff, that would just get messy. --- .../gml/base/source/lodging/GML2Farm.java | 10 ++- .../overheid/aerius/gml/GMLRoundtripTest.java | 6 ++ .../gml/v5_1/roundtrip/farm_no_conversion.gml | 82 +++++++++++++++++ .../gml/v6_0/roundtrip/farm_no_conversion.gml | 88 +++++++++++++++++++ 4 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 source/imaer-gml/src/test/resources/gml/v5_1/roundtrip/farm_no_conversion.gml create mode 100644 source/imaer-gml/src/test/resources/gml/v6_0/roundtrip/farm_no_conversion.gml diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/base/source/lodging/GML2Farm.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/base/source/lodging/GML2Farm.java index de8f5bdb..0246ff88 100644 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/base/source/lodging/GML2Farm.java +++ b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/base/source/lodging/GML2Farm.java @@ -16,6 +16,11 @@ */ package nl.overheid.aerius.gml.base.source.lodging; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -126,7 +131,10 @@ private CustomFarmAnimalHousing convertStandardWithoutConversion( customEmissions.setAnimalTypeCode(standardLodging.getCode() == null || standardLodging.getCode().length() <= 1 ? UNKNOWN_ANIMAL_TYPE_CODE : standardLodging.getCode().substring(0, 1)); - customEmissions.setDescription(""); + final List descriptionParts = new ArrayList<>(); + Optional.ofNullable(standardLodging.getCode()).ifPresent(descriptionParts::add); + Optional.ofNullable(standardLodging.getLodgingSystemDefinitionCode()).ifPresent(descriptionParts::add); + customEmissions.setDescription(descriptionParts.stream().collect(Collectors.joining(", "))); customEmissions.setFarmEmissionFactorType(FarmEmissionFactorType.PER_ANIMAL_PER_YEAR); customEmissions.getEmissionFactors().put(Substance.NH3, 0.0); // Warn the user that this source has been converted to custom animal housing. diff --git a/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLRoundtripTest.java b/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLRoundtripTest.java index 839f6ec0..886631c6 100644 --- a/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLRoundtripTest.java +++ b/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLRoundtripTest.java @@ -163,6 +163,9 @@ class GMLRoundtripTest { {"farm_animal_housing", CharacteristicsType.OPS}, {"farm_animal_housing_with_systems", CharacteristicsType.OPS}, {"farm_animal_housing_custom_per_day", CharacteristicsType.OPS}, + // Case where lodging could not be converted directly to animal housing + {"farm_no_conversion", CharacteristicsType.OPS, + EnumSet.of(ImaerExceptionReason.GML_SOURCE_NO_EMISSION, ImaerExceptionReason.GML_CONVERTED_LODGING_TO_CUSTOM), true}, }; private static final String LATEST_VERSION = "latest"; @@ -230,6 +233,9 @@ private static Set getWarningReasons(final Object[] object, final Aerius if (warnings.contains(ImaerExceptionReason.GML_CONVERTED_LODGING_WITH_SYSTEMS) && version.ordinal() <= AeriusGMLVersion.V6_0.ordinal()) { warnings.remove(ImaerExceptionReason.GML_CONVERTED_LODGING_WITH_SYSTEMS); } + if (warnings.contains(ImaerExceptionReason.GML_CONVERTED_LODGING_TO_CUSTOM) && version.ordinal() <= AeriusGMLVersion.V6_0.ordinal()) { + warnings.remove(ImaerExceptionReason.GML_CONVERTED_LODGING_TO_CUSTOM); + } return warnings; } diff --git a/source/imaer-gml/src/test/resources/gml/v5_1/roundtrip/farm_no_conversion.gml b/source/imaer-gml/src/test/resources/gml/v5_1/roundtrip/farm_no_conversion.gml new file mode 100644 index 00000000..1ba5317b --- /dev/null +++ b/source/imaer-gml/src/test/resources/gml/v5_1/roundtrip/farm_no_conversion.gml @@ -0,0 +1,82 @@ + + + + + + + 2013 + Situatie 1 + + + + + Situatie 1 + RpXpU4DVH2Nw + PROPOSED + + + + + DEV + BETA8_20140904_7fbba21b46 + + + + + + + + + NL.IMAER + ES.6 + + + Boerderij + + + + + 0.0 + + + 5.0 + + + + + + + 69462.46 443548.56 + + + + + + + 2149.0 + + + + + 0.0 + + + + + 0.0 + + + + + 0.0 + + + + + 100 + LWB1999.0.1 + + + + + diff --git a/source/imaer-gml/src/test/resources/gml/v6_0/roundtrip/farm_no_conversion.gml b/source/imaer-gml/src/test/resources/gml/v6_0/roundtrip/farm_no_conversion.gml new file mode 100644 index 00000000..d6cd9ab2 --- /dev/null +++ b/source/imaer-gml/src/test/resources/gml/v6_0/roundtrip/farm_no_conversion.gml @@ -0,0 +1,88 @@ + + + + + + + 2013 + Situatie 1 + + + + + Situatie 1 + RpXpU4DVH2Nw + PROPOSED + + + + + DEV + BETA8_20140904_7fbba21b46 + + + + + + + + + NL.IMAER + ES.6 + + + Boerderij + + + + + 0.0 + + + 5.0 + + + + + + + 69462.46 443548.56 + + + + + + + 0.0 + + + + + 0.0 + + + + + 0.0 + + + + + 0.0 + + + + + 100 + X9.8, LWB1999.0.1 + + + 0.0 + + + PER_ANIMAL_PER_YEAR + + + + + From 179dac20efb850ced806fd87f0584e7f474cee0b Mon Sep 17 00:00:00 2001 From: Bert Scholten Date: Fri, 7 Jun 2024 14:25:46 +0200 Subject: [PATCH 2/2] Review comment --- .../nl/overheid/aerius/gml/base/source/lodging/GML2Farm.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/base/source/lodging/GML2Farm.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/base/source/lodging/GML2Farm.java index 0246ff88..4c477a78 100644 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/base/source/lodging/GML2Farm.java +++ b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/base/source/lodging/GML2Farm.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -134,7 +133,7 @@ private CustomFarmAnimalHousing convertStandardWithoutConversion( final List descriptionParts = new ArrayList<>(); Optional.ofNullable(standardLodging.getCode()).ifPresent(descriptionParts::add); Optional.ofNullable(standardLodging.getLodgingSystemDefinitionCode()).ifPresent(descriptionParts::add); - customEmissions.setDescription(descriptionParts.stream().collect(Collectors.joining(", "))); + customEmissions.setDescription(String.join(", ", descriptionParts)); customEmissions.setFarmEmissionFactorType(FarmEmissionFactorType.PER_ANIMAL_PER_YEAR); customEmissions.getEmissionFactors().put(Substance.NH3, 0.0); // Warn the user that this source has been converted to custom animal housing.