Commit 709cd9cd authored by Rushikesh Padsala's avatar Rushikesh Padsala
Browse files

Merge branch 'beta7' into 'master'

Initial commit

See merge request energy-ade/energy-ade-2-3dcitydb!1
parents f37efb20 31a9fd12
package de.stuttgart.hft.ade.energy2.exporter;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import org.citydb.core.ade.exporter.ADEExporter;
import org.citydb.core.ade.exporter.CityGMLExportHelper;
import org.citydb.core.database.schema.mapping.AbstractType;
import org.citydb.core.database.schema.mapping.ComplexType;
import org.citydb.core.database.schema.mapping.SchemaMapping;
import org.citydb.core.operation.exporter.CityGMLExportException;
import org.citydb.core.query.filter.projection.ProjectionFilter;
import org.citydb.core.registry.ObjectRegistry;
import org.citygml4j.ade.energy.model.core.*;
import org.citygml4j.ade.energy.model.module.EnergyADEModule;
import org.citygml4j.model.gml.basicTypes.Code;
import org.citygml4j.model.gml.basicTypes.Measure;
import org.citygml4j.model.gml.base.StringOrRef;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
public class AbstractQualifiedAttributeExporter implements ADEExporter {
private final PreparedStatement ps;
private final CityGMLExportHelper helper;
private final ExportManager manager;
private final Connection connection;
private WeatherDataExporter weatherDataExporter;
private ResourceExporter resourceExporter;
private String module;
private Map<Integer, Class <? extends AbstractQualifiedAttribute>> attributeClassMap;
public AbstractQualifiedAttributeExporter(Connection connection, CityGMLExportHelper helper, ExportManager manager) throws CityGMLExportException, SQLException {
this.connection = connection;
this.helper = helper;
this.manager = manager;
attributeClassMap = new HashMap<>();
SchemaMapping schemaMapping = ObjectRegistry.getInstance().getSchemaMapping();
ComplexType qualifiedHeightType = schemaMapping.getComplexType("QualifiedHeight", "http://www.citygml.org/ade/energy/2.0");
int objectClassIdOfQualifiedHeight = qualifiedHeightType.getObjectClassId();
attributeClassMap.put(objectClassIdOfQualifiedHeight, QualifiedHeight.class);
ComplexType qualifiedAreaType = schemaMapping.getComplexType("QualifiedArea", "http://www.citygml.org/ade/energy/2.0");
int objectClassIdOfQualifiedArea = qualifiedAreaType.getObjectClassId();
attributeClassMap.put(objectClassIdOfQualifiedArea, QualifiedArea.class);
ComplexType qualifiedVolumeType = schemaMapping.getComplexType("QualifiedVolume", "http://www.citygml.org/ade/energy/2.0");
int objectClassIdOfQualifiedVolume = qualifiedVolumeType.getObjectClassId();
attributeClassMap.put(objectClassIdOfQualifiedVolume, QualifiedVolume.class);
String tableName = helper.getTableNameWithSchema(
manager.getSchemaMapper().getTableName(ADETable.QUALIFIED_ATTRIBUTE)
);
String select = "SELECT id, objectclass_id, type, type_codespace, \"value\", value_uom, description, source, building_id, building_partition_id " +
"FROM " + tableName + " WHERE building_id = ?";
module = EnergyADEModule.v2_0.getNamespaceURI();
ps = connection.prepareStatement(select);
}
public Collection<AbstractQualifiedAttribute> doExport(long objectId) throws SQLException {
ps.setLong(1, objectId);
try (ResultSet rs = ps.executeQuery()) {
Collection<AbstractQualifiedAttribute> result = new ArrayList<>();
while (rs.next()) {
long objectIdFromDB = rs.getLong(1);
int objectClassId = rs.getInt(2);
AbstractQualifiedAttribute attribute = createQualifiedAttribute(objectClassId);
String descriptionValue = rs.getString(7);
if (descriptionValue != null && !descriptionValue.trim().isEmpty()) {
StringOrRef description = new StringOrRef();
description.setValue(descriptionValue);
attribute.setDescription(description);
// System.out.println("Set description for QualifiedAttribute id=" + objectIdFromDB + ": " + descriptionValue);
}
if (rs.getString(8) != null)
attribute.setSource(rs.getString(8));
Measure value = new Measure();
value.setValue(rs.getDouble(5));
value.setUom(rs.getString(6));
attribute.setValue(value);
if (attribute instanceof QualifiedHeight qualifiedHeight) {
Code type = new Code();
type.setValue(rs.getString(3));
type.setCodeSpace(rs.getString(4));
qualifiedHeight.setType(type);
} else if (attribute instanceof QualifiedArea qualifiedArea) {
Code type = new Code();
type.setValue(rs.getString(3));
type.setCodeSpace(rs.getString(4));
qualifiedArea.setType(type);
} else if (attribute instanceof QualifiedVolume qualifiedVolume) {
Code type = new Code();
type.setValue(rs.getString(3));
type.setCodeSpace(rs.getString(4));
qualifiedVolume.setType(type);
}
result.add(attribute);
}
return result;
}
}
private AbstractQualifiedAttribute createQualifiedAttribute(int objectClassId) {
try {
Class<? extends AbstractQualifiedAttribute> aClass = attributeClassMap.get(objectClassId);
return aClass.getDeclaredConstructor().newInstance();
}catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException exception){
throw new IllegalStateException(exception);
}
}
@Override
public void close() throws CityGMLExportException, SQLException {
ps.close();
}
}
package de.stuttgart.hft.ade.energy2.exporter;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import net.opengis.gml.CodeType;
import org.citydb.core.ade.exporter.ADEExporter;
import org.citydb.core.ade.exporter.CityGMLExportHelper;
import org.citydb.core.database.schema.mapping.AbstractType;
import org.citydb.core.operation.exporter.CityGMLExportException;
import org.citydb.core.query.filter.projection.ProjectionFilter;
import org.citygml4j.ade.energy.model.core.*;
import org.citygml4j.ade.energy.model.module.EnergyADEModule;
import org.citygml4j.model.citygml.building.AbstractBuilding;
import org.sig3d.citygml.energyADE2beta7.ThermalStatusValueType;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
public class BuildingPropertiesExporter implements ADEExporter {
private final PreparedStatement ps;
private final CityGMLExportHelper helper;
private final ExportManager manager;
private final Connection connection;
private final AbstractQualifiedAttributeExporter abstractQualifiedAttributeExporter;
private final RefurbishmentMeasureExporter refurbishmentMeasureExporter;
private final String module;
public BuildingPropertiesExporter(Connection connection, CityGMLExportHelper helper, ExportManager manager) throws CityGMLExportException, SQLException {
this.connection = connection;
this.helper = helper;
this.manager = manager;
String select = "select id, type, type_codespace, is_protected, constr_weight, constr_weight_codespace, attic_thm_status, basement_thm_status from " +
helper.getTableNameWithSchema(manager.getSchemaMapper().getTableName(ADETable.BUILDING)) +
" where id = ?";
module = EnergyADEModule.v2_0.getNamespaceURI();
ps = connection.prepareStatement(select);
abstractQualifiedAttributeExporter = manager.getExporter(AbstractQualifiedAttributeExporter.class);
refurbishmentMeasureExporter = manager.getExporter(RefurbishmentMeasureExporter.class);
}
public void doExport(AbstractBuilding building, long objectId, AbstractType<?> objectType, ProjectionFilter projectionFilter) throws SQLException, CityGMLExportException {
ps.setLong(1, objectId);
try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) {
// Building type
if (projectionFilter.containsProperty("buildingType", module)) {
String type = rs.getString("type");
String typeCodespace = rs.getString("type_codespace");
if (type != null || typeCodespace != null) {
CodeType bdgType = new CodeType();
if (type != null)
bdgType.setValue(type);
if (typeCodespace != null)
bdgType.setCodeSpace(typeCodespace);
BuildingTypeProperty buildingTypeProperty = new BuildingTypeProperty();
buildingTypeProperty.setValue(bdgType);
building.addGenericApplicationPropertyOfAbstractBuilding(buildingTypeProperty);
}
}
// Is protected
if (projectionFilter.containsProperty("isProtected", module)) {
int isProtected = rs.getInt("is_protected");
boolean wasNull = rs.wasNull();
Boolean isProtectedValue = wasNull ? false : (isProtected == 1);
BuildingIsProtectedProperty buildingIsProtectedProperty = new BuildingIsProtectedProperty();
buildingIsProtectedProperty.setValue(isProtectedValue);
building.addGenericApplicationPropertyOfAbstractBuilding(buildingIsProtectedProperty);
}
// Construction weight
if (projectionFilter.containsProperty("constructionWeight", module)) {
String constrWeightValue = rs.getString("constr_weight");
String constrWeightCodeSpace = rs.getString("constr_weight_codespace");
if (constrWeightValue != null || constrWeightCodeSpace != null) {
CodeType constrWeight = new CodeType();
constrWeight.setValue(constrWeightValue);
constrWeight.setCodeSpace(constrWeightCodeSpace);
BuildingConstructionWeightProperty buildingConstructionWeightProperty = new BuildingConstructionWeightProperty();
buildingConstructionWeightProperty.setValue(constrWeight);
building.addGenericApplicationPropertyOfAbstractBuilding(buildingConstructionWeightProperty);
}
}
// Attic thermal status
if (projectionFilter.containsProperty("atticThermalStatus", module)) {
String atticThmStatusValue = rs.getString("attic_thm_status");
if (atticThmStatusValue != null) {
ThermalStatusValueType thermalStatusValue = ThermalStatusValueType.fromValue(atticThmStatusValue);
BuildingAtticThermalStatusProperty buildingAtticThmStatusProperty = new BuildingAtticThermalStatusProperty();
buildingAtticThmStatusProperty.setValue(thermalStatusValue);
building.addGenericApplicationPropertyOfAbstractBuilding(buildingAtticThmStatusProperty);
}
}
// Basement thermal status
if (projectionFilter.containsProperty("basementThermalStatus", module)) {
String basementThmStatusValue = rs.getString("basement_thm_status");
if (basementThmStatusValue != null) {
ThermalStatusValueType thermalStatusValueType = ThermalStatusValueType.fromValue(basementThmStatusValue);
BuildingBasementThermalStatusProperty buildingBasementThermalStatusProperty = new BuildingBasementThermalStatusProperty();
buildingBasementThermalStatusProperty.setValue(thermalStatusValueType);
building.addGenericApplicationPropertyOfAbstractBuilding(buildingBasementThermalStatusProperty);
}
}
// Refurbishment measures
if (projectionFilter.containsProperty("refurbishmentMeasure", module)) {
Collection<RefurbishmentMeasureProperty> refurbProps = refurbishmentMeasureExporter.doExport(objectId, objectType, projectionFilter);
for (RefurbishmentMeasureProperty refurbProp : refurbProps) {
building.addGenericApplicationPropertyOfAbstractBuilding(refurbProp);
}
}
// Qualified attributes
if (projectionFilter.containsProperty("qualifiedAttribute", module)) {
for (AbstractQualifiedAttribute qualifiedAttribute : abstractQualifiedAttributeExporter.doExport(objectId)) {
AbstractQualifiedAttributeProperty property = new AbstractQualifiedAttributeProperty(qualifiedAttribute);
building.addGenericApplicationPropertyOfAbstractBuilding(property);
}
}
}
}
}
@Override
public void close() throws CityGMLExportException, SQLException {
ps.close();
abstractQualifiedAttributeExporter.close();
refurbishmentMeasureExporter.close();
}
}
\ No newline at end of file
package de.stuttgart.hft.ade.energy2.exporter;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import org.citydb.config.geometry.GeometryObject;
import org.citydb.core.ade.exporter.ADEExporter;
import org.citydb.core.ade.exporter.CityGMLExportHelper;
import org.citydb.core.database.schema.mapping.AbstractType;
import org.citydb.core.operation.exporter.CityGMLExportException;
import org.citydb.core.query.filter.projection.ProjectionFilter;
import org.citygml4j.ade.energy.model.core.*;
import org.citygml4j.ade.energy.model.module.EnergyADEModule;
import org.citygml4j.model.citygml.core.AbstractCityObject;
import org.citygml4j.model.gml.geometry.primitives.PointProperty;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
public class CityObjectPropertiesExporter implements ADEExporter {
private final PreparedStatement ps;
private final CityGMLExportHelper helper;
private final ExportManager manager;
private final Connection connection;
private WeatherDataExporter weatherDataExporter;
private ResourceExporter resourceExporter;
private String module;
public CityObjectPropertiesExporter(Connection connection, CityGMLExportHelper helper, ExportManager manager) throws CityGMLExportException, SQLException {
this.connection = connection;
this.helper = helper;
this.manager = manager;
String select = "select id, ref_point from " +
helper.getTableNameWithSchema(manager.getSchemaMapper().getTableName(ADETable.CITYOBJECT)) +
" where id = ?";
module = EnergyADEModule.v2_0.getNamespaceURI();
ps = connection.prepareStatement(select);
weatherDataExporter = manager.getExporter(WeatherDataExporter.class);
resourceExporter = manager.getExporter(ResourceExporter.class);
}
public Collection<AbstractCityObject> doExport(AbstractCityObject cityObject, long objectId, AbstractType<?> objectType, ProjectionFilter projectionFilter) throws SQLException {
ps.setLong(1, objectId);
try (ResultSet rs = ps.executeQuery()) {
Collection<AbstractCityObject> result = new ArrayList<>();
while (rs.next()) {
Object pointObj = rs.getObject(2);
if (projectionFilter.containsProperty("weatherData", module)) {
for (WeatherData weatherData : weatherDataExporter.doExport(objectId)) {
WeatherDataProperty property = new WeatherDataProperty(weatherData);
cityObject.addGenericApplicationPropertyOfCityObject(property);
}
}
if (projectionFilter.containsProperty("resource", module)) {
for (AbstractResource resource : resourceExporter.doExport(objectId)) {
AbstractResourceProperty property = new AbstractResourceProperty(resource);
cityObject.addGenericApplicationPropertyOfCityObject(property);
}
}
if (pointObj != null) {
GeometryObject pointObject = helper.getDatabaseAdapter().getGeometryConverter().getPoint(pointObj);
if (pointObject != null) {
PointProperty point = helper.getGMLConverter().getPointProperty(pointObject , false);
ReferencePointProperty referencePointProperty = new ReferencePointProperty(point);
cityObject.getGenericApplicationPropertyOfCityObject().add(referencePointProperty);
}
}
result.add(cityObject);
}
return result;
} catch (CityGMLExportException e) {
throw new RuntimeException(e);
}
}
@Override
public void close() throws CityGMLExportException, SQLException {
ps.close();
}
}
/*
* 3D City Database - The Open Source CityGML Database
* https://www.3dcitydb.org/
*
* Copyright 2013 - 2024
* Chair of Geoinformatics
* Technical University of Munich, Germany
* https://www.lrg.tum.de/gis/
*
* The 3D City Database is jointly developed with the following
* cooperation partners:
*
* Virtual City Systems, Berlin <https://vc.systems/>
* M.O.S.S. Computer Grafik Systeme GmbH, Taufkirchen <http://www.moss.de/>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.stuttgart.hft.ade.energy2.exporter;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import de.stuttgart.hft.ade.energy2.schema.ObjectMapper;
import de.stuttgart.hft.ade.energy2.schema.SchemaMapper;
import org.citydb.core.ade.exporter.ADEExportManager;
import org.citydb.core.ade.exporter.ADEExporter;
import org.citydb.core.ade.exporter.CityGMLExportHelper;
import org.citydb.core.database.schema.mapping.AbstractObjectType;
import org.citydb.core.database.schema.mapping.FeatureType;
import org.citydb.core.operation.exporter.CityGMLExportException;
import org.citydb.core.query.filter.projection.ProjectionFilter;
import org.citygml4j.ade.energy.model.core.AbstractResource;
import org.citygml4j.ade.energy.model.core.QualifiedHeight;
import org.citygml4j.ade.energy.model.core.WeatherData;
import org.citygml4j.ade.energy.model.supportingClasses.*;
import org.citygml4j.model.citygml.ade.binding.ADEModelObject;
import org.citygml4j.model.citygml.building.AbstractBuilding;
import org.citygml4j.model.citygml.core.AbstractCityObject;
import org.citygml4j.model.gml.feature.AbstractFeature;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class ExportManager implements ADEExportManager {
private final Map<Class<? extends ADEExporter>, ADEExporter> exporters;
private final ObjectMapper objectMapper;
private final SchemaMapper schemaMapper;
private Connection connection;
private CityGMLExportHelper helper;
public ExportManager(ObjectMapper objectMapper, SchemaMapper schemaMapper) {
this.objectMapper = objectMapper;
this.schemaMapper = schemaMapper;
exporters = new HashMap<>();
}
@Override
public void init(Connection connection, CityGMLExportHelper helper) throws CityGMLExportException, SQLException {
this.connection = connection;
this.helper = helper;
}
@Override
public void exportObject(ADEModelObject object, long objectId, AbstractObjectType<?> objectType, ProjectionFilter projectionFilter) throws CityGMLExportException, SQLException {
if (object instanceof WeatherStation)
getExporter(WeatherStationExporter.class).doExport((WeatherStation) object, objectId, objectType, projectionFilter);
else if (object instanceof WeatherData)
getExporter(WeatherDataExporter.class).doExport(objectId);
else if (object instanceof UrbanFunctionArea)
getExporter(UrbanFunctionAreaExporter.class).doExport((UrbanFunctionArea) object, objectId, objectType, projectionFilter);
else if (object instanceof AbstractTimeSeries)
getExporter(TimeSeriesExporter.class).doExport(objectId);
else if (object instanceof AbstractResource)
getExporter(ResourceExporter.class).doExport(objectId);
}
@Override
public void exportGenericApplicationProperties(String adeHookTable, AbstractFeature parent, long parentId, FeatureType parentType, ProjectionFilter projectionFilter) throws CityGMLExportException, SQLException {
if (adeHookTable.equals(schemaMapper.getTableName(ADETable.TIME_SERIES)) && parent instanceof AbstractTimeSeries)
getExporter(TimeSeriesExporter.class).doExport(parentId);
else if (adeHookTable.equals(schemaMapper.getTableName(ADETable.CITYOBJECT)) && parent instanceof AbstractCityObject)
getExporter(CityObjectPropertiesExporter.class).doExport((AbstractCityObject) parent, parentId, parentType, projectionFilter);
else if (adeHookTable.equals(schemaMapper.getTableName(ADETable.RESOURCE)) && parent instanceof AbstractResource)
getExporter(ResourceExporter.class).doExport(parentId);
else if (adeHookTable.equals(schemaMapper.getTableName(ADETable.BUILDING)) && parent instanceof AbstractBuilding)
getExporter(BuildingPropertiesExporter.class).doExport((AbstractBuilding) parent, parentId, parentType, projectionFilter);
}
@Override
public void close() throws CityGMLExportException, SQLException {
for (ADEExporter exporter : exporters.values())
exporter.close();
}
protected ObjectMapper getObjectMapper() {
return objectMapper;
}
protected SchemaMapper getSchemaMapper() {
return schemaMapper;
}
protected <T extends ADEExporter> T getExporter(Class<T> type) throws CityGMLExportException, SQLException {
ADEExporter exporter = exporters.get(type);
if (exporter == null) {
if (type == TimeSeriesExporter.class)
exporter = new TimeSeriesExporter(connection, helper, this);
else if (type == UrbanFunctionAreaExporter.class)
exporter = new UrbanFunctionAreaExporter(connection, helper, this);
else if (type == WeatherStationExporter.class)
exporter = new WeatherStationExporter(connection, helper, this);
else if (type == ResourceExporter.class)
exporter = new ResourceExporter(connection, helper, this);
else if (type == WeatherDataExporter.class)
exporter = new WeatherDataExporter(connection, helper, this);
else if (type == CityObjectPropertiesExporter.class)
exporter = new CityObjectPropertiesExporter(connection, helper, this);
else if (type == BuildingPropertiesExporter.class)
exporter = new BuildingPropertiesExporter(connection, helper, this);
else if (type == AbstractQualifiedAttributeExporter.class)
exporter = new AbstractQualifiedAttributeExporter(connection, helper, this);
else if (type == RefurbishmentMeasureExporter.class)
exporter = new RefurbishmentMeasureExporter(connection, helper, this);
if (exporter == null)
throw new SQLException("Failed to build ADE exporter of type " + type.getName() + ".");
exporters.put(type, exporter);
}
return type.cast(exporter);
}
}
package de.stuttgart.hft.ade.energy2.exporter;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import org.citydb.core.ade.exporter.ADEExporter;
import org.citydb.core.ade.exporter.CityGMLExportHelper;
import org.citydb.core.database.schema.mapping.AbstractType;
import org.citydb.core.operation.exporter.CityGMLExportException;
import org.citydb.core.query.filter.projection.ProjectionFilter;
import org.citygml4j.ade.energy.model.core.RefurbishmentMeasure;
import org.citygml4j.ade.energy.model.core.RefurbishmentMeasureProperty;
import org.citygml4j.ade.energy.model.module.EnergyADEModule;
import org.citygml4j.model.gml.basicTypes.Code;
import org.citygml4j.model.gml.base.StringOrRef;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.GregorianCalendar;
public class RefurbishmentMeasureExporter implements ADEExporter {
private final PreparedStatement ps;
private final PreparedStatement cityObjectPs;
private final CityGMLExportHelper helper;
private final ExportManager manager;
private final Connection connection;
private final String module;
public RefurbishmentMeasureExporter(Connection connection, CityGMLExportHelper helper, ExportManager manager) throws CityGMLExportException, SQLException {
this.connection = connection;
this.helper = helper;
this.manager = manager;
String select = "SELECT id, type, type_codespace, start_date, end_date, library_code, library_code_codespace, building_id, building_partition_id FROM " +
helper.getTableNameWithSchema(manager.getSchemaMapper().getTableName(ADETable.REFURBISHMENT_MEASURE)) +
" WHERE building_id = ?";
module = EnergyADEModule.v2_0.getNamespaceURI();
ps = connection.prepareStatement(select);
// Prepare statement for cityobject table
String cityObjectSelect = "SELECT gmlid, description FROM " +
helper.getTableNameWithSchema("cityobject") +
" WHERE id = ?";
cityObjectPs = connection.prepareStatement(cityObjectSelect);
}
public Collection<RefurbishmentMeasureProperty> doExport(long objectId, AbstractType<?> objectType, ProjectionFilter projectionFilter) throws SQLException {
ps.setLong(1, objectId); // Set the building_id parameter
Collection<RefurbishmentMeasureProperty> result = new ArrayList<>();
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
long refurbId = rs.getLong("id");
RefurbishmentMeasure refurbishmentMeasure = new RefurbishmentMeasure();
// Fetch gmlid and description from cityobject
cityObjectPs.setLong(1, refurbId);
try (ResultSet cityObjectRs = cityObjectPs.executeQuery()) {
if (cityObjectRs.next()) {
String gmlId = cityObjectRs.getString("gmlid");
if (!cityObjectRs.wasNull()) {
refurbishmentMeasure.setId(gmlId);
}
String description = cityObjectRs.getString("description");
if (!cityObjectRs.wasNull()) {
StringOrRef descriptionType = new StringOrRef();
descriptionType.setValue(description);
refurbishmentMeasure.setDescription(descriptionType);
}
}
}
// Set type
if (projectionFilter.containsProperty("type", module)) {
String type = rs.getString("type");
String typeCodespace = rs.getString("type_codespace");
if (type != null || typeCodespace != null) {
Code refMeasureType = new Code();
if (type != null) {
refMeasureType.setValue(type);
}
if (typeCodespace != null) {
refMeasureType.setCodeSpace(typeCodespace);
}
refurbishmentMeasure.setType(refMeasureType);
}
}
// Set start date
if (projectionFilter.containsProperty("startDate", module)) {
Date start_date = rs.getDate("start_date");
if (start_date != null) {
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(start_date);
XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
//xmlCal.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
refurbishmentMeasure.setStartDate(xmlCal);
}
}
// Set end date
if (projectionFilter.containsProperty("endDate", module)) {
Date end_date = rs.getDate("end_date");
if (end_date != null) {
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(end_date);
XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
// xmlCal.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
refurbishmentMeasure.setEndDate(xmlCal);
}
}
// Set library code
if (projectionFilter.containsProperty("libraryCode", module)) {
String library_code = rs.getString("library_code");
String library_code_codespace = rs.getString("library_code_codespace");
if (library_code != null || library_code_codespace != null) {
Code library = new Code();
if (library_code != null) {
library.setValue(library_code);
}
if (library_code_codespace != null) {
library.setCodeSpace(library_code_codespace);
}
refurbishmentMeasure.setLibraryCode(library);
}
}
// Wrap in RefurbishmentMeasureProperty
RefurbishmentMeasureProperty refurbProp = new RefurbishmentMeasureProperty();
refurbProp.setRefurbishmentMeasure(refurbishmentMeasure);
result.add(refurbProp);
}
return result;
} catch (DatatypeConfigurationException e) {
throw new SQLException("Failed to convert date: " + e.getMessage(), e);
} catch (SQLException e) {
throw e;
}
}
@Override
public void close() throws CityGMLExportException, SQLException {
ps.close();
cityObjectPs.close();
}
}
\ No newline at end of file
package de.stuttgart.hft.ade.energy2.exporter;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import org.citydb.core.ade.exporter.ADEExporter;
import org.citydb.core.ade.exporter.CityGMLExportHelper;
import org.citydb.core.database.schema.mapping.ObjectType;
import org.citydb.core.operation.exporter.CityGMLExportException;
import org.citydb.core.query.filter.projection.ProjectionFilter;
import org.citygml4j.ade.energy.model.core.AbstractResource;
import org.citygml4j.ade.energy.model.supportingClasses.*;
import org.citygml4j.model.gml.basicTypes.Code;
import org.citygml4j.model.gml.basicTypes.Measure;
import org.sig3d.citygml.energyADE2beta7.ResourceStatusValueType;
import java.sql.*;
import java.util.ArrayList;
import java.util.Collection;
public class ResourceExporter implements ADEExporter {
private final CityGMLExportHelper helper;
private TimeSeriesExporter timeSeriesExporter;
private PreparedStatement ps;
public ResourceExporter(Connection connection, CityGMLExportHelper helper, ExportManager manager)
throws CityGMLExportException, SQLException {
this.helper = helper;
String tableName = helper.getTableNameWithSchema(manager.getSchemaMapper().getTableName(ADETable.RESOURCE));
String sql = "SELECT " + getColumnNames() + " FROM " + tableName + " WHERE cityobject_id = ?";
ps = connection.prepareStatement(sql);
timeSeriesExporter = manager.getExporter(TimeSeriesExporter.class);
}
public Collection<AbstractResource> doExport(long cityObjectId) throws CityGMLExportException, SQLException {
ps.setLong(1, cityObjectId);
try (ResultSet rs = ps.executeQuery()) {
Collection<AbstractResource> result = new ArrayList<>();
while (rs.next()) {
long objectId = rs.getLong(1);
int objectClassId = rs.getInt(2);
if (rs.wasNull()) {
continue;
}
AbstractResource resource = helper.createObject(objectId, objectClassId, AbstractResource.class);
if (resource == null) {
helper.logOrThrowErrorMessage("Failed to instantiate " + helper.getObjectSignature(objectClassId, cityObjectId) + " as resource object.");
continue;
}
ObjectType objectType = helper.getObjectType(objectClassId);
ProjectionFilter projectionFilter = helper.getProjectionFilter(objectType);
// Set AbstractResource properties
String statusValue = rs.getString(7);
if (statusValue != null) {
resource.setStatus(ResourceStatusValueType.fromValue(statusValue));
}
String operationValue = rs.getString(8);
String operationCodeSpace = rs.getString(9);
if (operationValue != null || operationCodeSpace != null) {
Code operationType = new Code();
operationType.setValue(operationValue);
operationType.setCodeSpace(operationCodeSpace);
resource.setOperationType(operationType);
}
String amountValue = rs.getString(11);
String amountCodeSpace = rs.getString(12);
if (amountValue != null || amountCodeSpace != null) {
Code amountType = new Code();
amountType.setValue(amountValue);
amountType.setCodeSpace(amountCodeSpace);
resource.setAmountType(amountType);
}
double amountVal = rs.getDouble(13);
if (!rs.wasNull()) {
Measure amount = new Measure();
amount.setValue(amountVal);
String uom = rs.getString(14);
if (uom != null) {
amount.setUom(uom);
}
amount.setParent(resource);
resource.setAmount(amount);
}
int normalized = rs.getInt(16);
if (!rs.wasNull()) {
resource.setAmountNormalized(normalized == 1);
}
String normalizationParam = rs.getString(17);
if (normalizationParam != null) {
resource.setNormalizationParameter(normalizationParam);
}
double normVal = rs.getDouble(18);
if (!rs.wasNull()) {
Measure normalizationValue = new Measure();
normalizationValue.setParent(resource);
normalizationValue.setValue(normVal);
String uom = rs.getString(19);
if (uom != null) {
normalizationValue.setUom(uom);
}
resource.setNormalizationValue(normalizationValue);
}
double co2Val = rs.getDouble(20);
if (!rs.wasNull()) {
Measure co2Equivalent = new Measure();
co2Equivalent.setValue(co2Val);
String uom = rs.getString(21);
if (uom != null) {
co2Equivalent.setUom(uom);
}
resource.setCo2Equivalent(co2Equivalent);
}
int year = rs.getInt(10);
if (!rs.wasNull()) {
resource.setYear(year);
}
double costVal = rs.getDouble(22);
if (!rs.wasNull()) {
Measure costsMoney = new Measure();
costsMoney.setValue(costVal);
String uom = rs.getString(23);
if (uom != null) {
costsMoney.setUom(uom);
}
resource.setCostsMoney(costsMoney);
}
double yieldVal = rs.getDouble(24);
if (!rs.wasNull()) {
Measure yieldsMoney = new Measure();
yieldsMoney.setValue(yieldVal);
String uom = rs.getString(25);
if (uom != null) {
yieldsMoney.setUom(uom);
}
resource.setYieldsMoney(yieldsMoney);
}
long timeSeriesId = rs.getLong(15);
if (timeSeriesId != 0 && timeSeriesExporter != null) {
Collection<AbstractTimeSeries> timeSeries = timeSeriesExporter.doExport(timeSeriesId);
if (timeSeries != null && !timeSeries.isEmpty()) {
AbstractTimeSeries firstSeries = timeSeries.iterator().next();
if (firstSeries != null) {
resource.setTimeDependentAmount(new AbstractTimeSeriesProperty(firstSeries));
}
}
}
if (resource instanceof Energy) {
Energy energy = (Energy) resource;
String energyType = rs.getString(3);
String energyTypeCodeSpace = rs.getString(4);
if (energyType != null || energyTypeCodeSpace != null) {
Code energyTypeValue = new Code();
energyTypeValue.setValue(energyType);
energyTypeValue.setCodeSpace(energyTypeCodeSpace);
energy.setEnergyTypeValue(energyTypeValue);
}
String energyEndUse = rs.getString(5);
String energyEndUseCodeSpace = rs.getString(6);
if (energyEndUse != null || energyEndUseCodeSpace != null) {
Code energyEndUseValue = new Code();
energyEndUseValue.setValue(energyEndUse);
energyEndUseValue.setCodeSpace(energyEndUseCodeSpace);
energy.setEnergyEndUseValue(energyEndUseValue);
}
String energyCarrier = rs.getString(26);
String energyCarrierCodeSpace = rs.getString(27);
if (energyCarrier != null || energyCarrierCodeSpace != null) {
Code energyCarrierValue = new Code();
energyCarrierValue.setValue(energyCarrier);
energyCarrierValue.setCodeSpace(energyCarrierCodeSpace);
energy.setEnergyCarrierValue(energyCarrierValue);
}
double maxLoadVal = rs.getDouble(28);
if (!rs.wasNull()) {
Measure maximumLoad = new Measure();
maximumLoad.setValue(maxLoadVal);
String uom = rs.getString(29);
if (uom != null) {
maximumLoad.setUom(uom);
}
energy.setMaximumLoad(maximumLoad);
}
String energySource = rs.getString(30);
String energySourceCodeSpace = rs.getString(31);
if (energySource != null || energySourceCodeSpace != null) {
Code energySourceValue = new Code();
energySourceValue.setValue(energySource);
energySourceValue.setCodeSpace(energySourceCodeSpace);
energy.setEnergySourceValue(energySourceValue);
}
} else if (resource instanceof Water) {
Water water = (Water) resource;
String waterType = rs.getString(3);
String waterTypeCodeSpace = rs.getString(4);
if (waterType != null || waterTypeCodeSpace != null) {
Code waterTypeValue = new Code();
waterTypeValue.setValue(waterType);
waterTypeValue.setCodeSpace(waterTypeCodeSpace);
water.setWaterTypeValue(waterTypeValue);
}
String waterEndUse = rs.getString(5);
String waterEndUseCodeSpace = rs.getString(6);
if (waterEndUse != null || waterEndUseCodeSpace != null) {
Code waterEndUseValue = new Code();
waterEndUseValue.setValue(waterEndUse);
waterEndUseValue.setCodeSpace(waterEndUseCodeSpace);
water.setWaterEndUseValue(waterEndUseValue);
}
} else if (resource instanceof Waste) {
Waste waste = (Waste) resource;
String wasteType = rs.getString(3);
String wasteTypeCodeSpace = rs.getString(4);
if (wasteType != null || wasteTypeCodeSpace != null) {
Code wasteTypeValue = new Code();
wasteTypeValue.setValue(wasteType);
wasteTypeValue.setCodeSpace(wasteTypeCodeSpace);
waste.setWasteTypeValue(wasteTypeValue);
}
String wasteEndUse = rs.getString(5);
String wasteEndUseCodeSpace = rs.getString(6);
if (wasteEndUse != null || wasteEndUseCodeSpace != null) {
Code wasteEndUseValue = new Code();
wasteEndUseValue.setValue(wasteEndUse);
wasteEndUseValue.setCodeSpace(wasteEndUseCodeSpace);
waste.setWasteEndUseValue(wasteEndUseValue);
}
int isDangerous = rs.getInt(32);
if (!rs.wasNull()) {
waste.setAmountNormalized(isDangerous == 1);
}
int recyclable = rs.getInt(33);
if (!rs.wasNull()) {
waste.setRecyclable(recyclable == 1);
}
} else if (resource instanceof ConstructionMaterial) {
ConstructionMaterial cm = (ConstructionMaterial) resource;
String type = rs.getString(3);
String typeCodeSpace = rs.getString(4);
if (type != null || typeCodeSpace != null) {
Code typeValue = new Code();
typeValue.setValue(type);
typeValue.setCodeSpace(typeCodeSpace);
cm.setConstructionMaterialTypeValue(typeValue);
}
String endUse = rs.getString(5);
String endUseCodeSpace = rs.getString(6);
if (endUse != null || endUseCodeSpace != null) {
Code endUseValue = new Code();
endUseValue.setValue(endUse);
endUseValue.setCodeSpace(endUseCodeSpace);
cm.setConstructionMaterialEndUseValue(endUseValue);
}
} else if (resource instanceof Food) {
Food food = (Food) resource;
String foodType = rs.getString(3);
String foodTypeCodeSpace = rs.getString(4);
if (foodType != null || foodTypeCodeSpace != null) {
Code foodTypeValue = new Code();
foodTypeValue.setValue(foodType);
foodTypeValue.setCodeSpace(foodTypeCodeSpace);
food.setFoodTypeValue(foodTypeValue);
}
String foodEndUse = rs.getString(5);
String foodEndUseCodeSpace = rs.getString(6);
if (foodEndUse != null || foodEndUseCodeSpace != null) {
Code foodEndUseValue = new Code();
foodEndUseValue.setValue(foodEndUse);
foodEndUseValue.setCodeSpace(foodEndUseCodeSpace);
food.setFoodEndUseValue(foodEndUseValue);
}
} else if (resource instanceof OtherResource) {
OtherResource other = (OtherResource) resource;
String otherType = rs.getString(3);
String otherTypeCodeSpace = rs.getString(4);
if (otherType != null || otherTypeCodeSpace != null) {
Code otherTypeValue = new Code();
otherTypeValue.setValue(otherType);
otherTypeValue.setCodeSpace(otherTypeCodeSpace);
other.setOtherResourceTypeValue(otherTypeValue);
}
String otherEndUse = rs.getString(5);
String otherEndUseCS = rs.getString(6);
if (otherEndUse != null || otherEndUseCS != null) {
Code otherEndUseValue = new Code();
otherEndUseValue.setValue(otherEndUse);
otherEndUseValue.setCodeSpace(otherEndUseCS);
other.setOtherResourceEndUseValue(otherEndUseValue);
}
}
result.add(resource);
}
return result;
}
}
@Override
public void close() throws CityGMLExportException, SQLException {
ps.close();
}
private String getColumnNames() {
return "id, objectclass_id, type, type_codespace, enduse, enduse_codespace, status, operation_type," +
" operation_type_codespace, year, amount_type, amount_type_codespace, amount, " +
"amount_uom, time_series_id, is_amount_normalized, normalization_param, normalization_value, " +
"normalization_value_uom, co2_equivalent, co2_equivalent_uom, costs_money, costs_money_uom, " +
"yields_money, yields_money_uom, energy_carrier, energy_carrier_codespace, maximum_load, " +
"maximum_load_uom, source, source_codespace, is_dangerous, is_recyclable, cityobject_id";
}
}
\ No newline at end of file
package de.stuttgart.hft.ade.energy2.exporter;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import org.citydb.core.ade.exporter.ADEExporter;
import org.citydb.core.ade.exporter.CityGMLExportHelper;
import org.citydb.core.operation.exporter.CityGMLExportException;
import org.citygml4j.ade.energy.model.supportingClasses.*;
import org.citygml4j.model.gml.basicTypes.Code;
import org.citygml4j.model.gml.basicTypes.MeasureList;
import java.net.URI;
import java.sql.*;
import java.time.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
public class TimeSeriesExporter implements ADEExporter {
private final CityGMLExportHelper helper;
private AbstractTimeSeries abstractTimeSeries;
private PreparedStatement ps;
public TimeSeriesExporter(Connection connection, CityGMLExportHelper helper, ExportManager manager)
throws CityGMLExportException, SQLException {
this.helper = helper;
String tableName = helper.getTableNameWithSchema(manager.getSchemaMapper().getTableName(ADETable.TIME_SERIES));
String sql = "SELECT " + getColumnNames() + " FROM " + tableName + " WHERE id = ?";
ps = connection.prepareStatement(sql);
}
public Collection<AbstractTimeSeries> doExport(long objectId) throws CityGMLExportException, SQLException {
ps.setLong(1, objectId);
try (ResultSet rs = ps.executeQuery()) {
Collection<AbstractTimeSeries> result = new ArrayList<>();
while (rs.next()) {
long timeSeriesId = rs.getLong(1);
int abstractTimeSeriesObjectClassId = rs.getInt(2);
if (rs.wasNull()) {
continue;
}
abstractTimeSeries = helper.createObject(timeSeriesId, abstractTimeSeriesObjectClassId, AbstractTimeSeries.class);
if (abstractTimeSeries == null) {
helper.logOrThrowErrorMessage("Failed to instantiate " + helper.getObjectSignature(abstractTimeSeriesObjectClassId, timeSeriesId) + " as time series object.");
continue;
}
// Set AbstractTimeSeries properties
String acquisition_method = rs.getString(3);
String acquisition_method_codespace = rs.getString(4);
if (acquisition_method != null || acquisition_method_codespace != null) {
Code aqmtd = new Code();
aqmtd.setParent(abstractTimeSeries);
aqmtd.setValue(acquisition_method);
aqmtd.setCodeSpace(acquisition_method_codespace);
abstractTimeSeries.setAcquisitionMethod(aqmtd);
}
String interpolation_type = rs.getString(5);
if (interpolation_type != null) {
abstractTimeSeries.setInterpolationTypeValue(InterpolationTypeValue.fromValue(interpolation_type));
}
String source = rs.getString(6);
if (source != null) {
abstractTimeSeries.setSource(source);
}
if (abstractTimeSeries instanceof RegularTimeSeries) {
RegularTimeSeries regularTimeSeries = (RegularTimeSeries) abstractTimeSeries;
Timestamp period_begin = rs.getTimestamp(7);
Timestamp period_end = rs.getTimestamp(8);
if (period_begin != null && period_end != null) {
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime beginZdt = period_begin.toInstant().atZone(zoneId);
ZonedDateTime endZdt = period_end.toInstant().atZone(zoneId);
TimePeriod timePeriod = new TimePeriod();
timePeriod.setBeginPosition(beginZdt);
timePeriod.setEndPosition(endZdt);
TimePeriodProperty timePeriodProperty = new TimePeriodProperty();
timePeriodProperty.setTimePeriod(timePeriod);
regularTimeSeries.setTemporalExtent(timePeriodProperty);
}
Double time_interval = rs.getObject(14) != null ? rs.getDouble(14) : null;
String time_interval_unit = rs.getString(15);
if (time_interval != null) {
TimeIntervalLength timeIntervalLength = new TimeIntervalLength();
timeIntervalLength.setValue(time_interval);
timeIntervalLength.setUnit(time_interval_unit);
regularTimeSeries.setTimeInterval(timeIntervalLength);
}
String valuesString = rs.getString(16);
String uom = rs.getString(17);
if (valuesString != null && !valuesString.isBlank()) {
List<Double> valuesList = Arrays.stream(valuesString.trim().split("\\s+"))
.map(Double::parseDouble)
.collect(Collectors.toList());
MeasureList measureList = new MeasureList();
measureList.setValue(valuesList);
measureList.setUom(uom != null ? uom : "");
regularTimeSeries.setValues(measureList);
}
} else if (abstractTimeSeries instanceof RegularTimeSeriesFile) {
RegularTimeSeriesFile regularTimeSeriesFile = (RegularTimeSeriesFile) abstractTimeSeries;
ZonedDateTime beginZdt = rs.getObject(7, ZonedDateTime.class);
ZonedDateTime endZdt = rs.getObject(8, ZonedDateTime.class);
if (beginZdt != null && endZdt != null) {
TimePeriod timePeriod = new TimePeriod();
timePeriod.setBeginPosition(beginZdt);
timePeriod.setEndPosition(endZdt);
TimePeriodProperty timePeriodProperty = new TimePeriodProperty();
timePeriodProperty.setTimePeriod(timePeriod);
regularTimeSeriesFile.setTemporalExtent(timePeriodProperty);
}
String uom = rs.getString(18);
if (uom != null) {
regularTimeSeriesFile.setUom(uom);
}
String file_uri = rs.getString(19);
if (file_uri != null && !file_uri.isEmpty()) {
try {
regularTimeSeriesFile.setFileURI(URI.create(file_uri));
} catch (IllegalArgumentException e) {
System.out.println("Invalid URI for TimeSeries id=" + timeSeriesId + ": " + file_uri);
}
}
Double time_interval = rs.getObject(14) != null ? rs.getDouble(14) : null;
String time_interval_unit = rs.getString(15);
if (time_interval != null) {
TimeIntervalLength timeIntervalLength = new TimeIntervalLength();
timeIntervalLength.setValue(time_interval);
timeIntervalLength.setUnit(time_interval_unit);
regularTimeSeriesFile.setTimeInterval(timeIntervalLength);
}
int num_of_header_lines = rs.getInt(20);
if (!rs.wasNull()) {
regularTimeSeriesFile.setNumberOfHeaderLines(num_of_header_lines);
}
String field_separator = rs.getString(21);
if (field_separator != null) {
regularTimeSeriesFile.setFieldSeparator(field_separator);
}
String record_separator = rs.getString(22);
if (record_separator != null) {
regularTimeSeriesFile.setRecordSeparator(record_separator);
}
String decimal_symbol = rs.getString(24);
if (decimal_symbol != null) {
regularTimeSeriesFile.setDecimalSymbol(decimal_symbol);
}
Integer value_column_number = rs.getObject(23) != null ? rs.getInt(23) : null;
if (value_column_number != null) {
regularTimeSeriesFile.setValueColumnNumber(value_column_number);
}
} else if (abstractTimeSeries instanceof TypicalValuesTimeSeries) {
TypicalValuesTimeSeries typicalValuesTimeSeries = (TypicalValuesTimeSeries) abstractTimeSeries;
Time start_time = rs.getTime(9);
if (start_time != null) {
LocalTime startTimestamp = start_time.toLocalTime();
typicalValuesTimeSeries.setStartTime(startTimestamp);
}
Integer start_day = rs.getObject(10) != null ? rs.getInt(10) : null;
if (start_day != null) {
typicalValuesTimeSeries.setStartDay(start_day);
}
Integer start_month = rs.getObject(11) != null ? rs.getInt(11) : null;
if (start_month != null) {
typicalValuesTimeSeries.setStartMonth(start_month);
}
Double time_interval = rs.getObject(14) != null ? rs.getDouble(14) : null;
String time_interval_unit = rs.getString(15);
if (time_interval != null) {
TimeIntervalLength timeIntervalLength = new TimeIntervalLength();
timeIntervalLength.setValue(time_interval);
timeIntervalLength.setUnit(time_interval_unit);
typicalValuesTimeSeries.setTimeInterval(timeIntervalLength);
}
Double temporal_extent = rs.getDouble(12);
String temporal_extent_unit = rs.getString(13);
if (!rs.wasNull()) {
TimeIntervalLength timeIntervalLength = new TimeIntervalLength();
timeIntervalLength.setValue(temporal_extent);
timeIntervalLength.setUnit(temporal_extent_unit);
typicalValuesTimeSeries.setTemporalExtent(timeIntervalLength);
}
String valuesString = rs.getString(16);
String uom = rs.getString(17);
if (valuesString != null && !valuesString.isBlank()) {
List<Double> valuesList = Arrays.stream(valuesString.trim().split("\\s+"))
.map(Double::parseDouble)
.collect(Collectors.toList());
MeasureList measureList = new MeasureList();
measureList.setValue(valuesList);
measureList.setUom(uom != null ? uom : "");
typicalValuesTimeSeries.setValues(measureList);
}
} else if (abstractTimeSeries instanceof TypicalValuesTimeSeriesFile) {
TypicalValuesTimeSeriesFile timeSeriesFile = (TypicalValuesTimeSeriesFile) abstractTimeSeries;
Time start_time = rs.getTime(9);
if (start_time != null) {
LocalTime localTime = start_time.toLocalTime();
ZonedDateTime zonedDateTime = localTime.atDate(LocalDate.now())
.atZone(ZoneId.systemDefault());
timeSeriesFile.setStartTime(zonedDateTime);
}
Integer start_day = rs.getObject(10) != null ? rs.getInt(10) : null;
if (start_day != null) {
timeSeriesFile.setStartDay(start_day);
}
Integer start_month = rs.getObject(11) != null ? rs.getInt(11) : null;
if (start_month != null) {
timeSeriesFile.setStartMonth(start_month);
}
Double time_interval = rs.getObject(14) != null ? rs.getDouble(14) : null;
String time_interval_unit = rs.getString(15);
if (time_interval != null) {
TimeIntervalLength timeIntervalLength = new TimeIntervalLength();
timeIntervalLength.setValue(time_interval);
timeIntervalLength.setUnit(time_interval_unit);
timeSeriesFile.setTimeInterval(timeIntervalLength);
}
Double temporal_extent = rs.getDouble(12);
String temporal_extent_unit = rs.getString(13);
if (!rs.wasNull()) {
TimeIntervalLength timeIntervalLength = new TimeIntervalLength();
timeIntervalLength.setValue(temporal_extent);
timeIntervalLength.setUnit(temporal_extent_unit);
timeSeriesFile.setTemporalExtent(timeIntervalLength);
}
String uom = rs.getString(18);
if (uom != null) {
timeSeriesFile.setUom(uom);
}
String file_uri = rs.getString(19);
if (file_uri != null && !file_uri.isEmpty()) {
try {
timeSeriesFile.setFileURI(URI.create(file_uri));
} catch (IllegalArgumentException e) {
System.out.println("Invalid URI for TimeSeries id=" + timeSeriesId + ": " + file_uri);
}
}
int num_of_header_lines = rs.getInt(20);
if (!rs.wasNull()) {
timeSeriesFile.setNumberOfHeaderLines(num_of_header_lines);
}
String field_separator = rs.getString(21);
if (field_separator != null) {
timeSeriesFile.setFieldSeparator(field_separator);
}
String record_separator = rs.getString(22);
if (record_separator != null) {
timeSeriesFile.setRecordSeparator(record_separator);
}
String decimal_symbol = rs.getString(24);
if (decimal_symbol != null) {
timeSeriesFile.setDecimalSymbol(decimal_symbol);
}
Integer value_column_number = rs.getObject(23) != null ? rs.getInt(23) : null;
if (value_column_number != null) {
timeSeriesFile.setValueColumnNumber(value_column_number);
}
} else if (abstractTimeSeries instanceof SensorConnection) {
SensorConnection sensorConnection = (SensorConnection) abstractTimeSeries;
Double temporal_extent = rs.getDouble(12);
String temporal_extent_unit = rs.getString(13);
if (!rs.wasNull()) {
TimeIntervalLength timeIntervalLength = new TimeIntervalLength();
timeIntervalLength.setValue(temporal_extent);
timeIntervalLength.setUnit(temporal_extent_unit);
sensorConnection.setTemporalExtent(timeIntervalLength);
}
String connection_type = rs.getString(28);
String connection_type_codespace = rs.getString(29);
if (connection_type != null) {
Code code = new Code();
code.setValue(connection_type);
code.setCodeSpace(connection_type_codespace);
sensorConnection.setConnectionType(code);
}
String observation_property = rs.getString(36);
if (observation_property != null) {
sensorConnection.setObservationProperty(observation_property);
}
String uom = rs.getString(18);
if (uom != null) {
sensorConnection.setUom(uom);
}
String sensor_id = rs.getString(37);
if (sensor_id != null) {
sensorConnection.setSensorID(sensor_id);
}
String sensor_name = rs.getString(38);
if (sensor_name != null) {
sensorConnection.setSensorName(sensor_name);
}
String observation_id = rs.getString(35);
if (observation_id != null) {
sensorConnection.setObservationID(observation_id);
}
String datastream_id = rs.getString(30);
if (datastream_id != null) {
sensorConnection.setDataStreamID(datastream_id);
}
String base_url = rs.getString(27);
if (base_url != null) {
try {
sensorConnection.setBaseURL(URI.create(base_url));
} catch (IllegalArgumentException e) {
System.out.println("Invalid base_url for TimeSeries id=" + timeSeriesId + ": " + base_url);
}
}
String auth_type = rs.getString(25);
String auth_type_codespace = rs.getString(26);
if (auth_type != null) {
Code code = new Code();
code.setValue(auth_type);
code.setCodeSpace(auth_type_codespace);
sensorConnection.setAuthType(code);
}
String link_to_observation = rs.getString(31);
if (link_to_observation != null) {
sensorConnection.setLinkToObservation(link_to_observation);
}
String link_to_sensor_description = rs.getString(32);
if (link_to_sensor_description != null) {
sensorConnection.setLinkToSensorDescription(link_to_sensor_description);
}
String mqtt_server = rs.getString(33);
if (mqtt_server != null) {
sensorConnection.setMqtServer(mqtt_server);
}
String mqtt_topic = rs.getString(34);
if (mqtt_topic != null) {
sensorConnection.setMqtTopic(mqtt_topic);
}
}
result.add(abstractTimeSeries);
}
return result;
}
}
@Override
public void close() throws CityGMLExportException, SQLException {
ps.close();
}
private String getColumnNames() {
return "id, objectclass_id, acquisition_method, acquisition_method_codespace, interpolation_type, source, " +
"period_begin, period_end, start_time, start_day, start_month, temporal_extent, temporal_extent_unit, " +
"time_interval, time_interval_unit, values_list, values_list_uom, uom, file_uri, num_of_header_lines, " +
"field_separator, record_separator, value_column_number, decimal_symbol, auth_type, auth_type_codespace, " +
"base_url, connection_type, connection_type_codespace, datastream_id, link_to_observation, " +
"link_to_sensor_description, mqtt_server, mqtt_topic, observation_id, observation_property, " +
"sensor_id, sensor_name";
}
}
\ No newline at end of file
package de.stuttgart.hft.ade.energy2.exporter;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import org.citydb.core.ade.exporter.ADEExporter;
import org.citydb.core.ade.exporter.CityGMLExportHelper;
import org.citydb.core.database.schema.mapping.AbstractType;
import org.citydb.core.operation.exporter.CityGMLExportException;
import org.citydb.core.query.filter.projection.ProjectionFilter;
import org.citygml4j.ade.energy.model.module.EnergyADEModule;
import org.citygml4j.ade.energy.model.supportingClasses.AbstractTimeSeries;
import org.citygml4j.ade.energy.model.supportingClasses.AbstractTimeSeriesProperty;
import org.citygml4j.ade.energy.model.supportingClasses.UrbanFunctionArea;
import org.citygml4j.model.gml.basicTypes.Code;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class UrbanFunctionAreaExporter implements ADEExporter {
private PreparedStatement ps;
private String module;
private CityObjectPropertiesExporter cityObjectPropertiesExporter;
private TimeSeriesExporter timeSeriesExporter;
public UrbanFunctionAreaExporter(Connection connection, CityGMLExportHelper helper, ExportManager manager) throws CityGMLExportException, SQLException {
String select = "select type, type_codespace, code, code_codespace from " +
helper.getTableNameWithSchema(manager.getSchemaMapper().getTableName(ADETable.URBAN_FUNCTION_AREA)) +
" where ";
module = EnergyADEModule.v2_0.getNamespaceURI();
ps = connection.prepareStatement(select + "id = ?");
cityObjectPropertiesExporter = manager.getExporter(CityObjectPropertiesExporter.class);
timeSeriesExporter = manager.getExporter(TimeSeriesExporter.class);
}
public UrbanFunctionArea doExport(UrbanFunctionArea uaf, long objectId, AbstractType<?> objectType, ProjectionFilter projectionFilter) throws SQLException {
ps.setLong(1, objectId);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
String type = rs.getString(1);
String typeCodespace = rs.getString(2);
String code = rs.getString(3);
String codeCodespace = rs.getString(4);
Code typeCode = new Code();
if (typeCodespace != null) {
typeCode.setCodeSpace(typeCodespace);
}
if (type != null) {
typeCode.setValue(type);
}
uaf.setType(typeCode);
Code code1 = new Code();
if (codeCodespace != null) {
code1.setCodeSpace(codeCodespace);
}
if (code != null) {
code1.setValue(code);
}
uaf.setCode(code1);
if (projectionFilter.containsProperty("timeSeries", module)) {
for (AbstractTimeSeries timeSeries : timeSeriesExporter.doExport(objectId)) {
AbstractTimeSeriesProperty property = new AbstractTimeSeriesProperty(timeSeries);
uaf.addGenericApplicationPropertyOfCityObject(property);
}
}
}
} catch (CityGMLExportException e) {
throw new RuntimeException(e);
}
return uaf;
}
@Override
public void close() throws CityGMLExportException, SQLException {
ps.close();
}
}
package de.stuttgart.hft.ade.energy2.exporter;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import org.citydb.config.geometry.GeometryObject;
import org.citydb.core.ade.exporter.ADEExporter;
import org.citydb.core.ade.exporter.CityGMLExportHelper;
import org.citydb.core.database.schema.mapping.AbstractType;
import org.citydb.core.database.schema.mapping.ObjectType;
import org.citydb.core.operation.exporter.CityGMLExportException;
import org.citydb.core.operation.exporter.database.content.GMLConverter;
import org.citydb.core.query.filter.projection.CombinedProjectionFilter;
import org.citydb.core.query.filter.projection.ProjectionFilter;
import org.citydb.sqlbuilder.expression.PlaceHolder;
import org.citydb.sqlbuilder.schema.Table;
import org.citydb.sqlbuilder.select.Select;
import org.citydb.sqlbuilder.select.operator.comparison.ComparisonFactory;
import org.citygml4j.ade.energy.model.core.ReferencePointProperty;
import org.citygml4j.ade.energy.model.core.WeatherData;
import org.citygml4j.ade.energy.model.module.EnergyADEModule;
import org.citygml4j.ade.energy.model.supportingClasses.AbstractTimeSeries;
import org.citygml4j.ade.energy.model.supportingClasses.AbstractTimeSeriesProperty;
import org.citygml4j.model.gml.basicTypes.Code;
import org.citygml4j.model.gml.basicTypes.Measure;
import org.citygml4j.model.gml.geometry.primitives.Point;
import org.citygml4j.model.gml.geometry.primitives.PointProperty;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
public class WeatherDataExporter implements ADEExporter {
private final CityGMLExportHelper helper;
private final int objectClassId;
private PreparedStatement ps;
private TimeSeriesExporter timeSeriesExporter;
private GMLConverter gmlConverter;
private String module;
public WeatherDataExporter(Connection connection, CityGMLExportHelper helper, ExportManager manager) throws CityGMLExportException, SQLException {
this.helper = helper;
objectClassId = manager.getObjectMapper().getObjectClassId(WeatherData.class);
String tableName = manager.getSchemaMapper().getTableName(ADETable.WEATHER_DATA);
CombinedProjectionFilter projectionFilter = helper.getCombinedProjectionFilter(tableName);
module = EnergyADEModule.v2_0.getNamespaceURI();
Table table = new Table(helper.getTableNameWithSchema(tableName));
Select select = new Select().addProjection(
table.getColumn("id"),
table.getColumn("type"),
table.getColumn("type_codespace"),
table.getColumn("value_type"),
table.getColumn("value_type_codespace"),
table.getColumn("yearly_value"),
table.getColumn("yearly_value_uom"),
table.getColumn("library_code"),
table.getColumn("library_code_codespace"),
table.getColumn("time_series_id"),
table.getColumn("cityobject_id")
);
if (projectionFilter.containsProperty("position", module))
select.addProjection(table.getColumn("position"));
select.addSelection(ComparisonFactory.equalTo(table.getColumn("cityobject_id"), new PlaceHolder<>()));
ps = connection.prepareStatement(select.toString());
timeSeriesExporter = manager.getExporter(TimeSeriesExporter.class);
gmlConverter = helper.getGMLConverter();
}
public Collection<WeatherData> doExport(long parentId) throws CityGMLExportException, SQLException {
ps.setLong(1, parentId);
try (ResultSet rs = ps.executeQuery()) {
Collection<WeatherData> result = new ArrayList<>();
while (rs.next()) {
long weatherDataId = rs.getLong(1);
WeatherData weatherData = helper.createObject(weatherDataId, objectClassId, WeatherData.class);
if (weatherData == null) {
helper.logOrThrowErrorMessage("Failed to instantiate " + helper.getObjectSignature(objectClassId, weatherDataId) + " as weather data object.");
continue;
}
ObjectType objectType = helper.getObjectType(objectClassId);
ProjectionFilter projectionFilter = helper.getProjectionFilter(objectType);
weatherData.setId(String.valueOf(weatherDataId));
// Set type
String typeValue = rs.getString(2);
String typeCodeSpace = rs.getString(3);
if (typeValue != null || typeCodeSpace != null) {
Code type = new Code();
type.setValue(typeValue);
type.setCodeSpace(typeCodeSpace);
type.setParent(weatherData);
weatherData.setType(type);
}
// Set value type
String valueTypeValue = rs.getString(4);
String valueTypeCodeSpace = rs.getString(5);
if (valueTypeValue != null || valueTypeCodeSpace != null) {
Code valueType = new Code();
valueType.setValue(valueTypeValue);
valueType.setCodeSpace(valueTypeCodeSpace);
valueType.setParent(weatherData);
weatherData.setValueType(valueType);
}
// Set yearly value and UOM
double yearlyValue = rs.getDouble(6);
if (!rs.wasNull()) {
Measure yearlyMeasure = new Measure();
yearlyMeasure.setValue(yearlyValue);
String yearlyValueUom = rs.getString(7);
if (yearlyValueUom != null) {
yearlyMeasure.setUom(yearlyValueUom);
}
yearlyMeasure.setParent(weatherData);
weatherData.setYearlyValue(yearlyMeasure);
}
// Set library code
String libraryCodeValue = rs.getString(8);
String libraryCodeSpace = rs.getString(9);
if (libraryCodeValue != null || libraryCodeSpace != null) {
Code libraryCode = new Code();
libraryCode.setValue(libraryCodeValue);
libraryCode.setCodeSpace(libraryCodeSpace);
libraryCode.setParent(weatherData);
weatherData.setLibraryCode(libraryCode);
}
// Set time series
long timeSeriesId = rs.getLong(10);
if (!rs.wasNull()) {
Collection<AbstractTimeSeries> timeSeries = timeSeriesExporter.doExport(timeSeriesId);
if (timeSeries != null && !timeSeries.isEmpty()) {
AbstractTimeSeries firstSeries = timeSeries.iterator().next();
weatherData.setTimeDependentValues(new AbstractTimeSeriesProperty(firstSeries));
}
}
// Set position (if requested)
if (projectionFilter.containsProperty("position", module)) {
Object pointObj = rs.getObject("position");
if (pointObj != null) {
try {
GeometryObject point = helper.getDatabaseAdapter().getGeometryConverter().getPoint(pointObj);
if (point != null) {
Point gmlPoint = gmlConverter.getPoint(point);
PointProperty pointProperty = new PointProperty(gmlPoint);
ReferencePointProperty refPointProp = new ReferencePointProperty(pointProperty);
weatherData.setPosition(refPointProp);
}
} catch (Exception e) {
// Skip invalid geometry to continue export
}
}
}
result.add(weatherData);
}
return result;
}
}
@Override
public void close() throws CityGMLExportException, SQLException {
ps.close();
}
}
\ No newline at end of file
/*
* 3D City Database - The Open Source CityGML Database
* https://www.3dcitydb.org/
*
* Copyright 2013 - 2024
* Chair of Geoinformatics
* Technical University of Munich, Germany
* https://www.lrg.tum.de/gis/
*
* The 3D City Database is jointly developed with the following
* cooperation partners:
*
* Virtual City Systems, Berlin <https://vc.systems/>
* M.O.S.S. Computer Grafik Systeme GmbH, Taufkirchen <http://www.moss.de/>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.stuttgart.hft.ade.energy2.exporter;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import org.citydb.core.ade.exporter.ADEExporter;
import org.citydb.core.ade.exporter.CityGMLExportHelper;
import org.citydb.core.database.schema.mapping.AbstractType;
import org.citydb.core.operation.exporter.CityGMLExportException;
import org.citydb.core.operation.exporter.database.content.GMLConverter;
import org.citydb.core.query.filter.projection.ProjectionFilter;
import org.citydb.sqlbuilder.expression.PlaceHolder;
import org.citydb.sqlbuilder.schema.Table;
import org.citydb.sqlbuilder.select.Select;
import org.citydb.sqlbuilder.select.operator.comparison.ComparisonFactory;
import org.citygml4j.ade.energy.model.core.*;
import org.citygml4j.ade.energy.model.module.EnergyADEModule;
import org.citygml4j.ade.energy.model.supportingClasses.WeatherStation;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class WeatherStationExporter implements ADEExporter {
private final CityGMLExportHelper helper;
private final int weatherDataObjectClassId;
private PreparedStatement ps;
private TimeSeriesExporter timeSeriesExporter;
private WeatherDataExporter weatherDataExporter;
private GMLConverter gmlConverter;
private String module;
public WeatherStationExporter(Connection connection, CityGMLExportHelper helper, ExportManager manager) throws CityGMLExportException, SQLException {
this.helper = helper;
weatherDataObjectClassId = manager.getObjectMapper().getObjectClassId(WeatherData.class);
String tableName = manager.getSchemaMapper().getTableName(ADETable.CITYOBJECT);
module = EnergyADEModule.v2_0.getNamespaceURI();
Table table = new Table(helper.getTableNameWithSchema(tableName));
Select select = new Select().addProjection(table.getColumn("id"));
select.addSelection(ComparisonFactory.equalTo(table.getColumn("id"), new PlaceHolder<>()));
ps = connection.prepareStatement(select.toString());
timeSeriesExporter = manager.getExporter(TimeSeriesExporter.class);
weatherDataExporter = manager.getExporter(WeatherDataExporter.class);
gmlConverter = helper.getGMLConverter();
}
public void doExport(WeatherStation weatherStation, long objectId, AbstractType<?> objectType, ProjectionFilter projectionFilter) throws CityGMLExportException, SQLException {
ps.setLong(1, objectId);
// try (ResultSet rs = ps.executeQuery()) {
// while (rs.next()) {
//
// long weatherDataId = rs.getLong("id");
// if (!rs.wasNull()) {
// WeatherData weatherData = helper.createObject(weatherDataId, weatherDataObjectClassId, WeatherData.class);
// if (weatherData == null) {
// helper.logOrThrowErrorMessage("Failed to instantiate " + helper.getObjectSignature(weatherDataObjectClassId, weatherDataId) + " as weather data object.");
// continue;
// }
//
// ObjectType weatherDataObjectType = helper.getObjectType(weatherDataObjectClassId);
// ProjectionFilter weatherDataProjectionFilter = helper.getProjectionFilter(weatherDataObjectType);
//
//// weatherData.setType(new Code(rs.getString("weatherdatatype")));
////
//// long valuesId = rs.getLong("values_id");
// if (!rs.wasNull()) {
// AbstractTimeSeries timeSeries = timeSeriesExporter.doExport(objectId);
// if (timeSeries != null)
// weatherData.setTimeDependentValues(new AbstractTimeSeriesProperty(timeSeries));
// }
//
// if (weatherDataProjectionFilter.containsProperty("position", module)) {
// Object pointObj = rs.getObject("position");
// if (pointObj != null) {
// GeometryObject point = helper.getDatabaseAdapter().getGeometryConverter().getPoint(pointObj);
// if (point != null) {
//
// PointProperty pointProperty = new PointProperty();
// pointProperty.setGeometry(point);
//
//
// ReferencePointProperty referencePointProperty = new ReferencePointProperty(pointProperty);
//
// weatherData.setPosition(referencePointProperty);
// }
// }
// }
//
// weatherStation.addParameter(new WeatherDataProperty(weatherData));
// }
// }
// }
}
@Override
public void close() throws CityGMLExportException, SQLException {
ps.close();
}
}
package de.stuttgart.hft.ade.energy2.importer;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import de.stuttgart.hft.ade.energy2.schema.SchemaMapper;
import org.citydb.config.geometry.GeometryObject;
import org.citydb.core.ade.importer.ADEImporter;
import org.citydb.core.ade.importer.ADEPropertyCollection;
import org.citydb.core.ade.importer.CityGMLImportHelper;
import org.citydb.core.database.schema.mapping.FeatureType;
import org.citydb.core.operation.importer.CityGMLImportException;
import org.citydb.core.operation.importer.util.GeometryConverter;
import org.citygml4j.ade.energy.model.core.AbstractBuilding;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Collections;
public class AbstractBuildingImporter implements ADEImporter {
private final Connection connection;
private final CityGMLImportHelper helper;
private final SchemaMapper schemaMapper;
private GeometryConverter geometryConverter;
private PreparedStatement ps;
private int batchCounter;
public AbstractBuildingImporter(Connection connection, CityGMLImportHelper helper, ImportManager manager) throws CityGMLImportException, SQLException {
this.connection = connection;
this.helper = helper;
this.schemaMapper = manager.getSchemaMapper();
ps = connection.prepareStatement(
"INSERT INTO " + helper.getTableNameWithSchema(manager.getSchemaMapper().getTableName(ADETable.BUILDING)) +
" (id, type, type_codespace, is_protected, constr_weight, constr_weight_codespace, attic_thm_status, basement_thm_status) " +
"VALUES (" + String.join(", ", Collections.nCopies(8, "?")) + ")"
);
geometryConverter = helper.getGeometryConverter();
}
public void doImport(ADEPropertyCollection properties, AbstractBuilding building, long parentId, FeatureType parentType) throws CityGMLImportException, SQLException {
ps.setLong(1, parentId);
ps.setString(2, building.getBdgType() != null ? building.getBdgType().getValue() : null);
ps.setString(3, building.getBdgType() != null ? building.getBdgType().getCodeSpace() : null);
ps.setInt(4, building.isBdgIsProtected() ? 0 : 1);
ps.setString(5, building.getBdgConstructionWeight() != null ? building.getBdgConstructionWeight().getValue() : null);
ps.setString(6, building.getBdgConstructionWeight() != null ? building.getBdgConstructionWeight().getCodeSpace() : null);
ps.setString(7, building.getBdgAtticThermalStatus() != null ? building.getBdgAtticThermalStatus().toString() : null);
ps.setString(8, building.getBdgBasementThermalStatus() != null ? building.getBdgBasementThermalStatus().toString() : null);
GeometryObject geometryObject = null;
ps.addBatch();
if (++batchCounter == helper.getDatabaseAdapter().getMaxBatchSize())
helper.executeBatch(schemaMapper.getTableName(ADETable.BUILDING));
}
@Override
public void executeBatch() throws CityGMLImportException, SQLException {
if (batchCounter > 0) {
ps.executeBatch();
batchCounter = 0;
}
}
@Override
public void close() throws CityGMLImportException, SQLException {
ps.close();
}
}
package de.stuttgart.hft.ade.energy2.importer;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import de.stuttgart.hft.ade.energy2.schema.SchemaMapper;
import org.citydb.core.ade.importer.ADEImporter;
import org.citydb.core.ade.importer.CityGMLImportHelper;
import org.citydb.core.ade.importer.ForeignKeys;
import org.citydb.core.database.schema.mapping.AbstractObjectType;
import org.citydb.core.operation.importer.CityGMLImportException;
import org.citygml4j.ade.energy.model.core.AbstractDevice;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
public class AbstractDeviceImporter implements ADEImporter {
private final Connection connection;
private final CityGMLImportHelper helper;
private final SchemaMapper schemaMapper;
private PreparedStatement ps;
private int batchCounter;
public AbstractDeviceImporter(Connection connection, CityGMLImportHelper helper, ImportManager manager) throws CityGMLImportException, SQLException {
this.helper = helper;
this.connection = connection;
this.schemaMapper = manager.getSchemaMapper();
ps = connection.prepareStatement(
"INSERT INTO " + helper.getTableNameWithSchema(schemaMapper.getTableName(ADETable.DEVICE)) + " " +
"(id, objectclass_id, model, num_of_devices, year_of_manufacture, installed_power, installed_power_uom, " +
"nominal_efficiency, nominal_efficiency_uom, efficiency_indicator, heat_diss, heat_diss_uom, heat_diss_conv, " +
"heat_diss_conv_uom, heat_diss_lat, heat_diss_lat_uom, heat_diss_rad, heat_diss_rad_uom, heat_source, " +
"cop_source_temp, cop_source_temp_uom, cop_operation_temp, cop_operation_temp_uom, has_condensation, type, " +
"type_codespace, installation_side, max_cover_ratio, max_cover_ratio_uom, transmittance_id, cityobject_id) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
);
}
public void doImport(AbstractDevice abstractDevice, long objectId, AbstractObjectType<?> objectType, ForeignKeys foreignKeys) throws CityGMLImportException, SQLException {
ps.setLong(1, objectId);
ps.setInt(2, objectType != null ? objectType.getObjectClassId() : 0);
ps.setString(3, abstractDevice != null ? abstractDevice.getModel() : null);
ps.setInt(4, abstractDevice != null ? abstractDevice.getNumberOfDevices() : 0);
ps.setInt(5, abstractDevice != null ? abstractDevice.getYearOfManufacture() : 0);
ps.setDouble(6, (abstractDevice != null && abstractDevice.getInstalledPower() != null) ?
abstractDevice.getInstalledPower().getValue() : 0.0);
ps.setString(7, (abstractDevice != null && abstractDevice.getInstalledPower() != null) ?
abstractDevice.getInstalledPower().getUom() : null);
ps.setDouble(8, (abstractDevice != null && abstractDevice.getNominalEfficiency() != null) ?
abstractDevice.getNominalEfficiency().getValue() : 0.0);
ps.setString(9, (abstractDevice != null && abstractDevice.getNominalEfficiency() != null) ?
abstractDevice.getNominalEfficiency().getUom() : null);
ps.setString(10, abstractDevice != null ? abstractDevice.getEfficiencyIndicator() : null);
ps.setDouble(11, (abstractDevice != null && abstractDevice.getHeatDissipation() != null) ?
abstractDevice.getHeatDissipation().getValue() : 0.0);
ps.setString(12, (abstractDevice != null && abstractDevice.getHeatDissipation() != null) ?
abstractDevice.getHeatDissipation().getUom() : null);
ps.setDouble(13, (abstractDevice != null && abstractDevice.getHeatDissipationConvectiveFraction() != null) ?
abstractDevice.getHeatDissipationConvectiveFraction().getValue() : 0.0);
ps.setString(14, (abstractDevice != null && abstractDevice.getHeatDissipationConvectiveFraction() != null) ?
abstractDevice.getHeatDissipationConvectiveFraction().getUom() : null);
ps.setDouble(15, (abstractDevice != null && abstractDevice.getHeatDissipationLatentFraction() != null) ?
abstractDevice.getHeatDissipationLatentFraction().getValue() : 0.0);
ps.setString(16, (abstractDevice != null && abstractDevice.getHeatDissipationLatentFraction() != null) ?
abstractDevice.getHeatDissipationLatentFraction().getUom() : null);
ps.setDouble(17, (abstractDevice != null && abstractDevice.getHeatDissipationRadiantFraction() != null) ?
abstractDevice.getHeatDissipationRadiantFraction().getValue() : 0.0);
ps.setString(18, (abstractDevice != null && abstractDevice.getHeatDissipationRadiantFraction() != null) ?
abstractDevice.getHeatDissipationRadiantFraction().getUom() : null);
ps.setNull(19, Types.VARCHAR);
ps.setNull(20, Types.DOUBLE);
ps.setNull(21, Types.VARCHAR);
ps.setNull(22, Types.DOUBLE);
ps.setNull(23, Types.VARCHAR);
ps.setNull(24, Types.DOUBLE);
ps.setNull(25, Types.VARCHAR);
ps.setNull(26, Types.VARCHAR);
ps.setNull(27, Types.VARCHAR);
ps.setNull(28, Types.DOUBLE);
ps.setNull(29, Types.VARCHAR);
ps.setNull(30, Types.BIGINT);
ps.setNull(31, Types.BIGINT);
ps.addBatch();
if (++batchCounter == helper.getDatabaseAdapter().getMaxBatchSize())
helper.executeBatch(objectType);
}
@Override
public void executeBatch() throws CityGMLImportException, SQLException {
if (batchCounter > 0) {
ps.executeBatch();
batchCounter = 0;
}
}
@Override
public void close() throws CityGMLImportException, SQLException {
ps.close();
}
}
package de.stuttgart.hft.ade.energy2.importer;
import de.stuttgart.hft.ade.energy2.schema.ADESequence;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import de.stuttgart.hft.ade.energy2.schema.SchemaMapper;
import org.citydb.core.ade.importer.ADEImporter;
import org.citydb.core.ade.importer.CityGMLImportHelper;
import org.citydb.core.ade.importer.ForeignKeys;
import org.citydb.core.database.schema.mapping.AbstractObjectType;
import org.citydb.core.database.schema.mapping.ComplexType;
import org.citydb.core.database.schema.mapping.ObjectType;
import org.citydb.core.database.schema.mapping.SchemaMapping;
import org.citydb.core.operation.importer.CityGMLImportException;
import org.citydb.core.operation.importer.util.GeometryConverter;
import org.citydb.core.registry.ObjectRegistry;
import org.citydb.core.util.Util;
import org.citygml4j.ade.energy.model.core.AbstractQualifiedAttribute;
import org.citygml4j.ade.energy.model.core.QualifiedArea;
import org.citygml4j.ade.energy.model.core.QualifiedHeight;
import org.citygml4j.ade.energy.model.core.QualifiedVolume;
import org.sig3d.citygml.energyADE2beta7.AbstractQualifiedAttributeType;
import org.sig3d.citygml.energyADE2beta7.QualifiedAreaType;
import org.sig3d.citygml.energyADE2beta7.QualifiedHeightType;
import org.sig3d.citygml.energyADE2beta7.QualifiedVolumeType;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Collections;
public class AbstractQualifiedAttributeImporter implements ADEImporter {
private final Connection connection;
private final CityGMLImportHelper helper;
private final ImportManager manager;
private SchemaMapper schemaMapper;
private GeometryConverter geometryConverter;
private PreparedStatement ps;
private int batchCounter;
public AbstractQualifiedAttributeImporter(Connection connection, CityGMLImportHelper helper, ImportManager manager) throws CityGMLImportException, SQLException {
this.connection = connection;
this.helper = helper;
this.manager = manager;
this.schemaMapper = manager.getSchemaMapper();
ps = connection.prepareStatement(
"INSERT INTO " + helper.getTableNameWithSchema(manager.getSchemaMapper().getTableName(ADETable.QUALIFIED_ATTRIBUTE)) +
"(id, objectclass_id, type, type_codespace, value, value_uom, description, source, building_id, building_partition_id) " +
"VALUES (" + String.join(", ", Collections.nCopies(10, "?")) + ")"
);
geometryConverter = helper.getGeometryConverter();
}
public void doImport(AbstractQualifiedAttributeType abstractQualifiedAttribute, long parentId) throws CityGMLImportException, SQLException {
setAbstractQualifiedAttributeToNull();
long objectId = helper.getNextSequenceValue(schemaMapper.getSequenceName(ADESequence.QUALIFIED_ATTRIBUTE_SEQ));
ps.setLong(1, objectId);
ps.setLong(9, parentId);
if (abstractQualifiedAttribute.isSetDescription())
ps.setString(7, abstractQualifiedAttribute.getDescription());
if (abstractQualifiedAttribute.isSetSource())
ps.setString(8, abstractQualifiedAttribute.getSource());
if (abstractQualifiedAttribute.isSetValue()) {
ps.setDouble(5, abstractQualifiedAttribute.getValue().getValue());
ps.setString(6, abstractQualifiedAttribute.getValue().getUom());
}
if (abstractQualifiedAttribute instanceof QualifiedHeightType qualifiedHeight) {
if (qualifiedHeight.isSetType()) {
SchemaMapping schemaMapping = ObjectRegistry.getInstance().getSchemaMapping();
ComplexType qualifiedHeightType = schemaMapping.getComplexType("QualifiedHeight", "http://www.citygml.org/ade/energy/2.0");
int objectClassId = qualifiedHeightType.getObjectClassId();
ps.setInt(2, objectClassId);
ps.setString(3, qualifiedHeight.getType().getValue());
ps.setString(4, qualifiedHeight.getType().getCodeSpace());
}
} else if (abstractQualifiedAttribute instanceof QualifiedAreaType qualifiedArea) {
if (qualifiedArea.isSetType()) {
SchemaMapping schemaMapping = ObjectRegistry.getInstance().getSchemaMapping();
ComplexType qualifiedAreaType = schemaMapping.getComplexType("QualifiedArea", "http://www.citygml.org/ade/energy/2.0");
int objectClassId = qualifiedAreaType.getObjectClassId();
ps.setInt(2, objectClassId);
ps.setString(3, qualifiedArea.getType().getValue());
ps.setString(4, qualifiedArea.getType().getCodeSpace());
}
} else if (abstractQualifiedAttribute instanceof QualifiedVolumeType qualifiedVolume) {
if (qualifiedVolume.isSetType()){
SchemaMapping schemaMapping = ObjectRegistry.getInstance().getSchemaMapping();
ComplexType qualifiedVolumeType = schemaMapping.getComplexType("QualifiedVolume", "http://www.citygml.org/ade/energy/2.0");
int objectClassId = qualifiedVolumeType.getObjectClassId();
ps.setInt(2, objectClassId);
ps.setString(3, qualifiedVolume.getType().getValue());
ps.setString(4, qualifiedVolume.getType().getCodeSpace());
}
}
ps.addBatch();
if (++batchCounter == helper.getDatabaseAdapter().getMaxBatchSize())
helper.executeBatch(schemaMapper.getTableName(ADETable.QUALIFIED_ATTRIBUTE));
}
private void setAbstractQualifiedAttributeToNull() throws SQLException {
ps.setNull(1, Types.BIGINT); // id
ps.setNull(2, Types.INTEGER); // objectclass_id
ps.setNull(3, Types.VARCHAR); // type
ps.setNull(4, Types.VARCHAR); // type_codespace
ps.setNull(5, Types.DOUBLE); // value
ps.setNull(6, Types.VARCHAR); // value_uom
ps.setNull(7, Types.VARCHAR); // description
ps.setNull(8, Types.VARCHAR); // source
ps.setNull(9, Types.BIGINT); // building_id
ps.setNull(10, Types.BIGINT); // building_partition_id
}
@Override
public void executeBatch() throws CityGMLImportException, SQLException {
if (batchCounter > 0) {
ps.executeBatch();
batchCounter = 0;
}
}
@Override
public void close() throws CityGMLImportException, SQLException {
ps.close();
}
}
/*
* 3D City Database - The Open Source CityGML Database
* https://www.3dcitydb.org/
*
* Copyright 2013 - 2024
* Chair of Geoinformatics
* Technical University of Munich, Germany
* https://www.lrg.tum.de/gis/
*
* The 3D City Database is jointly developed with the following
* cooperation partners:
*
* Virtual City Systems, Berlin <https://vc.systems/>
* M.O.S.S. Computer Grafik Systeme GmbH, Taufkirchen <http://www.moss.de/>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.stuttgart.hft.ade.energy2.importer;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import de.stuttgart.hft.ade.energy2.schema.SchemaMapper;
import org.citydb.core.ade.importer.ADEImporter;
import org.citydb.core.ade.importer.ADEPropertyCollection;
import org.citydb.core.ade.importer.CityGMLImportHelper;
import org.citydb.core.ade.importer.ForeignKeys;
import org.citydb.core.database.schema.mapping.FeatureType;
import org.citydb.core.operation.importer.CityGMLImportException;
import org.citydb.core.operation.importer.util.GeometryConverter;
import org.citygml4j.ade.energy.model.core.*;
import org.citygml4j.model.citygml.building.AbstractBuilding;
import org.sig3d.citygml.energyADE2beta7.QualifiedAreaType;
import org.sig3d.citygml.energyADE2beta7.QualifiedHeightType;
import org.sig3d.citygml.energyADE2beta7.QualifiedVolumeType;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
public class BuildingPropertiesImporter implements ADEImporter {
private final Connection connection;
private final CityGMLImportHelper helper;
private final SchemaMapper schemaMapper;
private final ImportManager manager;
private GeometryConverter geometryConverter;
private PreparedStatement ps;
private int batchCounter;
private AbstractQualifiedAttributeImporter abstractQualifiedAttributeImporter;
private RefurbishmentMeasureImporter refurbishmentMeasureImporter;
public BuildingPropertiesImporter(Connection connection, CityGMLImportHelper helper, ImportManager manager) throws CityGMLImportException, SQLException {
this.connection = connection;
this.helper = helper;
this.schemaMapper = manager.getSchemaMapper();
this.manager = manager;
ps = connection.prepareStatement("insert into " +
helper.getTableNameWithSchema(schemaMapper.getTableName(ADETable.BUILDING)) + " " +
"(id, type, type_codespace, is_protected, constr_weight, constr_weight_codespace, attic_thm_status, basement_thm_status) " +
"values (?, ?, ?, ?, ?, ?, ?, ?)");
geometryConverter = helper.getGeometryConverter();
abstractQualifiedAttributeImporter = manager.getImporter(AbstractQualifiedAttributeImporter.class);
refurbishmentMeasureImporter = manager.getImporter(RefurbishmentMeasureImporter.class);
}
public void doImport(ADEPropertyCollection properties, AbstractBuilding abstractBuilding, long parentId, FeatureType parentType) throws CityGMLImportException, SQLException {
ps.setLong(1, parentId);
setBuildingNull();
if (properties.contains(BuildingTypeProperty.class)){
for (BuildingTypeProperty propertyElement : properties.getAll(BuildingTypeProperty.class)) {
String type = propertyElement.getValue().getValue();
ps.setString(2, type);
String typeCodeSpace = propertyElement.getValue().getCodeSpace();
ps.setString(3, typeCodeSpace);
}
}
if (properties.contains(BuildingIsProtectedProperty.class)) {
for (BuildingIsProtectedProperty propertyElement : properties.getAll(BuildingIsProtectedProperty.class)) {
Boolean isProtected = propertyElement.getValue();
ps.setInt(4, (isProtected != null && isProtected) ? 1 : 0);
}
}
if (properties.contains(BuildingConstructionWeightProperty.class)) {
for (BuildingConstructionWeightProperty propertyElement : properties.getAll(BuildingConstructionWeightProperty.class)) {
String weight = propertyElement.getValue().getValue();
ps.setString(5, weight);
String weightCodeSpace = propertyElement.getValue().getCodeSpace();
ps.setString(6, weightCodeSpace);
}
}
if (properties.contains(BuildingAtticThermalStatusProperty.class)) {
for (BuildingAtticThermalStatusProperty propertyElement : properties.getAll(BuildingAtticThermalStatusProperty.class)) {
String atticThermalStatus = propertyElement.getValue().value();
ps.setString(7, atticThermalStatus);
}
}
if (properties.contains(BuildingBasementThermalStatusProperty.class)){
for (BuildingBasementThermalStatusProperty propertyElement : properties.getAll(BuildingBasementThermalStatusProperty.class)) {
String buildingBasementThermalStatus = propertyElement.getValue().value();
ps.setString(8, buildingBasementThermalStatus);
}
}
if (properties.contains(QualifiedAreaProperty.class)){
for (QualifiedAreaProperty propertyElement : properties.getAll(QualifiedAreaProperty.class)) {
QualifiedAreaType qualifiedArea = propertyElement.getValue().getQualifiedArea();
if (qualifiedArea != null) {
abstractQualifiedAttributeImporter.doImport(qualifiedArea, parentId);
}
}
}
if (properties.contains(QualifiedHeightProperty.class)){
for (QualifiedHeightProperty propertyElement : properties.getAll(QualifiedHeightProperty.class)) {
QualifiedHeightType qualifiedHeightType = propertyElement.getValue().getQualifiedHeight();
if (qualifiedHeightType != null) {
abstractQualifiedAttributeImporter.doImport(qualifiedHeightType, parentId);
}
}
}
if (properties.contains(QualifiedVolumeProperty.class)){
for (QualifiedVolumeProperty propertyElement : properties.getAll(QualifiedVolumeProperty.class)) {
QualifiedVolumeType qualifiedVolumeType = propertyElement.getValue().getQualifiedVolume();
if (qualifiedVolumeType != null) {
abstractQualifiedAttributeImporter.doImport(qualifiedVolumeType, parentId);
}
}
}
if (properties.contains(RefurbishmentMeasureProperty.class)){
for (RefurbishmentMeasureProperty propertyElement : properties.getAll(RefurbishmentMeasureProperty.class)) {
RefurbishmentMeasure refurbishmentMeasure = propertyElement.getRefurbishmentMeasure();
if (refurbishmentMeasure != null) {
helper.importObject(refurbishmentMeasure, ForeignKeys.create().with("buildingId", parentId));
}
}
}
// if (properties.contains(UsageZoneProperty.class)) {
// for (UsageZoneProperty propertyElement : properties.getAll(UsageZoneProperty.class)) {
// AbstractUsageZone usageZone = propertyElement.getValue().getAbstractUsageZone();
// if (usageZone != null) {
// helper.importObject(usageZone, ForeignKeys.create().with("buildingId", parentId));
// propertyElement.getValue().unsetAbstractUsageZone();
// } else {
// String href = propertyElement.getValue().getHref();
// if (href != null && href.length() != 0)
// helper.logOrThrowUnsupportedXLinkMessage(parent, AbstractUsageZone.class, href);
// }
// }
// }
//
// if (properties.contains(ThermalZonePropertyElement.class)) {
// for (ThermalZonePropertyElement propertyElement : properties.getAll(ThermalZonePropertyElement.class)) {
// AbstractThermalZone thermalZone = propertyElement.getValue().getAbstractThermalZone();
// if (thermalZone != null) {
// helper.importObject(thermalZone, ForeignKeys.create().with("buildingId", parentId));
// propertyElement.getValue().unsetAbstractThermalZone();
// } else {
// String href = propertyElement.getValue().getHref();
// if (href != null && href.length() != 0)
// helper.logOrThrowUnsupportedXLinkMessage(parent, AbstractThermalZone.class, href);
// }
// }
// }
ps.addBatch();
if (++batchCounter == helper.getDatabaseAdapter().getMaxBatchSize())
helper.executeBatch(schemaMapper.getTableName(ADETable.BUILDING));
}
private void setBuildingNull() throws SQLException {
ps.setNull(2, Types.VARCHAR);
ps.setNull(3, Types.VARCHAR);
ps.setNull(4, Types.INTEGER);
ps.setNull(5, Types.VARCHAR);
ps.setNull(6, Types.VARCHAR);
ps.setNull(7, Types.VARCHAR);
ps.setNull(8, Types.VARCHAR);
}
@Override
public void executeBatch() throws CityGMLImportException, SQLException {
if (batchCounter > 0) {
ps.executeBatch();
batchCounter = 0;
}
}
@Override
public void close() throws CityGMLImportException, SQLException {
ps.close();
}
}
/*
* 3D City Database - The Open Source CityGML Database
* https://www.3dcitydb.org/
*
* Copyright 2013 - 2024
* Chair of Geoinformatics
* Technical University of Munich, Germany
* https://www.lrg.tum.de/gis/
*
* The 3D City Database is jointly developed with the following
* cooperation partners:
*
* Virtual City Systems, Berlin <https://vc.systems/>
* M.O.S.S. Computer Grafik Systeme GmbH, Taufkirchen <http://www.moss.de/>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.stuttgart.hft.ade.energy2.importer;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import de.stuttgart.hft.ade.energy2.schema.SchemaMapper;
import org.citydb.config.geometry.GeometryObject;
import org.citydb.core.ade.importer.ADEImporter;
import org.citydb.core.ade.importer.ADEPropertyCollection;
import org.citydb.core.ade.importer.CityGMLImportHelper;
import org.citydb.core.ade.importer.ForeignKeys;
import org.citydb.core.database.schema.mapping.FeatureType;
import org.citydb.core.operation.importer.CityGMLImportException;
import org.citygml4j.ade.energy.model.core.*;
import org.citygml4j.ade.energy.model.supportingClasses.*;
import org.citygml4j.model.citygml.core.AbstractCityObject;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class CityObjectPropertiesImporter implements ADEImporter {
private final CityGMLImportHelper helper;
private final SchemaMapper schemaMapper;
private final ImportManager manager;
private PreparedStatement ps;
private int batchCounter;
private Connection connection;
public CityObjectPropertiesImporter(Connection connection, CityGMLImportHelper helper, ImportManager manager) throws CityGMLImportException, SQLException {
this.helper = helper;
this.schemaMapper = manager.getSchemaMapper();
this.manager = manager;
this.connection=connection;
ps = connection.prepareStatement("insert into " +
helper.getTableNameWithSchema(schemaMapper.getTableName(ADETable.CITYOBJECT)) + " " +
"(id, ref_point) " +
"values (?,?)");
}
public void doImport(ADEPropertyCollection properties, AbstractCityObject parent, long parentId, FeatureType parentType) throws CityGMLImportException, SQLException {
ps.setLong(1, parentId);
GeometryObject geometryObject = null;
ReferencePointProperty referencePoint = properties.getFirst(ReferencePointProperty.class);
if (referencePoint != null && referencePoint.isSetValue())
geometryObject = helper.getGeometryConverter().getPoint(referencePoint.getValue());
if (geometryObject != null)
ps.setObject(2, helper.getDatabaseAdapter().getGeometryConverter().getDatabaseObject(geometryObject, connection));
else
ps.setNull(2, helper.getDatabaseAdapter().getGeometryConverter().getNullGeometryType(),
helper.getDatabaseAdapter().getGeometryConverter().getNullGeometryTypeName());
ps.addBatch();
if (++batchCounter == helper.getDatabaseAdapter().getMaxBatchSize())
helper.executeBatch(schemaMapper.getTableName(ADETable.CITYOBJECT));
if (properties.contains(AbstractResourceProperty.class)) {
for (AbstractResourceProperty propertyElement : properties.getAll(AbstractResourceProperty.class)) {
AbstractResource resource = propertyElement.getAbstractResource();
if (resource != null) {
helper.importObject(resource, ForeignKeys.create().with("cityObjectId", parentId));
propertyElement.unsetAbstractResource();
} else {
String href = propertyElement.getHref();
if (href != null && href.length() != 0)
helper.logOrThrowUnsupportedXLinkMessage(parent, AbstractResource.class, href);
}
}
}
if (properties.contains(EnergyProperty.class)) {
for (EnergyProperty propertyElement : properties.getAll(EnergyProperty.class)) {
Energy energyDemand = propertyElement.getEnergy();
if (energyDemand != null) {
helper.importObject(energyDemand, ForeignKeys.create().with("cityObjectId", parentId));
propertyElement.unsetEnergy();
} else {
String href = propertyElement.getHref();
if (href != null && href.length() != 0)
helper.logOrThrowUnsupportedXLinkMessage(parent, Energy.class, href);
}
}
}
if (properties.contains(WeatherDataProperty.class)) {
for (WeatherDataProperty propertyElement : properties.getAll(WeatherDataProperty.class)) {
WeatherData weatherData = propertyElement.getWeatherData();
if (weatherData != null) {
helper.importObject(weatherData, ForeignKeys.create().with("cityObjectId", parentId));
propertyElement.unsetWeatherData();
} else {
String href = propertyElement.getHref();
if (href != null && href.length() != 0)
helper.logOrThrowUnsupportedXLinkMessage(parent, WeatherData.class, href);
}
}
}
}
@Override
public void executeBatch() throws CityGMLImportException, SQLException {
if (batchCounter > 0) {
ps.executeBatch();
batchCounter = 0;
}
}
@Override
public void close() throws CityGMLImportException, SQLException {
ps.close();
}
}
package de.stuttgart.hft.ade.energy2.importer;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import org.citydb.core.ade.importer.ADEImporter;
import org.citydb.core.ade.importer.CityGMLImportHelper;
import org.citydb.core.ade.importer.ForeignKeys;
import org.citydb.core.database.schema.mapping.AbstractObjectType;
import org.citydb.core.operation.importer.CityGMLImportException;
import org.citydb.core.operation.importer.util.GeometryConverter;
import org.citygml4j.ade.energy.model.core.CityObjectRelation;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class CityObjectRelationImporter implements ADEImporter {
private final Connection connection;
private final CityGMLImportHelper helper;
private GeometryConverter geometryConverter;
private PreparedStatement ps;
private int batchCounter;
public CityObjectRelationImporter(Connection connection, CityGMLImportHelper helper, ImportManager manager) throws CityGMLImportException, SQLException {
this.connection = connection;
this.helper = helper;
ps = connection.prepareStatement("INSERT INTO " +
helper.getTableNameWithSchema(manager.getSchemaMapper().getTableName(ADETable.UTL_NTW_CONNECTION)) + " " +
"(id, ng2_cityobject_id, cityobject_id, relation_type, relation_type_codespace) " +
"VALUES (?, ?, ?, ?, ?)");
geometryConverter = helper.getGeometryConverter();
}
public void doImport(CityObjectRelation cityObjectRelation, long objectId, AbstractObjectType<?> objectType, ForeignKeys foreignKeys) throws CityGMLImportException, SQLException {
ps.setLong(1, objectId);
if (cityObjectRelation.isSetRelation()) {
ps.setString(4, cityObjectRelation.getRelationType().getValue());
ps.setString(5, cityObjectRelation.getRelationType().getCodeSpace());
}
//set correctly
ps.setLong(2, objectType.getObjectClassId());
ps.setLong(3, objectType.getObjectClassId());
ps.addBatch();
if (++batchCounter == helper.getDatabaseAdapter().getMaxBatchSize())
helper.executeBatch(objectType);
}
@Override
public void executeBatch() throws CityGMLImportException, SQLException {
if (batchCounter > 0) {
ps.executeBatch();
batchCounter = 0;
}
}
@Override
public void close() throws CityGMLImportException, SQLException {
ps.close();
}
}
package de.stuttgart.hft.ade.energy2.importer;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import de.stuttgart.hft.ade.energy2.schema.SchemaMapper;
import org.citydb.core.ade.importer.ADEImporter;
import org.citydb.core.ade.importer.CityGMLImportHelper;
import org.citydb.core.ade.importer.ForeignKeys;
import org.citydb.core.database.schema.mapping.AbstractObjectType;
import org.citydb.core.operation.importer.CityGMLImportException;
import org.citygml4j.ade.energy.model.core.DeviceOperation;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class DeviceOperationImporter implements ADEImporter {
private final CityGMLImportHelper helper;
private final SchemaMapper schemaMapper;
private PreparedStatement ps;
private int batchCounter;
public DeviceOperationImporter(Connection connection, CityGMLImportHelper helper, ImportManager manager) throws CityGMLImportException, SQLException {
this.helper = helper;
this.schemaMapper = manager.getSchemaMapper();
ps = connection.prepareStatement("insert into " +
helper.getTableNameWithSchema(schemaMapper.getTableName(ADETable.DEVICE_OPERATION)) + " " +
"(id, type, type_codespace, yearly_global_efficiency, schedule_id, device_id) " +
"values (?, ?, ?, ?, ?,?)");
}
public void doImport(DeviceOperation deviceOperation, long objectId, AbstractObjectType<?> objectType, ForeignKeys foreignKeys) throws CityGMLImportException, SQLException {
ps.setLong(1, objectId);
ps.setString(2,
deviceOperation.getType() != null ?
deviceOperation.getType().getValue() : null);
ps.setString(3,
deviceOperation.getType() != null ?
deviceOperation.getType().getCodeSpace() : null);
ps.setDouble(4,
deviceOperation.getYearlyGlobalEfficiency() != null ?
deviceOperation.getYearlyGlobalEfficiency() : 0.0);
}
@Override
public void executeBatch() throws CityGMLImportException, SQLException {
if (batchCounter > 0) {
ps.executeBatch();
batchCounter = 0;
}
}
@Override
public void close() throws CityGMLImportException, SQLException {
ps.close();
}
}
package de.stuttgart.hft.ade.energy2.importer;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import org.citydb.config.geometry.GeometryObject;
import org.citydb.core.ade.importer.ADEImporter;
import org.citydb.core.ade.importer.CityGMLImportHelper;
import org.citydb.core.ade.importer.ForeignKeys;
import org.citydb.core.database.schema.mapping.AbstractObjectType;
import org.citydb.core.operation.importer.CityGMLImportException;
import org.citydb.core.operation.importer.util.GeometryConverter;
import org.citygml4j.ade.energy.model.core.EnergyPerformanceCertificate;
import javax.xml.datatype.XMLGregorianCalendar;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Collections;
public class EnergyPerformanceCertificateImporter implements ADEImporter {
private final Connection connection;
private final CityGMLImportHelper helper;
private GeometryConverter geometryConverter;
private PreparedStatement ps;
private int batchCounter;
public EnergyPerformanceCertificateImporter(Connection connection, CityGMLImportHelper helper, ImportManager manager) throws CityGMLImportException, SQLException {
this.connection = connection;
this.helper = helper;
PreparedStatement ps = connection.prepareStatement(
"INSERT INTO " + helper.getTableNameWithSchema(manager.getSchemaMapper().getTableName(ADETable.ENERGY_PERF_CERT)) +
" (id, type, type_codespace, label, value, value_uom, issue_date, expiration_date, cert_method, cert_uri, cityobject_id) " +
"VALUES (" + String.join(", ", Collections.nCopies(11, "?")) + ")"
);
geometryConverter = helper.getGeometryConverter();
}
public void doImport(EnergyPerformanceCertificate energyPerformanceCertificate, long objectId, AbstractObjectType<?> objectType, ForeignKeys foreignKeys) throws CityGMLImportException, SQLException {
ps.setLong(1, objectId);
if (energyPerformanceCertificate.isSetType()) {
ps.setString(2, energyPerformanceCertificate.getType().getValue());
ps.setString(3, energyPerformanceCertificate.getType().getCodeSpace());
}
if (energyPerformanceCertificate.isSetLabel())
ps.setString(4, energyPerformanceCertificate.getLabel());
if (energyPerformanceCertificate.isSetValue()){
ps.setDouble(5, energyPerformanceCertificate.getValue().getValue());
ps.setString(6, energyPerformanceCertificate.getValue().getUom());
}
if (energyPerformanceCertificate.isSetIssueDate()){
XMLGregorianCalendar xmlCal = energyPerformanceCertificate.getIssueDate();
Timestamp timestamp = new Timestamp(xmlCal.toGregorianCalendar().getTimeInMillis());
ps.setTimestamp(7, timestamp);
}
if (energyPerformanceCertificate.isSetExpirationDate()){
XMLGregorianCalendar xmlCal = energyPerformanceCertificate.getExpirationDate();
Timestamp timestamp = new Timestamp(xmlCal.toGregorianCalendar().getTimeInMillis());
ps.setTimestamp(8, timestamp);
}
if (energyPerformanceCertificate.isSetCertificationMethod())
ps.setString(9, energyPerformanceCertificate.getCertificationMethod());
if (energyPerformanceCertificate.isSetCertificationURI())
ps.setString(10, energyPerformanceCertificate.getCertificationURI().toString());
ps.setLong(11, objectId);
ps.addBatch();
if (++batchCounter == helper.getDatabaseAdapter().getMaxBatchSize())
helper.executeBatch(objectType);
}
@Override
public void executeBatch() throws CityGMLImportException, SQLException {
if (batchCounter > 0) {
ps.executeBatch();
batchCounter = 0;
}
}
@Override
public void close() throws CityGMLImportException, SQLException {
ps.close();
}
}
/*
* 3D City Database - The Open Source CityGML Database
* https://www.3dcitydb.org/
*
* Copyright 2013 - 2024
* Chair of Geoinformatics
* Technical University of Munich, Germany
* https://www.lrg.tum.de/gis/
*
* The 3D City Database is jointly developed with the following
* cooperation partners:
*
* Virtual City Systems, Berlin <https://vc.systems/>
* M.O.S.S. Computer Grafik Systeme GmbH, Taufkirchen <http://www.moss.de/>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.stuttgart.hft.ade.energy2.importer;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import de.stuttgart.hft.ade.energy2.schema.SchemaMapper;
import org.citydb.core.ade.ADEExtension;
import org.citydb.core.ade.importer.*;
import org.citydb.core.database.schema.mapping.AbstractObjectType;
import org.citydb.core.database.schema.mapping.FeatureType;
import org.citydb.core.operation.importer.CityGMLImportException;
import org.citygml4j.ade.energy.model.core.*;
import org.citygml4j.ade.energy.model.supportingClasses.*;
import org.citygml4j.model.citygml.ade.binding.ADEModelObject;
import org.citygml4j.model.citygml.building.AbstractBuilding;
import org.citygml4j.model.citygml.core.AbstractCityObject;
import org.citygml4j.model.gml.feature.AbstractFeature;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class ImportManager implements ADEImportManager {
private final ADEExtension adeExtension;
private final Map<Class<? extends ADEImporter>, ADEImporter> importers;
private final SchemaMapper schemaMapper;
private Connection connection;
private CityGMLImportHelper helper;
public ImportManager(ADEExtension adeExtension, SchemaMapper schemaMapper) {
this.adeExtension = adeExtension;
this.schemaMapper = schemaMapper;
importers = new HashMap<>();
}
@Override
public void init(Connection connection, CityGMLImportHelper helper) throws CityGMLImportException, SQLException {
this.connection = connection;
this.helper = helper;
}
@Override
public void importObject(ADEModelObject object, long objectId, AbstractObjectType<?> objectType, ForeignKeys foreignKeys) throws CityGMLImportException, SQLException {
if(object instanceof AbstractTimeSeries)
getImporter(TimeSeriesImporter.class).doImport((AbstractTimeSeries) object, objectId, objectType, foreignKeys);
else if (object instanceof AbstractDevice)
getImporter(AbstractDeviceImporter.class).doImport((AbstractDevice) object, objectId, objectType, foreignKeys);
else if (object instanceof DeviceOperation)
getImporter(DeviceOperationImporter.class).doImport((DeviceOperation) object, objectId, objectType, foreignKeys);
else if (object instanceof AbstractResource)
getImporter(ResourceImporter.class).doImport((AbstractResource) object, objectId, objectType, foreignKeys);
else if(object instanceof UrbanFunctionArea)
getImporter(UrbanFunctionAreaImporter.class).doImport((UrbanFunctionArea) object, objectId, objectType, foreignKeys);
else if(object instanceof RefurbishmentMeasure)
getImporter(RefurbishmentMeasureImporter.class).doImport((RefurbishmentMeasure) object, objectId, objectType, foreignKeys);
else if(object instanceof WeatherStation)
getImporter(WeatherStationImporter.class).doImport((WeatherStation) object, objectId, objectType, foreignKeys);
else if (object instanceof WeatherData)
getImporter(WeatherDataImporter.class).doImport((WeatherData) object, objectId, objectType, foreignKeys);
}
@Override
public void importGenericApplicationProperties(ADEPropertyCollection properties, AbstractFeature parent, long parentId, FeatureType parentType) throws CityGMLImportException, SQLException {
if (parent instanceof AbstractCityObject)
getImporter(CityObjectPropertiesImporter.class).doImport(properties, (AbstractCityObject) parent, parentId, parentType);
if (parent instanceof AbstractBuilding
&& properties.containsOneOf(QualifiedHeightProperty.class,
QualifiedAreaProperty.class, QualifiedVolumeProperty.class, RefurbishmentMeasureProperty.class))
getImporter(BuildingPropertiesImporter.class).doImport(properties,(AbstractBuilding) parent, parentId, parentType);
}
@Override
public void executeBatch(String tableName) throws CityGMLImportException, SQLException {
ADETable adeTable = schemaMapper.fromTableName(tableName);
if (adeTable != null) {
ADEImporter importer = importers.get(adeTable.getImporterClass());
if (importer != null)
importer.executeBatch();
} else
throw new CityGMLImportException("The table " + tableName + " not managed by the ADE extension for '" + adeExtension.getMetadata().getIdentifier() + "'.");
}
@Override
public void close() throws CityGMLImportException, SQLException {
for (ADEImporter importer : importers.values())
importer.close();
}
protected SchemaMapper getSchemaMapper() {
return schemaMapper;
}
protected <T extends ADEImporter> T getImporter(Class<T> type) throws CityGMLImportException, SQLException {
ADEImporter importer = importers.get(type);
if (importer == null) {
if(type== AbstractDeviceImporter.class)
importer = new AbstractDeviceImporter(connection, helper, this);
else if(type== CityObjectPropertiesImporter.class)
importer = new CityObjectPropertiesImporter(connection, helper, this);
else if(type== DeviceOperationImporter.class)
importer = new DeviceOperationImporter(connection, helper, this);
else if(type== TimeSeriesImporter.class)
importer = new TimeSeriesImporter(connection, helper, this);
else if(type== ResourceImporter.class)
importer = new ResourceImporter(connection, helper, this);
// else if(type== WaterImporter.class)
// importer = new WaterImporter(connection, helper, this);
else if(type == UrbanFunctionAreaImporter.class)
importer = new UrbanFunctionAreaImporter(connection, helper, this);
else if (type == WeatherStationImporter.class)
importer = new WeatherStationImporter(connection, helper, this);
else if (type == WeatherDataImporter.class)
importer = new WeatherDataImporter(connection, helper, this);
else if (type == RefurbishmentMeasureImporter.class)
importer = new RefurbishmentMeasureImporter(connection, helper, this);
else if (type == BuildingPropertiesImporter.class)
importer = new BuildingPropertiesImporter(connection, helper, this);
else if (type == AbstractQualifiedAttributeImporter.class)
importer = new AbstractQualifiedAttributeImporter(connection, helper, this);
else throw new SQLException("Failed to build ADE importer of type " + type.getName() + ".");
importers.put(type, importer);
}
return type.cast(importer);
}
}
package de.stuttgart.hft.ade.energy2.importer;
import de.stuttgart.hft.ade.energy2.schema.ADESequence;
import de.stuttgart.hft.ade.energy2.schema.ADETable;
import de.stuttgart.hft.ade.energy2.schema.SchemaMapper;
import org.citydb.core.ade.importer.ADEImporter;
import org.citydb.core.ade.importer.CityGMLImportHelper;
import org.citydb.core.ade.importer.ForeignKeys;
import org.citydb.core.database.schema.mapping.AbstractObjectType;
import org.citydb.core.operation.importer.CityGMLImportException;
import org.citydb.core.operation.importer.util.GeometryConverter;
import org.citygml4j.ade.energy.model.core.RefurbishmentMeasure;
import javax.xml.datatype.XMLGregorianCalendar;
import java.sql.*;
public class RefurbishmentMeasureImporter implements ADEImporter {
private final Connection connection;
private final CityGMLImportHelper helper;
private SchemaMapper schemaMapper;
private GeometryConverter geometryConverter;
private PreparedStatement ps;
private int batchCounter;
public RefurbishmentMeasureImporter(Connection connection, CityGMLImportHelper helper, ImportManager manager) throws CityGMLImportException, SQLException {
this.connection = connection;
this.helper = helper;
this.schemaMapper = manager.getSchemaMapper();
ps = connection.prepareStatement("insert into " +
helper.getTableNameWithSchema(manager.getSchemaMapper().getTableName(ADETable.REFURBISHMENT_MEASURE)) + " " +
"(id, type, type_codespace, start_date, end_date, library_code, library_code_codespace, building_id, building_partition_id) " +
"values (?, ?, ?, ?, ?, ?, ?, ?, ?)");
geometryConverter = helper.getGeometryConverter();
}
public void doImport(RefurbishmentMeasure refurbishmentMeasure, long objectId, AbstractObjectType<?> objectType, ForeignKeys foreignKeys) throws CityGMLImportException, SQLException {
ps.setLong(1, objectId);
setRefurbishmentNull(refurbishmentMeasure);
if (refurbishmentMeasure.isSetType()) {
ps.setString(2, refurbishmentMeasure.getType().getValue());
ps.setString(3, refurbishmentMeasure.getType().getCodeSpace());
}
if (refurbishmentMeasure.isSetStartDate()) {
XMLGregorianCalendar xmlCal = refurbishmentMeasure.getStartDate();
Timestamp timestamp = new Timestamp(xmlCal.toGregorianCalendar().getTimeInMillis());
ps.setTimestamp(4, timestamp);
}
if (refurbishmentMeasure.isSetEndDate()) {
XMLGregorianCalendar xmlCal = refurbishmentMeasure.getEndDate();
Timestamp timestamp = new Timestamp(xmlCal.toGregorianCalendar().getTimeInMillis());
ps.setTimestamp(5, timestamp);
}
if (refurbishmentMeasure.isSetLibraryCode()) {
ps.setString(6, refurbishmentMeasure.getLibraryCode().getValue());
ps.setString(7, refurbishmentMeasure.getLibraryCode().getCodeSpace());
}
ps.setLong(8, foreignKeys.get("buildingId")); //building id
ps.setNull(9, Types.BIGINT); //building partionId is null
ps.addBatch();
if (++batchCounter == helper.getDatabaseAdapter().getMaxBatchSize())
helper.executeBatch(schemaMapper.getTableName(ADETable.REFURBISHMENT_MEASURE));
}
private void setRefurbishmentNull(RefurbishmentMeasure refurbishmentMeasure) throws SQLException {
ps.setNull(2, Types.VARCHAR); // type
ps.setNull(3, Types.VARCHAR); // type_codespace
ps.setNull(4, Types.DATE); // start_date
ps.setNull(5, Types.DATE); // end_date
ps.setNull(6, Types.VARCHAR); // library_code
ps.setNull(7, Types.VARCHAR); // library_code_codespace
ps.setNull(8, Types.BIGINT); // building_id
ps.setNull(9, Types.BIGINT); // building_partition_id
}
@Override
public void executeBatch() throws CityGMLImportException, SQLException {
if (batchCounter > 0) {
ps.executeBatch();
batchCounter = 0;
}
}
@Override
public void close() throws CityGMLImportException, SQLException {
ps.close();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment