Search in sources :

Example 1 with HistoryEntry

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);
    }
}
Also used : JSONWriter(org.json.JSONWriter) Project(com.google.refine.model.Project) HistoryEntry(com.google.refine.history.HistoryEntry) Pool(com.google.refine.util.Pool) Properties(java.util.Properties) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 2 with HistoryEntry

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);
    }
}
Also used : JSONWriter(org.json.JSONWriter) Project(com.google.refine.model.Project) HistoryEntry(com.google.refine.history.HistoryEntry) Pool(com.google.refine.util.Pool) Properties(java.util.Properties) ReconCandidate(com.google.refine.model.ReconCandidate) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Judgment(com.google.refine.model.Recon.Judgment)

Example 3 with HistoryEntry

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);
    }
}
Also used : JSONWriter(org.json.JSONWriter) Project(com.google.refine.model.Project) HistoryEntry(com.google.refine.history.HistoryEntry) JSONException(org.json.JSONException) Properties(java.util.Properties)

Example 4 with HistoryEntry

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));
}
Also used : Column(com.google.refine.model.Column) MassRowColumnChange(com.google.refine.model.changes.MassRowColumnChange) ArrayList(java.util.ArrayList) HistoryEntry(com.google.refine.history.HistoryEntry) Row(com.google.refine.model.Row) Cell(com.google.refine.model.Cell)

Example 5 with HistoryEntry

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);
}
Also used : CellAtRow(com.google.refine.model.changes.CellAtRow) ColumnAdditionChange(com.google.refine.model.changes.ColumnAdditionChange) Column(com.google.refine.model.Column) ArrayList(java.util.ArrayList) HistoryEntry(com.google.refine.history.HistoryEntry) Change(com.google.refine.history.Change) ColumnAdditionChange(com.google.refine.model.changes.ColumnAdditionChange) FilteredRows(com.google.refine.browsing.FilteredRows) Engine(com.google.refine.browsing.Engine) JSONException(org.json.JSONException)

Aggregations

HistoryEntry (com.google.refine.history.HistoryEntry)22 ArrayList (java.util.ArrayList)15 Column (com.google.refine.model.Column)10 Engine (com.google.refine.browsing.Engine)8 JSONException (org.json.JSONException)8 FilteredRows (com.google.refine.browsing.FilteredRows)7 Cell (com.google.refine.model.Cell)7 Row (com.google.refine.model.Row)7 Project (com.google.refine.model.Project)6 Properties (java.util.Properties)6 Change (com.google.refine.history.Change)5 JSONWriter (org.json.JSONWriter)5 JSONObject (org.json.JSONObject)4 RowVisitor (com.google.refine.browsing.RowVisitor)3 MassChange (com.google.refine.model.changes.MassChange)3 MassRowChange (com.google.refine.model.changes.MassRowChange)3 MassRowColumnChange (com.google.refine.model.changes.MassRowColumnChange)3 Pool (com.google.refine.util.Pool)3 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3