//logger.info("Fetching entity in read/write mode" + repositoryId);
QueryResults results = oql.execute(Database.READONLY);
while (results.hasMore())
{
Event event = (Event)results.next();
//logger.warn("event:" + event.getId());
//logger.warn("entityClass:" + event.getEntityClass());
//logger.warn("entityId:" + event.getEntityId());
boolean isValid = true;
if(validate)
{
try
{
if(event.getEntityClass().equalsIgnoreCase(ContentVersion.class.getName()))
{
//ContentVersion contentVersion = null;
ContentVersionVO contentVersionVO = null;
ContentVO contentVO = null;
try
{
contentVersionVO = ContentVersionController.getContentVersionController().getContentVersionVOWithId(event.getEntityId(), db);
//contentVersion = ContentVersionController.getContentVersionController().getContentVersionWithId(event.getEntityId(), db);
if(contentVersionVO != null && contentVersionVO.getContentId() != null)
contentVO = ContentController.getContentController().getContentVOWithId(contentVersionVO.getContentId(), db);
}
catch(SystemException e)
{
hasBrokenItems = true;
throw e;
}
if(contentVersionVO == null || contentVO == null)
{
isValid = false;
hasBrokenItems = true;
}
else
{
if(principal != null && filter != null && filter.equalsIgnoreCase("groupBased"))
{
String versionModifier = contentVersionVO.getVersionModifier();
if(versionModifier != null)
{
InfoGluePrincipal versionModifierPrincipal = UserControllerProxy.getController(db).getUser(versionModifier);
if(versionModifierPrincipal != null)
{
boolean hasGroup = false;
List groups = versionModifierPrincipal.getGroups();
Iterator groupsIterator = groups.iterator();
while(groupsIterator.hasNext())
{
InfoGlueGroup group = (InfoGlueGroup)groupsIterator.next();
if(principal.getGroups().contains(group))
hasGroup = true;
}
if(!hasGroup)
isValid = false;
}
}
}
else if(principal != null && filter != null && filter.indexOf("groupNameBased_") > -1)
{
String versionModifier = contentVersionVO.getVersionModifier();
if(versionModifier != null)
{
InfoGluePrincipal versionModifierPrincipal = UserControllerProxy.getController(db).getUser(versionModifier);
if(versionModifierPrincipal != null)
{
boolean hasGroup = false;
String groupName = filter.substring(filter.indexOf("_") + 1);
List groups = versionModifierPrincipal.getGroups();
Iterator groupsIterator = groups.iterator();
while(groupsIterator.hasNext())
{
InfoGlueGroup group = (InfoGlueGroup)groupsIterator.next();
if(groupName.equalsIgnoreCase(group.getName()))
hasGroup = true;
}
if(!hasGroup)
isValid = false;
}
}
}
}
}
else if(event.getEntityClass().equalsIgnoreCase(SiteNodeVersion.class.getName()))
{
SiteNodeVersionVO siteNodeVersion = null;
SiteNodeVO siteNode = null;
try
{
siteNodeVersion = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(event.getEntityId(), db);
//siteNodeVersion = SiteNodeVersionController.getController().getSiteNodeVersionWithIdAsReadOnly(event.getEntityId(), db);
if(siteNodeVersion.getSiteNodeId() != null)
siteNode = SiteNodeController.getController().getSiteNodeVOWithId(siteNodeVersion.getSiteNodeId(), db);
}
catch(SystemException e)
{
hasBrokenItems = true;
throw e;
}
if(siteNodeVersion == null || siteNode == null)
{
hasBrokenItems = true;
isValid = false;
}
else
{
if(principal != null && filter != null && filter.equalsIgnoreCase("groupBased"))
{
String versionModifier = siteNodeVersion.getVersionModifier();
if(versionModifier != null)
{
InfoGluePrincipal versionModifierPrincipal = UserControllerProxy.getController(db).getUser(versionModifier);
if(versionModifierPrincipal != null)
{
boolean hasGroup = false;
List groups = versionModifierPrincipal.getGroups();
Iterator groupsIterator = groups.iterator();
while(groupsIterator.hasNext())
{
InfoGlueGroup group = (InfoGlueGroup)groupsIterator.next();
if(principal.getGroups().contains(group))
hasGroup = true;
}
if(!hasGroup)
isValid = false;
}
}
}
else if(principal != null && filter != null && filter.indexOf("groupNameBased_") > -1)
{
String versionModifier = siteNodeVersion.getVersionModifier();
if(versionModifier != null)
{
InfoGluePrincipal versionModifierPrincipal = UserControllerProxy.getController(db).getUser(versionModifier);
if(versionModifierPrincipal != null)
{
boolean hasGroup = false;
String groupName = filter.substring(filter.indexOf("_") + 1);
List groups = versionModifierPrincipal.getGroups();
Iterator groupsIterator = groups.iterator();
while(groupsIterator.hasNext())
{
InfoGlueGroup group = (InfoGlueGroup)groupsIterator.next();
if(groupName.equalsIgnoreCase(group.getName()))
hasGroup = true;
}
if(!hasGroup)
isValid = false;
}
}
}
}
}
}
catch(Exception e)
{
isValid = false;
hasBrokenItems = true;
}
}
if(isValid && !hasBrokenItems)
events.add(event.getValueObject());
}
results.close();
oql.close();