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));
}
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;
}
Aggregations