Action Types

Overview

Actions are activated when a doucment is added, removed or read in the ECM Explorer portlet. Actions are bound to JCR Nodes thanks to the UI in the explorer as described in the "Actions Concept" section. As you can see there we provide some default preconfigured actions such as the workflowAction or the trasformBinaryToText one.

Each action is in fact a custom NodeType that extends one of the exo:action NodeType. Each time you want to create a new ActionType you will have to extend one of the provided concrete "exo:action" definition. By default there exist 3 NodeTypes that extend the "exo:action" one as shown in the next diagram:

You already knew that activating an action would, underneath, launch a BusinessProcess, a script or a Business Rule. Now you know why! PLugin a new default type that the admin can use to create new concreate ActionType is a developer work as he will need to plug new eXo plugins to tell the service that new action types are supported.

When you reach from the ECM Admin portlet the "Manage ActionType" section you will get a list of al the existing ActionType as well as, in the second column, the list of the NodeType it extends. That provides you the same information as in the previous picture. Indeed, we can see that the two ActionTypes that are "exo:workflowAction" and "exo:backupAction" extends the "exo:businessProcessAction" one and hence they will launch some business processes.

As ActionTypes are NodeTypes, it is not possible to remove them (for integrity reasons) but you can create new ones. Remind that you will create NodeType and not Node instances! In the next screenshot, the admin must choose among the 3 ActionType to extend. In our current case, it is a "exo:businessProcess" one. The form below the selectbox is adapted according to the selected ActionType and in the case of a business process base action type then the admin is allowed to select the business process to map with the ActionType (here "content-backup"). The admin can also define new varailable that will be then passed to the business process and stored as JCR properties when the ActionType will be instantiated.

Finally, the Move checkbox tells if the Action will move the document from one location in a workspace to another one in another workspace. Underneath, the newly created ActionType also gets the "exo:move" MixinType which defines the "exo:destWorkspace" and the "exo:destPath" JCR properties.

In the next screenshot you can see that the form is adapted to the main selected ActionType. Here we see all the available business processes that the action could launch. If the admin had selected the "exo:scriptAction" base NodeType then the list would have been filled with the available Scripts.

The next code sample is simple the "TransformBinaryChildrenToTextScript.groovy". As you can see, it gets the information through the context object and then has access to all the necessary information to process some document manipulations such as transforming all the binary documents of a folder into text documents under the same folder using the eXo DocumentReaderService.

import java.util.Map;

import javax.jcr.Property;
import javax.jcr.Node ;
import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;

import org.exoplatform.services.cms.scripts.CmsScript;
import org.exoplatform.services.document.DocumentReaderService;

/*
* Will need to get The MailService when it has been moved to exo-platform
*/
public class TransformBinaryChildrenToTextScript implements CmsScript {
  
  private DocumentReaderService readerService_;
  
  public TransformBinaryChildrenToTextScript(DocumentReaderService readerService) {  
    readerService_ = readerService;
  }
  
  public void execute(Object context) {
    Map variables = (Map) context;       

    Node actionNode = (Node) variables.get("actionNode");
    Node folderNode = actionNode.getParent();    
    
    try {
      NodeIterator iter = folderNode.getNodes();
      while(iter.hasNext()) {
        Node childNode = iter.nextNode();
        if("nt:file".equals(childNode.getPrimaryNodeType().getName())) {
          Node content = childNode.getNode("jcr:content");
          Property mime = content.getProperty("jcr:mimeType");
          if (!mime.getString().startsWith("text")) {          
            String text = readerService_.getContentAsText(mime.getString(), content
              .getProperty("jcr:data").getStream());
            Node file = null;           
            try {
              file = folderNode.getNode(childNode.getName() + ".txt");
            } catch (PathNotFoundException e) {
              file = folderNode.addNode(childNode.getName() + ".txt", "nt:file");
            }
            Node contentNode = file.addNode("jcr:content", "nt:resource");
            contentNode.setProperty("jcr:encoding", "UTF-8");
            contentNode.setProperty("jcr:mimeType", "text/html");    
            contentNode.setProperty("jcr:data", text);
            contentNode.setProperty("jcr:lastModified", new GregorianCalendar());                              
          }
        }        
      }
      folderNode.save();
    } catch (Exception e) {      
      e.printStackTrace();
    }  
  }

  public void setParams(String[] params) {}

}

Note that when a node is bound with an action then it gets the MixinType "exo:actionable" which mandates the Node to have a child Node of type exo:action. In the JCR explorer, those are, by default, managed as hidden files but you can view them by configuration from the Preferences form.

Service Configuration

<component>
    <key>org.exoplatform.services.cms.actions.ActionServiceContainer</key>  
    <type>org.exoplatform.services.cms.actions.ActionServiceContainerImpl</type>
    ..............
  </component>

As in many cases the service can get plugins and there are alot of defined actions type pluged-in action service thought actions plugin

  • Business process action plugin: init publication and bakup actions
<component-plugin>
        <name>exo:businessProcessAction</name>
        <set-method>addPlugin</set-method>
        <type>org.exoplatform.services.cms.actions.BPActionPlugin</type>
        <init-params>
          <object-param>
            <name>predefined.actions</name>
            <description>description</description>
            <object type="org.exoplatform.services.cms.actions.ActionConfig">
              <field  name="workspace"><string>production</string></field>
              <field  name="actions">
                <collection type="java.util.ArrayList">
                  <value>
                    <object type="org.exoplatform.services.cms.actions.ActionConfig$Action">
                      <field  name="type"><string>exo:workflowAction</string></field>
                      <field  name="name"><string>publication</string></field>                  
                      <field  name="description"><string>publication workflow</string></field>
                      <field  name="srcWorkspace"><string>draft</string></field>
                      <field  name="srcPath"><string>/cms/publications</string></field>
                      <field  name="lifecyclePhase"><string>add</string></field>                      
                      <field  name="roles"><string>*:/user</string></field>                      
                      <field  name="variables">
                        <string>exo:validator=member:/company/direction</string>
                      </field>              
                      <field name="mixins">
                        <collection type="java.util.ArrayList">
                          <value>
                            <object type="org.exoplatform.services.cms.actions.ActionConfig$Mixin">
                              <field  name="name"><string>exo:move</string></field>
                              <field  name="properties">
                                <string>exo:destWorkspace=production;exo:destPath=/cms/publications</string>
                              </field>
                            </object>
                          </value>
                        </collection>     
                      </field>    
                    </object>  
                  </value> 
                  <value>
                    <object type="org.exoplatform.services.cms.actions.ActionConfig$Action">
                      <field  name="type"><string>exo:backupAction</string></field>
                      <field  name="name"><string>backup</string></field>                  
                      <field  name="description"><string>backup workflow</string></field>
                      <field  name="srcWorkspace"><string>production</string></field>
                      <field  name="srcPath"><string>/cms/publications</string></field>
                      <field  name="lifecyclePhase"><string>add</string></field>                      
                      <field  name="roles"><string>*:/user</string></field>      
                      <field name="mixins">
                        <collection type="java.util.ArrayList">
                          <value>
                            <object type="org.exoplatform.services.cms.actions.ActionConfig$Mixin">
                              <field  name="name"><string>exo:move</string></field>
                              <field  name="properties">
                                <string>exo:destWorkspace=backup;exo:destPath=/cms/publications</string>
                              </field>
                            </object>
                          </value>
                        </collection>     
                      </field>                                                                
                    </object>  
                  </value> 
                </collection>   
              </field>  
            </object>
          </object-param>
        </init-params>   
      </component-plugin>

  • Script action plugin: init a send mail script action
<component-plugin>
          <name>exo:scriptAction</name>   
          <set-method>addPlugin</set-method>
          <type>org.exoplatform.services.cms.actions.ScriptActionPlugin</type>
          <init-params>
            <object-param>
              <name>predefined.actions</name>
              <description>description</description>
              <object type="org.exoplatform.services.cms.actions.ActionConfig">
                <field  name="workspace"><string>production</string></field>
                <field  name="actions">
                  <collection type="java.util.ArrayList">
                    <value>
                      <object type="org.exoplatform.services.cms.actions.ActionConfig$Action">
                        <field  name="type"><string>exo:sendMailAction</string></field>
                        <field  name="name"><string>sendMail</string></field>                  
                        <field  name="description"><string>send a notification mail</string></field>
                        <field  name="srcWorkspace"><string>production</string></field>
                        <field  name="srcPath"><string>/cms/publications</string></field>
                        <field  name="lifecyclePhase"><string>add</string></field>
                        <field  name="roles"><string>*:/admin</string></field>
                        <field  name="variables">
                          <string>exo:to=benjamin.mestrallet@exoplatform.com</string>
                        </field>                  
                      </object>  
                    </value>                                   
                  </collection>   
                </field>  
              </object>
            </object-param>
          </init-params>    
        </component-plugin>
 
Navigation

Creator: Benjamin Mestrallet on 2007/05/23 07:18
Copyright (c) 2000-2009. Allright reserved - eXo platform SAS
1.6.13286