Pattern filterPattern = null;
if (filter != null)
filterPattern = Pattern.compile(filter);
if (tt == PropertyOptionsSource.TargetType.RESOURCE || tt == PropertyOptionsSource.TargetType.CONFIGURATION) {
ResourceCriteria criteria = new ResourceCriteria();
//Use CriteriaQuery to automatically chunk/page through criteria query results
CriteriaQueryExecutor<Resource, ResourceCriteria> queryExecutor = new CriteriaQueryExecutor<Resource, ResourceCriteria>() {
@Override
public PageList<Resource> execute(ResourceCriteria criteria) {
return resourceManager.findResourcesByCriteria(subject, criteria);
}
};
Iterable<Resource> foundResources = null;
if (tt == PropertyOptionsSource.TargetType.CONFIGURATION) {
// split out expression part for target=configuration
// return if no property specifier is given
String expr = expression;
if (expr.contains(":")) {
expr = expr.substring(expr.indexOf(':') + 1);
if (!"self".equals(expr)) {
criteria.setSearchExpression(expr);
foundResources = new CriteriaQuery<Resource, ResourceCriteria>(criteria, queryExecutor);
if (expressionScope == PropertyOptionsSource.ExpressionScope.BASE_RESOURCE
&& baseResource != null) {
foundResources = Iterables.filter(foundResources, new IsInBaseResourcePredicate(
baseResource));
}
} else if (resource != null) {
ArrayList<Resource> resourceList = new ArrayList<Resource>();
resourceList.add(resource);
foundResources = resourceList;
} else {
LOG.warn("Self reference requested but resource id is not valid."
+ "Option source expression:" + expression);
return;
}
} else {
LOG.warn("Option source expression for property " + pds.getName()
+ " and target configuration contains no ':'");
return;
}
} else {
criteria.setSearchExpression(expression);
foundResources = new CriteriaQuery<Resource, ResourceCriteria>(criteria, queryExecutor);
if (expressionScope == PropertyOptionsSource.ExpressionScope.BASE_RESOURCE && baseResource != null) {
foundResources = Iterables.filter(foundResources, new IsInBaseResourcePredicate(baseResource));
}
}