Commit d06b334b authored by PrabithaPrabhakaran's avatar PrabithaPrabhakaran
Browse files

Add SensorData imp and exp

parent 83e7fafd
...@@ -5,6 +5,7 @@ build/ ...@@ -5,6 +5,7 @@ build/
!**/src/test/**/build/ !**/src/test/**/build/
### IntelliJ IDEA ### ### IntelliJ IDEA ###
.idea/
.idea/modules.xml .idea/modules.xml
.idea/jarRepositories.xml .idea/jarRepositories.xml
.idea/compiler.xml .idea/compiler.xml
......
...@@ -9,10 +9,7 @@ import org.citydb.core.operation.exporter.CityGMLExportException; ...@@ -9,10 +9,7 @@ import org.citydb.core.operation.exporter.CityGMLExportException;
import org.citydb.core.query.filter.projection.ProjectionFilter; import org.citydb.core.query.filter.projection.ProjectionFilter;
import org.citygml4j.ade.energy3.model.core.*; import org.citygml4j.ade.energy3.model.core.*;
import org.citygml4j.ade.energy3.model.module.EnergyADEModule; import org.citygml4j.ade.energy3.model.module.EnergyADEModule;
import org.citygml4j.ade.energy3.model.supportingClasses.AbstractADEFeature; import org.citygml4j.ade.energy3.model.supportingClasses.*;
import org.citygml4j.ade.energy3.model.supportingClasses.AbstractADEFeatureProperty;
import org.citygml4j.ade.energy3.model.supportingClasses.AbstractFeatureWithLifeSpan;
import org.citygml4j.ade.energy3.model.supportingClasses.AbstractFeatureWithLifeSpanProperty;
import org.citygml4j.model.citygml.core.AbstractCityObject; import org.citygml4j.model.citygml.core.AbstractCityObject;
import org.citygml4j.model.gml.geometry.primitives.PointProperty; import org.citygml4j.model.gml.geometry.primitives.PointProperty;
...@@ -31,6 +28,7 @@ public class CityObjectPropertiesExporter implements ADEExporter { ...@@ -31,6 +28,7 @@ public class CityObjectPropertiesExporter implements ADEExporter {
private final Connection connection; private final Connection connection;
//private WeatherDataExporter weatherDataExporter; //private WeatherDataExporter weatherDataExporter;
private ResourceExporter resourceExporter; private ResourceExporter resourceExporter;
private SensorDataExporter sensorDataExporter;
private AbstractADEFeatureExporter adeFeatureExporter; private AbstractADEFeatureExporter adeFeatureExporter;
private AbstractFeatureWithLifeSpanExporter featureWithLifeSpanExporter; private AbstractFeatureWithLifeSpanExporter featureWithLifeSpanExporter;
private String module; private String module;
...@@ -71,6 +69,12 @@ public class CityObjectPropertiesExporter implements ADEExporter { ...@@ -71,6 +69,12 @@ public class CityObjectPropertiesExporter implements ADEExporter {
cityObject.addGenericApplicationPropertyOfCityObject(property); cityObject.addGenericApplicationPropertyOfCityObject(property);
} }
} }
if (projectionFilter.containsProperty("sensorData", module)) {
for (SensorData sensorData : sensorDataExporter.doExport(objectId)) {
SensorDataProperty property = new SensorDataProperty(sensorData);
cityObject.addGenericApplicationPropertyOfCityObject(property);
}
}
if (projectionFilter.containsProperty("abstractAdeFeature", module)) { if (projectionFilter.containsProperty("abstractAdeFeature", module)) {
for (AbstractADEFeature feature : adeFeatureExporter.doExport(objectId)) { for (AbstractADEFeature feature : adeFeatureExporter.doExport(objectId)) {
AbstractADEFeatureProperty property = new AbstractADEFeatureProperty(feature); AbstractADEFeatureProperty property = new AbstractADEFeatureProperty(feature);
......
package de.stuttgart.hft.ade.energy3.exporter;
import de.stuttgart.hft.ade.energy3.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.operation.exporter.CityGMLExportException;
import org.citygml4j.ade.energy3.model.supportingClasses.*;
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 SensorDataExporter implements ADEExporter {
private final CityGMLExportHelper helper;
private TimeSeriesExporter timeSeriesExporter;
private PreparedStatement ps;
public SensorDataExporter(Connection connection, CityGMLExportHelper helper, ExportManager manager)
throws CityGMLExportException, SQLException {
this.helper = helper;
String tableName = helper.getTableNameWithSchema(manager.getSchemaMapper().getTableName(ADETable.SENSOR_DATA));
String sql = "SELECT " + getColumnNames() + " FROM " + tableName + " WHERE cityobject_id = ?";
ps = connection.prepareStatement(sql);
timeSeriesExporter = manager.getExporter(TimeSeriesExporter.class);
}
public SensorDataExporter(CityGMLExportHelper helper) {
this.helper = helper;
}
public Collection<SensorData> doExport(long cityObjectId) throws CityGMLExportException, SQLException {
ps.setLong(1, cityObjectId);
try (ResultSet rs = ps.executeQuery()) {
Collection<SensorData> result = new ArrayList<>();
SensorData sensorData = null;
while (rs.next()) {
int id = rs.getInt(1);
int objectClassId = rs.getInt(2);
sensorData = helper.createObject(id, objectClassId, SensorData.class);
String type = rs.getString(3);
String typeCodespace = rs.getString(4);
sensorData.getType().setValue(type);
sensorData.getType().setCodeSpace(typeCodespace);
String valueType = rs.getString(4);
String valueTypeCodespace = rs.getString(5);
sensorData.getValueType().setValue(valueType);
sensorData.getValueType().setCodeSpace(valueTypeCodespace);
Double yearlyValue = rs.getObject(6) != null ? rs.getDouble(6) : null;
String yearlyValueUom = rs.getString(7);
sensorData.getYearlyValue().setValue(yearlyValue);
sensorData.getYearlyValue().setUom(yearlyValueUom);
Object pointObj = rs.getObject("position");
if (pointObj != null) {
GeometryObject point = helper.getDatabaseAdapter().getGeometryConverter().getPoint(pointObj);
if (point != null) {
PointProperty pointProperty = new PointProperty();
// pointProperty.setPoint(point);
sensorData.setPosition(pointProperty);
}
}
}
return result;
}
}
@Override
public void close() throws CityGMLExportException, SQLException {
ps.close();
}
private String getColumnNames() {
return "id, objectclass_id, type, type_codespace, value_type, value_type_codespace, " +
"yearly_value, yearly_value_uom, time_series_id, cityobject_id, position";
}
}
...@@ -30,6 +30,9 @@ ...@@ -30,6 +30,9 @@
//import java.util.ArrayList; //import java.util.ArrayList;
//import java.util.Collection; //import java.util.Collection;
// //
/*
Not a part of beta 8
*/
//public class WeatherDataExporter implements ADEExporter { //public class WeatherDataExporter implements ADEExporter {
// //
// private final CityGMLExportHelper helper; // private final CityGMLExportHelper helper;
......
...@@ -121,6 +121,19 @@ public class CityObjectPropertiesImporter implements ADEImporter { ...@@ -121,6 +121,19 @@ public class CityObjectPropertiesImporter implements ADEImporter {
} }
} }
} }
if (properties.contains(SensorDataProperty.class)) {
for (SensorDataProperty propertyElement : properties.getAll(SensorDataProperty.class)) {
SensorData sensorData = propertyElement.getSensorData();
if (sensorData != null) {
helper.importObject(sensorData, ForeignKeys.create().with("cityObjectId", parentId));
propertyElement.unsetSensorData();
} else {
String href = propertyElement.getHref();
if (href != null && href.length() != 0)
helper.logOrThrowUnsupportedXLinkMessage(parent, SensorData.class, href);
}
}
}
} }
@Override @Override
......
...@@ -151,7 +151,8 @@ public class ResourceImporter implements ADEImporter { ...@@ -151,7 +151,8 @@ public class ResourceImporter implements ADEImporter {
helper.executeBatch(objectType); helper.executeBatch(objectType);
} }
private void setAbstractResourceProperties(AbstractResource abstractResource) throws SQLException, CityGMLImportException { private void setAbstractResourceProperties(AbstractResource abstractResource)
throws SQLException, CityGMLImportException {
if (abstractResource.getStatus() != null) { if (abstractResource.getStatus() != null) {
ps.setString(7, abstractResource.getStatus().value()); ps.setString(7, abstractResource.getStatus().value());
...@@ -172,31 +173,42 @@ public class ResourceImporter implements ADEImporter { ...@@ -172,31 +173,42 @@ public class ResourceImporter implements ADEImporter {
ps.setString(14, abstractResource.getAmount().getUom()); ps.setString(14, abstractResource.getAmount().getUom());
} }
if (abstractResource.isSetTimeDependentAmount()){ if (abstractResource.isSetTimeDependentAmount()) {
long timeSeriesId = helper.importObject(abstractResource.getTimeDependentAmount().getAbstractTimeSeries(), null); long timeSeriesId = helper.importObject(
ps.setLong(15, timeSeriesId); abstractResource.getTimeDependentAmount().getAbstractTimeSeries(), null);
ps.setLong(35, timeSeriesId);
}
if (abstractResource.isSetTimeDependentCosts()) {
long timeSeriesId = helper.importObject(
abstractResource.getTimeDependentCosts().getAbstractTimeSeries(), null);
ps.setLong(36, timeSeriesId);
}
if (abstractResource.isSetTimeDependentYields()) {
long timeSeriesId = helper.importObject(
abstractResource.getTimeDependentYields().getAbstractTimeSeries(), null);
ps.setLong(37, timeSeriesId);
} }
// Handling boolean-to-numeric conversion
if (abstractResource.isSetAmountNormalized()) { if (abstractResource.isSetAmountNormalized()) {
ps.setInt(16, 1); // True -> 1 ps.setBoolean(15, true);
} else { } else {
ps.setInt(16, 0); ps.setBoolean(15, false);
} }
if (abstractResource.getNormalizationValue() != null) { if (abstractResource.getNormalizationParameter() != null) {
ps.setDouble(18, abstractResource.getNormalizationValue().getValue()); ps.setString(16, abstractResource.getNormalizationParameter());
ps.setString(19, abstractResource.getNormalizationValue().getUom());
} }
if (abstractResource.getNormalizationParameter() != null) { if (abstractResource.getNormalizationValue() != null) {
ps.setString(17, abstractResource.getNormalizationParameter()); ps.setDouble(17, abstractResource.getNormalizationValue().getValue());
ps.setString(18, abstractResource.getNormalizationValue().getUom());
} }
if (abstractResource.getCo2Equivalent() != null) { if (abstractResource.getCo2Equivalent() != null) {
ps.setDouble(20, abstractResource.getCo2Equivalent().getValue()); ps.setDouble(21, abstractResource.getCo2Equivalent().getValue());
ps.setString(21, abstractResource.getCo2Equivalent().getUom()); ps.setString(22, abstractResource.getCo2Equivalent().getUom());
} }
if (abstractResource.getYear() != null) { if (abstractResource.getYear() != null) {
...@@ -204,16 +216,23 @@ public class ResourceImporter implements ADEImporter { ...@@ -204,16 +216,23 @@ public class ResourceImporter implements ADEImporter {
} }
if (abstractResource.getCostsMoney() != null) { if (abstractResource.getCostsMoney() != null) {
ps.setDouble(22, abstractResource.getCostsMoney().getValue()); ps.setDouble(23, abstractResource.getCostsMoney().getValue());
ps.setString(23, abstractResource.getCostsMoney().getUom()); ps.setString(24, abstractResource.getCostsMoney().getUom());
} }
if (abstractResource.getYieldsMoney() != null) { if (abstractResource.getYieldsMoney() != null) {
ps.setDouble(24, abstractResource.getYieldsMoney().getValue());
ps.setString(25, abstractResource.getYieldsMoney().getUom()); ps.setDouble(25, abstractResource.getYieldsMoney().getValue());
ps.setString(26, abstractResource.getYieldsMoney().getUom());
} }
if (abstractResource.getReferencePeriodValue() != null) {
ps.setString(19, abstractResource.getReferencePeriodValue().getValue());
ps.setString(20, abstractResource.getReferencePeriodValue().getCodeSpace());
} }
}
private void setResourceToNull() throws SQLException { private void setResourceToNull() throws SQLException {
ps.setNull(1, Types.BIGINT); // id ps.setNull(1, Types.BIGINT); // id
...@@ -230,26 +249,31 @@ public class ResourceImporter implements ADEImporter { ...@@ -230,26 +249,31 @@ public class ResourceImporter implements ADEImporter {
ps.setNull(12, Types.VARCHAR); // amount_type_codespace ps.setNull(12, Types.VARCHAR); // amount_type_codespace
ps.setNull(13, Types.NUMERIC); // amount ps.setNull(13, Types.NUMERIC); // amount
ps.setNull(14, Types.VARCHAR); // amount_uom ps.setNull(14, Types.VARCHAR); // amount_uom
ps.setNull(15, Types.BIGINT); // time_series_id ps.setNull(15, Types.BOOLEAN); // is_amount_normalized
ps.setNull(16, Types.NUMERIC); // is_amount_normalized ps.setNull(16, Types.VARCHAR); // normalization_param
ps.setNull(17, Types.VARCHAR); // normalization_param ps.setNull(17, Types.NUMERIC); // normalization_value
ps.setNull(18, Types.NUMERIC); // normalization_value ps.setNull(18, Types.VARCHAR); // normalization_value_uom
ps.setNull(19, Types.VARCHAR); // normalization_value_uom ps.setNull(19, Types.VARCHAR); // ref_period
ps.setNull(20, Types.NUMERIC); // co2_equivalent ps.setNull(20, Types.VARCHAR); // ref_period_codespace
ps.setNull(21, Types.VARCHAR); // co2_equivalent_uom ps.setNull(21, Types.NUMERIC); // co2_equivalent
ps.setNull(22, Types.NUMERIC); // costs_money ps.setNull(22, Types.VARCHAR); // co2_equivalent_uom
ps.setNull(23, Types.VARCHAR); // costs_money_uom ps.setNull(23, Types.NUMERIC); // costs_money
ps.setNull(24, Types.NUMERIC); // yields_money ps.setNull(24, Types.VARCHAR); // costs_money_uom
ps.setNull(25, Types.NUMERIC); // yields_money_uom ps.setNull(25, Types.NUMERIC); // yields_money
ps.setNull(26, Types.VARCHAR); // energy_carrier ps.setNull(26, Types.VARCHAR); // yields_money_uom
ps.setNull(27, Types.VARCHAR); // energy_carrier_codespace ps.setNull(27, Types.VARCHAR); // energy_carrier
ps.setNull(28, Types.NUMERIC); // maximum_load ps.setNull(28, Types.VARCHAR); // energy_carrier_codespace
ps.setNull(29, Types.VARCHAR); // maximum_load_uom ps.setNull(29, Types.NUMERIC); // maximum_load
ps.setNull(30, Types.VARCHAR); // source ps.setNull(30, Types.VARCHAR); // maximum_load_uom
ps.setNull(31, Types.VARCHAR); // source_codespace ps.setNull(31, Types.VARCHAR); // source
ps.setNull(32, Types.NUMERIC); // is_dangerous ps.setNull(32, Types.VARCHAR); // source_codespace
ps.setNull(33, Types.NUMERIC); // is_recyclable ps.setNull(33, Types.BOOLEAN); // is_dangerous
ps.setNull(34, Types.BIGINT); // cityobject_id ps.setNull(34, Types.BOOLEAN); // is_recyclable
ps.setNull(35, Types.BIGINT); // amount_time_series_id
ps.setNull(36, Types.BIGINT); // costs_time_series_id
ps.setNull(37, Types.BIGINT); // yields_time_series_id
ps.setNull(38, Types.BIGINT); // cityobject_id
} }
......
package de.stuttgart.hft.ade.energy3.importer;
import de.stuttgart.hft.ade.energy3.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.energy3.model.supportingClasses.SensorData;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
public class SensorDataImporter implements ADEImporter {
private final Connection connection;
private final CityGMLImportHelper helper;
private GeometryConverter geometryConverter;
private PreparedStatement ps;
private int batchCounter;
public SensorDataImporter(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.SENSOR_DATA)) + " " +
"(id, objectclass_id, type, type_codespace, value_type, value_type_codespace,yearly_value," +
" yearly_value_uom, time_series_id, cityobject_id, position) " +
"values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
geometryConverter = helper.getGeometryConverter();
}
public void doImport(SensorData sensorData, long objectId, AbstractObjectType<?> objectType, ForeignKeys foreignKeys) throws CityGMLImportException, SQLException {
ps.setLong(1, objectId);
setSensorDataNull();
if (sensorData.isSetType()) {
ps.setString(3, sensorData.getType().getValue());
ps.setString(4, sensorData.getType().getCodeSpace());
}
if (sensorData.isSetValueType()){
ps.setString(5, sensorData.getValueType().getValue());
ps.setString(6, sensorData.getValueType().getCodeSpace());
}
if (sensorData.isSetYearlyValue()) {
ps.setDouble(7, sensorData.getYearlyValue().getValue());
ps.setString(8, sensorData.getYearlyValue().getUom());
}
if (sensorData.isSetPosition()) {
ps.setObject(9, sensorData.getPosition().getPoint());
}
ps.addBatch();
if (++batchCounter == helper.getDatabaseAdapter().getMaxBatchSize())
helper.executeBatch(objectType);
}
private void setSensorDataNull() 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.VARCHAR); // value_type
ps.setNull(6, Types.VARCHAR); // value_type_codespace
ps.setNull(7, Types.DOUBLE); // yearly_value
ps.setNull(8, Types.VARCHAR); // yearly_value_uom
ps.setNull(9, Types.BIGINT); // time_series_id
ps.setNull(10, Types.BIGINT); // cityobject_id
ps.setNull(11, Types.OTHER); // position (PostGIS geometry)
}
@Override
public void executeBatch() throws CityGMLImportException, SQLException {
if (batchCounter > 0) {
ps.executeBatch();
batchCounter = 0;
}
}
@Override
public void close() throws CityGMLImportException, SQLException {
ps.close();
}
}
...@@ -17,6 +17,9 @@ import java.sql.PreparedStatement; ...@@ -17,6 +17,9 @@ import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
/*
Not a part of beta 8
*/
public class WeatherDataImporter implements ADEImporter { public class WeatherDataImporter implements ADEImporter {
private final Connection connection; private final Connection connection;
...@@ -60,10 +63,10 @@ public class WeatherDataImporter implements ADEImporter { ...@@ -60,10 +63,10 @@ public class WeatherDataImporter implements ADEImporter {
ps.setString(7, weatherData.getYearlyValue().getUom()); ps.setString(7, weatherData.getYearlyValue().getUom());
} }
if (weatherData.isSetLibraryCode()){ // if (weatherData.isSetLibraryCode()){
ps.setString(8, weatherData.getLibraryCode().getValue()); // ps.setString(8, weatherData.getLibraryCode().getValue());
ps.setString(9, weatherData.getLibraryCode().getCodeSpace()); // ps.setString(9, weatherData.getLibraryCode().getCodeSpace());
} // }
if (cityObjectId != 0) { if (cityObjectId != 0) {
ps.setLong(11, cityObjectId); ps.setLong(11, cityObjectId);
...@@ -72,9 +75,9 @@ public class WeatherDataImporter implements ADEImporter { ...@@ -72,9 +75,9 @@ public class WeatherDataImporter implements ADEImporter {
if (weatherData.isSetPosition()){ if (weatherData.isSetPosition()){
GeometryObject geometryObject = null; GeometryObject geometryObject = null;
ReferencePointProperty referencePoint = weatherData.getPosition(); // ReferencePointProperty referencePoint = weatherData.getPosition();
if (referencePoint != null && referencePoint.isSetValue()) // if (referencePoint != null && referencePoint.isSetValue())
geometryObject = helper.getGeometryConverter().getPoint(referencePoint.getValue()); // geometryObject = helper.getGeometryConverter().getPoint(referencePoint.getValue());
if (geometryObject != null) if (geometryObject != null)
ps.setObject(12, helper.getDatabaseAdapter().getGeometryConverter().getDatabaseObject(geometryObject, connection)); ps.setObject(12, helper.getDatabaseAdapter().getGeometryConverter().getDatabaseObject(geometryObject, connection));
else else
......
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