use of com.google.refine.model.Project in project OpenRefine by OpenRefine.
the class History method addEntry.
/**
* Adds a HistoryEntry to the list of past histories
* Adding a new entry clears all currently held future histories
* @param entry
*/
public void addEntry(HistoryEntry entry) {
Project project = ProjectManager.singleton.getProject(_projectID);
synchronized (project) {
// synchronized block instead of synchronizing the entire method.
synchronized (this) {
entry.apply(project);
_pastEntries.add(entry);
setModified();
// Any new change will clear all future entries.
List<HistoryEntry> futureEntries = _futureEntries;
_futureEntries = new ArrayList<HistoryEntry>();
for (HistoryEntry entry2 : futureEntries) {
try {
// remove residual data on disk
entry2.delete();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
use of com.google.refine.model.Project in project OpenRefine by OpenRefine.
the class ProjectManagerTests method canSaveAllModified.
// TODO test ensureProjectSave in race condition
@Test
public void canSaveAllModified() {
// 5 minute difference
whenGetSaveTimes(project, metadata);
registerProject(project, metadata);
// add a second project to the cache
Project project2 = spy(new ProjectStub(2));
ProjectMetadata metadata2 = mock(ProjectMetadata.class);
// not modified since the last save but within 30 seconds flush limit
whenGetSaveTimes(project2, metadata2, 10);
registerProject(project2, metadata2);
// check that the two projects are not the same
Assert.assertFalse(project.id == project2.id);
SUT.save(true);
verifySaved(project, metadata);
verifySaved(project2, metadata2);
verify(SUT, times(1)).saveWorkspace();
}
use of com.google.refine.model.Project in project OpenRefine by OpenRefine.
the class RefineTest method createCSVProject.
/**
* Helper to create a project from a CSV encoded as a file. Not much control is given on the import options, because
* this method is intended to be a quick way to create a project for a test. For more control over the import, just
* call the importer directly.
*
* The projects created via this method and their importing jobs will be disposed of at the end of each test.
*
* @param projectName
* the name of the project to create
* @param input
* the content of the file, encoded as a CSV (with "," as a separator)
* @return
*/
protected Project createCSVProject(String projectName, String input) {
Project project = new Project();
ProjectMetadata metadata = new ProjectMetadata();
metadata.setName(projectName);
ObjectNode options = mock(ObjectNode.class);
prepareImportOptions(options, ",", -1, 0, 0, 1, false, false);
ImportingJob job = ImportingManager.createJob();
SeparatorBasedImporter importer = new SeparatorBasedImporter();
List<Exception> exceptions = new ArrayList<Exception>();
importer.parseOneFile(project, metadata, job, "filesource", new StringReader(input), -1, options, exceptions);
project.update();
ProjectManager.singleton.registerProject(project, metadata);
projects.add(project);
importingJobs.add(job);
return project;
}
use of com.google.refine.model.Project in project OpenRefine by OpenRefine.
the class RefineTest method createProjectWithColumns.
protected Project createProjectWithColumns(String projectName, String... columnNames) throws IOException, ModelException {
Project project = new Project();
ProjectMetadata pm = new ProjectMetadata();
pm.setName(projectName);
ProjectManager.singleton.registerProject(project, pm);
if (columnNames != null) {
for (String columnName : columnNames) {
int index = project.columnModel.allocateNewCellIndex();
Column column = new Column(index, columnName);
project.columnModel.addColumn(index, column, true);
}
}
return project;
}
use of com.google.refine.model.Project in project OpenRefine by OpenRefine.
the class ReconCopyAcrossColumnsOperation method createHistoryEntry.
@Override
protected HistoryEntry createHistoryEntry(final Project project, final long historyEntryID) throws Exception {
Engine engine = createEngine(project);
final Column fromColumn = project.columnModel.getColumnByName(_fromColumnName);
final List<Column> toColumns = new ArrayList<Column>(_toColumnNames.length);
for (String c : _toColumnNames) {
Column toColumn = project.columnModel.getColumnByName(c);
if (toColumn != null) {
toColumns.add(toColumn);
}
}
final Set<Recon.Judgment> judgments = new HashSet<Recon.Judgment>(_judgments.length);
for (String j : _judgments) {
judgments.add(Recon.stringToJudgment(j));
}
final List<CellChange> cellChanges = new ArrayList<CellChange>(project.rows.size());
if (fromColumn != null && toColumns.size() > 0) {
final Map<Object, Recon> cellValueToRecon = new HashMap<Object, Recon>();
FilteredRows filteredRows = engine.getAllFilteredRows();
try {
filteredRows.accept(project, new RowVisitor() {
@Override
public void start(Project project) {
// nothing to do
}
@Override
public void end(Project project) {
// nothing to do
}
@Override
public boolean visit(Project project, int rowIndex, Row row) {
Cell cell = row.getCell(fromColumn.getCellIndex());
if (cell != null && cell.value != null && cell.recon != null) {
if (judgments.contains(cell.recon.judgment)) {
cellValueToRecon.put(cell.value, cell.recon);
}
}
return false;
}
});
filteredRows.accept(project, new RowVisitor() {
@Override
public void start(Project project) {
// nothing to do
}
@Override
public void end(Project project) {
// nothing to do
}
@Override
public boolean visit(Project project, int rowIndex, Row row) {
for (Column column : toColumns) {
int cellIndex = column.getCellIndex();
Cell cell = row.getCell(cellIndex);
if (cell != null && cell.value != null) {
Recon reconToCopy = cellValueToRecon.get(cell.value);
boolean judged = cell.recon != null && cell.recon.judgment != Judgment.None;
if (reconToCopy != null && (!judged || _applyToJudgedCells)) {
Cell newCell = new Cell(cell.value, reconToCopy);
CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, newCell);
cellChanges.add(cellChange);
}
}
}
return false;
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
String description = "Copy " + cellChanges.size() + " recon judgments from column " + _fromColumnName + " to " + StringUtils.join(_toColumnNames);
return new HistoryEntry(historyEntryID, project, description, this, new MassChange(cellChanges, false));
}
Aggregations