Search in sources :

Example 1 with StudyParticipant

use of org.sagebionetworks.bridge.models.accounts.StudyParticipant 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 StudyParticipant

use of org.sagebionetworks.bridge.models.accounts.StudyParticipant in project BridgeServer2 by Sage-Bionetworks.

the class BridgeUtilsTest method participantTemplateVariablesWorks.

@Test
public void participantTemplateVariablesWorks() {
    StudyParticipant participant = new StudyParticipant.Builder().withFirstName("aFirstName").withLastName("aLastName").withEmail(EMAIL).withPhone(PHONE).withAttributes(ImmutableMap.of("first_prop", "A", "second prop", "B")).build();
    Map<String, String> map = BridgeUtils.participantTemplateVariables(participant);
    assertEquals(map.get("participantFirstName"), "aFirstName");
    assertEquals(map.get("participantLastName"), "aLastName");
    assertEquals(map.get("participantPhone"), "+19712486796");
    assertEquals(map.get("participantPhoneRegion"), "US");
    assertEquals(map.get("participant.first_prop"), "A");
    assertEquals(map.get("participant.second prop"), "B");
    assertEquals(map.get("participantEmail"), "email@email.com");
    assertEquals(map.get("participantPhoneNationalFormat"), "(971) 248-6796");
}
Also used : StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) Test(org.testng.annotations.Test) AssessmentConfigValidatorTest(org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)

Example 3 with StudyParticipant

use of org.sagebionetworks.bridge.models.accounts.StudyParticipant in project BridgeServer2 by Sage-Bionetworks.

the class CacheProviderTest method testSetUserSessionNullSessionToken.

@Test
public void testSetUserSessionNullSessionToken() throws Exception {
    StudyParticipant participant = new StudyParticipant.Builder().withEmail("userEmail").withId(USER_ID).withHealthCode("healthCode").build();
    UserSession session = new UserSession(participant);
    try {
        cacheProvider.setUserSession(session);
    } catch (NullPointerException e) {
        assertTrue(true, "NPE expected.");
    } catch (Throwable e) {
        fail(e.getMessage());
    }
    verify(transaction, never()).setex(eq(TOKEN_TO_USER_ID.toString()), anyInt(), anyString());
    verify(transaction, never()).setex(eq(USER_ID_TO_SESSION.toString()), anyInt(), eq(DECRYPTED_SESSION_TOKEN));
    verify(transaction, never()).exec();
}
Also used : UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) Test(org.testng.annotations.Test)

Example 4 with StudyParticipant

use of org.sagebionetworks.bridge.models.accounts.StudyParticipant in project BridgeServer2 by Sage-Bionetworks.

the class CacheProviderTest method testRemoveSession.

@Test
public void testRemoveSession() {
    StudyParticipant participant = new StudyParticipant.Builder().withId(USER_ID).build();
    UserSession session = new UserSession(participant);
    session.setSessionToken(DECRYPTED_SESSION_TOKEN);
    cacheProvider.removeSession(session);
    cacheProvider.getUserSession(DECRYPTED_SESSION_TOKEN);
    verify(transaction).del(TOKEN_TO_USER_ID.toString());
    verify(transaction).del(USER_ID_TO_SESSION.toString());
    verify(transaction).exec();
}
Also used : UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) Test(org.testng.annotations.Test)

Example 5 with StudyParticipant

use of org.sagebionetworks.bridge.models.accounts.StudyParticipant in project BridgeServer2 by Sage-Bionetworks.

the class CacheProviderTest method assertSession.

private void assertSession(String json) {
    JedisOps jedisOps = mock(JedisOps.class);
    when(jedisOps.get(TOKEN_TO_USER_ID.toString())).thenReturn(USER_ID);
    when(jedisOps.get(USER_ID_TO_SESSION.toString())).thenReturn(json);
    cacheProvider.setJedisOps(jedisOps);
    UserSession session = cacheProvider.getUserSession(DECRYPTED_SESSION_TOKEN);
    assertTrue(session.isAuthenticated());
    assertEquals(session.getEnvironment(), Environment.LOCAL);
    assertEquals(session.getSessionToken(), DECRYPTED_SESSION_TOKEN);
    assertEquals(session.getInternalSessionToken(), "4f0937a5-6ebf-451b-84bc-fbf649b9e93c");
    assertEquals(session.getId(), "6gq4jGXLmAxVbLLmVifKN4");
    assertEquals(session.getAppId(), TEST_APP_ID);
    StudyParticipant participant = session.getParticipant();
    assertEquals(participant.getFirstName(), "Bridge");
    assertEquals(participant.getLastName(), "IT");
    assertEquals(participant.getEmail(), "bridgeit@sagebase.org");
    assertEquals(participant.getSharingScope(), SharingScope.NO_SHARING);
    assertEquals(participant.getCreatedOn(), DateTime.parse("2016-04-21T16:48:22.386Z"));
    assertEquals(participant.getRoles(), Sets.newHashSet(Roles.ADMIN));
    assertEquals(participant.getLanguages(), ImmutableList.of("en", "fr"));
    assertEquals(participant.getExternalId(), "ABC");
    assertEquals(ENCRYPTOR.decrypt(ENCRYPTED_SESSION_TOKEN), participant.getHealthCode());
    SubpopulationGuid apiGuid = SubpopulationGuid.create(TEST_APP_ID);
    Map<SubpopulationGuid, ConsentStatus> consentStatuses = session.getConsentStatuses();
    ConsentStatus status = consentStatuses.get(apiGuid);
    assertEquals(status.getName(), "Default Consent Group");
    assertEquals(status.getSubpopulationGuid(), apiGuid.getGuid());
    assertTrue(status.getSignedMostRecentConsent());
    assertTrue(status.isRequired());
    assertFalse(status.isConsented());
}
Also used : JedisOps(org.sagebionetworks.bridge.redis.JedisOps) ConsentStatus(org.sagebionetworks.bridge.models.accounts.ConsentStatus) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) SubpopulationGuid(org.sagebionetworks.bridge.models.subpopulations.SubpopulationGuid) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant)

Aggregations

StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)307 Test (org.testng.annotations.Test)246 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)58 App (org.sagebionetworks.bridge.models.apps.App)54 RequestContext (org.sagebionetworks.bridge.RequestContext)43 JsonNode (com.fasterxml.jackson.databind.JsonNode)26 CriteriaContext (org.sagebionetworks.bridge.models.CriteriaContext)25 Account (org.sagebionetworks.bridge.models.accounts.Account)22 AppAndUsers (org.sagebionetworks.bridge.models.apps.AppAndUsers)19 PostMapping (org.springframework.web.bind.annotation.PostMapping)17 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)16 DynamoApp (org.sagebionetworks.bridge.dynamodb.DynamoApp)14 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)14 IdentifierHolder (org.sagebionetworks.bridge.models.accounts.IdentifierHolder)13 SubpopulationGuid (org.sagebionetworks.bridge.models.subpopulations.SubpopulationGuid)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 ConsentStatus (org.sagebionetworks.bridge.models.accounts.ConsentStatus)9 Enrollment (org.sagebionetworks.bridge.models.studies.Enrollment)9 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)8 DateTime (org.joda.time.DateTime)7