Search in sources :

Example 1 with App

use of org.sagebionetworks.bridge.models.apps.App in project BridgeServer2 by Sage-Bionetworks.

the class DefaultAppBootstrapper method onApplicationEvent.

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    List<TableDescription> tables = annotationBasedTableCreator.getTables("org.sagebionetworks.bridge.dynamodb");
    dynamoInitializer.init(tables);
    s3Initializer.initBuckets();
    RequestContext.set(new RequestContext.Builder().withCallerAppId(API_APP_ID).withCallerRoles(ImmutableSet.of(SUPERADMIN)).withCallerUserId("DefaultStudyBootstrapper").build());
    // The integration bootstrap account should be ADMIN in production, and SUPERADMIN in other environments.
    // It should have the Synapse user ID of the synapse.user set for the integration tests.
    String adminEmail = bridgeConfig.get("admin.email");
    String adminSynUserId = bridgeConfig.get("admin.synapse.user.id");
    Roles adminRole = (bridgeConfig.getEnvironment() == PROD) ? ADMIN : SUPERADMIN;
    boolean bootstrapUserConfigured = (adminEmail != null && adminSynUserId != null);
    StudyParticipant admin = new StudyParticipant.Builder().withEmail(adminEmail).withSynapseUserId(adminSynUserId).withDataGroups(Sets.newHashSet(TEST_USER_GROUP)).withSharingScope(NO_SHARING).withRoles(Sets.newHashSet(adminRole)).build();
    App app = createApp(API_APP_ID, "Test App", provided -> {
        provided.setMinAgeOfConsent(18);
        provided.setDataGroups(Sets.newHashSet(TEST_DATA_GROUPS));
        provided.setTaskIdentifiers(Sets.newHashSet(TEST_TASK_IDENTIFIERS));
        provided.setUserProfileAttributes(Sets.newHashSet("can_be_recontacted"));
    });
    if (bootstrapUserConfigured) {
        createAccount(app, admin);
    }
    App app2 = createApp(API_2_APP_ID, "Test App 2", null);
    if (bootstrapUserConfigured) {
        createAccount(app2, admin);
    }
    App shared = createApp(SHARED_APP_ID, "Shared App", null);
    if (bootstrapUserConfigured && bridgeConfig.getEnvironment() != Environment.PROD) {
        createAccount(shared, admin);
    }
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription)

Example 2 with App

use of org.sagebionetworks.bridge.models.apps.App in project BridgeServer2 by Sage-Bionetworks.

the class DynamoAppDao method createApp.

@Override
public App createApp(App app) {
    checkNotNull(app);
    checkArgument(app.getVersion() == null, "%s has a version; may not be new", "app");
    try {
        mapper.save(app);
    } catch (ConditionalCheckFailedException e) {
        // in the create scenario, this should be a hash key clash.
        throw new EntityAlreadyExistsException(App.class, "identifier", app.getIdentifier());
    }
    return app;
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) EntityAlreadyExistsException(org.sagebionetworks.bridge.exceptions.EntityAlreadyExistsException) ConditionalCheckFailedException(com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)

Example 3 with App

use of org.sagebionetworks.bridge.models.apps.App in project BridgeServer2 by Sage-Bionetworks.

the class DynamoAppDao method deactivateApp.

@Override
public void deactivateApp(String appId) {
    checkNotNull(appId);
    if (appWhitelist.contains(appId)) {
        throw new UnauthorizedException(appId + " is protected by whitelist.");
    }
    App app = getApp(appId);
    app.setActive(false);
    updateApp(app);
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) UnauthorizedException(org.sagebionetworks.bridge.exceptions.UnauthorizedException)

Example 4 with App

use of org.sagebionetworks.bridge.models.apps.App in project BridgeServer2 by Sage-Bionetworks.

the class DynamoAppDaoTest method deleteApp.

@Test
public void deleteApp() {
    App app = App.create();
    app.setIdentifier(TEST_APP_ID);
    dao.deleteApp(app);
    verify(mockMapper).delete(app);
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) Test(org.testng.annotations.Test)

Example 5 with App

use of org.sagebionetworks.bridge.models.apps.App in project BridgeServer2 by Sage-Bionetworks.

the class DynamoAppDaoTest method getApp.

@Test
public void getApp() {
    DynamoApp saved = new DynamoApp();
    doReturn(saved).when(mockMapper).load(any());
    App result = dao.getApp(TEST_APP_ID);
    assertSame(result, saved);
    verify(mockMapper).load(appCaptor.capture());
    App key = appCaptor.getValue();
    assertEquals(key.getIdentifier(), TEST_APP_ID);
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) Test(org.testng.annotations.Test)

Aggregations

App (org.sagebionetworks.bridge.models.apps.App)389 Test (org.testng.annotations.Test)213 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)103 DynamoApp (org.sagebionetworks.bridge.dynamodb.DynamoApp)81 PostMapping (org.springframework.web.bind.annotation.PostMapping)74 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)65 Account (org.sagebionetworks.bridge.models.accounts.Account)57 GetMapping (org.springframework.web.bind.annotation.GetMapping)36 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)29 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)28 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)25 RequestContext (org.sagebionetworks.bridge.RequestContext)23 CriteriaContext (org.sagebionetworks.bridge.models.CriteriaContext)23 SignIn (org.sagebionetworks.bridge.models.accounts.SignIn)22 DateTime (org.joda.time.DateTime)20 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)19 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)19 JsonNode (com.fasterxml.jackson.databind.JsonNode)18 StudyActivityEvent (org.sagebionetworks.bridge.models.activities.StudyActivityEvent)17 AppAndUsers (org.sagebionetworks.bridge.models.apps.AppAndUsers)16