diff --git a/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/AbstractAppearanceExporter.java b/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/AbstractAppearanceExporter.java index fb0fcd801..b727db1df 100644 --- a/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/AbstractAppearanceExporter.java +++ b/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/AbstractAppearanceExporter.java @@ -81,11 +81,17 @@ public abstract class AbstractAppearanceExporter extends AbstractTypeExporter { private final List appearanceADEHookTables; private final List
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(); @@ -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"))) diff --git a/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/CityGMLExportManager.java b/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/CityGMLExportManager.java index 38c5b5dfb..f316a1a33 100644 --- a/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/CityGMLExportManager.java +++ b/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/CityGMLExportManager.java @@ -616,6 +616,10 @@ public AffineTransformer getAffineTransformer() { return affineTransformer; } + public IdReplacer getIdReplacer() { + return idReplacer; + } + public InternalConfig getInternalConfig() { return internalConfig; } diff --git a/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/DBGlobalAppearance.java b/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/DBGlobalAppearance.java index 4605f2312..b335fd417 100644 --- a/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/DBGlobalAppearance.java +++ b/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/DBGlobalAppearance.java @@ -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()) @@ -81,7 +83,16 @@ protected Appearance doExport(long appearanceId) throws CityGMLExportException, try (ResultSet rs = ps.executeQuery()) { Map 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; + } } } diff --git a/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/DBGlobalToLocalAppearance.java b/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/DBGlobalToLocalAppearance.java index 8fbab6a66..855049ac7 100644 --- a/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/DBGlobalToLocalAppearance.java +++ b/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/DBGlobalToLocalAppearance.java @@ -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; @@ -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 batches; @@ -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(); @@ -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); } } }); @@ -217,11 +224,19 @@ private List postprocess(Map appearances, Map 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; } diff --git a/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/DBLocalAppearance.java b/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/DBLocalAppearance.java index 2635faf58..9794b9870 100644 --- a/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/DBLocalAppearance.java +++ b/impexp-core/src/main/java/org/citydb/core/operation/exporter/database/content/DBLocalAppearance.java @@ -56,7 +56,7 @@ public class DBLocalAppearance extends AbstractAppearanceExporter { private List> 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();