use of org.alfresco.repo.solr.AclChangeSet 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));
}
}
}
use of org.alfresco.repo.solr.AclChangeSet in project alfresco-remote-api by Alfresco.
the class SOLRWebScriptTest method testAclsGet.
public void testAclsGet() throws Exception {
List<AclChangeSet> aclChangeSets = solrTrackingComponent.getAclChangeSets(null, null, null, null, 100);
if (aclChangeSets.size() == 0) {
// Can't test, but very unlikely
return;
}
// Build JSON using these
JSONObject json = new JSONObject();
JSONArray aclChangeSetIdsJSON = new JSONArray();
int count = 0;
List<Long> aclChangeSetIds = new ArrayList<Long>();
for (AclChangeSet aclChangeSet : aclChangeSets) {
if (count >= 512) {
break;
}
if (aclChangeSet.getAclCount() == 0) {
// No ACLs
continue;
}
Long aclChangeSetId = aclChangeSet.getId();
aclChangeSetIdsJSON.put(aclChangeSetId);
aclChangeSetIds.add(aclChangeSetId);
count++;
}
json.put("aclChangeSetIds", aclChangeSetIdsJSON);
String url = "/api/solr/acls";
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 acls = json.getJSONArray("acls");
// Check
List<Acl> aclsCheck = solrTrackingComponent.getAcls(aclChangeSetIds, null, 512);
assertEquals("Script and API returned different number of results", aclsCheck.size(), acls.length());
}
Aggregations