use of fi.otavanopisto.muikku.search.SearchResult in project muikku by otavanopisto.
the class NoPassedCoursesNotificationStrategy method getStudentsToNotify.
public List<SchoolDataIdentifier> getStudentsToNotify() {
Collection<Long> groups = getGroups();
if (groups.isEmpty()) {
return Collections.emptyList();
}
Date thresholdDate = Date.from(OffsetDateTime.now().minusDays(NOTIFICATION_THRESHOLD_DAYS).toInstant());
List<SchoolDataIdentifier> studentIdentifierAlreadyNotified = noPassedCoursesNotificationController.listNotifiedSchoolDataIdentifiersAfter(thresholdDate);
SearchResult searchResult = noPassedCoursesNotificationController.searchActiveStudentIds(groups, FIRST_RESULT + offset, MAX_RESULTS, studentIdentifierAlreadyNotified, thresholdDate);
logger.log(Level.INFO, String.format("%s processing %d/%d", getClass().getSimpleName(), offset, searchResult.getTotalHitCount()));
if ((offset + MAX_RESULTS) > searchResult.getTotalHitCount()) {
offset = 0;
} else {
offset += MAX_RESULTS;
}
List<SchoolDataIdentifier> studentIdentifiers = new ArrayList<>();
for (Map<String, Object> result : searchResult.getResults()) {
String studentId = (String) result.get("id");
if (StringUtils.isBlank(studentId)) {
logger.severe("Could not process user found from search index because it had a null id");
continue;
}
String[] studentIdParts = studentId.split("/", 2);
SchoolDataIdentifier studentIdentifier = studentIdParts.length == 2 ? new SchoolDataIdentifier(studentIdParts[0], studentIdParts[1]) : null;
if (studentIdentifier == null) {
logger.severe(String.format("Could not process user found from search index with id %s", studentId));
continue;
}
User student = userController.findUserByIdentifier(studentIdentifier);
if ((student != null) && isNotifiedStudent(student.getStudyStartDate(), student.getStudyEndDate(), OffsetDateTime.now(), NOTIFICATION_THRESHOLD_DAYS)) {
Long passedCourseCount = noPassedCoursesNotificationController.countPassedCoursesByStudentIdentifierSince(studentIdentifier, Date.from(student.getStudyStartDate().toInstant()));
if (passedCourseCount == null) {
logger.severe(String.format("Could not read course count for %s", studentId));
continue;
} else if (passedCourseCount < MIN_PASSED_COURSES) {
studentIdentifiers.add(studentIdentifier);
}
}
}
return studentIdentifiers;
}
Aggregations