2010-01-24 22:09:50 +01:00
|
|
|
package com.metaweb.gridlock;
|
|
|
|
|
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-02 21:50:35 +01:00
|
|
|
import com.metaweb.gridlock.commands.ApproveNewReconcileCommand;
|
|
|
|
import com.metaweb.gridlock.commands.ApproveReconcileCommand;
|
2010-01-25 23:51:25 +01:00
|
|
|
import com.metaweb.gridlock.commands.Command;
|
2010-01-30 02:05:30 +01:00
|
|
|
import com.metaweb.gridlock.commands.ComputeFacetsCommand;
|
2010-01-25 23:51:25 +01:00
|
|
|
import com.metaweb.gridlock.commands.CreateProjectFromUploadCommand;
|
2010-02-02 21:50:35 +01:00
|
|
|
import com.metaweb.gridlock.commands.DiscardReconcileCommand;
|
2010-01-27 02:48:42 +01:00
|
|
|
import com.metaweb.gridlock.commands.DoTextTransformCommand;
|
2010-01-25 23:51:25 +01:00
|
|
|
import com.metaweb.gridlock.commands.GetColumnModelCommand;
|
2010-01-27 02:48:42 +01:00
|
|
|
import com.metaweb.gridlock.commands.GetHistoryCommand;
|
2010-02-01 04:22:35 +01:00
|
|
|
import com.metaweb.gridlock.commands.GetProcessesCommand;
|
2010-01-26 06:17:14 +01:00
|
|
|
import com.metaweb.gridlock.commands.GetProjectMetadataCommand;
|
2010-01-25 23:51:25 +01:00
|
|
|
import com.metaweb.gridlock.commands.GetRowsCommand;
|
2010-02-01 09:31:50 +01:00
|
|
|
import com.metaweb.gridlock.commands.ReconcileCommand;
|
2010-01-27 02:48:42 +01:00
|
|
|
import com.metaweb.gridlock.commands.UndoRedoCommand;
|
2010-01-25 23:51:25 +01:00
|
|
|
|
2010-01-24 22:09:50 +01:00
|
|
|
public class GridlockServlet extends HttpServlet {
|
|
|
|
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 {
|
|
|
|
_commands.put("create-project-from-upload", new CreateProjectFromUploadCommand());
|
2010-02-01 04:22:35 +01:00
|
|
|
|
2010-01-26 06:17:14 +01:00
|
|
|
_commands.put("get-project-metadata", new GetProjectMetadataCommand());
|
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-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-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() {
|
|
|
|
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("\"", "\\\"");
|
|
|
|
}
|
|
|
|
}
|