2010-02-03 03:29:47 +01:00
|
|
|
package com.metaweb.gridworks;
|
2010-01-24 22:09:50 +01:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2010-01-25 23:51:25 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2010-03-08 01:37:06 +01:00
|
|
|
import java.util.Timer;
|
|
|
|
import java.util.TimerTask;
|
2010-01-24 22:09:50 +01:00
|
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
import javax.servlet.http.HttpServlet;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
2010-02-03 03:29:47 +01:00
|
|
|
import com.metaweb.gridworks.commands.Command;
|
2010-02-05 00:38:40 +01:00
|
|
|
import com.metaweb.gridworks.commands.edit.AddColumnCommand;
|
2010-02-23 08:45:12 +01:00
|
|
|
import com.metaweb.gridworks.commands.edit.AnnotateOneRowCommand;
|
|
|
|
import com.metaweb.gridworks.commands.edit.AnnotateRowsCommand;
|
2010-02-18 06:00:56 +01:00
|
|
|
import com.metaweb.gridworks.commands.edit.ApplyOperationsCommand;
|
2010-02-05 20:19:38 +01:00
|
|
|
import com.metaweb.gridworks.commands.edit.CreateProjectCommand;
|
2010-03-06 11:17:58 +01:00
|
|
|
import com.metaweb.gridworks.commands.edit.DeleteProjectCommand;
|
2010-03-08 03:34:25 +01:00
|
|
|
import com.metaweb.gridworks.commands.edit.ExportProjectCommand;
|
|
|
|
import com.metaweb.gridworks.commands.edit.ImportProjectCommand;
|
2010-03-07 01:25:00 +01:00
|
|
|
import com.metaweb.gridworks.commands.edit.TextTransformCommand;
|
2010-03-05 09:11:48 +01:00
|
|
|
import com.metaweb.gridworks.commands.edit.EditOneCellCommand;
|
2010-03-07 01:25:00 +01:00
|
|
|
import com.metaweb.gridworks.commands.edit.MassEditCommand;
|
2010-02-05 07:29:27 +01:00
|
|
|
import com.metaweb.gridworks.commands.edit.JoinMultiValueCellsCommand;
|
2010-02-05 00:38:40 +01:00
|
|
|
import com.metaweb.gridworks.commands.edit.RemoveColumnCommand;
|
2010-02-11 07:44:48 +01:00
|
|
|
import com.metaweb.gridworks.commands.edit.SaveProtographCommand;
|
2010-02-05 07:29:27 +01:00
|
|
|
import com.metaweb.gridworks.commands.edit.SplitMultiValueCellsCommand;
|
2010-02-04 07:12:22 +01:00
|
|
|
import com.metaweb.gridworks.commands.edit.UndoRedoCommand;
|
2010-03-06 11:17:58 +01:00
|
|
|
import com.metaweb.gridworks.commands.info.ComputeClustersCommand;
|
2010-02-04 07:12:22 +01:00
|
|
|
import com.metaweb.gridworks.commands.info.ComputeFacetsCommand;
|
2010-02-05 02:58:06 +01:00
|
|
|
import com.metaweb.gridworks.commands.info.ExportRowsCommand;
|
2010-02-04 07:12:22 +01:00
|
|
|
import com.metaweb.gridworks.commands.info.GetAllProjectMetadataCommand;
|
2010-03-03 22:21:38 +01:00
|
|
|
import com.metaweb.gridworks.commands.info.GetExpressionHistoryCommand;
|
2010-02-04 07:12:22 +01:00
|
|
|
import com.metaweb.gridworks.commands.info.GetHistoryCommand;
|
2010-03-03 03:53:07 +01:00
|
|
|
import com.metaweb.gridworks.commands.info.GetModelsCommand;
|
2010-02-17 02:30:09 +01:00
|
|
|
import com.metaweb.gridworks.commands.info.GetOperationsCommand;
|
2010-02-04 07:12:22 +01:00
|
|
|
import com.metaweb.gridworks.commands.info.GetProcessesCommand;
|
|
|
|
import com.metaweb.gridworks.commands.info.GetProjectMetadataCommand;
|
|
|
|
import com.metaweb.gridworks.commands.info.GetRowsCommand;
|
2010-02-22 05:23:25 +01:00
|
|
|
import com.metaweb.gridworks.commands.recon.ReconDiscardJudgmentsCommand;
|
|
|
|
import com.metaweb.gridworks.commands.recon.ReconJudgeOneCellCommand;
|
|
|
|
import com.metaweb.gridworks.commands.recon.ReconJudgeSimilarCellsCommand;
|
2010-03-03 03:53:07 +01:00
|
|
|
import com.metaweb.gridworks.commands.recon.ReconMarkNewTopicsCommand;
|
|
|
|
import com.metaweb.gridworks.commands.recon.ReconMatchBestCandidatesCommand;
|
2010-02-22 05:23:25 +01:00
|
|
|
import com.metaweb.gridworks.commands.recon.ReconMatchSpecificTopicCommand;
|
2010-02-04 07:12:22 +01:00
|
|
|
import com.metaweb.gridworks.commands.recon.ReconcileCommand;
|
2010-03-03 01:30:39 +01:00
|
|
|
import com.metaweb.gridworks.commands.util.CancelProcessesCommand;
|
2010-02-07 10:02:22 +01:00
|
|
|
import com.metaweb.gridworks.commands.util.GetExpressionLanguageInfoCommand;
|
2010-02-19 01:28:34 +01:00
|
|
|
import com.metaweb.gridworks.commands.util.GuessTypesOfColumnCommand;
|
2010-03-03 22:21:38 +01:00
|
|
|
import com.metaweb.gridworks.commands.util.LogExpressionCommand;
|
2010-02-04 07:12:22 +01:00
|
|
|
import com.metaweb.gridworks.commands.util.PreviewExpressionCommand;
|
2010-03-13 08:13:18 +01:00
|
|
|
import com.metaweb.gridworks.commands.util.PreviewExtendDataCommand;
|
2010-02-16 21:15:19 +01:00
|
|
|
import com.metaweb.gridworks.commands.util.PreviewProtographCommand;
|
2010-01-25 23:51:25 +01:00
|
|
|
|
2010-02-03 03:29:47 +01:00
|
|
|
public class GridworksServlet extends HttpServlet {
|
2010-03-03 03:53:07 +01:00
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
private static final long serialVersionUID = 2386057901503517403L;
|
|
|
|
|
|
|
|
static protected Map<String, Command> _commands = new HashMap<String, Command>();
|
2010-03-08 01:37:06 +01:00
|
|
|
static protected Timer _timer = new Timer();
|
2010-03-03 05:19:58 +01:00
|
|
|
|
|
|
|
static {
|
|
|
|
_commands.put("create-project-from-upload", new CreateProjectCommand());
|
2010-03-08 03:34:25 +01:00
|
|
|
_commands.put("import-project", new ImportProjectCommand());
|
|
|
|
_commands.put("export-project", new ExportProjectCommand());
|
2010-03-03 05:19:58 +01:00
|
|
|
_commands.put("export-rows", new ExportRowsCommand());
|
|
|
|
|
|
|
|
_commands.put("get-project-metadata", new GetProjectMetadataCommand());
|
|
|
|
_commands.put("get-all-project-metadata", new GetAllProjectMetadataCommand());
|
2010-03-05 02:52:55 +01:00
|
|
|
|
|
|
|
_commands.put("delete-project", new DeleteProjectCommand());
|
2010-03-03 05:19:58 +01:00
|
|
|
|
|
|
|
_commands.put("get-models", new GetModelsCommand());
|
|
|
|
_commands.put("get-rows", new GetRowsCommand());
|
|
|
|
_commands.put("get-processes", new GetProcessesCommand());
|
|
|
|
_commands.put("get-history", new GetHistoryCommand());
|
|
|
|
_commands.put("get-operations", new GetOperationsCommand());
|
|
|
|
|
|
|
|
_commands.put("undo-redo", new UndoRedoCommand());
|
|
|
|
_commands.put("apply-operations", new ApplyOperationsCommand());
|
|
|
|
_commands.put("cancel-processes", new CancelProcessesCommand());
|
|
|
|
|
|
|
|
_commands.put("compute-facets", new ComputeFacetsCommand());
|
2010-03-06 11:17:58 +01:00
|
|
|
_commands.put("compute-clusters", new ComputeClustersCommand());
|
2010-03-07 01:25:00 +01:00
|
|
|
|
2010-03-05 09:11:48 +01:00
|
|
|
_commands.put("edit-one-cell", new EditOneCellCommand());
|
2010-03-07 01:25:00 +01:00
|
|
|
_commands.put("text-transform", new TextTransformCommand());
|
|
|
|
_commands.put("mass-edit", new MassEditCommand());
|
|
|
|
_commands.put("join-multi-value-cells", new JoinMultiValueCellsCommand());
|
|
|
|
_commands.put("split-multi-value-cells", new SplitMultiValueCellsCommand());
|
2010-03-03 05:19:58 +01:00
|
|
|
|
|
|
|
_commands.put("add-column", new AddColumnCommand());
|
|
|
|
_commands.put("remove-column", new RemoveColumnCommand());
|
|
|
|
|
|
|
|
_commands.put("reconcile", new ReconcileCommand());
|
|
|
|
_commands.put("recon-match-best-candidates", new ReconMatchBestCandidatesCommand());
|
|
|
|
_commands.put("recon-mark-new-topics", new ReconMarkNewTopicsCommand());
|
|
|
|
_commands.put("recon-discard-judgments", new ReconDiscardJudgmentsCommand());
|
|
|
|
_commands.put("recon-match-specific-topic-to-cells", new ReconMatchSpecificTopicCommand());
|
|
|
|
_commands.put("recon-judge-one-cell", new ReconJudgeOneCellCommand());
|
2010-02-22 05:23:25 +01:00
|
|
|
_commands.put("recon-judge-similar-cells", new ReconJudgeSimilarCellsCommand());
|
2010-03-03 05:19:58 +01:00
|
|
|
|
2010-02-23 08:45:12 +01:00
|
|
|
_commands.put("annotate-one-row", new AnnotateOneRowCommand());
|
|
|
|
_commands.put("annotate-rows", new AnnotateRowsCommand());
|
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
_commands.put("save-protograph", new SaveProtographCommand());
|
|
|
|
|
2010-02-07 10:02:22 +01:00
|
|
|
_commands.put("get-expression-language-info", new GetExpressionLanguageInfoCommand());
|
2010-03-03 22:21:38 +01:00
|
|
|
_commands.put("get-expression-history", new GetExpressionHistoryCommand());
|
|
|
|
_commands.put("log-expression", new LogExpressionCommand());
|
|
|
|
|
2010-03-13 08:13:18 +01:00
|
|
|
_commands.put("preview-expression", new PreviewExpressionCommand());
|
|
|
|
_commands.put("preview-extend-data", new PreviewExtendDataCommand());
|
2010-02-16 21:15:19 +01:00
|
|
|
_commands.put("preview-protograph", new PreviewProtographCommand());
|
2010-03-13 08:13:18 +01:00
|
|
|
|
2010-02-19 01:28:34 +01:00
|
|
|
_commands.put("guess-types-of-column", new GuessTypesOfColumnCommand());
|
2010-03-03 05:19:58 +01:00
|
|
|
}
|
2010-01-24 22:09:50 +01:00
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
@Override
|
|
|
|
public void init() throws ServletException {
|
|
|
|
super.init();
|
2010-03-08 01:37:06 +01:00
|
|
|
|
|
|
|
ProjectManager.initialize();
|
|
|
|
|
|
|
|
long period = 1000 * 60 * 5; // 5 minutes
|
|
|
|
_timer.scheduleAtFixedRate(new TimerTask() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
ProjectManager.singleton.save(false);
|
|
|
|
}
|
|
|
|
}, period, period);
|
2010-03-03 05:19:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void destroy() {
|
2010-03-08 01:37:06 +01:00
|
|
|
_timer.cancel();
|
|
|
|
_timer = null;
|
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
if (ProjectManager.singleton != null) {
|
2010-03-08 01:37:06 +01:00
|
|
|
ProjectManager.singleton.save(true);
|
2010-03-03 05:19:58 +01:00
|
|
|
ProjectManager.singleton = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
super.destroy();
|
|
|
|
}
|
|
|
|
|
2010-01-24 22:09:50 +01:00
|
|
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
2010-03-04 08:02:03 +01:00
|
|
|
Command command = _commands.get(getCommandName(request));
|
2010-03-03 05:19:58 +01:00
|
|
|
if (command != null) {
|
|
|
|
command.doPost(request, response);
|
|
|
|
}
|
2010-01-24 22:09:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
2010-03-04 08:02:03 +01:00
|
|
|
Command command = _commands.get(getCommandName(request));
|
2010-03-03 05:19:58 +01:00
|
|
|
if (command != null) {
|
|
|
|
command.doGet(request, response);
|
|
|
|
}
|
2010-01-24 22:09:50 +01:00
|
|
|
}
|
|
|
|
|
2010-03-04 08:02:03 +01:00
|
|
|
protected String getCommandName(HttpServletRequest request) {
|
|
|
|
String commandName = request.getPathInfo().substring(1);
|
|
|
|
int slash = commandName.indexOf('/');
|
|
|
|
return slash > 0 ? commandName.substring(0, slash) : commandName;
|
|
|
|
}
|
2010-01-24 22:09:50 +01:00
|
|
|
}
|