Search in sources :

Example 36 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 ObjectNode optionObj, final List<Exception> exceptions, final Format record, final Project project) {
    ProjectMetadata pm = createProjectMetadata(optionObj);
    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 37 with ProjectMetadata

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

the class ProjectMetadataUtilities method load.

public static ProjectMetadata load(File projectDir) {
    ProjectMetadata pm = null;
    pm = loadMetaDataIfExist(projectDir, ProjectMetadata.DEFAULT_FILE_NAME);
    if (pm == null) {
        pm = loadMetaDataIfExist(projectDir, ProjectMetadata.TEMP_FILE_NAME);
    }
    if (pm == null) {
        pm = loadMetaDataIfExist(projectDir, ProjectMetadata.OLD_FILE_NAME);
    }
    return pm;
}
Also used : ProjectMetadata(com.google.refine.ProjectMetadata)

Example 38 with ProjectMetadata

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

the class HistoryProcessTests method setUp.

@BeforeMethod
public void setUp() {
    project = new Project();
    projectMetadata = mock(ProjectMetadata.class);
    ProjectManager.singleton.registerProject(project, projectMetadata);
    AbstractOperation op = mock(AbstractOperation.class);
    Change ch = mock(Change.class);
    HistoryEntry entry = new HistoryEntry(1234L, project, "first operation", op, ch);
    project.history.addEntry(entry);
    entry = new HistoryEntry(5678L, project, "second operation", op, ch);
    project.history.addEntry(entry);
}
Also used : Project(com.google.refine.model.Project) AbstractOperation(com.google.refine.model.AbstractOperation) ProjectMetadata(com.google.refine.ProjectMetadata) HistoryEntry(com.google.refine.history.HistoryEntry) Change(com.google.refine.history.Change) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 39 with ProjectMetadata

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

the class ImportProjectCommand method doPost.

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (!hasValidCSRFTokenAsGET(request)) {
        respondCSRFError(response);
        return;
    }
    ProjectManager.singleton.setBusy(true);
    try {
        Properties options = ParsingUtilities.parseUrlParameters(request);
        long projectID = Project.generateID();
        logger.info("Importing existing project using new ID {}", projectID);
        internalImport(request, options, projectID);
        ProjectManager.singleton.loadProjectMetadata(projectID);
        ProjectMetadata pm = ProjectManager.singleton.getProjectMetadata(projectID);
        if (pm != null) {
            if (options.containsKey("project-name")) {
                String projectName = options.getProperty("project-name");
                if (projectName != null && projectName.length() > 0) {
                    pm.setName(projectName);
                }
            }
            redirect(response, "/project?project=" + projectID);
        } else {
            respondWithErrorPage(request, response, "Failed to import project. Reason unknown.", null);
        }
    } catch (Exception e) {
        respondWithErrorPage(request, response, "Failed to import project", e);
    } finally {
        ProjectManager.singleton.setBusy(false);
    }
}
Also used : ProjectMetadata(com.google.refine.ProjectMetadata) Properties(java.util.Properties) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 40 with ProjectMetadata

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

the class RenameProjectCommand method doPost.

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (!hasValidCSRFToken(request)) {
        respondCSRFError(response);
        return;
    }
    try {
        String name = request.getParameter("name");
        ProjectMetadata pm = getProjectMetadata(request);
        pm.setName(name);
        respond(response, "{ \"code\" : \"ok\" }");
    } catch (Exception e) {
        respondException(response, e);
    }
}
Also used : ProjectMetadata(com.google.refine.ProjectMetadata) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

ProjectMetadata (com.google.refine.ProjectMetadata)48 Project (com.google.refine.model.Project)34 BeforeMethod (org.testng.annotations.BeforeMethod)21 Properties (java.util.Properties)15 File (java.io.File)12 Engine (com.google.refine.browsing.Engine)11 IOException (java.io.IOException)9 ServletException (javax.servlet.ServletException)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 ProjectManagerStub (com.google.refine.ProjectManagerStub)6 Test (org.testng.annotations.Test)6 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 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 SeparatorBasedImporter (com.google.refine.importers.SeparatorBasedImporter)3 BeforeTest (org.testng.annotations.BeforeTest)3 ProjectManager (com.google.refine.ProjectManager)2