Search in sources :

Example 1 with LoggedIn

use of fi.otavanopisto.security.LoggedIn 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)

Aggregations

UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)1 User (fi.otavanopisto.muikku.schooldata.entity.User)1 UserAddress (fi.otavanopisto.muikku.schooldata.entity.UserAddress)1 UserPhoneNumber (fi.otavanopisto.muikku.schooldata.entity.UserPhoneNumber)1 LoggedIn (fi.otavanopisto.security.LoggedIn)1 OffsetDateTime (java.time.OffsetDateTime)1 Locale (java.util.Locale)1 RequestAction (org.ocpsoft.rewrite.annotation.RequestAction)1