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());
}
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));
}
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);
}
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"));
}
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"));
}
Aggregations