use of org.molgenis.emx2.TableMetadata in project molgenis-emx2 by molgenis.
the class SqlTableMetadata method alterColumn.
@Override
public TableMetadata alterColumn(String columnName, Column column) {
// ignore mg_ columns
if (column.getName().startsWith("mg_"))
return this;
Column oldColumn = getColumn(columnName);
if (oldColumn == null) {
throw new MolgenisException("Alter column failed: Column '" + getTableName() + "." + column.getName() + "' does not exist");
}
if (getInherit() != null && getInheritedTable().getColumn(columnName) != null) {
throw new MolgenisException("Alter column " + getTableName() + "." + columnName + " failed: column is part of inherited table " + getInherit());
}
if (getInherit() != null && getInheritedTable().getColumn(column.getName()) != null) {
throw new MolgenisException("Rename column from " + getTableName() + "." + columnName + " to " + getTableName() + "." + column.getName() + " failed: column '" + column.getName() + "' is part of inherited table " + getInherit());
}
getDatabase().tx(db -> sync(alterColumnTransaction(getSchemaName(), getTableName(), columnName, column, db)));
// reload the state
((SqlSchemaMetadata) getSchema()).sync(getDatabase().getSchema(getSchemaName()).getMetadata());
return this;
}
use of org.molgenis.emx2.TableMetadata in project molgenis-emx2 by molgenis.
the class SettingsDataModel method create.
public static void create(Schema schema) {
TableMetadata tm = table("Settings");
tm.add(column("schema").setKey(1));
tm.add(column("key").setKey(1));
tm.add(column("value"));
schema.create(tm);
}
use of org.molgenis.emx2.TableMetadata in project molgenis-emx2 by molgenis.
the class TableSort method sortTableByDependency.
public static void sortTableByDependency(List<TableMetadata> tableList) {
ArrayList<TableMetadata> result = new ArrayList<>();
ArrayList<TableMetadata> todo = new ArrayList<>(tableList);
// ensure deterministic order
todo.sort(new Comparator<TableMetadata>() {
@Override
public int compare(TableMetadata o1, TableMetadata o2) {
return o1.getTableName().compareTo(o2.getTableName());
}
});
while (!todo.isEmpty()) {
int size = todo.size();
for (int i = 0; i < todo.size(); i++) {
TableMetadata current = todo.get(i);
boolean depends = false;
for (int j = 0; j < todo.size(); j++) {
if (current.getInherit() != null && current.getImportSchema() == null && todo.get(j).equals(current.getInheritedTable())) {
depends = true;
break;
}
}
if (!depends)
for (Column c : current.getColumns()) {
if (c.getRefTableName() != null && !c.isRefback()) {
for (int j = 0; j < todo.size(); j++) {
if (i != j && (todo.get(j).getTableName().equals(c.getRefTableName()))) {
depends = true;
break;
}
}
}
}
if (!depends) {
result.add(todo.get(i));
todo.remove(i);
}
}
// check for circular relationship
if (size == todo.size()) {
throw new MolgenisException("circular dependency error: following tables have circular dependency: " + todo.stream().map(TableMetadata::getTableName).collect(Collectors.joining(",")));
}
}
tableList.clear();
tableList.addAll(result);
}
use of org.molgenis.emx2.TableMetadata in project molgenis-emx2 by molgenis.
the class TestGetSetAllTypesOnRows method addContents.
private void addContents(SchemaMetadata m, List<ColumnType> columnTypes) {
TableMetadata t = m.create(table("TypeTest"));
for (ColumnType columnType : columnTypes) {
t.add(column("test" + columnType).setType(columnType).setRequired(true));
t.add(column("test" + columnType + "_nullable").setType(columnType));
t.add(column("test" + columnType + "_readonly").setType(columnType).setReadonly(true));
}
}
use of org.molgenis.emx2.TableMetadata in project molgenis-emx2 by molgenis.
the class OpenApiYamlGenerator method createOpenApi.
public static OpenAPI createOpenApi(SchemaMetadata schema) {
Paths paths = new Paths();
Components components = new Components();
// basic metadata
OpenAPI api = new OpenAPI();
api.info(info(schema));
api.security(securityRequirementList());
// components
components.addSecuritySchemes("ApiKeyAuth", securityScheme());
components.addSchemas(PROBLEM, problemSchema());
components.addResponses(PROBLEM, problemResponse());
// api/zip/:schema
String zipType = "Zip";
String zipPrefix = "/" + schema.getName() + "/api/zip";
PathItem zipPath = getSchemaOperations(zipType, ACCEPT_ZIP);
paths.addPathItem(zipPrefix, zipPath);
// api/excel/:schema
String excelType = "Excel";
String excelPrefix = "/" + schema.getName() + "/api/excel";
PathItem excelPath = getSchemaOperations(excelType, ACCEPT_EXCEL);
paths.addPathItem(excelPrefix, excelPath);
// table paths
for (TableMetadata table : schema.getTables()) {
paths.addPathItem(excelPrefix + "/" + table.getTableName(), getExcelTableOperations(excelType));
paths.addPathItem(zipPrefix + "/" + table.getTableName(), getExcelTableOperations(zipType));
}
// api/csv/:schema
// assembly
api.setPaths(paths);
api.setComponents(components);
return api;
}
Aggregations