Search in sources :

Example 6 with TimeWindow

use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.

the class SchedulerTest method eachTimeWindowCreatesAScheduledSession.

@Test
public void eachTimeWindowCreatesAScheduledSession() {
    Schedule2 schedule = createSchedule("P1W");
    Session session = createOneTimeSession(null);
    TimeWindow window = new TimeWindow();
    window.setGuid(SESSION_GUID_2);
    window.setStartTime(LocalTime.parse("14:00"));
    session.getTimeWindows().add(window);
    schedule.getSessions().add(session);
    Timeline timeline = INSTANCE.calculateTimeline(schedule);
    assertEquals(timeline.getSchedule().size(), 2);
    assertEquals(timeline.getSchedule().get(0).getStartTime(), LocalTime.parse("08:00"));
    assertEquals(timeline.getSchedule().get(1).getStartTime(), LocalTime.parse("14:00"));
    assertEquals(timeline.getSessions().size(), 1);
    assertEquals(timeline.getAssessments().size(), 1);
}
Also used : Schedule2(org.sagebionetworks.bridge.models.schedules2.Schedule2) TimeWindow(org.sagebionetworks.bridge.models.schedules2.TimeWindow) Session(org.sagebionetworks.bridge.models.schedules2.Session) Test(org.testng.annotations.Test)

Example 7 with TimeWindow

use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.

the class SchedulerTest method createRepeatingSession.

private Session createRepeatingSession(String delay, String interval) {
    if (interval == null) {
        interval = "P1D";
    }
    Session session = new Session();
    session.setStartEventIds(ImmutableList.of("enrollment"));
    if (delay != null) {
        session.setDelay(Period.parse(delay));
    }
    session.setInterval(Period.parse(interval));
    session.setAssessments(ImmutableList.of(createAssessmentRef(ASSESSMENT_2_GUID)));
    session.setGuid(SESSION_GUID_1);
    session.setName("Repeating Session");
    TimeWindow window = new TimeWindow();
    window.setGuid(SESSION_WINDOW_GUID_1);
    window.setStartTime(LocalTime.parse("08:00"));
    window.setExpiration(Period.parse("PT8H"));
    session.getTimeWindows().add(window);
    return session;
}
Also used : TimeWindow(org.sagebionetworks.bridge.models.schedules2.TimeWindow) Session(org.sagebionetworks.bridge.models.schedules2.Session)

Example 8 with TimeWindow

use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.

the class SchedulerTest method createOneTimeSession.

private Session createOneTimeSession(String delay) {
    Session session = new Session();
    session.setStartEventIds(ImmutableList.of("enrollment"));
    if (delay != null) {
        session.setDelay(Period.parse(delay));
    }
    session.setAssessments(ImmutableList.of(createAssessmentRef(ASSESSMENT_1_GUID)));
    session.setGuid(SESSION_GUID_3);
    session.setName("One Time Session");
    TimeWindow window = new TimeWindow();
    window.setGuid(SESSION_WINDOW_GUID_2);
    window.setStartTime(LocalTime.parse("08:00"));
    window.setExpiration(Period.parse("PT8H"));
    session.getTimeWindows().add(window);
    return session;
}
Also used : TimeWindow(org.sagebionetworks.bridge.models.schedules2.TimeWindow) Session(org.sagebionetworks.bridge.models.schedules2.Session)

Example 9 with TimeWindow

use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.

the class SchedulerTest method multipleEventIdsGenerateSeparateScheduledSessions.

@Test
public void multipleEventIdsGenerateSeparateScheduledSessions() {
    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", "timeline_retrieved"));
    session.setName("Sessions repeating weekly");
    session.setInterval(Period.parse("P1D"));
    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("P2D"));
    schedule.setSessions(ImmutableList.of(session));
    Timeline timeline = INSTANCE.calculateTimeline(schedule);
    assertEquals(timeline.getSchedule().size(), 4);
    assertEquals(timeline.getSchedule().stream().map(ScheduledSession::getInstanceGuid).collect(toSet()).size(), 4);
    ScheduledSession schSession = timeline.getSchedule().get(0);
    assertEquals(schSession.getStartEventId(), "enrollment");
    assertEquals(schSession.getRefGuid(), SESSION_GUID_1);
    assertEquals(schSession.getStartDay(), Integer.valueOf(0));
    schSession = timeline.getSchedule().get(1);
    assertEquals(schSession.getStartEventId(), "timeline_retrieved");
    assertEquals(schSession.getRefGuid(), SESSION_GUID_1);
    assertEquals(schSession.getStartDay(), Integer.valueOf(0));
    schSession = timeline.getSchedule().get(2);
    assertEquals(schSession.getStartEventId(), "enrollment");
    assertEquals(schSession.getRefGuid(), SESSION_GUID_1);
    assertEquals(schSession.getStartDay(), Integer.valueOf(1));
    schSession = timeline.getSchedule().get(3);
    assertEquals(schSession.getStartEventId(), "timeline_retrieved");
    assertEquals(schSession.getRefGuid(), SESSION_GUID_1);
    assertEquals(schSession.getStartDay(), Integer.valueOf(1));
}
Also used : Schedule2(org.sagebionetworks.bridge.models.schedules2.Schedule2) TimeWindow(org.sagebionetworks.bridge.models.schedules2.TimeWindow) Session(org.sagebionetworks.bridge.models.schedules2.Session) Test(org.testng.annotations.Test)

Example 10 with TimeWindow

use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.

the class SchedulerTest method createComplexSchedule.

private Schedule2 createComplexSchedule() {
    Schedule2 schedule = new Schedule2();
    schedule.setModifiedOn(MODIFIED_ON);
    schedule.setGuid(SCHEDULE_GUID);
    schedule.setName("Test");
    schedule.setPublished(true);
    schedule.setDuration(Period.parse("P52W"));
    Session session1 = new Session();
    session1.setGuid(SESSION_GUID_1);
    session1.setName("Session #1");
    session1.setStartEventIds(ImmutableList.of("activities_retrieved"));
    session1.setInterval(Period.parse("P2D"));
    session1.setPerformanceOrder(SEQUENTIAL);
    session1.setAssessments(ImmutableList.of(createAssessmentRef(ASSESSMENT_1_GUID)));
    TimeWindow tw = new TimeWindow();
    tw.setGuid(SESSION_WINDOW_GUID_1);
    tw.setStartTime(LocalTime.parse("08:00"));
    tw.setExpiration(Period.parse("PT8H"));
    session1.setTimeWindows(ImmutableList.of(tw));
    Session session2 = new Session();
    session2.setGuid(SESSION_GUID_2);
    session2.setName("Session #2");
    session2.setStartEventIds(ImmutableList.of("enrollment"));
    session2.setInterval(Period.parse("P1D"));
    session2.setPerformanceOrder(SEQUENTIAL);
    session2.setAssessments(ImmutableList.of(createAssessmentRef(ASSESSMENT_2_GUID)));
    TimeWindow tw1 = new TimeWindow();
    tw1.setGuid(SESSION_WINDOW_GUID_2);
    tw1.setStartTime(LocalTime.parse("08:00"));
    tw1.setExpiration(Period.parse("PT4H"));
    TimeWindow tw2 = new TimeWindow();
    tw2.setGuid(SESSION_WINDOW_GUID_3);
    tw2.setStartTime(LocalTime.parse("12:00"));
    tw2.setExpiration(Period.parse("PT4H"));
    tw2.setPersistent(true);
    TimeWindow tw3 = new TimeWindow();
    tw3.setGuid(SESSION_WINDOW_GUID_4);
    tw3.setStartTime(LocalTime.parse("16:00"));
    tw3.setExpiration(Period.parse("PT4H"));
    session2.setTimeWindows(ImmutableList.of(tw1, tw2, tw3));
    AssessmentReference as1 = new AssessmentReference();
    as1.setGuid(ASSESSMENT_1_GUID);
    as1.setAppId("shared");
    as1.setIdentifier("shared-assessment");
    as1.setTitle("A shared assessment");
    as1.setLabels(ImmutableList.of(new Label("en", "This is a test")));
    as1.setMinutesToComplete(3);
    as1.setColorScheme(new ColorScheme("#ff33ff", null, null, null));
    AssessmentReference as2 = new AssessmentReference();
    as2.setGuid(ASSESSMENT_2_GUID);
    as2.setAppId("local");
    as2.setIdentifier("local-assessment");
    as2.setTitle("A local assessment");
    as2.setMinutesToComplete(3);
    session2.setAssessments(ImmutableList.of(as1, as2));
    schedule.setSessions(ImmutableList.of(session2, session1));
    return schedule;
}
Also used : Schedule2(org.sagebionetworks.bridge.models.schedules2.Schedule2) Label(org.sagebionetworks.bridge.models.Label) ColorScheme(org.sagebionetworks.bridge.models.assessments.ColorScheme) AssessmentReference(org.sagebionetworks.bridge.models.schedules2.AssessmentReference) TimeWindow(org.sagebionetworks.bridge.models.schedules2.TimeWindow) Session(org.sagebionetworks.bridge.models.schedules2.Session)

Aggregations

TimeWindow (org.sagebionetworks.bridge.models.schedules2.TimeWindow)23 Session (org.sagebionetworks.bridge.models.schedules2.Session)21 Test (org.testng.annotations.Test)13 Schedule2 (org.sagebionetworks.bridge.models.schedules2.Schedule2)8 SessionTest (org.sagebionetworks.bridge.models.schedules2.SessionTest)6 SessionTest.createValidSession (org.sagebionetworks.bridge.models.schedules2.SessionTest.createValidSession)6 AssessmentReference (org.sagebionetworks.bridge.models.schedules2.AssessmentReference)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 LocalTime (org.joda.time.LocalTime)2 RequestContext (org.sagebionetworks.bridge.RequestContext)2 Label (org.sagebionetworks.bridge.models.Label)2 StudyBurst (org.sagebionetworks.bridge.models.schedules2.StudyBurst)2 Study (org.sagebionetworks.bridge.models.studies.Study)2 AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)1 BatchGetAssetsHistoryRequest (com.google.cloud.asset.v1.BatchGetAssetsHistoryRequest)1 BatchGetAssetsHistoryResponse (com.google.cloud.asset.v1.BatchGetAssetsHistoryResponse)1 ContentType (com.google.cloud.asset.v1.ContentType)1