Search in sources :

Example 46 with MolgenisException

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

the class SqlTableMetadata method dropColumn.

@Override
public void dropColumn(String name) {
    Column column = getColumn(name);
    if (column == null) {
        throw new MolgenisException("Drop column " + name + " failed: column does not exist");
    }
    // if changing 'ref' then check if not refBack exists
    checkNotRefback(name, column);
    long start = System.currentTimeMillis();
    // return silently, idempotent
    if (getColumn(name) == null)
        return;
    getDatabase().tx(db -> sync(dropColumnTransaction(db, getSchemaName(), getTableName(), name)));
    log(start, "removed column '" + name + "' from ");
}
Also used : MetadataUtils.deleteColumn(org.molgenis.emx2.sql.MetadataUtils.deleteColumn)

Example 47 with MolgenisException

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

the class Migrations method executeMigrationFile.

static void executeMigrationFile(Database db, String sqlFile, String message) {
    try {
        String sql = new String(Migrations.class.getResourceAsStream(sqlFile).readAllBytes());
        ((SqlDatabase) db).getJooq().execute(sql);
        logger.debug(message + "(file = " + sqlFile);
    } catch (IOException e) {
        throw new MolgenisException(e.getMessage());
    }
}
Also used : MolgenisException(org.molgenis.emx2.MolgenisException) IOException(java.io.IOException)

Example 48 with MolgenisException

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

the class OIDCController method handleLoginRequest.

public Object handleLoginRequest(Request request, Response response) {
    final SparkWebContext context = new SparkWebContext(request, response);
    final var client = securityConfig.getClients().findClient(OIDC_CLIENT_NAME).orElseThrow(() -> new MolgenisException("Expected OIDC client not found in security configuration"));
    HttpAction action;
    try {
        @SuppressWarnings("unchecked") Optional<HttpAction> httpAction = client.getRedirectionAction(context);
        if (httpAction.isEmpty()) {
            throw new MolgenisException("Expected OIDC redirection action not found");
        }
        action = httpAction.get();
    } catch (final HttpAction e) {
        action = e;
    }
    return SparkHttpActionAdapter.INSTANCE.adapt(action, context);
}
Also used : SparkWebContext(org.pac4j.sparkjava.SparkWebContext) MolgenisException(org.molgenis.emx2.MolgenisException) HttpAction(org.pac4j.core.exception.http.HttpAction)

Example 49 with MolgenisException

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

the class EvaluateExpressionsTest method testCalculateComputedExpressionFailure.

@Test
public void testCalculateComputedExpressionFailure() {
    String expression = "5 + YAAARGH";
    Row row = new Row();
    try {
        calculateComputedExpression(expression, row);
    } catch (MolgenisException exception) {
        assertEquals("Failed to execute expression: " + expression, exception.getMessage());
    }
}
Also used : MolgenisException(org.molgenis.emx2.MolgenisException) Row(org.molgenis.emx2.Row) Test(org.junit.Test)

Example 50 with MolgenisException

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

the class EvaluateExpressionsTest method testCheckValidationInvalidExpression.

@Test
public void testCheckValidationInvalidExpression() {
    Map<String, Object> values = new HashMap<>();
    Collection<Column> columns = new ArrayList<>();
    String validation = "this is very invalid";
    Column column = new Column("name");
    column.setValidation(validation);
    columns.add(column);
    try {
        checkValidation(values, columns);
    } catch (MolgenisException exception) {
        assertEquals("Cannot execute expression: this is very invalid", exception.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) Column(org.molgenis.emx2.Column) ArrayList(java.util.ArrayList) MolgenisException(org.molgenis.emx2.MolgenisException) Test(org.junit.Test)

Aggregations

MolgenisException (org.molgenis.emx2.MolgenisException)39 Path (java.nio.file.Path)9 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)6 Row (org.molgenis.emx2.Row)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 File (java.io.File)5 Column (org.molgenis.emx2.Column)5 ZipFile (java.util.zip.ZipFile)4 Schema (org.molgenis.emx2.Schema)4 Table (org.molgenis.emx2.Table)4 MetadataUtils.deleteColumn (org.molgenis.emx2.sql.MetadataUtils.deleteColumn)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 OutputStream (java.io.OutputStream)3 Writer (java.io.Writer)3 FileSystem (java.nio.file.FileSystem)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ZipEntry (java.util.zip.ZipEntry)3 org.molgenis.emx2 (org.molgenis.emx2)3