cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Evaluators for Node Associations

deepak1987
Star Contributor
Star Contributor
Hi,

I want to implement a Custom Evaluator to render an Action on Alfresco Share Document details page, where I want to check whether a Document/Node has association or not. (The way we check for Aspect - hasAspectEvaluator)

Thanks a lot.
3 REPLIES 3

prignony
Champ on-the-rise
Champ on-the-rise
Hello,

I do have exactly the same question. Why isn't it there by default? It seems like a common thing to be able to solve.


I've read that I should extend the repository thier in order to pass the relations to share. But it seems like it is going to impact the performance. Could someone explain this?

Tanks you,
Regards,
Yves

Hello,

One approach which I did was.. Create one Custom Evaluator and make a call to your custom data web-script which will return node associations.


<java>

package com.alfshare.evaluator;

import org.alfresco.web.evaluator.BaseEvaluator;
import org.json.JSONException;
import org.json.simple.JSONObject;
import org.springframework.extensions.surf.RequestContext;
import org.springframework.extensions.surf.ServletUtil;
import org.springframework.extensions.surf.exception.ConnectorServiceException;
import org.springframework.extensions.surf.support.ThreadLocalRequestContext;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.connector.Connector;
import org.springframework.extensions.webscripts.connector.Response;


public class HasRelatedDocumentAssocEvaluator extends BaseEvaluator
{

    @Override
    public boolean evaluate(JSONObject jsonObject)
    {


        final RequestContext rc = ThreadLocalRequestContext.getRequestContext();
        final String userId = rc.getUserId();
       
        try
        {
            final Connector conn = rc
                    .getServiceRegistry()
                        .getConnectorService()
                        .getConnector("alfresco", userId, ServletUtil.getSession());
           
            final String nodeRef = "";
            final Response response = conn.call("/relateddocuments?nodeId=" + nodeRef);
          
            if (response.getStatus().getCode() == Status.STATUS_OK)
            {
              
                try
                {
                    org.json.JSONObject json = new org.json.JSONObject(response.getResponse());

                    org.json.JSONArray responseArray = (org.json.JSONArray) json.get("response");
                   
                    if(responseArray.length() > 0)
                    {
                        return true;
                    }
                  
                }
                catch (JSONException je)
                {
                    je.printStackTrace();
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        catch (ConnectorServiceException cse)
        {
            cse.printStackTrace();
            return false;
        }

        return false;
    }

}




</java>

Hope this helps!!..

niketapatel
Star Contributor
Star Contributor
You also can modify below alfresco repository data webscript response to include association list.

Need to include association list in "node" object of "items". So you can access this node and assoc list in your custom Evaluator class.

URL: /slingshot/doclib2/doclist/{type}/site/{site}/{container}

Location: tomcat\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\org\alfresco\slingshot\documentlibrary-v2\doclist.get.json.ftl

Hope its helpful!