Search in sources :

Example 1 with ProjectMetadata

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

the class GetAllProjectMetadataCommand method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Type", "application/json");
        JSONWriter writer = new JSONWriter(response.getWriter());
        Properties options = new Properties();
        writer.object();
        writer.key("projects");
        writer.object();
        Map<Long, ProjectMetadata> m = ProjectManager.singleton.getAllProjectMetadata();
        for (Entry<Long, ProjectMetadata> e : m.entrySet()) {
            ProjectMetadata pm = e.getValue();
            if (pm != null) {
                writer.key(e.getKey().toString());
                e.getValue().write(writer, options);
            }
        }
        writer.endObject();
        writer.endObject();
    } catch (JSONException e) {
        respondException(response, e);
    }
}
Also used : JSONWriter(org.json.JSONWriter) ProjectMetadata(com.google.refine.ProjectMetadata) JSONException(org.json.JSONException) Properties(java.util.Properties)

Example 2 with ProjectMetadata

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

the class ImportingUtilities method createProjectSynchronously.

private static void createProjectSynchronously(final ImportingJob job, final String format, final JSONObject optionObj, final List<Exception> exceptions, final Format record, final Project project) {
    ProjectMetadata pm = new ProjectMetadata();
    pm.setName(JSONUtilities.getString(optionObj, "projectName", "Untitled"));
    String encoding = JSONUtilities.getString(optionObj, "encoding", "UTF-8");
    if ("".equals(encoding)) {
        // encoding can be present, but empty, which won't trigger JSONUtilities default processing
        encoding = "UTF-8";
    }
    pm.setEncoding(encoding);
    record.parser.parse(project, pm, job, job.getSelectedFileRecords(), format, -1, optionObj, exceptions);
    if (!job.canceled) {
        if (exceptions.size() == 0) {
            // update all internal models, indexes, caches, etc.
            project.update();
            ProjectManager.singleton.registerProject(project, pm);
            job.setProjectID(project.id);
            job.setState("created-project");
        } else {
            job.setError(exceptions);
        }
        job.touch();
        job.updating = false;
    }
}
Also used : ProjectMetadata(com.google.refine.ProjectMetadata)

Example 3 with ProjectMetadata

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

the class FileProjectManager method loadFromFile.

protected boolean loadFromFile(File file) {
    logger.info("Loading workspace: {}", file.getAbsolutePath());
    _projectsMetadata.clear();
    boolean found = false;
    if (file.exists() || file.canRead()) {
        FileReader reader = null;
        try {
            reader = new FileReader(file);
            JSONTokener tokener = new JSONTokener(reader);
            JSONObject obj = (JSONObject) tokener.nextValue();
            JSONArray a = obj.getJSONArray("projectIDs");
            int count = a.length();
            for (int i = 0; i < count; i++) {
                long id = a.getLong(i);
                File projectDir = getProjectDir(id);
                ProjectMetadata metadata = ProjectMetadataUtilities.load(projectDir);
                _projectsMetadata.put(id, metadata);
            }
            if (obj.has("preferences") && !obj.isNull("preferences")) {
                _preferenceStore.load(obj.getJSONObject("preferences"));
            }
            if (obj.has("expressions") && !obj.isNull("expressions")) {
                // backward compatibility
                ((TopList) _preferenceStore.get("scripting.expressions")).load(obj.getJSONArray("expressions"));
            }
            found = true;
        } catch (JSONException e) {
            logger.warn("Error reading file", e);
        } catch (IOException e) {
            logger.warn("Error reading file", e);
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
                logger.warn("Exception closing file", e);
            }
        }
    }
    return found;
}
Also used : JSONTokener(org.json.JSONTokener) TopList(com.google.refine.preference.TopList) JSONObject(org.json.JSONObject) ProjectMetadata(com.google.refine.ProjectMetadata) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File)

Example 4 with ProjectMetadata

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

the class XlsExporterTests method SetUp.

@BeforeMethod
public void SetUp() {
    SUT = new XlsExporter(false);
    stream = new ByteArrayOutputStream();
    ProjectManager.singleton = new ProjectManagerStub();
    projectMetadata = new ProjectMetadata();
    project = new Project();
    projectMetadata.setName(TEST_PROJECT_NAME);
    ProjectManager.singleton.registerProject(project, projectMetadata);
    engine = new Engine(project);
    options = mock(Properties.class);
}
Also used : Project(com.google.refine.model.Project) ProjectManagerStub(com.google.refine.tests.ProjectManagerStub) XlsExporter(com.google.refine.exporters.XlsExporter) ProjectMetadata(com.google.refine.ProjectMetadata) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties) Engine(com.google.refine.browsing.Engine) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with ProjectMetadata

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

the class BooleanTests 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)

Aggregations

ProjectMetadata (com.google.refine.ProjectMetadata)47 Project (com.google.refine.model.Project)33 BeforeMethod (org.testng.annotations.BeforeMethod)20 Properties (java.util.Properties)14 File (java.io.File)12 Engine (com.google.refine.browsing.Engine)10 IOException (java.io.IOException)9 ServletException (javax.servlet.ServletException)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 Test (org.testng.annotations.Test)6 ProjectManagerStub (com.google.refine.ProjectManagerStub)5 StringWriter (java.io.StringWriter)5 JSONObject (org.json.JSONObject)5 ImportingJob (com.google.refine.importing.ImportingJob)4 Column (com.google.refine.model.Column)4 ProjectManagerStub (com.google.refine.tests.ProjectManagerStub)4 SeparatorBasedImporter (com.google.refine.importers.SeparatorBasedImporter)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 BeforeTest (org.testng.annotations.BeforeTest)3 ProjectManager (com.google.refine.ProjectManager)2