use of com.google.refine.model.Project in project OpenRefine by OpenRefine.
the class ApplyOperationsCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (!hasValidCSRFToken(request)) {
respondCSRFError(response);
return;
}
Project project = getProject(request);
String jsonString = request.getParameter("operations");
try {
ArrayNode a = ParsingUtilities.evaluateJsonStringToArrayNode(jsonString);
int count = a.size();
for (int i = 0; i < count; i++) {
if (a.get(i) instanceof ObjectNode) {
ObjectNode obj = (ObjectNode) a.get(i);
reconstructOperation(project, obj);
}
}
if (project.processManager.hasPending()) {
respond(response, "{ \"code\" : \"pending\" }");
} else {
respond(response, "{ \"code\" : \"ok\" }");
}
} catch (IOException e) {
respondException(response, e);
}
}
use of com.google.refine.model.Project in project OpenRefine by OpenRefine.
the class UndoRedoCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (!hasValidCSRFToken(request)) {
respondCSRFError(response);
return;
}
Project project = getProject(request);
long lastDoneID = -1;
String lastDoneIDString = request.getParameter("lastDoneID");
if (lastDoneIDString != null) {
lastDoneID = Long.parseLong(lastDoneIDString);
} else {
String undoIDString = request.getParameter("undoID");
if (undoIDString != null) {
long undoID = Long.parseLong(undoIDString);
lastDoneID = project.history.getPrecedingEntryID(undoID);
}
}
try {
boolean done = lastDoneID == -1 || project.processManager.queueProcess(new HistoryProcess(project, lastDoneID));
respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
} catch (Exception e) {
respondException(response, e);
}
}
use of com.google.refine.model.Project in project OpenRefine by OpenRefine.
the class TransposeRowsIntoColumnsCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (!hasValidCSRFToken(request)) {
respondCSRFError(response);
return;
}
try {
Project project = getProject(request);
String columnName = request.getParameter("columnName");
int rowCount = Integer.parseInt(request.getParameter("rowCount"));
AbstractOperation op = new TransposeRowsIntoColumnsOperation(columnName, rowCount);
Process process = op.createProcess(project, new Properties());
performProcessAndRespond(request, response, project, process);
} catch (Exception e) {
respondException(response, e);
}
}
use of com.google.refine.model.Project in project OpenRefine by OpenRefine.
the class RenameColumnCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (!hasValidCSRFToken(request)) {
respondCSRFError(response);
return;
}
try {
Project project = getProject(request);
String oldColumnName = request.getParameter("oldColumnName");
String newColumnName = request.getParameter("newColumnName");
AbstractOperation op = new ColumnRenameOperation(oldColumnName, newColumnName);
Process process = op.createProcess(project, new Properties());
performProcessAndRespond(request, response, project, process);
} catch (Exception e) {
respondException(response, e);
}
}
use of com.google.refine.model.Project in project OpenRefine by OpenRefine.
the class SetProjectTagsCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (!hasValidCSRFToken(request)) {
respondCSRFError(response);
return;
}
response.setHeader("Content-Type", "application/json");
Project project;
try {
project = getProject(request);
} catch (ServletException e) {
respond(response, "error", e.getLocalizedMessage());
return;
}
ProjectMetadata metadata = project.getMetadata();
String oldT = request.getParameter("old");
String newT = request.getParameter("new");
Map<String, Integer> allProjectTags = ProjectManager.singleton.getAllProjectTags();
// Lets remove the old tags from the general map
String[] oldTags = oldT.split(",");
for (String tag : oldTags) {
if (allProjectTags != null && allProjectTags.containsKey(tag)) {
int occurrence = allProjectTags.get(tag);
if (occurrence == 1) {
allProjectTags.remove(tag);
} else {
allProjectTags.put(tag, occurrence - 1);
}
}
}
// Lets add the new tags to the general map
String[] newTags = newT.split(" |\\,");
List<String> polishedTags = new ArrayList<String>(newTags.length);
for (String tag : newTags) {
tag = tag.trim();
if (!tag.isEmpty()) {
if (allProjectTags != null) {
if (allProjectTags.containsKey(tag)) {
allProjectTags.put(tag, allProjectTags.get(tag) + 1);
} else {
allProjectTags.put(tag, 1);
}
}
polishedTags.add(tag);
}
}
// Lets update the project tags
metadata.setTags(polishedTags.toArray(new String[polishedTags.size()]));
metadata.updateModified();
respond(response, "{ \"code\" : \"ok\" }");
}
Aggregations