diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/base/GMLVersionWriterFactory.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/base/GMLVersionWriterFactory.java index 646e36b2..2b8ff542 100644 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/base/GMLVersionWriterFactory.java +++ b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/base/GMLVersionWriterFactory.java @@ -18,7 +18,6 @@ import javax.xml.validation.Schema; -import nl.overheid.aerius.gml.v5_1.togml.GMLVersionWriterV51; import nl.overheid.aerius.gml.v6_0.togml.GMLVersionWriterV60; import nl.overheid.aerius.shared.domain.geo.HexagonZoomLevel; import nl.overheid.aerius.shared.exception.AeriusException; @@ -32,7 +31,6 @@ private GMLVersionWriterFactory() { public static GMLVersionWriter createGMLVersionWriter(final HexagonZoomLevel zoomLevel1, final String srsName, final AeriusGMLVersion aeriusGMLVersion, final boolean withRepresentation) { return switch (aeriusGMLVersion) { - case V5_1 -> new GMLVersionWriterV51(zoomLevel1, srsName); case V6_0 -> new GMLVersionWriterV60(zoomLevel1, srsName, withRepresentation); default -> throw new IllegalArgumentException("Aerius GML version is not supported"); }; diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Building2GML.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Building2GML.java deleted file mode 100644 index 81339c4a..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Building2GML.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.v5_1.togml; - -import nl.overheid.aerius.gml.base.geo.Geometry2GML; -import nl.overheid.aerius.gml.v5_1.building.Building; -import nl.overheid.aerius.shared.domain.v2.building.BuildingFeature; -import nl.overheid.aerius.shared.exception.AeriusException; - -/** - * - */ -final class Building2GML { - - private final Geometry2GML geometry2gml; - - public Building2GML(final Geometry2GML geometry2gml) { - this.geometry2gml = geometry2gml; - } - - /** - * Convert a Building to a GML object. - * @param building The building to convert to a GML object. - * @return the GML object representing the Building. - * @throws AeriusException when the objects could not be converted to GML correctly. - */ - public Building toGML(final BuildingFeature feature) throws AeriusException { - final Building gmlBuilding = new Building(); - final nl.overheid.aerius.shared.domain.v2.building.Building building = feature.getProperties(); - - gmlBuilding.setGeometry(geometry2gml, feature.getGeometry()); - gmlBuilding.setId(building.getGmlId()); - gmlBuilding.setLabel(building.getLabel()); - gmlBuilding.setHeight(building.getHeight()); - gmlBuilding.setDiameter(building.isCircle() ? building.getDiameter() : null); - - return gmlBuilding; - } - -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/CIMLKDispersionLine2GML.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/CIMLKDispersionLine2GML.java deleted file mode 100644 index f3ccc329..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/CIMLKDispersionLine2GML.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.v5_1.togml; - -import nl.overheid.aerius.gml.base.geo.Geometry2GML; -import nl.overheid.aerius.gml.v5_1.geo.LineString; -import nl.overheid.aerius.gml.v5_1.source.road.SRM1RoadDispersionLine; -import nl.overheid.aerius.shared.domain.v2.cimlk.CIMLKDispersionLine; -import nl.overheid.aerius.shared.domain.v2.cimlk.CIMLKDispersionLineFeature; -import nl.overheid.aerius.shared.exception.AeriusException; -import nl.overheid.aerius.util.gml.GMLIdUtil; - -/** - * - */ -final class CIMLKDispersionLine2GML { - - private final Geometry2GML geometry2gml; - - public CIMLKDispersionLine2GML(final Geometry2GML geometry2gml) { - this.geometry2gml = geometry2gml; - } - - /** - * Convert a CIMLKDispersionLine to a GML object. - * @param dispersionLine The dispersionLine to convert to a GML object. - * @return the GML object representing the CIMLKDispersionLine. - * @throws AeriusException when the objects could not be converted to GML correctly. - */ - public SRM1RoadDispersionLine toGML(final CIMLKDispersionLineFeature dispersionLineFeature) throws AeriusException { - final SRM1RoadDispersionLine gmlDispersionLine = new SRM1RoadDispersionLine(); - final CIMLKDispersionLine dispersionLine = dispersionLineFeature.getProperties(); - final String calculationPointId = GMLIdUtil.toValidGmlId(dispersionLine.getCalculationPointGmlId(), GMLIdUtil.POINT_PREFIX); - final String roadId = GMLIdUtil.toValidGmlId(dispersionLine.getGmlId(), GMLIdUtil.SOURCE_PREFIX); - final String id = "DL." + calculationPointId + "." + roadId; - - gmlDispersionLine.setId(id); - dispersionLine.setGmlId(id); - gmlDispersionLine.setDescription(dispersionLine.getDescription()); - gmlDispersionLine.setLabel(dispersionLine.getLabel()); - gmlDispersionLine.setJurisdictionId(dispersionLine.getJurisdictionId()); - gmlDispersionLine.setRoadProfile(dispersionLine.getRoadProfile()); - gmlDispersionLine.setTreeProfile(dispersionLine.getTreeProfile()); - - gmlDispersionLine.setRoad(ToGMLUtil.toReferenceType(roadId)); - gmlDispersionLine.setCalculationPoint(ToGMLUtil.toReferenceType(calculationPointId)); - - if (dispersionLineFeature.getGeometry() != null) { - gmlDispersionLine.setLineString(geometry2gml.toXMLLineString(dispersionLineFeature.getGeometry(), new LineString())); - } - - return gmlDispersionLine; - } - -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/CIMLKMeasure2GML.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/CIMLKMeasure2GML.java deleted file mode 100644 index 23fa1ad9..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/CIMLKMeasure2GML.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.v5_1.togml; - -import java.util.List; -import java.util.stream.Collectors; - -import nl.overheid.aerius.gml.base.geo.Geometry2GML; -import nl.overheid.aerius.gml.v5_1.measure.EmissionReduction; -import nl.overheid.aerius.gml.v5_1.measure.EmissionReductionProperty; -import nl.overheid.aerius.gml.v5_1.measure.SRM1RoadMeasure; -import nl.overheid.aerius.gml.v5_1.measure.SRM1RoadMeasureArea; -import nl.overheid.aerius.gml.v5_1.measure.SRM1RoadMeasureProperty; -import nl.overheid.aerius.shared.domain.v2.cimlk.CIMLKMeasure; -import nl.overheid.aerius.shared.domain.v2.cimlk.CIMLKMeasureFeature; -import nl.overheid.aerius.shared.domain.v2.source.road.StandardVehicleMeasure; -import nl.overheid.aerius.shared.exception.AeriusException; - -/** - * - */ -final class CIMLKMeasure2GML { - - private final Geometry2GML geometry2gml; - - public CIMLKMeasure2GML(final Geometry2GML geometry2gml) { - this.geometry2gml = geometry2gml; - } - - /** - * Convert a CIMLKMeasure to a GML object. - * @param measure The measure to convert to a GML object. - * @return the GML object representing the CIMLKMeasure. - * @throws AeriusException when the objects could not be converted to GML correctly. - */ - public SRM1RoadMeasureArea toGML(final CIMLKMeasureFeature feature) throws AeriusException { - final SRM1RoadMeasureArea gmlMeasure = new SRM1RoadMeasureArea(); - final CIMLKMeasure measure = feature.getProperties(); - - gmlMeasure.setGeometry(geometry2gml, feature.getGeometry()); - gmlMeasure.setId(measure.getGmlId()); - gmlMeasure.setDescription(measure.getDescription()); - gmlMeasure.setLabel(measure.getLabel()); - gmlMeasure.setJurisdictionId(measure.getJurisdictionId()); - - gmlMeasure.setMeasures(toGML(measure.getVehicleMeasures())); - - return gmlMeasure; - } - - private List toGML(final List vehicleMeasures) { - return vehicleMeasures.stream() - .map(this::toGMLRoadMeasure) - .map(SRM1RoadMeasureProperty::new) - .collect(Collectors.toList()); - } - - private SRM1RoadMeasure toGMLRoadMeasure(final StandardVehicleMeasure vehicleMeasure) { - final SRM1RoadMeasure roadMeasure = new SRM1RoadMeasure(); - roadMeasure.setVehicleType(vehicleMeasure.getVehicleTypeCode()); - roadMeasure.setRoadType(vehicleMeasure.getRoadTypeCode()); - roadMeasure.setReductions(toGMLReductions(vehicleMeasure.getEmissionReductions())); - return roadMeasure; - } - - private List toGMLReductions(final List reductions) { - return reductions.stream() - .map(this::toGMLReduction) - .map(EmissionReductionProperty::new) - .collect(Collectors.toList()); - } - - private EmissionReduction toGMLReduction(final nl.overheid.aerius.shared.domain.v2.base.EmissionReduction measure) { - final EmissionReduction reduction = new EmissionReduction(); - reduction.setSubstance(measure.getSubstance()); - reduction.setFactor(measure.getFactor()); - return reduction; - } - -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Farmland2GML.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Farmland2GML.java deleted file mode 100644 index 76086c6b..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Farmland2GML.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.v5_1.togml; - -import java.util.ArrayList; -import java.util.List; - -import nl.overheid.aerius.gml.v5_1.source.farmland.FarmlandActivityProperty; -import nl.overheid.aerius.shared.domain.Substance; -import nl.overheid.aerius.shared.domain.v2.source.FarmlandEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.farmland.AbstractFarmlandActivity; -import nl.overheid.aerius.shared.domain.v2.source.farmland.CustomFarmlandActivity; -import nl.overheid.aerius.shared.domain.v2.source.farmland.StandardFarmlandActivity; - -/** - * - */ -class Farmland2GML extends SpecificSource2GML { - - private static final Substance FALLBACK_SUBSTANCE = Substance.NH3; - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource convert(final FarmlandEmissionSource emissionSource) { - final nl.overheid.aerius.gml.v5_1.source.farmland.FarmlandEmissionSource returnSource = - new nl.overheid.aerius.gml.v5_1.source.farmland.FarmlandEmissionSource(); - final List landSources = emissionSource.getSubSources(); - final List activities = new ArrayList<>(landSources.size()); - - for (final AbstractFarmlandActivity landSource : landSources) { - if (landSource instanceof CustomFarmlandActivity) { - activities.add(new FarmlandActivityProperty(convert((CustomFarmlandActivity) landSource))); - } else if (landSource instanceof StandardFarmlandActivity) { - activities.add(new FarmlandActivityProperty(convert((StandardFarmlandActivity) landSource))); - } - } - - returnSource.setActivities(activities); - return returnSource; - } - - private nl.overheid.aerius.gml.v5_1.source.farmland.CustomFarmlandActivity convert(final CustomFarmlandActivity landSource) { - final nl.overheid.aerius.gml.v5_1.source.farmland.CustomFarmlandActivity gmlLandSource = - new nl.overheid.aerius.gml.v5_1.source.farmland.CustomFarmlandActivity(); - gmlLandSource.setCode(landSource.getActivityCode()); - gmlLandSource.setEmissions(getEmissions(landSource.getEmissions(), FALLBACK_SUBSTANCE)); - return gmlLandSource; - } - - private nl.overheid.aerius.gml.v5_1.source.farmland.StandardFarmlandActivity convert(final StandardFarmlandActivity landSource) { - final nl.overheid.aerius.gml.v5_1.source.farmland.StandardFarmlandActivity gmlLandSource = - new nl.overheid.aerius.gml.v5_1.source.farmland.StandardFarmlandActivity(); - gmlLandSource.setCode(landSource.getActivityCode()); - gmlLandSource.setStandardActivityCode(landSource.getFarmSourceCategoryCode()); - gmlLandSource.setNumberOfAnimals(landSource.getNumberOfAnimals()); - gmlLandSource.setNumberOfDays(landSource.getNumberOfDays()); - gmlLandSource.setTonnes(landSource.getTonnes()); - gmlLandSource.setMetersCubed(landSource.getMetersCubed()); - gmlLandSource.setNumberOfApplications(landSource.getNumberOfApplications()); - return gmlLandSource; - } - -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/GMLVersionWriterV51.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/GMLVersionWriterV51.java deleted file mode 100644 index 47aefd42..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/GMLVersionWriterV51.java +++ /dev/null @@ -1,318 +0,0 @@ -/* - * 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.v5_1.togml; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import nl.overheid.aerius.gml.base.AeriusGMLVersion; -import nl.overheid.aerius.gml.base.Definitions; -import nl.overheid.aerius.gml.base.FeatureMember; -import nl.overheid.aerius.gml.base.GMLVersionWriter; -import nl.overheid.aerius.gml.base.MetaData; -import nl.overheid.aerius.gml.base.MetaDataInput; -import nl.overheid.aerius.gml.base.OtherSituationMetaData; -import nl.overheid.aerius.gml.base.StringUtils; -import nl.overheid.aerius.gml.base.geo.Geometry2GML; -import nl.overheid.aerius.gml.base.metadata.LegacySituationType; -import nl.overheid.aerius.gml.v5_1.base.CalculatorSchema; -import nl.overheid.aerius.gml.v5_1.collection.FeatureCollectionImpl; -import nl.overheid.aerius.gml.v5_1.definitions.CustomDiurnalVariation; -import nl.overheid.aerius.gml.v5_1.definitions.DefinitionsImpl; -import nl.overheid.aerius.gml.v5_1.metadata.AddressImpl; -import nl.overheid.aerius.gml.v5_1.metadata.ArchiveMetadata; -import nl.overheid.aerius.gml.v5_1.metadata.CalculationMetadata; -import nl.overheid.aerius.gml.v5_1.metadata.CalculationOption; -import nl.overheid.aerius.gml.v5_1.metadata.CalculationOptionProperty; -import nl.overheid.aerius.gml.v5_1.metadata.MetaDataImpl; -import nl.overheid.aerius.gml.v5_1.metadata.OtherSituationMetadata; -import nl.overheid.aerius.gml.v5_1.metadata.OtherSituationMetadataProperty; -import nl.overheid.aerius.gml.v5_1.metadata.ProjectMetadata; -import nl.overheid.aerius.gml.v5_1.metadata.SituationMetadata; -import nl.overheid.aerius.gml.v5_1.metadata.VersionMetadata; -import nl.overheid.aerius.shared.domain.Substance; -import nl.overheid.aerius.shared.domain.Theme; -import nl.overheid.aerius.shared.domain.calculation.CalculationSetOptions; -import nl.overheid.aerius.shared.domain.geo.HexagonZoomLevel; -import nl.overheid.aerius.shared.domain.result.EmissionResultKey; -import nl.overheid.aerius.shared.domain.result.EmissionResultType; -import nl.overheid.aerius.shared.domain.v2.archive.ArchiveProject; -import nl.overheid.aerius.shared.domain.v2.building.BuildingFeature; -import nl.overheid.aerius.shared.domain.v2.cimlk.CIMLKCorrection; -import nl.overheid.aerius.shared.domain.v2.cimlk.CIMLKDispersionLineFeature; -import nl.overheid.aerius.shared.domain.v2.cimlk.CIMLKMeasureFeature; -import nl.overheid.aerius.shared.domain.v2.point.CalculationPointFeature; -import nl.overheid.aerius.shared.domain.v2.scenario.ScenarioMetaData; -import nl.overheid.aerius.shared.domain.v2.source.EmissionSourceFeature; -import nl.overheid.aerius.shared.exception.AeriusException; -import nl.overheid.aerius.shared.exception.ImaerExceptionReason; -import nl.overheid.aerius.util.OptionsMetadataUtil; -import nl.overheid.aerius.util.gml.GMLIdUtil; - -/** - * GML proxy for version 5.1. - */ -public class GMLVersionWriterV51 implements GMLVersionWriter { - - private final Source2GML source2gml; - private final Building2GML building2gml; - private final Result2GML result2gml; - private final CIMLKMeasure2GML measure2gml; - private final CIMLKDispersionLine2GML dispersionLine2gml; - - public GMLVersionWriterV51(final HexagonZoomLevel zoomLevel1, final String srsName) { - final Geometry2GML geometry2gml = new Geometry2GML(srsName); - source2gml = new Source2GML(geometry2gml); - building2gml = new Building2GML(geometry2gml); - result2gml = new Result2GML(geometry2gml, zoomLevel1); - measure2gml = new CIMLKMeasure2GML(geometry2gml); - dispersionLine2gml = new CIMLKDispersionLine2GML(geometry2gml); - } - - @Override - public AeriusGMLVersion getGMLVersion() { - return AeriusGMLVersion.V5_1; - } - - @Override - public String getNameSpace() { - return CalculatorSchema.NAMESPACE; - } - - @Override - public String getPublicSchemaLocation() { - return CalculatorSchema.PUBLIC_SCHEMA_LOCATION; - } - - @Override - public FeatureCollectionImpl createFeatureCollection() { - return new FeatureCollectionImpl(); - } - - @Override - public MetaData metaData2GML(final MetaDataInput metaDataInput) throws AeriusException { - final MetaDataImpl metaDataImpl = new MetaDataImpl(); - metaDataImpl.setSituation(getSituation(metaDataInput)); - metaDataImpl.setCalculation(getCalculation(metaDataInput)); - metaDataImpl.setProject(getProject(metaDataInput)); - metaDataImpl.setVersion(getVersion(metaDataInput)); - metaDataImpl.setArchive(getArchive(metaDataInput)); - return metaDataImpl; - } - - private static SituationMetadata getSituation(final MetaDataInput input) throws AeriusException { - final SituationMetadata situation; - if (isEmptySituationData(input)) { - situation = null; - } else { - ensureSituationType(input); - situation = new SituationMetadata(); - situation.setName(input.getName()); - situation.setReference(input.getReference()); - situation.setSituationType(LegacySituationType.safeValueOf(input.getSituationType() != null ? input.getSituationType().name() : null)); - situation.setNettingFactor(input.getNettingFactor()); - } - return situation; - } - - private static ProjectMetadata getProject(final MetaDataInput input) { - final ProjectMetadata project = new ProjectMetadata(); - project.setYear(input.getYear()); - - setScenarioMetaData(project, input.getScenarioMetaData()); - return project; - } - - private static void setScenarioMetaData(final ProjectMetadata project, final ScenarioMetaData scenarioData) { - if (scenarioData != null) { - project.setName(scenarioData.getProjectName()); - project.setCorporation(scenarioData.getCorporation()); - project.setDescription(scenarioData.getDescription()); - if (hasValidAddress(scenarioData)) { - final AddressImpl address = new AddressImpl(); - project.setFacilityLocation(address); - address.setStreetAddress(scenarioData.getStreetAddress()); - address.setPostcode(scenarioData.getPostcode()); - address.setCity(scenarioData.getCity()); - } - } - } - - private static boolean isEmptySituationData(final MetaDataInput input) { - return StringUtils.isEmpty(input.getName()) && StringUtils.isEmpty(input.getReference()) - && input.getSituationType() == null; - } - - private static void ensureSituationType(final MetaDataInput input) throws AeriusException { - // Sanity check on situation type. It should be set when writing, - // but older files are read without a default, - // since there is no obvious default without knowledge about the file containing the GML. - if (input.getSituationType() == null) { - // situation type wasn't available in metadata, which will generate GML which is invalid according to XSD. - throw new AeriusException(ImaerExceptionReason.INTERNAL_ERROR); - } - } - - private static boolean hasValidAddress(final ScenarioMetaData scenarioData) { - return !StringUtils.isEmpty(scenarioData.getStreetAddress()) && !StringUtils.isEmpty(scenarioData.getPostcode()) - && !StringUtils.isEmpty(scenarioData.getCity()); - } - - private static CalculationMetadata getCalculation(final MetaDataInput input) { - final CalculationMetadata calculation; - if (input.isResultsIncluded()) { - calculation = new CalculationMetadata(); - calculation.setCalculationMethod(input.getOptions().getCalculationMethod()); - calculation.setCalculationJobType(input.getOptions().getCalculationJobType()); - if (input.getOptions().isMaximumRangeRelevant()) { - calculation.setMaximumRange(input.getOptions().getCalculateMaximumRange()); - } - calculation.setSubstances(input.getOptions().getSubstances()); - calculation.setResultTypes(determineResultTypes(input.getOptions().getEmissionResultKeys())); - calculation.setOptions(options2GML(input.getTheme(), input.getOptions())); - calculation.setOtherSituations(otherSituations2GML(input.getOtherSituations())); - } else { - calculation = null; - } - return calculation; - } - - private static VersionMetadata getVersion(final MetaDataInput input) { - final VersionMetadata version = new VersionMetadata(); - version.setAeriusVersion(input.getVersion()); - version.setDatabaseVersion(input.getDatabaseVersion()); - return version; - } - - private static ArchiveMetadata getArchive(final MetaDataInput input) { - final ArchiveMetadata archive; - if (input.getArchiveMetaData() == null) { - archive = null; - } else { - archive = new ArchiveMetadata(); - archive.setRetrievalDateTime(input.getArchiveMetaData().getRetrievalDateTime()); - archive.setArchiveProjects(archiveProjects2GML(input.getArchiveMetaData().getArchiveProjects())); - } - return archive; - } - - private static List archiveProjects2GML(final List archveProjects) { - return archveProjects.stream() - .map(GMLVersionWriterV51::archiveProject2GML) - .toList(); - } - - private static nl.overheid.aerius.gml.v5_1.metadata.ArchiveProject archiveProject2GML(final ArchiveProject archiveProject) { - final nl.overheid.aerius.gml.v5_1.metadata.ArchiveProject gmlArchiveProject = new nl.overheid.aerius.gml.v5_1.metadata.ArchiveProject(); - gmlArchiveProject.setId(archiveProject.getId()); - gmlArchiveProject.setName(archiveProject.getName()); - gmlArchiveProject.setAeriusVersion(archiveProject.getAeriusVersion()); - return gmlArchiveProject; - } - - private static List determineResultTypes(final Set keys) { - final List types = new ArrayList<>(); - for (final EmissionResultKey key : keys) { - if (!types.contains(key.getEmissionResultType())) { - types.add(key.getEmissionResultType()); - } - } - return types.stream().sorted().toList(); - } - - private static List options2GML(final Theme theme, final CalculationSetOptions options) { - final Map gmlOptionsMap = OptionsMetadataUtil.optionsToMap(theme, options, false); - return gmlOptionsMap.entrySet().stream() - .map(entry -> new CalculationOption(entry.getKey(), entry.getValue())) - .map(CalculationOptionProperty::new) - .toList(); - } - - private static List otherSituations2GML(final List otherSituations) { - return otherSituations.stream() - .map(GMLVersionWriterV51::otherSituation2GML) - .map(OtherSituationMetadataProperty::new) - .toList(); - } - - private static OtherSituationMetadata otherSituation2GML(final OtherSituationMetaData otherSituation) { - final OtherSituationMetadata gmlOtherSituation = new OtherSituationMetadata(); - gmlOtherSituation.setSituationType(otherSituation.getSituationType()); - gmlOtherSituation.setName(otherSituation.getName()); - gmlOtherSituation.setReference(otherSituation.getReference()); - return gmlOtherSituation; - } - - @Override - public Definitions definitions2GML(final nl.overheid.aerius.shared.domain.v2.scenario.Definitions definitions) throws AeriusException { - final DefinitionsImpl gmlDefinitions; - if (definitions != null && definitions.hasContent()) { - gmlDefinitions = new DefinitionsImpl(); - final List customDiurnalVariations = definitions.getCustomTimeVaryingProfiles().stream() - .map(this::convert) - .toList(); - gmlDefinitions.setCustomDiurnalVariations(customDiurnalVariations); - } else { - gmlDefinitions = null; - } - return gmlDefinitions; - } - - private CustomDiurnalVariation convert(final nl.overheid.aerius.shared.domain.v2.characteristics.CustomTimeVaryingProfile customVariation) { - final CustomDiurnalVariation gmlCustomVariation = new CustomDiurnalVariation(); - final String validGmlId = GMLIdUtil.toValidGmlId(customVariation.getGmlId(), getNameSpace(), GMLIdUtil.DIURNAL_VARIATION_PREFIX); - gmlCustomVariation.setId(validGmlId); - gmlCustomVariation.setLabel(customVariation.getLabel()); - gmlCustomVariation.setCustomType(customVariation.getType().name()); - gmlCustomVariation.setValues(customVariation.getValues()); - return gmlCustomVariation; - } - - @Override - public FeatureMember result2GML(final CalculationPointFeature point, final Substance[] substances, final List corrections) - throws AeriusException { - return result2gml.toGML(point, substances, corrections); - } - - @Override - public List source2GML(final EmissionSourceFeature source, final Substance[] substances) throws AeriusException { - return source2gml.toGML(source, substances); - } - - @Override - public FeatureMember cimlkMeasure2GML(final CIMLKMeasureFeature measure) throws AeriusException { - return measure2gml.toGML(measure); - } - - @Override - public FeatureMember cimlkDispersionLine2GML(final CIMLKDispersionLineFeature dispersionLine) throws AeriusException { - return dispersionLine2gml.toGML(dispersionLine); - } - - @Override - public Object cimlkCorrection2GML(final CIMLKCorrection correction) throws AeriusException { - return result2gml.toGMLCorrection(correction); - } - - @Override - public FeatureMember building2GML(final BuildingFeature building) throws AeriusException { - return building2gml.toGML(building); - } - -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Inland2GMLUtil.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Inland2GMLUtil.java deleted file mode 100644 index d27daf20..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Inland2GMLUtil.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.v5_1.togml; - -import nl.overheid.aerius.gml.v5_1.source.ship.CustomInlandShippingEmissionPropertiesProperty; -import nl.overheid.aerius.gml.v5_1.source.ship.InlandWaterway; -import nl.overheid.aerius.gml.v5_1.source.ship.InlandWaterwayProperty; -import nl.overheid.aerius.shared.domain.Substance; -import nl.overheid.aerius.shared.domain.v2.source.shipping.inland.CustomInlandShippingEmissionProperties; -import nl.overheid.aerius.shared.domain.v2.source.shipping.inland.WaterwayDirection; -import nl.overheid.aerius.shared.exception.AeriusException; -import nl.overheid.aerius.shared.exception.ImaerExceptionReason; - -/** - * - */ -final class Inland2GMLUtil { - - private Inland2GMLUtil() { - //util class. - } - - static InlandWaterwayProperty getWaterway(final nl.overheid.aerius.shared.domain.v2.source.shipping.inland.InlandWaterway waterwayType, - final String sourceId) throws AeriusException { - if (waterwayType == null || waterwayType.getWaterwayCode() == null) { - throw new AeriusException(ImaerExceptionReason.GML_INLAND_WATERWAY_NOT_SET, sourceId); - } else { - final InlandWaterway waterway = new InlandWaterway(); - waterway.setType(waterwayType.getWaterwayCode()); - waterway.setDirection(waterwayType.getDirection() == WaterwayDirection.IRRELEVANT ? null : waterwayType.getDirection()); - return new InlandWaterwayProperty(waterway); - } - } - - static CustomInlandShippingEmissionPropertiesProperty toCustomEmissionProperties(final CustomInlandShippingEmissionProperties originalProperties) { - final nl.overheid.aerius.gml.v5_1.source.ship.CustomInlandShippingEmissionProperties properties = new nl.overheid.aerius.gml.v5_1.source.ship.CustomInlandShippingEmissionProperties(); - properties.setEmissionFactorsEmpty(SpecificSource2GML.getEmissions(originalProperties.getEmissionFactorsEmpty(), Substance.NOX)); - properties.setEmissionFactorsLaden(SpecificSource2GML.getEmissions(originalProperties.getEmissionFactorsLaden(), Substance.NOX)); - properties.setHeatContentEmpty(originalProperties.getHeatContentEmpty()); - properties.setHeatContentLaden(originalProperties.getHeatContentLaden()); - properties.setEmissionHeightEmpty(originalProperties.getEmissionHeightEmpty()); - properties.setEmissionHeightLaden(originalProperties.getEmissionHeightLaden()); - return new CustomInlandShippingEmissionPropertiesProperty(properties); - } -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/InlandMooring2GML.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/InlandMooring2GML.java deleted file mode 100644 index 2f9a344e..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/InlandMooring2GML.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.v5_1.togml; - -import java.util.ArrayList; -import java.util.List; - -import nl.overheid.aerius.gml.v5_1.source.TimeUnit; -import nl.overheid.aerius.gml.v5_1.source.ship.MooringInlandShippingProperty; -import nl.overheid.aerius.shared.domain.v2.source.MooringInlandShippingEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.shipping.inland.CustomMooringInlandShipping; -import nl.overheid.aerius.shared.domain.v2.source.shipping.inland.MooringInlandShipping; -import nl.overheid.aerius.shared.domain.v2.source.shipping.inland.StandardMooringInlandShipping; -import nl.overheid.aerius.shared.exception.AeriusException; - -/** - * - */ -class InlandMooring2GML extends SpecificSource2GML { - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource convert(final MooringInlandShippingEmissionSource emissionSource) - throws AeriusException { - final nl.overheid.aerius.gml.v5_1.source.ship.MooringInlandShippingEmissionSource returnSource = new nl.overheid.aerius.gml.v5_1.source.ship.MooringInlandShippingEmissionSource(); - final List vesselGroups = emissionSource.getSubSources(); - final List mooringMaritimeShippings = new ArrayList<>(vesselGroups.size()); - - for (final MooringInlandShipping vesselGroup : vesselGroups) { - final nl.overheid.aerius.gml.v5_1.source.ship.MooringInlandShipping gmlShip = determineType(vesselGroup); - gmlShip.setDescription(vesselGroup.getDescription()); - gmlShip.setAverageResidenceTime(vesselGroup.getAverageResidenceTime()); - gmlShip.setShorePowerFactor(vesselGroup.getShorePowerFactor()); - gmlShip.setShipsPerTimeUnit(vesselGroup.getShipsPerTimeUnit()); - gmlShip.setTimeUnit(TimeUnit.from(vesselGroup.getTimeUnit())); - gmlShip.setPercentageLaden(vesselGroup.getPercentageLaden()); - //we're not adding emissionfactor/description to avoid impression that it will be used on import. - mooringMaritimeShippings.add(new MooringInlandShippingProperty(gmlShip)); - } - returnSource.setShips(mooringMaritimeShippings); - return returnSource; - } - - private nl.overheid.aerius.gml.v5_1.source.ship.MooringInlandShipping determineType(final MooringInlandShipping inlandShipping) { - nl.overheid.aerius.gml.v5_1.source.ship.MooringInlandShipping gmlInlandShipping; - if (inlandShipping instanceof StandardMooringInlandShipping) { - gmlInlandShipping = toStandard((StandardMooringInlandShipping) inlandShipping); - } else if (inlandShipping instanceof CustomMooringInlandShipping) { - gmlInlandShipping = toCustom((CustomMooringInlandShipping) inlandShipping); - } else { - throw new IllegalArgumentException("Unknown inland shipping type: " + inlandShipping); - } - return gmlInlandShipping; - } - - private nl.overheid.aerius.gml.v5_1.source.ship.MooringInlandShipping toStandard(final StandardMooringInlandShipping vesselGroup) { - final nl.overheid.aerius.gml.v5_1.source.ship.StandardMooringInlandShipping gmlShip = new nl.overheid.aerius.gml.v5_1.source.ship.StandardMooringInlandShipping(); - gmlShip.setCode(vesselGroup.getShipCode()); - return gmlShip; - } - - private nl.overheid.aerius.gml.v5_1.source.ship.MooringInlandShipping toCustom(final CustomMooringInlandShipping vesselGroup) { - final nl.overheid.aerius.gml.v5_1.source.ship.CustomMooringInlandShipping gmlShip = new nl.overheid.aerius.gml.v5_1.source.ship.CustomMooringInlandShipping(); - gmlShip.setEmissionProperties(Inland2GMLUtil.toCustomEmissionProperties(vesselGroup.getEmissionProperties())); - return gmlShip; - } - -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/InlandRoute2GML.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/InlandRoute2GML.java deleted file mode 100644 index 19c23636..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/InlandRoute2GML.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.v5_1.togml; - -import java.util.ArrayList; -import java.util.List; - -import nl.overheid.aerius.gml.v5_1.base.ReferenceType; -import nl.overheid.aerius.gml.v5_1.source.TimeUnit; -import nl.overheid.aerius.gml.v5_1.source.ship.InlandShippingProperty; -import nl.overheid.aerius.shared.domain.v2.source.InlandShippingEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.shipping.inland.CustomInlandShipping; -import nl.overheid.aerius.shared.domain.v2.source.shipping.inland.InlandShipping; -import nl.overheid.aerius.shared.domain.v2.source.shipping.inland.StandardInlandShipping; -import nl.overheid.aerius.shared.exception.AeriusException; -import nl.overheid.aerius.util.gml.GMLIdUtil; - -/** - * - */ -class InlandRoute2GML extends SpecificSource2GML { - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource convert(final InlandShippingEmissionSource emissionSource) throws AeriusException { - final nl.overheid.aerius.gml.v5_1.source.ship.InlandShippingEmissionSource returnSource = - new nl.overheid.aerius.gml.v5_1.source.ship.InlandShippingEmissionSource(); - final List vesselGroups = emissionSource.getSubSources(); - final List ships = new ArrayList<>(vesselGroups.size()); - - for (final InlandShipping vesselGroupEmissionValues : vesselGroups) { - final nl.overheid.aerius.gml.v5_1.source.ship.InlandShipping gmlShip = determineType(vesselGroupEmissionValues); - gmlShip.setDescription(vesselGroupEmissionValues.getDescription()); - gmlShip.setNumberOfShipsAtoBperTimeUnit(vesselGroupEmissionValues.getMovementsAtoBPerTimeUnit()); - gmlShip.setNumberOfShipsBtoAperTimeUnit(vesselGroupEmissionValues.getMovementsBtoAPerTimeUnit()); - gmlShip.setTimeUnitShipsAtoB(TimeUnit.from(vesselGroupEmissionValues.getTimeUnitAtoB())); - gmlShip.setTimeUnitShipsBtoA(TimeUnit.from(vesselGroupEmissionValues.getTimeUnitBtoA())); - gmlShip.setPercentageLadenAtoB(vesselGroupEmissionValues.getPercentageLadenAtoB()); - gmlShip.setPercentageLadenBtoA(vesselGroupEmissionValues.getPercentageLadenBtoA()); - //we're not adding emissionfactor/description to avoid impression that it will be used on import. - ships.add(new InlandShippingProperty(gmlShip)); - } - - returnSource.setInlandWaterwayProperty(Inland2GMLUtil.getWaterway(emissionSource.getWaterway(), emissionSource.getGmlId())); - - returnSource.setMooringA(toReferenceType(emissionSource.getMooringAId())); - returnSource.setMooringB(toReferenceType(emissionSource.getMooringBId())); - - returnSource.setInlandShippings(ships); - return returnSource; - } - - private nl.overheid.aerius.gml.v5_1.source.ship.InlandShipping determineType(final InlandShipping inlandShipping) { - nl.overheid.aerius.gml.v5_1.source.ship.InlandShipping gmlInlandShipping; - if (inlandShipping instanceof StandardInlandShipping) { - gmlInlandShipping = toStandard((StandardInlandShipping) inlandShipping); - } else if (inlandShipping instanceof CustomInlandShipping) { - gmlInlandShipping = toCustom((CustomInlandShipping) inlandShipping); - } else { - throw new IllegalArgumentException("Unknown inland shipping type: " + inlandShipping); - } - return gmlInlandShipping; - } - - private nl.overheid.aerius.gml.v5_1.source.ship.InlandShipping toStandard(final StandardInlandShipping inlandShipping) { - final nl.overheid.aerius.gml.v5_1.source.ship.StandardInlandShipping gmlShip = - new nl.overheid.aerius.gml.v5_1.source.ship.StandardInlandShipping(); - gmlShip.setCode(inlandShipping.getShipCode()); - return gmlShip; - } - - private nl.overheid.aerius.gml.v5_1.source.ship.InlandShipping toCustom(final CustomInlandShipping inlandShipping) { - final nl.overheid.aerius.gml.v5_1.source.ship.CustomInlandShipping gmlShip = new nl.overheid.aerius.gml.v5_1.source.ship.CustomInlandShipping(); - gmlShip.setEmissionPropertiesAtoB(Inland2GMLUtil.toCustomEmissionProperties(inlandShipping.getEmissionPropertiesAtoB())); - gmlShip.setEmissionPropertiesBtoA(Inland2GMLUtil.toCustomEmissionProperties(inlandShipping.getEmissionPropertiesBtoA())); - return gmlShip; - } - - private ReferenceType toReferenceType(final String id) { - return ToGMLUtil.toReferenceType(id, GMLIdUtil.SOURCE_PREFIX); - } - -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/ManureStorage2GML.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/ManureStorage2GML.java deleted file mode 100644 index 7b149891..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/ManureStorage2GML.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Crown copyright - * - * 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.v5_1.togml; - -import java.util.ArrayList; -import java.util.List; - -import nl.overheid.aerius.gml.v5_1.source.manure.ManureStorageProperty; -import nl.overheid.aerius.shared.domain.Substance; -import nl.overheid.aerius.shared.domain.v2.source.ManureStorageEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.manure.AbstractManureStorage; -import nl.overheid.aerius.shared.domain.v2.source.manure.CustomManureStorage; -import nl.overheid.aerius.shared.domain.v2.source.manure.StandardManureStorage; - -/** - * - */ -class ManureStorage2GML extends SpecificSource2GML { - - private static final Substance FALLBACK_SUBSTANCE = Substance.NH3; - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource convert(final ManureStorageEmissionSource emissionSource) { - final nl.overheid.aerius.gml.v5_1.source.manure.ManureStorageEmissionSource returnSource = - new nl.overheid.aerius.gml.v5_1.source.manure.ManureStorageEmissionSource(); - final List manureStorages = emissionSource.getSubSources(); - final List manureStorageProperties = new ArrayList<>(manureStorages.size()); - - for (final AbstractManureStorage manureStorage : manureStorages) { - if (manureStorage instanceof CustomManureStorage) { - manureStorageProperties.add(new ManureStorageProperty(convert((CustomManureStorage) manureStorage))); - } else if (manureStorage instanceof StandardManureStorage) { - manureStorageProperties.add(new ManureStorageProperty(convert((StandardManureStorage) manureStorage))); - } - } - - returnSource.setManureStorages(manureStorageProperties); - return returnSource; - } - - private nl.overheid.aerius.gml.v5_1.source.manure.CustomManureStorage convert(final CustomManureStorage storage) { - final nl.overheid.aerius.gml.v5_1.source.manure.CustomManureStorage gmlStorage = - new nl.overheid.aerius.gml.v5_1.source.manure.CustomManureStorage(); - gmlStorage.setDescription(storage.getDescription()); - gmlStorage.setAnimalCode(storage.getAnimalCode()); - gmlStorage.setEmissionFactorType(storage.getFarmEmissionFactorType().name()); - gmlStorage.setEmissionFactors(getEmissions(storage.getEmissionFactors(), FALLBACK_SUBSTANCE)); - setBasicProperties(storage, gmlStorage); - return gmlStorage; - } - - private nl.overheid.aerius.gml.v5_1.source.manure.StandardManureStorage convert(final StandardManureStorage storage) { - final nl.overheid.aerius.gml.v5_1.source.manure.StandardManureStorage gmlStorage = - new nl.overheid.aerius.gml.v5_1.source.manure.StandardManureStorage(); - gmlStorage.setManureStorageCode(storage.getManureStorageCode()); - setBasicProperties(storage, gmlStorage); - return gmlStorage; - } - - private void setBasicProperties(final AbstractManureStorage storage, - final nl.overheid.aerius.gml.v5_1.source.manure.AbstractManureStorage gmlStorage) { - gmlStorage.setTonnes(storage.getTonnes()); - gmlStorage.setMetersSquared(storage.getMetersSquared()); - gmlStorage.setNumberOfDays(storage.getNumberOfDays()); - } - -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Maritime2GMLUtil.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Maritime2GMLUtil.java deleted file mode 100644 index f7e744ad..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Maritime2GMLUtil.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.v5_1.togml; - -import nl.overheid.aerius.gml.v5_1.source.ship.CustomMaritimeShippingEmissionPropertiesProperty; -import nl.overheid.aerius.shared.domain.Substance; -import nl.overheid.aerius.shared.domain.v2.source.shipping.maritime.CustomMaritimeShippingEmissionProperties; - -/** - * - */ -final class Maritime2GMLUtil { - - private Maritime2GMLUtil() { - //util class. - } - - static CustomMaritimeShippingEmissionPropertiesProperty toCustomEmissionProperties( - final CustomMaritimeShippingEmissionProperties customProperties) { - final nl.overheid.aerius.gml.v5_1.source.ship.CustomMaritimeShippingEmissionProperties gmlProperties = new nl.overheid.aerius.gml.v5_1.source.ship.CustomMaritimeShippingEmissionProperties(); - gmlProperties.setEmissionFactors(SpecificSource2GML.getEmissions(customProperties.getEmissionFactors(), Substance.NOX)); - gmlProperties.setHeatContent(customProperties.getHeatContent()); - gmlProperties.setEmissionHeight(customProperties.getEmissionHeight()); - return new CustomMaritimeShippingEmissionPropertiesProperty(gmlProperties); - } -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/MaritimeMooring2GML.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/MaritimeMooring2GML.java deleted file mode 100644 index bfb54aca..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/MaritimeMooring2GML.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.v5_1.togml; - -import java.util.ArrayList; -import java.util.List; - -import nl.overheid.aerius.gml.v5_1.source.TimeUnit; -import nl.overheid.aerius.gml.v5_1.source.ship.MooringMaritimeShippingProperty; -import nl.overheid.aerius.shared.domain.v2.source.MooringMaritimeShippingEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.shipping.maritime.CustomMooringMaritimeShipping; -import nl.overheid.aerius.shared.domain.v2.source.shipping.maritime.MooringMaritimeShipping; -import nl.overheid.aerius.shared.domain.v2.source.shipping.maritime.StandardMooringMaritimeShipping; -import nl.overheid.aerius.shared.exception.AeriusException; - -/** - * - */ -class MaritimeMooring2GML extends SpecificSource2GML { - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource convert(final MooringMaritimeShippingEmissionSource emissionSource) - throws AeriusException { - final nl.overheid.aerius.gml.v5_1.source.ship.MooringMaritimeShippingEmissionSource returnSource = new nl.overheid.aerius.gml.v5_1.source.ship.MooringMaritimeShippingEmissionSource(); - final List vesselGroups = emissionSource.getSubSources(); - final List mooringMaritimeShippings = new ArrayList<>(vesselGroups.size()); - - for (final MooringMaritimeShipping vesselGroup : vesselGroups) { - final nl.overheid.aerius.gml.v5_1.source.ship.MooringMaritimeShipping gmlShip = determineType(vesselGroup); - gmlShip.setDescription(vesselGroup.getDescription()); - gmlShip.setAverageResidenceTime(vesselGroup.getAverageResidenceTime()); - gmlShip.setShorePowerFactor(vesselGroup.getShorePowerFactor()); - gmlShip.setShipsPerTimeUnit(vesselGroup.getShipsPerTimeUnit()); - gmlShip.setTimeUnit(TimeUnit.from(vesselGroup.getTimeUnit())); - //we're not adding emissionfactor/description to avoid impression that it will be used on import. - mooringMaritimeShippings.add(new MooringMaritimeShippingProperty(gmlShip)); - } - returnSource.setShips(mooringMaritimeShippings); - return returnSource; - } - - private nl.overheid.aerius.gml.v5_1.source.ship.MooringMaritimeShipping determineType(final MooringMaritimeShipping maritimeShipping) { - nl.overheid.aerius.gml.v5_1.source.ship.MooringMaritimeShipping gmlMaritimeShipping; - if (maritimeShipping instanceof StandardMooringMaritimeShipping) { - gmlMaritimeShipping = toStandard((StandardMooringMaritimeShipping) maritimeShipping); - } else if (maritimeShipping instanceof CustomMooringMaritimeShipping) { - gmlMaritimeShipping = toCustom((CustomMooringMaritimeShipping) maritimeShipping); - } else { - throw new IllegalArgumentException("Unknown inland shipping type: " + maritimeShipping); - } - return gmlMaritimeShipping; - } - - private nl.overheid.aerius.gml.v5_1.source.ship.MooringMaritimeShipping toStandard(final StandardMooringMaritimeShipping vesselGroup) { - final nl.overheid.aerius.gml.v5_1.source.ship.StandardMooringMaritimeShipping gmlShip = new nl.overheid.aerius.gml.v5_1.source.ship.StandardMooringMaritimeShipping(); - gmlShip.setCode(vesselGroup.getShipCode()); - return gmlShip; - } - - private nl.overheid.aerius.gml.v5_1.source.ship.MooringMaritimeShipping toCustom(final CustomMooringMaritimeShipping maritimeShipping) { - final nl.overheid.aerius.gml.v5_1.source.ship.CustomMooringMaritimeShipping gmlShip = new nl.overheid.aerius.gml.v5_1.source.ship.CustomMooringMaritimeShipping(); - gmlShip.setEmissionProperties(Maritime2GMLUtil.toCustomEmissionProperties(maritimeShipping.getEmissionProperties())); - return gmlShip; - } - -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/MaritimeRoute2GML.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/MaritimeRoute2GML.java deleted file mode 100644 index c749e018..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/MaritimeRoute2GML.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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.v5_1.togml; - -import java.util.ArrayList; -import java.util.List; - -import nl.overheid.aerius.gml.v5_1.base.ReferenceType; -import nl.overheid.aerius.gml.v5_1.source.TimeUnit; -import nl.overheid.aerius.gml.v5_1.source.ship.MaritimeShippingProperty; -import nl.overheid.aerius.shared.domain.v2.source.MaritimeShippingEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.shipping.maritime.CustomMaritimeShipping; -import nl.overheid.aerius.shared.domain.v2.source.shipping.maritime.MaritimeShipping; -import nl.overheid.aerius.shared.domain.v2.source.shipping.maritime.StandardMaritimeShipping; -import nl.overheid.aerius.util.gml.GMLIdUtil; - -/** - * - */ -class MaritimeRoute2GML extends SpecificSource2GML { - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource convert(final MaritimeShippingEmissionSource emissionSource) { - final nl.overheid.aerius.gml.v5_1.source.ship.MaritimeShippingEmissionSource returnSource = new nl.overheid.aerius.gml.v5_1.source.ship.MaritimeShippingEmissionSource(); - final List vesselGroups = emissionSource.getSubSources(); - final List maritimeShippings = new ArrayList<>(vesselGroups.size()); - - for (final MaritimeShipping vesselGroup : vesselGroups) { - final nl.overheid.aerius.gml.v5_1.source.ship.MaritimeShipping gmlShip = determineType(vesselGroup); - gmlShip.setShipsPerTimeUnit(vesselGroup.getMovementsPerTimeUnit()); - gmlShip.setTimeUnit(TimeUnit.from(vesselGroup.getTimeUnit())); - gmlShip.setDescription(vesselGroup.getDescription()); - maritimeShippings.add(new MaritimeShippingProperty(gmlShip)); - } - returnSource.setMovementType(emissionSource.getMovementType()); - returnSource.setMaritimeShippings(maritimeShippings); - returnSource.setMooringA(toReferenceType(emissionSource.getMooringAId())); - returnSource.setMooringB(toReferenceType(emissionSource.getMooringBId())); - return returnSource; - } - - private nl.overheid.aerius.gml.v5_1.source.ship.MaritimeShipping determineType(final MaritimeShipping maritimeShipping) { - nl.overheid.aerius.gml.v5_1.source.ship.MaritimeShipping gmlMaritimeShipping; - if (maritimeShipping instanceof StandardMaritimeShipping) { - gmlMaritimeShipping = toStandard((StandardMaritimeShipping) maritimeShipping); - } else if (maritimeShipping instanceof CustomMaritimeShipping) { - gmlMaritimeShipping = toCustom((CustomMaritimeShipping) maritimeShipping); - } else { - throw new IllegalArgumentException("Unknown inland shipping type: " + maritimeShipping); - } - return gmlMaritimeShipping; - } - - private nl.overheid.aerius.gml.v5_1.source.ship.MaritimeShipping toStandard(final StandardMaritimeShipping maritimeShipping) { - final nl.overheid.aerius.gml.v5_1.source.ship.StandardMaritimeShipping gmlShip = new nl.overheid.aerius.gml.v5_1.source.ship.StandardMaritimeShipping(); - gmlShip.setCode(maritimeShipping.getShipCode()); - return gmlShip; - } - - private nl.overheid.aerius.gml.v5_1.source.ship.MaritimeShipping toCustom(final CustomMaritimeShipping maritimeShipping) { - final nl.overheid.aerius.gml.v5_1.source.ship.CustomMaritimeShipping gmlShip = new nl.overheid.aerius.gml.v5_1.source.ship.CustomMaritimeShipping(); - gmlShip.setEmissionProperties(Maritime2GMLUtil.toCustomEmissionProperties(maritimeShipping.getEmissionProperties())); - gmlShip.setGrossTonnage(maritimeShipping.getGrossTonnage()); - return gmlShip; - } - - private ReferenceType toReferenceType(final String id) { - return ToGMLUtil.toReferenceType(id, GMLIdUtil.SOURCE_PREFIX); - } - -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/OffRoad2GML.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/OffRoad2GML.java deleted file mode 100644 index 9b361085..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/OffRoad2GML.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.v5_1.togml; - -import java.util.ArrayList; -import java.util.List; - -import nl.overheid.aerius.gml.v5_1.source.mobile.CustomOffRoadMobileSource; -import nl.overheid.aerius.gml.v5_1.source.mobile.OffRoadMobileSource; -import nl.overheid.aerius.gml.v5_1.source.mobile.OffRoadMobileSourceProperty; -import nl.overheid.aerius.shared.domain.Substance; -import nl.overheid.aerius.shared.domain.v2.characteristics.OPSSourceCharacteristics; -import nl.overheid.aerius.shared.domain.v2.source.OffRoadMobileEmissionSource; - -/** - * - */ -class OffRoad2GML extends SpecificSource2GML { - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource convert(final OffRoadMobileEmissionSource emissionSource) { - final nl.overheid.aerius.gml.v5_1.source.mobile.OffRoadMobileEmissionSource returnSource = new nl.overheid.aerius.gml.v5_1.source.mobile.OffRoadMobileEmissionSource(); - final List mobileSources = new ArrayList<>(); - - for (final nl.overheid.aerius.shared.domain.v2.source.offroad.OffRoadMobileSource vehicleEmissionValues : emissionSource - .getSubSources()) { - if (vehicleEmissionValues instanceof nl.overheid.aerius.shared.domain.v2.source.offroad.CustomOffRoadMobileSource) { - mobileSources.add(toCustom((nl.overheid.aerius.shared.domain.v2.source.offroad.CustomOffRoadMobileSource) vehicleEmissionValues)); - } else if (vehicleEmissionValues instanceof nl.overheid.aerius.shared.domain.v2.source.offroad.StandardOffRoadMobileSource) { - mobileSources.add(toStandard((nl.overheid.aerius.shared.domain.v2.source.offroad.StandardOffRoadMobileSource) vehicleEmissionValues)); - } else { - - } - } - - returnSource.setOffRoadMobileSources(mobileSources); - return returnSource; - } - - private OffRoadMobileSourceProperty toCustom( - final nl.overheid.aerius.shared.domain.v2.source.offroad.CustomOffRoadMobileSource vehicleEmissionValues) { - final CustomOffRoadMobileSource gmlMobileSource = new CustomOffRoadMobileSource(); - gmlMobileSource.setCharacteristics(SourceCharacteristics2GML.toGML((OPSSourceCharacteristics) vehicleEmissionValues.getCharacteristics(), false)); - gmlMobileSource.setEmissions(getEmissions(vehicleEmissionValues.getEmissions(), Substance.NOX)); - gmlMobileSource.setDescription(vehicleEmissionValues.getDescription()); - return new OffRoadMobileSourceProperty(gmlMobileSource); - } - - private OffRoadMobileSourceProperty toStandard( - final nl.overheid.aerius.shared.domain.v2.source.offroad.StandardOffRoadMobileSource vehicleEmissionValues) { - final OffRoadMobileSource gmlMobileSource = new OffRoadMobileSource(); - gmlMobileSource.setCode(vehicleEmissionValues.getOffRoadMobileSourceCode()); - gmlMobileSource.setDescription(vehicleEmissionValues.getDescription()); - gmlMobileSource.setLiterFuelPerYear(vehicleEmissionValues.getLiterFuelPerYear()); - gmlMobileSource.setOperatingHoursPerYear(vehicleEmissionValues.getOperatingHoursPerYear()); - gmlMobileSource.setLiterAdBluePerYear(vehicleEmissionValues.getLiterAdBluePerYear()); - return new OffRoadMobileSourceProperty(gmlMobileSource); - } - -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Result2GML.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Result2GML.java deleted file mode 100644 index 43b02e73..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Result2GML.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * 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.v5_1.togml; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map.Entry; -import java.util.stream.Collectors; - -import nl.overheid.aerius.gml.base.geo.Geometry2GML; -import nl.overheid.aerius.gml.v5_1.base.CalculatorSchema; -import nl.overheid.aerius.gml.v5_1.geo.Polygon; -import nl.overheid.aerius.gml.v5_1.result.AbstractCalculationPoint; -import nl.overheid.aerius.gml.v5_1.result.CIMLKCalculationPoint; -import nl.overheid.aerius.gml.v5_1.result.CalculationPointCorrection; -import nl.overheid.aerius.gml.v5_1.result.CalculationPointCorrectionProperty; -import nl.overheid.aerius.gml.v5_1.result.CustomCalculationPoint; -import nl.overheid.aerius.gml.v5_1.result.NcaCustomCalculationPoint; -import nl.overheid.aerius.gml.v5_1.result.ReceptorPoint; -import nl.overheid.aerius.gml.v5_1.result.Result; -import nl.overheid.aerius.gml.v5_1.result.ResultProperty; -import nl.overheid.aerius.gml.v5_1.result.SubPoint; -import nl.overheid.aerius.shared.domain.Substance; -import nl.overheid.aerius.shared.domain.geo.HexagonUtil; -import nl.overheid.aerius.shared.domain.geo.HexagonZoomLevel; -import nl.overheid.aerius.shared.domain.result.EmissionResultKey; -import nl.overheid.aerius.shared.domain.result.EmissionResultType; -import nl.overheid.aerius.shared.domain.v2.characteristics.adms.NcaPointHeightSupplier; -import nl.overheid.aerius.shared.domain.v2.cimlk.CIMLKCorrection; -import nl.overheid.aerius.shared.domain.v2.geojson.Geometry; -import nl.overheid.aerius.shared.domain.v2.geojson.Point; -import nl.overheid.aerius.shared.domain.v2.point.CalculationPoint; -import nl.overheid.aerius.shared.domain.v2.point.CalculationPointFeature; -import nl.overheid.aerius.shared.exception.AeriusException; -import nl.overheid.aerius.util.gml.GMLIdUtil; - -/** - * Utility class to convert Deposition objects to GML objects. - */ -final class Result2GML { - - private final Geometry2GML geometry2gml; - private final HexagonZoomLevel zoomLevel1; - - public Result2GML(final Geometry2GML geometry2gml, final HexagonZoomLevel zoomLevel1) { - this.geometry2gml = geometry2gml; - this.zoomLevel1 = zoomLevel1; - } - - /** - * Convert a AeriusPoint (custom or not) to a GML object. - * @param point The point to convert to a GML object. - * @param substances The substances to use when setting depositions. - * @param corrections The corrections to add to receptors. - * @return the GML object representing the AeriusPoint. - * @throws AeriusException when the objects could not be converted to GML correctly. - */ - public AbstractCalculationPoint toGML(final CalculationPointFeature feature, final Substance[] substances, final List corrections) - throws AeriusException { - final CalculationPoint point = feature.getProperties(); - final AbstractCalculationPoint returnPoint = determineSpecificType(point, feature.getGeometry()); - //set the generic properties. - returnPoint.setGeometry(geometry2gml, feature.getGeometry()); - returnPoint.setId(determineId(point)); - returnPoint.setLabel(point.getLabel()); - returnPoint.setDescription(point.getDescription()); - returnPoint.setJurisdictionId(point.getJurisdictionId()); - if (returnPoint.getRepresentation() != null) { - returnPoint.getRepresentation().getGmlPolygon().setId(CalculatorSchema.GML_ID_NAMESPACE + ".REPR." - + point.getId()); - } - //set emission results (if not 0 and only for the right substances). - returnPoint.setResults(getResults(point, substances)); - returnPoint.setCorrections(getCorrections(point, corrections)); - return returnPoint; - } - - private String determineId(final CalculationPoint point) { - //avoid conflicting IDs by using a prefix. - if (point instanceof nl.overheid.aerius.shared.domain.v2.point.SubPoint) { - final nl.overheid.aerius.shared.domain.v2.point.SubPoint subPoint = (nl.overheid.aerius.shared.domain.v2.point.SubPoint) point; - return GMLIdUtil.toValidGmlId(point.getGmlId(), GMLIdUtil.SUB_POINT_PREFIX, subPoint.getReceptorId() + "_" + subPoint.getSubPointId()); - } else { - return GMLIdUtil.toValidGmlId(point.getGmlId(), GMLIdUtil.POINT_PREFIX, String.valueOf(point.getId())); - } - } - - private AbstractCalculationPoint determineSpecificType(final CalculationPoint aeriusPoint, final Point point) throws AeriusException { - final AbstractCalculationPoint returnPoint; - if (aeriusPoint instanceof nl.overheid.aerius.shared.domain.v2.point.CIMLKCalculationPoint) { - returnPoint = fromAeriusCalculationPoint((nl.overheid.aerius.shared.domain.v2.point.CIMLKCalculationPoint) aeriusPoint); - } else if (aeriusPoint instanceof nl.overheid.aerius.shared.domain.v2.point.NcaCustomCalculationPoint) { - returnPoint = fromNcaCustomPoint((nl.overheid.aerius.shared.domain.v2.point.NcaCustomCalculationPoint) aeriusPoint); - } else if (aeriusPoint instanceof nl.overheid.aerius.shared.domain.v2.point.CustomCalculationPoint) { - returnPoint = fromCustomPoint((nl.overheid.aerius.shared.domain.v2.point.CustomCalculationPoint) aeriusPoint); - } else if (aeriusPoint instanceof nl.overheid.aerius.shared.domain.v2.point.SubPoint) { - returnPoint = fromSubPoint((nl.overheid.aerius.shared.domain.v2.point.SubPoint) aeriusPoint); - } else { - returnPoint = fromReceptorPoint((nl.overheid.aerius.shared.domain.v2.point.ReceptorPoint) aeriusPoint, point); - } - return returnPoint; - } - - private AbstractCalculationPoint fromAeriusCalculationPoint(final nl.overheid.aerius.shared.domain.v2.point.CIMLKCalculationPoint aeriusPoint) { - //treat as a custom calculation point with added properties - final CIMLKCalculationPoint point = new CIMLKCalculationPoint(); - point.setRejectionGrounds(aeriusPoint.getRejectionGrounds()); - point.setMonitorSubstance(aeriusPoint.getMonitorSubstance()); - setCustomProperties(aeriusPoint, point); - return point; - } - - private AbstractCalculationPoint fromNcaCustomPoint(final nl.overheid.aerius.shared.domain.v2.point.NcaCustomCalculationPoint aeriusPoint) { - final NcaCustomCalculationPoint returnPoint = new NcaCustomCalculationPoint(); - returnPoint.setRoadLocalFractionNO2(aeriusPoint.getRoadLocalFractionNO2()); - setCustomProperties(aeriusPoint, returnPoint); - returnPoint.setHeight(NcaPointHeightSupplier.getHeight(aeriusPoint)); - return returnPoint; - } - - private AbstractCalculationPoint fromCustomPoint(final nl.overheid.aerius.shared.domain.v2.point.CustomCalculationPoint aeriusPoint) { - //treat as a custom calculation point - //The proper representation of a custompoint would be a circle with a surface of 1ha. - //Unclear at this point if this is required for GML and if it should be implemented by a GML polygon, arc or circle. - //for now, just let the representation be as it isn't as specific as the hexagon. - final CustomCalculationPoint returnPoint = new CustomCalculationPoint(); - setCustomProperties(aeriusPoint, returnPoint); - return returnPoint; - } - - private void setCustomProperties(final nl.overheid.aerius.shared.domain.v2.point.CustomCalculationPoint aeriusPoint, - final AbstractCalculationPoint returnPoint) { - returnPoint.setAssessmentCategory(aeriusPoint.getAssessmentCategory() == null ? null : aeriusPoint.getAssessmentCategory().name()); - returnPoint.setHeight(aeriusPoint.getHeight()); - } - - private AbstractCalculationPoint fromSubPoint(final nl.overheid.aerius.shared.domain.v2.point.SubPoint aeriusPoint) { - final SubPoint returnSubPoint = new SubPoint(); - returnSubPoint.setSubPointId(aeriusPoint.getSubPointId()); - returnSubPoint.setReceptorPointId(aeriusPoint.getReceptorId()); - returnSubPoint.setLevel(aeriusPoint.getLevel()); - //not adding a representation (yet) - return returnSubPoint; - } - - private AbstractCalculationPoint fromReceptorPoint(final nl.overheid.aerius.shared.domain.v2.point.ReceptorPoint aeriusPoint, final Point point) - throws AeriusException { - //treat as receptor point. - final ReceptorPoint returnReceptorPoint = new ReceptorPoint(); - returnReceptorPoint.setReceptorPointId(aeriusPoint.getId()); - returnReceptorPoint.setEdgeEffect(aeriusPoint.getEdgeEffect()); - //receptor are represented by a hexagon. - final Geometry geometry = HexagonUtil.createHexagon(point, zoomLevel1); - if (geometry instanceof nl.overheid.aerius.shared.domain.v2.geojson.Polygon) { - returnReceptorPoint.setRepresentation( - geometry2gml.toXMLPolygon((nl.overheid.aerius.shared.domain.v2.geojson.Polygon) geometry, new Polygon())); - } - return returnReceptorPoint; - } - - private static List getResults(final CalculationPoint aeriusPoint, final Substance[] substances) { - final List substanceList = Arrays.asList(substances); - final List results = toResultProperties(aeriusPoint, substanceList); - //sort the list so the substances ordering is preserved and the ordering is always the same (concentration before deposition). - //some of the unittests expect this ordering, but for consistency sake it's better to return the results in the same order. - Collections.sort(results, new Comparator() { - - @Override - public int compare(final ResultProperty o1, final ResultProperty o2) { - final Result result1 = o1.getProperty(); - final Result result2 = o2.getProperty(); - int compared = Integer.compare( - substanceList.indexOf(result1.getSubstance()), - substanceList.indexOf(result2.getSubstance())); - if (compared == 0) { - compared = result1.getResultType().name().compareTo(result2.getResultType().name()); - } - return compared; - } - }); - //to avoid having empty depositions tag, return null when empty. - return results.isEmpty() ? null : results; - } - - private static List toResultProperties(final CalculationPoint arp, final List substanceList) { - final List results = new ArrayList<>(); - toResultTypeProperty(arp, substanceList, results, EmissionResultType.CONCENTRATION); - toResultTypeProperty(arp, substanceList, results, EmissionResultType.DEPOSITION); - return results; - } - - private static void toResultTypeProperty(final CalculationPoint arp, final List substanceList, final List results, - final EmissionResultType ert) { - for (final Entry entry : arp.getResults().entrySet()) { - if (substanceList.contains(entry.getKey().getSubstance()) && entry.getValue() != 0 && entry.getKey().getEmissionResultType() == ert) { - final Result result = new Result(); - result.setSubstance(entry.getKey().getSubstance()); - result.setResultType(entry.getKey().getEmissionResultType()); - result.setValue(entry.getValue()); - final ResultProperty resultProperty = new ResultProperty(result); - results.add(resultProperty); - } - } - } - - private List getCorrections(final CalculationPoint aeriusPoint, final List corrections) { - return corrections.stream() - .filter(correction -> correction.getCalculationPointGmlId().equals(aeriusPoint.getGmlId())) - .map(this::toGMLCorrection) - .map(CalculationPointCorrectionProperty::new) - .collect(Collectors.toList()); - } - - public CalculationPointCorrection toGMLCorrection(final CIMLKCorrection correction) { - final CalculationPointCorrection gmlCorrection = new CalculationPointCorrection(); - gmlCorrection.setLabel(correction.getLabel()); - gmlCorrection.setDescription(correction.getDescription()); - gmlCorrection.setJurisdictionId(correction.getJurisdictionId()); - gmlCorrection.setResultType(correction.getResultType()); - gmlCorrection.setSubstance(correction.getSubstance()); - gmlCorrection.setValue(correction.getValue()); - return gmlCorrection; - } - -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Road2GML.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Road2GML.java deleted file mode 100644 index b132c8ad..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Road2GML.java +++ /dev/null @@ -1,322 +0,0 @@ -/* - * 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.v5_1.togml; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import nl.overheid.aerius.gml.v5_1.source.TimeUnit; -import nl.overheid.aerius.gml.v5_1.source.characteristics.AbstractDiurnalVariation; -import nl.overheid.aerius.gml.v5_1.source.road.ADMSRoad; -import nl.overheid.aerius.gml.v5_1.source.road.ADMSRoadSideBarrierProperty; -import nl.overheid.aerius.gml.v5_1.source.road.CustomVehicle; -import nl.overheid.aerius.gml.v5_1.source.road.RoadEmissionSource; -import nl.overheid.aerius.gml.v5_1.source.road.RoadSideBarrierProperty; -import nl.overheid.aerius.gml.v5_1.source.road.SRM1Road; -import nl.overheid.aerius.gml.v5_1.source.road.SRM1RoadLinearReference; -import nl.overheid.aerius.gml.v5_1.source.road.SRM1RoadLinearReferenceProperty; -import nl.overheid.aerius.gml.v5_1.source.road.SRM2Road; -import nl.overheid.aerius.gml.v5_1.source.road.SRM2RoadLinearReference; -import nl.overheid.aerius.gml.v5_1.source.road.SRM2RoadLinearReferenceProperty; -import nl.overheid.aerius.gml.v5_1.source.road.SpecificVehicle; -import nl.overheid.aerius.gml.v5_1.source.road.StandardVehicle; -import nl.overheid.aerius.gml.v5_1.source.road.VehiclesProperty; -import nl.overheid.aerius.shared.domain.Substance; -import nl.overheid.aerius.shared.domain.v2.characteristics.ADMSSourceCharacteristics; -import nl.overheid.aerius.shared.domain.v2.source.ADMSRoadEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.SRM1RoadEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.SRM2RoadEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.road.ADMSRoadSideBarrier; -import nl.overheid.aerius.shared.domain.v2.source.road.ADMSRoadSideBarrierType; -import nl.overheid.aerius.shared.domain.v2.source.road.CustomVehicles; -import nl.overheid.aerius.shared.domain.v2.source.road.RoadElevation; -import nl.overheid.aerius.shared.domain.v2.source.road.SRM1LinearReference; -import nl.overheid.aerius.shared.domain.v2.source.road.SRM2LinearReference; -import nl.overheid.aerius.shared.domain.v2.source.road.SRM2RoadSideBarrier; -import nl.overheid.aerius.shared.domain.v2.source.road.SpecificVehicles; -import nl.overheid.aerius.shared.domain.v2.source.road.StandardVehicles; -import nl.overheid.aerius.shared.domain.v2.source.road.ValuesPerVehicleType; -import nl.overheid.aerius.shared.domain.v2.source.road.Vehicles; - -/** - * Converts {@link nl.overheid.aerius.shared.domain.v2.source.RoadEmissionSource} to GML data object. - */ -class Road2GML extends SpecificSource2GML { - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource convert( - final nl.overheid.aerius.shared.domain.v2.source.RoadEmissionSource emissionSource) { - final nl.overheid.aerius.gml.v5_1.source.EmissionSource returnSource; - - if (emissionSource instanceof SRM1RoadEmissionSource) { - returnSource = convertSrm1((SRM1RoadEmissionSource) emissionSource); - } else if (emissionSource instanceof SRM2RoadEmissionSource) { - returnSource = convertSrm2((SRM2RoadEmissionSource) emissionSource); - } else if (emissionSource instanceof ADMSRoadEmissionSource) { - returnSource = convertAdms((ADMSRoadEmissionSource) emissionSource); - } else { - returnSource = null; - } - - return returnSource; - } - - private ADMSRoad convertAdms(final ADMSRoadEmissionSource emissionSource) { - final ADMSRoad returnSource = new ADMSRoad(); - - returnSource.setVehicles(toVehicleProperties(emissionSource.getSubSources())); - - handleGenericProperties(emissionSource, returnSource); - returnSource.setWidth(emissionSource.getWidth()); - returnSource.setElevation(emissionSource.getElevation()); - returnSource.setGradient(emissionSource.getGradient()); - returnSource.setCoverage(emissionSource.getCoverage()); - handleBarriers(emissionSource, returnSource); - handleDiurnalVariation(emissionSource, returnSource); - - return returnSource; - } - - private SRM2Road convertSrm2(final SRM2RoadEmissionSource emissionSource) { - final SRM2Road returnSource = new SRM2Road(); - - returnSource.setVehicles(toVehicleProperties(emissionSource.getSubSources())); - - handleGenericProperties(emissionSource, returnSource); - handleTunnel(emissionSource, returnSource); - handleElevation(emissionSource, returnSource); - handleBarriers(emissionSource, returnSource); - - returnSource.setDynamicSegments(getSrm2DynamicSegments(emissionSource)); - - return returnSource; - } - - private SRM1Road convertSrm1(final SRM1RoadEmissionSource emissionSource) { - final SRM1Road returnSource = new SRM1Road(); - - returnSource.setVehicles(toVehicleProperties(emissionSource.getSubSources())); - - handleGenericProperties(emissionSource, returnSource); - handleTunnel(emissionSource, returnSource); - - returnSource.setDynamicSegments(getSrm1DynamicSegments(emissionSource)); - - return returnSource; - } - - private List toVehicleProperties(final List vehicleGroups) { - final List vehiclesList = new ArrayList<>(vehicleGroups.size()); - - for (final Vehicles vehicleGroup : vehicleGroups) { - if (vehicleGroup instanceof StandardVehicles) { - addVehicleEmissionSource(vehiclesList, (StandardVehicles) vehicleGroup); - } else if (vehicleGroup instanceof SpecificVehicles) { - addVehicleEmissionSource(vehiclesList, (SpecificVehicles) vehicleGroup); - } else if (vehicleGroup instanceof CustomVehicles) { - addVehicleEmissionSource(vehiclesList, (CustomVehicles) vehicleGroup); - } else { - throw new IllegalArgumentException("EmissionCategory for traffic not allowed to be null: " + vehicleGroup); - } - } - return vehiclesList; - } - - private void handleGenericProperties(final nl.overheid.aerius.shared.domain.v2.source.RoadEmissionSource emissionSource, - final RoadEmissionSource returnSource) { - handleRoadCodes(emissionSource, returnSource); - handleRoadManager(emissionSource, returnSource); - handleTrafficDirection(emissionSource, returnSource); - } - - private void handleRoadCodes(final nl.overheid.aerius.shared.domain.v2.source.RoadEmissionSource emissionSource, - final RoadEmissionSource returnSource) { - returnSource.setRoadAreaCode(emissionSource.getRoadAreaCode()); - returnSource.setRoadTypeCode(emissionSource.getRoadTypeCode()); - } - - private void handleTunnel(final nl.overheid.aerius.shared.domain.v2.source.RoadEmissionSource emissionSource, final SRM2Road returnSource) { - //don't return tunnel factor if it's the default value. - if (Double.doubleToLongBits(emissionSource.getTunnelFactor()) != Double.doubleToLongBits(1.0)) { - returnSource.setTunnelFactor(emissionSource.getTunnelFactor()); - } - } - - private void handleTunnel(final nl.overheid.aerius.shared.domain.v2.source.SRM1RoadEmissionSource emissionSource, final SRM1Road returnSource) { - //don't return tunnel factor if it's the default value. - if (Double.doubleToLongBits(emissionSource.getTunnelFactor()) != Double.doubleToLongBits(1.0)) { - returnSource.setTunnelFactor(emissionSource.getTunnelFactor()); - } - } - - private void handleElevation(final SRM2RoadEmissionSource emissionSource, final SRM2Road returnSource) { - returnSource.setElevation(emissionSource.getElevation()); - //don't set the elevation height if it's normal elevation. - if (returnSource.getElevation() != RoadElevation.NORMAL) { - returnSource.setElevationHeight(emissionSource.getElevationHeight()); - } - } - - private void handleBarriers(final SRM2RoadEmissionSource emissionSource, final SRM2Road returnSource) { - if (emissionSource.getBarrierLeft() != null) { - returnSource.setBarrierLeft(toGMLRoadSideBarrier(emissionSource.getBarrierLeft())); - } - if (emissionSource.getBarrierRight() != null) { - returnSource.setBarrierRight(toGMLRoadSideBarrier(emissionSource.getBarrierRight())); - } - } - - private RoadSideBarrierProperty toGMLRoadSideBarrier(final SRM2RoadSideBarrier barrier) { - final nl.overheid.aerius.gml.v5_1.source.road.RoadSideBarrier gmlBarrier = new nl.overheid.aerius.gml.v5_1.source.road.RoadSideBarrier(); - gmlBarrier.setBarrierType(barrier.getBarrierType()); - gmlBarrier.setHeight(barrier.getHeight()); - gmlBarrier.setDistance(barrier.getDistance()); - return new RoadSideBarrierProperty(gmlBarrier); - } - - private void handleBarriers(final ADMSRoadEmissionSource emissionSource, final ADMSRoad returnSource) { - if (emissionSource.getBarrierLeft() != null && emissionSource.getBarrierLeft().getBarrierType() != ADMSRoadSideBarrierType.NONE) { - returnSource.setBarrierLeft(toGMLRoadSideBarrier(emissionSource.getBarrierLeft())); - } - if (emissionSource.getBarrierRight() != null && emissionSource.getBarrierRight().getBarrierType() != ADMSRoadSideBarrierType.NONE) { - returnSource.setBarrierRight(toGMLRoadSideBarrier(emissionSource.getBarrierRight())); - } - } - - private void handleDiurnalVariation(final ADMSRoadEmissionSource emissionSource, final ADMSRoad returnSource) { - if (emissionSource.getCharacteristics() instanceof ADMSSourceCharacteristics) { - final ADMSSourceCharacteristics characteristics = (ADMSSourceCharacteristics) emissionSource.getCharacteristics(); - final AbstractDiurnalVariation diurnalVariation = ToGMLUtil.determineDiurnalVariation( - characteristics::getCustomHourlyTimeVaryingProfileId, - characteristics::getStandardHourlyTimeVaryingProfileCode); - returnSource.setDiurnalVariation(diurnalVariation); - } - } - - private ADMSRoadSideBarrierProperty toGMLRoadSideBarrier(final ADMSRoadSideBarrier barrier) { - final nl.overheid.aerius.gml.v5_1.source.road.ADMSRoadSideBarrier gmlBarrier = new nl.overheid.aerius.gml.v5_1.source.road.ADMSRoadSideBarrier(); - gmlBarrier.setBarrierType(barrier.getBarrierType()); - gmlBarrier.setDistance(barrier.getWidth()); - gmlBarrier.setAverageHeight(barrier.getAverageHeight()); - gmlBarrier.setMaximumHeight(barrier.getMaximumHeight()); - gmlBarrier.setMinimumHeight(barrier.getMinimumHeight()); - gmlBarrier.setPorosity(barrier.getPorosity()); - return new ADMSRoadSideBarrierProperty(gmlBarrier); - } - - private void handleRoadManager(final nl.overheid.aerius.shared.domain.v2.source.RoadEmissionSource emissionSource, - final RoadEmissionSource returnSource) { - returnSource.setRoadManager(emissionSource.getRoadManager()); - } - - private void handleTrafficDirection(final nl.overheid.aerius.shared.domain.v2.source.RoadEmissionSource emissionSource, - final RoadEmissionSource returnSource) { - returnSource.setTrafficDirection(emissionSource.getTrafficDirection()); - } - - private void addVehicleEmissionSource(final List vehiclesList, final StandardVehicles vse) { - // Loop over all vehicle types in the valuesPerVehicleTypes map, but sort them first to get predictable order. - final List vehicleTypes = vse.getValuesPerVehicleTypes().keySet().stream().sorted().collect(Collectors.toList()); - for (final String vehicleType : vehicleTypes) { - if (vse.getValuesPerVehicleTypes().containsKey(vehicleType)) { - final ValuesPerVehicleType valuesPerVehicleType = vse.getValuesPerVehicleTypes().get(vehicleType); - final StandardVehicle sv = new StandardVehicle(); - sv.setVehiclesPerTimeUnit(valuesPerVehicleType.getVehiclesPerTimeUnit()); - sv.setStagnationFactor(valuesPerVehicleType.getStagnationFraction()); - sv.setVehicleType(vehicleType); - sv.setMaximumSpeed(vse.getMaximumSpeed()); - sv.setStrictEnforcement(vse.getStrictEnforcement()); - sv.setTimeUnit(TimeUnit.from(vse.getTimeUnit())); - vehiclesList.add(new VehiclesProperty(sv)); - } - } - } - - private void addVehicleEmissionSource(final List vehiclesList, final SpecificVehicles vse) { - final SpecificVehicle sv = new SpecificVehicle(); - - sv.setCode(vse.getVehicleCode()); - sv.setVehiclesPerTimeUnit(vse.getVehiclesPerTimeUnit()); - sv.setTimeUnit(TimeUnit.from(vse.getTimeUnit())); - vehiclesList.add(new VehiclesProperty(sv)); - } - - private void addVehicleEmissionSource(final List vehiclesList, final CustomVehicles vce) { - final CustomVehicle cv = new CustomVehicle(); - cv.setDescription(vce.getDescription()); - cv.setEmissionFactors(getEmissions(vce.getEmissionFactors(), Substance.NOX)); - cv.setVehiclesPerTimeUnit(vce.getVehiclesPerTimeUnit()); - cv.setTimeUnit(TimeUnit.from(vce.getTimeUnit())); - vehiclesList.add(new VehiclesProperty(cv)); - } - - private List getSrm2DynamicSegments(final SRM2RoadEmissionSource emissionSource) { - final List partialChangeProperties = new ArrayList<>(); - if (emissionSource.getPartialChanges() != null && !emissionSource.getPartialChanges().isEmpty()) { - for (final SRM2LinearReference dynamicSegment : emissionSource.getPartialChanges()) { - addSrm2PartialChanges(dynamicSegment, partialChangeProperties); - } - - } - return partialChangeProperties; - } - - private void addSrm2PartialChanges(final SRM2LinearReference dynamicSegment, - final List partialChangeProperties) { - final SRM2RoadLinearReference dynamicSegmentGML = new SRM2RoadLinearReference(); - - dynamicSegmentGML.setFromPosition(dynamicSegment.getFromPosition()); - dynamicSegmentGML.setToPosition(dynamicSegment.getToPosition()); - dynamicSegmentGML.setTunnelFactor(dynamicSegment.getTunnelFactor()); - dynamicSegmentGML.setElevation(dynamicSegment.getElevation()); - dynamicSegmentGML.setElevationHeight(dynamicSegment.getElevationHeight()); - - if (dynamicSegment.getBarrierLeft() != null) { - dynamicSegmentGML.setBarrierLeft(toGMLRoadSideBarrier(dynamicSegment.getBarrierLeft())); - } - - if (dynamicSegment.getBarrierRight() != null) { - dynamicSegmentGML.setBarrierRight(toGMLRoadSideBarrier(dynamicSegment.getBarrierRight())); - } - - partialChangeProperties.add(new SRM2RoadLinearReferenceProperty(dynamicSegmentGML)); - } - - private List getSrm1DynamicSegments(final SRM1RoadEmissionSource emissionSource) { - final List partialChangeProperties = new ArrayList<>(); - if (emissionSource.getPartialChanges() != null && !emissionSource.getPartialChanges().isEmpty()) { - for (final SRM1LinearReference dynamicSegment : emissionSource.getPartialChanges()) { - addSrm1PartialChanges(dynamicSegment, partialChangeProperties); - } - - } - return partialChangeProperties; - } - - private void addSrm1PartialChanges(final SRM1LinearReference dynamicSegment, - final List partialChangeProperties) { - final SRM1RoadLinearReference dynamicSegmentGML = new SRM1RoadLinearReference(); - - dynamicSegmentGML.setFromPosition(dynamicSegment.getFromPosition()); - dynamicSegmentGML.setToPosition(dynamicSegment.getToPosition()); - dynamicSegmentGML.setTunnelFactor(dynamicSegment.getTunnelFactor()); - - partialChangeProperties.add(new SRM1RoadLinearReferenceProperty(dynamicSegmentGML)); - } - -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Source2GML.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Source2GML.java deleted file mode 100644 index b02b9a69..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/Source2GML.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * 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.v5_1.togml; - -import java.util.ArrayList; -import java.util.List; - -import nl.overheid.aerius.gml.base.FeatureMember; -import nl.overheid.aerius.gml.base.geo.Geometry2GML; -import nl.overheid.aerius.gml.v5_1.source.Emission; -import nl.overheid.aerius.gml.v5_1.source.EmissionProperty; -import nl.overheid.aerius.gml.v5_1.source.characteristics.EmissionSourceCharacteristics; -import nl.overheid.aerius.shared.domain.Substance; -import nl.overheid.aerius.shared.domain.v2.characteristics.ADMSSourceCharacteristics; -import nl.overheid.aerius.shared.domain.v2.characteristics.OPSSourceCharacteristics; -import nl.overheid.aerius.shared.domain.v2.geojson.IsFeature; -import nl.overheid.aerius.shared.domain.v2.geojson.Point; -import nl.overheid.aerius.shared.domain.v2.source.ADMSRoadEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.ColdStartEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.EmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.EmissionSourceFeature; -import nl.overheid.aerius.shared.domain.v2.source.EmissionSourceVisitor; -import nl.overheid.aerius.shared.domain.v2.source.FarmAnimalHousingEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.FarmlandEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.GenericEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.InlandShippingEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.ManureStorageEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.MaritimeShippingEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.MooringInlandShippingEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.MooringMaritimeShippingEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.OffRoadMobileEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.SRM1RoadEmissionSource; -import nl.overheid.aerius.shared.domain.v2.source.SRM2RoadEmissionSource; -import nl.overheid.aerius.shared.exception.AeriusException; - -/** - * Util class to convert {@link EmissionSource} to GML object. - */ -final class Source2GML implements EmissionSourceVisitor { - - private final Geometry2GML geometry2gml; - - public Source2GML(final Geometry2GML geometry2gml) { - this.geometry2gml = geometry2gml; - } - - /** - * Convert a emissionsource to a GML-object. - * Based on the actual emissionvalues object of the emissionSource, a specific GML-object will be chosen. - * @param source The source to convert. - * @param substances The substances to use when determining emission values. - * @return The converted GML-object (can be a subclass) - * @throws AeriusException when objects could not be converted to GML. - */ - public List toGML(final EmissionSourceFeature source, final Substance[] substances) throws AeriusException { - if (source.getGeometry() == null) { - throw new IllegalArgumentException("Emissionsource without geometry not allowed: " + source); - } - final List members = new ArrayList<>(); - // For now assume no more road networks. If these DO reappear, add all related features to the members list. - members.add(toGMLDefault(source, substances)); - return members; - } - - private nl.overheid.aerius.gml.v5_1.source.EmissionSource toGMLDefault(final EmissionSourceFeature sourceFeature, - final Substance[] substances) throws AeriusException { - final EmissionSource source = sourceFeature.getProperties(); - final nl.overheid.aerius.gml.v5_1.source.EmissionSource returnSource = sourceFeature.accept(this); - //set the generic properties. - returnSource.setGeometry(geometry2gml, sourceFeature.getGeometry()); - returnSource.setId(source.getGmlId()); - - returnSource.setLabel(source.getLabel()); - returnSource.setDescription(source.getDescription()); - returnSource.setJurisdictionId(source.getJurisdictionId()); - //getSector always returns a sector, even if it was null. - returnSource.setSectorId(source.getSectorId()); - - toGMLCharacteristics(sourceFeature, source, returnSource); - - //always set emissionvalues (even for things like farm/road where we won't use them when importing) - returnSource.setEmissionValues(getEmissions(source, substances)); - if (returnSource.getEmissionValues() == null) { - throw new IllegalArgumentException("Emissionsource without emission not allowed: " + source); - } - return returnSource; - } - - private void toGMLCharacteristics(final EmissionSourceFeature sourceFeature, final EmissionSource source, - final nl.overheid.aerius.gml.v5_1.source.EmissionSource returnSource) throws AeriusException { - if (source.getCharacteristics() instanceof OPSSourceCharacteristics) { - returnSource.setCharacteristics(SourceCharacteristics2GML.toGML((OPSSourceCharacteristics) source.getCharacteristics(), true)); - //ensure spread isn't exported for pointsources. - if (sourceFeature.getGeometry() instanceof Point) { - ((EmissionSourceCharacteristics) returnSource.getCharacteristics()).setSpread(null); - } - //ensure diurnal variation isn't exported for sources other then generic ones. - if (!(source instanceof GenericEmissionSource)) { // - ((EmissionSourceCharacteristics) returnSource.getCharacteristics()).setDiurnalVariation(null); - } - } - // For ADMS, don't export characteristics for road. - // It does not really use any characteristic but the diurnal variation, and that's specified directly on the object. - if (source.getCharacteristics() instanceof ADMSSourceCharacteristics - && !(source instanceof ADMSRoadEmissionSource)) { - returnSource.setCharacteristics(SourceCharacteristics2GML.toGML((ADMSSourceCharacteristics) source.getCharacteristics())); - } - } - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource visit(final GenericEmissionSource emissionSource, final IsFeature feature) { - return new nl.overheid.aerius.gml.v5_1.source.EmissionSource(); - } - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource visit(final MooringMaritimeShippingEmissionSource emissionSource, final IsFeature feature) - throws AeriusException { - return new MaritimeMooring2GML().convert(emissionSource); - } - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource visit(final MaritimeShippingEmissionSource emissionSource, final IsFeature feature) - throws AeriusException { - return new MaritimeRoute2GML().convert(emissionSource); - } - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource visit(final InlandShippingEmissionSource emissionSource, final IsFeature feature) - throws AeriusException { - return new InlandRoute2GML().convert(emissionSource); - } - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource visit(final MooringInlandShippingEmissionSource emissionSource, final IsFeature feature) - throws AeriusException { - return new InlandMooring2GML().convert(emissionSource); - } - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource visit(final OffRoadMobileEmissionSource emissionSource, final IsFeature feature) - throws AeriusException { - return new OffRoad2GML().convert(emissionSource); - } - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource visit(final FarmAnimalHousingEmissionSource emissionSource, final IsFeature feature) - throws AeriusException { - // In this version the animal housing is not implemented, just export as a generic source (other option would be an exception). - return new nl.overheid.aerius.gml.v5_1.source.EmissionSource(); - } - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource visit(final FarmlandEmissionSource emissionSource, final IsFeature feature) - throws AeriusException { - return new Farmland2GML().convert(emissionSource); - } - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource visit(final ManureStorageEmissionSource emissionSource, final IsFeature feature) - throws AeriusException { - return new ManureStorage2GML().convert(emissionSource); - } - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource visit(final ColdStartEmissionSource emissionSource, final IsFeature feature) throws AeriusException { - throw new IllegalArgumentException("Coldstart not yet supported."); - } - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource visit(final SRM1RoadEmissionSource emissionSource, final IsFeature feature) - throws AeriusException { - return new Road2GML().convert(emissionSource); - } - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource visit(final SRM2RoadEmissionSource emissionSource, final IsFeature feature) - throws AeriusException { - return new Road2GML().convert(emissionSource); - } - - @Override - public nl.overheid.aerius.gml.v5_1.source.EmissionSource visit(final ADMSRoadEmissionSource emissionSource, final IsFeature feature) - throws AeriusException { - return new Road2GML().convert(emissionSource); - } - - private List getEmissions( - final EmissionSource source, final Substance[] substances) { - final List emissions = new ArrayList<>(substances.length); - for (final Substance substance : substances) { - //always export for each substance found - //it'll result in a bit more elements, but it's clearer to user - //if all emissions would be 0 it'd result in emissions being empty as well, which conflicts with XSD. - final Emission emission = new Emission(); - emission.setSubstance(substance); - emission.setValue(source.getEmissions().getOrDefault(substance, 0.0)); - emissions.add(new EmissionProperty(emission)); - - } - return emissions; - } - -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/SourceCharacteristics2GML.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/SourceCharacteristics2GML.java deleted file mode 100644 index 3ff15ba2..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/SourceCharacteristics2GML.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * 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.v5_1.togml; - -import nl.overheid.aerius.gml.v5_1.base.ReferenceType; -import nl.overheid.aerius.gml.v5_1.source.characteristics.AbstractDiurnalVariation; -import nl.overheid.aerius.gml.v5_1.source.characteristics.AbstractHeatContent; -import nl.overheid.aerius.gml.v5_1.source.characteristics.CalculatedHeatContent; -import nl.overheid.aerius.gml.v5_1.source.characteristics.EmissionSourceCharacteristics; -import nl.overheid.aerius.gml.v5_1.source.characteristics.SpecifiedHeatContent; -import nl.overheid.aerius.shared.domain.ops.OutflowDirectionType; -import nl.overheid.aerius.shared.domain.ops.OutflowVelocityType; -import nl.overheid.aerius.shared.domain.v2.characteristics.ADMSSourceCharacteristics; -import nl.overheid.aerius.shared.domain.v2.characteristics.HeatContentType; -import nl.overheid.aerius.shared.domain.v2.characteristics.OPSSourceCharacteristics; -import nl.overheid.aerius.shared.domain.v2.characteristics.SourceCharacteristics; -import nl.overheid.aerius.shared.exception.AeriusException; -import nl.overheid.aerius.shared.exception.ImaerExceptionReason; -import nl.overheid.aerius.util.gml.GMLIdUtil; - -/** - * - */ -final class SourceCharacteristics2GML { - - private SourceCharacteristics2GML() { - //util class. - } - - static EmissionSourceCharacteristics toGML( - final OPSSourceCharacteristics characteristics, final boolean includeOptionals) { - final EmissionSourceCharacteristics returnCharacteristics = new EmissionSourceCharacteristics(); - returnCharacteristics.setHeatContent(determineHeatContent(characteristics)); - returnCharacteristics.setEmissionHeight(characteristics.getEmissionHeight()); - returnCharacteristics.setSpread(characteristics.getSpread()); - if (includeOptionals) { - returnCharacteristics.setDiurnalVariation(determineDiurnalVariation(characteristics)); - } - returnCharacteristics.setBuilding(determineBuilding(characteristics)); - return returnCharacteristics; - } - - private static AbstractHeatContent determineHeatContent(final OPSSourceCharacteristics characteristics) { - if (characteristics.getHeatContentType() == HeatContentType.FORCED) { - final CalculatedHeatContent heatContent = new CalculatedHeatContent(); - heatContent.setEmissionTemperature(characteristics.getEmissionTemperature()); - heatContent.setOutflowDiameter(characteristics.getOutflowDiameter()); - heatContent.setOutflowVelocity(characteristics.getOutflowVelocity()); - heatContent.setOutflowDirection(characteristics.getOutflowDirection() == null - ? OutflowDirectionType.VERTICAL - : characteristics.getOutflowDirection()); - heatContent.setOutflowVelocityType(characteristics.getOutflowVelocityType() == null - ? OutflowVelocityType.ACTUAL_FLOW - : characteristics.getOutflowVelocityType()); - return heatContent; - } else { - final SpecifiedHeatContent heatContent = new SpecifiedHeatContent(); - heatContent.setValue(characteristics.getHeatContent() == null - ? 0 - : characteristics.getHeatContent()); - return heatContent; - - } - } - - private static AbstractDiurnalVariation determineDiurnalVariation(final OPSSourceCharacteristics characteristics) { - return ToGMLUtil.determineDiurnalVariation( - () -> null, - () -> characteristics.getDiurnalVariation() == null ? null : characteristics.getDiurnalVariation().getCode()); - } - - static nl.overheid.aerius.gml.v5_1.source.characteristics.ADMSSourceCharacteristics toGML( - final ADMSSourceCharacteristics characteristics) throws AeriusException { - final nl.overheid.aerius.gml.v5_1.source.characteristics.ADMSSourceCharacteristics returnCharacteristics = - new nl.overheid.aerius.gml.v5_1.source.characteristics.ADMSSourceCharacteristics(); - returnCharacteristics.setBuilding(determineBuilding(characteristics)); - returnCharacteristics.setHeight(characteristics.getHeight()); - returnCharacteristics.setSpecificHeatCapacity(characteristics.getSpecificHeatCapacity()); - - determineSourceType(characteristics, returnCharacteristics); - determineBuoyancyType(characteristics, returnCharacteristics); - determineEffluxType(characteristics, returnCharacteristics); - returnCharacteristics.setDiurnalVariation(determineDiurnalVariation(characteristics)); - returnCharacteristics.setMonthlyVariation(determineMonthlyVariation(characteristics)); - - return returnCharacteristics; - } - - private static void determineSourceType(final ADMSSourceCharacteristics characteristics, - final nl.overheid.aerius.gml.v5_1.source.characteristics.ADMSSourceCharacteristics returnCharacteristics) { - returnCharacteristics.setSourceType(characteristics.getSourceType()); - switch (characteristics.getSourceType()) { - case JET: - returnCharacteristics.setElevationAngle(characteristics.getElevationAngle()); - returnCharacteristics.setHorizontalAngle(characteristics.getHorizontalAngle()); - // Intentional fallthrough - case POINT: - returnCharacteristics.setDiameter(characteristics.getDiameter()); - break; - case AREA: - break; - case LINE: - case ROAD: - returnCharacteristics.setWidth(characteristics.getWidth()); - break; - case VOLUME: - returnCharacteristics.setVerticalDimension(characteristics.getVerticalDimension()); - break; - } - } - - private static void determineBuoyancyType(final ADMSSourceCharacteristics characteristics, - final nl.overheid.aerius.gml.v5_1.source.characteristics.ADMSSourceCharacteristics returnCharacteristics) { - returnCharacteristics.setBuoyancyType(characteristics.getBuoyancyType()); - switch (characteristics.getBuoyancyType()) { - case AMBIENT: - break; - case DENSITY: - returnCharacteristics.setDensity(characteristics.getDensity()); - break; - case TEMPERATURE: - returnCharacteristics.setTemperature(characteristics.getTemperature()); - break; - } - } - - private static void determineEffluxType(final ADMSSourceCharacteristics characteristics, - final nl.overheid.aerius.gml.v5_1.source.characteristics.ADMSSourceCharacteristics returnCharacteristics) throws AeriusException { - returnCharacteristics.setEffluxType(characteristics.getEffluxType()); - switch (characteristics.getEffluxType()) { - case VELOCITY: - returnCharacteristics.setVerticalVelocity(characteristics.getVerticalVelocity()); - break; - case VOLUME: - returnCharacteristics.setVolumetricFlowRate(characteristics.getVolumetricFlowRate()); - break; - case MASS: - break; - case MOMENTUM: - // Not (yet) supported - throw new AeriusException(ImaerExceptionReason.INTERNAL_ERROR); - } - } - - private static AbstractDiurnalVariation determineDiurnalVariation(final ADMSSourceCharacteristics characteristics) { - return ToGMLUtil.determineDiurnalVariation( - characteristics::getCustomHourlyTimeVaryingProfileId, - characteristics::getStandardHourlyTimeVaryingProfileCode); - } - - private static AbstractDiurnalVariation determineMonthlyVariation(final ADMSSourceCharacteristics characteristics) { - return ToGMLUtil.determineDiurnalVariation( - characteristics::getCustomMonthlyTimeVaryingProfileId, - characteristics::getStandardMonthlyTimeVaryingProfileCode); - } - - private static ReferenceType determineBuilding(final SourceCharacteristics characteristics) { - return ToGMLUtil.toReferenceType(characteristics.getBuildingId(), GMLIdUtil.BUILDING_PREFIX); - } - -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/SpecificSource2GML.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/SpecificSource2GML.java deleted file mode 100644 index 3940ba2a..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/SpecificSource2GML.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.v5_1.togml; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import nl.overheid.aerius.gml.v5_1.source.Emission; -import nl.overheid.aerius.gml.v5_1.source.EmissionProperty; -import nl.overheid.aerius.shared.domain.Substance; -import nl.overheid.aerius.shared.domain.v2.source.EmissionSource; -import nl.overheid.aerius.shared.exception.AeriusException; - -/** - * Base class for {@link EmissionSource} objects conversion to GML. - * @param specific {@link EmissionSource} - */ -abstract class SpecificSource2GML { - - protected static final String ID_SEPARATOR = "_"; - - abstract nl.overheid.aerius.gml.v5_1.source.EmissionSource convert(T emissionSource) throws AeriusException; - - protected static List getEmissions(final Map emissionValues, final Substance defaultSubstance) { - final List emissions = new ArrayList<>(emissionValues.entrySet().size() + 1); - - // Not using entryset to have a predictable order - for (final Substance substance : Substance.values()) { - if (emissionValues.containsKey(substance)) { - final Emission emission = new Emission(); - emission.setSubstance(substance); - emission.setValue(emissionValues.get(substance)); - emissions.add(new EmissionProperty(emission)); - } - } - if (emissions.isEmpty()) { - final Emission emission = new Emission(); - emission.setSubstance(defaultSubstance); - emission.setValue(0.0); - emissions.add(new EmissionProperty(emission)); - } - return emissions; - } - -} diff --git a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/ToGMLUtil.java b/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/ToGMLUtil.java deleted file mode 100644 index 1714a7bd..00000000 --- a/source/imaer-gml/src/main/java/nl/overheid/aerius/gml/v5_1/togml/ToGMLUtil.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.v5_1.togml; - -import java.util.function.Supplier; - -import nl.overheid.aerius.gml.v5_1.base.ReferenceType; -import nl.overheid.aerius.gml.v5_1.source.characteristics.AbstractDiurnalVariation; -import nl.overheid.aerius.gml.v5_1.source.characteristics.ReferenceDiurnalVariation; -import nl.overheid.aerius.gml.v5_1.source.characteristics.StandardDiurnalVariation; -import nl.overheid.aerius.util.gml.GMLIdUtil; - -final class ToGMLUtil { - - private ToGMLUtil() { - // Util class - } - - /** - * @param gmlId Id to reference, should not be null and already a valid GML ID. - */ - static ReferenceType toReferenceType(final String gmlId) { - return toValidReferenceType(gmlId); - } - - /** - * @param id Id to reference, can be null and will be made into a valid GML ID if needed. - * @param validIdPrefixFallback Prefix to use if the ID isn't valid yet and needs a prefix. - */ - static ReferenceType toReferenceType(final String id, final String validIdPrefixFallback) { - final ReferenceType reference; - if (id == null) { - reference = null; - } else { - final String gmlId = GMLIdUtil.toValidGmlId(id, validIdPrefixFallback); - reference = toValidReferenceType(gmlId); - } - return reference; - } - - private static ReferenceType toValidReferenceType(final String gmlId) { - final ReferenceType reference = new ReferenceType(null); - reference.setHref("#" + gmlId); - return reference; - } - - static AbstractDiurnalVariation determineDiurnalVariation(final Supplier customDiurnalVariationIdGetter, - final Supplier standardDiurnalVariationCodeGetter) { - AbstractDiurnalVariation gmlVariation = null; - final String customDiurnalVariationId = customDiurnalVariationIdGetter.get(); - final String standardDiurnalVariationCode = standardDiurnalVariationCodeGetter.get(); - if (customDiurnalVariationId != null) { - final ReferenceDiurnalVariation referenceVariation = new ReferenceDiurnalVariation(); - referenceVariation.setCustomDiurnalVariation( - ToGMLUtil.toReferenceType(customDiurnalVariationId, GMLIdUtil.DIURNAL_VARIATION_PREFIX)); - gmlVariation = referenceVariation; - } else if (standardDiurnalVariationCode != null) { - final StandardDiurnalVariation standardVariation = new StandardDiurnalVariation(); - standardVariation.setCode(standardDiurnalVariationCode); - gmlVariation = standardVariation; - } - return gmlVariation; - } - -} 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 c5fc463d..1a6ead2f 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 @@ -180,7 +180,7 @@ class GMLRoundtripTest { private static final List SUBSTANCES = List.of(Substance.NOX, Substance.NO2, Substance.NH3); - private static final Set SUPPORTED_GML_WRITER_VERSIONS = EnumSet.of(AeriusGMLVersion.V6_0, AeriusGMLVersion.V5_1); + private static final Set SUPPORTED_GML_WRITER_VERSIONS = EnumSet.of(AeriusGMLVersion.V6_0); static List data() throws FileNotFoundException { final List files = new ArrayList<>();