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