Search in sources :

Example 6 with ApplicationMailTemplateDAO

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

the class ArchiveMailTemplateJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    try {
        ApplicationMailTemplateDAO applicationMailTemplateDAO = DAOFactory.getInstance().getApplicationMailTemplateDAO();
        ApplicationMailTemplate applicationMailTemplate = null;
        Long id = requestContext.getLong("id");
        if (id != null) {
            applicationMailTemplate = applicationMailTemplateDAO.findById(id);
        }
        if (applicationMailTemplate == null) {
            logger.log(Level.WARNING, "Refusing mail template archive due to template not found");
            requestContext.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }
        applicationMailTemplateDAO.archive(applicationMailTemplate);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Error archiving mail template", e);
    }
}
Also used : ApplicationMailTemplateDAO(fi.otavanopisto.pyramus.dao.application.ApplicationMailTemplateDAO) ApplicationMailTemplate(fi.otavanopisto.pyramus.domainmodel.application.ApplicationMailTemplate)

Example 7 with ApplicationMailTemplateDAO

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

the class EditMailTemplateJSONRequestController 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;
        }
        Long templateId = requestContext.getLong("templateId");
        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;
        }
        ApplicationMailTemplate applicationMailTemplate = null;
        ApplicationMailTemplateDAO applicationMailTemplateDAO = DAOFactory.getInstance().getApplicationMailTemplateDAO();
        if (templateId == null) {
            applicationMailTemplate = applicationMailTemplateDAO.create(line, name, subject, content, staffMember);
        } else {
            applicationMailTemplate = applicationMailTemplateDAO.findById(templateId);
            if (applicationMailTemplate == null) {
                requestContext.getResponse().sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }
            applicationMailTemplate = applicationMailTemplateDAO.update(applicationMailTemplate, line, name, subject, content);
        }
        requestContext.setRedirectURL(requestContext.getReferer(true));
    } 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)

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