Skip to content

Commit

Permalink
AER-2828 farm animal housing in IMAER (#264)
Browse files Browse the repository at this point in the history
* 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
BertScholten authored May 6, 2024
1 parent e438123 commit 0c25fd9
Show file tree
Hide file tree
Showing 47 changed files with 1,877 additions and 1,808 deletions.
Binary file modified source/imaer-gml/src/main/eap/6.0/IMAER.EAP
Binary file not shown.
1,600 changes: 776 additions & 824 deletions source/imaer-gml/src/main/eap/6.0/IMAER.xmi

Large diffs are not rendered by default.

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;
}

}
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 {

}
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();

}
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();

}
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();

}
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();

}
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();

}
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();

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import nl.overheid.aerius.gml.base.characteristics.GML2SourceCharacteristics;
import nl.overheid.aerius.gml.base.source.GML2Generic;
import nl.overheid.aerius.gml.base.source.farmland.GML2Farmland;
import nl.overheid.aerius.gml.base.source.lodging.GML2Farm;
import nl.overheid.aerius.gml.base.source.housing.GML2FarmAnimalHousing;
import nl.overheid.aerius.gml.base.source.manure.GML2ManureStorage;
import nl.overheid.aerius.gml.base.source.mobile.v40.GML2OffRoad;
import nl.overheid.aerius.gml.base.source.road.GML2ADMSRoad;
Expand All @@ -37,7 +37,7 @@
import nl.overheid.aerius.gml.base.source.ship.GML2MaritimeRoute;
import nl.overheid.aerius.gml.v6_0.source.EmissionSource;
import nl.overheid.aerius.gml.v6_0.source.farmland.FarmlandEmissionSource;
import nl.overheid.aerius.gml.v6_0.source.lodging.FarmLodgingEmissionSource;
import nl.overheid.aerius.gml.v6_0.source.housing.FarmAnimalHousingEmissionSource;
import nl.overheid.aerius.gml.v6_0.source.manure.ManureStorageEmissionSource;
import nl.overheid.aerius.gml.v6_0.source.mobile.OffRoadMobileEmissionSource;
import nl.overheid.aerius.gml.v6_0.source.road.ADMSRoad;
Expand All @@ -62,7 +62,7 @@ class GML2SourceVisitor<S extends SourceCharacteristics> implements IsGML2Source

GML2SourceVisitor(final GMLConversionData conversionData, final GML2SourceCharacteristics<S> gml2SourceCharacteristics) {
handlers.put(EmissionSource.class, new GML2Generic<EmissionSource>(conversionData));
handlers.put(FarmLodgingEmissionSource.class, new GML2Farm<FarmLodgingEmissionSource>(conversionData));
handlers.put(FarmAnimalHousingEmissionSource.class, new GML2FarmAnimalHousing<FarmAnimalHousingEmissionSource>(conversionData));
handlers.put(FarmlandEmissionSource.class, new GML2Farmland<FarmlandEmissionSource>(conversionData));
handlers.put(ManureStorageEmissionSource.class, new GML2ManureStorage<ManureStorageEmissionSource>(conversionData));
handlers.put(MooringInlandShippingEmissionSource.class, new GML2InlandMooring<MooringInlandShippingEmissionSource>(conversionData));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import nl.overheid.aerius.gml.v6_0.result.SubPoint;
import nl.overheid.aerius.gml.v6_0.source.EmissionSource;
import nl.overheid.aerius.gml.v6_0.source.farmland.FarmlandEmissionSource;
import nl.overheid.aerius.gml.v6_0.source.lodging.FarmLodgingEmissionSource;
import nl.overheid.aerius.gml.v6_0.source.housing.FarmAnimalHousingEmissionSource;
import nl.overheid.aerius.gml.v6_0.source.manure.ManureStorageEmissionSource;
import nl.overheid.aerius.gml.v6_0.source.mobile.OffRoadMobileEmissionSource;
import nl.overheid.aerius.gml.v6_0.source.road.ADMSRoad;
Expand Down Expand Up @@ -69,7 +69,7 @@ public FeatureMemberProperty(final FeatureMemberImpl featureMemberImpl) {
@Override
@XmlElements({
@XmlElement(namespace = CalculatorSchema.NAMESPACE, name = "EmissionSource", type = EmissionSource.class),
@XmlElement(namespace = CalculatorSchema.NAMESPACE, name = "FarmLodgingEmissionSource", type = FarmLodgingEmissionSource.class),
@XmlElement(namespace = CalculatorSchema.NAMESPACE, name = "FarmAnimalHousingSource", type = FarmAnimalHousingEmissionSource.class),
@XmlElement(namespace = CalculatorSchema.NAMESPACE, name = "FarmlandEmissionSource", type = FarmlandEmissionSource.class),
@XmlElement(namespace = CalculatorSchema.NAMESPACE, name = "ManureStorageEmissionSource", type = ManureStorageEmissionSource.class),
@XmlElement(namespace = CalculatorSchema.NAMESPACE, name = "ADMSRoad", type = ADMSRoad.class),
Expand Down
Loading

0 comments on commit 0c25fd9

Please sign in to comment.