I stole code from app.itemupdate | AddBitstreamsAction trying to come up with
a program that can replace the bitstream contents of an item with a new version
of the bitstream. I got real close but noticed that deleting the item after
the addition of the bitstream fails. The error
ERROR: update or delete on table "item" violates foreign key constraint
"bi_5_dmap_item_id_fkey" on table "bi_5_dmap"
When I ran out of ideas I tested the item updater directly:
<DSPACE>/bin/dspace itemupdate -e
moni...@princeton.edu<mailto:moni...@princeton.edu> -s dest -A
with a directory that I created with export. I did change the contents to
include a new file for the item. After the command I can see the new file just
fine - along with the pre existing bitstream. But deleting/expunging fails with
the above message.
Any ideas anybody ?
Here an explanation why I am doing this: I want to put a cronjob together that
works on all pdf bitstreams in items that are in the workflow for a given
community. The cronjob is supposed to glue a cover page in front of all those
bitstreams and replace the existing one with the new one. I have the ‘list
all interesting bitstreams’ code more or less in place. It is fairly generic
and I will eventually send a PR. I have a way of copying the bitstream files
from the system, to a temp location. I know how to glue the cover page. The
last step - insert the updated bitstream proofs to be challenging. I am tempted
to copy the bitstream over the old one in the assetstore and adjust the shasum
in the database directly. BUT … well it is not quite the right thing todo …
And just for reference the code snipped that I use to replace an item
Here is the code snipped I use to replace a bitstream:
private Bundle[] replaceBitstream() throws SQLException, IOException,
AuthorizeException {
Item item = (Item) bit.getParentObject();
if (bit.getFormat().getMIMEType().equals(fileFormat) &&
!ignoreFormatMismatch) {
throw new RuntimeException("format mistmatch");
}
Bundle[] bundles = bit.getBundles();
for (Bundle bdl : bundles) {
Bitstream nBit = bdl.createBitstream(stream);
nBit.setName("cp:" + bit.getName()); // changed name to make sure
this is not the cause of the error
nBit.setDescription(bit.getDescription());
nBit.setSource(bit.getSource());
nBit.setUserFormatDescription(bit.getFormatDescription());
nBit.setUserFormatDescription(bit.getFormatDescription());
bdl.removeBitstream(bit);
}
item.update();
context.commit();
return bundles;
}
Monika
________________
Monika Mevenkamp
phone: 609-258-4161
Lewis Library,Washington Road and Ivy Lane, Princeton University, Princeton, NJ
08544
------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
_______________________________________________
DSpace-tech mailing list
DSpace-tech@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dspace-tech
List Etiquette: https://wiki.duraspace.org/display/DSPACE/Mailing+List+Etiquette