else {
expandedPattern = new LeftJoin(statementPattern, joinOfAttributePatterns);
}
// build an Or-ed set of filter conditions on the status and team.
Or filterConditions = new Or();
/* first condition is that none are bound: this is the case where the subject
* is not a restricted resource (and therefore has no associated attributes)
*
* And(Not(Bound(?acl_attr1)), Not(Bound(?acl_attr_1), ...)
*/
And and = new And();
for (Var attributeVar : attributeVars) {
and.addArg(new Not(new Bound(attributeVar)));
}
if (and.getArgs().size() == 1) {
filterConditions.addArg(and.getArg(0));
}
else {
filterConditions.addArg(and);
}
if (permissions == null) {
List<URI> roles = getRolesForUser(getCurrentUser());
permissions = getAssignedPermissions(roles, ACL.VIEW);
}
// for each permission, we add an additional condition to the filter,
// checking that either
// team, or status, or both match.
for (URI permission : permissions) {
And permissionCondition = new And();
for (int j = 0; j < attributes.size(); j++) {
URI attribute = attributes.get(j);
URI attributePermissionValue = getAttributeValueForPermission(permission, attribute);
Compare attributeValueCompare = null;
if (attributePermissionValue != null) {
attributeValueCompare = new Compare(attributeVars.get(j), new Var("acl_attr_val_" + j,
attributePermissionValue));
permissionCondition.addArg(attributeValueCompare);
}
}
if (permissionCondition.getNumberOfArguments() == 1) {
filterConditions.addArg(permissionCondition.getArg(0));
}
else {
// add the permission-defined condition to the set of Or-ed
// filter conditions.
filterConditions.addArg(permissionCondition);
}
}
// set the filter conditions on the query pattern
if (filterConditions.getNumberOfArguments() == 1) {
// no second argument in the or
expandedPattern = new Filter(expandedPattern, filterConditions.getArg(0));
}
else {
expandedPattern = new Filter(expandedPattern, filterConditions);
}