use of org.alfresco.repo.solr.AclReaders in project alfresco-remote-api by Alfresco.
the class AclsReadersGet method buildModel.
private Map<String, Object> buildModel(WebScriptRequest req) throws JSONException, IOException {
List<Long> aclIds = null;
Content content = req.getContent();
if (content == null) {
throw new WebScriptException("Request content is empty");
}
JSONObject o = new JSONObject(content.getContent());
JSONArray aclIdsJSON = o.has("aclIds") ? o.getJSONArray("aclIds") : null;
if (aclIdsJSON == null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Parameter 'aclIds' not provided in request content.");
} else if (aclIdsJSON.length() == 0) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Parameter 'aclIds' must hold from 1 or more IDs.");
}
aclIds = new ArrayList<Long>(aclIdsJSON.length());
for (int i = 0; i < aclIdsJSON.length(); i++) {
aclIds.add(aclIdsJSON.getLong(i));
}
// Request according to the paging query style required
List<AclReaders> aclsReaders = solrTrackingComponent.getAclsReaders(aclIds);
Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
model.put("aclsReaders", aclsReaders);
if (logger.isDebugEnabled()) {
logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
}
return model;
}
use of org.alfresco.repo.solr.AclReaders in project alfresco-remote-api by Alfresco.
the class SOLRWebScriptTest method aclReadersGetImpl.
private void aclReadersGetImpl() throws Exception {
List<AclChangeSet> aclChangeSets = solrTrackingComponent.getAclChangeSets(null, null, null, null, 1024);
List<Long> aclChangeSetIds = new ArrayList<Long>(50);
for (AclChangeSet aclChangeSet : aclChangeSets) {
if (aclChangeSet.getAclCount() > 0) {
aclChangeSetIds.add(aclChangeSet.getId());
break;
}
}
if (aclChangeSetIds.size() == 0) {
// No ACLs; not likely
}
List<Acl> acls = solrTrackingComponent.getAcls(aclChangeSetIds, null, 1024);
List<Long> aclIds = new ArrayList<Long>(acls.size());
JSONObject json = new JSONObject();
JSONArray aclIdsJSON = new JSONArray();
for (Acl acl : acls) {
Long aclId = acl.getId();
aclIds.add(aclId);
aclIdsJSON.put(aclId);
}
json.put("aclIds", aclIdsJSON);
// Now get the readers
List<AclReaders> aclsReaders = solrTrackingComponent.getAclsReaders(aclIds);
assertEquals("Should have same number of ACLs as supplied", aclIds.size(), aclsReaders.size());
assertTrue("Must have *some* ACLs here", aclIds.size() > 0);
Map<Long, Set<String>> readersByAclId = new HashMap<Long, Set<String>>();
for (AclReaders aclReaders : aclsReaders) {
readersByAclId.put(aclReaders.getAclId(), aclReaders.getReaders());
}
Map<Long, Set<String>> deniedByAclId = new HashMap<Long, Set<String>>();
for (AclReaders aclReaders : aclsReaders) {
assertNotNull("AclReaders should not contain null denial set", aclReaders.getDenied());
deniedByAclId.put(aclReaders.getAclId(), aclReaders.getDenied());
}
// Now query using the webscript
String url = "/api/solr/aclsReaders";
TestWebScriptServer.PostRequest req = new TestWebScriptServer.PostRequest(url, json.toString(), "application/json");
Response response = sendRequest(req, Status.STATUS_OK, admin);
if (logger.isDebugEnabled()) {
logger.debug(response.getContentAsString());
}
json = new JSONObject(response.getContentAsString());
JSONArray aclsReadersJSON = json.getJSONArray("aclsReaders");
// Check
assertEquals("Script and API returned different number of results", readersByAclId.size(), aclsReadersJSON.length());
// Iterate of the JSON and ensure that the list of ACL readers is correct
for (int i = 0; i < aclsReadersJSON.length(); i++) {
// Choose an ACL and check the readers
JSONObject aclReadersJSON = aclsReadersJSON.getJSONObject(i);
Long aclIdJSON = aclReadersJSON.getLong("aclId");
Set<String> readersCheck = readersByAclId.get(aclIdJSON);
JSONArray readersJSON = aclReadersJSON.getJSONArray("readers");
assertEquals("Readers list for ACL " + aclIdJSON + " is wrong. ", readersCheck.size(), readersJSON.length());
for (int j = 0; j < readersJSON.length(); j++) {
String readerJSON = readersJSON.getString(j);
assertTrue("Found reader not in check set: " + readerJSON, readersCheck.contains(readerJSON));
}
Set<String> deniedCheck = deniedByAclId.get(aclIdJSON);
JSONArray deniedJSON = aclReadersJSON.getJSONArray("denied");
assertEquals("Denied list for ACL " + aclIdJSON + " is wrong. ", deniedCheck.size(), deniedJSON.length());
for (int j = 0; j < deniedJSON.length(); j++) {
String denyJSON = deniedJSON.getString(j);
assertTrue("Found denied authority not in check set: " + denyJSON, deniedCheck.contains(denyJSON));
}
}
}
Aggregations