From 670aa8bc701a6a59ad4c47fa2e5ea69a6b6b357a Mon Sep 17 00:00:00 2001 From: Philip Marzullo Date: Tue, 7 Mar 2023 13:20:20 -0500 Subject: [PATCH] 0005729: DBImport- Allow the UI specification of the catalog and schema to override the catalog and schema specs in XML imported file --- .../jumpmind/symmetric/io/data/DbImport.java | 2 ++ .../io/data/reader/XmlDataReader.java | 32 +++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/DbImport.java b/symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/DbImport.java index 9717707053..ab2d206752 100644 --- a/symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/DbImport.java +++ b/symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/DbImport.java @@ -211,6 +211,8 @@ protected void importTablesFromCsvDquote(InputStream in, String tableName) { protected void importTablesFromXml(InputStream in) { XmlDataReader reader = new XmlDataReader(in); + reader.setCatalog(catalog); + reader.setSchema(schema); DefaultDatabaseWriter writer = new DefaultDatabaseWriter(symmetricPlatform, buildDatabaseWriterSettings()); DataProcessor dataProcessor = new DataProcessor(reader, writer, "import"); dataProcessor.process(); diff --git a/symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/reader/XmlDataReader.java b/symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/reader/XmlDataReader.java index e547e10538..7f84c695bd 100644 --- a/symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/reader/XmlDataReader.java +++ b/symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/reader/XmlDataReader.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Map; +import org.apache.commons.lang3.StringUtils; import org.jumpmind.db.io.DatabaseXmlUtil; import org.jumpmind.db.model.Column; import org.jumpmind.db.model.Database; @@ -56,6 +57,9 @@ public class XmlDataReader extends AbstractDataReader implements IDataReader { protected XmlPullParser parser; protected Statistics statistics = new Statistics(); protected List next = new ArrayList(); + // These values will override the specification from the input stream + protected String catalog; + protected String schema; public XmlDataReader(InputStream is) { this(toReader(is)); @@ -83,8 +87,8 @@ protected void readNext() { String columnName = null; CsvData data = null; Table table = null; - String catalog = null; - String schema = null; + String localCatalog = catalog; + String localSchema = schema; int eventType = parser.next(); while (eventType != XmlPullParser.END_DOCUMENT) { switch (eventType) { @@ -138,8 +142,8 @@ protected void readNext() { next.add(table); Database db = new Database(); db.setName("dbimport"); - db.setCatalog(catalog); - db.setSchema(schema); + db.setCatalog(localCatalog); + db.setSchema(localSchema); db.addTable(table); String xml = DatabaseXmlUtil.toXml(db); data = new CsvData(DataEventType.CREATE); @@ -150,9 +154,9 @@ protected void readNext() { String attributeName = parser.getAttributeName(i); String attributeValue = parser.getAttributeValue(i); if ("catalog".equalsIgnoreCase(attributeName)) { - catalog = attributeValue; + localCatalog = StringUtils.isBlank(catalog) ? attributeValue : catalog; } else if ("schema".equalsIgnoreCase(attributeName)) { - schema = attributeValue; + localSchema = StringUtils.isBlank(schema) ? attributeValue : schema; } } } @@ -245,4 +249,20 @@ public Map getStatistics() { map.put(batch, statistics); return map; } + + public String getCatalog() { + return catalog; + } + + public void setCatalog(String catalog) { + this.catalog = catalog; + } + + public String getSchema() { + return schema; + } + + public void setSchema(String schema) { + this.schema = schema; + } }