use of com.google.refine.history.HistoryEntry in project OpenRefine by OpenRefine.
the class ReconClearOneCellCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
Project project = getProject(request);
int rowIndex = Integer.parseInt(request.getParameter("row"));
int cellIndex = Integer.parseInt(request.getParameter("cell"));
ClearOneCellProcess process = new ClearOneCellProcess(project, "Clear one cell's recon data", rowIndex, cellIndex);
HistoryEntry historyEntry = project.processManager.queueProcess(process);
if (historyEntry != null) {
/*
* If the process is done, write back the cell's data so that the
* client side can update its UI right away.
*/
JSONWriter writer = new JSONWriter(response.getWriter());
Pool pool = new Pool();
Properties options = new Properties();
options.put("pool", pool);
writer.object();
writer.key("code");
writer.value("ok");
writer.key("historyEntry");
historyEntry.write(writer, options);
writer.key("cell");
process.newCell.write(writer, options);
writer.key("pool");
pool.write(writer, options);
writer.endObject();
} else {
respond(response, "{ \"code\" : \"pending\" }");
}
} catch (Exception e) {
respondException(response, e);
}
}
use of com.google.refine.history.HistoryEntry in project OpenRefine by OpenRefine.
the class ReconJudgeOneCellCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
Project project = getProject(request);
int rowIndex = Integer.parseInt(request.getParameter("row"));
int cellIndex = Integer.parseInt(request.getParameter("cell"));
Judgment judgment = Recon.stringToJudgment(request.getParameter("judgment"));
ReconCandidate match = null;
String id = request.getParameter("id");
if (id != null) {
String scoreString = request.getParameter("score");
match = new ReconCandidate(id, request.getParameter("name"), request.getParameter("types").split(","), scoreString != null ? Double.parseDouble(scoreString) : 100);
}
JudgeOneCellProcess process = new JudgeOneCellProcess(project, "Judge one cell's recon result", judgment, rowIndex, cellIndex, match, request.getParameter("identifierSpace"), request.getParameter("schemaSpace"));
HistoryEntry historyEntry = project.processManager.queueProcess(process);
if (historyEntry != null) {
/*
* If the process is done, write back the cell's data so that the
* client side can update its UI right away.
*/
JSONWriter writer = new JSONWriter(response.getWriter());
Pool pool = new Pool();
Properties options = new Properties();
options.put("pool", pool);
writer.object();
writer.key("code");
writer.value("ok");
writer.key("historyEntry");
historyEntry.write(writer, options);
writer.key("cell");
process.newCell.write(writer, options);
writer.key("pool");
pool.write(writer, options);
writer.endObject();
} else {
respond(response, "{ \"code\" : \"pending\" }");
}
} catch (Exception e) {
respondException(response, e);
}
}
use of com.google.refine.history.HistoryEntry in project OpenRefine by OpenRefine.
the class GetOperationsCommand method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Project project = getProject(request);
try {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json");
Properties options = new Properties();
JSONWriter writer = new JSONWriter(response.getWriter());
writer.object();
writer.key("entries");
writer.array();
for (HistoryEntry entry : project.history.getLastPastEntries(-1)) {
writer.object();
writer.key("description");
writer.value(entry.description);
if (entry.operation != null) {
writer.key("operation");
entry.operation.write(writer, options);
}
writer.endObject();
}
writer.endArray();
writer.endObject();
} catch (JSONException e) {
respondException(response, e);
}
}
use of com.google.refine.history.HistoryEntry in project OpenRefine by OpenRefine.
the class TransposeRowsIntoColumnsOperation method createHistoryEntry.
@Override
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
List<Column> newColumns = new ArrayList<Column>();
List<Column> oldColumns = project.columnModel.columns;
int columnIndex = project.columnModel.getColumnIndexByName(_columnName);
int columnCount = oldColumns.size();
for (int i = 0; i < columnCount; i++) {
Column column = oldColumns.get(i);
if (i == columnIndex) {
int newIndex = 1;
for (int n = 0; n < _rowCount; n++) {
String columnName = _columnName + " " + newIndex++;
while (project.columnModel.getColumnByName(columnName) != null) {
columnName = _columnName + " " + newIndex++;
}
newColumns.add(new Column(i + n, columnName));
}
} else if (i < columnIndex) {
newColumns.add(new Column(i, column.getName()));
} else {
newColumns.add(new Column(i + _rowCount - 1, column.getName()));
}
}
List<Row> oldRows = project.rows;
List<Row> newRows = new ArrayList<Row>(oldRows.size() / _rowCount);
for (int r = 0; r < oldRows.size(); r += _rowCount) {
Row firstNewRow = new Row(newColumns.size());
for (int r2 = 0; r2 < _rowCount && r + r2 < oldRows.size(); r2++) {
Row oldRow = oldRows.get(r + r2);
Row newRow = r2 == 0 ? firstNewRow : new Row(newColumns.size());
boolean hasData = r2 == 0;
for (int c = 0; c < oldColumns.size(); c++) {
Column column = oldColumns.get(c);
Cell cell = oldRow.getCell(column.getCellIndex());
if (cell != null && cell.value != null) {
if (c == columnIndex) {
firstNewRow.setCell(columnIndex + r2, cell);
} else if (c < columnIndex) {
newRow.setCell(c, cell);
hasData = true;
} else {
newRow.setCell(c + _rowCount - 1, cell);
hasData = true;
}
}
}
if (hasData) {
newRows.add(newRow);
}
}
}
return new HistoryEntry(historyEntryID, project, getBriefDescription(null), this, new MassRowColumnChange(newColumns, newRows));
}
use of com.google.refine.history.HistoryEntry in project OpenRefine by OpenRefine.
the class ColumnAdditionOperation method createHistoryEntry.
@Override
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
Engine engine = createEngine(project);
Column column = project.columnModel.getColumnByName(_baseColumnName);
if (column == null) {
throw new Exception("No column named " + _baseColumnName);
}
if (project.columnModel.getColumnByName(_newColumnName) != null) {
throw new Exception("Another column already named " + _newColumnName);
}
List<CellAtRow> cellsAtRows = new ArrayList<CellAtRow>(project.rows.size());
FilteredRows filteredRows = engine.getAllFilteredRows();
filteredRows.accept(project, createRowVisitor(project, cellsAtRows));
String description = createDescription(column, cellsAtRows);
Change change = new ColumnAdditionChange(_newColumnName, _columnInsertIndex, cellsAtRows);
return new HistoryEntry(historyEntryID, project, description, this, change);
}
Aggregations