-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AER-2828 farm animal housing in IMAER (#264)
* Animal housing in IMAER 6.0 Removed lodging from IMAER 6 (or replaced parts of it), as it should now be a good time to do so. * Removed some IMAER 6.0 classes related to lodging * Changed additionalSystemType to be an attribute More in line with how we do this for other classes. Also added some more test cases for round trip.
- Loading branch information
1 parent
e438123
commit 0c25fd9
Showing
47 changed files
with
1,877 additions
and
1,808 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
141 changes: 141 additions & 0 deletions
141
...r-gml/src/main/java/nl/overheid/aerius/gml/base/source/housing/GML2FarmAnimalHousing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* 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.gml.base.source.housing; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import nl.overheid.aerius.gml.base.AbstractGML2Specific; | ||
import nl.overheid.aerius.gml.base.GMLConversionData; | ||
import nl.overheid.aerius.gml.base.IsGmlProperty; | ||
import nl.overheid.aerius.gml.base.source.IsGmlEmission; | ||
import nl.overheid.aerius.shared.domain.v2.source.FarmAnimalHousingEmissionSource; | ||
import nl.overheid.aerius.shared.domain.v2.source.farm.AdditionalHousingSystem; | ||
import nl.overheid.aerius.shared.domain.v2.source.farm.CustomAdditionalHousingSystem; | ||
import nl.overheid.aerius.shared.domain.v2.source.farm.CustomFarmAnimalHousing; | ||
import nl.overheid.aerius.shared.domain.v2.source.farm.FarmAnimalHousing; | ||
import nl.overheid.aerius.shared.domain.v2.source.farm.StandardAdditionalHousingSystem; | ||
import nl.overheid.aerius.shared.domain.v2.source.farm.StandardFarmAnimalHousing; | ||
import nl.overheid.aerius.shared.emissions.FarmEmissionFactorType; | ||
import nl.overheid.aerius.shared.exception.AeriusException; | ||
import nl.overheid.aerius.shared.exception.ImaerExceptionReason; | ||
|
||
/** | ||
* | ||
*/ | ||
public class GML2FarmAnimalHousing<T extends IsGmlFarmAnimalHousingSource> extends AbstractGML2Specific<T, FarmAnimalHousingEmissionSource> { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(GML2FarmAnimalHousing.class); | ||
|
||
public GML2FarmAnimalHousing(final GMLConversionData conversionData) { | ||
super(conversionData); | ||
} | ||
|
||
@Override | ||
public FarmAnimalHousingEmissionSource convert(final T source) throws AeriusException { | ||
final FarmAnimalHousingEmissionSource emissionValues = new FarmAnimalHousingEmissionSource(); | ||
for (final IsGmlProperty<IsGmlFarmAnimalHousing> housing : source.getFarmAnimalHousings()) { | ||
emissionValues.getSubSources().add(getFarmLodging(housing.getProperty(), source.getId())); | ||
} | ||
emissionValues.setEstablished(source.getEstablished()); | ||
return emissionValues; | ||
} | ||
|
||
private FarmAnimalHousing getFarmLodging(final IsGmlFarmAnimalHousing housing, final String sourceId) throws AeriusException { | ||
final FarmAnimalHousing returnHousing; | ||
if (housing instanceof final IsGmlCustomFarmAnimalHousing custom) { | ||
returnHousing = convertCustom(custom, sourceId); | ||
} else if (housing instanceof final IsGmlStandardFarmAnimalHousing standard) { | ||
returnHousing = convertStandard(standard); | ||
} else { | ||
LOG.error("Don't know how to treat lodging type: {}", housing.getClass()); | ||
throw new AeriusException(ImaerExceptionReason.INTERNAL_ERROR); | ||
} | ||
returnHousing.setAnimalTypeCode(housing.getAnimalCode()); | ||
returnHousing.setNumberOfAnimals(housing.getNumberOfAnimals()); | ||
returnHousing.setNumberOfDays(housing.getNumberOfDays()); | ||
return returnHousing; | ||
} | ||
|
||
private CustomFarmAnimalHousing convertCustom(final IsGmlCustomFarmAnimalHousing customHousing, final String sourceId) throws AeriusException { | ||
final CustomFarmAnimalHousing customEmissions = new CustomFarmAnimalHousing(); | ||
customEmissions.setDescription(customHousing.getDescription()); | ||
customEmissions.setFarmEmissionFactorType(determineEmissionFactorType(customHousing.getEmissionFactorType(), sourceId)); | ||
for (final IsGmlProperty<IsGmlEmission> emissionProperty : customHousing.getEmissionFactors()) { | ||
final IsGmlEmission emission = emissionProperty.getProperty(); | ||
customEmissions.getEmissionFactors().put(emission.getSubstance(), emission.getValue()); | ||
} | ||
return customEmissions; | ||
} | ||
|
||
private FarmEmissionFactorType determineEmissionFactorType(final String gmlEmissionFactorType, final String sourceId) throws AeriusException { | ||
if (gmlEmissionFactorType == null) { | ||
return FarmEmissionFactorType.PER_ANIMAL_PER_YEAR; | ||
} | ||
final FarmEmissionFactorType type = FarmEmissionFactorType.safeValueOf(gmlEmissionFactorType); | ||
if (type == null) { | ||
throw new AeriusException(ImaerExceptionReason.GML_UNKNOWN_FARM_EMISSION_FACTOR_TYPE, sourceId, gmlEmissionFactorType); | ||
} | ||
|
||
return type; | ||
} | ||
|
||
private StandardFarmAnimalHousing convertStandard(final IsGmlStandardFarmAnimalHousing standardLodging) throws AeriusException { | ||
final StandardFarmAnimalHousing standardEmissions = new StandardFarmAnimalHousing(); | ||
final String categoryCode = standardLodging.getCode(); | ||
|
||
standardEmissions.setAnimalHousingCode(categoryCode); | ||
handleAdditionalSystems(standardLodging, standardEmissions); | ||
|
||
return standardEmissions; | ||
} | ||
|
||
private void handleAdditionalSystems(final IsGmlStandardFarmAnimalHousing housing, final StandardFarmAnimalHousing standardEmissions) | ||
throws AeriusException { | ||
for (final IsGmlProperty<IsGmlAdditionalHousingSystem> additionalSystemProperty : housing.getAdditionalSystems()) { | ||
final IsGmlAdditionalHousingSystem lodgingSystem = additionalSystemProperty.getProperty(); | ||
final AdditionalHousingSystem resultSystem; | ||
if (lodgingSystem instanceof final IsGmlStandardAdditionalHousingSystem standardSystem) { | ||
resultSystem = getStandardAdditionalSystem(standardSystem); | ||
} else if (lodgingSystem instanceof final IsGmlCustomAdditionalHousingSystem customSystem) { | ||
resultSystem = getCustomAdditionalSystem(customSystem); | ||
} else { | ||
LOG.error("Don't know how to treat additional system type: {}", lodgingSystem.getClass()); | ||
throw new AeriusException(ImaerExceptionReason.INTERNAL_ERROR); | ||
} | ||
standardEmissions.getAdditionalSystems().add(resultSystem); | ||
} | ||
} | ||
|
||
private StandardAdditionalHousingSystem getStandardAdditionalSystem(final IsGmlStandardAdditionalHousingSystem additionalSystem) { | ||
final StandardAdditionalHousingSystem resultSystem = new StandardAdditionalHousingSystem(); | ||
resultSystem.setAdditionalSystemCode(additionalSystem.getCode()); | ||
return resultSystem; | ||
} | ||
|
||
private CustomAdditionalHousingSystem getCustomAdditionalSystem(final IsGmlCustomAdditionalHousingSystem additionalSystem) { | ||
final CustomAdditionalHousingSystem resultSystem = new CustomAdditionalHousingSystem(); | ||
resultSystem.setDescription(additionalSystem.getDescription()); | ||
resultSystem.setAirScrubber(additionalSystem.getAirScrubber() == null || additionalSystem.getAirScrubber()); | ||
for (final IsGmlProperty<IsGmlEmission> emissionProperty : additionalSystem.getEmissionReductionFactors()) { | ||
final IsGmlEmission emission = emissionProperty.getProperty(); | ||
resultSystem.getEmissionReductionFactors().put(emission.getSubstance(), emission.getValue()); | ||
} | ||
return resultSystem; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...rc/main/java/nl/overheid/aerius/gml/base/source/housing/IsGmlAdditionalHousingSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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.gml.base.source.housing; | ||
|
||
public interface IsGmlAdditionalHousingSystem { | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...n/java/nl/overheid/aerius/gml/base/source/housing/IsGmlCustomAdditionalHousingSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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.gml.base.source.housing; | ||
|
||
import java.util.List; | ||
|
||
import nl.overheid.aerius.gml.base.IsGmlProperty; | ||
import nl.overheid.aerius.gml.base.source.IsGmlEmission; | ||
|
||
public interface IsGmlCustomAdditionalHousingSystem extends IsGmlAdditionalHousingSystem { | ||
|
||
String getDescription(); | ||
|
||
Boolean getAirScrubber(); | ||
|
||
List<? extends IsGmlProperty<IsGmlEmission>> getEmissionReductionFactors(); | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...rc/main/java/nl/overheid/aerius/gml/base/source/housing/IsGmlCustomFarmAnimalHousing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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.gml.base.source.housing; | ||
|
||
import java.util.List; | ||
|
||
import nl.overheid.aerius.gml.base.IsGmlProperty; | ||
import nl.overheid.aerius.gml.base.source.IsGmlEmission; | ||
|
||
public interface IsGmlCustomFarmAnimalHousing extends IsGmlFarmAnimalHousing { | ||
|
||
String getDescription(); | ||
|
||
String getEmissionFactorType(); | ||
|
||
List<? extends IsGmlProperty<IsGmlEmission>> getEmissionFactors(); | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...-gml/src/main/java/nl/overheid/aerius/gml/base/source/housing/IsGmlFarmAnimalHousing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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.gml.base.source.housing; | ||
|
||
public interface IsGmlFarmAnimalHousing { | ||
|
||
String getAnimalCode(); | ||
|
||
int getNumberOfAnimals(); | ||
|
||
Integer getNumberOfDays(); | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...rc/main/java/nl/overheid/aerius/gml/base/source/housing/IsGmlFarmAnimalHousingSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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.gml.base.source.housing; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
import nl.overheid.aerius.gml.base.IsGmlProperty; | ||
import nl.overheid.aerius.gml.base.source.IsGmlEmissionSource; | ||
|
||
public interface IsGmlFarmAnimalHousingSource extends IsGmlEmissionSource { | ||
|
||
List<? extends IsGmlProperty<IsGmlFarmAnimalHousing>> getFarmAnimalHousings(); | ||
|
||
LocalDate getEstablished(); | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...java/nl/overheid/aerius/gml/base/source/housing/IsGmlStandardAdditionalHousingSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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.gml.base.source.housing; | ||
|
||
public interface IsGmlStandardAdditionalHousingSystem extends IsGmlAdditionalHousingSystem { | ||
|
||
String getCode(); | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
.../main/java/nl/overheid/aerius/gml/base/source/housing/IsGmlStandardFarmAnimalHousing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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.gml.base.source.housing; | ||
|
||
import java.util.List; | ||
|
||
import nl.overheid.aerius.gml.base.IsGmlProperty; | ||
|
||
public interface IsGmlStandardFarmAnimalHousing extends IsGmlFarmAnimalHousing { | ||
|
||
String getCode(); | ||
|
||
List<? extends IsGmlProperty<IsGmlAdditionalHousingSystem>> getAdditionalSystems(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.