Search in sources :

Example 1 with ApplicationMailTemplate

use of fi.otavanopisto.pyramus.domainmodel.application.ApplicationMailTemplate in project pyramus by otavanopisto.

the class CreateMailTemplateJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    try {
        StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
        StaffMember staffMember = staffMemberDAO.findById(requestContext.getLoggedUserId());
        if (staffMember == null) {
            logger.log(Level.WARNING, "Refusing mail template due to staff member not found");
            requestContext.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }
        String line = requestContext.getString("line");
        String name = requestContext.getString("name");
        String subject = requestContext.getString("subject");
        String content = requestContext.getString("content");
        if (StringUtils.isEmpty(name) || StringUtils.isEmpty(subject) || StringUtils.isEmpty(content)) {
            requestContext.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }
        ApplicationMailTemplateDAO applicationMailTemplateDAO = DAOFactory.getInstance().getApplicationMailTemplateDAO();
        ApplicationMailTemplate applicationMailTemplate = applicationMailTemplateDAO.create(line, name, subject, content, staffMember);
        String redirectURL = requestContext.getRequest().getContextPath() + "/applications/editmailtemplate.page?template=" + applicationMailTemplate.getId();
        requestContext.setRedirectURL(redirectURL);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Error saving mail template", e);
    }
}
Also used : StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) ApplicationMailTemplateDAO(fi.otavanopisto.pyramus.dao.application.ApplicationMailTemplateDAO) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) ApplicationMailTemplate(fi.otavanopisto.pyramus.domainmodel.application.ApplicationMailTemplate)

Example 2 with ApplicationMailTemplate

use of fi.otavanopisto.pyramus.domainmodel.application.ApplicationMailTemplate in project pyramus by otavanopisto.

the class GetMailTemplateJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    try {
        Long id = requestContext.getLong("id");
        if (id == null) {
            requestContext.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }
        ApplicationMailTemplateDAO applicationMailTemplateDAO = DAOFactory.getInstance().getApplicationMailTemplateDAO();
        ApplicationMailTemplate applicationMailTemplate = applicationMailTemplateDAO.findById(id);
        if (applicationMailTemplate == null) {
            requestContext.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        requestContext.addResponseParameter("id", applicationMailTemplate.getId());
        requestContext.addResponseParameter("line", applicationMailTemplate.getLine());
        requestContext.addResponseParameter("name", applicationMailTemplate.getName());
        requestContext.addResponseParameter("subject", applicationMailTemplate.getSubject());
        requestContext.addResponseParameter("content", applicationMailTemplate.getContent());
        requestContext.addResponseParameter("author", applicationMailTemplate.getStaffMember().getFullName());
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Error retrieving mail template", e);
    }
}
Also used : ApplicationMailTemplateDAO(fi.otavanopisto.pyramus.dao.application.ApplicationMailTemplateDAO) ApplicationMailTemplate(fi.otavanopisto.pyramus.domainmodel.application.ApplicationMailTemplate)

Example 3 with ApplicationMailTemplate

use of fi.otavanopisto.pyramus.domainmodel.application.ApplicationMailTemplate in project pyramus by otavanopisto.

the class ApplicationMailTemplateDAO method create.

public ApplicationMailTemplate create(String line, String name, String subject, String content, StaffMember user) {
    EntityManager entityManager = getEntityManager();
    ApplicationMailTemplate applicationMailTemplate = new ApplicationMailTemplate();
    applicationMailTemplate.setLine(line);
    applicationMailTemplate.setName(name);
    applicationMailTemplate.setSubject(subject);
    applicationMailTemplate.setContent(content);
    applicationMailTemplate.setStaffMember(user);
    applicationMailTemplate.setArchived(Boolean.FALSE);
    entityManager.persist(applicationMailTemplate);
    return applicationMailTemplate;
}
Also used : EntityManager(javax.persistence.EntityManager) ApplicationMailTemplate(fi.otavanopisto.pyramus.domainmodel.application.ApplicationMailTemplate)

Example 4 with ApplicationMailTemplate

use of fi.otavanopisto.pyramus.domainmodel.application.ApplicationMailTemplate in project pyramus by otavanopisto.

the class EditMailTemplateViewController method process.

public void process(PageRequestContext pageRequestContext) {
    ApplicationMailTemplateDAO applicationMailTemplateDAO = DAOFactory.getInstance().getApplicationMailTemplateDAO();
    Long templateId = pageRequestContext.getLong("template");
    ApplicationMailTemplate applicationMailTemplate = applicationMailTemplateDAO.findById(templateId);
    pageRequestContext.getRequest().setAttribute("template", applicationMailTemplate);
    pageRequestContext.setIncludeJSP("/templates/applications/editmailtemplate.jsp");
}
Also used : ApplicationMailTemplateDAO(fi.otavanopisto.pyramus.dao.application.ApplicationMailTemplateDAO) ApplicationMailTemplate(fi.otavanopisto.pyramus.domainmodel.application.ApplicationMailTemplate)

Example 5 with ApplicationMailTemplate

use of fi.otavanopisto.pyramus.domainmodel.application.ApplicationMailTemplate in project pyramus by otavanopisto.

the class ListMailTemplatesViewController method process.

public void process(PageRequestContext pageRequestContext) {
    ApplicationMailTemplateDAO applicationMailTemplateDAO = DAOFactory.getInstance().getApplicationMailTemplateDAO();
    List<ApplicationMailTemplate> applicationMailTemplates = applicationMailTemplateDAO.listUnarchived();
    Collections.sort(applicationMailTemplates, new Comparator<ApplicationMailTemplate>() {

        public int compare(ApplicationMailTemplate o1, ApplicationMailTemplate o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    String jsonMailTemplates = new JSONArrayExtractor("name", "id").extractString(applicationMailTemplates);
    setJsDataVariable(pageRequestContext, "mailTemplates", jsonMailTemplates);
    pageRequestContext.setIncludeJSP("/templates/applications/listmailtemplates.jsp");
}
Also used : ApplicationMailTemplateDAO(fi.otavanopisto.pyramus.dao.application.ApplicationMailTemplateDAO) ApplicationMailTemplate(fi.otavanopisto.pyramus.domainmodel.application.ApplicationMailTemplate) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor)

Aggregations

ApplicationMailTemplate (fi.otavanopisto.pyramus.domainmodel.application.ApplicationMailTemplate)8 ApplicationMailTemplateDAO (fi.otavanopisto.pyramus.dao.application.ApplicationMailTemplateDAO)7 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)2 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)2 JSONArrayExtractor (fi.otavanopisto.pyramus.util.JSONArrayExtractor)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 EntityManager (javax.persistence.EntityManager)1