Permalink
Browse files

Improved error reports on various wiki dump prerequisites failure cases.

Also added some JavaDoc.
  • Loading branch information...
luccioman committed Apr 11, 2017
1 parent dfe8d41 commit 7edddd7b0d8b9087a60de7675fc8d237f6bccef5
Showing with 34 additions and 9 deletions.
  1. +6 −1 htroot/IndexImportMediawiki_p.html
  2. +28 −8 htroot/IndexImportMediawiki_p.java
@@ -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>
@@ -30,9 +30,24 @@
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 static serverObjects respond(@SuppressWarnings("unused") final RequestHea
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);

0 comments on commit 7edddd7

Please sign in to comment.