Search in sources :

Example 56 with FacesContext

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

Example 57 with FacesContext

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;
}
Also used : FacesContext(javax.faces.context.FacesContext) SelectItem(javax.faces.model.SelectItem)

Example 58 with FacesContext

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;
}
Also used : FacesContext(javax.faces.context.FacesContext) SelectItem(javax.faces.model.SelectItem)

Example 59 with FacesContext

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());
}
Also used : FacesContext(javax.faces.context.FacesContext)

Example 60 with FacesContext

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);
}
Also used : FacesContext(javax.faces.context.FacesContext)

Aggregations

FacesContext (javax.faces.context.FacesContext)361 NodeRef (org.alfresco.service.cmr.repository.NodeRef)61 Node (org.alfresco.web.bean.repository.Node)44 UserTransaction (javax.transaction.UserTransaction)43 ArrayList (java.util.ArrayList)33 HashMap (java.util.HashMap)28 IOException (java.io.IOException)27 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)27 ExternalContext (javax.faces.context.ExternalContext)26 SelectItem (javax.faces.model.SelectItem)26 QName (org.alfresco.service.namespace.QName)25 FacesMessage (javax.faces.application.FacesMessage)24 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)22 Map (java.util.Map)21 ResourceBundle (java.util.ResourceBundle)20 HttpServletResponse (javax.servlet.http.HttpServletResponse)19 MapNode (org.alfresco.web.bean.repository.MapNode)18 UIViewRoot (javax.faces.component.UIViewRoot)17 HttpServletRequest (javax.servlet.http.HttpServletRequest)16 Serializable (java.io.Serializable)15