use of org.molgenis.emx2.MolgenisException in project molgenis-emx2 by molgenis.
the class SqlColumnRefBackExecutor method createRefBackColumnConstraints.
// will create a dummy array column matching the toColumn we will link to
// will create a before insert trigger to update all REF instances in the other table that needs
// updating
static void createRefBackColumnConstraints(DSLContext jooq, Column ref) {
try {
// get ref table
validateColumn(ref);
String columNames = ref.getReferences().stream().map(Reference::getName).collect(Collectors.joining(","));
// get the via column which is also in the 'toTable'
String refBackColumnName = ref.getRefBack();
if (refBackColumnName == null) {
throw new MolgenisException("Create column failed: Create of REFBACK column '" + ref.getQualifiedName() + "' failed because refBack was not set.");
}
// create the trigger so that insert/update/delete on REFBACK column updates the
// relationship
Column refBack = ref.getRefBackColumn();
if (refBack == null) {
throw new MolgenisException("Set refBack on column '" + ref.getTableName() + "." + ref.getName() + "'failed: refBack column '" + ref.getRefBack() + "'not found");
}
if (refBack.isRef()) {
createTriggerForRef(jooq, ref, true);
createTriggerForRef(jooq, ref, false);
} else if (refBack.isRefArray()) {
createTriggerForRefArray(jooq, ref);
} else {
throw new MolgenisException("Create column failed: Create of REFBACK column(s) '" + ref.getTableName() + "." + getNames(ref) + "' failed because refBack '" + ref.getRefBack() + "' was not of type REF, REF_ARRAY");
}
} catch (DataAccessException dae) {
throw new SqlMolgenisException("REFBACK column(s) '" + getNames(ref) + "' could not be created in table '" + ref.getTableName() + "'", dae);
}
}
use of org.molgenis.emx2.MolgenisException in project molgenis-emx2 by molgenis.
the class MolgenisSession method getGraphqlForSchema.
public GraphQL getGraphqlForSchema(String schemaName) {
logger.info("getting graphql schema '{}' for user '{}'", schemaName, getSessionUser());
if (graphqlPerSchema.get(schemaName) == null) {
Schema schema = database.getSchema(schemaName);
if (schema == null)
throw new MolgenisException("Schema not found: Schema with name '" + schemaName + "' does not exist or permission denied");
graphqlPerSchema.put(schemaName, new GraphqlApiFactory().createGraphqlForSchema(schema));
logger.info("created graphql schema '{}' for user '{}'", schemaName, getSessionUser());
}
logger.info("return graphql schema '{}' for user '{}'", schemaName, getSessionUser());
return graphqlPerSchema.get(schemaName);
}
use of org.molgenis.emx2.MolgenisException in project molgenis-emx2 by molgenis.
the class TableStoreForCsvFilesDirectory method writeTable.
@Override
public void writeTable(String name, List<String> columnNames, Iterable<Row> rows) {
Path relativePath = directoryPath.resolve(name + CSV_EXTENSION);
try {
Writer writer = Files.newBufferedWriter(relativePath);
if (rows.iterator().hasNext()) {
CsvTableWriter.write(rows, writer, separator);
} else {
// only header in case no rows provided
writer.write(columnNames.stream().collect(Collectors.joining("" + separator)));
}
writer.close();
} catch (IOException ioe) {
throw new MolgenisException("Export failed", ioe);
}
}
use of org.molgenis.emx2.MolgenisException in project molgenis-emx2 by molgenis.
the class TableStoreForCsvInZipFile method writeTable.
@Override
public void writeTable(String name, List<String> columnNames, Iterable<Row> rows) {
// 'Version' table)
if (columnNames.isEmpty()) {
return;
}
if (!Files.exists(zipFilePath)) {
create();
}
try (FileSystem zipfs = open()) {
Path pathInZipfile = zipfs.getPath(File.separator + name + CSV_EXTENSION);
Writer writer = Files.newBufferedWriter(pathInZipfile);
if (rows.iterator().hasNext()) {
CsvTableWriter.write(rows, writer, COMMA);
} else {
// only header in case no rows provided
writer.write(columnNames.stream().collect(Collectors.joining("" + COMMA)));
}
writer.close();
} catch (IOException ioe) {
throw new MolgenisException("Import failed", ioe);
}
}
use of org.molgenis.emx2.MolgenisException in project molgenis-emx2 by molgenis.
the class TableStoreForCsvInZipFile method tableNames.
@Override
public Collection<String> tableNames() {
List<String> result = new ArrayList<>();
try (ZipFile zf = new ZipFile(zipFilePath.toFile())) {
zf.stream().forEach(e -> {
String name = e.getName();
if (name.toLowerCase().endsWith(".csv") || name.toLowerCase().endsWith(".tsv")) {
name = name.substring(0, name.length() - 4);
}
result.add(name);
});
} catch (IOException ioe) {
throw new MolgenisException("Import failed: ", ioe);
}
return result;
}
Aggregations