use of org.sagebionetworks.bridge.models.accounts.AccountSummary in project BridgeServer2 by Sage-Bionetworks.
the class ParticipantControllerTest method before.
@BeforeMethod
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
app = new DynamoApp();
app.setUserProfileAttributes(Sets.newHashSet("foo", "baz"));
app.setIdentifier(TEST_APP_ID);
participant = new StudyParticipant.Builder().withRoles(CALLER_ROLES).withStudyIds(CALLER_STUDIES).withId(TEST_USER_ID).build();
session = new UserSession(participant);
session.setAuthenticated(true);
session.setAppId(TEST_APP_ID);
doAnswer((ans) -> {
RequestContext.updateFromSession(session, mockSponsorService);
return session;
}).when(controller).getSessionIfItExists();
when(mockAppService.getApp(TEST_APP_ID)).thenReturn(app);
List<AccountSummary> summaries = ImmutableList.of(SUMMARY1, SUMMARY1, SUMMARY1);
PagedResourceList<AccountSummary> page = new PagedResourceList<>(summaries, 30).withRequestParam("offsetBy", 10).withRequestParam("pageSize", 20).withRequestParam("startTime", START_TIME).withRequestParam("endTime", END_TIME).withRequestParam("emailFilter", "foo");
when(mockParticipantService.getPagedAccountSummaries(eq(app), any())).thenReturn(page);
SessionUpdateService sessionUpdateService = new SessionUpdateService();
sessionUpdateService.setCacheProvider(mockCacheProvider);
sessionUpdateService.setConsentService(mockConsentService);
sessionUpdateService.setNotificationTopicService(mock(NotificationTopicService.class));
controller.setSessionUpdateService(sessionUpdateService);
doReturn(mockRequest).when(controller).request();
doReturn(mockResponse).when(controller).response();
}
use of org.sagebionetworks.bridge.models.accounts.AccountSummary in project BridgeServer2 by Sage-Bionetworks.
the class MembershipControllerTest method getMembersInaccessibleToOtherOrgs.
@Test(expectedExceptions = UnauthorizedException.class)
public void getMembersInaccessibleToOtherOrgs() throws Exception {
setContext(b -> b.withCallerAppId(TEST_APP_ID).withCallerOrgMembership("another-organization"));
doReturn(session).when(controller).getAdministrativeSession();
PagedResourceList<AccountSummary> page = new PagedResourceList<AccountSummary>(ImmutableList.of(), 0);
when(mockOrganizationService.getMembers(eq(TEST_APP_ID), eq(TEST_ORG_ID), any())).thenReturn(page);
AccountSummarySearch search = new AccountSummarySearch.Builder().withEmailFilter("email").build();
mockRequestBody(mockRequest, search);
controller.getMembers(TEST_ORG_ID);
}
use of org.sagebionetworks.bridge.models.accounts.AccountSummary in project BridgeServer2 by Sage-Bionetworks.
the class ParticipantControllerTest method searchForAccountSummariesForWorker.
@Test
public void searchForAccountSummariesForWorker() throws Exception {
session.setParticipant(new StudyParticipant.Builder().copyOf(session.getParticipant()).withRoles(ImmutableSet.of(Roles.WORKER)).build());
AccountSummarySearch payload = setAccountSummarySearch();
PagedResourceList<AccountSummary> result = controller.searchForAccountSummariesForWorker(app.getIdentifier());
assertEquals(result.getItems().size(), 3);
verify(mockParticipantService).getPagedAccountSummaries(eq(app), searchCaptor.capture());
AccountSummarySearch search = searchCaptor.getValue();
assertEquals(search, payload);
}
use of org.sagebionetworks.bridge.models.accounts.AccountSummary in project BridgeServer2 by Sage-Bionetworks.
the class HibernateAccountDao method unmarshallAccountSummary.
// Helper method to unmarshall a HibernateAccount into an AccountSummary.
// Package-scoped to facilitate unit tests.
AccountSummary unmarshallAccountSummary(HibernateAccount acct) {
AccountSummary.Builder builder = new AccountSummary.Builder();
builder.withAppId(acct.getAppId());
builder.withId(acct.getId());
builder.withFirstName(acct.getFirstName());
builder.withLastName(acct.getLastName());
builder.withEmail(acct.getEmail());
builder.withPhone(acct.getPhone());
builder.withCreatedOn(acct.getCreatedOn());
builder.withStatus(acct.getStatus());
builder.withSynapseUserId(acct.getSynapseUserId());
builder.withAttributes(acct.getAttributes());
builder.withOrgMembership(acct.getOrgMembership());
builder.withNote(acct.getNote());
builder.withClientTimeZone(acct.getClientTimeZone());
builder.withRoles(acct.getRoles());
builder.withDataGroups(acct.getDataGroups());
StudyAssociations assoc = BridgeUtils.studyAssociationsVisibleToCaller(null);
if (acct.getId() != null) {
assoc = BridgeUtils.studyAssociationsVisibleToCaller(acct);
}
builder.withExternalIds(assoc.getExternalIdsVisibleToCaller());
builder.withStudyIds(assoc.getStudyIdsVisibleToCaller());
return builder.build();
}
use of org.sagebionetworks.bridge.models.accounts.AccountSummary in project BridgeServer2 by Sage-Bionetworks.
the class HibernateAccountDaoTest method unmarshallAccountSummaryFiltersStudies.
@Test
public void unmarshallAccountSummaryFiltersStudies() throws Exception {
RequestContext.set(new RequestContext.Builder().withCallerUserId(// it's not the same as ACCOUNT_ID
TEST_USER_ID).withCallerRoles(ImmutableSet.of(STUDY_COORDINATOR)).withOrgSponsoredStudies(ImmutableSet.of("studyB", "studyC")).build());
Enrollment en1 = Enrollment.create(TEST_APP_ID, "studyA", ACCOUNT_ID, "externalIdA");
Enrollment en2 = Enrollment.create(TEST_APP_ID, "studyB", ACCOUNT_ID, "externalIdB");
// Create HibernateAccount. Only fill in values needed for AccountSummary.
HibernateAccount hibernateAccount = new HibernateAccount();
hibernateAccount.setId(ACCOUNT_ID);
hibernateAccount.setAppId(TEST_APP_ID);
hibernateAccount.setStatus(ENABLED);
hibernateAccount.setEnrollments(ImmutableSet.of(en1, en2));
// Unmarshall
AccountSummary accountSummary = dao.unmarshallAccountSummary(hibernateAccount);
assertEquals(accountSummary.getExternalIds(), ImmutableMap.of("studyB", "externalIdB"));
assertEquals(accountSummary.getStudyIds(), ImmutableSet.of("studyB"));
}
Aggregations