Search in sources :

Example 26 with ProjectMetadata

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

the class HtmlExporterTests method SetUp.

@BeforeMethod
public void SetUp() {
    SUT = new HtmlTableExporter();
    writer = new StringWriter();
    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.ProjectManagerStub) StringWriter(java.io.StringWriter) ProjectMetadata(com.google.refine.ProjectMetadata) Properties(java.util.Properties) Engine(com.google.refine.browsing.Engine) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 27 with ProjectMetadata

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

the class XlsxExporterTests method SetUp.

@BeforeMethod
public void SetUp() {
    SUT = new XlsExporter(true);
    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.ProjectManagerStub) 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 28 with ProjectMetadata

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

the class WikidataRefineTest method createCSVProject.

protected Project createCSVProject(String projectName, String input) {
    Project project = new Project();
    ProjectMetadata metadata = new ProjectMetadata();
    metadata.setName(projectName);
    ObjectNode options = mock(ObjectNode.class);
    RefineTest.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;
}
Also used : Project(com.google.refine.model.Project) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProjectMetadata(com.google.refine.ProjectMetadata) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) ImportingJob(com.google.refine.importing.ImportingJob) SeparatorBasedImporter(com.google.refine.importers.SeparatorBasedImporter)

Example 29 with ProjectMetadata

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

the class DatabaseImportControllerTest method setUp.

@BeforeMethod
public void setUp() throws IOException {
    MockitoAnnotations.initMocks(this);
    File dir = DBExtensionTestUtils.createTempDirectory("OR_DBExtension_Test_WorkspaceDir");
    FileProjectManager.initialize(dir);
    servlet = new RefineDbServletStub();
    ImportingManager.initialize(servlet);
    project = new Project();
    metadata = new ProjectMetadata();
    job = ImportingManager.createJob();
    metadata.setName("Database Import Test Project");
    ProjectManager.singleton.registerProject(project, metadata);
    SUT = new DatabaseImportController();
}
Also used : Project(com.google.refine.model.Project) ProjectMetadata(com.google.refine.ProjectMetadata) RefineDbServletStub(com.google.refine.extension.database.stub.RefineDbServletStub) File(java.io.File) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 30 with ProjectMetadata

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

the class DatabaseImportController method doCreateProject.

/**
 * doCreateProject
 * @param request
 * @param response
 * @param parameters
 */
private void doCreateProject(HttpServletRequest request, HttpServletResponse response, Properties parameters) throws ServletException, IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("DatabaseImportController::doCreateProject:::{}", parameters.getProperty("jobID"));
    }
    long jobID = Long.parseLong(parameters.getProperty("jobID"));
    final ImportingJob job = ImportingManager.getJob(jobID);
    if (job == null) {
        HttpUtilities.respond(response, "error", "No such import job");
        return;
    }
    final DatabaseQueryInfo databaseQueryInfo = getQueryInfo(request);
    if (databaseQueryInfo == null) {
        HttpUtilities.respond(response, "error", "Invalid or missing Query Info");
    }
    job.updating = true;
    try {
        final ObjectNode optionObj = ParsingUtilities.evaluateJsonStringToObjectNode(request.getParameter("options"));
        final List<Exception> exceptions = new LinkedList<Exception>();
        job.setState("creating-project");
        final Project project = new Project();
        new Thread() {

            @Override
            public void run() {
                ProjectMetadata pm = new ProjectMetadata();
                pm.setName(JSONUtilities.getString(optionObj, "projectName", "Untitled"));
                pm.setEncoding(JSONUtilities.getString(optionObj, "encoding", "UTF-8"));
                try {
                    parseCreate(databaseQueryInfo, project, pm, job, -1, optionObj, exceptions);
                } catch (DatabaseServiceException e) {
                    logger.error("DatabaseImportController::doCreateProject:::run{}", e);
                // throw new RuntimeException("DatabaseServiceException::", e);
                }
                if (!job.canceled) {
                    if (exceptions.size() > 0) {
                        job.setError(exceptions);
                    } else {
                        // update all internal models, indexes, caches, etc.
                        project.update();
                        ProjectManager.singleton.registerProject(project, pm);
                        job.setState("created-project");
                        job.setProjectID(project.id);
                    // logger.info("DatabaseImportController::doCreateProject:::run::projectID :{}", project.id);
                    }
                    job.touch();
                    job.updating = false;
                }
            }
        }.start();
        HttpUtilities.respond(response, "ok", "done");
    } catch (IOException e) {
        throw new ServletException(e);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) ServletException(javax.servlet.ServletException) Project(com.google.refine.model.Project) ProjectMetadata(com.google.refine.ProjectMetadata) ImportingJob(com.google.refine.importing.ImportingJob) DatabaseQueryInfo(com.google.refine.extension.database.model.DatabaseQueryInfo)

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