Wednesday, March 14, 2012

Create new evaluator in documentLibrary Action - alfresco 4 share

To create our custom evaluator we need to configure following files :
1) share-config-custom.xml
2) custom-slingshot-application-context.xml

For example let I will create my one custom action called "Start Draft Workflow" in specified type of content only and checking specified properties in it.

Step 1:  Configure first custom action and actionGroup (share-config-custom.xml)
====================================================================
<config evaluator="string-compare" condition="DocLibActions"> <actions> 
<action id="folder-assign-workflow" type="javascript" icon="folder-manage-permissions" label="Start Draft Workflow">
<param name="function">onActionAssignWorkflow</param>
<evaluator>evaluator.doclib.action.draftTypeFolder</evaluator>
</action>
</actions>
<actionGroups>
<actionGroup id="folder-browse">
<action index="161" id="folder-assign-workflow" />
</actionGroup>
</actionGroups>
</config>


Step 2:  Configure bean entry in slingshot context file for evaluator (custom-slingshot-application-context.xml)
=====================================================================
<bean id="evaluator.doclib.action.draftTypeFolder" class="com.clms.web.evaluator.CLMSActivateDraftWorkflowEvaluator" > </bean>
Step 3:  Create java class for evaluator (CLMSActivateDraftWorkflowEvaluator.java)
Step 4:  Finally put jar at share/WEB-INF/lib
Finally we need to take care that this evaluator can only find our jar, unless we provide jar to share class path. so through your ant build, copy alfresco/WEB-INF/lib/<custom-jar> to share/WEB-INF/lib/<custom-jar>




ENJOY !!

8 comments:

  1. I need to implement an evaluator which looks at the logged in user's role in order to enable actions only to admin users.
    Have you ever implemented this type of evaluator?

    Thanks in advance

    ReplyDelete
    Replies
    1. Hi Douglas,
      For that you can process jsonObject and get the user name from that json and by that way you can achieve your objective.

      Delete
    2. Solved with this

      public class IsAdminEvaluator extends BaseEvaluator {

      @Override
      public boolean evaluate(JSONObject jsonObject) {
      RequestContext rc = ThreadLocalRequestContext.getRequestContext();
      User user = rc.getUser();

      return (user != null && user.isAdmin());
      }
      }

      Thank you

      Delete
  2. Hi G. Rathod,

    I am doing something similar with a JAR extension for Alfresco Share. I only have an easy question, where does the java class for evaluator reside?

    Thanks in advance

    ReplyDelete
  3. Java evaluator class is of share side. so you should keep it inside share/web-inf/lib.

    ReplyDelete
    Replies
    1. But, Why can not we keep it inside TOMCAT_HOME/shared/lib?

      Delete
  4. Great tutorial!

    How to implement an evaluator that has to check if a node has a certain association?

    Thanks in advance

    ReplyDelete