Extract embargo information using Java code

9 views
Skip to first unread message

Jun Won Jung

unread,
Jun 14, 2019, 8:16:12 AM6/14/19
to DSpace Technical Support
Hello all,

We need some statistics from DSpace 5.x .
The statistics should include type of each item, whether the item(or some of it's attachments) is embargoed.

To solve it we made a simple Java application using 'org.dspace.core.Context' & 'org.dspace.conent.Item'.

Firstly, I tried to extract the number of attached files in each item with the following code
    ------------------------------------------------------------------------
ItemIterator items = Item.findAll(context);
...
while (items.hasNext()) {
Item item = items.next();

if (item.isArchived() && !item.isWithdrawn()) {

Bitstream[] bitstreams = null;
if((item.getBundles() != null) && (item.getBundles().length > 0) ){
ArrayList<Bundle> allBundles = new ArrayList<Bundle>(Arrays.asList(item.getBundles()));
Bundle currentBundle = allBundles.get( item.getBundles().length - 1 );
//  <- Is this the lastest Bundle of Item ? 
bitstreams = currentBundle.getBitstreams();
}
    ------------------------------------------------------------------------
There is no method for Item object like 'getCurrentBundle()' or 'getLatestBundle(()'. 
Is it right that last elements of 'item.getBundles()' is the current item's bundle?
Secondly, I cannot find how to extract embargo information from 'Item object' & 'BitStream object'.
How can I know whether 'Item' or 'Bitstream' is embargoed using Java code?


Regards,
Jun


ps. Here is the simplified source code of my works.
    ------------------------------------------------------------------------
import org.dspace.content.*;
import org.dspace.core.Context;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;

public class IRRStats {
    public static void main(String[] args) throws SQLException, IOException {
        Context context = null;
        try {
            context = new Context();
            context.turnOffAuthorisationSystem();
            ItemIterator items = Item.findAll(context);

            while (items.hasNext()) {
                Item item = items.next();

                if (item.isArchived() && !item.isWithdrawn() ) {

                    Bitstream[] bitstreams = null;
                    if((item.getBundles() != null) && (item.getBundles().length > 0) ){
                        ArrayList<Bundle> allBundles = new ArrayList<Bundle>(Arrays.asList(item.getBundles()));
                        Bundle currentBundle = allBundles.get( item.getBundles().length - 1 );
                        bitstreams = currentBundle.getBitstreams();
                    }
                    int attachfileCounts = bitstreams != null ? bitstreams.length : 0;

                    System.out.println("[" + item.getMetadata("dc.identifier.uri")  + " : "
                                            + item.getMetadata("dc.type")
                                            + " (" + attachfileCounts + ") ] "
                                            + item.getName());
                }
            }


        }  catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } finally {
            if (context != null && context.isValid()) {
                context.abort();
            }
        }
    }
    ------------------------------------------------------------------------

Mark H. Wood

unread,
Jun 18, 2019, 9:39:36 AM6/18/19
to DSpace Technical Support
I do not understand "latest bundle."

Bitstreams are contained in Bundles according to what use DSpace makes
of them. For example, Bitstreams in the ORIGINAL Bundle are the files
submitted to create the item. Other bundles contain derivatives of
the submitted files, the license selected by the submitter, etc.

--
Mark H. Wood
Lead Technology Analyst

University Library
Indiana University - Purdue University Indianapolis
755 W. Michigan Street
Indianapolis, IN 46202
317-274-0749
www.ulib.iupui.edu
signature.asc
Reply all
Reply to author
Forward
0 new messages