AuthorizeException, SQLException, IOException
{
boolean success = false;
Bundle original = null;
Bitstream bs = null;
WorkspaceItem wi = null;
try
{
// Save the PDF in a bitstream first, since the parser
// has to read it as well, and we cannot "rewind" it after that.
wi = WorkspaceItem.create(context, (Collection)parent, false);
Item myitem = wi.getItem();
original = myitem.createBundle("ORIGINAL");
InputStream fileStream = null;
try
{
fileStream = new FileInputStream(pkgFile);
bs = original.createBitstream(fileStream);
}
finally
{
if (fileStream != null)
{
fileStream.close();
}
}
bs.setName("package.pdf");
setFormatToMIMEType(context, bs, "application/pdf");
bs.update();
if (log.isDebugEnabled())
{
log.debug("Created bitstream ID=" + String.valueOf(bs.getID()) + ", parsing...");
}
crosswalkPDF(context, myitem, bs.retrieve());
wi.update();
context.commit();
success = true;
log.info(LogManager.getHeader(context, "ingest",
"Created new Item, db ID="+String.valueOf(myitem.getID())+
", WorkspaceItem ID="+String.valueOf(wi.getID())));
myitem = PackageUtils.finishCreateItem(context, wi, null, params);
return myitem;
}
finally
{
// get rid of bitstream and item if ingest fails
if (!success)
{
if (original != null && bs != null)
{
original.removeBitstream(bs);
}
if (wi != null)
{
wi.deleteAll();
}
}
context.commit();
}
}