Search in sources :

Example 36 with SchoolDataIdentifier

use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.

the class AssesmentRequestNotificationController method listNotifiedSchoolDataIdentifiers.

public List<SchoolDataIdentifier> listNotifiedSchoolDataIdentifiers() {
    List<SchoolDataIdentifier> results = new ArrayList<>();
    List<AssesmentRequestNotification> assessmentRequestNotifications = assessmentRequestNotificationDAO.listAll();
    for (AssesmentRequestNotification assessmentRequestNotification : assessmentRequestNotifications) {
        results.add(SchoolDataIdentifier.fromId(assessmentRequestNotification.getStudentIdentifier()));
    }
    return results;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) AssesmentRequestNotification(fi.otavanopisto.muikku.plugins.timed.notifications.model.AssesmentRequestNotification) ArrayList(java.util.ArrayList)

Example 37 with SchoolDataIdentifier

use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.

the class NoPassedCoursesNotificationController method listNotifiedSchoolDataIdentifiersAfter.

public List<SchoolDataIdentifier> listNotifiedSchoolDataIdentifiersAfter(Date date) {
    List<SchoolDataIdentifier> results = new ArrayList<>();
    List<NoPassedCoursesNotification> noPassedCoursesNotifications = noPassedCoursesNotificationDAO.listByDateAfter(date);
    for (NoPassedCoursesNotification noPassedCoursesNotification : noPassedCoursesNotifications) {
        results.add(SchoolDataIdentifier.fromId(noPassedCoursesNotification.getStudentIdentifier()));
    }
    return results;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) ArrayList(java.util.ArrayList) NoPassedCoursesNotification(fi.otavanopisto.muikku.plugins.timed.notifications.model.NoPassedCoursesNotification)

Example 38 with SchoolDataIdentifier

use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.

the class NotificationController method sendNotification.

public void sendNotification(String category, String subject, String content, UserEntity recipient, SchoolDataIdentifier recipientIdentifier, String notificationType) {
    HashMap<String, Object> map = new HashMap<>();
    map.put("notificationType", notificationType);
    map.put("recipient", recipient.getId());
    map.put("recipientIdentifier", recipientIdentifier.toId());
    map.put("time", String.valueOf(System.currentTimeMillis()));
    UserEntity guidanceCounselor = null;
    SchoolDataIdentifier userIdentifier = new SchoolDataIdentifier(recipient.getDefaultIdentifier(), recipient.getDefaultSchoolDataSource().getIdentifier());
    List<UserGroupEntity> userGroupEntities = userGroupEntityController.listUserGroupsByUserIdentifier(userIdentifier);
    // #3089: An awkward workaround to use the latest guidance group based on its identifier. Assumes a larger
    // identifier means a more recent entity. A more proper fix would be to sync group creation dates from
    // Pyramus and include them in the Elastic index. Then again, user groups would have to be refactored
    // entirely, as Pyramus handles group members as students (one study programme) while Muikku handles
    // them as user entities (all study programmes)...
    userGroupEntities.sort(new Comparator<UserGroupEntity>() {

        public int compare(UserGroupEntity o1, UserGroupEntity o2) {
            long l1 = NumberUtils.toLong(StringUtils.substringAfterLast(o1.getIdentifier(), "-"), -1);
            long l2 = NumberUtils.toLong(StringUtils.substringAfterLast(o2.getIdentifier(), "-"), -1);
            return (int) (l2 - l1);
        }
    });
    userGroupEntities: for (UserGroupEntity userGroupEntity : userGroupEntities) {
        UserGroup userGroup = userGroupController.findUserGroup(userGroupEntity);
        if (userGroup.isGuidanceGroup()) {
            List<GroupUser> groupUsers = userGroupController.listUserGroupStaffMembers(userGroup);
            for (GroupUser groupUser : groupUsers) {
                User user = userGroupController.findUserByGroupUser(groupUser);
                guidanceCounselor = userEntityController.findUserEntityByUser(user);
                break userGroupEntities;
            }
        }
    }
    LogProvider provider = getProvider(LOG_PROVIDER);
    if (provider != null) {
        provider.log(COLLECTION_NAME, map);
    }
    if (isDryRun()) {
        String recipientEmail = getRecipientEmail();
        if (recipientEmail == null) {
            logger.log(Level.INFO, String.format("Sending notification %s - %s to %s", category, subject, recipient.getDefaultIdentifier()));
        } else {
            mailer.sendMail(MailType.HTML, Arrays.asList(recipientEmail), subject, "SENT TO: " + recipient.getDefaultIdentifier() + "<br/><br/><br/>" + content);
        }
    } else {
        ArrayList<UserEntity> recipients = new ArrayList<>();
        recipients.add(recipient);
        if (guidanceCounselor != null) {
            recipients.add(guidanceCounselor);
        }
        String studentEmail = userEmailEntityController.getUserDefaultEmailAddress(recipient, Boolean.FALSE);
        if (studentEmail != null) {
            mailer.sendMail(MailType.HTML, Arrays.asList(studentEmail), subject, content);
        } else {
            logger.log(Level.WARNING, String.format("Cannot send email notification to student %s because no email address was found", recipient.getDefaultIdentifier()));
        }
        communicatorController.postMessage(recipient, category, subject, content, recipients);
    }
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) User(fi.otavanopisto.muikku.schooldata.entity.User) GroupUser(fi.otavanopisto.muikku.schooldata.entity.GroupUser) GroupUser(fi.otavanopisto.muikku.schooldata.entity.GroupUser) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UserGroupEntity(fi.otavanopisto.muikku.model.users.UserGroupEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) UserGroup(fi.otavanopisto.muikku.schooldata.entity.UserGroup) LogProvider(fi.otavanopisto.muikku.plugins.commonlog.LogProvider) ArrayList(java.util.ArrayList) List(java.util.List)

Example 39 with SchoolDataIdentifier

use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.

the class ProfileBackingBean method init.

@RequestAction
@LoggedIn
public String init() {
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    User user = userController.findUserByDataSourceAndIdentifier(sessionController.getLoggedUserSchoolDataSource(), sessionController.getLoggedUserIdentifier());
    List<UserAddress> userAddresses = userController.listUserAddresses(user);
    List<UserPhoneNumber> userPhoneNumbers = userController.listUserPhoneNumbers(user);
    displayName = user.getNickName() == null ? user.getDisplayName() : String.format("%s %s (%s)", user.getNickName(), user.getLastName(), user.getStudyProgrammeName());
    studyStartDate = user.getStudyStartDate();
    studyTimeEnd = user.getStudyTimeEnd();
    studyTimeLeftStr = "";
    if (studyTimeEnd != null) {
        OffsetDateTime now = OffsetDateTime.now();
        Locale locale = sessionController.getLocale();
        if (now.isBefore(studyTimeEnd)) {
            long studyTimeLeftYears = now.until(studyTimeEnd, ChronoUnit.YEARS);
            now = now.plusYears(studyTimeLeftYears);
            if (studyTimeLeftYears > 0) {
                studyTimeLeftStr += studyTimeLeftYears + " " + localeController.getText(locale, "plugin.profile.studyTimeEndShort.y");
            }
            long studyTimeLeftMonths = now.until(studyTimeEnd, ChronoUnit.MONTHS);
            now = now.plusMonths(studyTimeLeftMonths);
            if (studyTimeLeftMonths > 0) {
                if (studyTimeLeftStr.length() > 0)
                    studyTimeLeftStr += " ";
                studyTimeLeftStr += studyTimeLeftMonths + " " + localeController.getText(locale, "plugin.profile.studyTimeEndShort.m");
            }
            long studyTimeLeftDays = now.until(studyTimeEnd, ChronoUnit.DAYS);
            now = now.plusDays(studyTimeLeftDays);
            if (studyTimeLeftDays > 0) {
                if (studyTimeLeftStr.length() > 0)
                    studyTimeLeftStr += " ";
                studyTimeLeftStr += studyTimeLeftDays + " " + localeController.getText(locale, "plugin.profile.studyTimeEndShort.d");
            }
        }
    }
    addresses = new ArrayList<>();
    for (UserAddress userAddress : userAddresses) {
        addresses.add(String.format("%s %s %s %s", userAddress.getStreet(), userAddress.getPostalCode(), userAddress.getCity(), userAddress.getCountry()));
    }
    phoneNumbers = new ArrayList<>();
    for (UserPhoneNumber userPhoneNumber : userPhoneNumbers) {
        phoneNumbers.add(userPhoneNumber.getNumber());
    }
    SchoolDataIdentifier identifier = new SchoolDataIdentifier(userEntity.getDefaultIdentifier(), userEntity.getDefaultSchoolDataSource().getIdentifier());
    emails = userEmailEntityController.getUserEmailAddresses(identifier);
    return null;
}
Also used : Locale(java.util.Locale) SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) User(fi.otavanopisto.muikku.schooldata.entity.User) OffsetDateTime(java.time.OffsetDateTime) UserAddress(fi.otavanopisto.muikku.schooldata.entity.UserAddress) UserPhoneNumber(fi.otavanopisto.muikku.schooldata.entity.UserPhoneNumber) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction) LoggedIn(fi.otavanopisto.security.LoggedIn)

Example 40 with SchoolDataIdentifier

use of fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier in project muikku by otavanopisto.

the class VopsLister method processTransferCredits.

private VopsRESTModel.VopsEntry processTransferCredits(Subject subject, int courseNumber) {
    for (TransferCredit transferCredit : transferCredits) {
        boolean subjectsMatch = Objects.equals(transferCredit.getSubjectIdentifier(), new SchoolDataIdentifier(subject.getIdentifier(), subject.getSchoolDataSource()));
        boolean courseNumbersMatch = Objects.equals(transferCredit.getCourseNumber(), courseNumber);
        if (subjectsMatch && courseNumbersMatch) {
            String grade = "";
            GradingScaleItem gradingScaleItem = null;
            Mandatority mandatority = Mandatority.MANDATORY;
            if (transferCredit.getOptionality() == Optionality.OPTIONAL) {
                mandatority = Mandatority.UNSPECIFIED_OPTIONAL;
            }
            if (transferCredit.getGradeIdentifier() != null && transferCredit.getGradingScaleIdentifier() != null) {
                gradingScaleItem = findGradingScaleItemCached(transferCredit.getGradingScaleIdentifier(), transferCredit.getGradeIdentifier());
                String gradeName = gradingScaleItem.getName();
                if (!StringUtils.isBlank(gradeName)) {
                    if (gradeName.length() > 2)
                        grade = gradeName.substring(0, 2);
                    else
                        grade = gradeName;
                }
            }
            numCourses++;
            if (mandatority == Mandatority.MANDATORY) {
                numMandatoryCourses++;
            }
            return new VopsRESTModel.VopsItem(courseNumber, CourseCompletionState.ASSESSED, (String) null, mandatority, grade, false, transferCredit.getCourseName(), "");
        }
    }
    return null;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) Mandatority(fi.otavanopisto.muikku.plugins.transcriptofrecords.rest.Mandatority) GradingScaleItem(fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem) TransferCredit(fi.otavanopisto.muikku.schooldata.entity.TransferCredit)

Aggregations

SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)130 Path (javax.ws.rs.Path)63 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)59 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)58 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)53 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)50 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)48 ArrayList (java.util.ArrayList)38 GET (javax.ws.rs.GET)36 User (fi.otavanopisto.muikku.schooldata.entity.User)30 HashMap (java.util.HashMap)19 Workspace (fi.otavanopisto.muikku.schooldata.entity.Workspace)13 SearchResult (fi.otavanopisto.muikku.search.SearchResult)13 WorkspaceUser (fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser)12 Date (java.util.Date)11 POST (javax.ws.rs.POST)11 GradingScaleItem (fi.otavanopisto.muikku.schooldata.entity.GradingScaleItem)10 WorkspaceAssessment (fi.otavanopisto.muikku.schooldata.entity.WorkspaceAssessment)10 HashSet (java.util.HashSet)9 PUT (javax.ws.rs.PUT)9