Search in sources :

Example 1 with I18NMessageMethod

use of org.alfresco.repo.template.I18NMessageMethod in project acs-community-packaging by Alfresco.

the class NodeInfoBean method getModel.

// ------------------------------------------------------------------------------
// Helper methods
private Map<String, Object> getModel(NodeRef nodeRef, Map<String, String> requestMap) throws ContentIOException {
    FacesContext context = FacesContext.getCurrentInstance();
    Map<String, Object> model = new HashMap<String, Object>(8, 1.0f);
    I18NUtil.registerResourceBundle("alfresco.messages.webclient");
    // create api methods
    model.put("date", new Date());
    model.put("msg", new I18NMessageMethod());
    model.put("url", new BaseTemplateContentServlet.URLHelper(context));
    model.put("locale", I18NUtil.getLocale());
    if (nodeRef != null) {
        model.put("node", new TemplateNode(nodeRef, Repository.getServiceRegistry(context), this.imageResolver));
    }
    // add URL arguments as a map called 'args' to the root of the model
    Map<String, String> args = new HashMap<String, String>(4, 1.0f);
    for (String name : requestMap.keySet()) {
        args.put(name, requestMap.get(name));
    }
    model.put("args", args);
    return model;
}
Also used : TemplateNode(org.alfresco.repo.template.TemplateNode) FacesContext(javax.faces.context.FacesContext) I18NMessageMethod(org.alfresco.repo.template.I18NMessageMethod) HashMap(java.util.HashMap) BaseTemplateContentServlet(org.alfresco.web.app.servlet.BaseTemplateContentServlet) Date(java.util.Date)

Example 2 with I18NMessageMethod

use of org.alfresco.repo.template.I18NMessageMethod in project acs-community-packaging by Alfresco.

the class TaskInfoBean method getModel.

// ------------------------------------------------------------------------------
// Helper methods
private Map<String, Object> getModel(WorkflowTask task) {
    FacesContext context = FacesContext.getCurrentInstance();
    Map<String, Object> model = new HashMap<String, Object>(8, 1.0f);
    I18NUtil.registerResourceBundle("alfresco.messages.webclient");
    // create template api methods and objects
    model.put("date", new Date());
    model.put("msg", new I18NMessageMethod());
    model.put("url", new BaseTemplateContentServlet.URLHelper(context));
    model.put("locale", I18NUtil.getLocale());
    model.put("task", new Workflow.WorkflowTaskItem(Repository.getServiceRegistry(context), this.imageResolver, task));
    return model;
}
Also used : FacesContext(javax.faces.context.FacesContext) I18NMessageMethod(org.alfresco.repo.template.I18NMessageMethod) HashMap(java.util.HashMap) BaseTemplateContentServlet(org.alfresco.web.app.servlet.BaseTemplateContentServlet) Workflow(org.alfresco.repo.template.Workflow) Date(java.util.Date)

Example 3 with I18NMessageMethod

use of org.alfresco.repo.template.I18NMessageMethod 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);
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) MimeMessagePreparator(org.springframework.mail.javamail.MimeMessagePreparator) I18NMessageMethod(org.alfresco.repo.template.I18NMessageMethod) BaseTemplateContentServlet(org.alfresco.web.app.servlet.BaseTemplateContentServlet) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) NodeRef(org.alfresco.service.cmr.repository.NodeRef) MimeMessage(javax.mail.internet.MimeMessage) ServiceRegistry(org.alfresco.service.ServiceRegistry)

Aggregations

FacesContext (javax.faces.context.FacesContext)3 I18NMessageMethod (org.alfresco.repo.template.I18NMessageMethod)3 BaseTemplateContentServlet (org.alfresco.web.app.servlet.BaseTemplateContentServlet)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 MimeMessage (javax.mail.internet.MimeMessage)1 TemplateNode (org.alfresco.repo.template.TemplateNode)1 Workflow (org.alfresco.repo.template.Workflow)1 ServiceRegistry (org.alfresco.service.ServiceRegistry)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)1 MimeMessagePreparator (org.springframework.mail.javamail.MimeMessagePreparator)1