use of com.google.pubsub.v1.Schema in project molgenis-emx2 by molgenis.
the class BootstrapThemeService method getParams.
@NotNull
private static Map<String, String> getParams(Request request) {
Schema schema = getSchema(request);
Map<String, String> params = new LinkedHashMap<>();
if (schema != null) {
String cssUrl = schema.getMetadata().getSetting("cssURL");
if (cssUrl != null) {
params.putAll(splitQuery(cssUrl.split("\\?")[1]));
}
}
return params;
}
use of com.google.pubsub.v1.Schema in project molgenis-emx2 by molgenis.
the class ExcelApi method getExcel.
static String getExcel(Request request, Response response) throws IOException {
Schema schema = getSchema(request);
Path tempDir = Files.createTempDirectory(MolgenisWebservice.TEMPFILES_DELETE_ON_EXIT);
tempDir.toFile().deleteOnExit();
try (OutputStream outputStream = response.raw().getOutputStream()) {
Path excelFile = tempDir.resolve("download.xlsx");
if (request.queryParams("emx1") != null) {
MolgenisIO.toEmx1ExcelFile(excelFile, schema);
} else {
MolgenisIO.toExcelFile(excelFile, schema);
}
response.type("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.header("Content-Disposition", "attachment; filename=" + schema.getMetadata().getName() + System.currentTimeMillis() + ".xlsx");
outputStream.write(Files.readAllBytes(excelFile));
return "Export success";
}
}
use of com.google.pubsub.v1.Schema in project molgenis-emx2 by molgenis.
the class TestQueryJsonGraph method testGroupBy.
// todo @Test
// we want to refactor this
public void testGroupBy() throws JsonProcessingException {
Schema schema = db.dropCreateSchema(TestQueryJsonGraph.class.getSimpleName() + "_testGroupBy");
schema.create(table("Test", column("id").setPkey(), column("tag"), column("tag_array").setType(STRING_ARRAY), column("tag_array2").setType(STRING_ARRAY)));
schema.getTable("Test").insert(row("id", 1, "tag", "blue", "tag_array", new String[] { "blue", "green" }, "tag_array2", new String[] { "yellow", "red" }), row("id", 2, "tag", "blue", "tag_array", new String[] { "green", "blue" }, "tag_array2", new String[] { "yellow", "red" }), row("id", 3, "tag", "green", "tag_array", new String[] { "blue" }, "tag_array2", new String[] { "yellow", "red" }));
ObjectMapper mapper = new ObjectMapper();
Map<String, Map<String, List<Map<String, Object>>>> result = mapper.readValue(schema.agg("Test").select(s("groupBy", s("count"), s("tag"))).retrieveJSON(), Map.class);
assertEquals(2, result.get("Test_agg").get("groupBy").get(1).get("count"));
result = mapper.readValue(schema.agg("Test").select(s("groupBy", s("count"), s("tag_array"))).retrieveJSON(), Map.class);
assertEquals(2, result.get("Test_agg").get("groupBy").get(0).get("count"));
result = mapper.readValue(schema.agg("Test").select(s("groupBy", s("count"), s("tag_array"), s("tag_array2"))).retrieveJSON(), Map.class);
assertEquals(3, result.get("Test_agg").get("groupBy").get(0).get("count"));
}
use of com.google.pubsub.v1.Schema in project molgenis-emx2 by molgenis.
the class TestQueryJsonGraph method testAgg.
@Test
public void testAgg() {
Schema schema = db.dropCreateSchema(TestQueryJsonGraph.class.getSimpleName() + "_testAgg");
new PetStoreLoader().load(schema, true);
String json = schema.query("Order_agg", s("max", s("quantity"))).retrieveJSON();
assertTrue(json.contains("{\"Order_agg\": {\"max\": {\"quantity\": 7}}}"));
}
use of com.google.pubsub.v1.Schema in project molgenis-emx2 by molgenis.
the class TestSchemaCreateDestroy method schemaCrudTest.
@Test
public void schemaCrudTest() {
try {
db.dropCreateSchema("");
fail("Schema createTableIfNotExists should fail on empty name");
} catch (MolgenisException e) {
System.out.println("Error correctly:\n" + e);
}
Schema schema = db.dropCreateSchema(getClass().getSimpleName());
try {
db.createSchema(getClass().getSimpleName());
fail("Schema createTableIfNotExists should fail on duplicated name");
} catch (MolgenisException e) {
System.out.println("Error correctly:\n" + e);
}
schema.create(table("test"));
try {
schema.dropTable("test2");
fail("Drop schema should fail for unknown table");
} catch (Exception e) {
System.out.println("Error correctly:\n" + e);
}
schema.dropTable("test");
assertNull(schema.getTable("test"));
try {
db.dropSchema(getClass().getSimpleName() + "fake");
fail("Drop schema should fail for unknown schema");
} catch (Exception e) {
System.out.println("Error correctly:\n" + e);
}
db.dropSchema(getClass().getSimpleName());
assertNull(db.getSchema(getClass().getSimpleName()));
}
Aggregations