use of org.sagebionetworks.bridge.models.schedules2.AssessmentReference in project BridgeServer2 by Sage-Bionetworks.
the class SchedulerTest method assessmentsCopiedToTimeline.
@Test
public void assessmentsCopiedToTimeline() throws Exception {
// must respect configuration differences and create separate entries in the timeline,
// and line up the $ref values between ScheduledAssessments and AssessmentInfo
// stanzas. We don't have to test the copy factory methods for ScheduledAssessment as
// this is tested separately.
Schedule2 schedule = createSchedule("P1W");
AssessmentReference ref1 = createAssessmentRef(ASSESSMENT_1_GUID);
AssessmentReference ref2 = createAssessmentRef(ASSESSMENT_2_GUID);
AssessmentReference ref3 = createAssessmentRef(ASSESSMENT_2_GUID);
ref3.setColorScheme(new ColorScheme("#111111", "#222222", "#333333", "#444444"));
AssessmentReference ref4 = createAssessmentRef(ASSESSMENT_3_GUID);
AssessmentReference ref5 = createAssessmentRef(ASSESSMENT_3_GUID);
ref5.setLabels(ImmutableList.of(new Label("en", "English")));
AssessmentReference ref6 = createAssessmentRef(ASSESSMENT_4_GUID);
Session session1 = createOneTimeSession(null);
session1.setAssessments(ImmutableList.of(ref1, ref2, ref3, ref4));
Session session2 = createRepeatingSession(null, "P10W");
session2.setAssessments(ImmutableList.of(ref3, ref4, ref5, ref6));
schedule.setSessions(ImmutableList.of(session1, session2));
Timeline timeline = INSTANCE.calculateTimeline(schedule);
assertEquals(timeline.getAssessments().size(), 6);
AssessmentInfo info1 = getByKey(timeline.getAssessments(), "932e4de6932e4de6");
assertEquals(info1.getGuid(), ASSESSMENT_1_GUID);
AssessmentInfo info2 = getByKey(timeline.getAssessments(), "5fa66c675fa66c67");
assertEquals(info2.getGuid(), ASSESSMENT_2_GUID);
assertNotNull(info2.getColorScheme());
AssessmentInfo info3 = getByKey(timeline.getAssessments(), "24df134324df1343");
assertEquals(info3.getGuid(), ASSESSMENT_3_GUID);
assertEquals(info3.getLabel(), "English");
AssessmentInfo info4 = getByKey(timeline.getAssessments(), "fa3150eafa3150ea");
assertEquals(info4.getGuid(), ASSESSMENT_2_GUID);
assertNull(info4.getColorScheme());
AssessmentInfo info5 = getByKey(timeline.getAssessments(), "75705eb175705eb1");
assertEquals(info5.getGuid(), ASSESSMENT_4_GUID);
AssessmentInfo info6 = getByKey(timeline.getAssessments(), "ae40875fae40875f");
assertEquals(info6.getGuid(), ASSESSMENT_3_GUID);
assertEquals(info6.getLabel(), "Assessment 3");
Set<String> infoRefs = timeline.getAssessments().stream().map(AssessmentInfo::getKey).collect(toSet());
Set<String> schAsmtRefs = new HashSet<>();
timeline.getSchedule().stream().forEach(schSession -> {
for (ScheduledAssessment schAsmt : schSession.getAssessments()) {
schAsmtRefs.add(schAsmt.getRefKey());
}
});
assertEquals(infoRefs, schAsmtRefs);
}
use of org.sagebionetworks.bridge.models.schedules2.AssessmentReference in project BridgeServer2 by Sage-Bionetworks.
the class AssessmentInfoTest method canSerialize.
@Test
public void canSerialize() throws Exception {
ConfigResolver resolver = ConfigResolver.INSTANCE;
String url = resolver.url("ws", "/v1/assessments/guid/config");
AssessmentReference ref = new AssessmentReference();
ref.setGuid("guid");
ref.setAppId(TEST_APP_ID);
ref.setIdentifier("identifier");
ref.setRevision(5);
ref.setTitle("title");
ref.setLabels(ImmutableList.of(new Label("en", "English"), new Label("de", "German")));
ref.setMinutesToComplete(10);
ref.setColorScheme(new ColorScheme("#111111", "#222222", "#333333", "#444444"));
AssessmentInfo info = AssessmentInfo.create(ref);
JsonNode node = BridgeObjectMapper.get().valueToTree(info);
assertEquals(node.get("guid").textValue(), "guid");
assertEquals(node.get("appId").textValue(), TEST_APP_ID);
assertEquals(node.get("identifier").textValue(), "identifier");
assertEquals(node.get("revision").intValue(), 5);
assertEquals(node.get("label").textValue(), "English");
assertEquals(node.get("minutesToComplete").intValue(), 10);
assertEquals(node.get("key").textValue(), "b380003bb380003b");
assertEquals(node.get("configUrl").textValue(), url);
assertEquals(node.get("type").textValue(), "AssessmentInfo");
assertEquals(node.get("colorScheme").get("background").textValue(), "#111111");
assertEquals(node.get("colorScheme").get("foreground").textValue(), "#222222");
assertEquals(node.get("colorScheme").get("activated").textValue(), "#333333");
assertEquals(node.get("colorScheme").get("inactivated").textValue(), "#444444");
assertEquals(node.get("colorScheme").get("type").textValue(), "ColorScheme");
// shared ID also generates the correct URL
url = resolver.url("ws", "/v1/sharedassessments/guid/config");
ref.setAppId(SHARED_APP_ID);
info = AssessmentInfo.create(ref);
node = BridgeObjectMapper.get().valueToTree(info);
assertEquals(node.get("configUrl").textValue(), url);
}
use of org.sagebionetworks.bridge.models.schedules2.AssessmentReference in project BridgeServer2 by Sage-Bionetworks.
the class AssessmentInfoTest method serializationHandlesNulls.
@Test
public void serializationHandlesNulls() {
AssessmentReference ref = new AssessmentReference();
AssessmentInfo info = AssessmentInfo.create(ref);
JsonNode node = BridgeObjectMapper.get().valueToTree(info);
assertEquals(node.size(), 2);
assertEquals(node.get("key").textValue(), "0000000000000000");
assertEquals(node.get("type").textValue(), "AssessmentInfo");
}
use of org.sagebionetworks.bridge.models.schedules2.AssessmentReference 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;
}
use of org.sagebionetworks.bridge.models.schedules2.AssessmentReference in project BridgeServer2 by Sage-Bionetworks.
the class SchedulerTest method timelineUsesFallbackValuesWhenLabelsMissing.
@Test
public void timelineUsesFallbackValuesWhenLabelsMissing() {
RequestContext.set(new RequestContext.Builder().withCallerLanguages(ImmutableList.of("zh")).build());
Schedule2 schedule = createSchedule(null);
Session session = createOneTimeSession(null);
session.setLabels(createLabels("de", "German", "es", "Spanish"));
schedule.setSessions(ImmutableList.of(session));
AssessmentReference asmt = createAssessmentRef(ASSESSMENT_1_GUID);
asmt.setLabels(createLabels("ja", "Japanese", "es", "Spanish"));
session.setAssessments(ImmutableList.of(asmt));
Timeline timeline = INSTANCE.calculateTimeline(schedule);
// Similar to above test of mixed values, but note that nothing breaks if there
// is no suitable message (validators prevent this from happening however).
assertEquals(timeline.getLang(), "zh");
assertEquals(timeline.getAssessments().get(0).getLabel(), "Assessment 1");
assertEquals(timeline.getSessions().get(0).getLabel(), "One Time Session");
}
Aggregations