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