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;
}
Aggregations