Search in sources :

Example 16 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project molgenis-emx2 by molgenis.

the class ExcelApi method getExcelTable.

static String getExcelTable(Request request, Response response) throws IOException {
    Table table = getTable(request);
    if (table == null)
        throw new MolgenisException("Table " + request.params(TABLE) + " unknown");
    Path tempDir = Files.createTempDirectory(MolgenisWebservice.TEMPFILES_DELETE_ON_EXIT);
    tempDir.toFile().deleteOnExit();
    try (OutputStream outputStream = response.raw().getOutputStream()) {
        Path excelFile = tempDir.resolve("download.xlsx");
        MolgenisIO.toExcelFile(excelFile, table);
        response.type("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.header("Content-Disposition", "attachment; filename=" + table.getSchema().getMetadata().getName() + "_" + table.getName() + System.currentTimeMillis() + ".xlsx");
        outputStream.write(Files.readAllBytes(excelFile));
        return "Export success";
    }
}
Also used : Path(java.nio.file.Path) MolgenisWebservice.getTable(org.molgenis.emx2.web.MolgenisWebservice.getTable) Table(org.molgenis.emx2.Table) OutputStream(java.io.OutputStream) MolgenisException(org.molgenis.emx2.MolgenisException)

Example 17 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project molgenis-emx2 by molgenis.

the class LinkedDataFragmentsApi method ttlTable.

private static String ttlTable(Request request, Response response) {
    Table table = getTable(request);
    StringWriter sw = new StringWriter();
    LinkedDataService.getTtlForTable(table, new PrintWriter(sw));
    return sw.getBuffer().toString();
}
Also used : MolgenisWebservice.getTable(org.molgenis.emx2.web.MolgenisWebservice.getTable) Table(org.molgenis.emx2.Table) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 18 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project molgenis-emx2 by molgenis.

the class CatalogueSiteMapTest method buildSiteMap.

@Test
public void buildSiteMap() {
    Schema schema = mock(Schema.class);
    Table table = mock(Table.class);
    Query query = mock(Query.class);
    List<Row> row = Collections.singletonList(new Row("pid", "my-cohort-pid"));
    when(schema.getTable("Cohorts")).thenReturn(table);
    when(table.select(any())).thenReturn(query);
    when(query.retrieveRows()).thenReturn(row);
    CatalogueSiteMap catalogueSiteMap = new CatalogueSiteMap(schema, "https://my/base/url");
    String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" >\n" + "  <url>\n" + "    <loc>https://my/base/url/ssr-catalogue/Cohorts/my-cohort-pid</loc>\n" + "  </url>\n" + "</urlset>";
    assertEquals(expected, catalogueSiteMap.buildSiteMap());
}
Also used : Table(org.molgenis.emx2.Table) Query(org.molgenis.emx2.Query) Schema(org.molgenis.emx2.Schema) Row(org.molgenis.emx2.Row) Test(org.junit.Test)

Example 19 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project molgenis-emx2 by molgenis.

the class Benchmark method testCopyInAndOut.

public void testCopyInAndOut() {
    Database database = TestDatabaseFactory.getTestDatabase();
    Schema schema = database.dropCreateSchema(Benchmark.class.getSimpleName());
    int aSize = 50;
    int bSize = 100000;
    Table a = schema.create(table("TableA").add(column("ID").setPkey()));
    List<String> values = new ArrayList<>();
    Table b = schema.create(table("TableB").add(column("ID").setPkey()).add(column("ref").setType(REF_ARRAY).setRefTable("TableA")));
    // Table c =
    // schema.create(
    // table("TableC")
    // .add(column("ID").setPkey())
    // .add(column("ref").setType(MREF).setRefTable("TableA")));
    StopWatch.start("benchmark started");
    List<Row> aRows = new ArrayList<>();
    for (int i = 0; i < aSize; i++) {
        aRows.add(new Row().set("ID", "row" + i));
        values.add("row" + i);
    }
    StopWatch.start("benchmark1");
    a.insert(aRows);
    StopWatch.print("inserted primary", aSize);
    aRows.clear();
    List<Row> bRows = new ArrayList<>();
    for (int i = 0; i < bSize; i++) {
        bRows.add(new Row().set("ID", "row" + i).set("ref", values));
    }
    StopWatch.start("benchmark2 started");
    b.insert(bRows);
    StopWatch.print("inserted ref_array", bSize);
    bRows.clear();
// List<Row> cRows = new ArrayList<>();
// for (int i = 0; i < bSize; i++) {
// cRows.add(new Row().set("ID", "row" + i).set("ref", values));
// }
// StopWatch.start("benchmark3 started");
// c.insert(cRows);
// StopWatch.print("inserted mref", bSize);
// cRows.clear();
// StopWatch.print("inserted mref", bSize);
// ref_array
}
Also used : Table(org.molgenis.emx2.Table) Schema(org.molgenis.emx2.Schema) Database(org.molgenis.emx2.Database) ArrayList(java.util.ArrayList) Row(org.molgenis.emx2.Row)

Example 20 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project molgenis-emx2 by molgenis.

the class TestCompositeForeignKeys method testCompositeRef.

@Test
public void testCompositeRef() {
    Schema schema = database.dropCreateSchema(TestCompositeForeignKeys.class.getSimpleName() + "Ref");
    schema.create(table("Person", column("firstName").setPkey(), column("lastName").setPkey(), column("uncle", REF).setRefTable("Person")));
    Table p = schema.getTable("Person");
    p.insert(new Row().setString("firstName", "Donald").setString("lastName", "Duck"));
    try {
        p.insert(new Row().setString("firstName", "Kwik").setString("lastName", "Duck").setString("uncle.firstName", "Donald").setString("uncle.lastName", "MISSING"));
        fail("should have failed on missing foreign key");
    } catch (Exception e) {
        System.out.println("errored correctly: " + e);
    }
    p.insert(new Row().setString("firstName", "Kwik").setString("lastName", "Duck").setString("uncle.firstName", "Donald").setString("uncle.lastName", "Duck"));
    p.insert(new Row().setString("firstName", "Kwek").setString("lastName", "Duck").setString("uncle.firstName", "Donald").setString("uncle.lastName", "Duck"));
    p.insert(new Row().setString("firstName", "Kwak").setString("lastName", "Duck").setString("uncle.firstName", "Donald").setString("uncle.lastName", "Duck"));
    try {
        p.delete(new Row().setString("firstName", "Donald").setString("lastName", "Duck"));
        fail("should have failed on foreign key (Donald is used in foreign key)");
    } catch (Exception e) {
        System.out.println("errored correctly: " + e);
    }
    schema.create(table("Student").setInherit("Person"));
    Table s = schema.getTable("Student");
    s.insert(new Row().setString("firstName", "Mickey").setString("lastName", "Mouse").setString("uncle.firstName", "Kwik").setString("uncle.lastName", "Duck"));
    String result = schema.query("Student", s("firstName"), s("lastName"), s("uncle", s("firstName"), s("lastName")), s("uncle", s("firstName"), s("lastName"))).retrieveJSON();
    System.out.println(result);
    result = schema.query("Student").select(s("firstName"), s("lastName")).where(or(and(f("firstName", EQUALS, "Donald"), f("lastName", EQUALS, "Duck")), and(f("firstName", EQUALS, "Mickey"), f("lastName", EQUALS, "Mouse")))).retrieveJSON();
    System.out.println(result);
    assertTrue(result.contains("Mouse"));
    assertFalse(result.contains("Duck"));
    result = schema.query("Person").select(s("firstName"), s("lastName")).where(or(and(f("firstName", EQUALS, "Donald"), f("lastName", EQUALS, "Duck")), and(f("firstName", EQUALS, "Mickey"), f("lastName", EQUALS, "Mouse")))).retrieveJSON();
    System.out.println(result);
    assertTrue(result.contains("Mouse"));
    assertTrue(result.contains("Duck"));
    // composite key filter
    result = schema.query("Person").select(s("firstName"), s("lastName")).where(f("uncle", or(and(f("firstName", EQUALS, "Donald"), f("lastName", EQUALS, "Duck")), and(f("firstName", EQUALS, "Mickey"), f("lastName", EQUALS, "Mouse"))))).retrieveJSON();
    System.out.println(result);
    assertTrue(result.contains("Kwik"));
    assertFalse(result.contains("Mouse"));
    // refback
    schema.getTable("Person").getMetadata().add(column("nephew").setType(REFBACK).setRefTable("Person").setRefBack("uncle"));
    s.insert(new Row().setString("firstName", "Katrien").setString("lastName", "Duck").setString("nephew.firstName", "Kwik").setString("nephew.lastName", // I know, not true
    "Duck"));
    assertTrue(List.of(s.query().select(s("firstName"), s("lastName"), s("nephew", s("firstName"), s("lastName")), s("uncle", s("firstName"), s("lastName"))).where(f("firstName", EQUALS, "Katrien")).retrieveRows().get(0).getStringArray("nephew-firstName")).contains("Kwik"));
    assertTrue(List.of(p.query().select(s("firstName"), s("lastName"), s("nephew", s("firstName"), s("lastName")), s("uncle", s("firstName"), s("lastName"))).where(f("firstName", EQUALS, "Kwik")).retrieveRows().get(0).getStringArray("uncle-firstName")).contains("Katrien"));
    // test order by for refback
    p.query().select(s("firstName"), s("lastName"), s("nephew", s("firstName"), s("lastName")), s("uncle", s("firstName"), s("lastName"))).orderBy("nephew").retrieveJSON();
}
Also used : Table(org.molgenis.emx2.Table) Schema(org.molgenis.emx2.Schema) Row(org.molgenis.emx2.Row) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)40 Table (com.google.privacy.dlp.v2.Table)23 Table (org.molgenis.emx2.Table)23 Table (com.google.bigtable.admin.v2.Table)21 ByteString (com.google.protobuf.ByteString)18 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)17 ArrayList (java.util.ArrayList)14 AbstractMessage (com.google.protobuf.AbstractMessage)13 HashMap (java.util.HashMap)13 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)11 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)10 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)10 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint)10 Row (org.molgenis.emx2.Row)10 IOException (java.io.IOException)9 List (java.util.List)9 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum)7 DlpServiceClient (com.google.cloud.dlp.v2.DlpServiceClient)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table)6