Search in sources :

Example 1 with SchemaMetadata

use of org.molgenis.emx2.SchemaMetadata in project molgenis-emx2 by molgenis.

the class RefAndRefArrayTestExample method createRefAndRefArrayTestExample.

public static void createRefAndRefArrayTestExample(SchemaMetadata schema) {
    ColumnType[] columnTypes = new ColumnType[] { UUID, STRING, BOOL, INT, DECIMAL, TEXT, DATE, DATETIME };
    for (ColumnType columnType : columnTypes) {
        String aTableName = columnType.toString() + "_A";
        String fieldName = "AKeyOf" + columnType;
        schema.create(table(aTableName).add(column(fieldName).setType(columnType).setPkey()));
        String bTableName = columnType.toString() + "_B";
        String refFromBToA = "RefToAKeyOf" + columnType;
        String refArrayFromBToA = "RefArrayToAKeyOf" + columnType;
        schema.create(table(bTableName).add(column(refFromBToA).setType(REF).setRefTable(aTableName)).add(column(refArrayFromBToA).setType(REF_ARRAY).setRefTable(aTableName)));
    }
}
Also used : ColumnType(org.molgenis.emx2.ColumnType)

Example 2 with SchemaMetadata

use of org.molgenis.emx2.SchemaMetadata in project molgenis-emx2 by molgenis.

the class ArrayTypeTestExample method createSimpleTypeTest.

public static void createSimpleTypeTest(SchemaMetadata schema) {
    TableMetadata typeTestTable = schema.create(table("ArrayTypeTest"));
    typeTestTable.add(column("id").setPkey());
    ColumnType[] columnTypes = new ColumnType[] { UUID_ARRAY, STRING_ARRAY, BOOL_ARRAY, INT_ARRAY, DECIMAL_ARRAY, TEXT_ARRAY, DATE_ARRAY, DATETIME_ARRAY };
    for (ColumnType columnType : columnTypes) {
        typeTestTable.add(column("Test_" + columnType.toString().toLowerCase()).setType(columnType).setRequired(true));
        typeTestTable.add(column("Test_" + columnType.toString().toLowerCase() + "_nillable").setType(columnType));
    }
}
Also used : TableMetadata(org.molgenis.emx2.TableMetadata) ColumnType(org.molgenis.emx2.ColumnType)

Example 3 with SchemaMetadata

use of org.molgenis.emx2.SchemaMetadata in project molgenis-emx2 by molgenis.

the class SimpleTypeTestExample method createSimpleTypeTest.

public static void createSimpleTypeTest(SchemaMetadata schema) {
    TableMetadata typeTestTable = table(TYPE_TEST).add(column("id").setPkey());
    ColumnType[] columnTypes = new ColumnType[] { UUID, STRING, BOOL, INT, DECIMAL, TEXT, DATE, DATETIME };
    for (ColumnType columnType : columnTypes) {
        typeTestTable.add(column("Test " + columnType.toString().toLowerCase()).setType(columnType).setRequired(true));
        typeTestTable.add(column("Test " + columnType.toString().toLowerCase() + " nillable").setType(columnType));
    }
    schema.create(typeTestTable);
}
Also used : TableMetadata(org.molgenis.emx2.TableMetadata) ColumnType(org.molgenis.emx2.ColumnType)

Example 4 with SchemaMetadata

use of org.molgenis.emx2.SchemaMetadata in project molgenis-emx2 by molgenis.

the class Schema method getSchemaMetadata.

public SchemaMetadata getSchemaMetadata() {
    SchemaMetadata s = new SchemaMetadata();
    s.setSettings(this.settings);
    for (Table t : this.tables) {
        TableMetadata tm = s.create(table(t.getName()));
        tm.setInherit(t.getInherit());
        tm.setSettings(t.getSettings());
        tm.setOldName(t.getOldName());
        if (t.getDrop())
            tm.drop();
        tm.setSemantics(t.getSemantics());
        tm.setDescription(t.getDescription());
        for (Column c : t.getColumns()) {
            int i = 1;
            if (!c.isInherited()) {
                // we remove clearly inherited columns here
                org.molgenis.emx2.Column cm = c.getColumnMetadata(tm);
                tm.add(cm);
            }
        }
        tm.setTableType(t.getTableType());
    }
    return s;
}
Also used : TableMetadata(org.molgenis.emx2.TableMetadata) SchemaMetadata(org.molgenis.emx2.SchemaMetadata)

Example 5 with SchemaMetadata

use of org.molgenis.emx2.SchemaMetadata in project molgenis-emx2 by molgenis.

the class Emx1 method loadColumns.

private static List<Emx1Attribute> loadColumns(TableStore store, Map<String, Emx1Entity> entities, SchemaMetadata schema) {
    // line 1 is header
    int line = 2;
    List<Emx1Attribute> attributes = new ArrayList<>();
    try {
        if (store.containsTable("attributes")) {
            for (Row row : store.readTable("attributes")) {
                attributes.add(new Emx1Attribute(row));
                line++;
            }
        }
        // line 1 is header
        line = 2;
        for (Emx1Attribute attribute : attributes) {
            // create the table, if needed
            String entityName = attribute.getEntity();
            String tableName = getTableName(entities, entityName);
            TableMetadata table = schema.getTableMetadata(tableName);
            if (table == null) {
                table = schema.create(table(tableName));
            }
            // create the attribute
            ColumnType type = getColumnType(attribute.getDataType());
            Column column = column(attribute.getName()).setType(type).setRequired(!attribute.getNillable());
            // pkey
            if (attribute.getIdAttribute()) {
                column.setKey(1);
            }
            table.add(column);
            line++;
        }
    } catch (MolgenisException me) {
        throw new MolgenisException(EMX_1_IMPORT_FAILED + me.getMessage() + ". See 'attributes' line " + line, me);
    }
    return attributes;
}
Also used : ColumnType(org.molgenis.emx2.ColumnType) ArrayList(java.util.ArrayList)

Aggregations

ColumnType (org.molgenis.emx2.ColumnType)6 SchemaMetadata (org.molgenis.emx2.SchemaMetadata)5 TableMetadata (org.molgenis.emx2.TableMetadata)5 Test (org.junit.Test)4 File (java.io.File)2 OpenAPI (io.swagger.v3.oas.models.OpenAPI)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 SqlSchemaMetadata (org.molgenis.emx2.sql.SqlSchemaMetadata)1 MolgenisWebservice.getSchema (org.molgenis.emx2.web.MolgenisWebservice.getSchema)1