* @throws Exception
*/
private static void processDownloadableExport(List<DSpaceObject> dsObjects,
Context context, final String additionalEmail, boolean toMigrate) throws Exception
{
final EPerson eperson = context.getCurrentUser();
final boolean migrate = toMigrate;
// before we create a new export archive lets delete the 'expired'
// archives
deleteOldExportArchives(eperson.getID());
// keep track of the commulative size of all bitstreams in each of the
// items
// it will be checked against the config file entry
float size = 0;
final ArrayList<Integer> items = new ArrayList<Integer>();
for (DSpaceObject dso : dsObjects)
{
if (dso.getType() == Constants.COMMUNITY)
{
Community community = (Community) dso;
// 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())
{