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
...@@ -39,4 +40,4 @@ bin/ ...@@ -39,4 +40,4 @@ bin/
.vscode/ .vscode/
### Mac OS ### ### Mac OS ###
.DS_Store .DS_Store
\ No newline at end of file
...@@ -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);
......
...@@ -30,27 +30,33 @@ public class ResourceExporter implements ADEExporter { ...@@ -30,27 +30,33 @@ public class ResourceExporter implements ADEExporter {
timeSeriesExporter = manager.getExporter(TimeSeriesExporter.class); timeSeriesExporter = manager.getExporter(TimeSeriesExporter.class);
} }
public Collection<AbstractResource> doExport(long cityObjectId) throws CityGMLExportException, SQLException { public Collection<AbstractResource> doExport(long cityObjectId)
throws CityGMLExportException, SQLException {
ps.setLong(1, cityObjectId); ps.setLong(1, cityObjectId);
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
Collection<AbstractResource> result = new ArrayList<>(); Collection<AbstractResource> result = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
long objectId = rs.getLong(1); long objectId = rs.getLong(1);
int objectClassId = rs.getInt(2); int objectClassId = rs.getInt(2);
if (rs.wasNull()) { if (rs.wasNull())
continue; continue;
}
AbstractResource resource = helper.createObject(objectId, objectClassId, AbstractResource.class); AbstractResource resource =
helper.createObject(objectId, objectClassId, AbstractResource.class);
if (resource == null) { if (resource == null) {
helper.logOrThrowErrorMessage("Failed to instantiate " + helper.getObjectSignature(objectClassId, cityObjectId) + " as resource object."); helper.logOrThrowErrorMessage(
"Failed to instantiate "
+ helper.getObjectSignature(objectClassId, cityObjectId)
+ " as resource object.");
continue; continue;
} }
ObjectType objectType = helper.getObjectType(objectClassId);
ProjectionFilter projectionFilter = helper.getProjectionFilter(objectType);
// Set AbstractResource properties
String statusValue = rs.getString(7); String statusValue = rs.getString(7);
if (statusValue != null) { if (statusValue != null) {
resource.setStatus(ResourceStatusValueType.fromValue(statusValue)); resource.setStatus(ResourceStatusValueType.fromValue(statusValue));
...@@ -65,6 +71,11 @@ public class ResourceExporter implements ADEExporter { ...@@ -65,6 +71,11 @@ public class ResourceExporter implements ADEExporter {
resource.setOperationType(operationType); resource.setOperationType(operationType);
} }
int year = rs.getInt(10);
if (!rs.wasNull()) {
resource.setYear(year);
}
String amountValue = rs.getString(11); String amountValue = rs.getString(11);
String amountCodeSpace = rs.getString(12); String amountCodeSpace = rs.getString(12);
if (amountValue != null || amountCodeSpace != null) { if (amountValue != null || amountCodeSpace != null) {
...@@ -78,234 +89,237 @@ public class ResourceExporter implements ADEExporter { ...@@ -78,234 +89,237 @@ public class ResourceExporter implements ADEExporter {
if (!rs.wasNull()) { if (!rs.wasNull()) {
Measure amount = new Measure(); Measure amount = new Measure();
amount.setValue(amountVal); amount.setValue(amountVal);
String uom = rs.getString(14); amount.setUom(rs.getString(14));
if (uom != null) {
amount.setUom(uom);
}
amount.setParent(resource); amount.setParent(resource);
resource.setAmount(amount); resource.setAmount(amount);
} }
int normalized = rs.getInt(16); boolean normalized = rs.getBoolean(15);
if (!rs.wasNull()) { if (!rs.wasNull()) {
resource.setAmountNormalized(normalized == 1); resource.setAmountNormalized(normalized);
} }
String normalizationParam = rs.getString(17); String normalizationParam = rs.getString(16);
if (normalizationParam != null) { if (normalizationParam != null) {
resource.setNormalizationParameter(normalizationParam); resource.setNormalizationParameter(normalizationParam);
} }
double normVal = rs.getDouble(18); double normVal = rs.getDouble(17);
if (!rs.wasNull()) { if (!rs.wasNull()) {
Measure normalizationValue = new Measure(); Measure normalizationValue = new Measure();
normalizationValue.setParent(resource); normalizationValue.setParent(resource);
normalizationValue.setValue(normVal); normalizationValue.setValue(normVal);
String uom = rs.getString(19); normalizationValue.setUom(rs.getString(18));
if (uom != null) {
normalizationValue.setUom(uom);
}
resource.setNormalizationValue(normalizationValue); resource.setNormalizationValue(normalizationValue);
} }
double co2Val = rs.getDouble(20); String refPeriodVal = rs.getString(19);
String refPeriodCS = rs.getString(20);
if (refPeriodVal != null || refPeriodCS != null) {
Code refPeriod = new Code();
refPeriod.setValue(refPeriodVal);
refPeriod.setCodeSpace(refPeriodCS);
resource.setReferencePeriodValue(refPeriod);
}
double co2Val = rs.getDouble(21);
if (!rs.wasNull()) { if (!rs.wasNull()) {
Measure co2Equivalent = new Measure(); Measure co2Equivalent = new Measure();
co2Equivalent.setValue(co2Val); co2Equivalent.setValue(co2Val);
String uom = rs.getString(21); co2Equivalent.setUom(rs.getString(22));
if (uom != null) {
co2Equivalent.setUom(uom);
}
resource.setCo2Equivalent(co2Equivalent); resource.setCo2Equivalent(co2Equivalent);
} }
int year = rs.getInt(10); double costVal = rs.getDouble(23);
if (!rs.wasNull()) {
resource.setYear(year);
}
double costVal = rs.getDouble(22);
if (!rs.wasNull()) { if (!rs.wasNull()) {
Measure costsMoney = new Measure(); Measure costsMoney = new Measure();
costsMoney.setValue(costVal); costsMoney.setValue(costVal);
String uom = rs.getString(23); costsMoney.setUom(rs.getString(24));
if (uom != null) {
costsMoney.setUom(uom);
}
resource.setCostsMoney(costsMoney); resource.setCostsMoney(costsMoney);
} }
double yieldVal = rs.getDouble(24); double yieldVal = rs.getDouble(25);
if (!rs.wasNull()) { if (!rs.wasNull()) {
Measure yieldsMoney = new Measure(); Measure yieldsMoney = new Measure();
yieldsMoney.setValue(yieldVal); yieldsMoney.setValue(yieldVal);
String uom = rs.getString(25); yieldsMoney.setUom(rs.getString(26));
if (uom != null) {
yieldsMoney.setUom(uom);
}
resource.setYieldsMoney(yieldsMoney); resource.setYieldsMoney(yieldsMoney);
} }
long timeSeriesId = rs.getLong(15); long amountTS = rs.getLong(35);
if (timeSeriesId != 0 && timeSeriesExporter != null) { if (!rs.wasNull() && timeSeriesExporter != null) {
Collection<AbstractTimeSeries> timeSeries = timeSeriesExporter.doExport(timeSeriesId); Collection<AbstractTimeSeries> ts =
if (timeSeries != null && !timeSeries.isEmpty()) { timeSeriesExporter.doExport(amountTS);
AbstractTimeSeries firstSeries = timeSeries.iterator().next(); if (ts != null && !ts.isEmpty()) {
if (firstSeries != null) { resource.setTimeDependentAmount(
resource.setTimeDependentAmount(new AbstractTimeSeriesProperty(firstSeries)); new AbstractTimeSeriesProperty(ts.iterator().next()));
}
} }
} }
long costsTS = rs.getLong(36);
if (!rs.wasNull() && timeSeriesExporter != null) {
Collection<AbstractTimeSeries> ts =
timeSeriesExporter.doExport(costsTS);
if (resource instanceof Energy) { if (ts != null && !ts.isEmpty()) {
Energy energy = (Energy) resource; resource.setTimeDependentCosts(
String energyType = rs.getString(3); new AbstractTimeSeriesProperty(ts.iterator().next()));
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) { long yieldsTS = rs.getLong(37);
Code energyEndUseValue = new Code(); if (!rs.wasNull() && timeSeriesExporter != null) {
energyEndUseValue.setValue(energyEndUse); Collection<AbstractTimeSeries> ts =
energyEndUseValue.setCodeSpace(energyEndUseCodeSpace); timeSeriesExporter.doExport(yieldsTS);
energy.setEnergyEndUseValue(energyEndUseValue);
} if (ts != null && !ts.isEmpty()) {
String energyCarrier = rs.getString(26); resource.setTimeDependentYields(
String energyCarrierCodeSpace = rs.getString(27); new AbstractTimeSeriesProperty(ts.iterator().next()));
if (energyCarrier != null || energyCarrierCodeSpace != null) {
Code energyCarrierValue = new Code();
energyCarrierValue.setValue(energyCarrier);
energyCarrierValue.setCodeSpace(energyCarrierCodeSpace);
energy.setEnergyCarrierValue(energyCarrierValue);
} }
double maxLoadVal = rs.getDouble(28); }
if (resource instanceof Energy) {
Energy energy = (Energy) resource;
Code type = new Code();
type.setValue(rs.getString(3));
type.setCodeSpace(rs.getString(4));
energy.setEnergyTypeValue(type);
Code endUse = new Code();
endUse.setValue(rs.getString(5));
endUse.setCodeSpace(rs.getString(6));
energy.setEnergyEndUseValue(endUse);
Code carrier = new Code();
carrier.setValue(rs.getString(27));
carrier.setCodeSpace(rs.getString(28));
energy.setEnergyCarrierValue(carrier);
double maxLoad = rs.getDouble(29);
if (!rs.wasNull()) { if (!rs.wasNull()) {
Measure maximumLoad = new Measure(); Measure maximumLoad = new Measure();
maximumLoad.setValue(maxLoadVal); maximumLoad.setValue(maxLoad);
String uom = rs.getString(29); maximumLoad.setUom(rs.getString(30));
if (uom != null) {
maximumLoad.setUom(uom);
}
energy.setMaximumLoad(maximumLoad); energy.setMaximumLoad(maximumLoad);
} }
String energySource = rs.getString(30);
String energySourceCodeSpace = rs.getString(31); Code source = new Code();
if (energySource != null || energySourceCodeSpace != null) { source.setValue(rs.getString(31));
Code energySourceValue = new Code(); source.setCodeSpace(rs.getString(32));
energySourceValue.setValue(energySource); energy.setEnergySourceValue(source);
energySourceValue.setCodeSpace(energySourceCodeSpace); }
energy.setEnergySourceValue(energySourceValue);
} else if (resource instanceof Waste) {
} 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; Waste waste = (Waste) resource;
String wasteType = rs.getString(3);
String wasteTypeCodeSpace = rs.getString(4); boolean dangerous = rs.getBoolean(33);
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()) { if (!rs.wasNull()) {
waste.setAmountNormalized(isDangerous == 1); waste.setDangerous(dangerous);
} }
int recyclable = rs.getInt(33);
boolean recyclable = rs.getBoolean(34);
if (!rs.wasNull()) { if (!rs.wasNull()) {
waste.setRecyclable(recyclable == 1); waste.setRecyclable(recyclable);
} }
} else if (resource instanceof ConstructionMaterial) { }
else if (resource instanceof Water) {
Water water = (Water) resource;
String typeVal = rs.getString(3);
String typeCS = rs.getString(4);
if (typeVal != null || typeCS != null) {
Code type = new Code();
type.setValue(typeVal);
type.setCodeSpace(typeCS);
water.setWaterTypeValue(type);
}
String endUseVal = rs.getString(5);
String endUseCS = rs.getString(6);
if (endUseVal != null || endUseCS != null) {
Code endUse = new Code();
endUse.setValue(endUseVal);
endUse.setCodeSpace(endUseCS);
water.setWaterEndUseValue(endUse);
}
}
else if (resource instanceof ConstructionMaterial) {
ConstructionMaterial cm = (ConstructionMaterial) resource; ConstructionMaterial cm = (ConstructionMaterial) resource;
String type = rs.getString(3);
String typeCodeSpace = rs.getString(4); String typeVal = rs.getString(3);
if (type != null || typeCodeSpace != null) { String typeCS = rs.getString(4);
Code typeValue = new Code(); if (typeVal != null || typeCS != null) {
typeValue.setValue(type); Code type = new Code();
typeValue.setCodeSpace(typeCodeSpace); type.setValue(typeVal);
cm.setConstructionMaterialTypeValue(typeValue); type.setCodeSpace(typeCS);
cm.setConstructionMaterialTypeValue(type);
} }
String endUse = rs.getString(5);
String endUseCodeSpace = rs.getString(6); String endUseVal = rs.getString(5);
if (endUse != null || endUseCodeSpace != null) { String endUseCS = rs.getString(6);
Code endUseValue = new Code(); if (endUseVal != null || endUseCS != null) {
endUseValue.setValue(endUse); Code endUse = new Code();
endUseValue.setCodeSpace(endUseCodeSpace); endUse.setValue(endUseVal);
cm.setConstructionMaterialEndUseValue(endUseValue); endUse.setCodeSpace(endUseCS);
cm.setConstructionMaterialEndUseValue(endUse);
} }
} else if (resource instanceof Food) { }
else if (resource instanceof Food) {
Food food = (Food) resource; Food food = (Food) resource;
String foodType = rs.getString(3);
String foodTypeCodeSpace = rs.getString(4); String typeVal = rs.getString(3);
if (foodType != null || foodTypeCodeSpace != null) { String typeCS = rs.getString(4);
Code foodTypeValue = new Code(); if (typeVal != null || typeCS != null) {
foodTypeValue.setValue(foodType); Code type = new Code();
foodTypeValue.setCodeSpace(foodTypeCodeSpace); type.setValue(typeVal);
food.setFoodTypeValue(foodTypeValue); type.setCodeSpace(typeCS);
food.setFoodTypeValue(type);
} }
String foodEndUse = rs.getString(5);
String foodEndUseCodeSpace = rs.getString(6); String endUseVal = rs.getString(5);
if (foodEndUse != null || foodEndUseCodeSpace != null) { String endUseCS = rs.getString(6);
Code foodEndUseValue = new Code(); if (endUseVal != null || endUseCS != null) {
foodEndUseValue.setValue(foodEndUse); Code endUse = new Code();
foodEndUseValue.setCodeSpace(foodEndUseCodeSpace); endUse.setValue(endUseVal);
food.setFoodEndUseValue(foodEndUseValue); endUse.setCodeSpace(endUseCS);
food.setFoodEndUseValue(endUse);
} }
} else if (resource instanceof OtherResource) { }
else if (resource instanceof OtherResource) {
OtherResource other = (OtherResource) resource; OtherResource other = (OtherResource) resource;
String otherType = rs.getString(3);
String otherTypeCodeSpace = rs.getString(4); String typeVal = rs.getString(3);
if (otherType != null || otherTypeCodeSpace != null) { String typeCS = rs.getString(4);
Code otherTypeValue = new Code(); if (typeVal != null || typeCS != null) {
otherTypeValue.setValue(otherType); Code type = new Code();
otherTypeValue.setCodeSpace(otherTypeCodeSpace); type.setValue(typeVal);
other.setOtherResourceTypeValue(otherTypeValue); type.setCodeSpace(typeCS);
other.setOtherResourceTypeValue(type);
} }
String otherEndUse = rs.getString(5);
String otherEndUseCS = rs.getString(6); String endUseVal = rs.getString(5);
if (otherEndUse != null || otherEndUseCS != null) { String endUseCS = rs.getString(6);
Code otherEndUseValue = new Code(); if (endUseVal != null || endUseCS != null) {
otherEndUseValue.setValue(otherEndUse); Code endUse = new Code();
otherEndUseValue.setCodeSpace(otherEndUseCS); endUse.setValue(endUseVal);
other.setOtherResourceEndUseValue(otherEndUseValue); endUse.setCodeSpace(endUseCS);
other.setOtherResourceEndUseValue(endUse);
} }
} }
result.add(resource); result.add(resource);
} }
return result; return result;
} }
} }
@Override @Override
public void close() throws CityGMLExportException, SQLException { public void close() throws CityGMLExportException, SQLException {
ps.close(); ps.close();
...@@ -319,4 +333,4 @@ public class ResourceExporter implements ADEExporter { ...@@ -319,4 +333,4 @@ public class ResourceExporter implements ADEExporter {
"yields_money, yields_money_uom, energy_carrier, energy_carrier_codespace, maximum_load, " + "yields_money, yields_money_uom, energy_carrier, energy_carrier_codespace, maximum_load, " +
"maximum_load_uom, source, source_codespace, is_dangerous, is_recyclable, cityobject_id"; "maximum_load_uom, source, source_codespace, is_dangerous, is_recyclable, cityobject_id";
} }
} }
\ No newline at end of file
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;
...@@ -180,4 +183,4 @@ ...@@ -180,4 +183,4 @@
// public void close() throws CityGMLExportException, SQLException { // public void close() throws CityGMLExportException, SQLException {
// ps.close(); // ps.close();
// } // }
//} //}
\ No newline at end of file
...@@ -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,52 +216,64 @@ public class ResourceImporter implements ADEImporter { ...@@ -204,52 +216,64 @@ 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
ps.setNull(2, Types.INTEGER); // objectclass_id ps.setNull(2, Types.INTEGER); // objectclass_id
ps.setNull(3, Types.VARCHAR); // type ps.setNull(3, Types.VARCHAR); // type
ps.setNull(4, Types.VARCHAR); // type_codespace ps.setNull(4, Types.VARCHAR); // type_codespace
ps.setNull(5, Types.VARCHAR); // enduse ps.setNull(5, Types.VARCHAR); // enduse
ps.setNull(6, Types.VARCHAR); // enduse_codespace ps.setNull(6, Types.VARCHAR); // enduse_codespace
ps.setNull(7, Types.VARCHAR); // status ps.setNull(7, Types.VARCHAR); // status
ps.setNull(8, Types.VARCHAR); // operation_type ps.setNull(8, Types.VARCHAR); // operation_type
ps.setNull(9, Types.VARCHAR); // operation_type_codespace ps.setNull(9, Types.VARCHAR); // operation_type_codespace
ps.setNull(10, Types.INTEGER); // year ps.setNull(10, Types.INTEGER); // year
ps.setNull(11, Types.VARCHAR); // amount_type ps.setNull(11, Types.VARCHAR); // amount_type
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
...@@ -118,4 +121,4 @@ public class WeatherDataImporter implements ADEImporter { ...@@ -118,4 +121,4 @@ public class WeatherDataImporter implements ADEImporter {
public void close() throws CityGMLImportException, SQLException { public void close() throws CityGMLImportException, SQLException {
ps.close(); ps.close();
} }
} }
\ No newline at end of file
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