From 819e1ba5c6577dd076138ca393b8643d6bf0e1a6 Mon Sep 17 00:00:00 2001 From: jackyq2015 Date: Sat, 18 Jul 2015 10:27:35 -0400 Subject: [PATCH] patch for issue #708. fix few hanging UIs when importing file --- .../google/refine/importers/MarcImporter.java | 16 +++++++++------- .../modules/core/langs/translation-default.json | 1 + .../modules/core/langs/translation-en.json | 1 + .../modules/core/langs/translation-es.json | 1 + .../modules/core/langs/translation-fr.json | 1 + .../modules/core/langs/translation-it.json | 1 + .../modules/core/langs/translation-zh.json | 1 + .../default-importing-controller/controller.js | 11 ++++++++--- .../index/parser-interfaces/excel-parser-ui.js | 2 ++ .../parser-interfaces/rdf-triples-parser-ui.js | 2 ++ 10 files changed, 27 insertions(+), 10 deletions(-) diff --git a/main/src/com/google/refine/importers/MarcImporter.java b/main/src/com/google/refine/importers/MarcImporter.java index 9ffa6ea4b..5d561483e 100644 --- a/main/src/com/google/refine/importers/MarcImporter.java +++ b/main/src/com/google/refine/importers/MarcImporter.java @@ -41,6 +41,7 @@ import java.io.InputStream; import java.io.OutputStream; import org.json.JSONObject; +import org.marc4j.MarcException; import org.marc4j.MarcPermissiveStreamReader; import org.marc4j.MarcWriter; import org.marc4j.MarcXmlWriter; @@ -58,14 +59,11 @@ public class MarcImporter extends XmlImporter { @Override public JSONObject createParserUIInitializationData(ImportingJob job, java.util.List fileRecords, String format) { - if (fileRecords.size() > 0) { JSONObject firstFileRecord = fileRecords.get(0); File file = ImportingUtilities.getFile(job, firstFileRecord); File tempFile = new File(file.getAbsolutePath()+".xml"); - JSONUtilities.safePut(firstFileRecord, "location", - JSONUtilities.getString(firstFileRecord, "location", "")+".xml"); try { InputStream inputStream = new FileInputStream(file); @@ -84,7 +82,14 @@ public class MarcImporter extends XmlImporter { try { outputStream.close(); inputStream.close(); - file.delete(); // get rid of our original file + + if (tempFile.length() == 0) // write failed. Most of time because of wrong Marc format + tempFile.delete(); + else // only set json if write the temp file successfully: + JSONUtilities.safePut(firstFileRecord, "location", + JSONUtilities.getString(firstFileRecord, "location", "")+".xml"); + +// file.delete(); // get rid of our original file } catch (IOException e) { // Just ignore - not much we can do anyway } @@ -93,11 +98,8 @@ public class MarcImporter extends XmlImporter { logger.error("Failed to create temporary XML file from MARC file", e); } } - JSONObject options = super.createParserUIInitializationData(job, fileRecords, format); - return options; }; - } diff --git a/main/webapp/modules/core/langs/translation-default.json b/main/webapp/modules/core/langs/translation-default.json index daa79bd9c..425157c9f 100644 --- a/main/webapp/modules/core/langs/translation-default.json +++ b/main/webapp/modules/core/langs/translation-default.json @@ -533,6 +533,7 @@ "specify-sep": "Please specify a separator.", "warning-no-length": "No field length is specified.", "warning-format": "The given field lengths are not properly formatted.", + "check-format": "Please check the file format.", "split-into-col": "Split into several columns", "add-based-col": "Add column based on this column", "add-by-urls": "Add column by fetching URLs", diff --git a/main/webapp/modules/core/langs/translation-en.json b/main/webapp/modules/core/langs/translation-en.json index f90eb6ac7..ab8737628 100644 --- a/main/webapp/modules/core/langs/translation-en.json +++ b/main/webapp/modules/core/langs/translation-en.json @@ -533,6 +533,7 @@ "specify-sep": "Please specify a separator.", "warning-no-length": "No field length is specified.", "warning-format": "The given field lengths are not properly formatted.", + "check-format": "Please check the file format.", "split-into-col": "Split into several columns", "add-based-col": "Add column based on this column", "add-by-urls": "Add column by fetching URLs", diff --git a/main/webapp/modules/core/langs/translation-es.json b/main/webapp/modules/core/langs/translation-es.json index 4c57d82f4..f88047977 100644 --- a/main/webapp/modules/core/langs/translation-es.json +++ b/main/webapp/modules/core/langs/translation-es.json @@ -533,6 +533,7 @@ "specify-sep": "Por favor especifique un separador.", "warning-no-length": "No se especificó un valor de longitud.", "warning-format": "Los valores de longitud no cumplen con el formato.", + "check-format": "Favor verificar el formato de archivo.", "split-into-col": "Dividir en varias columnas", "add-based-col": "Agregar columna basada en esta columna", "add-by-urls": "Agregar columna accediendo a URLs", diff --git a/main/webapp/modules/core/langs/translation-fr.json b/main/webapp/modules/core/langs/translation-fr.json index 88d53829e..0e2e60860 100644 --- a/main/webapp/modules/core/langs/translation-fr.json +++ b/main/webapp/modules/core/langs/translation-fr.json @@ -533,6 +533,7 @@ "specify-sep": "Merci d’indiquer un séparateur.", "warning-no-length": "Aucune longueur de champ n’a été indiquée.", "warning-format": "Le paramètre des longueurs de champs n’est pas formaté correctement.", + "check-format": "Merci de vérifier le format du fichier.", "split-into-col": "Diviser en plusieurs colonnes", "add-based-col": "Ajouter une colonne en fonction de cette colonne", "add-by-urls": "Ajouter une colonne en moissonant des URL", diff --git a/main/webapp/modules/core/langs/translation-it.json b/main/webapp/modules/core/langs/translation-it.json index bd8c3cba0..8a49215cd 100644 --- a/main/webapp/modules/core/langs/translation-it.json +++ b/main/webapp/modules/core/langs/translation-it.json @@ -533,6 +533,7 @@ "specify-sep": "Per favore specifica il separatore.", "warning-no-length": "Nessuna lunghezza dei campi specificata.", "warning-format": "Le lunghezze dei campi non sono formattate correttamente.", + "check-format": "Per favore controlla il formato del file.", "split-into-col": "Dividi in diverse colonne", "add-based-col": "Aggiungi colonna basata su questa", "add-by-urls": "Aggiungi colonna recuperando da URLs", diff --git a/main/webapp/modules/core/langs/translation-zh.json b/main/webapp/modules/core/langs/translation-zh.json index b4c4ca332..f9d3e0634 100644 --- a/main/webapp/modules/core/langs/translation-zh.json +++ b/main/webapp/modules/core/langs/translation-zh.json @@ -534,6 +534,7 @@ "specify-sep": "请制定一个分隔符.", "warning-no-length": "No field length is specified.", "warning-format": "The given field lengths are not properly formatted.", + "check-format": "请检查文件格式.", "split-into-col": "分割此列", "add-based-col": "由此列派生新列", "add-by-urls": "添加远程数据为新列", diff --git a/main/webapp/modules/core/scripts/index/default-importing-controller/controller.js b/main/webapp/modules/core/scripts/index/default-importing-controller/controller.js index 0f671a4a7..59e604a3b 100644 --- a/main/webapp/modules/core/scripts/index/default-importing-controller/controller.js +++ b/main/webapp/modules/core/scripts/index/default-importing-controller/controller.js @@ -192,13 +192,17 @@ Refine.DefaultImportingController.prototype._ensureFormatParserUIHasInitializati } }, "json" - ); + ) + .fail(function() { + dismissBusy(); + alert($.i18n._('core-views')["check-format"]); + }); } else { onDone(); } }; -Refine.DefaultImportingController.prototype.updateFormatAndOptions = function(options, callback) { +Refine.DefaultImportingController.prototype.updateFormatAndOptions = function(options, callback, finallyCallBack) { var self = this; $.post( "command/core/importing-controller?" + $.param({ @@ -213,12 +217,13 @@ Refine.DefaultImportingController.prototype.updateFormatAndOptions = function(op function(o) { if (o.status == 'error') { if (o.message) { - alert(o.message); + alert(o.message); } else { var messages = []; $.each(o.errors, function() { messages.push(this.message); }); alert(messages.join('\n\n')); } + finallyCallBack(); } else { callback(o); } diff --git a/main/webapp/modules/core/scripts/index/parser-interfaces/excel-parser-ui.js b/main/webapp/modules/core/scripts/index/parser-interfaces/excel-parser-ui.js index e56fc3889..0c72639e2 100644 --- a/main/webapp/modules/core/scripts/index/parser-interfaces/excel-parser-ui.js +++ b/main/webapp/modules/core/scripts/index/parser-interfaces/excel-parser-ui.js @@ -217,5 +217,7 @@ Refine.ExcelParserUI.prototype._updatePreview = function() { new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty()); }); } + }, function() { + self._progressContainer.hide(); }); }; diff --git a/main/webapp/modules/core/scripts/index/parser-interfaces/rdf-triples-parser-ui.js b/main/webapp/modules/core/scripts/index/parser-interfaces/rdf-triples-parser-ui.js index d62c4b934..e4b7031cf 100644 --- a/main/webapp/modules/core/scripts/index/parser-interfaces/rdf-triples-parser-ui.js +++ b/main/webapp/modules/core/scripts/index/parser-interfaces/rdf-triples-parser-ui.js @@ -120,5 +120,7 @@ Refine.RdfTriplesParserUI.prototype._updatePreview = function() { new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty()); }); } + }, function() { + self._progressContainer.hide(); }); };