// get all the collections in the community
Collection[] collections = community.getCollections();
for (Collection collection : collections)
{
// get all the items in each collection
ItemIterator iitems = collection.getItems();
try
{
while (iitems.hasNext())
{
Item item = iitems.next();
// get all the bundles in the item
Bundle[] bundles = item.getBundles();
for (Bundle bundle : bundles)
{
// get all the bitstreams in each bundle
Bitstream[] bitstreams = bundle.getBitstreams();
for (Bitstream bit : bitstreams)
{
// add up the size
size += bit.getSize();
}
}
items.add(item.getID());
}
}
finally
{
if (iitems != null)
iitems.close();
}
}
}
else if (dso.getType() == Constants.COLLECTION)
{
Collection collection = (Collection) dso;
// get all the items in the collection
ItemIterator iitems = collection.getItems();
try
{
while (iitems.hasNext())
{
Item item = iitems.next();
// get all thebundles in the item
Bundle[] bundles = item.getBundles();
for (Bundle bundle : bundles)
{
// get all the bitstreams in the bundle
Bitstream[] bitstreams = bundle.getBitstreams();
for (Bitstream bit : bitstreams)
{
// add up the size
size += bit.getSize();
}
}
items.add(item.getID());
}
}
finally
{
if (iitems != null)
iitems.close();
}
}
else if (dso.getType() == Constants.ITEM)
{
Item item = (Item) dso;
// get all the bundles in the item
Bundle[] bundles = item.getBundles();
for (Bundle bundle : bundles)
{
// get all the bitstreams in the bundle
Bitstream[] bitstreams = bundle.getBitstreams();
for (Bitstream bit : bitstreams)
{
// add up the size
size += bit.getSize();
}
}
items.add(item.getID());
}
else
{
// nothing to do just ignore this type of DSPaceObject
}
}
// check the size of all the bitstreams against the configuration file
// entry if it exists
String megaBytes = ConfigurationManager
.getProperty("org.dspace.app.itemexport.max.size");
if (megaBytes != null)
{
float maxSize = 0;
try
{
maxSize = Float.parseFloat(megaBytes);
}
catch (Exception e)
{
// ignore...configuration entry may not be present
}
if (maxSize > 0)
{
if (maxSize < (size / 1048576.00))
{ // a megabyte
throw new ItemExportException(ItemExportException.EXPORT_TOO_LARGE,
"The overall size of this export is too large. Please contact your administrator for more information.");
}
}
}
// if we have any items to process then kick off annonymous thread
if (items.size() > 0)
{
Thread go = new Thread()
{
public void run()
{
Context context = null;
ItemIterator iitems = null;
try
{
// create a new dspace context
context = new Context();
// ignore auths
context.setIgnoreAuthorization(true);
iitems = new ItemIterator(context, items);
String fileName = assembleFileName("item", eperson,
new Date());
String workDir = getExportWorkDirectory()
+ System.getProperty("file.separator")
+ fileName;
String downloadDir = getExportDownloadDirectory(eperson
.getID());
File wkDir = new File(workDir);
if (!wkDir.exists())
{
wkDir.mkdirs();
}
File dnDir = new File(downloadDir);
if (!dnDir.exists())
{
dnDir.mkdirs();
}
// export the items using normal export method
exportItem(context, iitems, workDir, 1, migrate);
// now zip up the export directory created above
zip(workDir, downloadDir
+ System.getProperty("file.separator")
+ fileName + ".zip");
// email message letting user know the file is ready for
// download
emailSuccessMessage(context, eperson, fileName + ".zip");
// return to enforcing auths
context.setIgnoreAuthorization(false);
}
catch (Exception e1)
{
try
{
emailErrorMessage(eperson, e1.getMessage());
}
catch (Exception e)
{
// wont throw here
}
throw new RuntimeException(e1);
}
finally
{
if (iitems != null)
iitems.close();
// Make sure the database connection gets closed in all conditions.
try {
context.complete();
} catch (SQLException sqle) {