Search in sources :

Example 1 with RequestInfo

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

the class BridgeUtilsTest method participantEligibleForDeletion_testUserAllowedAfterSignIn.

@Test
public void participantEligibleForDeletion_testUserAllowedAfterSignIn() {
    RequestInfoService mockService = mock(RequestInfoService.class);
    Account account = Account.create();
    account.setDataGroups(ImmutableSet.of(TEST_USER_GROUP));
    // User has signed in, and is still eligible for deletion
    RequestInfoService mockRequestService = mock(RequestInfoService.class);
    RequestInfo requestInfo = new RequestInfo.Builder().withSignedInOn(CREATED_ON).build();
    when(mockRequestService.getRequestInfo(TEST_USER_ID)).thenReturn(requestInfo);
    assertTrue(participantEligibleForDeletion(mockService, account));
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) RequestInfoService(org.sagebionetworks.bridge.services.RequestInfoService) RequestInfo(org.sagebionetworks.bridge.models.RequestInfo) Test(org.testng.annotations.Test) AssessmentConfigValidatorTest(org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)

Example 2 with RequestInfo

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

the class CacheProviderTest method getRequestInfoNewCache.

@Test
public void getRequestInfoNewCache() throws Exception {
    RequestInfo info = new RequestInfo.Builder().withUserId(USER_ID).build();
    when(jedisOps.get(REQUEST_INFO_KEY)).thenReturn(BridgeObjectMapper.get().writeValueAsString(info));
    RequestInfo returned = cacheProvider.getRequestInfo(USER_ID);
    assertEquals(info, returned);
    verify(jedisOps).get(REQUEST_INFO_KEY);
}
Also used : RequestInfo(org.sagebionetworks.bridge.models.RequestInfo) Test(org.testng.annotations.Test)

Example 3 with RequestInfo

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

the class AccountsController method getRequestInfo.

@GetMapping(path = { "/v1/accounts/{userId}/requestInfo" }, produces = { APPLICATION_JSON_UTF8_VALUE })
public String getRequestInfo(@PathVariable String userId) throws JsonProcessingException {
    UserSession session = getAuthenticatedSession(ORG_ADMIN);
    verifyOrgAdminIsActingOnOrgMember(session, userId);
    // RequestInfo is accessible because the user is accessible, no reason to
    // test again.
    RequestInfo requestInfo = requestInfoService.getRequestInfo(userId);
    if (requestInfo == null) {
        requestInfo = new RequestInfo.Builder().build();
    }
    return REQUEST_INFO_WRITER.writeValueAsString(requestInfo);
}
Also used : UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) RequestInfo(org.sagebionetworks.bridge.models.RequestInfo) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with RequestInfo

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

the class ScheduledActivityControllerTest method getScheduledActivitiesV4.

@Test
public void getScheduledActivitiesV4() throws Exception {
    DateTimeZone zone = DateTimeZone.forOffsetHours(4);
    DateTime startsOn = DateTime.now(zone).minusMinutes(1);
    DateTime endsOn = DateTime.now(zone).plusDays(7);
    mockEditAccount(mockAccountService, mockAccount);
    String result = controller.getScheduledActivitiesByDateRange(startsOn.toString(), endsOn.toString());
    JsonNode node = BridgeObjectMapper.get().readTree(result);
    assertEquals(node.get("startTime").textValue(), startsOn.toString());
    assertEquals(node.get("endTime").textValue(), endsOn.toString());
    verify(sessionUpdateService).updateTimeZone(any(UserSession.class), timeZoneCaptor.capture());
    verify(mockRequestInfoService).updateRequestInfo(requestInfoCaptor.capture());
    verify(mockScheduledActivityService).getScheduledActivitiesV4(eq(APP), contextCaptor.capture());
    verify(controller).persistTimeZone(session, zone);
    verify(mockAccount).setTimeZone(zone);
    assertEquals(startsOn.getZone(), timeZoneCaptor.getValue());
    RequestInfo requestInfo = requestInfoCaptor.getValue();
    assertEquals(requestInfo.getUserId(), "id");
    assertEquals(requestInfo.getClientInfo(), CLIENT_INFO);
    assertEquals(requestInfo.getUserAgent(), USER_AGENT);
    assertEquals(requestInfo.getLanguages(), LANGUAGES);
    assertEquals(requestInfo.getUserDataGroups(), USER_DATA_GROUPS);
    assertEquals(requestInfo.getUserStudyIds(), USER_STUDY_IDS);
    assertTrue(requestInfo.getActivitiesAccessedOn().isAfter(startsOn));
    assertNull(requestInfo.getSignedInOn());
    assertEquals(requestInfo.getAppId(), TEST_APP_ID);
    ScheduleContext context = contextCaptor.getValue();
    assertEquals(context.getInitialTimeZone(), startsOn.getZone());
    // To make the range inclusive, we need to adjust timestamp to right before the start instant
    // This value is not mirrored back in the response (see test above of the response).
    assertEquals(context.getStartsOn(), startsOn.minusMillis(1));
    assertEquals(context.getEndsOn(), endsOn);
    assertEquals(0, context.getMinimumPerSchedule());
    assertEquals(context.getAccountCreatedOn(), ACCOUNT_CREATED_ON.withZone(DateTimeZone.UTC));
    CriteriaContext critContext = context.getCriteriaContext();
    assertEquals(critContext.getAppId(), TEST_APP_ID);
    assertEquals(critContext.getHealthCode(), HEALTH_CODE);
    assertEquals(critContext.getUserId(), ID);
    assertEquals(critContext.getClientInfo(), CLIENT_INFO);
    assertEquals(critContext.getUserDataGroups(), USER_DATA_GROUPS);
    assertEquals(critContext.getUserStudyIds(), USER_STUDY_IDS);
    assertEquals(critContext.getLanguages(), LANGUAGES);
}
Also used : UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) JsonNode(com.fasterxml.jackson.databind.JsonNode) RequestInfo(org.sagebionetworks.bridge.models.RequestInfo) ScheduleContext(org.sagebionetworks.bridge.models.schedules.ScheduleContext) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) CriteriaContext(org.sagebionetworks.bridge.models.CriteriaContext) Test(org.testng.annotations.Test)

Example 5 with RequestInfo

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

the class ScheduledActivityControllerTest method getScheduledActivtiesAssemblesCorrectContext.

@SuppressWarnings("deprecation")
@Test
public void getScheduledActivtiesAssemblesCorrectContext() throws Exception {
    mockEditAccount(mockAccountService, mockAccount);
    DateTimeZone MSK = DateTimeZone.forOffsetHours(3);
    List<ScheduledActivity> list = ImmutableList.of();
    when(mockScheduledActivityService.getScheduledActivities(eq(APP), any(ScheduleContext.class))).thenReturn(list);
    controller.getScheduledActivities(null, "+03:00", "3", "5");
    verify(mockScheduledActivityService).getScheduledActivities(eq(APP), contextCaptor.capture());
    ScheduleContext context = contextCaptor.getValue();
    assertEquals(context.getInitialTimeZone(), MSK);
    assertEquals(context.getCriteriaContext().getUserDataGroups(), USER_DATA_GROUPS);
    assertEquals(context.getMinimumPerSchedule(), 5);
    CriteriaContext critContext = context.getCriteriaContext();
    assertEquals(critContext.getHealthCode(), HEALTH_CODE);
    assertEquals(critContext.getLanguages(), LANGUAGES);
    assertEquals(critContext.getUserStudyIds(), USER_STUDY_IDS);
    assertEquals(critContext.getAppId(), TEST_APP_ID);
    assertEquals(critContext.getClientInfo(), CLIENT_INFO);
    verify(mockRequestInfoService).updateRequestInfo(requestInfoCaptor.capture());
    RequestInfo requestInfo = requestInfoCaptor.getValue();
    assertEquals(requestInfo.getUserId(), "id");
    assertEquals(requestInfo.getLanguages(), LANGUAGES);
    assertEquals(requestInfo.getUserDataGroups(), USER_DATA_GROUPS);
    assertEquals(requestInfo.getUserStudyIds(), USER_STUDY_IDS);
    assertEquals(requestInfo.getAppId(), TEST_APP_ID);
    assertEquals(requestInfo.getUserAgent(), USER_AGENT);
    assertEquals(requestInfo.getClientInfo(), CLIENT_INFO);
    assertNotNull(requestInfo.getActivitiesAccessedOn());
    assertEquals(requestInfo.getActivitiesAccessedOn().getZone(), MSK);
    verify(sessionUpdateService).updateTimeZone(session, MSK);
    // Verify that the account mock was updated with the anticipated time zone (however
    // it's a mock as is sessionUpdateService, so this doesn't change RequestInfo, as it's
    // based on changes to the session.
    verify(mockAccount).setTimeZone(MSK);
}
Also used : ScheduledActivity(org.sagebionetworks.bridge.models.schedules.ScheduledActivity) DynamoScheduledActivity(org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity) RequestInfo(org.sagebionetworks.bridge.models.RequestInfo) ScheduleContext(org.sagebionetworks.bridge.models.schedules.ScheduleContext) DateTimeZone(org.joda.time.DateTimeZone) CriteriaContext(org.sagebionetworks.bridge.models.CriteriaContext) Test(org.testng.annotations.Test)

Aggregations

RequestInfo (org.sagebionetworks.bridge.models.RequestInfo)54 Test (org.testng.annotations.Test)32 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)12 Account (org.sagebionetworks.bridge.models.accounts.Account)8 GetMapping (org.springframework.web.bind.annotation.GetMapping)7 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)6 RequestContext (org.sagebionetworks.bridge.RequestContext)5 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)5 DateTime (org.joda.time.DateTime)4 CriteriaContext (org.sagebionetworks.bridge.models.CriteriaContext)4 StudyActivityEvent (org.sagebionetworks.bridge.models.activities.StudyActivityEvent)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 DateTimeZone (org.joda.time.DateTimeZone)3 ScheduleContext (org.sagebionetworks.bridge.models.schedules.ScheduleContext)3 RequestInfoService (org.sagebionetworks.bridge.services.RequestInfoService)3 AssessmentConfigValidatorTest (org.sagebionetworks.bridge.validators.AssessmentConfigValidatorTest)3 UnauthorizedException (org.sagebionetworks.bridge.exceptions.UnauthorizedException)2 Metrics (org.sagebionetworks.bridge.models.Metrics)2 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)2 HealthDataRecord (org.sagebionetworks.bridge.models.healthdata.HealthDataRecord)2