11-28-2013 08:30 AM
11-29-2013 03:46 AM
11-29-2013 04:52 AM
11-29-2013 05:29 AM
public class IsSiteConsumerEvaluator extends BaseEvaluator{
private static Log logger = LogFactory.getLog(IsSiteConsumerEvaluator.class);
protected static final String SITE = "site";
/**
* Returns the current site id OR null if we aren't in a site
*
* @param context
* @return The current site id OR null if we aren't in a site
*/
protected String getSite(RequestContext context)
{
// Look for siteId in url path & parameters
String site = context.getUriTokens().get(SITE);
if (site == null)
{
site = context.getParameter(SITE);
}
if (site == null)
{
String[] pathNames = context.getUri().substring(context.getContextPath().length()).split("/");
for (int i = 0; i < pathNames.length; i++) {
if (pathNames.equals(SITE) && (i + 1 < pathNames.length))
{
site = pathNames;
break;
}
}
}
return site;
}
@Override
public boolean evaluate(JSONObject arg0) {
try{
final RequestContext rc = ThreadLocalRequestContext.getRequestContext();
HttpSession session = ServletUtil.getSession();
CredentialVault cv = rc.getCredentialVault();
String currentSite = getSite(rc);
if(cv!=null){
String userName = (String) session.getAttribute(UserFactory.SESSION_ATTRIBUTE_KEY_USER_ID);
Connector connector = rc.getServiceRegistry().getConnectorService().getConnector("alfresco", userName, session);
Response res = connector.call("/api/sites/"+currentSite+"/memberships/" +rc.getUserId());
logger.debug(">> Membership Response :: " + res);
if(res.getStatus().getCode() == Status.STATUS_OK){
String response = res.getResponse();
JSONParser p = new JSONParser();
Object obj = p.parse(response);
logger.debug(">> Object obj value :: " + obj);
if(obj instanceof JSONObject){
JSONObject jsonRes = (JSONObject) obj;
String siteMemberShip = (String) jsonRes.get("role");
logger.debug(">> Object obj value :: " + siteMemberShip);
if("SiteConsumer".equals(siteMemberShip)){
logger.debug(">> In final if returning TRUE");
return true;
}
}
}
}
}catch(ConnectorServiceException e){
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
return false;
}
}
<bean id="evaluator.doclib.action.IsSiteConsumer" class="com.sop.web.evaluator.IsSiteConsumerEvaluator" />
<config evaluator="string-compare" condition="DocLibActions">
<actions>
<action id="document-copy-to" type="javascript" label="actions.document.copy-to">
<param name="function">onActionCopyTo</param>
<evaluator negate="true">evaluator.doclib.action.IsSiteConsumer</evaluator>
<evaluator negate="true">evaluator.doclib.action.isLocked</evaluator>
<evaluator negate="true">evaluator.doclib.indicator.IsReadOnly</evaluator>
</action>
<action id="document-download" type="link" label="actions.document.download">
<param name="href">{downloadUrl}</param>
<evaluator>evaluator.doclib.action.IsSiteConsumer</evaluator>
</action>
</actions>
</config>
11-29-2013 06:19 AM
12-03-2013 11:07 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.