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;
}
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");
}
}
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();
}
}
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");
}
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();
}
Aggregations