changes to bring SWORD into line with current working practices on the trunk

git-svn-id: http://scm.dspace.org/svn/repo/trunk@2911 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Richard Jones
2008-04-16 14:32:35 +00:00
parent 9c3f4c2dc3
commit 4ea0b2f94c
7 changed files with 169 additions and 246 deletions

View File

@@ -48,7 +48,9 @@ import org.dspace.content.Collection;
import org.dspace.content.DSpaceObject; import org.dspace.content.DSpaceObject;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.handle.HandleManager; import org.dspace.uri.IdentifierService;
import org.dspace.uri.IdentifierException;
import org.dspace.uri.ResolvableIdentifier;
/** /**
* This class provides a single point of contact for * This class provides a single point of contact for
@@ -75,7 +77,7 @@ public class CollectionLocation
public String getLocation(Collection collection) public String getLocation(Collection collection)
throws DSpaceSWORDException throws DSpaceSWORDException
{ {
return this.getBaseUrl() + "/" + collection.getHandle(); return IdentifierService.getURL(this.getBaseUrl(), collection);
} }
/** /**
@@ -97,17 +99,9 @@ public class CollectionLocation
{ {
throw new DSpaceSWORDException("The deposit URL is incomplete"); throw new DSpaceSWORDException("The deposit URL is incomplete");
} }
String handle = location.substring(baseUrl.length());
if (handle.startsWith("/"))
{
handle = handle.substring(1);
}
if ("".equals(handle))
{
throw new DSpaceSWORDException("The deposit URL is incomplete");
}
DSpaceObject dso = HandleManager.resolveToObject(context, handle); ResolvableIdentifier ri = IdentifierService.resolve(context, location);
DSpaceObject dso = (DSpaceObject) IdentifierService.getResource(context, ri);
if (!(dso instanceof Collection)) if (!(dso instanceof Collection))
{ {
@@ -116,7 +110,7 @@ public class CollectionLocation
return (Collection) dso; return (Collection) dso;
} }
catch (SQLException e) catch (IdentifierException e)
{ {
log.error("Caught exception:", e); log.error("Caught exception:", e);
throw new DSpaceSWORDException("There was a problem resolving the collection", e); throw new DSpaceSWORDException("There was a problem resolving the collection", e);

View File

@@ -47,7 +47,7 @@ import org.dspace.content.DCDate;
import org.dspace.content.DCValue; import org.dspace.content.DCValue;
import org.dspace.content.Item; import org.dspace.content.Item;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.handle.HandleManager; import org.dspace.uri.IdentifierService;
import org.purl.sword.base.SWORDEntry; import org.purl.sword.base.SWORDEntry;
@@ -192,17 +192,14 @@ public class DSpaceATOMEntry
{ {
if (!noOp) if (!noOp)
{ {
if (item.getHandle() != null) handle = IdentifierService.getCanonicalForm(item);
{
handle = item.getHandle();
}
if (handle != null && !"".equals(handle)) if (handle != null && !"".equals(handle))
{ {
Content content = new Content(); Content content = new Content();
// content.setType("application/zip"); // content.setType("application/zip");
content.setType("text/html"); content.setType("text/html");
content.setSource(HandleManager.getCanonicalForm(handle)); content.setSource(handle);
entry.setContent(content); entry.setContent(content);
} }
} }
@@ -247,14 +244,11 @@ public class DSpaceATOMEntry
// it's possible that the item hasn't been assigned a handle yet // it's possible that the item hasn't been assigned a handle yet
if (!noOp) if (!noOp)
{ {
if (item.getHandle() != null) handle = IdentifierService.getCanonicalForm(item);
{
handle = item.getHandle();
}
if (handle != null && !"".equals(handle)) if (handle != null && !"".equals(handle))
{ {
entry.setId(HandleManager.getCanonicalForm(handle)); entry.setId(handle);
return; return;
} }
} }
@@ -276,8 +270,6 @@ public class DSpaceATOMEntry
*/ */
protected void addLinks(String handle) protected void addLinks(String handle)
throws DSpaceSWORDException throws DSpaceSWORDException
{
try
{ {
// if there is no handle, we can't generate links // if there is no handle, we can't generate links
if (handle == null) if (handle == null)
@@ -285,8 +277,6 @@ public class DSpaceATOMEntry
return; return;
} }
String base = ConfigurationManager.getProperty("dspace.url");
// in the default set up we just pass urls to all of the // in the default set up we just pass urls to all of the
// inidivual files in the item // inidivual files in the item
Bundle[] bundles = item.getBundles("ORIGINAL"); Bundle[] bundles = item.getBundles("ORIGINAL");
@@ -296,17 +286,12 @@ public class DSpaceATOMEntry
for (int j = 0; j < bss.length; j++) for (int j = 0; j < bss.length; j++)
{ {
Link link = new Link(); Link link = new Link();
String url = base + "/bitstream/" + handle + "/" + bss[j].getSequenceID() + "/" + bss[j].getName(); String url = IdentifierService.getURL(bss[j]).toString(); // base + "/bitstream/" + handle + "/" + bss[j].getSequenceID() + "/" + bss[j].getName();
link.setHref(url); link.setHref(url);
entry.addLink(link); entry.addLink(link);
} }
} }
} }
catch (SQLException e)
{
throw new DSpaceSWORDException(e);
}
}
/** /**
* Add the date of publication from the bibliographic metadata * Add the date of publication from the bibliographic metadata
@@ -337,8 +322,6 @@ public class DSpaceATOMEntry
* *
*/ */
protected void addRights(String handle) protected void addRights(String handle)
{
try
{ {
// if there's no handle, we can't give a link // if there's no handle, we can't give a link
if (handle == null) if (handle == null)
@@ -346,14 +329,6 @@ public class DSpaceATOMEntry
return; return;
} }
String base = ConfigurationManager.getProperty("dspace.url");
// if there's no base URL, we are stuck
if (base == null)
{
return;
}
StringBuilder rightsString = new StringBuilder(); StringBuilder rightsString = new StringBuilder();
Bundle[] bundles = item.getBundles("LICENSE"); Bundle[] bundles = item.getBundles("LICENSE");
for (int i = 0; i < bundles.length; i++) for (int i = 0; i < bundles.length; i++)
@@ -361,7 +336,7 @@ public class DSpaceATOMEntry
Bitstream[] bss = bundles[i].getBitstreams(); Bitstream[] bss = bundles[i].getBitstreams();
for (int j = 0; j < bss.length; j++) for (int j = 0; j < bss.length; j++)
{ {
String url = base + "/bitstream/" + handle + "/" + bss[j].getSequenceID() + "/" + bss[j].getName(); String url = IdentifierService.getURL(bss[j]).toString(); //base + "/bitstream/" + handle + "/" + bss[j].getSequenceID() + "/" + bss[j].getName();
rightsString.append(url + " "); rightsString.append(url + " ");
} }
} }
@@ -371,11 +346,6 @@ public class DSpaceATOMEntry
rights.setType(ContentType.TEXT); rights.setType(ContentType.TEXT);
entry.setRights(rights); entry.setRights(rights);
} }
catch (SQLException e)
{
// do nothing
}
}
/** /**
* Add the source of the bibliographic metadata. * Add the source of the bibliographic metadata.

View File

@@ -256,8 +256,7 @@ public class DSpaceSWORDServer implements SWORDServer
} }
log.info(LogManager.getHeader(context, "sword_authenticate", "username=" + un + ",on_behalf_of=" + obo)); log.info(LogManager.getHeader(context, "sword_authenticate", "username=" + un + ",on_behalf_of=" + obo));
try
{
// attempt to authenticate the primary user // attempt to authenticate the primary user
SWORDContext sc = new SWORDContext(); SWORDContext sc = new SWORDContext();
SWORDAuthentication auth = new SWORDAuthentication(); SWORDAuthentication auth = new SWORDAuthentication();
@@ -314,15 +313,4 @@ public class DSpaceSWORDServer implements SWORDServer
return sc; return sc;
} }
catch (SQLException e)
{
log.error("caught exception: ", e);
throw new SWORDException("There was a problem accessing the repository user database", e);
}
catch (AuthorizeException e)
{
log.error("caught exception: ", e);
throw new SWORDAuthenticationException("There was a problem authenticating or authorising the user", e);
}
}
} }

View File

@@ -39,7 +39,6 @@
package org.dspace.sword; package org.dspace.sword;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException;
import java.util.Date; import java.util.Date;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@@ -266,11 +265,6 @@ public class DepositManager
log.error("authentication problem; caught exception: ", e); log.error("authentication problem; caught exception: ", e);
throw new DSpaceSWORDException(e); throw new DSpaceSWORDException(e);
} }
catch (SQLException e)
{
log.error("caught exception: ", e);
throw new DSpaceSWORDException(e);
}
} }

View File

@@ -105,14 +105,11 @@ public class SWORDContext
* as asking the question of whether the given eperson is a member * as asking the question of whether the given eperson is a member
* of the special DSpace group Administrator, with id 1 * of the special DSpace group Administrator, with id 1
* *
* @param eperson
* @return true if administrator, false if not * @return true if administrator, false if not
* @throws SQLException * @throws SQLException
*/ */
public boolean isUserAdmin(Context context) public boolean isUserAdmin(Context context)
throws DSpaceSWORDException throws DSpaceSWORDException
{
try
{ {
if (this.authenticated != null) if (this.authenticated != null)
{ {
@@ -121,25 +118,17 @@ public class SWORDContext
} }
return false; return false;
} }
catch (SQLException e)
{
throw new DSpaceSWORDException(e);
}
}
/** /**
* Is the given onBehalfOf user DSpace administrator? This translates * Is the given onBehalfOf user DSpace administrator? This translates
* as asking the question of whether the given eperson is a member * as asking the question of whether the given eperson is a member
* of the special DSpace group Administrator, with id 1 * of the special DSpace group Administrator, with id 1
* *
* @param eperson
* @return true if administrator, false if not * @return true if administrator, false if not
* @throws SQLException * @throws SQLException
*/ */
public boolean isOnBehalfOfAdmin(Context context) public boolean isOnBehalfOfAdmin(Context context)
throws DSpaceSWORDException throws DSpaceSWORDException
{
try
{ {
if (this.onBehalfOf != null) if (this.onBehalfOf != null)
{ {
@@ -148,11 +137,6 @@ public class SWORDContext
} }
return false; return false;
} }
catch (SQLException e)
{
throw new DSpaceSWORDException(e);
}
}
/** /**
* Is the authenticated user a member of the given group * Is the authenticated user a member of the given group
@@ -236,8 +220,6 @@ public class SWORDContext
*/ */
public Collection[] getAllowedCollections(Context context) public Collection[] getAllowedCollections(Context context)
throws DSpaceSWORDException throws DSpaceSWORDException
{
try
{ {
// locate the collections to which the authenticated user has ADD rights // locate the collections to which the authenticated user has ADD rights
Collection[] cols = Collection.findAuthorized(context, null, Constants.ADD); Collection[] cols = Collection.findAuthorized(context, null, Constants.ADD);
@@ -276,11 +258,6 @@ public class SWORDContext
newCols = colList.toArray((Collection[]) newCols); newCols = colList.toArray((Collection[]) newCols);
return newCols; return newCols;
} }
catch (SQLException e)
{
throw new DSpaceSWORDException(e);
}
}
/** /**
* Can the current SWORD Context permit deposit into the given * Can the current SWORD Context permit deposit into the given

View File

@@ -54,9 +54,9 @@ import org.dspace.content.packager.PackageParameters;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.PluginManager; import org.dspace.core.PluginManager;
import org.dspace.handle.HandleManager;
import org.dspace.workflow.WorkflowItem; import org.dspace.workflow.WorkflowItem;
import org.dspace.workflow.WorkflowManager; import org.dspace.workflow.WorkflowManager;
import org.dspace.uri.IdentifierService;
import org.purl.sword.base.Deposit; import org.purl.sword.base.Deposit;
@@ -90,7 +90,7 @@ public class SWORDMETSIngester implements SWORDIngester
CollectionLocation cl = new CollectionLocation(); CollectionLocation cl = new CollectionLocation();
Collection collection = cl.getCollection(context, loc); Collection collection = cl.getCollection(context, loc);
message("Performing deposit using location: " + loc + "; "); message("Performing deposit using location: " + loc + "; ");
message("Location resolves to collection with handle: " + collection.getHandle() + message("Location resolves to collection with identifier: " + IdentifierService.getCanonicalForm(collection) +
" and name: " + collection.getMetadata("name") + "; "); " and name: " + collection.getMetadata("name") + "; ");
// load the plugin manager for the required configuration // load the plugin manager for the required configuration
@@ -143,7 +143,8 @@ public class SWORDMETSIngester implements SWORDIngester
// for some reason, DSpace will not give you the handle automatically, // for some reason, DSpace will not give you the handle automatically,
// so we have to look it up // so we have to look it up
String handle = HandleManager.findHandle(context, installedItem); // String handle = HandleManager.findHandle(context, installedItem);
String handle = IdentifierService.getCanonicalForm(installedItem);
message("Ingest successful; "); message("Ingest successful; ");
message("Item created with internal identifier: " + installedItem.getID() + "; "); message("Item created with internal identifier: " + installedItem.getID() + "; ");

View File

@@ -44,7 +44,6 @@ import org.apache.log4j.Logger;
import org.dspace.content.Collection; import org.dspace.content.Collection;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
import org.dspace.eperson.Group; import org.dspace.eperson.Group;