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();
});
}
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"));
}
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();
}
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();
}
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());
});
}
Aggregations