boolean isInventoryManager = authorizationManager.isInventoryManager(subject);
List<ResourceLineageComposite> resourceLineage = new ArrayList<ResourceLineageComposite>(
rawResourceLineage.size());
for (Resource resource : rawResourceLineage) {
boolean isLocked = !(isInventoryManager || authorizationManager.canViewResource(subject, resource.getId()));
ResourceLineageComposite composite = new ResourceLineageComposite(resource, isLocked);
resourceLineage.add(composite);
}
// Build up the result list, including only the direct ancestors of the Resource and all viewable siblings of
// the ancestors. The list will represent a tree, rooted at the platform, in depth-first order.
List<ResourceLineageComposite> result = new LinkedList<ResourceLineageComposite>();
for (ResourceLineageComposite ancestor : resourceLineage) {
// Always include a direct ancestor.
result.add(ancestor);
// If the ancestor is not locked, include viewable children.
if (!ancestor.isLocked() || ancestor.getResource() == parent) {
// Get viewable committed children, but bounded to ensure it's not an overwhelming return set
ResourceCriteria criteria = new ResourceCriteria();
criteria.addFilterParentResourceId(ancestor.getResource().getId());
criteria.addSortName(PageOrdering.ASC);
criteria.clearPaging();//disable paging as the code assumes all the results will be returned.
List<Resource> children = findResourcesByCriteriaBounded(subject, criteria, 0, 0);
// Remove any that are in the lineage to avoid repeated handling.
children.removeAll(rawResourceLineage);
for (Resource child : children) {
// Ensure the parentResource field is fetched. (do this here and not via criteria.fetchParentResource
// because that option would require inventory manager perm)
child.getParentResource().getId();
// The query only returned viewable children, so the composite should not be locked.
boolean isLocked = false;
ResourceLineageComposite composite = new ResourceLineageComposite(child, isLocked);
result.add(composite);
}
}
}