Showing posts with label association. action. Show all posts
Showing posts with label association. action. Show all posts

Wednesday, December 4, 2013

Alfresco share custom evaluator to check node associations

In Share, we have evaluator based on that templates, action, indicator can be displayed.
We also can have our own custom evaluator . 

I see - many has requirement to show/hide action based on content/folder associations and which is NOT available OOB.
So, In this example I will show you how you can implement it.

We will implement custom evaluator which checks if content has "cm:references" association then show OOB action - "Delete Document". You can have your custom action or any other action.

First we will start with Share side changes.

Step1:  Define custom evaluator

Create file - custom-documentlibrary-context.xml and put it to \tomcat\shared\classes\alfresco\web-extension

Add below code

Step 2: Create custom evaluator class.

This class calls alfresco repository webscript which accepts content noderef and association name and
checks if content has given association or not and accordingly return true or false.

Step 3:  Add new custom evaluator for delete document action in share-config-custom.xml
So now we are done with Share side changes.
We need to create alfresco repository webscript which checks if node has given association or not. This would be simple javascript webscript

Step1: Create desc file . node-association.get.desc.xml.
Put in to extension folder: \tomcat\shared\classes\alfresco\extension\templates\webscripts\custom\example\node\association
Step 2: Create node-association.get.js

Step 3: Create node-association.get.json.ftl

Deploy your custom code and restart server. Verify Delete action for content with and without cm:reference association.
I have not considered multiple association, you can change it same way.

Hope its helpful!