Search in sources :

Example 81 with Project

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

the class MassChangeTests method SetUp.

@BeforeMethod
public void SetUp() throws IOException, ModelException {
    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);
}
Also used : Project(com.google.refine.model.Project) ProjectMetadata(com.google.refine.ProjectMetadata) File(java.io.File) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 82 with Project

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

the class XmlImportUtilitiesTests method SetUp.

@BeforeMethod
public void SetUp() {
    SUT = new XmlImportUtilitiesStub();
    project = new Project();
    columnGroup = new ImportColumnGroup();
    record = new ImportRecord();
}
Also used : Project(com.google.refine.model.Project) ImportColumnGroup(com.google.refine.importers.tree.ImportColumnGroup) ImportRecord(com.google.refine.importers.tree.ImportRecord) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 83 with Project

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

the class UploadCommand method doPost.

// TODO: We need a way to provide progress to the user during long uploads
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (!hasValidCSRFToken(request)) {
        respondCSRFError(response);
        return;
    }
    String token = TokenCookie.getToken(request);
    if (token == null) {
        HttpUtilities.respond(response, "error", "Not authorized");
        return;
    }
    ProjectManager.singleton.setBusy(true);
    try {
        Project project = getProject(request);
        Engine engine = getEngine(request, project);
        Properties params = ExportRowsCommand.getRequestParameters(request);
        String name = params.getProperty("name");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Type", "application/json");
        Writer w = response.getWriter();
        JsonGenerator writer = ParsingUtilities.mapper.getFactory().createGenerator(w);
        try {
            writer.writeStartObject();
            List<Exception> exceptions = new LinkedList<Exception>();
            String url = upload(project, engine, params, token, name, exceptions);
            // The URL can be non-null even if it doesn't fail
            if (url != null && exceptions.size() == 0) {
                writer.writeStringField("status", "ok");
                writer.writeStringField("url", url);
            } else if (exceptions.size() == 0) {
                writer.writeStringField("status", "error");
                writer.writeStringField("message", "No such format");
            } else {
                for (Exception e : exceptions) {
                    logger.warn(e.getLocalizedMessage(), e);
                }
                writer.writeStringField("status", "error");
                writer.writeStringField("message", exceptions.get(0).getLocalizedMessage());
            }
        } catch (Exception e) {
            e.printStackTrace();
            writer.writeStringField("status", "error");
            writer.writeStringField("message", e.getMessage());
        } finally {
            writer.writeEndObject();
            writer.flush();
            writer.close();
            w.flush();
            w.close();
        }
    } catch (Exception e) {
        throw new ServletException(e);
    } finally {
        ProjectManager.singleton.setBusy(false);
    }
}
Also used : ServletException(javax.servlet.ServletException) Project(com.google.refine.model.Project) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Properties(java.util.Properties) Engine(com.google.refine.browsing.Engine) Writer(java.io.Writer) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) LinkedList(java.util.LinkedList)

Example 84 with Project

use of com.google.refine.model.Project 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 85 with Project

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

the class JythonEvaluableTest method unwrapPyObjectTest.

// Reproduces the situation when result is a PyObject
// Version with a test case which only calls the existing evaluate method
@Test
public void unwrapPyObjectTest() {
    Properties props = new Properties();
    Project project = new Project();
    Row row = new Row(2);
    row.setCell(0, new Cell("one", null));
    row.setCell(0, new Cell("1", null));
    props.put("columnName", "number");
    props.put("true", "true");
    props.put("false", "false");
    props.put("rowIndex", "0");
    props.put("value", 1);
    props.put("project", project);
    props.put("call", "number");
    props.put("PI", "3.141592654");
    props.put("cells", new CellTuple(project, row));
    String funcExpression = "class Foo(object):\n" + "    bar = 1\n" + "\n" + "return Foo()";
    JythonEvaluable eval1 = new JythonEvaluable(funcExpression);
    PyObject po = (PyObject) eval1.evaluate(props);
    Assert.assertEquals(po.__getattr__("bar").toString(), "1");
}
Also used : Project(com.google.refine.model.Project) CellTuple(com.google.refine.expr.CellTuple) Row(com.google.refine.model.Row) Properties(java.util.Properties) Cell(com.google.refine.model.Cell) Test(org.testng.annotations.Test)

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