Migrate ApplyOperationsCommand

This commit is contained in:
Antonin Delpeuch 2018-11-20 16:17:42 +00:00
parent 377b051bac
commit a76d88122a

View File

@ -40,10 +40,8 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.json.JSONArray; import com.fasterxml.jackson.databind.node.ArrayNode;
import org.json.JSONException; import com.fasterxml.jackson.databind.node.ObjectNode;
import org.json.JSONObject;
import com.google.refine.commands.Command; import com.google.refine.commands.Command;
import com.google.refine.model.AbstractOperation; import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project; import com.google.refine.model.Project;
@ -59,12 +57,14 @@ public class ApplyOperationsCommand extends Command {
Project project = getProject(request); Project project = getProject(request);
String jsonString = request.getParameter("operations"); String jsonString = request.getParameter("operations");
try { try {
JSONArray a = ParsingUtilities.evaluateJsonStringToArray(jsonString); ArrayNode a = ParsingUtilities.evaluateJsonStringToArrayNode(jsonString);
int count = a.length(); int count = a.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
JSONObject obj = a.getJSONObject(i); if (a.get(i) instanceof ObjectNode) {
ObjectNode obj = (ObjectNode) a.get(i);
reconstructOperation(project, obj);
reconstructOperation(project, obj);
}
} }
if (project.processManager.hasPending()) { if (project.processManager.hasPending()) {
@ -72,13 +72,13 @@ public class ApplyOperationsCommand extends Command {
} else { } else {
respond(response, "{ \"code\" : \"ok\" }"); respond(response, "{ \"code\" : \"ok\" }");
} }
} catch (JSONException e) { } catch (IOException e) {
respondException(response, e); respondException(response, e);
} }
} }
protected void reconstructOperation(Project project, JSONObject obj) throws IOException { protected void reconstructOperation(Project project, ObjectNode obj) throws IOException {
AbstractOperation operation = ParsingUtilities.mapper.readValue(obj.toString(), AbstractOperation.class); AbstractOperation operation = ParsingUtilities.mapper.convertValue(obj, AbstractOperation.class);
if (operation != null) { if (operation != null) {
try { try {
Process process = operation.createProcess(project, new Properties()); Process process = operation.createProcess(project, new Properties());