Search in sources :

Example 71 with Project

use of com.google.refine.model.Project in project OpenRefine by OpenRefine.

the class SortingRecordVisitor method end.

@Override
public void end(Project project) {
    _visitor.start(project);
    Collections.sort(_records, new Comparator<Record>() {

        Project project;

        Comparator<Record> init(Project project) {
            this.project = project;
            return this;
        }

        @Override
        public int compare(Record o1, Record o2) {
            return SortingRecordVisitor.this.compare(project, o1, o1.recordIndex, o2, o2.recordIndex);
        }
    }.init(project));
    for (Record record : _records) {
        _visitor.visit(project, record);
    }
    _visitor.end(project);
}
Also used : Project(com.google.refine.model.Project) Record(com.google.refine.model.Record) Comparator(java.util.Comparator)

Example 72 with Project

use of com.google.refine.model.Project in project OpenRefine by OpenRefine.

the class TimeRangeFacetTests method serializeTimeRangeFacet.

@Test
public void serializeTimeRangeFacet() throws JsonParseException, JsonMappingException, IOException {
    Project project = createCSVProject("my column\n" + "placeholder\n" + "nontime\n" + "placeholder\n" + "placeholder\n");
    project.rows.get(0).cells.set(0, new Cell(OffsetDateTime.parse("2018-01-03T08:09:10Z"), null));
    project.rows.get(2).cells.set(0, new Cell(OffsetDateTime.parse("2008-01-03T03:04:05Z"), null));
    project.rows.get(3).cells.set(0, new Cell(OffsetDateTime.parse("2012-04-05T02:00:01Z"), null));
    Engine engine = new Engine(project);
    TimeRangeFacetConfig config = ParsingUtilities.mapper.readValue(configJson, TimeRangeFacetConfig.class);
    TimeRangeFacet facet = config.apply(project);
    facet.computeChoices(project, engine.getAllFilteredRows());
    TestUtils.isSerializedTo(facet, facetJson);
}
Also used : Project(com.google.refine.model.Project) Cell(com.google.refine.model.Cell) TimeRangeFacet(com.google.refine.browsing.facets.TimeRangeFacet) Engine(com.google.refine.browsing.Engine) TimeRangeFacetConfig(com.google.refine.browsing.facets.TimeRangeFacet.TimeRangeFacetConfig) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test)

Example 73 with Project

use of com.google.refine.model.Project in project OpenRefine by OpenRefine.

the class InterProjectModel method computeJoin.

protected void computeJoin(ProjectJoin join) {
    if (join.fromProjectID < 0 || join.toProjectID < 0) {
        return;
    }
    Project fromProject = ProjectManager.singleton.getProject(join.fromProjectID);
    Project toProject = ProjectManager.singleton.getProject(join.toProjectID);
    if (fromProject == null || toProject == null) {
        return;
    }
    Column fromColumn = fromProject.columnModel.getColumnByName(join.fromProjectColumnName);
    Column toColumn = toProject.columnModel.getColumnByName(join.toProjectColumnName);
    if (fromColumn == null || toColumn == null) {
        return;
    }
    for (Row fromRow : fromProject.rows) {
        Object value = fromRow.getCellValue(fromColumn.getCellIndex());
        if (ExpressionUtils.isNonBlankData(value) && !join.valueToRowIndices.containsKey(value)) {
            join.valueToRowIndices.put(value, new ArrayList<Integer>());
        }
    }
    int count = toProject.rows.size();
    for (int r = 0; r < count; r++) {
        Row toRow = toProject.rows.get(r);
        Object value = toRow.getCellValue(toColumn.getCellIndex());
        if (ExpressionUtils.isNonBlankData(value) && join.valueToRowIndices.containsKey(value)) {
            join.valueToRowIndices.get(value).add(r);
        }
    }
}
Also used : Project(com.google.refine.model.Project) Column(com.google.refine.model.Column) WrappedRow(com.google.refine.expr.WrappedRow) Row(com.google.refine.model.Row)

Example 74 with Project

use of com.google.refine.model.Project in project OpenRefine by OpenRefine.

the class TransposeTests method SetUp.

@BeforeMethod
public void SetUp() {
    servlet = new RefineServletStub();
    ProjectManager.singleton = new ProjectManagerStub();
    ImportingManager.initialize(servlet);
    project = new Project();
    metadata = new ProjectMetadata();
    job = ImportingManager.createJob();
    options = mock(JSONObject.class);
    importer = new SeparatorBasedImporter();
}
Also used : Project(com.google.refine.model.Project) ProjectManagerStub(com.google.refine.tests.ProjectManagerStub) RefineServletStub(com.google.refine.tests.RefineServletStub) JSONObject(org.json.JSONObject) ProjectMetadata(com.google.refine.ProjectMetadata) SeparatorBasedImporter(com.google.refine.importers.SeparatorBasedImporter) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 75 with Project

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();
}
Also used : Project(com.google.refine.model.Project) ProjectStub(com.google.refine.tests.model.ProjectStub) ProjectMetadata(com.google.refine.ProjectMetadata) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

Project (com.google.refine.model.Project)146 Properties (java.util.Properties)46 IOException (java.io.IOException)40 Engine (com.google.refine.browsing.Engine)37 Test (org.testng.annotations.Test)37 ServletException (javax.servlet.ServletException)35 ProjectMetadata (com.google.refine.ProjectMetadata)33 BeforeMethod (org.testng.annotations.BeforeMethod)31 Cell (com.google.refine.model.Cell)29 Row (com.google.refine.model.Row)29 RefineTest (com.google.refine.RefineTest)25 Column (com.google.refine.model.Column)25 BeforeTest (org.testng.annotations.BeforeTest)18 Process (com.google.refine.process.Process)17 AbstractOperation (com.google.refine.model.AbstractOperation)14 StringWriter (java.io.StringWriter)13 RowVisitor (com.google.refine.browsing.RowVisitor)11 ArrayList (java.util.ArrayList)11 File (java.io.File)10 WrappedCell (com.google.refine.expr.WrappedCell)9