Custom Evaluators for Node Associations
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2013 02:18 PM
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.
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.
Labels:
- Labels:
-
Archive
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2013 04:05 AM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2013 12:32 PM
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!!..
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!!..

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2013 12:01 AM
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!
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!
