Search in sources :

Example 1 with EmailDAO

use of fi.otavanopisto.pyramus.dao.base.EmailDAO in project pyramus by otavanopisto.

the class StudentsService method addStudentEmail.

public void addStudentEmail(@WebParam(name = "studentId") Long studentId, @WebParam(name = "defaultAddress") Boolean defaultAddress, @WebParam(name = "address") String address) {
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    Student student = studentDAO.findById(studentId);
    address = StringUtils.trim(address);
    if (StringUtils.isNotBlank(address)) {
        // TODO contactType
        ContactType contactType = contactTypeDAO.findById(new Long(1));
        if (!UserUtils.isAllowedEmail(address, contactType, student.getPerson().getId()))
            throw new RuntimeException("Email address is in use");
        Email email = emailDAO.create(student.getContactInfo(), contactType, defaultAddress, address);
        validateEntity(email);
    }
}
Also used : StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) EmailDAO(fi.otavanopisto.pyramus.dao.base.EmailDAO)

Example 2 with EmailDAO

use of fi.otavanopisto.pyramus.dao.base.EmailDAO in project pyramus by otavanopisto.

the class StudentsService method updateStudentEmail.

public void updateStudentEmail(@WebParam(name = "studentId") Long studentId, @WebParam(name = "fromAddress") String fromAddress, @WebParam(name = "toAddress") String toAddress) {
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
    Student student = studentDAO.findById(studentId);
    // Trim the email address
    toAddress = toAddress != null ? toAddress.trim() : null;
    for (Email email : student.getContactInfo().getEmails()) {
        if (email.getAddress().equals(fromAddress)) {
            email = emailDAO.update(email, email.getContactType(), email.getDefaultAddress(), toAddress);
            validateEntity(email);
            break;
        }
    }
}
Also used : StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) EmailDAO(fi.otavanopisto.pyramus.dao.base.EmailDAO)

Example 3 with EmailDAO

use of fi.otavanopisto.pyramus.dao.base.EmailDAO in project pyramus by otavanopisto.

the class UsersService method removeUserEmail.

public void removeUserEmail(@WebParam(name = "userId") Long userId, @WebParam(name = "address") String address) {
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
    fi.otavanopisto.pyramus.domainmodel.users.User user = userDAO.findById(userId);
    for (Email email : user.getContactInfo().getEmails()) {
        if (email.getAddress().equals(address)) {
            emailDAO.delete(email);
            break;
        }
    }
}
Also used : StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) EmailDAO(fi.otavanopisto.pyramus.dao.base.EmailDAO)

Example 4 with EmailDAO

use of fi.otavanopisto.pyramus.dao.base.EmailDAO in project pyramus by otavanopisto.

the class UsersService method addUserEmail.

public void addUserEmail(@WebParam(name = "userId") Long userId, @WebParam(name = "address") String address) {
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    StaffMember user = userDAO.findById(userId);
    // Trim the email address
    address = StringUtils.trim(address);
    if (StringUtils.isNotBlank(address)) {
        // TODO contact type, default address
        ContactType contactType = contactTypeDAO.findById(new Long(1));
        if (!UserUtils.isAllowedEmail(address, contactType, user.getPerson().getId()))
            throw new RuntimeException("Email address is in use");
        Email email = emailDAO.create(user.getContactInfo(), contactType, Boolean.TRUE, address);
        validateEntity(email);
    }
}
Also used : StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) EmailDAO(fi.otavanopisto.pyramus.dao.base.EmailDAO)

Example 5 with EmailDAO

use of fi.otavanopisto.pyramus.dao.base.EmailDAO in project pyramus by otavanopisto.

the class ImportLDAPUsersViewController method processSend.

public void processSend(PageRequestContext requestContext) {
    EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
    UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
    List<User> createdUsers = new ArrayList<User>();
    int rowCount = requestContext.getInteger("importTable.rowCount");
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "importTable." + i;
        if ("1".equals(requestContext.getString(colPrefix + ".import"))) {
            String email = requestContext.getString(colPrefix + ".email");
            String firstName = requestContext.getString(colPrefix + ".firstName");
            String lastName = requestContext.getString(colPrefix + ".lastName");
            String roleName = requestContext.getString(colPrefix + ".role");
            String id = requestContext.getString(colPrefix + ".id");
            Role role = Enum.valueOf(Role.class, roleName);
            User user = userDAO.create(firstName, lastName, id, "LDAP", role);
            emailDAO.create(user.getContactInfo(), null, Boolean.TRUE, email);
            createdUsers.add(user);
        }
    }
    requestContext.getRequest().setAttribute("createdUsers", createdUsers);
    requestContext.setRedirectURL(requestContext.getRequest().getContextPath() + "system/importldapusers.page");
}
Also used : Role(fi.otavanopisto.pyramus.domainmodel.users.Role) UserRole(fi.otavanopisto.pyramus.framework.UserRole) User(fi.otavanopisto.pyramus.domainmodel.users.User) UserDAO(fi.otavanopisto.pyramus.dao.users.UserDAO) ArrayList(java.util.ArrayList) EmailDAO(fi.otavanopisto.pyramus.dao.base.EmailDAO)

Aggregations

EmailDAO (fi.otavanopisto.pyramus.dao.base.EmailDAO)21 Email (fi.otavanopisto.pyramus.domainmodel.base.Email)14 ContactTypeDAO (fi.otavanopisto.pyramus.dao.base.ContactTypeDAO)11 PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)11 ContactType (fi.otavanopisto.pyramus.domainmodel.base.ContactType)11 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)10 Person (fi.otavanopisto.pyramus.domainmodel.base.Person)10 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)10 AddressDAO (fi.otavanopisto.pyramus.dao.base.AddressDAO)9 PhoneNumberDAO (fi.otavanopisto.pyramus.dao.base.PhoneNumberDAO)9 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)9 School (fi.otavanopisto.pyramus.domainmodel.base.School)8 User (fi.otavanopisto.pyramus.domainmodel.users.User)7 TagDAO (fi.otavanopisto.pyramus.dao.base.TagDAO)6 UserVariableDAO (fi.otavanopisto.pyramus.dao.users.UserVariableDAO)6 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)6 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)6 HashSet (java.util.HashSet)6 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)5 SchoolDAO (fi.otavanopisto.pyramus.dao.base.SchoolDAO)5