Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

Improved error reports on various wiki dump prerequisites failure cases.

luccioman7edddd7b0d8b
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 @@
<h2>MediaWiki Dump Import</h2>
#(import)#
- <p>#(status)#No import thread is running, you can start a new thread here::Bad input data: #[message]# #(/status)#</p>
+ <p>#(status)#<div class="alert alert-info" role="alert">No import thread is running, you can start a new thread here</div>
+ ::<div class="alert alert-danger" role="alert">Error : file argument must be a path to a document in the local file system</div>
+ ::<div class="alert alert-danger" role="alert">Error : file not found "#[sourceFile]#"</div>
+ ::<div class="alert alert-danger" role="alert">Error : can not read file "#[sourceFile]#"</div>
+ ::<div class="alert alert-danger" role="alert">Error : you selected a directory ("#[sourceFile]#")</div>
+ #(/status)#</p>
<form action="IndexImportMediawiki_p.html" method="post" accept-charset="UTF-8" class="form-horizontal">
<fieldset>
<legend>MediaWiki Dump File Selection: select an XML file (which may be bz2- or gz-encoded)</legend>
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 :
+ * <ul>
+ * <li>file : a dump file path on this YaCy server local file system</li>
+ * </ul>
+ * @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);