mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
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:
@@ -48,7 +48,9 @@ import org.dspace.content.Collection;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
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
|
||||
@@ -75,7 +77,7 @@ public class CollectionLocation
|
||||
public String getLocation(Collection collection)
|
||||
throws DSpaceSWORDException
|
||||
{
|
||||
return this.getBaseUrl() + "/" + collection.getHandle();
|
||||
return IdentifierService.getURL(this.getBaseUrl(), collection);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,31 +99,23 @@ public class CollectionLocation
|
||||
{
|
||||
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))
|
||||
{
|
||||
throw new DSpaceSWORDException("The deposit URL does not resolve to a valid collection");
|
||||
}
|
||||
|
||||
|
||||
return (Collection) dso;
|
||||
}
|
||||
catch (SQLException e)
|
||||
}
|
||||
catch (IdentifierException e)
|
||||
{
|
||||
log.error("Caught exception:", e);
|
||||
throw new DSpaceSWORDException("There was a problem resolving the collection", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base deposit URL for the DSpace SWORD implementation. This
|
||||
|
@@ -47,7 +47,7 @@ import org.dspace.content.DCDate;
|
||||
import org.dspace.content.DCValue;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.handle.HandleManager;
|
||||
import org.dspace.uri.IdentifierService;
|
||||
|
||||
import org.purl.sword.base.SWORDEntry;
|
||||
|
||||
@@ -192,17 +192,14 @@ public class DSpaceATOMEntry
|
||||
{
|
||||
if (!noOp)
|
||||
{
|
||||
if (item.getHandle() != null)
|
||||
{
|
||||
handle = item.getHandle();
|
||||
}
|
||||
handle = IdentifierService.getCanonicalForm(item);
|
||||
|
||||
if (handle != null && !"".equals(handle))
|
||||
{
|
||||
Content content = new Content();
|
||||
// content.setType("application/zip");
|
||||
content.setType("text/html");
|
||||
content.setSource(HandleManager.getCanonicalForm(handle));
|
||||
content.setSource(handle);
|
||||
entry.setContent(content);
|
||||
}
|
||||
}
|
||||
@@ -247,14 +244,11 @@ public class DSpaceATOMEntry
|
||||
// it's possible that the item hasn't been assigned a handle yet
|
||||
if (!noOp)
|
||||
{
|
||||
if (item.getHandle() != null)
|
||||
{
|
||||
handle = item.getHandle();
|
||||
}
|
||||
handle = IdentifierService.getCanonicalForm(item);
|
||||
|
||||
if (handle != null && !"".equals(handle))
|
||||
{
|
||||
entry.setId(HandleManager.getCanonicalForm(handle));
|
||||
entry.setId(handle);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -277,35 +271,26 @@ public class DSpaceATOMEntry
|
||||
protected void addLinks(String handle)
|
||||
throws DSpaceSWORDException
|
||||
{
|
||||
try
|
||||
{
|
||||
// if there is no handle, we can't generate links
|
||||
if (handle == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String base = ConfigurationManager.getProperty("dspace.url");
|
||||
|
||||
// in the default set up we just pass urls to all of the
|
||||
// inidivual files in the item
|
||||
Bundle[] bundles = item.getBundles("ORIGINAL");
|
||||
for (int i = 0; i < bundles.length ; i++)
|
||||
{
|
||||
Bitstream[] bss = bundles[i].getBitstreams();
|
||||
for (int j = 0; j < bss.length; j++)
|
||||
{
|
||||
Link link = new Link();
|
||||
String url = base + "/bitstream/" + handle + "/" + bss[j].getSequenceID() + "/" + bss[j].getName();
|
||||
link.setHref(url);
|
||||
entry.addLink(link);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
throw new DSpaceSWORDException(e);
|
||||
}
|
||||
// if there is no handle, we can't generate links
|
||||
if (handle == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// in the default set up we just pass urls to all of the
|
||||
// inidivual files in the item
|
||||
Bundle[] bundles = item.getBundles("ORIGINAL");
|
||||
for (int i = 0; i < bundles.length ; i++)
|
||||
{
|
||||
Bitstream[] bss = bundles[i].getBitstreams();
|
||||
for (int j = 0; j < bss.length; j++)
|
||||
{
|
||||
Link link = new Link();
|
||||
String url = IdentifierService.getURL(bss[j]).toString(); // base + "/bitstream/" + handle + "/" + bss[j].getSequenceID() + "/" + bss[j].getName();
|
||||
link.setHref(url);
|
||||
entry.addLink(link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,43 +323,28 @@ public class DSpaceATOMEntry
|
||||
*/
|
||||
protected void addRights(String handle)
|
||||
{
|
||||
try
|
||||
{
|
||||
// if there's no handle, we can't give a link
|
||||
if (handle == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String base = ConfigurationManager.getProperty("dspace.url");
|
||||
|
||||
// if there's no base URL, we are stuck
|
||||
if (base == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder rightsString = new StringBuilder();
|
||||
Bundle[] bundles = item.getBundles("LICENSE");
|
||||
for (int i = 0; i < bundles.length; i++)
|
||||
{
|
||||
Bitstream[] bss = bundles[i].getBitstreams();
|
||||
for (int j = 0; j < bss.length; j++)
|
||||
{
|
||||
String url = base + "/bitstream/" + handle + "/" + bss[j].getSequenceID() + "/" + bss[j].getName();
|
||||
rightsString.append(url + " ");
|
||||
}
|
||||
}
|
||||
|
||||
Rights rights = new Rights();
|
||||
rights.setContent(rightsString.toString());
|
||||
rights.setType(ContentType.TEXT);
|
||||
entry.setRights(rights);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
// if there's no handle, we can't give a link
|
||||
if (handle == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder rightsString = new StringBuilder();
|
||||
Bundle[] bundles = item.getBundles("LICENSE");
|
||||
for (int i = 0; i < bundles.length; i++)
|
||||
{
|
||||
Bitstream[] bss = bundles[i].getBitstreams();
|
||||
for (int j = 0; j < bss.length; j++)
|
||||
{
|
||||
String url = IdentifierService.getURL(bss[j]).toString(); //base + "/bitstream/" + handle + "/" + bss[j].getSequenceID() + "/" + bss[j].getName();
|
||||
rightsString.append(url + " ");
|
||||
}
|
||||
}
|
||||
|
||||
Rights rights = new Rights();
|
||||
rights.setContent(rightsString.toString());
|
||||
rights.setType(ContentType.TEXT);
|
||||
entry.setRights(rights);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -256,73 +256,61 @@ public class DSpaceSWORDServer implements SWORDServer
|
||||
}
|
||||
|
||||
log.info(LogManager.getHeader(context, "sword_authenticate", "username=" + un + ",on_behalf_of=" + obo));
|
||||
try
|
||||
{
|
||||
// attempt to authenticate the primary user
|
||||
SWORDContext sc = new SWORDContext();
|
||||
SWORDAuthentication auth = new SWORDAuthentication();
|
||||
EPerson ep = null;
|
||||
boolean authenticated = false;
|
||||
if (auth.authenticates(this.context, un, pw))
|
||||
{
|
||||
// if authenticated, obtain the eperson object
|
||||
ep = EPerson.findByEmail(context, un);
|
||||
|
||||
if (ep != null)
|
||||
{
|
||||
authenticated = true;
|
||||
sc.setAuthenticated(ep);
|
||||
}
|
||||
|
||||
// if there is an onBehalfOfuser, then find their eperson
|
||||
// record, and if it exists set it. If not, then the
|
||||
// authentication process fails
|
||||
if (obo != null)
|
||||
{
|
||||
EPerson epObo= EPerson.findByEmail(this.context, obo);
|
||||
if (epObo != null)
|
||||
{
|
||||
sc.setOnBehalfOf(epObo);
|
||||
}
|
||||
else
|
||||
{
|
||||
authenticated = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// deal with the context or throw an authentication exception
|
||||
if (ep != null && authenticated)
|
||||
{
|
||||
this.context.setCurrentUser(ep);
|
||||
log.info(LogManager.getHeader(context, "sword_set_authenticated_user", "user_id=" + ep.getID()));
|
||||
}
|
||||
else
|
||||
{
|
||||
// decide what kind of error to throw
|
||||
if (ep != null)
|
||||
{
|
||||
log.info(LogManager.getHeader(context, "sword_unable_to_set_user", "username=" + un));
|
||||
throw new SWORDAuthenticationException("Unable to authenticate the supplied used");
|
||||
}
|
||||
else
|
||||
{
|
||||
log.info(LogManager.getHeader(context, "sword_unable_to_set_on_behalf_of", "username=" + un + ",on_behalf_of=" + obo));
|
||||
throw new SWORDAuthenticationException("Unable to authenticate the onBehalfOf account");
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// attempt to authenticate the primary user
|
||||
SWORDContext sc = new SWORDContext();
|
||||
SWORDAuthentication auth = new SWORDAuthentication();
|
||||
EPerson ep = null;
|
||||
boolean authenticated = false;
|
||||
if (auth.authenticates(this.context, un, pw))
|
||||
{
|
||||
// if authenticated, obtain the eperson object
|
||||
ep = EPerson.findByEmail(context, un);
|
||||
|
||||
if (ep != null)
|
||||
{
|
||||
authenticated = true;
|
||||
sc.setAuthenticated(ep);
|
||||
}
|
||||
|
||||
// if there is an onBehalfOfuser, then find their eperson
|
||||
// record, and if it exists set it. If not, then the
|
||||
// authentication process fails
|
||||
if (obo != null)
|
||||
{
|
||||
EPerson epObo= EPerson.findByEmail(this.context, obo);
|
||||
if (epObo != null)
|
||||
{
|
||||
sc.setOnBehalfOf(epObo);
|
||||
}
|
||||
else
|
||||
{
|
||||
authenticated = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// deal with the context or throw an authentication exception
|
||||
if (ep != null && authenticated)
|
||||
{
|
||||
this.context.setCurrentUser(ep);
|
||||
log.info(LogManager.getHeader(context, "sword_set_authenticated_user", "user_id=" + ep.getID()));
|
||||
}
|
||||
else
|
||||
{
|
||||
// decide what kind of error to throw
|
||||
if (ep != null)
|
||||
{
|
||||
log.info(LogManager.getHeader(context, "sword_unable_to_set_user", "username=" + un));
|
||||
throw new SWORDAuthenticationException("Unable to authenticate the supplied used");
|
||||
}
|
||||
else
|
||||
{
|
||||
log.info(LogManager.getHeader(context, "sword_unable_to_set_on_behalf_of", "username=" + un + ",on_behalf_of=" + obo));
|
||||
throw new SWORDAuthenticationException("Unable to authenticate the onBehalfOf account");
|
||||
}
|
||||
}
|
||||
|
||||
return sc;
|
||||
}
|
||||
}
|
||||
|
@@ -39,7 +39,6 @@
|
||||
package org.dspace.sword;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
@@ -266,11 +265,6 @@ public class DepositManager
|
||||
log.error("authentication problem; caught exception: ", e);
|
||||
throw new DSpaceSWORDException(e);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error("caught exception: ", e);
|
||||
throw new DSpaceSWORDException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -104,27 +104,19 @@ public class SWORDContext
|
||||
* Is the authenticated user a DSpace administrator? This translates
|
||||
* as asking the question of whether the given eperson is a member
|
||||
* of the special DSpace group Administrator, with id 1
|
||||
*
|
||||
* @param eperson
|
||||
*
|
||||
* @return true if administrator, false if not
|
||||
* @throws SQLException
|
||||
*/
|
||||
public boolean isUserAdmin(Context context)
|
||||
throws DSpaceSWORDException
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.authenticated != null)
|
||||
{
|
||||
Group admin = Group.find(context, 1);
|
||||
return admin.isMember(this.authenticated);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
throw new DSpaceSWORDException(e);
|
||||
}
|
||||
if (this.authenticated != null)
|
||||
{
|
||||
Group admin = Group.find(context, 1);
|
||||
return admin.isMember(this.authenticated);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,26 +124,18 @@ public class SWORDContext
|
||||
* as asking the question of whether the given eperson is a member
|
||||
* of the special DSpace group Administrator, with id 1
|
||||
*
|
||||
* @param eperson
|
||||
* @return true if administrator, false if not
|
||||
* @throws SQLException
|
||||
*/
|
||||
public boolean isOnBehalfOfAdmin(Context context)
|
||||
throws DSpaceSWORDException
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.onBehalfOf != null)
|
||||
{
|
||||
Group admin = Group.find(context, 1);
|
||||
return admin.isMember(this.onBehalfOf);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
throw new DSpaceSWORDException(e);
|
||||
}
|
||||
if (this.onBehalfOf != null)
|
||||
{
|
||||
Group admin = Group.find(context, 1);
|
||||
return admin.isMember(this.onBehalfOf);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,49 +221,42 @@ public class SWORDContext
|
||||
public Collection[] getAllowedCollections(Context context)
|
||||
throws DSpaceSWORDException
|
||||
{
|
||||
try
|
||||
{
|
||||
// locate the collections to which the authenticated user has ADD rights
|
||||
Collection[] cols = Collection.findAuthorized(context, null, Constants.ADD);
|
||||
// locate the collections to which the authenticated user has ADD rights
|
||||
Collection[] cols = Collection.findAuthorized(context, null, Constants.ADD);
|
||||
|
||||
// if there is no onBehalfOf user, just return the list
|
||||
if (this.getOnBehalfOf() == null)
|
||||
{
|
||||
return cols;
|
||||
}
|
||||
|
||||
// if the onBehalfOf user is an administrator, return the list
|
||||
if (this.isOnBehalfOfAdmin(context))
|
||||
{
|
||||
return cols;
|
||||
}
|
||||
|
||||
// if we are here, then we have to filter the list of collections
|
||||
List<Collection> colList = new ArrayList<Collection>();
|
||||
|
||||
for (int i = 0; i < cols.length; i++)
|
||||
{
|
||||
// we check each collection to see if the onBehalfOf user
|
||||
// is permitted to deposit
|
||||
|
||||
// urgh, this is so inefficient, but the authorisation API is
|
||||
// a total hellish nightmare
|
||||
Group subs = cols[i].getSubmitters();
|
||||
if (isOnBehalfOfInGroup(subs))
|
||||
{
|
||||
colList.add(cols[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// now create the new array and return that
|
||||
Collection[] newCols = new Collection[colList.size()];
|
||||
newCols = colList.toArray((Collection[]) newCols);
|
||||
return newCols;
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
throw new DSpaceSWORDException(e);
|
||||
}
|
||||
// if there is no onBehalfOf user, just return the list
|
||||
if (this.getOnBehalfOf() == null)
|
||||
{
|
||||
return cols;
|
||||
}
|
||||
|
||||
// if the onBehalfOf user is an administrator, return the list
|
||||
if (this.isOnBehalfOfAdmin(context))
|
||||
{
|
||||
return cols;
|
||||
}
|
||||
|
||||
// if we are here, then we have to filter the list of collections
|
||||
List<Collection> colList = new ArrayList<Collection>();
|
||||
|
||||
for (int i = 0; i < cols.length; i++)
|
||||
{
|
||||
// we check each collection to see if the onBehalfOf user
|
||||
// is permitted to deposit
|
||||
|
||||
// urgh, this is so inefficient, but the authorisation API is
|
||||
// a total hellish nightmare
|
||||
Group subs = cols[i].getSubmitters();
|
||||
if (isOnBehalfOfInGroup(subs))
|
||||
{
|
||||
colList.add(cols[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// now create the new array and return that
|
||||
Collection[] newCols = new Collection[colList.size()];
|
||||
newCols = colList.toArray((Collection[]) newCols);
|
||||
return newCols;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -54,9 +54,9 @@ import org.dspace.content.packager.PackageParameters;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.PluginManager;
|
||||
import org.dspace.handle.HandleManager;
|
||||
import org.dspace.workflow.WorkflowItem;
|
||||
import org.dspace.workflow.WorkflowManager;
|
||||
import org.dspace.uri.IdentifierService;
|
||||
|
||||
import org.purl.sword.base.Deposit;
|
||||
|
||||
@@ -90,7 +90,7 @@ public class SWORDMETSIngester implements SWORDIngester
|
||||
CollectionLocation cl = new CollectionLocation();
|
||||
Collection collection = cl.getCollection(context, 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") + "; ");
|
||||
|
||||
// load the plugin manager for the required configuration
|
||||
@@ -143,9 +143,10 @@ public class SWORDMETSIngester implements SWORDIngester
|
||||
|
||||
// for some reason, DSpace will not give you the handle automatically,
|
||||
// so we have to look it up
|
||||
String handle = HandleManager.findHandle(context, installedItem);
|
||||
|
||||
message("Ingest successful; ");
|
||||
// String handle = HandleManager.findHandle(context, installedItem);
|
||||
String handle = IdentifierService.getCanonicalForm(installedItem);
|
||||
|
||||
message("Ingest successful; ");
|
||||
message("Item created with internal identifier: " + installedItem.getID() + "; ");
|
||||
if (handle != null)
|
||||
{
|
||||
|
@@ -44,7 +44,6 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.eperson.Group;
|
||||
|
Reference in New Issue
Block a user