List<SmallestContentVersionVO> versionInitialSuggestions = new ArrayList<SmallestContentVersionVO>();
List<SmallestContentVersionVO> versionNonPublishedSuggestions = new ArrayList<SmallestContentVersionVO>();
while (results.hasMore())
{
SmallestContentVersionImpl version = (SmallestContentVersionImpl)results.next();
if(previousContentId != null && previousContentId.intValue() != version.getContentId().intValue())
{
if(minimumTimeBetweenVersionsDuringClean != -1 && versionInitialSuggestions.size() >= numberOfVersionsToKeep)
{
Iterator potentialContentVersionVOListIterator = potentialContentVersionVOList.iterator();
while(potentialContentVersionVOListIterator.hasNext())
{
SmallestContentVersionVO potentialContentVersionVO = (SmallestContentVersionVO)potentialContentVersionVOListIterator.next();
SmallestContentVersionVO firstInitialSuggestedContentVersionVO = null;
Iterator versionInitialSuggestionsIterator = versionInitialSuggestions.iterator();
while(versionInitialSuggestionsIterator.hasNext())
{
SmallestContentVersionVO initialSuggestedContentVersionVO = (SmallestContentVersionVO)versionInitialSuggestionsIterator.next();
if(initialSuggestedContentVersionVO.getStateId().equals(ContentVersionVO.PUBLISHED_STATE))
{
firstInitialSuggestedContentVersionVO = initialSuggestedContentVersionVO;
break;
}
}
if(firstInitialSuggestedContentVersionVO != null)
{
keptContentVersionVOList.remove(potentialContentVersionVO);
keptContentVersionVOList.add(firstInitialSuggestedContentVersionVO);
versionInitialSuggestions.remove(firstInitialSuggestedContentVersionVO);
versionInitialSuggestions.add(potentialContentVersionVO);
}
}
}
//System.out.println("versionNonPublishedSuggestions:" + versionNonPublishedSuggestions.size());
//System.out.println("versionInitialSuggestions:" + versionInitialSuggestions.size());
contentVersionsIdList.addAll(versionNonPublishedSuggestions);
contentVersionsIdList.addAll(versionInitialSuggestions);
potentialContentVersionVOList.clear();
versionInitialSuggestions.clear();
versionNonPublishedSuggestions.clear();
keptContentVersionVOList.clear();
numberOfLaterVersions = 0;
previousDate = null;
difference = -1;
potentialContentVersionVOList = 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)
{
keptContentVersionVOList.add(version.getValueObject());
potentialContentVersionVOList.add(version.getValueObject());
numberOfLaterVersions++;
}
else
{
keptContentVersionVOList.add(version.getValueObject());
previousDate = version.getModifiedDateTime();
numberOfLaterVersions++;
}
previousContentId = version.getContentId();
}
if(minimumTimeBetweenVersionsDuringClean != -1 && versionInitialSuggestions.size() >= numberOfVersionsToKeep)
{
//System.out.println("Inside again....");