log.debug(LogManager.getHeader(context, "harvest SQL", query));
// Execute
Object[] parametersArray = parameters.toArray();
TableRowIterator tri = DatabaseManager.query(context, query, parametersArray);
List infoObjects = new LinkedList();
int index = 0;
int itemCounter = 0;
try
{
// Process results of query into HarvestedItemInfo objects
while (tri.hasNext())
{
TableRow row = tri.next();
/**
* If we are looking for public-only items, we need to scan all objects
* for permissions in order to properly calculate the offset
*/
if ((!nonAnon) && (index < offset))
{
HarvestedItemInfo itemInfo = new HarvestedItemInfo();
itemInfo.itemID = row.getIntColumn("resource_id");
itemInfo.item = Item.find(context, itemInfo.itemID);
Group[] authorizedGroups = AuthorizeManager.getAuthorizedGroups(context, itemInfo.item, Constants.READ);
boolean added = false;
for (int i = 0; i < authorizedGroups.length; i++)
{
if ((authorizedGroups[i].getID() == 0) && (!added))
{
added = true;
}
}
if (!added)
{
offset++;
}
}
/*
* This conditional ensures that we only process items within any
* constraints specified by 'offset' and 'limit' parameters.
*/
else if ((index >= offset) && ((limit == 0) || (itemCounter < limit)))
{
HarvestedItemInfo itemInfo = new HarvestedItemInfo();
itemInfo.context = context;
itemInfo.handle = row.getStringColumn("handle");
itemInfo.itemID = row.getIntColumn("resource_id");
itemInfo.datestamp = row.getDateColumn("last_modified");
itemInfo.withdrawn = row.getBooleanColumn("withdrawn");
if (collections)
{
fillCollections(context, itemInfo);
}
if (items)
{
// Get the item
itemInfo.item = Item.find(context, itemInfo.itemID);
}
if ((nonAnon) || (itemInfo.item == null) || (withdrawn && itemInfo.withdrawn))
{
infoObjects.add(itemInfo);
itemCounter++;
} else
{
Group[] authorizedGroups = AuthorizeManager.getAuthorizedGroups(context, itemInfo.item, Constants.READ);
boolean added = false;
for (int i = 0; i < authorizedGroups.length; i++)
{
if ((authorizedGroups[i].getID() == 0) && (!added))
{
infoObjects.add(itemInfo);
added = true;
itemCounter++;
}
}
}
}
index++;
}
}
finally
{
// close the TableRowIterator to free up resources
if (tri != null)
tri.close();
}
return infoObjects;
}