Search in sources :

Example 1 with Email

use of fi.otavanopisto.pyramus.domainmodel.base.Email 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 Email

use of fi.otavanopisto.pyramus.domainmodel.base.Email 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 Email

use of fi.otavanopisto.pyramus.domainmodel.base.Email 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 Email

use of fi.otavanopisto.pyramus.domainmodel.base.Email 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 Email

use of fi.otavanopisto.pyramus.domainmodel.base.Email in project pyramus by otavanopisto.

the class EditSchoolViewController method process.

/**
 * Processes the page request by including the corresponding JSP page to the response.
 *
 * @param pageRequestContext Page request context
 */
public void process(PageRequestContext pageRequestContext) {
    SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
    SchoolFieldDAO schoolFieldDAO = DAOFactory.getInstance().getSchoolFieldDAO();
    SchoolVariableDAO schoolVariableDAO = DAOFactory.getInstance().getSchoolVariableDAO();
    SchoolVariableKeyDAO schoolVariableKeyDAO = DAOFactory.getInstance().getSchoolVariableKeyDAO();
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    ContactURLTypeDAO contactURLTypeDAO = DAOFactory.getInstance().getContactURLTypeDAO();
    Long schoolId = NumberUtils.createLong(pageRequestContext.getRequest().getParameter("school"));
    School school = schoolDAO.findById(schoolId);
    StringBuilder tagsBuilder = new StringBuilder();
    Iterator<Tag> tagIterator = school.getTags().iterator();
    while (tagIterator.hasNext()) {
        Tag tag = tagIterator.next();
        tagsBuilder.append(tag.getText());
        if (tagIterator.hasNext())
            tagsBuilder.append(' ');
    }
    List<ContactURLType> contactURLTypes = contactURLTypeDAO.listUnarchived();
    Collections.sort(contactURLTypes, new StringAttributeComparator("getName"));
    List<SchoolVariableKey> schoolUserEditableVariableKeys = schoolVariableKeyDAO.listUserEditableVariableKeys();
    Collections.sort(schoolUserEditableVariableKeys, new StringAttributeComparator("getVariableName"));
    List<ContactType> contactTypes = contactTypeDAO.listUnarchived();
    Collections.sort(contactTypes, new StringAttributeComparator("getName"));
    String jsonContactTypes = new JSONArrayExtractor("id", "name").extractString(contactTypes);
    List<Address> addresses = school.getContactInfo().getAddresses();
    JSONArray jsonAddresses = new JSONArrayExtractor("id", "defaultAddress", "name", "streetAddress", "postalCode", "city", "country").extract(addresses);
    for (int i = 0; i < jsonAddresses.size(); i++) {
        JSONObject jsonAddress = jsonAddresses.getJSONObject(i);
        if (addresses.get(i).getContactType() != null) {
            jsonAddress.put("contactTypeId", addresses.get(i).getContactType().getId());
        }
    }
    List<Email> emails = school.getContactInfo().getEmails();
    JSONArray jsonEmails = new JSONArrayExtractor("id", "defaultAddress", "address").extract(emails);
    for (int i = 0; i < jsonEmails.size(); i++) {
        JSONObject jsonEmail = jsonEmails.getJSONObject(i);
        if (emails.get(i).getContactType() != null) {
            jsonEmail.put("contactTypeId", emails.get(i).getContactType().getId());
        }
    }
    List<PhoneNumber> phoneNumbers = school.getContactInfo().getPhoneNumbers();
    JSONArray jsonPhoneNumbers = new JSONArrayExtractor("id", "defaultNumber", "number").extract(phoneNumbers);
    for (int i = 0; i < jsonPhoneNumbers.size(); i++) {
        JSONObject jsonPhoneNumber = jsonPhoneNumbers.getJSONObject(i);
        if (phoneNumbers.get(i).getContactType() != null) {
            jsonPhoneNumber.put("contactTypeId", phoneNumbers.get(i).getContactType().getId());
        }
    }
    JSONArray jsonVariableKeys = new JSONArrayExtractor("variableKey", "variableName", "variableType").extract(schoolUserEditableVariableKeys);
    for (int i = 0; i < jsonVariableKeys.size(); i++) {
        JSONObject jsonVariableKey = jsonVariableKeys.getJSONObject(i);
        String key = jsonVariableKey.getString("variableKey");
        String value = schoolVariableDAO.findValueBySchoolAndKey(school, key);
        if (value != null)
            jsonVariableKey.put("variableValue", value);
    }
    this.setJsDataVariable(pageRequestContext, "addresses", jsonAddresses.toString());
    this.setJsDataVariable(pageRequestContext, "emails", jsonEmails.toString());
    this.setJsDataVariable(pageRequestContext, "phoneNumbers", jsonPhoneNumbers.toString());
    this.setJsDataVariable(pageRequestContext, "contactTypes", jsonContactTypes);
    this.setJsDataVariable(pageRequestContext, "variableKeys", jsonVariableKeys.toString());
    pageRequestContext.getRequest().setAttribute("tags", tagsBuilder.toString());
    pageRequestContext.getRequest().setAttribute("school", school);
    pageRequestContext.getRequest().setAttribute("variableKeys", schoolUserEditableVariableKeys);
    pageRequestContext.getRequest().setAttribute("schoolFields", schoolFieldDAO.listUnarchived());
    pageRequestContext.setIncludeJSP("/templates/settings/editschool.jsp");
}
Also used : ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) Address(fi.otavanopisto.pyramus.domainmodel.base.Address) SchoolVariableKeyDAO(fi.otavanopisto.pyramus.dao.base.SchoolVariableKeyDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor) ContactURLTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactURLTypeDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) SchoolDAO(fi.otavanopisto.pyramus.dao.base.SchoolDAO) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) SchoolVariableDAO(fi.otavanopisto.pyramus.dao.base.SchoolVariableDAO) JSONArray(net.sf.json.JSONArray) SchoolVariableKey(fi.otavanopisto.pyramus.domainmodel.base.SchoolVariableKey) ContactURLType(fi.otavanopisto.pyramus.domainmodel.base.ContactURLType) JSONObject(net.sf.json.JSONObject) SchoolFieldDAO(fi.otavanopisto.pyramus.dao.base.SchoolFieldDAO) PhoneNumber(fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag)

Aggregations

Email (fi.otavanopisto.pyramus.domainmodel.base.Email)42 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)16 EmailDAO (fi.otavanopisto.pyramus.dao.base.EmailDAO)14 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)14 Path (javax.ws.rs.Path)14 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)12 ContactType (fi.otavanopisto.pyramus.domainmodel.base.ContactType)10 School (fi.otavanopisto.pyramus.domainmodel.base.School)10 Address (fi.otavanopisto.pyramus.domainmodel.base.Address)9 PhoneNumber (fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber)9 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)8 Person (fi.otavanopisto.pyramus.domainmodel.base.Person)8 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)8 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)7 User (fi.otavanopisto.pyramus.domainmodel.users.User)7 EntityManager (javax.persistence.EntityManager)7 PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)6 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 GET (javax.ws.rs.GET)6 AddressDAO (fi.otavanopisto.pyramus.dao.base.AddressDAO)5