use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.
the class Schedule2Service method preValidationCleanup.
/**
* Set GUIDs on objects that don't have them; clean up event keys or set
* them to null if they're not valid, so they will fail validation.
*/
void preValidationCleanup(Study study, Schedule2 schedule, Consumer<HasGuid> consumer) {
checkNotNull(study);
checkNotNull(schedule);
StudyActivityEventIdsMap map = new StudyActivityEventIdsMap();
map.addCustomEvents(study.getCustomEvents());
map.addStudyBursts(schedule.getStudyBursts());
for (Session session : schedule.getSessions()) {
consumer.accept(session);
session.setSchedule(schedule);
for (TimeWindow window : session.getTimeWindows()) {
consumer.accept(window);
}
List<String> events = session.getStartEventIds().stream().map(s -> formatActivityEventId(map, s)).collect(toList());
session.setStartEventIds(events);
}
}
use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.
the class Schedule2ServiceTest method setsBlankGuidsOnUpdate.
@Test
public void setsBlankGuidsOnUpdate() throws Exception {
App app = App.create();
when(mockAppService.getApp(TEST_APP_ID)).thenReturn(app);
when(mockOrganizationService.getOrganizationOpt(TEST_APP_ID, TEST_ORG_ID)).thenReturn(Optional.of(Organization.create()));
Schedule2 existing = new Schedule2();
existing.setAppId(TEST_APP_ID);
existing.setOwnerId(TEST_ORG_ID);
existing.setCreatedOn(CREATED_ON);
Schedule2 schedule = Schedule2Test.createValidSchedule();
Session session1 = SessionTest.createValidSession();
Session session2 = SessionTest.createValidSession();
session2.setGuid(null);
TimeWindow window1 = SessionTest.createValidSession().getTimeWindows().get(0);
TimeWindow window2 = SessionTest.createValidSession().getTimeWindows().get(0);
window2.setGuid(null);
window2.setStartTime(LocalTime.parse("14:00"));
window2.setExpiration(Period.parse("PT6H"));
session1.setTimeWindows(ImmutableList.of(window1, window2));
schedule.setSessions(ImmutableList.of(session1, session2));
// test valid schedule has GUID set on all the fields. for this test,
// let's set something else and verify that only blank GUID fields are set,
// allowing for copies and new items to be added to the schedule.
doReturn("otherGuid").when(service).generateGuid();
Study study = Study.create();
study.setAppId(TEST_APP_ID);
study.setIdentifier(TEST_STUDY_ID);
when(mockDao.updateSchedule(any())).thenReturn(schedule);
service.updateSchedule(study, existing, schedule);
assertEquals(schedule.getSessions().get(0).getGuid(), SESSION_GUID_1);
assertEquals(schedule.getSessions().get(0).getTimeWindows().get(0).getGuid(), SESSION_WINDOW_GUID_1);
assertEquals(schedule.getSessions().get(0).getTimeWindows().get(1).getGuid(), "otherGuid");
assertEquals(schedule.getSessions().get(1).getGuid(), "otherGuid");
assertEquals(schedule.getSessions().get(1).getTimeWindows().get(0).getGuid(), SESSION_WINDOW_GUID_1);
}
use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.
the class SessionInfo method createTimelineEntry.
public static final SessionInfo createTimelineEntry(Session session) {
List<String> languages = RequestContext.get().getCallerLanguages();
Label label = selectByLang(session.getLabels(), languages, new Label("", session.getName()));
int min = 0;
for (AssessmentReference ref : session.getAssessments()) {
if (ref.getMinutesToComplete() != null) {
min += ref.getMinutesToComplete();
}
}
SessionInfo info = new SessionInfo();
info.guid = session.getGuid();
info.label = label.getValue();
info.symbol = session.getSymbol();
info.startEventId = Iterables.getFirst(session.getStartEventIds(), null);
info.performanceOrder = session.getPerformanceOrder();
info.timeWindowGuids = session.getTimeWindows().stream().map(TimeWindow::getGuid).collect(toList());
info.notifications = session.getNotifications().stream().map(not -> NotificationInfo.create(not, languages)).collect(toList());
if (min > 0) {
info.minutesToComplete = min;
}
return info;
}
use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.
the class SessionValidator method validateTimeWindowOverlaps.
private void validateTimeWindowOverlaps(Errors errors, Session session) {
// no windows to overlap, or session doesn't repeat
if (session.getTimeWindows().size() < 2) {
return;
}
// windows are not required to be in time order, so sort them
List<TimeWindow> windowsInOrder = Lists.newArrayList(session.getTimeWindows());
windowsInOrder.sort(START_TIME_COMPARATOR);
long minuteInDay = 0;
for (TimeWindow window : windowsInOrder) {
LocalTime startTime = window.getStartTime();
long winStartMinute = localTimeInMinutes(startTime);
if (winStartMinute < minuteInDay) {
addOverlapError(errors, session, window);
}
minuteInDay = winStartMinute + periodInMinutes(window.getExpiration());
}
// with the first window in that sequence
if (session.getInterval() != null) {
TimeWindow longestWindow = longestTimeWindow(session);
long intervalInMinutes = periodInMinutes(session.getInterval());
long windowInMinutes = localTimeInMinutes(longestWindow.getStartTime()) + periodInMinutes(longestWindow.getExpiration());
if (windowInMinutes > intervalInMinutes) {
addOverlapError(errors, session, longestWindow);
}
}
}
use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.
the class SessionValidatorTest method timeWindows_expirationPlusDelayExceedsScheduleDuration.
@Test
public void timeWindows_expirationPlusDelayExceedsScheduleDuration() {
// Schedule duration is 8 weeks.
Session session = createValidSession();
TimeWindow timeWindow = new TimeWindow();
timeWindow.setGuid(SESSION_GUID_1);
timeWindow.setStartTime(LocalTime.parse("08:00"));
timeWindow.setExpiration(Period.parse("P4W"));
session.setTimeWindows(ImmutableList.of(timeWindow));
session.setInterval(Period.parse("P4W"));
session.setDelay(Period.parse("P4WT1H"));
assertValidatorMessage(INSTANCE, session, TIME_WINDOWS_FIELD + "[0].expiration", WINDOW_EXPIRATION_AFTER_SCHEDULE_DURATION);
}
Aggregations