Evaluators in alfresco share

Evaluators are used for control visibility of share document library action.For creating custom action in alfresco share you can follow below link.It has most of the things covered.

http://www.krutikjayswal.com/2016/08/custom-action-in-share-documentlibrary.html

Evaluators are nothing but a spring bean which is used for evaluating the visibility of custom action in alfresco share.In alfresco there are already few predefined evaluators are there.Those are generic and can me used in multiple scenarios.On below link all those evaluators are very well explained.

http://docs.alfresco.com/5.1/concepts/doclib-predefined-evaluators-reference.html

Even if all those evaluators are there, there can be a business requirement of creating a custom evaluator.In custom evaluators there are few things using which you can do evaluation like properties of node.

Lets take one example of custom evaluator.
In my previous blog we have created action called "open-form" and have added it on document-browse,document-details,folder-browse and folder-details section.

   onActionFormDialog
   action
   script
   create
   {node.nodeRef}
   message.execute-script.success
   message.execute-script.failure



Now for adding evaluator you have to create bean in slingshot application context file.That bean will reference a java class which extends a class called org.alfresco.web.evaluator.BaseEvaluator.Lets take a loon on that java file.

SampleEvaluator.Java

import org.alfresco.web.evaluator.BaseEvaluator;
import org.json.simple.JSONObject;

public class SampleEvaluator extends BaseEvaluator{

 @Override
 public boolean evaluate(JSONObject jsonObject) {
  boolean result=false;
  
  //Evaluate
  
  
  return result;
 }
 

}

In the method public boolean evaluate(JSONObject jsonObject), You can evaluate the node and set the value of result variable accordingly.Properties you can get from node are in jsonObject argument of method.Apart from this if you need anything else you can call alfresco webservice also.

{
 "node": {
  "isLink": false,
  "nodeRef": "workspace:\/\/SpacesStore\/43dd6777-b40f-4c49-9533-cd5a180fe4d4",
  "permissions": {
   "inherited": true,
   "roles": ["ALLOWED;GROUP_EVERYONE;Contributor;INHERITED"],
   "user": {
    "Delete": true,
    "Write": true,
    "CancelCheckOut": false,
    "ChangePermissions": true,
    "CreateChildren": true,
    "Unlock": false
   }
  },
  "isLocked": false,
  "aspects": ["cm:titled", "cm:auditable", "sys:referenceable", "sys:localized"],
  "isContainer": true,
  "type": "cm:folder",
  "properties": {
   "cm:title": "",
   "cm:creator": {
    "firstName": "Administrator",
    "lastName": "",
    "displayName": "Administrator",
    "userName": "admin"
   },
   "cm:modifier": {
    "firstName": "Administrator",
    "lastName": "",
    "displayName": "Administrator",
    "userName": "admin"
   },
   "cm:created": {
    "iso8601": "2016-08-27T12:56:35.349Z",
    "value": "Sat Aug 27 18:26:35 IST 2016"
   },
   "cm:name": "Inv",
   "sys:store-protocol": null,
   "sys:node-dbid": null,
   "sys:store-identifier": null,
   "sys:locale": null,
   "cm:modified": {
    "iso8601": "2016-08-27T12:56:35.349Z",
    "value": "Sat Aug 27 18:26:35 IST 2016"
   },
   "cm:description": "",
   "sys:node-uuid": null
  }
 },
 "webdavUrl": "\/webdav\/Shared\/Inv",
 "parent": {
  "isLink": false,
  "nodeRef": "workspace:\/\/SpacesStore\/3372c9eb-8ea2-4b1f-a19c-386158313f8f",
  "permissions": {
   "inherited": false,
   "roles": ["ALLOWED;GROUP_EVERYONE;Contributor;DIRECT"],
   "user": {
    "Delete": true,
    "Write": true,
    "CancelCheckOut": false,
    "ChangePermissions": true,
    "CreateChildren": true,
    "Unlock": false
   }
  },
  "isLocked": false,
  "aspects": ["cm:titled", "cm:auditable", "sys:referenceable", "sys:localized", "app:uifacets"],
  "isContainer": true,
  "type": "cm:folder",
  "properties": {
   "cm:title": "Shared Folder",
   "cm:creator": {
    "firstName": "System",
    "lastName": "User",
    "displayName": "System User",
    "userName": "System"
   },
   "cm:modifier": {
    "firstName": "Administrator",
    "lastName": "",
    "displayName": "Administrator",
    "userName": "admin"
   },
   "cm:created": {
    "iso8601": "2016-08-23T11:50:00.399Z",
    "value": "Tue Aug 23 17:20:00 IST 2016"
   },
   "sys:store-protocol": null,
   "sys:store-identifier": null,
   "cm:description": "Folder to store shared stuff ",
   "sys:node-uuid": null,
   "cm:name": "Shared",
   "sys:node-dbid": null,
   "sys:locale": null,
   "cm:modified": {
    "iso8601": "2016-08-27T12:56:35.402Z",
    "value": "Sat Aug 27 18:26:35 IST 2016"
   },
   "app:icon": "space-icon-default"
  }
 },
 "fileName": "Inv",
 "nodeRef": "workspace:\/\/SpacesStore\/43dd6777-b40f-4c49-9533-cd5a180fe4d4",
 "displayName": "Inv",
 "location": {
  "path": "\/Shared",
  "parent": {},
  "file": "Inv",
  "repositoryId": "6c2cf525-c6bf-4e63-8f8e-71d15bf1a588",
  "repoPath": "\/Shared"
 },
 "version": "1.0",
 "likes": {
  "isLiked": false,
  "totalLikes": 0
 }
}

In slingshot application context file you have to create bean like below.

 

Share this: