{
EventVO eventVO = (EventVO)eventIterator.next();
Event event = EventController.getEventWithId(eventVO.getId(), db);
//InfoGluePrincipal infoGluePrincipal = InfoGluePrincipalControllerProxy.getController().getInfoGluePrincipal(event.getCreator());
InfoGluePrincipal infoGluePrincipal = UserControllerProxy.getController().getUser(event.getCreator());
if(event.getTypeId().intValue() == EventVO.PUBLISH.intValue())
{
event.setTypeId(EventVO.PUBLISH_DENIED);
if(event.getEntityClass().equals(ContentVersion.class.getName()))
{
ContentVersion contentVersion = ContentVersionController.getContentVersionController().getContentVersionWithId(event.getEntityId(), db);
if(contentVersion.getStateId().intValue() == ContentVersionVO.PUBLISHED_STATE.intValue())
{
//If its a published version we just deletes the event - we don't want to delete the version.
EventController.delete(event, db);
}
else
{
Content content = contentVersion.getOwningContent();
Language language = contentVersion.getLanguage();
//event.setEntityId(ContentVersionController.getPreviousContentVersionVO(content.getId(), language.getId(), contentVersion.getId()).getId());
ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController().getPreviousActiveContentVersionVO(content.getId(), language.getId(), contentVersion.getId(), db);
if(contentVersionVO != null && event != null)
event.setEntityId(contentVersionVO.getId());
ContentVersionController.getContentVersionController().delete(contentVersion, db);
}
}
else if(event.getEntityClass().equals(SiteNodeVersion.class.getName()))
{
SiteNodeVersion siteNodeVersion = SiteNodeVersionController.getController().getSiteNodeVersionWithId(event.getEntityId(), db);
if(siteNodeVersion.getStateId().intValue() == SiteNodeVersionVO.PUBLISHED_STATE.intValue())
{
//If its a published version we just deletes the event - we don't want to delete the version.
EventController.delete(event, db);
}
else
{
SiteNode siteNode = siteNodeVersion.getOwningSiteNode();
//event.setEntityId(SiteNodeVersionController.getPreviousSiteNodeVersionVO(siteNode.getId(), siteNodeVersion.getId()).getId());
SiteNodeVersion previousSiteNodeVersion = SiteNodeVersionController.getController().getPreviousActiveSiteNodeVersion(siteNode.getId(), siteNodeVersion.getId(), db);
if(previousSiteNodeVersion != null && event != null)
event.setEntityId(previousSiteNodeVersion.getId());
SiteNodeVersionController.getController().delete(siteNodeVersion, db);
SiteNodeStateController.getController().changeStateOnMetaInfo(db, siteNode.getValueObject(), previousSiteNodeVersion.getValueObject(), previousSiteNodeVersion.getStateId(), "Denied publication", true, infoGluePrincipal, new ArrayList());
//db.remove(siteNodeVersion);
}
}
}
else if(event.getTypeId().intValue() == EventVO.UNPUBLISH_LATEST.intValue())
{
event.setTypeId(EventVO.UNPUBLISH_DENIED);
if(event.getEntityClass().equals(ContentVersion.class.getName()))
{
event.setEntityClass(Content.class.getName());
event.setEntityId(ContentVersionController.getContentVersionController().getContentVersionWithId(event.getEntityId(), db).getOwningContent().getId());
}
else if(event.getEntityClass().equals(SiteNodeVersion.class.getName()))
{
event.setEntityClass(SiteNode.class.getName());
event.setEntityId(SiteNodeVersionController.getController().getSiteNodeVersionWithId(event.getEntityId(), db).getOwningSiteNode().getId());
}
}
String email = (infoGluePrincipal!=null) ? infoGluePrincipal.getEmail() : publisher.getEmail();
if(infoGluePrincipal == null)
comment += "\n\n\n(" + event.getCreator() + " wasn't found.)";
mailNotification(event, publisher.getName(), publisher.getEmail(), email, comment, referenceUrl);
}