use of fi.otavanopisto.muikku.schooldata.entity.User in project muikku by otavanopisto.
the class AssessmentRequestNotificationStrategy method getStudentIdentifiersWithoutEvaluationActivity.
private List<SchoolDataIdentifier> getStudentIdentifiersWithoutEvaluationActivity(SearchResult searchResult) {
List<SchoolDataIdentifier> studentIdentifiers = new ArrayList<>();
for (Map<String, Object> result : searchResult.getResults()) {
// Convert the search result id into SchoolDataIdentifier. Skip student if this fails.
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;
}
// Find the student by SchoolDataIdentifier
User student = userController.findUserByIdentifier(studentIdentifier);
if (student != null) {
if (student.getStudyStartDate() == null || student.getStudyEndDate() != null) {
continue;
}
// Students that have started their studies in the last 60 days should not be notified
// (given searchResult should not even contain these but let's check it once more, just in case)
OffsetDateTime thresholdDateTime = OffsetDateTime.now().minusDays(NOTIFICATION_THRESHOLD_DAYS);
if (student.getStudyStartDate().isAfter(thresholdDateTime)) {
logger.severe(String.format("Skipping student id %s that just started studies", studentId));
continue;
}
// Check if student has made any assessment requests. If they have, they don't need to be notified
WorkspaceAssessmentRequest latestRequest = gradingController.findLatestAssessmentRequestByIdentifier(studentIdentifier);
if (latestRequest != null) {
continue;
}
// Check if student has any workspace assessments. If they have, they don't need to be notified
WorkspaceAssessment latestAssessment = gradingController.findLatestWorkspaceAssessmentByIdentifier(studentIdentifier);
if (latestAssessment != null) {
continue;
}
// By this point, we can be certain that the student has to be notified
studentIdentifiers.add(studentIdentifier);
}
}
return studentIdentifiers;
}
use of fi.otavanopisto.muikku.schooldata.entity.User 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;
}
use of fi.otavanopisto.muikku.schooldata.entity.User in project muikku by otavanopisto.
the class SessionBackingBean method init.
@PostConstruct
public void init() {
loggedUserRoleArchetype = null;
loggedUserName = null;
testsRunning = StringUtils.equals("true", System.getProperty("tests.running"));
bugsnagApiKey = systemSettingsController.getSetting("bugsnagApiKey");
bugsnagEnabled = StringUtils.isNotBlank(bugsnagApiKey);
loggedUserId = null;
loggedUser = null;
if (sessionController.isLoggedIn()) {
UserEntity loggedUser = sessionController.getLoggedUserEntity();
if (loggedUser != null) {
String activeSchoolDataSource = sessionController.getLoggedUserSchoolDataSource();
String activeUserIdentifier = sessionController.getLoggedUserIdentifier();
EnvironmentUser environmentUser = environmentUserController.findEnvironmentUserByUserEntity(loggedUser);
if ((environmentUser != null) && (environmentUser.getRole() != null)) {
loggedUserRoleArchetype = environmentUser.getRole().getArchetype();
}
User user = userController.findUserByDataSourceAndIdentifier(activeSchoolDataSource, activeUserIdentifier);
if (user != null) {
if (!loggedUserRoleArchetype.equals(EnvironmentRoleArchetype.STUDENT)) {
loggedUserName = String.format("%s %s (%s)", user.getFirstName(), user.getLastName(), resolveLoggedUserRoleText());
} else if (user.getNickName() != null) {
loggedUserName = String.format("%s %s (%s)", user.getNickName(), user.getLastName(), user.getStudyProgrammeName());
} else {
loggedUserName = user.getDisplayName();
}
}
}
this.loggedUserId = sessionController.getLoggedUserEntity().getId();
this.loggedUser = sessionController.getLoggedUser().toId();
}
}
Aggregations