Search in sources :

Example 16 with ProjectMetadata

use of com.google.refine.ProjectMetadata in project OpenRefine by OpenRefine.

the class FileProjectManager method saveToFile.

protected boolean saveToFile(File file) throws IOException, JSONException {
    FileWriter writer = new FileWriter(file);
    boolean saveWasNeeded = false;
    try {
        JSONWriter jsonWriter = new JSONWriter(writer);
        jsonWriter.object();
        jsonWriter.key("projectIDs");
        jsonWriter.array();
        for (Long id : _projectsMetadata.keySet()) {
            ProjectMetadata metadata = _projectsMetadata.get(id);
            if (metadata != null) {
                jsonWriter.value(id);
                if (metadata.isDirty()) {
                    ProjectMetadataUtilities.save(metadata, getProjectDir(id));
                    saveWasNeeded = true;
                }
            }
        }
        jsonWriter.endArray();
        writer.write('\n');
        jsonWriter.key("preferences");
        saveWasNeeded |= _preferenceStore.isDirty();
        _preferenceStore.write(jsonWriter, new Properties());
        jsonWriter.endObject();
    } finally {
        writer.close();
    }
    return saveWasNeeded;
}
Also used : JSONWriter(org.json.JSONWriter) ProjectMetadata(com.google.refine.ProjectMetadata) FileWriter(java.io.FileWriter) Properties(java.util.Properties)

Example 17 with ProjectMetadata

use of com.google.refine.ProjectMetadata 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 18 with ProjectMetadata

use of com.google.refine.ProjectMetadata 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)

Example 19 with ProjectMetadata

use of com.google.refine.ProjectMetadata in project OpenRefine by OpenRefine.

the class FunctionTests method SetUp.

@BeforeMethod
public void SetUp() throws IOException, ModelException {
    bindings = new Properties();
    File dir = TestUtils.createTempDirectory("openrefine-test-workspace-dir");
    FileProjectManager.initialize(dir);
    project = new Project();
    ProjectMetadata pm = new ProjectMetadata();
    pm.setName("TNG Test Project");
    ProjectManager.singleton.registerProject(project, pm);
    int index = project.columnModel.allocateNewCellIndex();
    Column column = new Column(index, "Column A");
    project.columnModel.addColumn(index, column, true);
    options = mock(Properties.class);
    bindings.put("project", project);
    // Five rows of a's and five of 1s
    for (int i = 0; i < 10; i++) {
        Row row = new Row(1);
        row.setCell(0, new Cell(i < 5 ? "a" : new Integer(1), null));
        project.rows.add(row);
    }
}
Also used : Project(com.google.refine.model.Project) Column(com.google.refine.model.Column) ProjectMetadata(com.google.refine.ProjectMetadata) Row(com.google.refine.model.Row) Properties(java.util.Properties) File(java.io.File) Cell(com.google.refine.model.Cell) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 20 with ProjectMetadata

use of com.google.refine.ProjectMetadata in project OpenRefine by OpenRefine.

the class ImporterTest method setUp.

public void setUp() {
    //FIXME - should we try and use mock(Project.class); - seems unnecessary complexity
    servlet = new RefineServletStub();
    ImportingManager.initialize(servlet);
    project = new Project();
    metadata = new ProjectMetadata();
    job = ImportingManager.createJob();
    options = Mockito.mock(JSONObject.class);
}
Also used : Project(com.google.refine.model.Project) RefineServletStub(com.google.refine.tests.RefineServletStub) JSONObject(org.json.JSONObject) ProjectMetadata(com.google.refine.ProjectMetadata)

Aggregations

ProjectMetadata (com.google.refine.ProjectMetadata)22 Project (com.google.refine.model.Project)16 Properties (java.util.Properties)10 BeforeMethod (org.testng.annotations.BeforeMethod)9 File (java.io.File)7 JSONObject (org.json.JSONObject)6 Engine (com.google.refine.browsing.Engine)5 Column (com.google.refine.model.Column)4 ProjectManagerStub (com.google.refine.tests.ProjectManagerStub)4 IOException (java.io.IOException)4 ServletException (javax.servlet.ServletException)3 JSONException (org.json.JSONException)3 Cell (com.google.refine.model.Cell)2 Row (com.google.refine.model.Row)2 RefineServletStub (com.google.refine.tests.RefineServletStub)2 StringWriter (java.io.StringWriter)2 JSONWriter (org.json.JSONWriter)2 BeforeTest (org.testng.annotations.BeforeTest)2 Test (org.testng.annotations.Test)2 AuthenticationException (com.google.gdata.util.AuthenticationException)1