Search in sources :

Example 1 with Enrollment

use of org.sagebionetworks.bridge.models.studies.Enrollment in project BridgeServer2 by Sage-Bionetworks.

the class BridgeUtils method studyAssociationsVisibleToCaller.

/**
 * Callers only see the enrollment records they themselves are assigned to, unless they have no
 * study memberships (then they are global and see everything). This call shows active enrollments
 * only.
 */
public static StudyAssociations studyAssociationsVisibleToCaller(Account account) {
    if (account == null || account.getActiveEnrollments().isEmpty()) {
        return NO_ASSOCIATIONS;
    }
    ImmutableSet.Builder<String> studyIds = new ImmutableSet.Builder<>();
    ImmutableMap.Builder<String, String> externalIds = new ImmutableMap.Builder<>();
    for (Enrollment enrollment : account.getActiveEnrollments()) {
        if (CAN_READ_STUDY_ASSOCIATIONS.check(STUDY_ID, enrollment.getStudyId(), USER_ID, account.getId())) {
            studyIds.add(enrollment.getStudyId());
            if (enrollment.getExternalId() != null) {
                externalIds.put(enrollment.getStudyId(), enrollment.getExternalId());
            }
        }
    }
    return new StudyAssociations(studyIds.build(), externalIds.build());
}
Also used : BridgeCollectors.toImmutableSet(org.sagebionetworks.bridge.util.BridgeCollectors.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with Enrollment

use of org.sagebionetworks.bridge.models.studies.Enrollment in project BridgeServer2 by Sage-Bionetworks.

the class BridgeUtilsTest method accountHasValidIdentifierInvalid.

@Test
public void accountHasValidIdentifierInvalid() {
    Account account = Account.create();
    account.setEnrollments(null);
    assertFalse(BridgeUtils.hasValidIdentifier(account));
    account = Account.create();
    Enrollment en1 = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
    account.setEnrollments(ImmutableSet.of(en1));
    assertFalse(BridgeUtils.hasValidIdentifier(account));
    account = Account.create();
    account.setEnrollments(ImmutableSet.of());
    assertFalse(BridgeUtils.hasValidIdentifier(account));
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Test(org.testng.annotations.Test) AssessmentConfigValidatorTest(org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)

Example 3 with Enrollment

use of org.sagebionetworks.bridge.models.studies.Enrollment in project BridgeServer2 by Sage-Bionetworks.

the class BridgeUtilsTest method getElement_handlesNullFieldValues.

@Test
public void getElement_handlesNullFieldValues() {
    Enrollment en1 = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, "someOtherId1");
    en1.setExternalId("en1");
    Enrollment en2 = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, "someOtherId2");
    Set<Enrollment> enrollments = ImmutableSet.of(en1, en2);
    Enrollment retValue = BridgeUtils.getElement(enrollments, Enrollment::getExternalId, "en1").orElse(null);
    assertSame(retValue, en1);
}
Also used : Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Test(org.testng.annotations.Test) AssessmentConfigValidatorTest(org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)

Example 4 with Enrollment

use of org.sagebionetworks.bridge.models.studies.Enrollment in project BridgeServer2 by Sage-Bionetworks.

the class BridgeUtilsTest method externalIdsVisibleToCaller.

@Test
public void externalIdsVisibleToCaller() {
    Set<String> callerStudies = ImmutableSet.of("studyA", "studyB", "studyD");
    RequestContext.set(new RequestContext.Builder().withCallerUserId(TEST_USER_ID).withCallerRoles(ImmutableSet.of(STUDY_COORDINATOR)).withOrgSponsoredStudies(callerStudies).build());
    Enrollment enA = Enrollment.create(TEST_APP_ID, "studyA", "id", "extA");
    Enrollment enB = Enrollment.create(TEST_APP_ID, "studyB", "id", "extB");
    Enrollment enC = Enrollment.create(TEST_APP_ID, "studyC", "id", "extC");
    Account account = Account.create();
    account.setId("id");
    account.setEnrollments(ImmutableSet.of(enA, enB, enC));
    Map<String, String> visibles = BridgeUtils.studyAssociationsVisibleToCaller(account).getExternalIdsVisibleToCaller();
    assertEquals(visibles, ImmutableMap.of("studyA", "extA", "studyB", "extB"));
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Test(org.testng.annotations.Test) AssessmentConfigValidatorTest(org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)

Example 5 with Enrollment

use of org.sagebionetworks.bridge.models.studies.Enrollment in project BridgeServer2 by Sage-Bionetworks.

the class BridgeUtilsTest method studyIdsVisibleToCallerFilters.

@Test
public void studyIdsVisibleToCallerFilters() {
    Set<String> callerStudies = ImmutableSet.of("studyA", "studyB", "studyD");
    RequestContext.set(new RequestContext.Builder().withCallerUserId("callerUserId").withCallerRoles(ImmutableSet.of(STUDY_COORDINATOR)).withOrgSponsoredStudies(callerStudies).build());
    Enrollment enA = Enrollment.create(TEST_APP_ID, "studyA", "id");
    Enrollment enB = Enrollment.create(TEST_APP_ID, "studyB", "id");
    Enrollment enC = Enrollment.create(TEST_APP_ID, "studyC", "id");
    Account account = Account.create();
    account.setEnrollments(ImmutableSet.of(enA, enB, enC));
    Set<String> visibles = BridgeUtils.studyAssociationsVisibleToCaller(account).getStudyIdsVisibleToCaller();
    assertEquals(visibles, ImmutableSet.of("studyA", "studyB"));
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Test(org.testng.annotations.Test) AssessmentConfigValidatorTest(org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)

Aggregations

Enrollment (org.sagebionetworks.bridge.models.studies.Enrollment)142 Test (org.testng.annotations.Test)115 Account (org.sagebionetworks.bridge.models.accounts.Account)73 RequestContext (org.sagebionetworks.bridge.RequestContext)30 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)17 AssessmentConfigValidatorTest (org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)15 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)14 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)12 Study (org.sagebionetworks.bridge.models.studies.Study)12 DateTime (org.joda.time.DateTime)11 StudyActivityEvent (org.sagebionetworks.bridge.models.activities.StudyActivityEvent)10 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)9 UnauthorizedException (org.sagebionetworks.bridge.exceptions.UnauthorizedException)6 Subpopulation (org.sagebionetworks.bridge.models.subpopulations.Subpopulation)6 SubpopulationGuid (org.sagebionetworks.bridge.models.subpopulations.SubpopulationGuid)6 HibernateEnrollment (org.sagebionetworks.bridge.hibernate.HibernateEnrollment)5 AccountSummary (org.sagebionetworks.bridge.models.accounts.AccountSummary)5 App (org.sagebionetworks.bridge.models.apps.App)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)4