Search in sources :

Example 76 with Schema

use of com.google.cloud.datacatalog.v1beta1.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;
}
Also used : Schema(org.molgenis.emx2.Schema) MolgenisWebservice.getSchema(org.molgenis.emx2.web.MolgenisWebservice.getSchema) NotNull(org.jetbrains.annotations.NotNull)

Example 77 with Schema

use of com.google.cloud.datacatalog.v1beta1.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";
    }
}
Also used : Path(java.nio.file.Path) MolgenisWebservice.getSchema(org.molgenis.emx2.web.MolgenisWebservice.getSchema) Schema(org.molgenis.emx2.Schema) OutputStream(java.io.OutputStream)

Example 78 with Schema

use of com.google.cloud.datacatalog.v1beta1.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"));
}
Also used : Schema(org.molgenis.emx2.Schema) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 79 with Schema

use of com.google.cloud.datacatalog.v1beta1.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}}}"));
}
Also used : Schema(org.molgenis.emx2.Schema) PetStoreLoader(org.molgenis.emx2.datamodels.PetStoreLoader) Test(org.junit.Test)

Example 80 with Schema

use of com.google.cloud.datacatalog.v1beta1.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()));
}
Also used : Schema(org.molgenis.emx2.Schema) MolgenisException(org.molgenis.emx2.MolgenisException) MolgenisException(org.molgenis.emx2.MolgenisException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)57 Schema (com.google.pubsub.v1.Schema)38 Schema (org.molgenis.emx2.Schema)38 AbstractMessage (com.google.protobuf.AbstractMessage)16 ByteString (com.google.protobuf.ByteString)16 QName (javax.xml.namespace.QName)16 File (java.io.File)15 IOException (java.io.IOException)15 Schema (org.geosdi.geoplatform.xml.xsd.v2001.Schema)15 SchemaServiceClient (com.google.cloud.pubsub.v1.SchemaServiceClient)14 ProjectName (com.google.pubsub.v1.ProjectName)14 URL (java.net.URL)14 LayerSchemaDTO (org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO)14 StringWriter (java.io.StringWriter)13 Schema (org.oasisopen.odata.csdl.v4.Schema)13 Schema (com.reprezen.kaizen.oasparser.model3.Schema)11 ArrayList (java.util.ArrayList)10 JAXBElement (javax.xml.bind.JAXBElement)10 HashMap (java.util.HashMap)9 List (java.util.List)9