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 !!
I need to implement an evaluator which looks at the logged in user's role in order to enable actions only to admin users.
ReplyDeleteHave you ever implemented this type of evaluator?
Thanks in advance
Hi Douglas,
DeleteFor that you can process jsonObject and get the user name from that json and by that way you can achieve your objective.
I will try this.
DeleteThank you
Solved with this
Deletepublic 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
Hi G. Rathod,
ReplyDeleteI 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
Java evaluator class is of share side. so you should keep it inside share/web-inf/lib.
ReplyDeleteBut, Why can not we keep it inside TOMCAT_HOME/shared/lib?
DeleteGreat tutorial!
ReplyDeleteHow to implement an evaluator that has to check if a node has a certain association?
Thanks in advance