Search in sources :

Example 96 with Schema

use of com.google.pubsub.v1.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 97 with Schema

use of com.google.pubsub.v1.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 98 with Schema

use of com.google.pubsub.v1.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 99 with Schema

use of com.google.pubsub.v1.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)

Example 100 with Schema

use of com.google.pubsub.v1.Schema in project odata-client by davidmoten.

the class Generator method printNavigationPropertyGetters.

private void printNavigationPropertyGetters(Structure<?> structure, Imports imports, Indent indent, PrintWriter p, List<TNavigationProperty> properties, Set<String> methodNames) {
    // write getters
    // 
    properties.forEach(x -> {
        String typeName = toClassName(x, imports);
        String methodName = Names.getGetterMethod(x.getName());
        methodNames.add(methodName);
        structure.printPropertyJavadoc(p, indent, x.getName(), "navigational property " + x.getName(), Collections.emptyMap());
        addNavigationPropertyAnnotation(imports, indent, p, x.getName());
        p.format("%s@%s\n", indent, imports.add(JsonIgnore.class));
        p.format("%spublic %s %s() {\n", indent, typeName, methodName);
        if (isCollection(x)) {
            if (names.isEntityWithNamespace(names.getType(x))) {
                p.format("%sreturn new %s(\n", indent.right(), toClassName(x, imports));
                // 
                p.format(// 
                "%scontextPath.addSegment(\"%s\"), %s.getValue(unmappedFields, \"%s\"));\n", indent.right().right().right().right(), x.getName(), imports.add(RequestHelper.class), x.getName());
                indent.left().left().left().left();
            } else {
                throw new RuntimeException("unexpected");
            }
        } else {
            if (names.isEntityWithNamespace(names.getType(x))) {
                Schema sch = names.getSchema(names.getInnerType(names.getType(x)));
                // 
                p.format(// 
                "%sreturn new %s(contextPath.addSegment(\"%s\"), %s.getValue(unmappedFields, \"%s\"));\n", // 
                indent.right(), imports.add(names.getFullClassNameEntityRequestFromTypeWithNamespace(sch, names.getInnerType(names.getType(x)))), // 
                x.getName(), // 
                imports.add(RequestHelper.class), x.getName());
            } else {
                throw new RuntimeException("unexpected");
            }
        }
        p.format("%s}\n", indent.left());
    });
}
Also used : JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) RequestHelper(com.github.davidmoten.odata.client.internal.RequestHelper) Schema(org.oasisopen.odata.csdl.v4.Schema)

Aggregations

Test (org.junit.Test)65 Schema (com.google.pubsub.v1.Schema)38 Schema (org.molgenis.emx2.Schema)38 ByteString (com.google.protobuf.ByteString)19 SchemaServiceClient (com.google.cloud.pubsub.v1.SchemaServiceClient)18 AbstractMessage (com.google.protobuf.AbstractMessage)18 QName (javax.xml.namespace.QName)16 SchemaName (com.google.pubsub.v1.SchemaName)15 File (java.io.File)15 Schema (org.geosdi.geoplatform.xml.xsd.v2001.Schema)15 ProjectName (com.google.pubsub.v1.ProjectName)14 IOException (java.io.IOException)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 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)12 StatusRuntimeException (io.grpc.StatusRuntimeException)12 Schema (com.reprezen.kaizen.oasparser.model3.Schema)11 JAXBElement (javax.xml.bind.JAXBElement)10