use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class TemplateMailHelperBean method notifyUser.
/**
* Send an email notification to the specified User authority
*
* @param person Person node representing the user
* @param node Node they are invited too
* @param from From text message
* @param roleText The role display label for the user invite notification
*/
public void notifyUser(NodeRef person, NodeRef node, final String from, String roleText) {
final String to = (String) this.getNodeService().getProperty(person, ContentModel.PROP_EMAIL);
if (to != null && to.length() != 0) {
String body = this.body;
if (this.usingTemplate != null) {
FacesContext fc = FacesContext.getCurrentInstance();
// use template service to format the email
NodeRef templateRef = new NodeRef(Repository.getStoreRef(), this.usingTemplate);
ServiceRegistry services = Repository.getServiceRegistry(fc);
Map<String, Object> model = DefaultModelHelper.buildDefaultModel(services, Application.getCurrentUser(fc), templateRef);
model.put("role", roleText);
model.put("space", node);
// object to allow client urls to be generated in emails
model.put("url", new BaseTemplateContentServlet.URLHelper(fc));
model.put("msg", new I18NMessageMethod());
model.put("document", node);
if (nodeService.getType(node).equals(ContentModel.TYPE_CONTENT)) {
NodeRef parentNodeRef = nodeService.getParentAssocs(node).get(0).getParentRef();
if (parentNodeRef == null) {
throw new IllegalArgumentException("Parent folder doesn't exists for node: " + node);
}
model.put("space", parentNodeRef);
}
model.put("shareUrl", UrlUtil.getShareUrl(services.getSysAdminParams()));
body = services.getTemplateService().processTemplate("freemarker", templateRef.toString(), model);
}
this.finalBody = body;
MimeMessagePreparator mailPreparer = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws MessagingException {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setTo(to);
message.setSubject(subject);
message.setText(finalBody, MailActionExecuter.isHTML(finalBody));
message.setFrom(from);
}
};
if (logger.isDebugEnabled())
logger.debug("Sending notification email to: " + to + "\n...with subject:\n" + subject + "\n...with body:\n" + body);
try {
// Send the message
this.getMailSender().send(mailPreparer);
} catch (Throwable e) {
// don't stop the action but let admins know email is not getting sent
logger.error("Failed to send email to " + to, e);
}
}
}
use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class TemplateSupportBean method getEmailTemplates.
/**
* @return the list of available Email Templates.
*/
public List<SelectItem> getEmailTemplates() {
List<SelectItem> templates = emailTemplates.get();
if (templates == null) {
// get the template from the special Email Templates folder
FacesContext fc = FacesContext.getCurrentInstance();
String xpath = Application.getRootPath(fc) + "/" + Application.getGlossaryFolderName(fc) + "/" + Application.getEmailTemplatesFolderName(fc) + "//*";
templates = selectDictionaryNodes(fc, xpath, MSG_SELECT_TEMPLATE, MimetypeMap.MIMETYPE_TEXT_PLAIN);
emailTemplates.put(templates);
}
return templates;
}
use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class TemplateSupportBean method getRSSTemplates.
/**
* @return the list of available RSS Templates.
*/
public List<SelectItem> getRSSTemplates() {
List<SelectItem> templates = rssTemplates.get();
if (templates == null) {
// get the template from the special Email Templates folder
FacesContext fc = FacesContext.getCurrentInstance();
String xpath = Application.getRootPath(fc) + "/" + Application.getGlossaryFolderName(fc) + "/" + Application.getRSSTemplatesFolderName(fc) + "//*";
templates = selectDictionaryNodes(fc, xpath, MSG_SELECT_TEMPLATE, MimetypeMap.MIMETYPE_TEXT_PLAIN);
rssTemplates.put(templates);
}
return templates;
}
use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class BaseActionWizard method removeAction.
/**
* Removes the requested action from the list
*/
public void removeAction() {
// use the built in JSF support for retrieving the object for the
// row that was clicked by the user
@SuppressWarnings("unchecked") int index = this.allActionsDataModel.getRowIndex();
this.allActionsProperties.remove(index);
// reset the action drop down
this.action = null;
// refresh the wizard
FacesContext context = FacesContext.getCurrentInstance();
goToPage(context, context.getViewRoot().getViewId());
}
use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.
the class BaseActionWizard method addAction.
/**
* Adds the action just setup by the user to the list of actions for the rule
*/
public void addAction() {
FacesContext context = FacesContext.getCurrentInstance();
// this is called from the actions page so there must be a handler
// present so there's no need to check for null
String summary = this.actionHandlers.get(this.action).generateSummary(context, this, this.currentActionProperties);
if (summary != null) {
this.currentActionProperties.put(PROP_ACTION_SUMMARY, summary);
}
if (this.editingAction == false) {
this.allActionsProperties.add(this.currentActionProperties);
}
// reset the action drop down
this.action = null;
// refresh the wizard
goToPage(context, this.returnViewId);
}
Aggregations