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();
}
}
}
}
------------------------------------------------------------------------