use of org.molgenis.emx2.SchemaMetadata in project molgenis-emx2 by molgenis.
the class JsonYamlApi method postSchemaJSON.
static String postSchemaJSON(Request request, Response response) throws IOException {
Schema schema = getSchema(request);
SchemaMetadata otherSchema = jsonToSchema(request.body());
schema.migrate(otherSchema);
response.status(200);
return "patch metadata success";
}
use of org.molgenis.emx2.SchemaMetadata in project molgenis-emx2 by molgenis.
the class TestCohortCatalogue method importTest.
@Test
public void importTest() throws IOException {
StopWatch.print("begin");
// load data model
SchemaMetadata schema = Emx2.fromRowList(CsvTableReader.read(new File("../../data/datacatalogue/molgenis.csv")));
cohortsSchema.migrate(schema);
// load ontologies
MolgenisIO.fromDirectory(new File("../../data/datacatalogue/CatalogueOntologies").toPath(), ontologySchema, false);
MolgenisIO.fromDirectory(new File("../../data/datacatalogue/Cohorts").toPath(), cohortsSchema, false);
MolgenisIO.importFromExcelFile(new File("../../data/datacatalogue/Cohorts_CoreVariables.xlsx").toPath(), cohortsSchema, // todo fix data so we can put strict=true
false);
assertEquals(36, TestCohortCatalogue.cohortsSchema.getTableNames().size());
// export import schema to compare
}
use of org.molgenis.emx2.SchemaMetadata in project molgenis-emx2 by molgenis.
the class TestCohortCatalogue method importTestRWE.
@Test
public void importTestRWE() throws IOException {
StopWatch.print("begin");
// load data model
SchemaMetadata schema = Emx2.fromRowList(CsvTableReader.read(new File("../../data/datacatalogue/molgenis.csv")));
rweSchema.migrate(schema);
// should be possible to update same schema
database.clearCache();
schema = Emx2.fromRowList(CsvTableReader.read(new File("../../data/datacatalogue/molgenis.csv")));
rweSchema.migrate(schema);
// load ontologies
MolgenisIO.fromDirectory(new File("../../data/datacatalogue/CatalogueOntologies").toPath(), ontologySchema, false);
MolgenisIO.fromDirectory(new File("../../data/datacatalogue/RWEcatalogue").toPath(), rweSchema, false);
assertEquals(36, TestCohortCatalogue.rweSchema.getTableNames().size());
// export import schema to compare
}
use of org.molgenis.emx2.SchemaMetadata in project molgenis-emx2 by molgenis.
the class TestMergeDrop method testDrop.
@Test
public void testDrop() {
SchemaMetadata newSchema = new SchemaMetadata();
newSchema.create(table("Person", column("name")));
schema.migrate(newSchema);
// idempotent
schema.migrate(newSchema);
assertNotNull(schema.getTable("Person"));
newSchema = new SchemaMetadata();
newSchema.create(table("Person"));
newSchema.getTableMetadata("Person").drop();
schema.migrate(newSchema);
// should be idempotent
schema.migrate(newSchema);
assertNull(schema.getTable("Person"));
// now more complex, with dependency
newSchema = new SchemaMetadata();
newSchema.create(table("Person", column("name").setPkey()));
newSchema.create(table("Pet", column("name").setPkey(), column("owner").setType(ColumnType.REF).setRefTable("Person")));
schema.migrate(newSchema);
// should be idempotent so repeat
schema.migrate(newSchema);
assertNotNull(schema.getTable("Person"));
assertNotNull(schema.getTable("Pet"));
schema.getTable("Person").insert(row("name", "Donald"));
schema.getTable("Pet").insert(row("name", "Pluto", "owner", "Donald"));
// should fail
newSchema = new SchemaMetadata();
try {
newSchema.create(table("Person"));
newSchema.getTableMetadata("Person").drop();
schema.migrate(newSchema);
fail("should fail because of foreign key");
} catch (Exception e) {
// fine
}
// should succeed
newSchema.create(table("Pet"));
newSchema.getTableMetadata("Pet").drop();
schema.migrate(newSchema);
// should be idempotent so repeat
schema.migrate(newSchema);
assertNull(schema.getTable("Person"));
assertNull(schema.getTable("Pet"));
}
use of org.molgenis.emx2.SchemaMetadata in project molgenis-emx2 by molgenis.
the class GraphqlSchemaFieldFactory method changeTables.
private void changeTables(Schema schema, DataFetchingEnvironment dataFetchingEnvironment) throws IOException {
Object tables = dataFetchingEnvironment.getArgument(GraphqlConstants.TABLES);
// tables
if (tables != null) {
Map tableMap = Map.of("tables", tables);
String json = JsonUtil.getWriter().writeValueAsString(tableMap);
SchemaMetadata otherSchema = jsonToSchema(json);
schema.migrate(otherSchema);
}
}
Aggregations