From 7edddd7b0d8b9087a60de7675fc8d237f6bccef5 Mon Sep 17 00:00:00 2001 From: luccioman Date: Tue, 11 Apr 2017 08:21:34 +0200 Subject: [PATCH] Improved error reports on various wiki dump prerequisites failure cases. Also added some JavaDoc. --- htroot/IndexImportMediawiki_p.html | 7 +++++- htroot/IndexImportMediawiki_p.java | 36 +++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/htroot/IndexImportMediawiki_p.html b/htroot/IndexImportMediawiki_p.html index 7c473f50d..1959ed091 100644 --- a/htroot/IndexImportMediawiki_p.html +++ b/htroot/IndexImportMediawiki_p.html @@ -13,7 +13,12 @@

MediaWiki Dump Import

#(import)# -

#(status)#No import thread is running, you can start a new thread here::Bad input data: #[message]# #(/status)#

+

#(status)#

+ :: + :: + :: + :: + #(/status)#

MediaWiki Dump File Selection: select an XML file (which may be bz2- or gz-encoded) diff --git a/htroot/IndexImportMediawiki_p.java b/htroot/IndexImportMediawiki_p.java index 37a1c6b87..095aaf106 100644 --- a/htroot/IndexImportMediawiki_p.java +++ b/htroot/IndexImportMediawiki_p.java @@ -30,9 +30,24 @@ import net.yacy.search.Switchboard; import net.yacy.server.serverObjects; import net.yacy.server.serverSwitch; +/** + * Import of MediaWiki dump files in the local index. + */ public class IndexImportMediawiki_p { - public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, final serverObjects post, final serverSwitch env) { + /** + * Run conditions : + * - no MediaWiki import thread is running : allow to start a new import by filling the "file" parameter + * - the MediaWiki import thread is running : returns monitoring information. + * @param header servlet request header + * @param post request parameters. Supported keys : + *
    + *
  • file : a dump file path on this YaCy server local file system
  • + *
+ * @param env server environment + * @return the servlet answer object + */ + public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { final serverObjects prop = new serverObjects(); final Switchboard sb = (Switchboard) env; @@ -56,21 +71,26 @@ public class IndexImportMediawiki_p { String file = post.get("file"); if (file.startsWith("file://")) file = file.substring(7); if (file.startsWith("http")) { - prop.put("import_dump", ""); - prop.put("import_thread", "Error: file argument must be a path to a document in the local file system"); + prop.put("import_status", 1); } else { final File sourcefile = new File(file); - if (sourcefile.exists()) { + if (!sourcefile.exists()) { + prop.put("import_status", 2); + prop.put("import_status_sourceFile", sourcefile.getAbsolutePath()); + } else if(!sourcefile.canRead()) { + prop.put("import_status", 3); + prop.put("import_status_sourceFile", sourcefile.getAbsolutePath()); + } else if(sourcefile.isDirectory()) { + prop.put("import_status", 4); + prop.put("import_status_sourceFile", sourcefile.getAbsolutePath()); + } else { MediawikiImporter.job = new MediawikiImporter(sourcefile, sb.surrogatesInPath); MediawikiImporter.job.start(); prop.put("import_dump", MediawikiImporter.job.source()); prop.put("import_thread", "started"); - } else { - prop.put("import_dump", ""); - prop.put("import_thread", "Error: file not found ["+sourcefile+"]"); + prop.put("import", 1); } } - prop.put("import", 1); prop.put("import_count", 0); prop.put("import_speed", 0); prop.put("import_runningHours", 0);