Search in sources :

Example 81 with Schema

use of com.reprezen.kaizen.oasparser.model3.Schema in project molgenis-emx2 by molgenis.

the class TestGraphQLCompositeKeys method setup.

// need ref
// need mref
// need ref_array
@BeforeClass
public static void setup() {
    database = TestDatabaseFactory.getTestDatabase();
    Schema schema = database.dropCreateSchema(schemaName);
    grapql = new GraphqlApiFactory().createGraphqlForSchema(schema);
}
Also used : Schema(org.molgenis.emx2.Schema) BeforeClass(org.junit.BeforeClass)

Example 82 with Schema

use of com.reprezen.kaizen.oasparser.model3.Schema in project molgenis-emx2 by molgenis.

the class TestGraphqlAdminFields method testUsers.

@Test
public void testUsers() {
    // put in transaction so user count is not affected by other operations
    database.tx(tdb -> {
        tdb.becomeAdmin();
        Schema schema = tdb.dropCreateSchema(schemaName);
        grapql = new GraphqlApiFactory().createGraphqlForSchema(schema);
        try {
            JsonNode result = execute("{_admin{users{username} userCount}}");
            TestCase.assertTrue(result.at("/_admin/userCount").intValue() > 0);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        // test that only admin can do this
        tdb.setActiveUser(ANONYMOUS);
        grapql = new GraphqlApiFactory().createGraphqlForSchema(schema);
        try {
            TestCase.assertEquals(null, execute("{_admin{userCount}}").textValue());
        } catch (Exception e) {
            TestCase.assertTrue(e.getMessage().contains("FieldUndefined"));
        }
        tdb.becomeAdmin();
    });
}
Also used : Schema(org.molgenis.emx2.Schema) JsonNode(com.fasterxml.jackson.databind.JsonNode) MolgenisException(org.molgenis.emx2.MolgenisException) IOException(java.io.IOException) Test(org.junit.Test)

Example 83 with Schema

use of com.reprezen.kaizen.oasparser.model3.Schema in project molgenis-emx2 by molgenis.

the class TestAddColumnUpdateSearchTrigger method setUp.

@BeforeClass
public static void setUp() {
    db = TestDatabaseFactory.getTestDatabase();
    Schema schema = db.dropCreateSchema(TestAddColumnUpdateSearchTrigger.class.getSimpleName());
    table = schema.create(table("TestAddColUpdateSearchTrigger").add(column("col1").setPkey()).add(column("col2").setType(STRING)));
    table.insert(new Row().setString("col1", "key1").setString("col2", "aaa"));
}
Also used : Schema(org.molgenis.emx2.Schema) Row(org.molgenis.emx2.Row) BeforeClass(org.junit.BeforeClass)

Example 84 with Schema

use of com.reprezen.kaizen.oasparser.model3.Schema in project molgenis-emx2 by molgenis.

the class TestCompositeForeignKeys method testCompositeRefArray.

@Test
public void testCompositeRefArray() {
    Schema schema = database.dropCreateSchema(TestCompositeForeignKeys.class.getSimpleName() + "RefArray");
    schema.create(table("Person", column("firstName").setPkey(), column("lastName").setPkey(), column("cousins", REF_ARRAY).setRefTable("Person")));
    Table p = schema.getTable("Person");
    p.insert(new Row().setString("firstName", "Kwik").setString("lastName", "Duck"));
    p.insert(new Row().setString("firstName", "Donald").setString("lastName", "Duck").setString("cousins.firstName", "Kwik").setString("cousins.lastName", "Duck"));
    try {
        p.delete(new Row().setString("firstName", "Kwik").setString("lastName", "Duck"));
        fail("should have failed on foreign key error");
    } 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("cousins.firstName", "Kwik").setString("cousins.lastName", "Duck"));
    String result = schema.query("Student").select(s("firstName"), s("lastName"), s("cousins", s("firstName"), s("lastName"))).retrieveJSON();
    System.out.println(result);
    // refback
    schema.getTable("Person").getMetadata().add(column("uncles").setType(REFBACK).setRefTable("Person").setRefBack("cousins"));
    s.insert(new Row().setString("firstName", // doesn't exist
    "Kwok").setString("lastName", "Duck").setString("uncles.firstName", "Donald").setString("uncles.lastName", "Duck"));
    assertTrue(List.of(s.query().select(s("firstName"), s("lastName"), s("uncles", s("firstName"), s("lastName")), s("cousins", s("firstName"), s("lastName"))).where(f("firstName", EQUALS, "Kwok")).retrieveRows().get(0).getStringArray("uncles-firstName")).contains("Donald"));
    assertTrue(List.of(p.query().select(s("firstName"), s("lastName"), s("cousins", s("firstName"), s("lastName")), s("uncles", s("firstName"), s("lastName"))).where(f("firstName", EQUALS, "Donald")).retrieveRows().get(// 
    1).getStringArray(// TODO should be array?
    "cousins-firstName")).contains("Kwok"));
    // check we can sort on ref_array
    p.query().select(s("firstName"), s("lastName"), s("cousins", s("firstName"), s("lastName")), s("uncles", s("firstName"), s("lastName"))).orderBy("cousins").retrieveJSON();
    // check we can sort on refback to a ref_array
    p.query().select(s("firstName"), s("lastName"), s("cousins", s("firstName"), s("lastName")), s("uncles", s("firstName"), s("lastName"))).orderBy("uncles").retrieveJSON();
}
Also used : Table(org.molgenis.emx2.Table) Schema(org.molgenis.emx2.Schema) Row(org.molgenis.emx2.Row) Test(org.junit.Test)

Example 85 with Schema

use of com.reprezen.kaizen.oasparser.model3.Schema in project molgenis-emx2 by molgenis.

the class ImportSchemaTask method run.

@Override
public void run() {
    this.start();
    Task commit = new Task("Committing");
    try {
        schema.tx(db -> {
            // import metadata, if any
            Schema s = db.getSchema(schema.getName());
            if (!filter.equals(Filter.DATA_ONLY)) {
                Task metadataTask = new ImportMetadataTask(s, tableStore, isStrict());
                this.addSubTask(metadataTask);
                metadataTask.run();
            }
            if (!filter.equals(Filter.METADATA_ONLY)) {
                Task dataTask = new ImportDataTask(s, tableStore, isStrict());
                this.addSubTask(dataTask);
                dataTask.run();
            }
            // committing
            this.addSubTask(commit.start());
        });
    } catch (Exception e) {
        this.setError("Import failed: " + e.getMessage());
        throw e;
    }
    commit.complete();
    this.complete();
}
Also used : Task(org.molgenis.emx2.tasks.Task) Schema(org.molgenis.emx2.Schema)

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 URL (java.net.URL)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 LayerSchemaDTO (org.geosdi.geoplatform.connector.wfs.response.LayerSchemaDTO)14 IOException (java.io.IOException)13 StringWriter (java.io.StringWriter)13 Schema (org.oasisopen.odata.csdl.v4.Schema)13 Schema (com.reprezen.kaizen.oasparser.model3.Schema)11 JAXBElement (javax.xml.bind.JAXBElement)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 List (java.util.List)8