Search in sources :

Example 1 with Setting

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

the class TestSettings method testTableSettings.

@Test
public void testTableSettings() {
    database.tx(// prevent side effect of user changes on other tests using tx
    db -> {
        Schema s = db.dropCreateSchema("testTableSettings");
        // set roles
        // viewer should only be able to see, not change
        // editor should be able to set values
        s.addMember("testtablesettingsviewer", VIEWER.toString());
        s.addMember("testtablesettingseditor", EDITOR.toString());
        s.create(table("test").add(column("test")));
        db.setActiveUser("testtablesettingsviewer");
        try {
            Table t = db.getSchema("testTableSettings").getTable("test");
            t.getMetadata().setSetting("key", "value");
            fail("viewers should not be able to change schema settings");
        } catch (Exception e) {
        // failed correctly
        }
        db.setActiveUser("testtablesettingseditor");
        try {
            Table t = db.getSchema("testTableSettings").getTable("test");
            t.getMetadata().setSetting("key", "value");
        } catch (Exception e) {
            e.printStackTrace();
            fail("managers should  be able to change schema settings");
        }
        db.clearCache();
        List<Setting> test = db.getSchema("testTableSettings").getTable("test").getMetadata().getSettings();
        assertEquals(1, test.size());
        assertEquals("key", test.get(0).key());
        assertEquals("value", test.get(0).value());
        assertEquals("key", db.getSchema("testTableSettings").getTable("test").getMetadata().getSettings().get(0).key());
        assertEquals("value", db.getSchema("testTableSettings").getTable("test").getMetadata().getSettings().get(0).value());
        db.becomeAdmin();
    });
}
Also used : Table(org.molgenis.emx2.Table) Schema(org.molgenis.emx2.Schema) Setting(org.molgenis.emx2.Setting) MolgenisException(org.molgenis.emx2.MolgenisException) Test(org.junit.Test)

Example 2 with Setting

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

the class MolgenisWebservice method start.

public static void start(int port) {
    sessionManager = new MolgenisSessionManager();
    oidcController = new OIDCController(sessionManager, new SecurityConfigFactory().build());
    port(port);
    staticFiles.location("/public_html");
    /*
     * WARNING !! SPARK JAVA USES DESIGN WHERE THE ORDER OF REQUEST DEFINITION DETERMINES THE HANDLER
     */
    get(("/" + OIDC_CALLBACK_PATH), (request, response) -> oidcController.handleLoginCallback(request, response));
    get(("/" + OIDC_LOGIN_PATH), oidcController::handleLoginRequest);
    get("/" + ROBOTS_TXT, MolgenisWebservice::robotsDotTxt);
    // get setting for home
    get("/", ACCEPT_HTML, (request, response) -> {
        // check for setting
        String ladingPagePath = sessionManager.getSession(request).getDatabase().getSettingValue(LANDING_PAGE);
        if (ladingPagePath != null) {
            response.redirect(ladingPagePath);
        } else {
            response.redirect("/apps/central/");
        }
        return response;
    });
    redirect.get("/api", "/api/");
    get("/api/", ACCEPT_HTML, (request, response) -> "Welcome to MOLGENIS EMX2 POC <br/>" + listSchemas(request, response));
    // documentation operations
    get("/api/openapi", ACCEPT_JSON, MolgenisWebservice::listSchemas);
    // docs per schema
    get("/:schema/api/openapi", OpenApiUiFactory::getOpenApiUserInterface);
    get("/:schema/api/openapi.yaml", MolgenisWebservice::openApiYaml);
    get("/:schema/api", (request, response) -> "Welcome to schema api. Check <a href=\"api/openapi\">openapi</a>");
    SiteMapService.create();
    CsvApi.create();
    ZipApi.create();
    ExcelApi.create();
    FileApi.create();
    JsonYamlApi.create();
    TaskApi.create();
    GraphqlApi.createGraphQLservice(sessionManager);
    LinkedDataFragmentsApi.create(sessionManager);
    BootstrapThemeService.create();
    get("/:schema", (req, res) -> {
        final String redirectLocation = "/" + req.params(SCHEMA) + "/";
        logger.debug(String.format("handle '/:schema' redirect: from: %s to: %s", req.pathInfo(), redirectLocation));
        res.redirect(redirectLocation);
        return "";
    });
    get("/:schema/", MolgenisWebservice::redirectSchemaToFirstMenuItem);
    // greedy proxy stuff, always put last!
    GroupPathMapper.create();
    // schema members operations
    // handling of exceptions
    exception(Exception.class, (e, req, res) -> {
        logger.error(e.getMessage());
        res.status(400);
        res.type(ACCEPT_JSON);
        res.body(molgenisExceptionToJson(e));
    });
}
Also used : OIDCController(org.molgenis.emx2.web.controllers.OIDCController)

Example 3 with Setting

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

the class TestEmx2Settings method testRolesIO.

@Test
public void testRolesIO() {
    // create settings
    schema.getMetadata().setSetting("foo", "bar");
    // export
    TableStore store = new TableStoreForCsvInMemory();
    Emx2Settings.outputSettings(store, schema);
    // empty the database, verify
    schema = schema.getDatabase().dropCreateSchema(TestEmx2Settings.class.getSimpleName());
    assertEquals(0, schema.getMetadata().getSettings().size());
    // import and see if consistent
    Emx2Settings.inputSettings(store, schema);
    List<Setting> settings = schema.getMetadata().getSettings();
    assertEquals("foo", settings.get(0).key());
    assertEquals("bar", settings.get(0).value());
}
Also used : TableStoreForCsvInMemory(org.molgenis.emx2.io.tablestore.TableStoreForCsvInMemory) Setting(org.molgenis.emx2.Setting) TableStore(org.molgenis.emx2.io.tablestore.TableStore) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 Setting (org.molgenis.emx2.Setting)2 MolgenisException (org.molgenis.emx2.MolgenisException)1 Schema (org.molgenis.emx2.Schema)1 Table (org.molgenis.emx2.Table)1 TableStore (org.molgenis.emx2.io.tablestore.TableStore)1 TableStoreForCsvInMemory (org.molgenis.emx2.io.tablestore.TableStoreForCsvInMemory)1 OIDCController (org.molgenis.emx2.web.controllers.OIDCController)1