所以我想根据一些存储库网页的结果在Share中编写一组新的评估器。
当前现有的Share评估程序可通过某些XML配置使用,并且与Alfresco通常的元数据相关。
但是,我想知道如何编写自己的Java评估程序,同时重新使用此处已有的大部分逻辑(BaseEvaluator)。
假设我有一个存储库webscript,它返回一些JSON,如{“result”:“true”}:
感谢您的帮助
答案 0 :(得分:3)
看看这是否有帮助。这进入了一个扩展BaseEvaluator的类。通过Spring连接bean,然后根据您的操作设置评估器。
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;
}
在这个例子中,我使用的是一个简单的示例Web脚本,它回显您的JSON并根据“echo”参数的值切换结果。因此,当使用“false”调用它时,JSON返回false并且赋值器返回false。
我应该指出evaluate方法期望的org.json.simple.JSONObject与我用来阻止响应JSON的结果的org.json.JSONObject之间的名称冲突。