if (relationTypeForThisEntity.getFromEntityType().equals(entity.getType()))
{
final String toEntityType = relationTypeForThisEntity.getToEntityType();
final Map<String,String> processedToType = processed.containsKey(toEntityType) ? processed.get(toEntityType) : new HashMap<String,String>();
final Set<String> processingToType = processing.containsKey(toEntityType) ? processing.get(toEntityType) : null;
BaseEntitySearchResultHandler handler = new BaseEntitySearchResultHandler()
{
@Override
protected boolean processSearchResult(Entity relatedEntity, int pageSize, int pageIndex, int index)
{
try
{
JetspeedPrincipal principal = null;
if (processingToType != null && processingToType.contains(relatedEntity.getId()))
{
// TODO: throw proper security exception type
throw new IllegalStateException("Circular relationship detected for Entity type "+toEntityType+" id: "+relatedEntity.getId());
}
else if (processedToType != null && processedToType.containsKey(relatedEntity.getId()))
{
String principalName = processed.get(relatedEntity.getType()).get(relatedEntity.getId());
principal = principalName != null ? getJetspeedPrincipal(relatedEntity.getType(),principalName) : null;
}
else
{
Set<String> processingFromType = processing.get(entity.getType());
if (processingFromType == null)
{
processingFromType = new HashSet<String>();
processing.put(entity.getType(), processingFromType);
}
processingFromType.add(entity.getId());
principal = synchronizeEntity(relatedEntity, processing, processed);
}
if (principal != null)
{
toAssociations.add(new JetspeedPrincipalAssociationReference(JetspeedPrincipalAssociationReference.Type.TO, principal, relationTypeForThisEntity.getRelationType()));
}
}
catch (SecurityException e)
{
setFeedback(e);
return false;
}
return true;
}
};
securityEntityManager.getRelatedEntitiesFrom(entity, relationTypeForThisEntity, handler);
if (handler.getFeedback() != null)
{
throw (SecurityException)handler.getFeedback();
}
Set<String> processingFromType = processing.get(entity.getType());
if (processingFromType != null)
{