Search in sources :

Example 46 with User

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;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) WorkspaceAssessment(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment) User(fi.otavanopisto.muikku.schooldata.entity.User) OffsetDateTime(java.time.OffsetDateTime) WorkspaceAssessmentRequest(fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessmentRequest) ArrayList(java.util.ArrayList)

Example 47 with User

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;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) User(fi.otavanopisto.muikku.schooldata.entity.User) ArrayList(java.util.ArrayList) SearchResult(fi.otavanopisto.muikku.search.SearchResult) Date(java.util.Date)

Example 48 with User

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();
    }
}
Also used : EnvironmentUser(fi.otavanopisto.muikku.model.users.EnvironmentUser) EnvironmentUser(fi.otavanopisto.muikku.model.users.EnvironmentUser) User(fi.otavanopisto.muikku.schooldata.entity.User) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) PostConstruct(javax.annotation.PostConstruct)

Aggregations

User (fi.otavanopisto.muikku.schooldata.entity.User)48 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)35 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)30 Path (javax.ws.rs.Path)21 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)18 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)17 ArrayList (java.util.ArrayList)16 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)14 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)14 EnvironmentUser (fi.otavanopisto.muikku.model.users.EnvironmentUser)12 GET (javax.ws.rs.GET)12 HashMap (java.util.HashMap)11 WorkspaceUser (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser)10 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)9 Date (java.util.Date)8 GradingScale (fi.otavanopisto.muikku.schooldata.entity.GradingScale)7 GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)7 WorkspaceGradingScale (fi.otavanopisto.muikku.plugins.evaluation.rest.model.WorkspaceGradingScale)6 PUT (javax.ws.rs.PUT)5 RestAssessment (fi.otavanopisto.muikku.plugins.evaluation.rest.model.RestAssessment)4