Search in sources :

Example 1 with SchedulePlan

use of org.sagebionetworks.bridge.models.schedules.SchedulePlan 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 SchedulePlan

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

the class CompoundActivityDefinitionServiceTest method deleteWithConstraintViolation.

@Test
public void deleteWithConstraintViolation() {
    SchedulePlan plan = TestUtils.getSimpleSchedulePlan(TEST_APP_ID);
    CompoundActivity compoundActivity = new CompoundActivity.Builder().withTaskIdentifier(TASK_ID).build();
    Activity newActivity = new Activity.Builder().withCompoundActivity(compoundActivity).build();
    plan.getStrategy().getAllPossibleSchedules().get(0).getActivities().set(0, newActivity);
    when(schedulePlanService.getSchedulePlans(ClientInfo.UNKNOWN_CLIENT, TEST_APP_ID, true)).thenReturn(Lists.newArrayList(plan));
    // Now, a schedule plan exists that references this task ID. It cannot be deleted.
    try {
        service.deleteCompoundActivityDefinition(TEST_APP_ID, TASK_ID);
        fail("Shoud have thrown exception");
    } catch (ConstraintViolationException e) {
        assertEquals(e.getReferrerKeys().get("guid"), "GGG");
        assertEquals(e.getReferrerKeys().get("type"), "SchedulePlan");
        assertEquals(e.getEntityKeys().get("taskId"), TASK_ID);
        assertEquals(e.getEntityKeys().get("type"), "CompoundActivityDefinition");
    }
}
Also used : CompoundActivity(org.sagebionetworks.bridge.models.schedules.CompoundActivity) CompoundActivity(org.sagebionetworks.bridge.models.schedules.CompoundActivity) Activity(org.sagebionetworks.bridge.models.schedules.Activity) ConstraintViolationException(org.sagebionetworks.bridge.exceptions.ConstraintViolationException) SchedulePlan(org.sagebionetworks.bridge.models.schedules.SchedulePlan) Test(org.testng.annotations.Test)

Example 3 with SchedulePlan

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

the class CompoundActivityDefinitionService method checkConstraintViolations.

private void checkConstraintViolations(String appId, String taskId) {
    // You cannot physically delete a compound activity if it is referenced by a logically deleted schedule plan.
    // It's possible the schedule plan could be restored. All you can do is logically delete the compound activity.
    List<SchedulePlan> plans = schedulePlanService.getSchedulePlans(ClientInfo.UNKNOWN_CLIENT, appId, true);
    SchedulePlan match = findFirstMatchingPlan(plans, taskId);
    if (match != null) {
        throw new ConstraintViolationException.Builder().withMessage("Cannot delete compound activity definition: it is referenced by a schedule plan that is still accessible through the API").withEntityKey("taskId", taskId).withEntityKey("type", "CompoundActivityDefinition").withReferrerKey("guid", match.getGuid()).withReferrerKey("type", "SchedulePlan").build();
    }
}
Also used : SchedulePlan(org.sagebionetworks.bridge.models.schedules.SchedulePlan)

Example 4 with SchedulePlan

use of org.sagebionetworks.bridge.models.schedules.SchedulePlan 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 5 with SchedulePlan

use of org.sagebionetworks.bridge.models.schedules.SchedulePlan 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)

Aggregations

SchedulePlan (org.sagebionetworks.bridge.models.schedules.SchedulePlan)97 Test (org.testng.annotations.Test)67 DynamoSchedulePlan (org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan)66 Activity (org.sagebionetworks.bridge.models.schedules.Activity)19 ScheduledActivity (org.sagebionetworks.bridge.models.schedules.ScheduledActivity)19 DynamoScheduledActivity (org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity)16 Schedule (org.sagebionetworks.bridge.models.schedules.Schedule)16 Survey (org.sagebionetworks.bridge.models.surveys.Survey)12 DynamoSurvey (org.sagebionetworks.bridge.dynamodb.DynamoSurvey)11 TestSurvey (org.sagebionetworks.bridge.models.surveys.TestSurvey)11 SimpleScheduleStrategy (org.sagebionetworks.bridge.models.schedules.SimpleScheduleStrategy)10 Criteria (org.sagebionetworks.bridge.models.Criteria)8 CriteriaScheduleStrategy (org.sagebionetworks.bridge.models.schedules.CriteriaScheduleStrategy)8 ScheduleCriteria (org.sagebionetworks.bridge.models.schedules.ScheduleCriteria)8 DateTime (org.joda.time.DateTime)7 LocalDateTime (org.joda.time.LocalDateTime)7 ConstraintViolationException (org.sagebionetworks.bridge.exceptions.ConstraintViolationException)7 ScheduleContext (org.sagebionetworks.bridge.models.schedules.ScheduleContext)7 Mockito.anyString (org.mockito.Mockito.anyString)6 CompoundActivity (org.sagebionetworks.bridge.models.schedules.CompoundActivity)6