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