List versionInitialSuggestions = new ArrayList();
List versionNonPublishedSuggestions = new ArrayList();
while (results.hasMore())
{
SmallSiteNodeVersionImpl version = (SmallSiteNodeVersionImpl)results.next();
if(previousSiteNodeId != null && previousSiteNodeId.intValue() != version.getSiteNodeId().intValue())
{
logger.info("previousSiteNodeId:" + previousSiteNodeId);
if(minimumTimeBetweenVersionsDuringClean != -1 && versionInitialSuggestions.size() > numberOfVersionsToKeep)
{
Iterator potentialSiteNodeVersionVOListIterator = potentialSiteNodeVersionVOList.iterator();
while(potentialSiteNodeVersionVOListIterator.hasNext())
{
SiteNodeVersionVO potentialSiteNodeVersionVO = (SiteNodeVersionVO)potentialSiteNodeVersionVOListIterator.next();
SiteNodeVersionVO firstInitialSuggestedSiteNodeVersionVO = null;
Iterator versionInitialSuggestionsIterator = versionInitialSuggestions.iterator();
while(versionInitialSuggestionsIterator.hasNext())
{
SiteNodeVersionVO initialSuggestedSiteNodeVersionVO = (SiteNodeVersionVO)versionInitialSuggestionsIterator.next();
if(initialSuggestedSiteNodeVersionVO.getStateId().equals(ContentVersionVO.PUBLISHED_STATE))
{
firstInitialSuggestedSiteNodeVersionVO = initialSuggestedSiteNodeVersionVO;
break;
}
}
if(firstInitialSuggestedSiteNodeVersionVO != null)
{
keptSiteNodeVersionVOList.remove(potentialSiteNodeVersionVO);
keptSiteNodeVersionVOList.add(firstInitialSuggestedSiteNodeVersionVO);
versionInitialSuggestions.remove(firstInitialSuggestedSiteNodeVersionVO);
versionInitialSuggestions.add(potentialSiteNodeVersionVO);
}
}
}
siteNodeVersionsIdList.addAll(versionNonPublishedSuggestions);
siteNodeVersionsIdList.addAll(versionInitialSuggestions);
potentialSiteNodeVersionVOList.clear();
versionInitialSuggestions.clear();
versionNonPublishedSuggestions.clear();
keptSiteNodeVersionVOList.clear();
numberOfLaterVersions = 0;
previousDate = null;
difference = -1;
potentialSiteNodeVersionVOList = new ArrayList();
}
else if(previousDate != null)
{
difference = previousDate.getTime() - version.getModifiedDateTime().getTime();
}
if(numberOfLaterVersions > numberOfVersionsToKeep || (keepOnlyOldPublishedVersions && numberOfLaterVersions > 0 && !version.getStateId().equals(ContentVersionVO.PUBLISHED_STATE)))
{
if(version.getStateId().equals(ContentVersionVO.PUBLISHED_STATE))
{
versionInitialSuggestions.add(version.getValueObject());
}
else
{
versionNonPublishedSuggestions.add(version.getValueObject());
}
}
else if(previousDate != null && difference != -1 && difference < minimumTimeBetweenVersionsDuringClean)
{
keptSiteNodeVersionVOList.add(version.getValueObject());
potentialSiteNodeVersionVOList.add(version.getValueObject());
numberOfLaterVersions++;
}
else
{
keptSiteNodeVersionVOList.add(version.getValueObject());
previousDate = version.getModifiedDateTime();
numberOfLaterVersions++;
}
previousSiteNodeId = version.getSiteNodeId();
}
results.close();
oql.close();