From 2d5165f5ad95fb241ef25db1c8b064a0ff65b9e3 Mon Sep 17 00:00:00 2001 From: Bert Scholten Date: Thu, 30 May 2024 13:09:40 +0200 Subject: [PATCH] AER-2858 added more information for conversion warnings (#276) --- .../gml/base/source/lodging/GML2Farm.java | 37 +++++++++++-------- .../aerius/gml/GMLValidateErrorsTest.java | 10 +++-- .../exception/ImaerExceptionReason.java | 12 ++++-- 3 files changed, 37 insertions(+), 22 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 cc535bbe..de8f5bdb 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 @@ -70,18 +70,18 @@ public EmissionSource convert(final T source) throws AeriusException { private FarmAnimalHousingEmissionSource convertToAnimalHousing(final T source) throws AeriusException { final FarmAnimalHousingEmissionSource animalHousingSource = new FarmAnimalHousingEmissionSource(); for (final IsGmlProperty lodging : source.getFarmLodgings()) { - animalHousingSource.getSubSources().add(getAnimalHousing(lodging.getProperty(), source.getId())); + animalHousingSource.getSubSources().add(getAnimalHousing(lodging.getProperty(), source)); } animalHousingSource.setEstablished(source.getEstablished()); return animalHousingSource; } - private FarmAnimalHousing getAnimalHousing(final IsGmlFarmLodging lodging, final String sourceId) throws AeriusException { + private FarmAnimalHousing getAnimalHousing(final IsGmlFarmLodging lodging, final T source) throws AeriusException { final FarmAnimalHousing returnAnimalHousing; if (lodging instanceof final IsGmlCustomFarmLodging customLodging) { - returnAnimalHousing = convertCustom(customLodging, sourceId); + returnAnimalHousing = convertCustom(customLodging, source); } else if (lodging instanceof final IsGmlStandardFarmLodging standardLodging) { - returnAnimalHousing = convertStandard(standardLodging, sourceId); + returnAnimalHousing = convertStandard(standardLodging, source); } else { LOG.error("Don't know how to treat lodging type: {}", lodging.getClass()); throw new AeriusException(ImaerExceptionReason.INTERNAL_ERROR); @@ -91,11 +91,11 @@ private FarmAnimalHousing getAnimalHousing(final IsGmlFarmLodging lodging, final return returnAnimalHousing; } - private CustomFarmAnimalHousing convertCustom(final IsGmlCustomFarmLodging customLodging, final String sourceId) throws AeriusException { + private CustomFarmAnimalHousing convertCustom(final IsGmlCustomFarmLodging customLodging, final T source) throws AeriusException { final CustomFarmAnimalHousing customEmissions = new CustomFarmAnimalHousing(); customEmissions.setAnimalTypeCode(customLodging.getAnimalCode() == null ? UNKNOWN_ANIMAL_TYPE_CODE : customLodging.getAnimalCode()); customEmissions.setDescription(customLodging.getDescription()); - customEmissions.setFarmEmissionFactorType(determineEmissionFactorType(customLodging.getEmissionFactorType(), sourceId)); + customEmissions.setFarmEmissionFactorType(determineEmissionFactorType(customLodging.getEmissionFactorType(), source.getId())); for (final IsGmlProperty emissionProperty : customLodging.getEmissionFactors()) { final IsGmlEmission emission = emissionProperty.getProperty(); customEmissions.getEmissionFactors().put(emission.getSubstance(), emission.getValue()); @@ -103,15 +103,15 @@ private CustomFarmAnimalHousing convertCustom(final IsGmlCustomFarmLodging custo return customEmissions; } - private FarmAnimalHousing convertStandard(final IsGmlStandardFarmLodging standardLodging, final String sourceId) { + private FarmAnimalHousing convertStandard(final IsGmlStandardFarmLodging standardLodging, final T source) { final FarmAnimalHousing converted; final String oldCode = standardLodging.getCode(); final FarmLodgingConversion conversion = getConversionData().determineFarmLodgingConversion(oldCode); if (conversion == null) { - converted = convertStandardWithoutConversion(standardLodging, sourceId); + converted = convertStandardWithoutConversion(standardLodging, source); } else { - converted = convertStandardWithConversion(conversion, standardLodging, sourceId); + converted = convertStandardWithConversion(conversion, standardLodging, source); } converted.setNumberOfAnimals(standardLodging.getNumberOfAnimals()); converted.setNumberOfDays(standardLodging.getNumberOfDays()); @@ -120,7 +120,7 @@ private FarmAnimalHousing convertStandard(final IsGmlStandardFarmLodging standar } private CustomFarmAnimalHousing convertStandardWithoutConversion( - final IsGmlStandardFarmLodging standardLodging, final String sourceId) { + final IsGmlStandardFarmLodging standardLodging, final T source) { final CustomFarmAnimalHousing customEmissions = new CustomFarmAnimalHousing(); // Not sure if this'll stick: relies on custom animal housing using the old AnimalType codes. customEmissions.setAnimalTypeCode(standardLodging.getCode() == null || standardLodging.getCode().length() <= 1 @@ -130,12 +130,12 @@ private CustomFarmAnimalHousing convertStandardWithoutConversion( 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. - addWarningForSource(ImaerExceptionReason.GML_CONVERTED_LODGING_TO_CUSTOM, sourceId, standardLodging); + addWarningForSource(ImaerExceptionReason.GML_CONVERTED_LODGING_TO_CUSTOM, source, standardLodging); return customEmissions; } private StandardFarmAnimalHousing convertStandardWithConversion(final FarmLodgingConversion conversion, - final IsGmlStandardFarmLodging standardLodging, final String sourceId) { + final IsGmlStandardFarmLodging standardLodging, final T source) { final StandardFarmAnimalHousing standardEmissions = new StandardFarmAnimalHousing(); standardEmissions.setAnimalTypeCode(conversion.getAnimalTypeCode()); standardEmissions.setAnimalHousingCode(conversion.getAnimalHousingCode()); @@ -147,16 +147,21 @@ private StandardFarmAnimalHousing convertStandardWithConversion(final FarmLodgin if (!standardLodging.getLodgingSystems().isEmpty() || !standardLodging.getFodderMeasures().isEmpty()) { // We can't convert additional systems: no data available to do so. // Instead, add a specific warning that the user has to check additional systems for this source. - addWarningForSource(ImaerExceptionReason.GML_CONVERTED_LODGING_WITH_SYSTEMS, sourceId, standardLodging); + addWarningForSource(ImaerExceptionReason.GML_CONVERTED_LODGING_WITH_SYSTEMS, source, standardLodging); } else if (!conversion.getAnimalHousingCode().equals(standardLodging.getCode())) { // Warn the user that this source has been converted. - addWarningForSource(ImaerExceptionReason.GML_CONVERTED_LODGING, sourceId, standardLodging); + addWarningForSource(ImaerExceptionReason.GML_CONVERTED_LODGING, source, standardLodging); } return standardEmissions; } - private void addWarningForSource(final ImaerExceptionReason reason, final String sourceId, final IsGmlStandardFarmLodging standardLodging) { - getConversionData().getWarnings().add(new AeriusException(reason, sourceId, standardLodging.getCode())); + private void addWarningForSource(final ImaerExceptionReason reason, final T source, final IsGmlStandardFarmLodging standardLodging) { + getConversionData().getWarnings().add(new AeriusException(reason, source.getId(), safe(source.getLabel()), + standardLodging.getCode(), safe(standardLodging.getLodgingSystemDefinitionCode()))); + } + + private String safe(final String value) { + return value == null ? "" : value; } public FarmLodgingEmissionSource convertLegacy(final T source) throws AeriusException { diff --git a/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLValidateErrorsTest.java b/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLValidateErrorsTest.java index 39d82868..fb0c4344 100644 --- a/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLValidateErrorsTest.java +++ b/source/imaer-gml/src/test/java/nl/overheid/aerius/gml/GMLValidateErrorsTest.java @@ -153,7 +153,9 @@ void testGMLUnknownPasMeasure() throws IOException { assertResult("fout_5216_unknown_pas_measure", "GML Unknown PAS measure", ImaerExceptionReason.GML_CONVERTED_LODGING_WITH_SYSTEMS, e -> { assertEquals("ES.1", e.getArgs()[0], "Id"); - assertEquals("A1.1", e.getArgs()[1], "Code of lodging"); + assertEquals("Bron 1", e.getArgs()[1], "Label"); + assertEquals("A1.1", e.getArgs()[2], "Code of lodging"); + assertEquals("GL_BB93.06.009", e.getArgs()[3], "System definition code of lodging"); }); } @@ -162,8 +164,10 @@ void testGMLUnsupportedLodingMeasure() throws IOException { // With animal housing, lodgings with systems are just converted with special warning. assertResult("fout_5217_unsupported_lodging_measure", "GML Unsupported loding measure", ImaerExceptionReason.GML_CONVERTED_LODGING_WITH_SYSTEMS, e -> { - assertEquals("ES.1", e.getArgs()[0], "Label"); - assertEquals("A1.1", e.getArgs()[1], "Code of lodging"); + assertEquals("ES.1", e.getArgs()[0], "ID"); + assertEquals("Bron 1", e.getArgs()[1], "Label"); + assertEquals("A1.1", e.getArgs()[2], "Code of lodging"); + assertEquals("GL_BB93.06.009", e.getArgs()[3], "System definition code of lodging"); }); } diff --git a/source/imaer-shared/src/main/java/nl/overheid/aerius/shared/exception/ImaerExceptionReason.java b/source/imaer-shared/src/main/java/nl/overheid/aerius/shared/exception/ImaerExceptionReason.java index f0d803b4..6923b005 100644 --- a/source/imaer-shared/src/main/java/nl/overheid/aerius/shared/exception/ImaerExceptionReason.java +++ b/source/imaer-shared/src/main/java/nl/overheid/aerius/shared/exception/ImaerExceptionReason.java @@ -524,7 +524,9 @@ public enum ImaerExceptionReason implements Reason { * GML contained a farm lodging that was converted to standard animal housing. * * @param 0 the id of the object that was converted. - * @param 1 the code of the lodging that was converted. + * @param 1 the label of the object that was converted. + * @param 2 the code of the lodging that was converted. + * @param 3 the system definition code of the lodging that was converted. */ GML_CONVERTED_LODGING(5263), /** @@ -532,7 +534,9 @@ public enum ImaerExceptionReason implements Reason { * In this case, the lodging contained additional or reductive systems or fodder measures, which were not converted. * * @param 0 the id of the object that was converted. - * @param 1 the code of the lodging that was converted. + * @param 1 the label of the object that was converted. + * @param 2 the code of the lodging that was converted. + * @param 3 the system definition code of the lodging that was converted. */ GML_CONVERTED_LODGING_WITH_SYSTEMS(5264), /** @@ -541,7 +545,9 @@ public enum ImaerExceptionReason implements Reason { * A custom animal housing has been created instead, with 0 emission factors. * * @param 0 the id of the object that was converted. - * @param 1 the code of the lodging that could not be converted. + * @param 1 the label of the object that was converted. + * @param 2 the code of the lodging that was converted. + * @param 3 the system definition code of the lodging that was converted. */ GML_CONVERTED_LODGING_TO_CUSTOM(5265),