use of org.alfresco.repo.search.SimpleResultSetMetaData 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