2010-02-03 03:29:47 +01:00
|
|
|
package com.metaweb.gridworks;
|
2010-01-24 22:09:50 +01:00
|
|
|
|
2010-01-25 23:51:25 +01:00
|
|
|
import java.io.File;
|
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-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;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONTokener;
|
|
|
|
|
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-05 20:19:38 +01:00
|
|
|
import com.metaweb.gridworks.commands.edit.CreateProjectCommand;
|
2010-02-04 07:12:22 +01:00
|
|
|
import com.metaweb.gridworks.commands.edit.DoTextTransformCommand;
|
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-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;
|
|
|
|
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;
|
|
|
|
import com.metaweb.gridworks.commands.info.GetColumnModelCommand;
|
|
|
|
import com.metaweb.gridworks.commands.info.GetHistoryCommand;
|
|
|
|
import com.metaweb.gridworks.commands.info.GetProcessesCommand;
|
|
|
|
import com.metaweb.gridworks.commands.info.GetProjectMetadataCommand;
|
|
|
|
import com.metaweb.gridworks.commands.info.GetRowsCommand;
|
|
|
|
import com.metaweb.gridworks.commands.recon.ApproveNewReconcileCommand;
|
|
|
|
import com.metaweb.gridworks.commands.recon.ApproveReconcileCommand;
|
|
|
|
import com.metaweb.gridworks.commands.recon.DiscardReconcileCommand;
|
|
|
|
import com.metaweb.gridworks.commands.recon.ReconcileCommand;
|
2010-02-07 10:02:22 +01:00
|
|
|
import com.metaweb.gridworks.commands.util.GetExpressionLanguageInfoCommand;
|
2010-02-04 07:12:22 +01:00
|
|
|
import com.metaweb.gridworks.commands.util.PreviewExpressionCommand;
|
2010-01-25 23:51:25 +01:00
|
|
|
|
2010-02-03 03:29:47 +01:00
|
|
|
public class GridworksServlet extends HttpServlet {
|
2010-01-24 22:09:50 +01:00
|
|
|
private static final long serialVersionUID = 2386057901503517403L;
|
|
|
|
|
2010-01-25 23:51:25 +01:00
|
|
|
static protected Map<String, Command> _commands = new HashMap<String, Command>();
|
|
|
|
|
|
|
|
static {
|
2010-02-05 20:19:38 +01:00
|
|
|
_commands.put("create-project-from-upload", new CreateProjectCommand());
|
2010-02-05 02:58:06 +01:00
|
|
|
_commands.put("export-rows", new ExportRowsCommand());
|
2010-02-01 04:22:35 +01:00
|
|
|
|
2010-01-26 06:17:14 +01:00
|
|
|
_commands.put("get-project-metadata", new GetProjectMetadataCommand());
|
2010-02-03 07:23:40 +01:00
|
|
|
_commands.put("get-all-project-metadata", new GetAllProjectMetadataCommand());
|
|
|
|
|
2010-01-25 23:51:25 +01:00
|
|
|
_commands.put("get-column-model", new GetColumnModelCommand());
|
|
|
|
_commands.put("get-rows", new GetRowsCommand());
|
2010-02-01 04:22:35 +01:00
|
|
|
_commands.put("get-processes", new GetProcessesCommand());
|
2010-01-27 02:48:42 +01:00
|
|
|
_commands.put("get-history", new GetHistoryCommand());
|
2010-02-01 04:22:35 +01:00
|
|
|
|
2010-01-27 02:48:42 +01:00
|
|
|
_commands.put("undo-redo", new UndoRedoCommand());
|
2010-02-01 04:22:35 +01:00
|
|
|
_commands.put("compute-facets", new ComputeFacetsCommand());
|
2010-01-27 02:48:42 +01:00
|
|
|
_commands.put("do-text-transform", new DoTextTransformCommand());
|
2010-02-02 21:50:35 +01:00
|
|
|
|
2010-02-05 00:38:40 +01:00
|
|
|
_commands.put("add-column", new AddColumnCommand());
|
|
|
|
_commands.put("remove-column", new RemoveColumnCommand());
|
2010-02-05 07:29:27 +01:00
|
|
|
_commands.put("join-multi-value-cells", new JoinMultiValueCellsCommand());
|
|
|
|
_commands.put("split-multi-value-cells", new SplitMultiValueCellsCommand());
|
2010-02-05 00:38:40 +01:00
|
|
|
|
2010-02-01 09:31:50 +01:00
|
|
|
_commands.put("reconcile", new ReconcileCommand());
|
2010-02-02 21:50:35 +01:00
|
|
|
_commands.put("approve-reconcile", new ApproveReconcileCommand());
|
|
|
|
_commands.put("approve-new-reconcile", new ApproveNewReconcileCommand());
|
|
|
|
_commands.put("discard-reconcile", new DiscardReconcileCommand());
|
2010-02-03 10:27:53 +01:00
|
|
|
|
|
|
|
_commands.put("preview-expression", new PreviewExpressionCommand());
|
2010-02-07 10:02:22 +01:00
|
|
|
_commands.put("get-expression-language-info", new GetExpressionLanguageInfoCommand());
|
2010-01-25 23:51:25 +01:00
|
|
|
}
|
2010-01-24 22:09:50 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void init() throws ServletException {
|
|
|
|
super.init();
|
2010-01-25 23:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void destroy() {
|
2010-02-08 00:15:50 +01:00
|
|
|
if (ProjectManager.singleton != null) {
|
|
|
|
ProjectManager.singleton.saveAllProjects();
|
|
|
|
ProjectManager.singleton.save();
|
|
|
|
ProjectManager.singleton = null;
|
|
|
|
}
|
2010-01-24 22:09:50 +01:00
|
|
|
|
2010-01-25 23:51:25 +01:00
|
|
|
super.destroy();
|
2010-01-24 22:09:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
2010-01-25 23:51:25 +01:00
|
|
|
ProjectManager.initialize(new File("./data"));
|
|
|
|
|
|
|
|
String commandName = request.getPathInfo().substring(1);
|
|
|
|
Command command = _commands.get(commandName);
|
|
|
|
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-01-25 23:51:25 +01:00
|
|
|
ProjectManager.initialize(new File("./data"));
|
|
|
|
|
|
|
|
String commandName = request.getPathInfo().substring(1);
|
|
|
|
Command command = _commands.get(commandName);
|
|
|
|
if (command != null) {
|
|
|
|
command.doGet(request, response);
|
|
|
|
}
|
2010-01-24 22:09:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static public JSONObject evaluateJsonStringToObject(String s) throws JSONException {
|
|
|
|
JSONTokener t = new JSONTokener(s);
|
|
|
|
JSONObject o = (JSONObject) t.nextValue();
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String encodeString(String s) {
|
|
|
|
return s.replace("\"", "\\\"");
|
|
|
|
}
|
|
|
|
}
|