use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.
the class SessionValidatorTest method comparatorHandlesNulls.
@Test
public void comparatorHandlesNulls() {
Session session = makeWindows("08:13", "PT1M", "08:02", "PT1M", "09:01", "P7D");
session.getTimeWindows().get(1).setStartTime(null);
List<TimeWindow> windows = Lists.newArrayList(session.getTimeWindows());
windows.sort(START_TIME_COMPARATOR);
assertEquals(windows.get(0).getStartTime(), LocalTime.parse("08:13"));
assertEquals(windows.get(1).getStartTime(), LocalTime.parse("09:01"));
assertNull(windows.get(2).getStartTime());
}
use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.
the class SessionValidatorTest method comparatorWorks.
@Test
public void comparatorWorks() {
Session session = makeWindows("08:13", "PT1M", "08:02", "PT1M", "09:01", "P7D");
List<TimeWindow> windows = Lists.newArrayList(session.getTimeWindows());
windows.sort(START_TIME_COMPARATOR);
assertEquals(windows.get(0).getStartTime(), LocalTime.parse("08:02"));
assertEquals(windows.get(1).getStartTime(), LocalTime.parse("08:13"));
assertEquals(windows.get(2).getStartTime(), LocalTime.parse("09:01"));
}
use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.
the class StudyAdherenceReportGeneratorTest method createSchedule.
/**
* This is not a super-complicated schedule, but I have mapped out the exact dates when
* everything should occur for a timeline_retrieved event of 3/1, so I can verify the
* dates and such are correct after the generator executes.
*/
public static Schedule2 createSchedule() {
// survey
AssessmentReference ref1 = new AssessmentReference();
ref1.setGuid("survey");
ref1.setAppId(TEST_APP_ID);
ref1.setIdentifier("survey");
// tapping test
AssessmentReference ref2 = new AssessmentReference();
ref2.setGuid("tappingTest");
ref2.setAppId(TEST_APP_ID);
ref2.setIdentifier("tappingTest");
// final survey
AssessmentReference ref3 = new AssessmentReference();
ref3.setGuid("finalSurvey");
ref3.setAppId(TEST_APP_ID);
ref3.setIdentifier("finalSurvey");
Schedule2 schedule = new Schedule2();
// Initial survey
TimeWindow win1 = new TimeWindow();
win1.setGuid("win1");
win1.setStartTime(LocalTime.parse("00:00"));
win1.setExpiration(Period.parse("P1D"));
Session s1 = new Session();
s1.setAssessments(ImmutableList.of(ref1));
s1.setDelay(Period.parse("P1D"));
s1.setStartEventIds(ImmutableList.of("timeline_retrieved"));
s1.setTimeWindows(ImmutableList.of(win1));
s1.setGuid("initialSurveyGuid");
s1.setName("Initial Survey");
s1.setPerformanceOrder(SEQUENTIAL);
// Baseline tapping test
TimeWindow win2 = new TimeWindow();
win2.setGuid("win2");
win2.setStartTime(LocalTime.parse("00:00"));
win2.setExpiration(Period.parse("P1D"));
Session s2 = new Session();
s2.setAssessments(ImmutableList.of(ref2));
s2.setDelay(Period.parse("P2D"));
s2.setStartEventIds(ImmutableList.of("timeline_retrieved"));
s2.setTimeWindows(ImmutableList.of(win2));
s2.setGuid("baselineGuid");
s2.setName("Baseline Tapping Test");
s2.setPerformanceOrder(SEQUENTIAL);
// Study Burst
StudyBurst burst = new StudyBurst();
burst.setIdentifier("Study Burst");
burst.setOriginEventId("timeline_retrieved");
burst.setUpdateType(IMMUTABLE);
burst.setDelay(Period.parse("P1W"));
burst.setOccurrences(3);
burst.setInterval(Period.parse("P1W"));
TimeWindow win3 = new TimeWindow();
win3.setGuid("win3");
win3.setStartTime(LocalTime.parse("00:00"));
win3.setExpiration(Period.parse("P1D"));
Session s3 = new Session();
s3.setAssessments(ImmutableList.of(ref2));
s3.setStudyBurstIds(ImmutableList.of("Study Burst"));
s3.setTimeWindows(ImmutableList.of(win3));
s3.setGuid("burstTappingGuid");
s3.setName("Study Burst Tapping Test");
s3.setPerformanceOrder(SEQUENTIAL);
// Final survey
TimeWindow win4 = new TimeWindow();
win4.setGuid("win4");
win4.setStartTime(LocalTime.parse("00:00"));
win4.setExpiration(Period.parse("P3D"));
Session s4 = new Session();
s4.setAssessments(ImmutableList.of(ref3));
s4.setDelay(Period.parse("P24D"));
s4.setStartEventIds(ImmutableList.of("timeline_retrieved"));
s4.setTimeWindows(ImmutableList.of(win4));
s4.setGuid("finalSurveyGuid");
s4.setName("Final Survey");
s4.setPerformanceOrder(SEQUENTIAL);
// Supplemental survey that does not fire for our test user
TimeWindow win5 = new TimeWindow();
win5.setGuid("win5");
win5.setStartTime(LocalTime.parse("00:00"));
win5.setExpiration(Period.parse("PT12H"));
Session s5 = new Session();
s5.setAssessments(ImmutableList.of(ref1));
s5.setStartEventIds(ImmutableList.of("custom:event1"));
s5.setTimeWindows(ImmutableList.of(win5));
s5.setGuid("session5");
s5.setName("Supplemental Survey");
s5.setPerformanceOrder(SEQUENTIAL);
schedule.setSessions(ImmutableList.of(s1, s2, s3, s4, s5));
schedule.setAppId(TEST_APP_ID);
schedule.setGuid(SCHEDULE_GUID);
schedule.setName("Test Schedule");
schedule.setOwnerId("sage-bionetworks");
schedule.setDuration(Period.parse("P4W"));
schedule.setStudyBursts(ImmutableList.of(burst));
schedule.setCreatedOn(CREATED_ON);
schedule.setModifiedOn(MODIFIED_ON);
return schedule;
}
use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.
the class ScheduledSessionTest method canSerialize.
@Test
public void canSerialize() throws Exception {
Session session = new Session();
session.setGuid(SESSION_GUID_1);
session.setStartEventIds(ImmutableList.of("enrollment"));
TimeWindow window = new TimeWindow();
window.setGuid(SESSION_WINDOW_GUID_1);
ScheduledAssessment asmt = new ScheduledAssessment.Builder().withRefKey("ref").withInstanceGuid("instanceGuid").build();
ScheduledSession schSession = new ScheduledSession.Builder().withSession(session).withTimeWindow(window).withStartEventId("timeline_retrieved").withInstanceGuid("instanceGuid").withStartDay(10).withEndDay(13).withDelayTime(Period.parse("PT3H")).withStartTime(LocalTime.parse("17:00")).withExpiration(Period.parse("PT30M")).withPersistent(true).withScheduledAssessment(asmt).withStartDate(CREATED_ON.toLocalDate()).withEndDate(MODIFIED_ON.toLocalDate()).withState(ABANDONED).build();
JsonNode node = BridgeObjectMapper.get().valueToTree(schSession);
assertEquals(node.get("refGuid").textValue(), SESSION_GUID_1);
assertEquals(node.get("instanceGuid").textValue(), "instanceGuid");
assertEquals(node.get("startEventId").textValue(), "timeline_retrieved");
assertEquals(node.get("startDay").intValue(), 10);
assertEquals(node.get("endDay").intValue(), 13);
assertEquals(node.get("startTime").textValue(), "17:00");
assertEquals(node.get("delayTime").textValue(), "PT3H");
assertEquals(node.get("expiration").textValue(), "PT30M");
assertEquals(node.get("timeWindowGuid").textValue(), SESSION_WINDOW_GUID_1);
assertTrue(node.get("persistent").booleanValue());
assertEquals(node.get("startDate").textValue(), CREATED_ON.toLocalDate().toString());
assertEquals(node.get("endDate").textValue(), MODIFIED_ON.toLocalDate().toString());
assertEquals(node.get("state").textValue(), "abandoned");
assertEquals(node.get("type").textValue(), "ScheduledSession");
assertEquals(node.get("assessments").size(), 1);
// Not part of the scheduled session JSON, but carried over to
// initialize the TimelineMetadata record without a lookup.
assertEquals(schSession.getSession(), session);
assertEquals(schSession.getTimeWindow(), window);
}
use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.
the class SchedulerTest method weeklyAppearsAt28Days.
// This behavior was not what I expected
@Test
public void weeklyAppearsAt28Days() {
TimeWindow timeWindow = new TimeWindow();
timeWindow.setGuid(SESSION_WINDOW_GUID_1);
timeWindow.setStartTime(LocalTime.parse("08:00"));
timeWindow.setExpiration(Period.parse("PT12H"));
Session session = new Session();
session.setGuid(SESSION_GUID_1);
session.setStartEventIds(ImmutableList.of("enrollment"));
session.setName("Sessions repeating weekly");
session.setInterval(Period.parse("P1W"));
session.setPerformanceOrder(SEQUENTIAL);
session.setTimeWindows(ImmutableList.of(timeWindow));
session.setAssessments(ImmutableList.of(createAssessmentRef("AAA")));
Schedule2 schedule = new Schedule2();
schedule.setGuid(SCHEDULE_GUID);
schedule.setDuration(Period.parse("P21D"));
schedule.setSessions(ImmutableList.of(session));
Timeline timeline = INSTANCE.calculateTimeline(schedule);
assertEquals(timeline.getSchedule().size(), 3);
// but change the expiration past the last day, and it'll be 3
timeWindow.setExpiration(Period.parse("PT24H"));
timeline = INSTANCE.calculateTimeline(schedule);
assertEquals(timeline.getSchedule().size(), 3);
}
Aggregations