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);
}
}
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);
}
}
Aggregations