Search in sources :

Example 1 with ApplicationMailTemplateDAO

use of fi.otavanopisto.pyramus.dao.application.ApplicationMailTemplateDAO 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 ApplicationMailTemplateDAO

use of fi.otavanopisto.pyramus.dao.application.ApplicationMailTemplateDAO 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 ApplicationMailTemplateDAO

use of fi.otavanopisto.pyramus.dao.application.ApplicationMailTemplateDAO 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 4 with ApplicationMailTemplateDAO

use of fi.otavanopisto.pyramus.dao.application.ApplicationMailTemplateDAO 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)

Example 5 with ApplicationMailTemplateDAO

use of fi.otavanopisto.pyramus.dao.application.ApplicationMailTemplateDAO in project pyramus by otavanopisto.

the class ListMailTemplatesJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    try {
        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());
            }
        });
        List<Map<String, Object>> results = new ArrayList<>();
        for (ApplicationMailTemplate applicationMailTemplate : applicationMailTemplates) {
            Map<String, Object> templateInfo = new HashMap<>();
            templateInfo.put("id", applicationMailTemplate.getId());
            templateInfo.put("lineInternal", applicationMailTemplate.getLine());
            templateInfo.put("lineUi", ApplicationUtils.applicationLineUiValue(applicationMailTemplate.getLine()));
            templateInfo.put("name", applicationMailTemplate.getName());
            templateInfo.put("authorName", applicationMailTemplate.getStaffMember().getFullName());
            templateInfo.put("owner", applicationMailTemplate.getStaffMember().getId().equals(requestContext.getLoggedUserId()));
            results.add(templateInfo);
        }
        requestContext.addResponseParameter("mailTemplates", results);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Error loading mail templates", e);
    }
}
Also used : HashMap(java.util.HashMap) ApplicationMailTemplateDAO(fi.otavanopisto.pyramus.dao.application.ApplicationMailTemplateDAO) ArrayList(java.util.ArrayList) ApplicationMailTemplate(fi.otavanopisto.pyramus.domainmodel.application.ApplicationMailTemplate) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ApplicationMailTemplateDAO (fi.otavanopisto.pyramus.dao.application.ApplicationMailTemplateDAO)7 ApplicationMailTemplate (fi.otavanopisto.pyramus.domainmodel.application.ApplicationMailTemplate)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