Search in sources :

Example 1 with DynamoSchedulePlan

use of org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan in project BridgeServer2 by Sage-Bionetworks.

the class TestUtils method getSchedulePlans.

public static List<SchedulePlan> getSchedulePlans(String appId) {
    List<SchedulePlan> plans = Lists.newArrayListWithCapacity(3);
    SchedulePlan plan = new DynamoSchedulePlan();
    plan.setGuid("DDD");
    plan.setStrategy(getStrategy("P3D", getActivity1()));
    plan.setAppId(appId);
    plans.add(plan);
    plan = new DynamoSchedulePlan();
    plan.setGuid("BBB");
    plan.setStrategy(getStrategy("P1D", getActivity2()));
    plan.setAppId(appId);
    plans.add(plan);
    plan = new DynamoSchedulePlan();
    plan.setGuid("CCC");
    plan.setStrategy(getStrategy("P2D", getActivity3()));
    plan.setAppId(appId);
    plans.add(plan);
    return plans;
}
Also used : DynamoSchedulePlan(org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan) SchedulePlan(org.sagebionetworks.bridge.models.schedules.SchedulePlan) DynamoSchedulePlan(org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan)

Example 2 with DynamoSchedulePlan

use of org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan in project BridgeServer2 by Sage-Bionetworks.

the class ScheduleControllerTest method getSchedulesV3AdjustsScheduleTypes.

@SuppressWarnings("deprecation")
@Test
public void getSchedulesV3AdjustsScheduleTypes() throws Exception {
    List<SchedulePlan> plans = Lists.newArrayList();
    Schedule schedule = new Schedule();
    schedule.addActivity(new Activity.Builder().withLabel("Label").withTask("foo").build());
    schedule.setScheduleType(ScheduleType.RECURRING);
    schedule.setCronTrigger("0 0 12 1/1 * ? *");
    SimpleScheduleStrategy strategy = new SimpleScheduleStrategy();
    strategy.setSchedule(schedule);
    SchedulePlan plan = new DynamoSchedulePlan();
    plan.setLabel("Label");
    plan.setGuid("BBB");
    plan.setAppId(TEST_APP_ID);
    plan.setStrategy(strategy);
    plans.add(plan);
    schedule = new Schedule();
    schedule.addActivity(new Activity.Builder().withLabel("Label").withTask("foo").build());
    schedule.setScheduleType(ScheduleType.RECURRING);
    schedule.setCronTrigger("0 0 12 1/1 * ? *");
    strategy = new SimpleScheduleStrategy();
    strategy.setSchedule(schedule);
    plan = new DynamoSchedulePlan();
    plan.setLabel("Label");
    plan.setGuid("BBB");
    plan.setAppId(TEST_APP_ID);
    plan.setStrategy(strategy);
    plans.add(plan);
    when(mockSchedulePlanService.getSchedulePlans(any(), any(), anyBoolean())).thenReturn(plans);
    controller.setSchedulePlanService(mockSchedulePlanService);
    String result = controller.getSchedulesV3();
    JsonNode node = BridgeObjectMapper.get().readTree(result);
    ArrayNode array = (ArrayNode) node.get("items");
    // Verify that both objects have been adjusted so that despite the fact that they are
    // marked as persistent, they are also marked as recurring.
    ObjectNode schedule1 = (ObjectNode) array.get(0);
    assertTrue(schedule1.get("persistent").asBoolean());
    assertEquals(schedule1.get("scheduleType").asText(), "recurring");
    ObjectNode schedule2 = (ObjectNode) array.get(1);
    assertTrue(schedule2.get("persistent").asBoolean());
    assertEquals(schedule2.get("scheduleType").asText(), "recurring");
}
Also used : DynamoSchedulePlan(org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Schedule(org.sagebionetworks.bridge.models.schedules.Schedule) SimpleScheduleStrategy(org.sagebionetworks.bridge.models.schedules.SimpleScheduleStrategy) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) SchedulePlan(org.sagebionetworks.bridge.models.schedules.SchedulePlan) DynamoSchedulePlan(org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan) Test(org.testng.annotations.Test)

Example 3 with DynamoSchedulePlan

use of org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan in project BridgeServer2 by Sage-Bionetworks.

the class ScheduleControllerTest method before.

@BeforeMethod
public void before() throws Exception {
    MockitoAnnotations.initMocks(this);
    appId = TestUtils.randomName(ScheduleControllerTest.class);
    ClientInfo clientInfo = ClientInfo.fromUserAgentCache("app name/9");
    List<SchedulePlan> plans = TestUtils.getSchedulePlans(appId);
    // Add a plan that will returns null for a schedule, this is not included in the final list.
    // This is now possible and should not cause an error or a gap in the returned array.
    SchedulePlan plan = new DynamoSchedulePlan();
    plan.setStrategy(new ScheduleStrategy() {

        @Override
        public Schedule getScheduleForUser(SchedulePlan plan, ScheduleContext context) {
            return null;
        }

        @Override
        public void validate(Set<String> dataGroups, Set<String> studyIds, Set<String> taskIdentifiers, Errors errors) {
        }

        @Override
        public List<Schedule> getAllPossibleSchedules() {
            return ImmutableList.of();
        }
    });
    plans.add(plan);
    when(mockSchedulePlanService.getSchedulePlans(clientInfo, appId, false)).thenReturn(plans);
    UserSession session = new UserSession();
    session.setAppId(appId);
    doReturn(session).when(controller).getAuthenticatedAndConsentedSession();
    RequestContext.set(new RequestContext.Builder().withCallerClientInfo(clientInfo).build());
    doReturn(mockRequest).when(controller).request();
    doReturn(mockResponse).when(controller).response();
}
Also used : DynamoSchedulePlan(org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan) SimpleScheduleStrategy(org.sagebionetworks.bridge.models.schedules.SimpleScheduleStrategy) ScheduleStrategy(org.sagebionetworks.bridge.models.schedules.ScheduleStrategy) SchedulePlan(org.sagebionetworks.bridge.models.schedules.SchedulePlan) DynamoSchedulePlan(org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan) Errors(org.springframework.validation.Errors) Schedule(org.sagebionetworks.bridge.models.schedules.Schedule) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) ResourceList(org.sagebionetworks.bridge.models.ResourceList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ClientInfo(org.sagebionetworks.bridge.models.ClientInfo) RequestContext(org.sagebionetworks.bridge.RequestContext) ScheduleContext(org.sagebionetworks.bridge.models.schedules.ScheduleContext) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with DynamoSchedulePlan

use of org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan in project BridgeServer2 by Sage-Bionetworks.

the class ScheduledActivityServiceTest method firstTimeStampFor.

private String firstTimeStampFor(int initialTZOffset, int requestTZOffset, Schedule schedule) {
    // Tests calling this method set up different mocked environment from other tests.
    reset(schedulePlanService);
    reset(activityEventService);
    DateTime enrollment = DateTime.parse("2017-02-20T01:00:00.000Z");
    DateTimeZone initialTimeZone = DateTimeZone.forOffsetHours(initialTZOffset);
    DateTimeZone requestTimeZone = DateTimeZone.forOffsetHours(requestTZOffset);
    DateTime startsOn = DateTime.parse("2017-04-06T17:10:10.000Z").withZone(requestTimeZone);
    Map<String, DateTime> eventMap = Maps.newHashMap();
    eventMap.put("enrollment", enrollment);
    when(activityEventService.getActivityEventMap(TEST_APP_ID, "healthCode")).thenReturn(eventMap);
    SchedulePlan plan = new DynamoSchedulePlan();
    plan.setGuid("BBB");
    SimpleScheduleStrategy strategy = new SimpleScheduleStrategy();
    strategy.setSchedule(schedule);
    plan.setStrategy(strategy);
    when(schedulePlanService.getSchedulePlans(ClientInfo.UNKNOWN_CLIENT, TEST_APP_ID, false)).thenReturn(Lists.newArrayList(plan));
    ScheduleContext context = new ScheduleContext.Builder().withAppId(TEST_APP_ID).withUserId("userId").withStartsOn(startsOn).withAccountCreatedOn(enrollment).withInitialTimeZone(initialTimeZone).withEndsOn(startsOn.plusDays(4).withZone(requestTimeZone)).withHealthCode("healthCode").build();
    List<ScheduledActivity> activities = service.getScheduledActivities(app, context);
    verify(activityEventService).getActivityEventMap(TEST_APP_ID, "healthCode");
    verify(schedulePlanService).getSchedulePlans(ClientInfo.UNKNOWN_CLIENT, TEST_APP_ID, false);
    return activities.get(0).getScheduledOn().toString();
}
Also used : DynamoSchedulePlan(org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan) SimpleScheduleStrategy(org.sagebionetworks.bridge.models.schedules.SimpleScheduleStrategy) ScheduledActivity(org.sagebionetworks.bridge.models.schedules.ScheduledActivity) DynamoScheduledActivity(org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity) Mockito.anyString(org.mockito.Mockito.anyString) ScheduleContext(org.sagebionetworks.bridge.models.schedules.ScheduleContext) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime) DateTimeZone(org.joda.time.DateTimeZone) SchedulePlan(org.sagebionetworks.bridge.models.schedules.SchedulePlan) DynamoSchedulePlan(org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan)

Example 5 with DynamoSchedulePlan

use of org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan in project BridgeServer2 by Sage-Bionetworks.

the class ScheduledActivityServiceTest method schedulePlan.

private SchedulePlan schedulePlan(Activity activity) {
    Schedule schedule = new Schedule();
    schedule.setScheduleType(ScheduleType.RECURRING);
    schedule.setInterval(Period.parse("P1D"));
    schedule.addActivity(activity);
    schedule.setExpires(Period.parse("P1D"));
    schedule.addTimes("10:00");
    schedule.setLabel("Test label for the user");
    SimpleScheduleStrategy strategy = new SimpleScheduleStrategy();
    strategy.setSchedule(schedule);
    DynamoSchedulePlan plan = new DynamoSchedulePlan();
    plan.setGuid(BridgeUtils.generateGuid());
    plan.setModifiedOn(DateUtils.getCurrentMillisFromEpoch());
    plan.setAppId(TEST_APP_ID);
    plan.setStrategy(strategy);
    return plan;
}
Also used : DynamoSchedulePlan(org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan) Schedule(org.sagebionetworks.bridge.models.schedules.Schedule) SimpleScheduleStrategy(org.sagebionetworks.bridge.models.schedules.SimpleScheduleStrategy)

Aggregations

DynamoSchedulePlan (org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan)24 SchedulePlan (org.sagebionetworks.bridge.models.schedules.SchedulePlan)14 Schedule (org.sagebionetworks.bridge.models.schedules.Schedule)10 SimpleScheduleStrategy (org.sagebionetworks.bridge.models.schedules.SimpleScheduleStrategy)10 Activity (org.sagebionetworks.bridge.models.schedules.Activity)7 Test (org.testng.annotations.Test)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ABTestScheduleStrategy (org.sagebionetworks.bridge.models.schedules.ABTestScheduleStrategy)4 ScheduledActivity (org.sagebionetworks.bridge.models.schedules.ScheduledActivity)4 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)3 ScheduleContext (org.sagebionetworks.bridge.models.schedules.ScheduleContext)3 ScheduleStrategy (org.sagebionetworks.bridge.models.schedules.ScheduleStrategy)3 Errors (org.springframework.validation.Errors)3 DynamoScheduledActivity (org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity)2 GuidVersionHolder (org.sagebionetworks.bridge.models.GuidVersionHolder)2 App (org.sagebionetworks.bridge.models.apps.App)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1