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);
}
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();
}
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);
}
}
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();
}
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");
}
Aggregations