Search in sources :

Example 1 with AccountSummary

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();
}
Also used : AccountSummary(org.sagebionetworks.bridge.models.accounts.AccountSummary) SessionUpdateService(org.sagebionetworks.bridge.services.SessionUpdateService) DynamoApp(org.sagebionetworks.bridge.dynamodb.DynamoApp) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) NotificationTopicService(org.sagebionetworks.bridge.services.NotificationTopicService) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with AccountSummary

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);
}
Also used : AccountSummary(org.sagebionetworks.bridge.models.accounts.AccountSummary) AccountSummarySearch(org.sagebionetworks.bridge.models.AccountSummarySearch) PagedResourceList(org.sagebionetworks.bridge.models.PagedResourceList) Test(org.testng.annotations.Test)

Example 3 with AccountSummary

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);
}
Also used : AccountSummary(org.sagebionetworks.bridge.models.accounts.AccountSummary) AccountSummarySearch(org.sagebionetworks.bridge.models.AccountSummarySearch) Test(org.testng.annotations.Test)

Example 4 with AccountSummary

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();
}
Also used : AccountSummary(org.sagebionetworks.bridge.models.accounts.AccountSummary) WhereClauseBuilder(org.sagebionetworks.bridge.hibernate.QueryBuilder.WhereClauseBuilder) StudyAssociations(org.sagebionetworks.bridge.BridgeUtils.StudyAssociations)

Example 5 with AccountSummary

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"));
}
Also used : AccountSummary(org.sagebionetworks.bridge.models.accounts.AccountSummary) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) RequestContext(org.sagebionetworks.bridge.RequestContext) Test(org.testng.annotations.Test)

Aggregations

AccountSummary (org.sagebionetworks.bridge.models.accounts.AccountSummary)25 Test (org.testng.annotations.Test)22 AccountSummarySearch (org.sagebionetworks.bridge.models.AccountSummarySearch)14 DateTime (org.joda.time.DateTime)7 RequestContext (org.sagebionetworks.bridge.RequestContext)7 PagedResourceList (org.sagebionetworks.bridge.models.PagedResourceList)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Enrollment (org.sagebionetworks.bridge.models.studies.Enrollment)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 HashMap (java.util.HashMap)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 StudyAssociations (org.sagebionetworks.bridge.BridgeUtils.StudyAssociations)1 DynamoApp (org.sagebionetworks.bridge.dynamodb.DynamoApp)1 WhereClauseBuilder (org.sagebionetworks.bridge.hibernate.QueryBuilder.WhereClauseBuilder)1 ForwardCursorPagedResourceList (org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList)1 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)1 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)1 NotificationTopicService (org.sagebionetworks.bridge.services.NotificationTopicService)1 SessionUpdateService (org.sagebionetworks.bridge.services.SessionUpdateService)1 BeforeMethod (org.testng.annotations.BeforeMethod)1