Domanda

So I'd like to write a new set of evaluators in Share based on the result of some repository webscripts.

The current existing Share evaluators are usable through some XML configuration and are related to Alfresco usual meta-data.

But, I'd like to know how to write my own Java evaluator while re using most of the logic already here (BaseEvaluator).

Suppose I have a repository webscript that returns some JSON like {"result" : "true"}:

  • How do I access it from my custom Evaluator? Mainly how do I access the proxy URL to alfresco webapp from the Spring context?
  • Do I need to write my own async call in Java?
  • Where do I find this JSONObject parameter of the required evaluate method?

thanks for your help

È stato utile?

Soluzione

See if this helps. This goes into a class that extends BaseEvaluator. Wire the bean in through Spring, then set the evaluator on your actions.

public boolean evaluate(JSONObject jsonObject) {
    boolean result = false;

    final RequestContext rc = ThreadLocalRequestContext.getRequestContext();
    final String userId = rc.getUserId();
    try {
        final Connector conn = rc.getServiceRegistry().getConnectorService().getConnector("alfresco", userId, ServletUtil.getSession());
        final Response response = conn.call("/someco/example?echo=false");
        if (response.getStatus().getCode() == Status.STATUS_OK) {
            System.out.println(response.getResponse());
            try {
                org.json.JSONObject json = new org.json.JSONObject(response.getResponse());
                result = Boolean.parseBoolean(((String) json.get("result")));
            } catch (JSONException je) {
                je.printStackTrace();
                return false;
            }
        } else {
            System.out.println("Call failed, code:" + response.getStatus().getCode());
            return false;
        }
    } catch (ConnectorServiceException cse) {
        cse.printStackTrace();
        return false;
    }
    return result;
}

In this example I am using a simple example web script that echoes back your JSON and switches the result based on the value of the "echo" argument. So when it is called with "false", the JSON returns false and the evaluator returns false.

I should probably point out the name collision between the org.json.simple.JSONObject that the evaluate method expects and the org.json.JSONObject I am using to snag the result from the response JSON.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top