use of fi.otavanopisto.muikku.schooldata.entity.UserPhoneNumber in project muikku by otavanopisto.
the class UserRESTService method listStudentPhoneNumbers.
@GET
@Path("/students/{ID}/phoneNumbers")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listStudentPhoneNumbers(@PathParam("ID") String id) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.UNAUTHORIZED).build();
}
SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(id);
if (studentIdentifier == null) {
return Response.status(Response.Status.BAD_REQUEST).entity(String.format("Invalid studentIdentifier %s", id)).build();
}
UserEntity studentEntity = userEntityController.findUserEntityByUserIdentifier(studentIdentifier);
if (studentEntity == null) {
return Response.status(Response.Status.BAD_REQUEST).entity(String.format("Could not find user entity for identifier %s", id)).build();
}
if (!studentEntity.getId().equals(sessionController.getLoggedUserEntity().getId())) {
if (!sessionController.hasEnvironmentPermission(MuikkuPermissions.LIST_STUDENT_PHONE_NUMBERS)) {
return Response.status(Status.FORBIDDEN).build();
}
}
List<UserPhoneNumber> phoneNumbers = userController.listUserPhoneNumbers(studentIdentifier);
Collections.sort(phoneNumbers, new Comparator<UserPhoneNumber>() {
@Override
public int compare(UserPhoneNumber o1, UserPhoneNumber o2) {
return o1.getDefaultNumber() ? -1 : o2.getDefaultNumber() ? 1 : 0;
}
});
return Response.ok(createRestModel(phoneNumbers.toArray(new UserPhoneNumber[0]))).build();
}
use of fi.otavanopisto.muikku.schooldata.entity.UserPhoneNumber 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;
}
use of fi.otavanopisto.muikku.schooldata.entity.UserPhoneNumber in project muikku by otavanopisto.
the class PyramusUserSchoolDataBridge method listUserPhoneNumbers.
@Override
public List<UserPhoneNumber> listUserPhoneNumbers(SchoolDataIdentifier userIdentifier) {
if (!StringUtils.equals(userIdentifier.getDataSource(), getSchoolDataSource())) {
throw new SchoolDataBridgeInternalException(String.format("Could not list phone numbers for user from school data source %s", userIdentifier.getDataSource()));
}
PhoneNumber[] phoneNumbers = null;
Long pyramusStudentId = identifierMapper.getPyramusStudentId(userIdentifier.getIdentifier());
if (pyramusStudentId != null) {
phoneNumbers = pyramusClient.get(String.format("/students/students/%d/phoneNumbers", pyramusStudentId), PhoneNumber[].class);
if (phoneNumbers == null) {
return Collections.emptyList();
}
} else {
Long pyramusStaffId = identifierMapper.getPyramusStaffId(userIdentifier.getIdentifier());
if (pyramusStaffId != null) {
phoneNumbers = pyramusClient.get(String.format("/staff/members/%d/phoneNumbers", pyramusStaffId), PhoneNumber[].class);
if (phoneNumbers == null) {
return Collections.emptyList();
}
}
}
List<UserPhoneNumber> result = new ArrayList<>();
for (PhoneNumber phoneNumber : phoneNumbers) {
ContactType contactType = phoneNumber.getContactTypeId() != null ? pyramusClient.get(String.format("/common/contactTypes/%d", phoneNumber.getContactTypeId()), ContactType.class) : null;
result.add(entityFactory.createEntity(userIdentifier, phoneNumber, contactType));
}
return result;
}
Aggregations