Search in sources :

Example 1 with RowDependency

use of com.google.refine.model.RecordModel.RowDependency in project OpenRefine by OpenRefine.

the class DenormalizeOperation method createHistoryEntry.

@Override
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
    List<Row> newRows = new ArrayList<Row>();
    List<Row> oldRows = project.rows;
    for (int r = 0; r < oldRows.size(); r++) {
        Row oldRow = oldRows.get(r);
        Row newRow = null;
        RowDependency rd = project.recordModel.getRowDependency(r);
        if (rd.cellDependencies != null) {
            newRow = oldRow.dup();
            for (CellDependency cd : rd.cellDependencies) {
                if (cd != null) {
                    int contextRowIndex = cd.rowIndex;
                    int contextCellIndex = cd.cellIndex;
                    if (contextRowIndex >= 0 && contextRowIndex < oldRows.size()) {
                        Row contextRow = oldRows.get(contextRowIndex);
                        Cell contextCell = contextRow.getCell(contextCellIndex);
                        newRow.setCell(contextCellIndex, contextCell);
                    }
                }
            }
        }
        newRows.add(newRow != null ? newRow : oldRow);
    }
    return new HistoryEntry(historyEntryID, project, getBriefDescription(project), DenormalizeOperation.this, new MassRowChange(newRows));
}
Also used : MassRowChange(com.google.refine.model.changes.MassRowChange) CellDependency(com.google.refine.model.RecordModel.CellDependency) ArrayList(java.util.ArrayList) HistoryEntry(com.google.refine.history.HistoryEntry) Row(com.google.refine.model.Row) RowDependency(com.google.refine.model.RecordModel.RowDependency) Cell(com.google.refine.model.Cell)

Example 2 with RowDependency

use of com.google.refine.model.RecordModel.RowDependency in project OpenRefine by OpenRefine.

the class StandardReconConfig method createJob.

@Override
public ReconJob createJob(Project project, int rowIndex, Row row, String columnName, Cell cell) {
    StandardReconJob job = new StandardReconJob();
    List<QueryProperty> properties = new ArrayList<>();
    for (ColumnDetail c : columnDetails) {
        int detailCellIndex = project.columnModel.getColumnByName(c.columnName).getCellIndex();
        Cell cell2 = row.getCell(detailCellIndex);
        if (cell2 == null || !ExpressionUtils.isNonBlankData(cell2.value)) {
            int cellIndex = project.columnModel.getColumnByName(columnName).getCellIndex();
            RowDependency rd = project.recordModel.getRowDependency(rowIndex);
            if (rd != null && rd.cellDependencies != null) {
                int contextRowIndex = rd.cellDependencies[cellIndex].rowIndex;
                if (contextRowIndex >= 0 && contextRowIndex < project.rows.size()) {
                    Row row2 = project.rows.get(contextRowIndex);
                    cell2 = row2.getCell(detailCellIndex);
                }
            }
        }
        if (cell2 != null && ExpressionUtils.isNonBlankData(cell2.value)) {
            Object v = null;
            if (cell2.recon != null && cell2.recon.match != null) {
                Map<String, String> recon = new HashMap<>();
                recon.put("id", cell2.recon.match.id);
                recon.put("name", cell2.recon.match.name);
                v = recon;
            } else {
                v = cell2.value;
            }
            properties.add(new QueryProperty(c.propertyID, v));
        }
    }
    ReconQuery query = new ReconQuery(cell.value.toString(), typeID, properties, limit);
    job.text = cell.value.toString();
    try {
        job.code = ParsingUtilities.defaultWriter.writeValueAsString(query);
    } catch (JsonProcessingException e) {
        // FIXME: This error will get lost
        e.printStackTrace();
        // TODO: Throw exception instead?
        return null;
    }
    return job;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RowDependency(com.google.refine.model.RecordModel.RowDependency) Row(com.google.refine.model.Row) Cell(com.google.refine.model.Cell) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

Cell (com.google.refine.model.Cell)2 RowDependency (com.google.refine.model.RecordModel.RowDependency)2 Row (com.google.refine.model.Row)2 ArrayList (java.util.ArrayList)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 HistoryEntry (com.google.refine.history.HistoryEntry)1 CellDependency (com.google.refine.model.RecordModel.CellDependency)1 MassRowChange (com.google.refine.model.changes.MassRowChange)1 HashMap (java.util.HashMap)1