Search in sources :

Example 1 with ForwardCursorPagedResourceList

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

the class ScheduledActivityControllerTest method createActivityResultsV2.

private ForwardCursorPagedResourceList<ScheduledActivity> createActivityResultsV2(int pageSize, String offsetKey) {
    DynamoScheduledActivity activity = new DynamoScheduledActivity();
    activity.setActivity(ACTIVITY_1);
    activity.setHealthCode("healthCode");
    activity.setSchedulePlanGuid("schedulePlanGuid");
    return new ForwardCursorPagedResourceList<ScheduledActivity>(ImmutableList.of(activity), "777").withRequestParam(ResourceList.PAGE_SIZE, pageSize).withRequestParam(ResourceList.OFFSET_KEY, offsetKey);
}
Also used : ForwardCursorPagedResourceList(org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList) DynamoScheduledActivity(org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity)

Example 2 with ForwardCursorPagedResourceList

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

the class ParticipantControllerTest method createActivityResultsV2.

private ForwardCursorPagedResourceList<ScheduledActivity> createActivityResultsV2(String offsetKey, int pageSize) {
    DynamoScheduledActivity activity = new DynamoScheduledActivity();
    activity.setActivity(ACTIVITY_1);
    activity.setHealthCode(HEALTH_CODE);
    activity.setSchedulePlanGuid("schedulePlanGuid");
    List<ScheduledActivity> list = ImmutableList.of(activity);
    return new ForwardCursorPagedResourceList<>(list, null).withRequestParam("pageSize", pageSize).withRequestParam("offsetKey", offsetKey);
}
Also used : ForwardCursorPagedResourceList(org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList) ScheduledActivity(org.sagebionetworks.bridge.models.schedules.ScheduledActivity) DynamoScheduledActivity(org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity) DynamoScheduledActivity(org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity)

Example 3 with ForwardCursorPagedResourceList

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

the class HealthDataEx3ControllerTest method getRecordsForStudy.

@Test
public void getRecordsForStudy() {
    // Set up mocks.
    Study study = Study.create();
    study.setAppId(TestConstants.TEST_APP_ID);
    study.setIdentifier(STUDY_ID);
    when(mockStudyService.getStudy(TestConstants.TEST_APP_ID, STUDY_ID, true)).thenReturn(study);
    ForwardCursorPagedResourceList<HealthDataRecordEx3> recordList = new ForwardCursorPagedResourceList<>(ImmutableList.of(HealthDataRecordEx3.create()), null);
    when(mockHealthDataEx3Service.getRecordsForAppAndStudy(TestConstants.TEST_APP_ID, STUDY_ID, CREATED_ON_START, CREATED_ON_END, BridgeConstants.API_DEFAULT_PAGE_SIZE, OFFSET_KEY)).thenReturn(recordList);
    // Execute and verify.
    ResourceList<HealthDataRecordEx3> outputList = controller.getRecordsForStudy(TestConstants.TEST_APP_ID, STUDY_ID, CREATED_ON_START_STRING, CREATED_ON_END_STRING, PAGE_SIZE_STRING, OFFSET_KEY);
    assertSame(outputList, recordList);
    assertEquals(outputList.getRequestParams().size(), 5);
    assertEquals(outputList.getRequestParams().get(ResourceList.START_TIME), CREATED_ON_START_STRING);
    assertEquals(outputList.getRequestParams().get(ResourceList.END_TIME), CREATED_ON_END_STRING);
    assertEquals(outputList.getRequestParams().get(ResourceList.PAGE_SIZE), BridgeConstants.API_DEFAULT_PAGE_SIZE);
    assertEquals(outputList.getRequestParams().get(ResourceList.OFFSET_KEY), OFFSET_KEY);
    assertEquals(outputList.getRequestParams().get(ResourceList.TYPE), ResourceList.REQUEST_PARAMS);
    verify(mockHealthDataEx3Service).getRecordsForAppAndStudy(TestConstants.TEST_APP_ID, STUDY_ID, CREATED_ON_START, CREATED_ON_END, BridgeConstants.API_DEFAULT_PAGE_SIZE, OFFSET_KEY);
}
Also used : ForwardCursorPagedResourceList(org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList) Study(org.sagebionetworks.bridge.models.studies.Study) HealthDataRecordEx3(org.sagebionetworks.bridge.models.healthdata.HealthDataRecordEx3) Test(org.testng.annotations.Test)

Example 4 with ForwardCursorPagedResourceList

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

the class ParticipantControllerTest method getActivityHistoryForWorkerV2.

@Test
public void getActivityHistoryForWorkerV2() throws Exception {
    session.setParticipant(new StudyParticipant.Builder().copyOf(session.getParticipant()).withRoles(ImmutableSet.of(Roles.WORKER)).build());
    ForwardCursorPagedResourceList<ScheduledActivity> cursor = new ForwardCursorPagedResourceList<>(ImmutableList.of(ScheduledActivity.create()), "asdf");
    when(mockParticipantService.getActivityHistory(eq(app), eq(TEST_USER_ID), eq("activityGuid"), any(), any(), eq("asdf"), eq(50))).thenReturn(cursor);
    JsonNode result = controller.getActivityHistoryForWorkerV2(TEST_APP_ID, TEST_USER_ID, "activityGuid", START_TIME.toString(), END_TIME.toString(), null, "asdf", "50");
    verify(mockParticipantService).getActivityHistory(eq(app), eq(TEST_USER_ID), eq("activityGuid"), any(), any(), eq("asdf"), eq(50));
    ForwardCursorPagedResourceList<ScheduledActivity> retrieved = MAPPER.readValue(result.toString(), new TypeReference<ForwardCursorPagedResourceList<ScheduledActivity>>() {
    });
    assertFalse(retrieved.getItems().isEmpty());
}
Also used : ForwardCursorPagedResourceList(org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList) ScheduledActivity(org.sagebionetworks.bridge.models.schedules.ScheduledActivity) DynamoScheduledActivity(org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.testng.annotations.Test)

Example 5 with ForwardCursorPagedResourceList

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

the class ScheduledActivityServiceTest method taskNotStartedIsUpdatedV4.

@Test
public void taskNotStartedIsUpdatedV4() {
    // Activity in DDB has survey reference pointing to createdOn 1234. Newly created activity has survey reference
    // pointing to createdOn 5678. Activity in DDB hasn't been started. We should update the activity in DDB.
    // Create task references and activities.
    // Schedule plan has been updated with a new activity that will be used in scheduled activity
    Activity newActivity = new Activity.Builder().withGuid("CCC").withSurvey("my-survey", "my-survey-guid", new DateTime(5678)).build();
    SchedulePlan ccc = schedulePlan(newActivity);
    // This is the schedule plan returned from the DB with the new Activity
    when(schedulePlanService.getSchedulePlans(ClientInfo.UNKNOWN_CLIENT, TEST_APP_ID, false)).thenReturn(Lists.newArrayList(ccc));
    // This is the persisted activity with the oldActivity
    Activity oldActivity = new Activity.Builder().withGuid("CCC").withSurvey("my-survey", "my-survey-guid", new DateTime(1234)).build();
    List<ScheduledActivity> db = createNewActivities("CCC" + TIME_PORTION);
    db.get(0).setActivity(oldActivity);
    ForwardCursorPagedResourceList<ScheduledActivity> page = new ForwardCursorPagedResourceList<>(db, null);
    when(activityDao.getActivityHistoryV2(any(), any(), any(), any(), any(), anyInt())).thenReturn(page);
    List<ScheduledActivity> returnedActivities = service.getScheduledActivitiesV4(app, createScheduleContext(NOW).build());
    assertEquals(returnedActivities.size(), 1);
    assertEquals(returnedActivities.get(0).getActivity().getSurvey().getCreatedOn().getMillis(), 5678);
    verify(activityDao).getActivityHistoryV2(any(), any(), any(), any(), any(), anyInt());
}
Also used : ForwardCursorPagedResourceList(org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList) Activity(org.sagebionetworks.bridge.models.schedules.Activity) ScheduledActivity(org.sagebionetworks.bridge.models.schedules.ScheduledActivity) DynamoScheduledActivity(org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity) ScheduledActivity(org.sagebionetworks.bridge.models.schedules.ScheduledActivity) DynamoScheduledActivity(org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) SchedulePlan(org.sagebionetworks.bridge.models.schedules.SchedulePlan) DynamoSchedulePlan(org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan) Test(org.testng.annotations.Test)

Aggregations

ForwardCursorPagedResourceList (org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList)32 Test (org.testng.annotations.Test)18 DateTime (org.joda.time.DateTime)10 ScheduledActivity (org.sagebionetworks.bridge.models.schedules.ScheduledActivity)10 List (java.util.List)9 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)7 Condition (com.amazonaws.services.dynamodbv2.model.Condition)7 ImmutableList (com.google.common.collect.ImmutableList)7 DynamoDBQueryExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression)6 ArrayList (java.util.ArrayList)6 DynamoScheduledActivity (org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity)6 Upload (org.sagebionetworks.bridge.models.upload.Upload)6 Item (com.amazonaws.services.dynamodbv2.document.Item)5 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Activity (org.sagebionetworks.bridge.models.schedules.Activity)4 PaginatedQueryList (com.amazonaws.services.dynamodbv2.datamodeling.PaginatedQueryList)3 QueryOutcome (com.amazonaws.services.dynamodbv2.document.QueryOutcome)3 RangeKeyCondition (com.amazonaws.services.dynamodbv2.document.RangeKeyCondition)3 QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)3