Skip to content

Commit

Permalink
SF patches #1165647, 1165647-52 - USCD mods to support SRB and Regist…
Browse files Browse the repository at this point in the history
…ration

git-svn-id: http://scm.dspace.org/svn/repo/trunk@1145 9c30dcfa-912a-0410-8fc2-9e0234be79fd
  • Loading branch information
ScottYeadon committed Mar 31, 2005
1 parent fe09396 commit 8f928e2
Show file tree
Hide file tree
Showing 7 changed files with 768 additions and 68 deletions.
64 changes: 64 additions & 0 deletions dspace/config/dspace.cfg
@@ -1,6 +1,12 @@
#
# DSpace Configuration
#
# *****
# Mods by David Little, UCSD Libraries 3/7/05
# Purpose: To allow integration with SRB for bitstream storage.
# Mods are in the File Storage section below.
# *****
#
# Revision: $Revision$
#
# Date: $Date$
Expand Down Expand Up @@ -92,6 +98,64 @@ assetstore.dir = /dspace/assetstore
# The default is 0 (zero) which corresponds to the 'assetstore.dir' above
# assetstore.incoming = 1

##### SRB File Storage #####

# The same 'assetstore.incoming' property is used to support the use of SRB
# (Storage Resource Broker - see http://www.sdsc.edu/srb/) as an _optional_
# replacement of or supplement to conventional file storage. DSpace will work
# with or without SRB and full backward compatibility is maintained.
#
# The 'assetstore.incoming' property is an integer that references where _new_
# bitstreams will be stored. The default (say the starting reference) is zero.
# The value will be used to identify the storage where all new bitstreams will
# be stored until this number is changed. This number is stored in the
# Bitstream table (store_number column) in the DSpace database, so older
# bitstreams that may have been stored when 'asset.incoming' had a different
# value can be found.
#
# In the simple case in which DSpace uses local (or mounted) storage the
# number can refer to different directories (or partitions). This gives DSpace
# some level of scalability. The number links to another set of properties
# 'assetstore.dir', 'assetstore.dir.1' (remember zero is default),
# 'assetstore.dir.2', etc., where the values are directories.
#
# To support the use of SRB DSpace uses this same scheme but broadened to
# support:
# - using SRB instead of the local filesystem
# - using the local filesystem (native DSpace)
# - using a mix of SRB and local filesystem
#
# In this broadened use the 'asset.incoming' integer will refer one of the
# following storage locations
# - a local filesystem directory (native DSpace)
# - a set of SRB account parameters (host, port, zone, domain, username,
# password, home directory, and resource)
#
# Should the be any conflict, like '2' refering to a local directory and
# to a set of SRB parameters, the program will select the local directory.
#
# If SRB is chosen from the first install of DSpace, it is suggested that
# 'assetstore.dir' (no integer appended) be retained to reference a local
# directory (as above under File Storage) because build.xml uses this value
# to do a mkdir. In this case, 'assetstore.incoming' can be set to 1 (i.e.
# uncomment the line in File Storage above) and the 'assetstore.dir' will not
# be used.
#
# Here is an example set of SRB parameters:
# Assetstore 1 - SRB
#srb.host.1 = mysrbmcathost.myu.edu
#srb.port.1 = 5544
#srb.mcatzone.1 = mysrbzone
#srb.mdasdomainname.1 = mysrbdomain
#srb.defaultstorageresource.1 = mydefaultsrbresource
#srb.username.1 = mysrbuser
#srb.password.1 = mysrbpassword
#srb.homedirectory.1 = /mysrbzone/home/mysrbuser.mysrbdomain
#srb.parentdir.1 = mysrbdspaceassetstore
#
# Assetstore n, n+1, ...
# Follow same pattern as for assetstores above (local or SRB)

# Directory for history serializations
history.dir = /dspace/history

Expand Down
Binary file added dspace/lib/jargon.jar
Binary file not shown.
31 changes: 29 additions & 2 deletions dspace/src/org/dspace/app/itemexport/ItemExport.java
@@ -1,6 +1,12 @@
/*
* ItemExport.java
*
* *****
* Mods by David Little, UCSD Libraries 3/10/05
* Purpose: To allow support the export of registrated files (bitstreams).
* Mods mark: MOD DRL
* *****
*
* $Id$
*
* Version: $Revision$
Expand Down Expand Up @@ -386,7 +392,20 @@ private static void writeHandle(Context c, Item i, File destDir)
}
}

// create both the bitstreams and the contents file
// MOD DRL
/**
* Create both the bitstreams and the contents file. Any bitstreams that
* were originally registered will be marked in the contents file as such.
* However, the export directory will contain actual copies of the content
* files being exported.
*
* @param c the DSpace context
* @param i the item being exported
* @param destDir the item's export directory
* @throws Exception if there is any problem writing to the export
* directory
*/
// MOD end
private static void writeBitstreams(Context c, Item i, File destDir)
throws Exception
{
Expand Down Expand Up @@ -428,7 +447,15 @@ private static void writeBitstreams(Context c, Item i, File destDir)
Utils.bufferedCopy(is, fos);

// write the manifest file entry
out.println(myName + "\tbundle:" + bundleName);
// MOD DRL - to support registration
if (b.isRegisteredBitstream()) {
out.println("-r -s " + b.getStoreNumber()
+ " -f " + myName
+ "\tbundle:" + bundleName);
} else {
out.println(myName + "\tbundle:" + bundleName);
}
// MOD end

isDone = true;
}
Expand Down
162 changes: 159 additions & 3 deletions dspace/src/org/dspace/app/itemimport/ItemImport.java
@@ -1,6 +1,13 @@
/*
* ItemImport.java
*
* *****
* Mods by David Little, UCSD Libraries 12/21/04
* Purpose: To allow the registration of files (bitstreams) into DSpace. See
* class javadoc comments below.
* Mods mark: MOD DRL
* *****
*
* $Id$
*
* Version: $Revision$
Expand Down Expand Up @@ -88,9 +95,21 @@
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

//MOD DRL - class comment modified
/**
* The Item importer does exactly that - imports items into the repository.
* Import items into DSpace. The conventional use is upload files by copying
* them. DSpace writes the item's bitstreams into its assetstore. Metadata is
* also loaded to the DSpace database.
*
* A second use assumes the bitstream files already exist in a storage
* resource accessible to DSpace. In this case the bitstreams are 'registered'.
* That is, the metadata is loaded to the DSpace database and DSpace is given
* the location of the file which is subsumed into DSpace.
*
* The distinction is controlled by the format of lines in the 'contents' file.
* See comments in processContentsFile() below.
*/
// MOD end
public class ItemImport
{
static boolean useWorkflow = false;
Expand Down Expand Up @@ -861,6 +880,7 @@ private String processHandleFile(Context c, Item i, String path,
return result;
}

// MOD DRL - this method has be modified for registration
/**
* Given a contents file and an item, stuffing it with bitstreams from the
* contents file
Expand All @@ -886,7 +906,73 @@ private void processContentsFile(Context c, Item i, String path,
continue;
}

// look for a bundle name
// MOD DRL - determine if bitstreams are being
// 1) registered into dspace (leading -r)
// 2) imported conventionally into dspace (no -r)
if (line.trim().startsWith("-r "))
{
// line should be one of these two:
// -r -s n -f filepath
// -r -s n -f filepath\tbundle:bundlename
// where
// n is the assetstore number
// filepath is the path of the file to be registered
// bundlename is an optional bundle name
String sRegistrationLine = line.trim();
int iAssetstore = -1;
String sFilePath = null;
String sBundle = null;
StringTokenizer tokenizer =
new StringTokenizer(sRegistrationLine);
while (tokenizer.hasMoreTokens())
{
String sToken = tokenizer.nextToken();
if (sToken.equals("-r"))
{
continue;
}
else if (sToken.equals("-s") && tokenizer.hasMoreTokens())
{
try
{
iAssetstore =
Integer.parseInt(tokenizer.nextToken());
}
catch (NumberFormatException e)
{
// ignore - iAssetstore remains -1
}
}
else if (sToken.equals("-f") && tokenizer.hasMoreTokens())
{
sFilePath = tokenizer.nextToken();

}
else if (sToken.startsWith("bundle:"))
{
sBundle = sToken.substring(7);
}
else
{
// unrecognized token - should be no problem
}
} // while
if (iAssetstore == -1 || sFilePath == null)
{
System.out.println("\tERROR: invalid contents file line");
System.out.println("\t\tSkipping line: "
+ sRegistrationLine);
continue;
}
registerBitstream(c, i, iAssetstore, sFilePath, sBundle);
System.out.println("\tRegistering Bitstream: " + sFilePath
+ "\tAssetstore: " + iAssetstore
+ "\tBundle: " + sBundle);
continue; // process next line in contents file
}
// MOD end

// look for a bundle name
String bundleMarker = "\tbundle:";

int markerIndex = line.indexOf(bundleMarker);
Expand Down Expand Up @@ -980,6 +1066,76 @@ public void processContentFileEntry(Context c, Item i, String path,
}
}

// MOD DRL: added method - parallels processContentFileEntry()
/**
* Register the bitstream file into DSpace
*
* @param c
* @param i
* @param assetstore
* @param bitstreamPath the full filepath expressed in the contents file
* @param bundleName
* @throws SQLException
* @throws IOException
* @throws AuthorizeException
*/
public void registerBitstream(Context c, Item i, int assetstore,
String bitstreamPath, String bundleName )
throws SQLException, IOException, AuthorizeException
{
// TODO validate assetstore number
// TODO make sure the bitstream is there

Bitstream bs = null;
String newBundleName = bundleName;

if (bundleName == null)
{
// is it license.txt?
if (bitstreamPath.endsWith("license.txt"))
{
newBundleName = "LICENSE";
}
else
{
// call it ORIGINAL
newBundleName = "ORIGINAL";
}
}

if(!isTest)
{
// find the bundle
Bundle[] bundles = i.getBundles(newBundleName);
Bundle targetBundle = null;

if( bundles.length < 1 )
{
// not found, create a new one
targetBundle = i.createBundle(newBundleName);
}
else
{
// put bitstreams into first bundle
targetBundle = bundles[0];
}

// now add the bitstream
bs = targetBundle.registerBitstream(assetstore, bitstreamPath);

// set the name to just the filename
int iLastSlash = bitstreamPath.lastIndexOf('/');
bs.setName(bitstreamPath.substring(iLastSlash + 1));

// Identify the format
// FIXME - guessing format guesses license.txt incorrectly as a text file format!
BitstreamFormat bf = FormatIdentifier.guessFormat(c, bs);
bs.setFormat(bf);

bs.update();
}
}

// XML utility methods
public String getAttributeValue(Node n, String myattributename)
{
Expand Down Expand Up @@ -1065,4 +1221,4 @@ private static Document loadXML(String filename) throws IOException,

return builder.parse(new File(filename));
}
}
}

0 comments on commit 8f928e2

Please sign in to comment.