Update HTML form to include ListView; populate commands; style correctly without AngularJS; process form the same way regardless of button or command submit.
diff --git a/proteus/src/main/java/drat/proteus/DratStartForm.java b/proteus/src/main/java/drat/proteus/DratStartForm.java
index 7fac9da..ea2a63d 100644
--- a/proteus/src/main/java/drat/proteus/DratStartForm.java
+++ b/proteus/src/main/java/drat/proteus/DratStartForm.java
@@ -18,31 +18,26 @@
package drat.proteus;
import drat.proteus.rest.Unzipper;
-
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.cxf.helpers.FileUtils;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.form.upload.FileUpload;
import org.apache.wicket.markup.html.form.upload.FileUploadField;
-import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
-
-import backend.GenericProcess;
-
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
-import java.util.Locale;
-import java.util.logging.Level;
import java.util.logging.Logger;
/**
- * Created by stevenfrancus on 11/16/15.
+ * Sets up a DRAT run based on the Proteus start form.
+ *
*/
public class DratStartForm extends Form {
private static final Logger LOG = Logger.getLogger(DratStartForm.class
@@ -50,34 +45,31 @@
private FileUploadField fileUploadField;
private TextField<String> pathField;
private ListView<String> cmdSelect;
+ private String theCommand = null;
public DratStartForm(String name, FileUploadField fileUploader,
TextField<String> path) {
super(name);
fileUploadField = fileUploader;
pathField = path;
- String[] cmdArray = {"Crawl", "Index", "Map", "Reduce", "Go"};
- List<String> commands = (List<String>)Arrays.asList(cmdArray);
+ String[] cmdArray = { "Crawl", "Index", "Map", "Reduce", "Go" };
+ List<String> commands = (List<String>) Arrays.asList(cmdArray);
cmdSelect = new ListView<String>("cmd", commands) {
@Override
protected void populateItem(final ListItem<String> item) {
final String cmdItemLabel = item.getModelObject();
- Link<String> link = new Link<String>("cmd_link") {
+ SubmitLink link = new SubmitLink("cmd_link") {
@Override
- public void onClick() {
- String theCmd = cmdItemLabel;
- String thePath = pathField.getModelObject();
- LOG.info("Running DRAT: ["+theCmd+"] on path: ["+thePath+"]");
- startDrat(thePath, theCmd.toUpperCase(Locale.getDefault()));
- setResponsePage(DratWorkflow.class);
+ public void onSubmit() {
+ theCommand = cmdItemLabel;
}
};
link.add(new Label("cmd_item_label", cmdItemLabel));
item.add(link);
-
+
}
- };
+ };
this.add(fileUploadField);
this.add(path);
this.add(cmdSelect);
@@ -86,25 +78,46 @@
@Override
protected void onSubmit() {
super.onSubmit();
+ if (theCommand != null) {
+ handleSubmit(theCommand);
+ } else
+ handleSubmit("GO");
+ }
+
+ private void handleSubmit(String command) {
FileUpload fileUpload = fileUploadField.getFileUpload();
+ boolean downloadPhase = command.toUpperCase().equals("GO") ||
+ command.toUpperCase().equals("CRAWL");
try {
String pathValue = pathField.getModelObject();
+ LOG.info("Running DRAT: [" + command + "] on path: [" + pathValue + "]");
+
if (pathValue == null || pathValue.isEmpty()) {
File file = new File(System.getProperty("java.io.tmpdir")
+ File.separator + fileUpload.getClientFileName());
- fileUpload.writeTo(file);
- File unzippedFile = Unzipper.unzip(file);
- file.delete();
- startDrat(unzippedFile.getCanonicalPath(), "GO");
- setResponsePage(DratWorkflow.class);
+ if (downloadPhase) {
+ fileUpload.writeTo(file);
+ File unzippedFile = Unzipper.unzip(file);
+ file.delete();
+ startDrat(unzippedFile.getCanonicalPath(), command);
+ setResponsePage(DratWorkflow.class);
+ return;
+ }
+ else{
+ LOG.info("Omitting uploading of zip: current phase: ["+command+"]");
+ startDrat(file.getAbsolutePath(), command);
+ setResponsePage(DratWorkflow.class);
+ return;
+ }
}
+
if (pathValue.startsWith("http://")) {
- parseAsVersionControlledRepo(pathValue);
+ parseAsVersionControlledRepo(pathValue, command, downloadPhase);
} else {
try {
File file = new File(pathValue);
if (file.exists()) {
- startDrat(pathValue, "GO");
+ startDrat(pathValue, command);
} else {
setResponsePage(HomePage.class);
return;
@@ -112,11 +125,13 @@
} catch (Exception e) {
e.printStackTrace();
setResponsePage(HomePage.class);
+ return;
}
}
setResponsePage(DratWorkflow.class);
} catch (Exception e) {
e.printStackTrace();
+ setResponsePage(HomePage.class);
}
}
@@ -125,7 +140,13 @@
dratStarterRunnable.start();
}
- private void parseAsVersionControlledRepo(String path) throws IOException {
+ private void parseAsVersionControlledRepo(String path, String command,
+ boolean downloadPhase) throws IOException {
+ if (!downloadPhase) {
+ startDrat(path, command);
+ return;
+ }
+
String projectName = null;
boolean git = path.endsWith(".git");
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
@@ -138,7 +159,7 @@
} else {
projectName = path.substring(path.lastIndexOf("/") + 1);
line = "svn export " + path;
- }
+ }
String clonePath = tmpDirPath + File.separator + projectName;
File cloneDir = new File(clonePath);
if (cloneDir.isDirectory() && cloneDir.exists()) {
@@ -149,7 +170,6 @@
LOG.info("Cloning Git / SVN project: [" + projectName + "] remote repo: ["
+ path + "] into " + tmpDirPath);
-
CommandLine cmdLine = CommandLine.parse(line);
DefaultExecutor executor = new DefaultExecutor();
executor.setWorkingDirectory(tmpDir);
@@ -162,7 +182,7 @@
FileUtils.removeDir(gitHiddenDir);
}
- startDrat(clonePath, "GO");
+ startDrat(clonePath, command);
}
}
diff --git a/proteus/src/main/java/drat/proteus/HomePage.html b/proteus/src/main/java/drat/proteus/HomePage.html
index 623a458..4988454 100644
--- a/proteus/src/main/java/drat/proteus/HomePage.html
+++ b/proteus/src/main/java/drat/proteus/HomePage.html
@@ -9,6 +9,19 @@
<link rel="stylesheet" type="text/css" href="nv.d3.min.css"/>
<link rel="stylesheet" type="text/css" href="HomePage.css">
</wicket:link>
+ <wicket:remove>
+ <style type="text/css">
+ .dropdown-menu>wicket\:remove>li>a {
+ display: block;
+ padding: 3px 20px;
+ clear: both;
+ font-weight: 400;
+ line-height: 1.42857143;
+ color: #333;
+ white-space: nowrap;
+ }
+ </style>
+ </wicket:remove>
</head>
<body ng-controller="switch">
<div class="container" ng-show="!goSecondPage">
@@ -60,20 +73,17 @@
<div class="btn-group">
<ul class="dropdown-menu">
<li class="ng-scope" wicket:id="cmd">
- <a href="#" class="ng-binding" wicket:id="cmd_link"><span wicket:id="cmd_item_label">[pick a command]</span></a>
+ <a href="#" class="ng-binding" wicket:id="cmd_link"><span wicket:id="cmd_item_label" class="ng-binding">Index</span></a>
</li>
- <wicket:remove>
- <li class="ng-scope">
- <a href="#" class="ng-binding">Index</a>
- </li>
+ <wicket:remove>
<li class="ng-scope">
- <a href="#" class="ng-binding">Crawl</a>
+ <a href="#" class="ng-binding"><span class="ng-binding">Crawl</span></a>
</li>
<li class="ng-scope">
- <a href="#" class="ng-binding">Map</a>
+ <a href="#" class="ng-binding"><span class="ng-binding">Map</span></a>
</li>
<li class="ng-scope">
- <a href="#" class="ng-binding">Reduce</a>
+ <a href="#" class="ng-binding"><span class="ng-binding">Reduce</span></a>
</li>
</wicket:remove>
</ul>