patch for issue #708. fix few hanging UIs when importing file

This commit is contained in:
jackyq2015 2015-07-18 10:27:35 -04:00
parent fa7733e03e
commit 819e1ba5c6
10 changed files with 27 additions and 10 deletions

View File

@ -41,6 +41,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import org.json.JSONObject; import org.json.JSONObject;
import org.marc4j.MarcException;
import org.marc4j.MarcPermissiveStreamReader; import org.marc4j.MarcPermissiveStreamReader;
import org.marc4j.MarcWriter; import org.marc4j.MarcWriter;
import org.marc4j.MarcXmlWriter; import org.marc4j.MarcXmlWriter;
@ -58,14 +59,11 @@ public class MarcImporter extends XmlImporter {
@Override @Override
public JSONObject createParserUIInitializationData(ImportingJob job, java.util.List<JSONObject> fileRecords, String format) { public JSONObject createParserUIInitializationData(ImportingJob job, java.util.List<JSONObject> fileRecords, String format) {
if (fileRecords.size() > 0) { if (fileRecords.size() > 0) {
JSONObject firstFileRecord = fileRecords.get(0); JSONObject firstFileRecord = fileRecords.get(0);
File file = ImportingUtilities.getFile(job, firstFileRecord); File file = ImportingUtilities.getFile(job, firstFileRecord);
File tempFile = new File(file.getAbsolutePath()+".xml"); File tempFile = new File(file.getAbsolutePath()+".xml");
JSONUtilities.safePut(firstFileRecord, "location",
JSONUtilities.getString(firstFileRecord, "location", "")+".xml");
try { try {
InputStream inputStream = new FileInputStream(file); InputStream inputStream = new FileInputStream(file);
@ -84,7 +82,14 @@ public class MarcImporter extends XmlImporter {
try { try {
outputStream.close(); outputStream.close();
inputStream.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) { } catch (IOException e) {
// Just ignore - not much we can do anyway // 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); logger.error("Failed to create temporary XML file from MARC file", e);
} }
} }
JSONObject options = super.createParserUIInitializationData(job, fileRecords, format); JSONObject options = super.createParserUIInitializationData(job, fileRecords, format);
return options; return options;
}; };
} }

View File

@ -533,6 +533,7 @@
"specify-sep": "Please specify a separator.", "specify-sep": "Please specify a separator.",
"warning-no-length": "No field length is specified.", "warning-no-length": "No field length is specified.",
"warning-format": "The given field lengths are not properly formatted.", "warning-format": "The given field lengths are not properly formatted.",
"check-format": "Please check the file format.",
"split-into-col": "Split into several columns", "split-into-col": "Split into several columns",
"add-based-col": "Add column based on this column", "add-based-col": "Add column based on this column",
"add-by-urls": "Add column by fetching URLs", "add-by-urls": "Add column by fetching URLs",

View File

@ -533,6 +533,7 @@
"specify-sep": "Please specify a separator.", "specify-sep": "Please specify a separator.",
"warning-no-length": "No field length is specified.", "warning-no-length": "No field length is specified.",
"warning-format": "The given field lengths are not properly formatted.", "warning-format": "The given field lengths are not properly formatted.",
"check-format": "Please check the file format.",
"split-into-col": "Split into several columns", "split-into-col": "Split into several columns",
"add-based-col": "Add column based on this column", "add-based-col": "Add column based on this column",
"add-by-urls": "Add column by fetching URLs", "add-by-urls": "Add column by fetching URLs",

View File

@ -533,6 +533,7 @@
"specify-sep": "Por favor especifique un separador.", "specify-sep": "Por favor especifique un separador.",
"warning-no-length": "No se especificó un valor de longitud.", "warning-no-length": "No se especificó un valor de longitud.",
"warning-format": "Los valores de longitud no cumplen con el formato.", "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", "split-into-col": "Dividir en varias columnas",
"add-based-col": "Agregar columna basada en esta columna", "add-based-col": "Agregar columna basada en esta columna",
"add-by-urls": "Agregar columna accediendo a URLs", "add-by-urls": "Agregar columna accediendo a URLs",

View File

@ -533,6 +533,7 @@
"specify-sep": "Merci dindiquer un séparateur.", "specify-sep": "Merci dindiquer un séparateur.",
"warning-no-length": "Aucune longueur de champ na été indiquée.", "warning-no-length": "Aucune longueur de champ na été indiquée.",
"warning-format": "Le paramètre des longueurs de champs nest pas formaté correctement.", "warning-format": "Le paramètre des longueurs de champs nest pas formaté correctement.",
"check-format": "Merci de vérifier le format du fichier.",
"split-into-col": "Diviser en plusieurs colonnes", "split-into-col": "Diviser en plusieurs colonnes",
"add-based-col": "Ajouter une colonne en fonction de cette colonne", "add-based-col": "Ajouter une colonne en fonction de cette colonne",
"add-by-urls": "Ajouter une colonne en moissonant des URL", "add-by-urls": "Ajouter une colonne en moissonant des URL",

View File

@ -533,6 +533,7 @@
"specify-sep": "Per favore specifica il separatore.", "specify-sep": "Per favore specifica il separatore.",
"warning-no-length": "Nessuna lunghezza dei campi specificata.", "warning-no-length": "Nessuna lunghezza dei campi specificata.",
"warning-format": "Le lunghezze dei campi non sono formattate correttamente.", "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", "split-into-col": "Dividi in diverse colonne",
"add-based-col": "Aggiungi colonna basata su questa", "add-based-col": "Aggiungi colonna basata su questa",
"add-by-urls": "Aggiungi colonna recuperando da URLs", "add-by-urls": "Aggiungi colonna recuperando da URLs",

View File

@ -534,6 +534,7 @@
"specify-sep": "请制定一个分隔符.", "specify-sep": "请制定一个分隔符.",
"warning-no-length": "No field length is specified.", "warning-no-length": "No field length is specified.",
"warning-format": "The given field lengths are not properly formatted.", "warning-format": "The given field lengths are not properly formatted.",
"check-format": "请检查文件格式.",
"split-into-col": "分割此列", "split-into-col": "分割此列",
"add-based-col": "由此列派生新列", "add-based-col": "由此列派生新列",
"add-by-urls": "添加远程数据为新列", "add-by-urls": "添加远程数据为新列",

View File

@ -192,13 +192,17 @@ Refine.DefaultImportingController.prototype._ensureFormatParserUIHasInitializati
} }
}, },
"json" "json"
); )
.fail(function() {
dismissBusy();
alert($.i18n._('core-views')["check-format"]);
});
} else { } else {
onDone(); onDone();
} }
}; };
Refine.DefaultImportingController.prototype.updateFormatAndOptions = function(options, callback) { Refine.DefaultImportingController.prototype.updateFormatAndOptions = function(options, callback, finallyCallBack) {
var self = this; var self = this;
$.post( $.post(
"command/core/importing-controller?" + $.param({ "command/core/importing-controller?" + $.param({
@ -213,12 +217,13 @@ Refine.DefaultImportingController.prototype.updateFormatAndOptions = function(op
function(o) { function(o) {
if (o.status == 'error') { if (o.status == 'error') {
if (o.message) { if (o.message) {
alert(o.message); alert(o.message);
} else { } else {
var messages = []; var messages = [];
$.each(o.errors, function() { messages.push(this.message); }); $.each(o.errors, function() { messages.push(this.message); });
alert(messages.join('\n\n')); alert(messages.join('\n\n'));
} }
finallyCallBack();
} else { } else {
callback(o); callback(o);
} }

View File

@ -217,5 +217,7 @@ Refine.ExcelParserUI.prototype._updatePreview = function() {
new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty()); new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty());
}); });
} }
}, function() {
self._progressContainer.hide();
}); });
}; };

View File

@ -120,5 +120,7 @@ Refine.RdfTriplesParserUI.prototype._updatePreview = function() {
new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty()); new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty());
}); });
} }
}, function() {
self._progressContainer.hide();
}); });
}; };