Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed export of global appearances when replacing IDs #276

Merged
merged 2 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,17 @@ public abstract class AbstractAppearanceExporter extends AbstractTypeExporter {
private final List<Table> appearanceADEHookTables;
private final List<Table> surfaceDataADEHookTables;

protected AbstractAppearanceExporter(boolean isGlobal, CacheTable cacheTable, CityGMLExportManager exporter, Config config) throws CityGMLExportException, SQLException {
enum Mode {
LOCAL,
GLOBAL,
GLOBAL_TO_LOCAL
}

protected AbstractAppearanceExporter(Mode mode, CacheTable cacheTable, CityGMLExportManager exporter, Config config) throws CityGMLExportException, SQLException {
super(exporter);

texImageIds = new HashSet<>();
lazyTextureImageExport = !isGlobal && exporter.isLazyTextureExport();
lazyTextureImageExport = mode == Mode.LOCAL && exporter.isLazyTextureExport();
exportTextureImage = exporter.getExportConfig().getAppearances().isSetExportTextureFiles();
uniqueFileNames = exporter.getExportConfig().getAppearances().isSetUniqueTextureFileNames();
noOfBuckets = exporter.getExportConfig().getAppearances().getTexturePath().getNoOfBuckets();
Expand Down Expand Up @@ -123,7 +129,7 @@ protected AbstractAppearanceExporter(boolean isGlobal, CacheTable cacheTable, Ci
appearanceADEHookTables = addJoinsToADEHookTables(TableEnum.APPEARANCE, table);
surfaceDataADEHookTables = addJoinsToADEHookTables(TableEnum.SURFACE_DATA, surfaceData);

if (isGlobal) {
if (mode == Mode.GLOBAL) {
Table tmp = new Table(cacheTable.getTableName());
select.addJoin(JoinFactory.inner(tmp, "id", ComparisonName.EQUAL_TO, textureParam.getColumn("surface_geometry_id")))
.addJoin(JoinFactory.inner(surfaceGeometry, "id", ComparisonName.EQUAL_TO, tmp.getColumn("id")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@ public AffineTransformer getAffineTransformer() {
return affineTransformer;
}

public IdReplacer getIdReplacer() {
return idReplacer;
}

public InternalConfig getInternalConfig() {
return internalConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@
public class DBGlobalAppearance extends AbstractAppearanceExporter {
private final PreparedStatement ps;
private final PreparedStatement psImport;
private final boolean replaceIds;

private int batchSize;
private int batchCounter;

public DBGlobalAppearance(CacheTable cacheTable, CityGMLExportManager exporter, Config config) throws CityGMLExportException, SQLException {
super(true, cacheTable, exporter, config);
super(Mode.GLOBAL, cacheTable, exporter, config);
ps = cacheTable.getConnection().prepareStatement(select.toString());

replaceIds = config.getExportConfig().getResourceId().isReplaceWithUUIDs();
String schema = exporter.getDatabaseAdapter().getConnectionDetails().getSchema();
batchSize = config.getDatabaseConfig().getImportBatching().getTempBatchSize();
if (batchSize > exporter.getDatabaseAdapter().getMaxBatchSize())
Expand All @@ -81,7 +83,16 @@ protected Appearance doExport(long appearanceId) throws CityGMLExportException,

try (ResultSet rs = ps.executeQuery()) {
Map<Long, Appearance> appearances = doExport(rs);
return !appearances.isEmpty() ? appearances.values().iterator().next() : null;
if (!appearances.isEmpty()) {
Appearance appearance = appearances.values().iterator().next();
if (replaceIds) {
appearance.accept(exporter.getIdReplacer());
}

return appearance;
} else {
return null;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.citydb.core.query.Query;
import org.citydb.core.query.builder.QueryBuildException;
import org.citydb.core.query.builder.sql.AppearanceFilterBuilder;
import org.citydb.core.util.CoreConstants;
import org.citydb.sqlbuilder.expression.LiteralList;
import org.citydb.sqlbuilder.expression.LiteralSelectExpression;
import org.citydb.sqlbuilder.expression.PlaceHolder;
Expand Down Expand Up @@ -68,6 +69,7 @@ public class DBGlobalToLocalAppearance extends AbstractAppearanceExporter {
private final Select appearanceQuery;
private final Table textureParam;

private final boolean replaceIds;
private final boolean handleImplicitGeometries;
private final AppearanceRemover appearanceRemover;
private final Map<Long, AbstractCityObject> batches;
Expand All @@ -82,9 +84,10 @@ private enum GeometryType {
}

public DBGlobalToLocalAppearance(Connection connection, Query query, CityGMLExportManager exporter, Config config) throws CityGMLExportException, SQLException {
super(false, null, exporter, config);
super(Mode.GLOBAL_TO_LOCAL, null, exporter, config);
this.connection = connection;

replaceIds = config.getExportConfig().getResourceId().isReplaceWithUUIDs();
handleImplicitGeometries = exporter.getInternalConfig().getOutputFormat() == OutputFormat.CITYGML;
if (handleImplicitGeometries) {
copyBuilder = new DeepCopyBuilder();
Expand Down Expand Up @@ -144,7 +147,11 @@ public void visit(AbstractGeometry geometry) {
GeometryType.IMPLICIT_GEOMETRY :
GeometryType.GEOMETRY;

targets.computeIfAbsent(type, v -> new HashSet<>()).add("#" + geometry.getId());
String target = replaceIds ?
(String) geometry.getLocalProperty(CoreConstants.OBJECT_ORIGINAL_GMLID) :
geometry.getId();

targets.computeIfAbsent(type, v -> new HashSet<>()).add("#" + target);
}
}
});
Expand Down Expand Up @@ -217,11 +224,19 @@ private List<Appearance> postprocess(Map<Long, Appearance> appearances, Map<Geom
if (geometryTargets != null) {
appearanceRemover.cleanupAppearances(appearances.values(), geometryTargets);
for (Map.Entry<Long, Appearance> entry : appearances.entrySet()) {
if (replaceIds) {
entry.getValue().accept(exporter.getIdReplacer());
}

AbstractCityObject cityObject = batches.get(entry.getKey());
cityObject.addAppearance(new AppearanceProperty(entry.getValue()));
}
}

if (replaceIds) {
globalAppearances.forEach(appearance -> appearance.accept(exporter.getIdReplacer()));
}

return globalAppearances;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class DBLocalAppearance extends AbstractAppearanceExporter {
private List<PlaceHolder<?>> themes;

public DBLocalAppearance(Connection connection, Query query, CityGMLExportManager exporter, Config config) throws CityGMLExportException, SQLException {
super(false, null, exporter, config);
super(Mode.LOCAL, null, exporter, config);
batches = new LinkedHashMap<>();
batchSize = exporter.getFeatureBatchSize();

Expand Down