Search in sources :

Example 1 with UserEmail

use of fi.otavanopisto.muikku.schooldata.entity.UserEmail in project muikku by otavanopisto.

the class PyramusUserSchoolDataBridge method listUserEmailsByUserIdentifier.

@Override
public List<UserEmail> listUserEmailsByUserIdentifier(String userIdentifier) {
    Email[] emails = null;
    Long studentId = identifierMapper.getPyramusStudentId(userIdentifier);
    if (studentId != null) {
        emails = pyramusClient.get(String.format("/students/students/%d/emails", studentId), Email[].class);
    } else {
        Long staffId = identifierMapper.getPyramusStaffId(userIdentifier);
        if (staffId != null) {
            emails = pyramusClient.get(String.format("/staff/members/%d/emails", staffId), Email[].class);
        } else {
            logger.severe(String.format("PyramusUserSchoolDataBridge.listUserEmailsByUserIdentifier malformed user identifier %s\n%s", userIdentifier, ExceptionUtils.getStackTrace(new Throwable())));
        }
    }
    if (emails != null) {
        List<UserEmail> result = new ArrayList<>(emails.length);
        for (Email email : emails) {
            ContactType contactType = email != null ? pyramusClient.get("/common/contactTypes/" + email.getContactTypeId(), ContactType.class) : null;
            UserEmail userEmail = entityFactory.createEntity(new SchoolDataIdentifier(userIdentifier, getSchoolDataSource()), email, contactType);
            if (userEmail != null) {
                result.add(userEmail);
            }
        }
        return result;
    }
    return Collections.emptyList();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserEmail(fi.otavanopisto.muikku.schooldata.entity.UserEmail) Email(fi.otavanopisto.pyramus.rest.model.Email) ContactType(fi.otavanopisto.pyramus.rest.model.ContactType) ArrayList(java.util.ArrayList) UserEmail(fi.otavanopisto.muikku.schooldata.entity.UserEmail)

Example 2 with UserEmail

use of fi.otavanopisto.muikku.schooldata.entity.UserEmail in project muikku by otavanopisto.

the class UserRESTService method listStudentEmails.

@GET
@Path("/students/{ID}/emails")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listStudentEmails(@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_EMAILS)) {
            return Response.status(Status.FORBIDDEN).build();
        }
    }
    List<UserEmail> emails = userController.listUserEmails(studentIdentifier);
    Collections.sort(emails, new Comparator<UserEmail>() {

        @Override
        public int compare(UserEmail o1, UserEmail o2) {
            return o1.getDefaultAddress() ? -1 : o2.getDefaultAddress() ? 1 : 0;
        }
    });
    return Response.ok(createRestModel(emails.toArray(new UserEmail[0]))).build();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) UserEmail(fi.otavanopisto.muikku.schooldata.entity.UserEmail) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 3 with UserEmail

use of fi.otavanopisto.muikku.schooldata.entity.UserEmail in project muikku by otavanopisto.

the class LocalUserSchoolDataBridge method listUserEmailsByUserIdentifier.

/**
 * {@inheritDoc}
 */
@Override
public List<UserEmail> listUserEmailsByUserIdentifier(String userIdentifier) {
    if (!StringUtils.isNumeric(userIdentifier)) {
        throw new SchoolDataBridgeInternalException("userIdentifier is invalid");
    }
    List<UserEmail> result = new ArrayList<>();
    List<LocalUserEmail> emails = localUserSchoolDataController.listUserEmailsByUserIdentifier(userIdentifier);
    for (LocalUserEmail email : emails) {
        UserEmail emailImpl = toLocalUserEmailImpl(email);
        if (emailImpl != null) {
            result.add(emailImpl);
        } else {
            throw new SchoolDataBridgeInternalException("Unexpected error occured while listing LocalUserEmails");
        }
    }
    return result;
}
Also used : SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) ArrayList(java.util.ArrayList) LocalUserEmail(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail) UserEmail(fi.otavanopisto.muikku.schooldata.entity.UserEmail) LocalUserEmail(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail)

Aggregations

UserEmail (fi.otavanopisto.muikku.schooldata.entity.UserEmail)3 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)2 ArrayList (java.util.ArrayList)2 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)1 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 LocalUserEmail (fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUserEmail)1 SchoolDataBridgeInternalException (fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException)1 ContactType (fi.otavanopisto.pyramus.rest.model.ContactType)1 Email (fi.otavanopisto.pyramus.rest.model.Email)1 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1