use of org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet in project alfresco-remote-api by Alfresco.
the class SearchSQLApiWebscript method execute.
@Override
public void execute(WebScriptRequest webScriptRequest, WebScriptResponse res) throws IOException {
try {
// Turn JSON into a Java object representation
SearchSQLQuery searchQuery = extractJsonContent(webScriptRequest, assistant.getJsonHelper(), SearchSQLQuery.class);
SearchParameters sparams = buildSearchParameters(searchQuery);
ResultSet results = searchService.query(sparams);
FilteringResultSet frs = (FilteringResultSet) results;
SolrSQLJSONResultSet ssjr = (SolrSQLJSONResultSet) frs.getUnFilteredResultSet();
// When solr format is requested pass the solr output directly.
if (searchQuery.getFormat().equalsIgnoreCase("solr")) {
res.getWriter().write(ssjr.getSolrResponse());
} else {
CollectionWithPagingInfo<TupleList> nodes = resultMapper.toCollectionWithPagingInfo(ssjr.getDocs(), searchQuery);
renderJsonResponse(res, nodes, assistant.getJsonHelper());
}
setResponse(res, DEFAULT_SUCCESS);
} catch (Exception exception) {
renderException(exception, res, assistant);
}
}
use of org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet in project records-management by Alfresco.
the class RMAfterInvocationProvider method decide.
private ResultSet decide(Authentication authentication, Object object, ConfigAttributeDefinition config, ResultSet returnedObject) {
if (returnedObject == null) {
return null;
}
class RMFilteringResultSet extends FilteringResultSet {
private long numberFound;
public RMFilteringResultSet(ResultSet unfiltered, BitSet inclusionMask) {
super(unfiltered, inclusionMask);
}
@Override
public long getNumberFound() {
return numberFound;
}
private void setNumberFound(long numberFound) {
this.numberFound = numberFound;
}
}
BitSet inclusionMask = new BitSet(returnedObject.length());
RMFilteringResultSet filteringResultSet = new RMFilteringResultSet(returnedObject, inclusionMask);
List<ConfigAttributeDefintion> supportedDefinitions = extractSupportedDefinitions(config);
Integer maxSize = null;
if (returnedObject.getResultSetMetaData().getSearchParameters().getMaxItems() >= 0) {
maxSize = Integer.valueOf(returnedObject.getResultSetMetaData().getSearchParameters().getMaxItems());
}
if ((maxSize == null) && (returnedObject.getResultSetMetaData().getSearchParameters().getLimitBy() == LimitBy.FINAL_SIZE)) {
maxSize = Integer.valueOf(returnedObject.getResultSetMetaData().getSearchParameters().getLimit());
}
// Allow for skip
if ((maxSize != null) && (returnedObject.getResultSetMetaData().getSearchParameters().getSkipCount() >= 0)) {
maxSize = Integer.valueOf(maxSize + returnedObject.getResultSetMetaData().getSearchParameters().getSkipCount());
}
if (supportedDefinitions.size() == 0) {
if (maxSize == null) {
return returnedObject;
} else if (returnedObject.length() > maxSize.intValue()) {
for (int i = 0; i < maxSize.intValue(); i++) {
inclusionMask.set(i, true);
}
filteringResultSet.setResultSetMetaData(new SimpleResultSetMetaData(returnedObject.getResultSetMetaData().getLimitedBy(), PermissionEvaluationMode.EAGER, returnedObject.getResultSetMetaData().getSearchParameters()));
return filteringResultSet;
} else {
for (int i = 0; i < returnedObject.length(); i++) {
inclusionMask.set(i, true);
}
filteringResultSet.setResultSetMetaData(new SimpleResultSetMetaData(returnedObject.getResultSetMetaData().getLimitedBy(), PermissionEvaluationMode.EAGER, returnedObject.getResultSetMetaData().getSearchParameters()));
return filteringResultSet;
}
}
// record the start time
long startTimeMillis = System.currentTimeMillis();
// set the default, unlimited resultset type
filteringResultSet.setResultSetMetaData(new SimpleResultSetMetaData(returnedObject.getResultSetMetaData().getLimitedBy(), PermissionEvaluationMode.EAGER, returnedObject.getResultSetMetaData().getSearchParameters()));
for (int i = 0; i < returnedObject.length(); i++) {
long currentTimeMillis = System.currentTimeMillis();
// All permission checks must pass
inclusionMask.set(i, true);
if (!nodeService.exists(returnedObject.getNodeRef(i))) {
inclusionMask.set(i, false);
} else {
int parentCheckRead = checkRead(returnedObject.getChildAssocRef(i).getParentRef());
int childCheckRead = checkRead(returnedObject.getNodeRef(i));
for (ConfigAttributeDefintion cad : supportedDefinitions) {
NodeRef testNodeRef = returnedObject.getNodeRef(i);
int checkRead = childCheckRead;
if (cad.parent) {
testNodeRef = returnedObject.getChildAssocRef(i).getParentRef();
checkRead = parentCheckRead;
}
if (isUnfiltered(testNodeRef)) {
continue;
}
if (inclusionMask.get(i) && (testNodeRef != null) && (checkRead != AccessDecisionVoter.ACCESS_GRANTED)) {
inclusionMask.set(i, false);
}
}
}
// Bug out if we are limiting by size
if ((maxSize != null) && (filteringResultSet.length() > maxSize.intValue())) {
// Remove the last match to fix the correct size
inclusionMask.set(i, false);
filteringResultSet.setResultSetMetaData(new SimpleResultSetMetaData(LimitBy.FINAL_SIZE, PermissionEvaluationMode.EAGER, returnedObject.getResultSetMetaData().getSearchParameters()));
break;
}
}
filteringResultSet.setNumberFound(returnedObject.getNumberFound());
return filteringResultSet;
}
Aggregations