diff --git a/dspace-sword/src/main/java/org/dspace/sword/ATOMCollectionGenerator.java b/dspace-sword/src/main/java/org/dspace/sword/ATOMCollectionGenerator.java index 7078ec9487..bb2f357e30 100644 --- a/dspace-sword/src/main/java/org/dspace/sword/ATOMCollectionGenerator.java +++ b/dspace-sword/src/main/java/org/dspace/sword/ATOMCollectionGenerator.java @@ -2,7 +2,7 @@ * The contents of this file are subject to the license and copyright * detailed in the LICENSE and NOTICE files at the root of the source * tree and available online at - * + *
* http://www.dspace.org/license/ */ package org.dspace.sword; @@ -12,30 +12,31 @@ import org.dspace.content.DSpaceObject; /** * @author Richard Jones - * + * * Define an abstract interface for classes wishing to generate ATOM Collections * for SWORD service documents */ public abstract class ATOMCollectionGenerator { - /** the sword service definition */ - protected SWORDService swordService; + /** the sword service definition */ + protected SWORDService swordService; - /** - * Create a new ATOM collection generator using the given sword service. - * - * @param service - */ - public ATOMCollectionGenerator(SWORDService service) - { - this.swordService = service; - } + /** + * Create a new ATOM collection generator using the given sword service. + * + * @param service + */ + public ATOMCollectionGenerator(SWORDService service) + { + this.swordService = service; + } - /** - * Build the ATOM Collection which represents the given DSpace Object. - * - * @param dso - * @throws DSpaceSWORDException - */ - public abstract Collection buildCollection(DSpaceObject dso) throws DSpaceSWORDException; + /** + * Build the ATOM Collection which represents the given DSpace Object. + * + * @param dso + * @throws DSpaceSWORDException + */ + public abstract Collection buildCollection(DSpaceObject dso) + throws DSpaceSWORDException; } diff --git a/dspace-sword/src/main/java/org/dspace/sword/BitstreamEntryGenerator.java b/dspace-sword/src/main/java/org/dspace/sword/BitstreamEntryGenerator.java index 337deeabaf..21b3c6a6db 100644 --- a/dspace-sword/src/main/java/org/dspace/sword/BitstreamEntryGenerator.java +++ b/dspace-sword/src/main/java/org/dspace/sword/BitstreamEntryGenerator.java @@ -2,7 +2,7 @@ * The contents of this file are subject to the license and copyright * detailed in the LICENSE and NOTICE files at the root of the source * tree and available online at - * + *
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -23,251 +23,258 @@ import java.util.List;
/**
* @author Richard Jones
- *
+ *
* Class to generate ATOM Entry documents for DSpace Bitstreams
*/
public class BitstreamEntryGenerator extends DSpaceATOMEntry
{
- /** logger */
- private static Logger log = Logger.getLogger(BitstreamEntryGenerator.class);
+ /** logger */
+ private static Logger log = Logger.getLogger(BitstreamEntryGenerator.class);
- /**
- * Create a new ATOM Entry generator which can provide a SWORD Entry for
- * a bitstream
- *
- * @param service
- */
- protected BitstreamEntryGenerator(SWORDService service)
- {
- super(service);
- log.debug("Create new instance of BitstreamEntryGenerator");
- }
+ /**
+ * Create a new ATOM Entry generator which can provide a SWORD Entry for
+ * a bitstream
+ *
+ * @param service
+ */
+ protected BitstreamEntryGenerator(SWORDService service)
+ {
+ super(service);
+ log.debug("Create new instance of BitstreamEntryGenerator");
+ }
- /**
- * Add all the subject classifications from the bibliographic
- * metadata.
- *
- */
- protected void addCategories()
- {
- // do nothing
- }
+ /**
+ * Add all the subject classifications from the bibliographic
+ * metadata.
+ *
+ */
+ protected void addCategories()
+ {
+ // do nothing
+ }
- /**
- * Set the content type that DSpace received.
- *
- */
- protected void addContentElement()
- throws DSpaceSWORDException
- {
- try
- {
- // get the things we need out of the service
- SWORDUrlManager urlManager = swordService.getUrlManager();
+ /**
+ * Set the content type that DSpace received.
+ *
+ */
+ protected void addContentElement()
+ throws DSpaceSWORDException
+ {
+ try
+ {
+ // get the things we need out of the service
+ SWORDUrlManager urlManager = swordService.getUrlManager();
- // if this is a deposit which is no op we can't do anything here
- if (this.deposit != null && this.deposit.isNoOp())
- {
- return;
- }
+ // if this is a deposit which is no op we can't do anything here
+ if (this.deposit != null && this.deposit.isNoOp())
+ {
+ return;
+ }
- String bsurl = urlManager.getBitstreamUrl(this.bitstream);
- BitstreamFormat bf = null;
- try {
- bf = this.bitstream.getFormat(swordService.getContext());
- } catch (SQLException e) {
- log.error("Exception caught: ", e);
- throw new DSpaceSWORDException(e);
- }
- String format = "application/octet-stream";
- if (bf != null)
- {
- format = bf.getMIMEType();
- }
+ String bsurl = urlManager.getBitstreamUrl(this.bitstream);
+ BitstreamFormat bf = null;
+ try
+ {
+ bf = this.bitstream.getFormat(swordService.getContext());
+ }
+ catch (SQLException e)
+ {
+ log.error("Exception caught: ", e);
+ throw new DSpaceSWORDException(e);
+ }
+ String format = "application/octet-stream";
+ if (bf != null)
+ {
+ format = bf.getMIMEType();
+ }
- Content con = new Content();
- con.setType(format);
- con.setSource(bsurl);
- entry.setContent(con);
+ Content con = new Content();
+ con.setType(format);
+ con.setSource(bsurl);
+ entry.setContent(con);
- log.debug("Adding content element with url=" + bsurl);
- }
- catch (InvalidMediaTypeException e)
- {
- log.error("caught and swallowed exception: ", e);
- // do nothing; we'll live without the content type declaration!
- }
- }
+ log.debug("Adding content element with url=" + bsurl);
+ }
+ catch (InvalidMediaTypeException e)
+ {
+ log.error("caught and swallowed exception: ", e);
+ // do nothing; we'll live without the content type declaration!
+ }
+ }
- /**
- * Add the identifier for the item. If the item object has
- * a handle already assigned, this is used, otherwise, the
- * passed handle is used. It is set in the form that
- * they can be used to access the resource over http (i.e.
- * a real URL).
- */
- protected void addIdentifier()
- throws DSpaceSWORDException
- {
- // if this is a deposit which is no op we can't do anything here
- if (this.deposit != null && this.deposit.isNoOp())
- {
- // just use the dspace url as the
- // property
- String cfg = ConfigurationManager.getProperty("dspace.url");
- entry.setId(cfg);
+ /**
+ * Add the identifier for the item. If the item object has
+ * a handle already assigned, this is used, otherwise, the
+ * passed handle is used. It is set in the form that
+ * they can be used to access the resource over http (i.e.
+ * a real URL).
+ */
+ protected void addIdentifier()
+ throws DSpaceSWORDException
+ {
+ // if this is a deposit which is no op we can't do anything here
+ if (this.deposit != null && this.deposit.isNoOp())
+ {
+ // just use the dspace url as the
+ // property
+ String cfg = ConfigurationManager.getProperty("dspace.url");
+ entry.setId(cfg);
- return;
- }
+ return;
+ }
+ SWORDUrlManager urlManager = swordService.getUrlManager();
- SWORDUrlManager urlManager = swordService.getUrlManager();
+ // for a bitstream, we just use the url for the bitstream
+ // as the identifier
+ String bsurl = urlManager.getBitstreamUrl(this.bitstream);
+ entry.setId(bsurl);
+ log.debug("Added identifier for bitstream with url=" + bsurl);
+ return;
- // for a bitstream, we just use the url for the bitstream
- // as the identifier
- String bsurl = urlManager.getBitstreamUrl(this.bitstream);
- entry.setId(bsurl);
- log.debug("Added identifier for bitstream with url=" + bsurl);
- return;
+ // FIXME: later on we will maybe have a workflow page supplied
+ // by the sword interface?
+ }
- // FIXME: later on we will maybe have a workflow page supplied
- // by the sword interface?
- }
+ /**
+ * Add links associated with this item.
+ *
+ */
+ protected void addLinks()
+ throws DSpaceSWORDException
+ {
+ // if this is a deposit which is no op we can't do anything here
+ if (this.deposit != null && this.deposit.isNoOp())
+ {
+ return;
+ }
- /**
- * Add links associated with this item.
- *
- */
- protected void addLinks()
- throws DSpaceSWORDException
- {
- // if this is a deposit which is no op we can't do anything here
- if (this.deposit != null && this.deposit.isNoOp())
- {
- return;
- }
+ // get the things we need out of the service
+ SWORDUrlManager urlManager = swordService.getUrlManager();
- // get the things we need out of the service
- SWORDUrlManager urlManager = swordService.getUrlManager();
+ String bsurl = urlManager.getBitstreamUrl(this.bitstream);
+ BitstreamFormat bf;
+ try
+ {
+ bf = this.bitstream.getFormat(swordService.getContext());
+ }
+ catch (SQLException e)
+ {
+ log.error("Exception caught: ", e);
+ throw new DSpaceSWORDException(e);
+ }
+ String format = "application/octet-stream";
+ if (bf != null)
+ {
+ format = bf.getMIMEType();
+ }
- String bsurl = urlManager.getBitstreamUrl(this.bitstream);
- BitstreamFormat bf;
- try {
- bf = this.bitstream.getFormat(swordService.getContext());
- } catch (SQLException e) {
- log.error("Exception caught: ", e);
- throw new DSpaceSWORDException(e);
- }
- String format = "application/octet-stream";
- if (bf != null)
- {
- format = bf.getMIMEType();
- }
+ Link link = new Link();
+ link.setType(format);
+ link.setHref(bsurl);
+ link.setRel("alternate");
+ entry.addLink(link);
- Link link = new Link();
- link.setType(format);
- link.setHref(bsurl);
- link.setRel("alternate");
- entry.addLink(link);
+ log.debug("Added link entity to entry for url " + bsurl);
+ }
- log.debug("Added link entity to entry for url " + bsurl);
- }
+ /**
+ * Add the date of publication from the bibliographic metadata
+ *
+ */
+ protected void addPublishDate()
+ {
+ // do nothing
+ }
- /**
- * Add the date of publication from the bibliographic metadata
- *
- */
- protected void addPublishDate()
- {
- // do nothing
- }
+ /**
+ * Add rights information. This attaches an href to the URL
+ * of the item's licence file
+ *
+ */
+ protected void addRights()
+ throws DSpaceSWORDException
+ {
+ try
+ {
+ // work our way up to the item
+ List
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -24,111 +24,120 @@ import java.util.List;
*/
public class CollectionCollectionGenerator extends ATOMCollectionGenerator
{
- /** logger */
- private static Logger log = Logger.getLogger(CollectionCollectionGenerator.class);
- protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
+ /** logger */
+ private static Logger log = Logger
+ .getLogger(CollectionCollectionGenerator.class);
- /**
- * Construct an object taking the sword service instance an argument
- * @param service
- */
- public CollectionCollectionGenerator(SWORDService service)
- {
- super(service);
- log.debug("Create new instance of CollectionCollectionGenerator");
- }
+ protected CollectionService collectionService = ContentServiceFactory
+ .getInstance().getCollectionService();
- /**
- * Build the collection for the given DSpaceObject. In this implementation,
- * if the object is not a DSpace Collection, it will throw an exception.
- * @param dso
- * @throws DSpaceSWORDException
- */
- public Collection buildCollection(DSpaceObject dso) throws DSpaceSWORDException
- {
- if (!(dso instanceof org.dspace.content.Collection))
- {
- log.error("buildCollection passed argument which is not of type Collection");
- throw new DSpaceSWORDException("Incorrect ATOMCollectionGenerator instantiated");
- }
+ /**
+ * Construct an object taking the sword service instance an argument
+ * @param service
+ */
+ public CollectionCollectionGenerator(SWORDService service)
+ {
+ super(service);
+ log.debug("Create new instance of CollectionCollectionGenerator");
+ }
- // get the things we need out of the service
- SWORDConfiguration swordConfig = swordService.getSwordConfig();
- SWORDUrlManager urlManager = swordService.getUrlManager();
+ /**
+ * Build the collection for the given DSpaceObject. In this implementation,
+ * if the object is not a DSpace Collection, it will throw an exception.
+ * @param dso
+ * @throws DSpaceSWORDException
+ */
+ public Collection buildCollection(DSpaceObject dso)
+ throws DSpaceSWORDException
+ {
+ if (!(dso instanceof org.dspace.content.Collection))
+ {
+ log.error(
+ "buildCollection passed argument which is not of type Collection");
+ throw new DSpaceSWORDException(
+ "Incorrect ATOMCollectionGenerator instantiated");
+ }
- org.dspace.content.Collection col = (org.dspace.content.Collection) dso;
+ // get the things we need out of the service
+ SWORDConfiguration swordConfig = swordService.getSwordConfig();
+ SWORDUrlManager urlManager = swordService.getUrlManager();
- Collection scol = new Collection();
+ org.dspace.content.Collection col = (org.dspace.content.Collection) dso;
- // prepare the parameters to be put in the sword collection
- String location = urlManager.getDepositLocation(col);
+ Collection scol = new Collection();
- // collection title is just its name
- String title = collectionService.getMetadata(col, "name");
+ // prepare the parameters to be put in the sword collection
+ String location = urlManager.getDepositLocation(col);
- // the collection policy is the licence to which the collection adheres
- String collectionPolicy = collectionService.getLicense(col);
+ // collection title is just its name
+ String title = collectionService.getMetadata(col, "name");
- // FIXME: what is the treatment? Doesn't seem appropriate for DSpace
- // String treatment = " ";
+ // the collection policy is the licence to which the collection adheres
+ String collectionPolicy = collectionService.getLicense(col);
- // abstract is the short description of the collection
- String dcAbstract = collectionService.getMetadata(col, "short_description");
+ // FIXME: what is the treatment? Doesn't seem appropriate for DSpace
+ // String treatment = " ";
- // we just do support mediation
- boolean mediation = swordConfig.isMediated();
+ // abstract is the short description of the collection
+ String dcAbstract = collectionService
+ .getMetadata(col, "short_description");
- // load up the sword collection
- scol.setLocation(location);
+ // we just do support mediation
+ boolean mediation = swordConfig.isMediated();
- // add the title if it exists
- if (title != null && !"".equals(title))
- {
- scol.setTitle(title);
- }
+ // load up the sword collection
+ scol.setLocation(location);
- // add the collection policy if it exists
- if (collectionPolicy != null && !"".equals(collectionPolicy))
- {
- scol.setCollectionPolicy(collectionPolicy);
- }
+ // add the title if it exists
+ if (title != null && !"".equals(title))
+ {
+ scol.setTitle(title);
+ }
- // FIXME: leave the treatment out for the time being,
- // as there is no analogue
- // scol.setTreatment(treatment);
+ // add the collection policy if it exists
+ if (collectionPolicy != null && !"".equals(collectionPolicy))
+ {
+ scol.setCollectionPolicy(collectionPolicy);
+ }
- // add the abstract if it exists
- if (dcAbstract != null && !"".equals(dcAbstract))
- {
- scol.setAbstract(dcAbstract);
- }
+ // FIXME: leave the treatment out for the time being,
+ // as there is no analogue
+ // scol.setTreatment(treatment);
- scol.setMediation(mediation);
+ // add the abstract if it exists
+ if (dcAbstract != null && !"".equals(dcAbstract))
+ {
+ scol.setAbstract(dcAbstract);
+ }
- List
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -40,130 +40,152 @@ import java.util.List;
*/
public class CollectionDepositor extends Depositor
{
- /** logger */
- private static Logger log = Logger.getLogger(CollectionDepositor.class);
+ /** logger */
+ private static Logger log = Logger.getLogger(CollectionDepositor.class);
- protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
- protected BundleService bundleService = ContentServiceFactory.getInstance().getBundleService();
- protected BitstreamService bitstreamService = ContentServiceFactory.getInstance().getBitstreamService();
- protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService();
+ protected ItemService itemService = ContentServiceFactory.getInstance()
+ .getItemService();
- /**
- * The DSpace Collection we are depositing into
- */
- private Collection collection;
+ protected BundleService bundleService = ContentServiceFactory.getInstance()
+ .getBundleService();
- /**
- * Construct a depositor for the given service instance on the
- * given DSpaceObject. If the DSpaceObject is not an instance of Collection
- * this constructor will throw an Exception
- *
- * @param swordService
- * @param dso
- * @throws DSpaceSWORDException
- */
- public CollectionDepositor(SWORDService swordService, DSpaceObject dso)
- throws DSpaceSWORDException
- {
- super(swordService, dso);
+ protected BitstreamService bitstreamService = ContentServiceFactory
+ .getInstance().getBitstreamService();
- if (!(dso instanceof Collection))
- {
- throw new DSpaceSWORDException("You tried to initialise the collection depositor with something" +
- "other than a collection object");
- }
+ protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory
+ .getInstance().getBitstreamFormatService();
- this.collection = (Collection) dso;
+ /**
+ * The DSpace Collection we are depositing into
+ */
+ private Collection collection;
- log.debug("Created instance of CollectionDepositor");
- }
+ /**
+ * Construct a depositor for the given service instance on the
+ * given DSpaceObject. If the DSpaceObject is not an instance of Collection
+ * this constructor will throw an Exception
+ *
+ * @param swordService
+ * @param dso
+ * @throws DSpaceSWORDException
+ */
+ public CollectionDepositor(SWORDService swordService, DSpaceObject dso)
+ throws DSpaceSWORDException
+ {
+ super(swordService, dso);
- /**
- * Perform a deposit, using the supplied SWORD Deposit object.
- *
- * @param deposit
- * @throws SWORDErrorException
- * @throws DSpaceSWORDException
- */
- public DepositResult doDeposit(Deposit deposit)
- throws SWORDErrorException, DSpaceSWORDException
- {
- // get the things out of the service that we need
- Context context = swordService.getContext();
- SWORDConfiguration swordConfig = swordService.getSwordConfig();
- SWORDUrlManager urlManager = swordService.getUrlManager();
+ if (!(dso instanceof Collection))
+ {
+ throw new DSpaceSWORDException(
+ "You tried to initialise the collection depositor with something" +
+ "other than a collection object");
+ }
- // FIXME: the spec is unclear what to do in this situation. I'm going
- // the throw a 415 (ERROR_CONTENT) until further notice
- //
- // determine if this is an acceptable file format
- if (!swordConfig.isAcceptableContentType(context, deposit.getContentType(), collection))
- {
- log.error("Unacceptable content type detected: " + deposit.getContentType() + " for collection " + collection.getID());
- throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT,
- "Unacceptable content type in deposit request: " + deposit.getContentType());
- }
+ this.collection = (Collection) dso;
- // determine if this is an acceptable packaging type for the deposit
- // if not, we throw a 415 HTTP error (Unsupported Media Type, ERROR_CONTENT)
- if (!swordConfig.isSupportedMediaType(deposit.getPackaging(), this.collection))
- {
- log.error("Unacceptable packaging type detected: " + deposit.getPackaging() + "for collection" + collection.getID());
- throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT,
- "Unacceptable packaging type in deposit request: " + deposit.getPackaging());
- }
+ log.debug("Created instance of CollectionDepositor");
+ }
- // Obtain the relevant ingester from the factory
- SWORDIngester si = SWORDIngesterFactory.getInstance(context, deposit, collection);
- swordService.message("Loaded ingester: " + si.getClass().getName());
+ /**
+ * Perform a deposit, using the supplied SWORD Deposit object.
+ *
+ * @param deposit
+ * @throws SWORDErrorException
+ * @throws DSpaceSWORDException
+ */
+ public DepositResult doDeposit(Deposit deposit)
+ throws SWORDErrorException, DSpaceSWORDException
+ {
+ // get the things out of the service that we need
+ Context context = swordService.getContext();
+ SWORDConfiguration swordConfig = swordService.getSwordConfig();
+ SWORDUrlManager urlManager = swordService.getUrlManager();
- // do the deposit
- DepositResult result = si.ingest(swordService, deposit, collection);
- swordService.message("Archive ingest completed successfully");
+ // FIXME: the spec is unclear what to do in this situation. I'm going
+ // the throw a 415 (ERROR_CONTENT) until further notice
+ //
+ // determine if this is an acceptable file format
+ if (!swordConfig
+ .isAcceptableContentType(context, deposit.getContentType(),
+ collection))
+ {
+ log.error("Unacceptable content type detected: " +
+ deposit.getContentType() + " for collection " +
+ collection.getID());
+ throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT,
+ "Unacceptable content type in deposit request: " +
+ deposit.getContentType());
+ }
- // if there's an item availalble, and we want to keep the original
- // then do that
- try
- {
- if (swordConfig.isKeepOriginal())
- {
- swordService.message("DSpace will store an original copy of the deposit, " +
- "as well as ingesting the item into the archive");
+ // determine if this is an acceptable packaging type for the deposit
+ // if not, we throw a 415 HTTP error (Unsupported Media Type, ERROR_CONTENT)
+ if (!swordConfig
+ .isSupportedMediaType(deposit.getPackaging(), this.collection))
+ {
+ log.error("Unacceptable packaging type detected: " +
+ deposit.getPackaging() + "for collection" +
+ collection.getID());
+ throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT,
+ "Unacceptable packaging type in deposit request: " +
+ deposit.getPackaging());
+ }
- // in order to be allowed to add the file back to the item, we need to ignore authorisations
- // for a moment
- context.turnOffAuthorisationSystem();
+ // Obtain the relevant ingester from the factory
+ SWORDIngester si = SWORDIngesterFactory
+ .getInstance(context, deposit, collection);
+ swordService.message("Loaded ingester: " + si.getClass().getName());
- String bundleName = ConfigurationManager.getProperty("sword-server", "bundle.name");
- if (bundleName == null || "".equals(bundleName))
- {
- bundleName = "SWORD";
- }
- Item item = result.getItem();
- List
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -25,117 +25,125 @@ import org.dspace.handle.service.HandleService;
* This class provides a single point of contact for
* resolving Collections from SWORD Deposit URLs and for
* generating SWORD Deposit URLs from Collections
- *
+ *
* @author Richard Jones
*
*/
public class CollectionLocation
{
- /** Log4j logger */
- public static final Logger log = Logger.getLogger(CollectionLocation.class);
+ /** Log4j logger */
+ public static final Logger log = Logger.getLogger(CollectionLocation.class);
- protected HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
+ protected HandleService handleService = HandleServiceFactory.getInstance()
+ .getHandleService();
- /**
- * Obtain the deposit URL for the given collection. These URLs
- * should not be considered persistent, but will remain consistent
- * unless configuration changes are made to DSpace
- *
- * @param collection
- * @return The Deposit URL
- * @throws DSpaceSWORDException
- */
- public String getLocation(Collection collection)
- throws DSpaceSWORDException
- {
- return this.getBaseUrl() + "/" + collection.getHandle();
- }
-
- /**
- * Obtain the collection which is represented by the given
- * URL
- *
- * @param context the DSpace context
- * @param location the URL to resolve to a collection
- * @return The collection to which the url resolves
- * @throws DSpaceSWORDException
- */
- public Collection getCollection(Context context, String location)
- throws DSpaceSWORDException
- {
- try
- {
- String baseUrl = this.getBaseUrl();
- if (baseUrl.length() == location.length())
- {
- 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");
- }
+ /**
+ * Obtain the deposit URL for the given collection. These URLs
+ * should not be considered persistent, but will remain consistent
+ * unless configuration changes are made to DSpace
+ *
+ * @param collection
+ * @return The Deposit URL
+ * @throws DSpaceSWORDException
+ */
+ public String getLocation(Collection collection)
+ throws DSpaceSWORDException
+ {
+ return this.getBaseUrl() + "/" + collection.getHandle();
+ }
- DSpaceObject dso = handleService.resolveToObject(context, handle);
-
- if (!(dso instanceof Collection))
- {
- throw new DSpaceSWORDException("The deposit URL does not resolve to a valid collection");
- }
-
- return (Collection) dso;
- }
- catch (SQLException 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
- * is effectively the URL of the servlet which deals with deposit
- * requests, and is used as the basis for the individual Collection
- * URLs
- *
- * If the configuration sword.deposit.url is set, this will be returned,
- * but if not, it will construct the url as follows:
- *
- * [dspace.baseUrl]/sword/deposit
- *
- * where dspace.baseUrl is also in the configuration file.
- *
- * @return the base URL for sword deposit
- * @throws DSpaceSWORDException
- */
- private String getBaseUrl()
- throws DSpaceSWORDException
- {
- String depositUrl = ConfigurationManager.getProperty("sword-server", "deposit.url");
- if (depositUrl == null || "".equals(depositUrl))
- {
- String dspaceUrl = ConfigurationManager.getProperty("dspace.baseUrl");
- if (dspaceUrl == null || "".equals(dspaceUrl))
- {
- throw new DSpaceSWORDException("Unable to construct deposit urls, due to missing/invalid config in sword.deposit.url and/or dspace.baseUrl");
- }
+ /**
+ * Obtain the collection which is represented by the given
+ * URL
+ *
+ * @param context the DSpace context
+ * @param location the URL to resolve to a collection
+ * @return The collection to which the url resolves
+ * @throws DSpaceSWORDException
+ */
+ public Collection getCollection(Context context, String location)
+ throws DSpaceSWORDException
+ {
+ try
+ {
+ String baseUrl = this.getBaseUrl();
+ if (baseUrl.length() == location.length())
+ {
+ 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 = handleService.resolveToObject(context, handle);
+
+ if (!(dso instanceof Collection))
+ {
+ throw new DSpaceSWORDException(
+ "The deposit URL does not resolve to a valid collection");
+ }
+
+ return (Collection) dso;
+ }
+ catch (SQLException 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
+ * is effectively the URL of the servlet which deals with deposit
+ * requests, and is used as the basis for the individual Collection
+ * URLs
+ *
+ * If the configuration sword.deposit.url is set, this will be returned,
+ * but if not, it will construct the url as follows:
+ *
+ * [dspace.baseUrl]/sword/deposit
+ *
+ * where dspace.baseUrl is also in the configuration file.
+ *
+ * @return the base URL for sword deposit
+ * @throws DSpaceSWORDException
+ */
+ private String getBaseUrl()
+ throws DSpaceSWORDException
+ {
+ String depositUrl = ConfigurationManager
+ .getProperty("sword-server", "deposit.url");
+ if (depositUrl == null || "".equals(depositUrl))
+ {
+ String dspaceUrl = ConfigurationManager
+ .getProperty("dspace.baseUrl");
+ if (dspaceUrl == null || "".equals(dspaceUrl))
+ {
+ throw new DSpaceSWORDException(
+ "Unable to construct deposit urls, due to missing/invalid config in sword.deposit.url and/or dspace.baseUrl");
+ }
try
{
URL url = new URL(dspaceUrl);
- depositUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), "/sword/deposit").toString();
+ depositUrl = new URL(url.getProtocol(), url.getHost(),
+ url.getPort(), "/sword/deposit").toString();
}
catch (MalformedURLException e)
{
- throw new DSpaceSWORDException("Unable to construct deposit urls, due to invalid dspace.baseUrl " + e.getMessage(),e);
+ throw new DSpaceSWORDException(
+ "Unable to construct deposit urls, due to invalid dspace.baseUrl " +
+ e.getMessage(), e);
}
-
-
- }
- return depositUrl;
- }
+
+ }
+ return depositUrl;
+ }
}
diff --git a/dspace-sword/src/main/java/org/dspace/sword/CommunityCollectionGenerator.java b/dspace-sword/src/main/java/org/dspace/sword/CommunityCollectionGenerator.java
index 8358ef897a..a7aebfc989 100644
--- a/dspace-sword/src/main/java/org/dspace/sword/CommunityCollectionGenerator.java
+++ b/dspace-sword/src/main/java/org/dspace/sword/CommunityCollectionGenerator.java
@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -20,70 +20,75 @@ import java.util.List;
public class CommunityCollectionGenerator extends ATOMCollectionGenerator
{
- private static Logger log = Logger.getLogger(CommunityCollectionGenerator.class);
+ private static Logger log = Logger
+ .getLogger(CommunityCollectionGenerator.class);
- protected CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
+ protected CommunityService communityService = ContentServiceFactory
+ .getInstance().getCommunityService();
- public CommunityCollectionGenerator(SWORDService service)
- {
- super(service);
- log.debug("Created instance of CommunityCollectionGenerator");
- }
+ public CommunityCollectionGenerator(SWORDService service)
+ {
+ super(service);
+ log.debug("Created instance of CommunityCollectionGenerator");
+ }
- public Collection buildCollection(DSpaceObject dso)
- throws DSpaceSWORDException
- {
- if (!(dso instanceof Community))
- {
- log.error("buildCollection passed something other than a Community object");
- throw new DSpaceSWORDException("Incorrect ATOMCollectionGenerator instantiated");
- }
+ public Collection buildCollection(DSpaceObject dso)
+ throws DSpaceSWORDException
+ {
+ if (!(dso instanceof Community))
+ {
+ log.error(
+ "buildCollection passed something other than a Community object");
+ throw new DSpaceSWORDException(
+ "Incorrect ATOMCollectionGenerator instantiated");
+ }
- // get the things we need out of the service
- SWORDConfiguration swordConfig = swordService.getSwordConfig();
- SWORDUrlManager urlManager = swordService.getUrlManager();
+ // get the things we need out of the service
+ SWORDConfiguration swordConfig = swordService.getSwordConfig();
+ SWORDUrlManager urlManager = swordService.getUrlManager();
- Community com = (Community) dso;
- Collection scol = new Collection();
+ Community com = (Community) dso;
+ Collection scol = new Collection();
- // prepare the parameters to be put in the sword collection
- String location = urlManager.getDepositLocation(com);
- scol.setLocation(location);
+ // prepare the parameters to be put in the sword collection
+ String location = urlManager.getDepositLocation(com);
+ scol.setLocation(location);
- // collection title is just the community name
- String title = communityService.getName(com);
- if (StringUtils.isNotBlank(title))
- {
- scol.setTitle(title);
- }
+ // collection title is just the community name
+ String title = communityService.getName(com);
+ if (StringUtils.isNotBlank(title))
+ {
+ scol.setTitle(title);
+ }
- // FIXME: the community has no obvious licence
- // the collection policy is the licence to which the collection adheres
- // String collectionPolicy = col.getLicense();
+ // FIXME: the community has no obvious licence
+ // the collection policy is the licence to which the collection adheres
+ // String collectionPolicy = col.getLicense();
- // abstract is the short description of the collection
- List
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -24,296 +24,297 @@ import org.purl.sword.atom.Generator;
* handles the objects in a default way, but the intention is
* for you to be able to extend the class with your own
* representation if necessary.
- *
+ *
* @author Richard Jones
*
*/
public abstract class DSpaceATOMEntry
{
- /** the SWORD ATOM entry which this class effectively decorates */
- protected SWORDEntry entry;
-
- /** the item this ATOM entry represents */
- protected Item item = null;
+ /** the SWORD ATOM entry which this class effectively decorates */
+ protected SWORDEntry entry;
- /** The bitstream this ATOM entry represents */
- protected Bitstream bitstream = null;
+ /** the item this ATOM entry represents */
+ protected Item item = null;
- /** the deposit result */
- protected DepositResult result = null;
+ /** The bitstream this ATOM entry represents */
+ protected Bitstream bitstream = null;
- /** sword service implementation */
- protected SWORDService swordService;
+ /** the deposit result */
+ protected DepositResult result = null;
- /** the original deposit */
- protected Deposit deposit = null;
+ /** sword service implementation */
+ protected SWORDService swordService;
- /**
- * Create a new atom entry object around the given service
- *
- * @param service
- */
- protected DSpaceATOMEntry(SWORDService service)
- {
- this.swordService = service;
- }
+ /** the original deposit */
+ protected Deposit deposit = null;
- /**
- * Reset all the internal variables of the class to their original values
- */
- public void reset()
- {
- this.entry = new SWORDEntry();
- this.item = null;
- this.bitstream = null;
- this.result = null;
- this.deposit = null;
- }
+ /**
+ * Create a new atom entry object around the given service
+ *
+ * @param service
+ */
+ protected DSpaceATOMEntry(SWORDService service)
+ {
+ this.swordService = service;
+ }
- /**
- * Get the SWORD entry for the given DSpace object. In this case,
- * we should be responding to requests for the media link, so this
- * method will throw an error unless the DSpace object is an instance
- * of the Bitstream.
- *
- * @param dso
- * @throws DSpaceSWORDException
- */
- public SWORDEntry getSWORDEntry(DSpaceObject dso)
- throws DSpaceSWORDException
- {
- // reset the object, just in case
- this.reset();
+ /**
+ * Reset all the internal variables of the class to their original values
+ */
+ public void reset()
+ {
+ this.entry = new SWORDEntry();
+ this.item = null;
+ this.bitstream = null;
+ this.result = null;
+ this.deposit = null;
+ }
- // NOTE: initially this exists just for the purposes of responding to media-link
- // requests, so should only ever respond to entries on Bitstreams
- if (dso instanceof Bitstream)
- {
- this.bitstream = (Bitstream) dso;
- }
- else
- {
- throw new DSpaceSWORDException("Can only recover a sword entry for a bitstream via this method");
- }
+ /**
+ * Get the SWORD entry for the given DSpace object. In this case,
+ * we should be responding to requests for the media link, so this
+ * method will throw an error unless the DSpace object is an instance
+ * of the Bitstream.
+ *
+ * @param dso
+ * @throws DSpaceSWORDException
+ */
+ public SWORDEntry getSWORDEntry(DSpaceObject dso)
+ throws DSpaceSWORDException
+ {
+ // reset the object, just in case
+ this.reset();
- this.constructEntry();
+ // NOTE: initially this exists just for the purposes of responding to media-link
+ // requests, so should only ever respond to entries on Bitstreams
+ if (dso instanceof Bitstream)
+ {
+ this.bitstream = (Bitstream) dso;
+ }
+ else
+ {
+ throw new DSpaceSWORDException(
+ "Can only recover a sword entry for a bitstream via this method");
+ }
- return entry;
- }
+ this.constructEntry();
- /**
- * Construct the SWORDEntry object which represents the given
- * item with the given handle. An argument as to whether this
- * is a NoOp request is required because in that event the
- * assigned identifier for the item will not be added to the
- * SWORDEntry as it will be invalid.
- *
- * @param result the result of the deposit operation
- * @param deposit the original deposit request
- * @return the SWORDEntry for the item
- */
- public SWORDEntry getSWORDEntry(DepositResult result, Deposit deposit)
- throws DSpaceSWORDException
- {
- this.reset();
+ return entry;
+ }
- this.entry = new SWORDEntry();
- this.item = result.getItem();
- this.bitstream = result.getBitstream();
- this.result = result;
- this.deposit = deposit;
+ /**
+ * Construct the SWORDEntry object which represents the given
+ * item with the given handle. An argument as to whether this
+ * is a NoOp request is required because in that event the
+ * assigned identifier for the item will not be added to the
+ * SWORDEntry as it will be invalid.
+ *
+ * @param result the result of the deposit operation
+ * @param deposit the original deposit request
+ * @return the SWORDEntry for the item
+ */
+ public SWORDEntry getSWORDEntry(DepositResult result, Deposit deposit)
+ throws DSpaceSWORDException
+ {
+ this.reset();
- this.constructEntry();
+ this.entry = new SWORDEntry();
+ this.item = result.getItem();
+ this.bitstream = result.getBitstream();
+ this.result = result;
+ this.deposit = deposit;
- return entry;
- }
+ this.constructEntry();
- /**
- * Construct the entry
- *
- * @throws DSpaceSWORDException
- */
- protected void constructEntry()
- throws DSpaceSWORDException
- {
- // set the generator
- this.addGenerator();
+ return entry;
+ }
- // add the authors to the sword entry
- this.addAuthors();
+ /**
+ * Construct the entry
+ *
+ * @throws DSpaceSWORDException
+ */
+ protected void constructEntry()
+ throws DSpaceSWORDException
+ {
+ // set the generator
+ this.addGenerator();
- // add the category information to the sword entry
- this.addCategories();
+ // add the authors to the sword entry
+ this.addAuthors();
- // add a content element to the sword entry
- this.addContentElement();
+ // add the category information to the sword entry
+ this.addCategories();
- // add a packaging element to the sword entry
- this.addPackagingElement();
+ // add a content element to the sword entry
+ this.addContentElement();
- // add contributors (authors plus any other bits) to the sword entry
- this.addContributors();
+ // add a packaging element to the sword entry
+ this.addPackagingElement();
- // add the identifier for the item, if the id is going
- // to be valid by the end of the request
- this.addIdentifier();
+ // add contributors (authors plus any other bits) to the sword entry
+ this.addContributors();
- // add any appropriate links
- this.addLinks();
+ // add the identifier for the item, if the id is going
+ // to be valid by the end of the request
+ this.addIdentifier();
- // add the publish date
- this.addPublishDate();
+ // add any appropriate links
+ this.addLinks();
- // add the rights information
- this.addRights();
+ // add the publish date
+ this.addPublishDate();
- // add the summary of the item
- this.addSummary();
+ // add the rights information
+ this.addRights();
- // add the title of the item
- this.addTitle();
+ // add the summary of the item
+ this.addSummary();
- // add the date on which the entry was last updated
- this.addLastUpdatedDate();
+ // add the title of the item
+ this.addTitle();
- // set the treatment
- this.addTreatment();
- }
+ // add the date on which the entry was last updated
+ this.addLastUpdatedDate();
- /**
- * Add deposit treatment text
- */
- protected void addTreatment()
- {
- if (result != null)
- {
- entry.setTreatment(result.getTreatment());
- }
- }
+ // set the treatment
+ this.addTreatment();
+ }
- /**
- * add the generator field content
- */
- protected void addGenerator()
- {
- boolean identify = ConfigurationManager.getBooleanProperty("sword-server", "identify-version");
- SWORDUrlManager urlManager = swordService.getUrlManager();
- String softwareUri = urlManager.getGeneratorUrl();
- if (identify)
- {
- Generator generator = new Generator();
- generator.setUri(softwareUri);
- generator.setVersion(SWORDProperties.VERSION);
- entry.setGenerator(generator);
- }
- }
+ /**
+ * Add deposit treatment text
+ */
+ protected void addTreatment()
+ {
+ if (result != null)
+ {
+ entry.setTreatment(result.getTreatment());
+ }
+ }
- /**
- * set the packaging format of the deposit
- */
- protected void addPackagingElement()
- {
- if (deposit != null)
- {
- entry.setPackaging(deposit.getPackaging());
- }
- }
+ /**
+ * add the generator field content
+ */
+ protected void addGenerator()
+ {
+ boolean identify = ConfigurationManager
+ .getBooleanProperty("sword-server", "identify-version");
+ SWORDUrlManager urlManager = swordService.getUrlManager();
+ String softwareUri = urlManager.getGeneratorUrl();
+ if (identify)
+ {
+ Generator generator = new Generator();
+ generator.setUri(softwareUri);
+ generator.setVersion(SWORDProperties.VERSION);
+ entry.setGenerator(generator);
+ }
+ }
- /**
- * add the author names from the bibliographic metadata. Does
- * not supply email addresses or URIs, both for privacy, and
- * because the data is not so readily available in DSpace.
- *
- */
- protected void addAuthors()
- {
- if (deposit != null)
- {
- String username = this.deposit.getUsername();
- Author author = new Author();
- author.setName(username);
- entry.addAuthors(author);
- }
- }
+ /**
+ * set the packaging format of the deposit
+ */
+ protected void addPackagingElement()
+ {
+ if (deposit != null)
+ {
+ entry.setPackaging(deposit.getPackaging());
+ }
+ }
- /**
- * Add the list of contributors to the item. This will include
- * the authors, and any other contributors that are supplied
- * in the bibliographic metadata
- *
- */
- protected void addContributors()
- {
- if (deposit != null)
- {
- String obo = deposit.getOnBehalfOf();
- if (obo != null)
- {
- Contributor cont = new Contributor();
- cont.setName(obo);
- entry.addContributor(cont);
- }
- }
- }
+ /**
+ * add the author names from the bibliographic metadata. Does
+ * not supply email addresses or URIs, both for privacy, and
+ * because the data is not so readily available in DSpace.
+ *
+ */
+ protected void addAuthors()
+ {
+ if (deposit != null)
+ {
+ String username = this.deposit.getUsername();
+ Author author = new Author();
+ author.setName(username);
+ entry.addAuthors(author);
+ }
+ }
- /**
- * Add all the subject classifications from the bibliographic
- * metadata.
- *
- */
- abstract void addCategories() throws DSpaceSWORDException;
+ /**
+ * Add the list of contributors to the item. This will include
+ * the authors, and any other contributors that are supplied
+ * in the bibliographic metadata
+ *
+ */
+ protected void addContributors()
+ {
+ if (deposit != null)
+ {
+ String obo = deposit.getOnBehalfOf();
+ if (obo != null)
+ {
+ Contributor cont = new Contributor();
+ cont.setName(obo);
+ entry.addContributor(cont);
+ }
+ }
+ }
- /**
- * Set the content type that DSpace received. This is just
- * "application/zip" in this default implementation.
- *
- */
- abstract void addContentElement() throws DSpaceSWORDException;
+ /**
+ * Add all the subject classifications from the bibliographic
+ * metadata.
+ *
+ */
+ abstract void addCategories() throws DSpaceSWORDException;
+ /**
+ * Set the content type that DSpace received. This is just
+ * "application/zip" in this default implementation.
+ *
+ */
+ abstract void addContentElement() throws DSpaceSWORDException;
- /**
- * Add the identifier for the item. If the item object has
- * a handle already assigned, this is used, otherwise, the
- * passed handle is used. It is set in the form that
- * they can be used to access the resource over http (i.e.
- * a real URL).
- */
- abstract void addIdentifier() throws DSpaceSWORDException;
-
- /**
- * Add links associated with this item.
- *
- */
- abstract void addLinks() throws DSpaceSWORDException;
-
- /**
- * Add the date of publication from the bibliographic metadata
- *
- */
- abstract void addPublishDate() throws DSpaceSWORDException;
+ /**
+ * Add the identifier for the item. If the item object has
+ * a handle already assigned, this is used, otherwise, the
+ * passed handle is used. It is set in the form that
+ * they can be used to access the resource over http (i.e.
+ * a real URL).
+ */
+ abstract void addIdentifier() throws DSpaceSWORDException;
- /**
- * Add rights information. This attaches an href to the URL
- * of the item's licence file
- *
- */
- abstract void addRights() throws DSpaceSWORDException;
+ /**
+ * Add links associated with this item.
+ *
+ */
+ abstract void addLinks() throws DSpaceSWORDException;
- /**
- * Add the summary/abstract from the bibliographic metadata
- *
- */
- abstract void addSummary() throws DSpaceSWORDException;
-
- /**
- * Add the title from the bibliographic metadata
- *
- */
- abstract void addTitle() throws DSpaceSWORDException;
-
- /**
- * Add the date that this item was last updated
- *
- */
- abstract void addLastUpdatedDate() throws DSpaceSWORDException;
+ /**
+ * Add the date of publication from the bibliographic metadata
+ *
+ */
+ abstract void addPublishDate() throws DSpaceSWORDException;
+
+ /**
+ * Add rights information. This attaches an href to the URL
+ * of the item's licence file
+ *
+ */
+ abstract void addRights() throws DSpaceSWORDException;
+
+ /**
+ * Add the summary/abstract from the bibliographic metadata
+ *
+ */
+ abstract void addSummary() throws DSpaceSWORDException;
+
+ /**
+ * Add the title from the bibliographic metadata
+ *
+ */
+ abstract void addTitle() throws DSpaceSWORDException;
+
+ /**
+ * Add the date that this item was last updated
+ *
+ */
+ abstract void addLastUpdatedDate() throws DSpaceSWORDException;
}
diff --git a/dspace-sword/src/main/java/org/dspace/sword/DSpaceSWORDErrorCodes.java b/dspace-sword/src/main/java/org/dspace/sword/DSpaceSWORDErrorCodes.java
index f1905f3294..531ca173b3 100644
--- a/dspace-sword/src/main/java/org/dspace/sword/DSpaceSWORDErrorCodes.java
+++ b/dspace-sword/src/main/java/org/dspace/sword/DSpaceSWORDErrorCodes.java
@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -12,30 +12,38 @@ package org.dspace.sword;
*/
public interface DSpaceSWORDErrorCodes
{
- /** if unpackaging the package fails */
- public static final String UNPACKAGE_FAIL = SWORDProperties.SOFTWARE_URI + "/errors/UnpackageFail";
+ /** if unpackaging the package fails */
+ public static final String UNPACKAGE_FAIL =
+ SWORDProperties.SOFTWARE_URI + "/errors/UnpackageFail";
- /** if the url of the request does not resolve to something meaningful */
- public static final String BAD_URL = SWORDProperties.SOFTWARE_URI + "/errors/BadUrl";
+ /** if the url of the request does not resolve to something meaningful */
+ public static final String BAD_URL =
+ SWORDProperties.SOFTWARE_URI + "/errors/BadUrl";
- /** if the media requested is unavailable */
- public static final String MEDIA_UNAVAILABLE = SWORDProperties.SOFTWARE_URI + "/errors/MediaUnavailable";
+ /** if the media requested is unavailable */
+ public static final String MEDIA_UNAVAILABLE =
+ SWORDProperties.SOFTWARE_URI + "/errors/MediaUnavailable";
/* additional codes */
-
+
/** Invalid package */
- public static final String PACKAGE_ERROR = SWORDProperties.SOFTWARE_URI + "/errors/PackageError";
-
+ public static final String PACKAGE_ERROR =
+ SWORDProperties.SOFTWARE_URI + "/errors/PackageError";
+
/** Missing resources in package */
- public static final String PACKAGE_VALIDATION_ERROR = SWORDProperties.SOFTWARE_URI + "/errors/PackageValidationError";
-
+ public static final String PACKAGE_VALIDATION_ERROR =
+ SWORDProperties.SOFTWARE_URI + "/errors/PackageValidationError";
+
/** Crosswalk error */
- public static final String CROSSWALK_ERROR = SWORDProperties.SOFTWARE_URI + "/errors/CrosswalkError";
-
+ public static final String CROSSWALK_ERROR =
+ SWORDProperties.SOFTWARE_URI + "/errors/CrosswalkError";
+
/** Invalid collection for linking */
- public static final String COLLECTION_LINK_ERROR = SWORDProperties.SOFTWARE_URI + "/errors/CollectionLinkError";
-
+ public static final String COLLECTION_LINK_ERROR =
+ SWORDProperties.SOFTWARE_URI + "/errors/CollectionLinkError";
+
/** Database or IO Error when installing new item */
- public static final String REPOSITORY_ERROR = SWORDProperties.SOFTWARE_URI + "/errors/RepositoryError";
+ public static final String REPOSITORY_ERROR =
+ SWORDProperties.SOFTWARE_URI + "/errors/RepositoryError";
}
diff --git a/dspace-sword/src/main/java/org/dspace/sword/DSpaceSWORDException.java b/dspace-sword/src/main/java/org/dspace/sword/DSpaceSWORDException.java
index f3ca1e80d0..01e4ed63c4 100644
--- a/dspace-sword/src/main/java/org/dspace/sword/DSpaceSWORDException.java
+++ b/dspace-sword/src/main/java/org/dspace/sword/DSpaceSWORDException.java
@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -10,31 +10,31 @@ package org.dspace.sword;
/**
* This Exception class can be thrown by the internals of the
* DSpace SWORD implementation
- *
+ *
* @author Richard Jones
*
*/
public class DSpaceSWORDException extends Exception
{
- public DSpaceSWORDException()
- {
- super();
- }
+ public DSpaceSWORDException()
+ {
+ super();
+ }
- public DSpaceSWORDException(String arg0, Throwable arg1)
- {
- super(arg0, arg1);
- }
+ public DSpaceSWORDException(String arg0, Throwable arg1)
+ {
+ super(arg0, arg1);
+ }
- public DSpaceSWORDException(String arg0)
- {
- super(arg0);
- }
+ public DSpaceSWORDException(String arg0)
+ {
+ super(arg0);
+ }
- public DSpaceSWORDException(Throwable arg0)
- {
- super(arg0);
- }
+ public DSpaceSWORDException(Throwable arg0)
+ {
+ super(arg0);
+ }
}
diff --git a/dspace-sword/src/main/java/org/dspace/sword/DSpaceSWORDServer.java b/dspace-sword/src/main/java/org/dspace/sword/DSpaceSWORDServer.java
index 8eccf1d534..57b52c71f8 100644
--- a/dspace-sword/src/main/java/org/dspace/sword/DSpaceSWORDServer.java
+++ b/dspace-sword/src/main/java/org/dspace/sword/DSpaceSWORDServer.java
@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -26,164 +26,183 @@ import org.purl.sword.base.ServiceDocumentRequest;
/**
* An implementation of the SWORDServer interface to allow SWORD deposit
* operations on DSpace. See:
- *
+ *
* http://www.ukoln.ac.uk/repositories/digirep/index/SWORD_APP_Profile_0.5
- *
+ *
* @author Richard Jones
*/
public class DSpaceSWORDServer implements SWORDServer
{
- /** Log4j logger */
- public static final Logger log = Logger.getLogger(DSpaceSWORDServer.class);
+ /** Log4j logger */
+ public static final Logger log = Logger.getLogger(DSpaceSWORDServer.class);
- // methods required by SWORDServer interface
- ////////////////////////////////////////////
+ // methods required by SWORDServer interface
+ ////////////////////////////////////////////
- /* (non-Javadoc)
- * @see org.purl.sword.SWORDServer#doServiceDocument(org.purl.sword.base.ServiceDocumentRequest)
- */
- public ServiceDocument doServiceDocument(ServiceDocumentRequest request)
- throws SWORDAuthenticationException, SWORDException, SWORDErrorException
- {
- // gah. bloody variable scoping.
- // set up a dummy sword context for the "finally" block
- SWORDContext sc = null;
+ /* (non-Javadoc)
+ * @see org.purl.sword.SWORDServer#doServiceDocument(org.purl.sword.base.ServiceDocumentRequest)
+ */
+ public ServiceDocument doServiceDocument(ServiceDocumentRequest request)
+ throws SWORDAuthenticationException, SWORDException,
+ SWORDErrorException
+ {
+ // gah. bloody variable scoping.
+ // set up a dummy sword context for the "finally" block
+ SWORDContext sc = null;
- try
- {
- // first authenticate the request
- // note: this will build our various DSpace contexts for us
- SWORDAuthenticator auth = new SWORDAuthenticator();
- sc = auth.authenticate(request);
- Context context = sc.getContext();
+ try
+ {
+ // first authenticate the request
+ // note: this will build our various DSpace contexts for us
+ SWORDAuthenticator auth = new SWORDAuthenticator();
+ sc = auth.authenticate(request);
+ Context context = sc.getContext();
- if (log.isDebugEnabled())
- {
- log.debug(LogManager.getHeader(context, "sword_do_service_document", ""));
- }
+ if (log.isDebugEnabled())
+ {
+ log.debug(LogManager
+ .getHeader(context, "sword_do_service_document", ""));
+ }
- // log the request
- log.info(LogManager.getHeader(context, "sword_service_document_request", "username=" + request.getUsername() + ",on_behalf_of=" + request.getOnBehalfOf()));
-
- // prep the service request, then get the service document out of it
- SWORDService service = new SWORDService(sc);
- ServiceDocumentManager manager = new ServiceDocumentManager(service);
- ServiceDocument doc = manager.getServiceDocument(request.getLocation());
-
- return doc;
- }
- catch (DSpaceSWORDException e)
- {
- log.error("caught exception: ", e);
- throw new SWORDException("The DSpace SWORD interface experienced an error", e);
- }
- finally
- {
- // this is a read operation only, so there's never any need to commit the context
+ // log the request
+ log.info(LogManager
+ .getHeader(context, "sword_service_document_request",
+ "username=" + request.getUsername() +
+ ",on_behalf_of=" +
+ request.getOnBehalfOf()));
+
+ // prep the service request, then get the service document out of it
+ SWORDService service = new SWORDService(sc);
+ ServiceDocumentManager manager = new ServiceDocumentManager(
+ service);
+ ServiceDocument doc = manager
+ .getServiceDocument(request.getLocation());
+
+ return doc;
+ }
+ catch (DSpaceSWORDException e)
+ {
+ log.error("caught exception: ", e);
+ throw new SWORDException(
+ "The DSpace SWORD interface experienced an error", e);
+ }
+ finally
+ {
+ // this is a read operation only, so there's never any need to commit the context
if (sc != null)
{
sc.abort();
}
- }
- }
-
- /* (non-Javadoc)
- * @see org.purl.sword.SWORDServer#doSWORDDeposit(org.purl.sword.server.Deposit)
- */
- public DepositResponse doDeposit(Deposit deposit)
- throws SWORDAuthenticationException, SWORDException, SWORDErrorException
- {
- // gah. bloody variable scoping.
- // set up a dummy sword context for the "finally" block
- SWORDContext sc = null;
+ }
+ }
- try
- {
- // first authenticate the request
- // note: this will build our various DSpace contexts for us
- SWORDAuthenticator auth = new SWORDAuthenticator();
- sc = auth.authenticate(deposit);
- Context context = sc.getContext();
+ /* (non-Javadoc)
+ * @see org.purl.sword.SWORDServer#doSWORDDeposit(org.purl.sword.server.Deposit)
+ */
+ public DepositResponse doDeposit(Deposit deposit)
+ throws SWORDAuthenticationException, SWORDException,
+ SWORDErrorException
+ {
+ // gah. bloody variable scoping.
+ // set up a dummy sword context for the "finally" block
+ SWORDContext sc = null;
+
+ try
+ {
+ // first authenticate the request
+ // note: this will build our various DSpace contexts for us
+ SWORDAuthenticator auth = new SWORDAuthenticator();
+ sc = auth.authenticate(deposit);
+ Context context = sc.getContext();
if (log.isDebugEnabled())
- {
- log.debug(LogManager.getHeader(context, "sword_do_deposit", ""));
- }
-
- // log the request
- log.info(LogManager.getHeader(context, "sword_deposit_request", "username=" + deposit.getUsername() + ",on_behalf_of=" + deposit.getOnBehalfOf()));
-
- // prep and execute the deposit
- SWORDService service = new SWORDService(sc);
- service.setVerbose(deposit.isVerbose());
- DepositManager dm = new DepositManager(service);
- DepositResponse response = dm.deposit(deposit);
-
- // if something hasn't killed it already (allowed), then complete the transaction
- sc.commit();
-
- return response;
- }
- catch (DSpaceSWORDException e)
- {
- log.error("caught exception:", e);
- throw new SWORDException("There was a problem depositing the item", e);
- }
- finally
- {
- // if, for some reason, we wind up here with a not null context
- // then abort it (the above should commit it if everything works fine)
- if (sc != null)
+ {
+ log.debug(
+ LogManager.getHeader(context, "sword_do_deposit", ""));
+ }
+
+ // log the request
+ log.info(LogManager.getHeader(context, "sword_deposit_request",
+ "username=" + deposit.getUsername() + ",on_behalf_of=" +
+ deposit.getOnBehalfOf()));
+
+ // prep and execute the deposit
+ SWORDService service = new SWORDService(sc);
+ service.setVerbose(deposit.isVerbose());
+ DepositManager dm = new DepositManager(service);
+ DepositResponse response = dm.deposit(deposit);
+
+ // if something hasn't killed it already (allowed), then complete the transaction
+ sc.commit();
+
+ return response;
+ }
+ catch (DSpaceSWORDException e)
+ {
+ log.error("caught exception:", e);
+ throw new SWORDException("There was a problem depositing the item",
+ e);
+ }
+ finally
+ {
+ // if, for some reason, we wind up here with a not null context
+ // then abort it (the above should commit it if everything works fine)
+ if (sc != null)
{
sc.abort();
}
- }
- }
+ }
+ }
- /* (non-Javadoc)
- * @see org.purl.sword.SWORDServer#doSWORDDeposit(org.purl.sword.server.Deposit)
- */
- public AtomDocumentResponse doAtomDocument(AtomDocumentRequest adr)
- throws SWORDAuthenticationException, SWORDException, SWORDErrorException
- {
- // gah. bloody variable scoping.
- // set up a dummy sword context for the "finally" block
- SWORDContext sc = null;
+ /* (non-Javadoc)
+ * @see org.purl.sword.SWORDServer#doSWORDDeposit(org.purl.sword.server.Deposit)
+ */
+ public AtomDocumentResponse doAtomDocument(AtomDocumentRequest adr)
+ throws SWORDAuthenticationException, SWORDException,
+ SWORDErrorException
+ {
+ // gah. bloody variable scoping.
+ // set up a dummy sword context for the "finally" block
+ SWORDContext sc = null;
- try
- {
- // first authenticate the request
- // note: this will build our various DSpace contexts for us
- SWORDAuthenticator auth = new SWORDAuthenticator();
- sc = auth.authenticate(adr);
- Context context = sc.getContext();
+ try
+ {
+ // first authenticate the request
+ // note: this will build our various DSpace contexts for us
+ SWORDAuthenticator auth = new SWORDAuthenticator();
+ sc = auth.authenticate(adr);
+ Context context = sc.getContext();
- if (log.isDebugEnabled())
- {
- log.debug(LogManager.getHeader(context, "sword_do_atom_document", ""));
- }
+ if (log.isDebugEnabled())
+ {
+ log.debug(LogManager
+ .getHeader(context, "sword_do_atom_document", ""));
+ }
- // log the request
- log.info(LogManager.getHeader(context, "sword_atom_document_request", "username=" + adr.getUsername()));
+ // log the request
+ log.info(LogManager
+ .getHeader(context, "sword_atom_document_request",
+ "username=" + adr.getUsername()));
- // prep the service request, then get the service document out of it
- SWORDService service = new SWORDService(sc);
- MediaEntryManager manager = new MediaEntryManager(service);
+ // prep the service request, then get the service document out of it
+ SWORDService service = new SWORDService(sc);
+ MediaEntryManager manager = new MediaEntryManager(service);
- return manager.getMediaEntry(adr.getLocation());
- }
- catch (DSpaceSWORDException e)
- {
- log.error("caught exception: ", e);
- throw new SWORDException("The DSpace SWORD interface experienced an error", e);
- }
- finally
- {
- // this is a read operation only, so there's never any need to commit the context
- if (sc != null)
+ return manager.getMediaEntry(adr.getLocation());
+ }
+ catch (DSpaceSWORDException e)
+ {
+ log.error("caught exception: ", e);
+ throw new SWORDException(
+ "The DSpace SWORD interface experienced an error", e);
+ }
+ finally
+ {
+ // this is a read operation only, so there's never any need to commit the context
+ if (sc != null)
{
sc.abort();
}
- }
- }
+ }
+ }
}
diff --git a/dspace-sword/src/main/java/org/dspace/sword/DepositManager.java b/dspace-sword/src/main/java/org/dspace/sword/DepositManager.java
index be5e401ea5..5635bf2e29 100644
--- a/dspace-sword/src/main/java/org/dspace/sword/DepositManager.java
+++ b/dspace-sword/src/main/java/org/dspace/sword/DepositManager.java
@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -32,119 +32,135 @@ import org.purl.sword.base.SWORDErrorException;
/**
* This class is responsible for initiating the process of
* deposit of SWORD Deposit objects into the DSpace repository
- *
+ *
* @author Richard Jones
*
*/
public class DepositManager
{
- /** Log4j logger */
- public static final Logger log = Logger.getLogger(DepositManager.class);
+ /** Log4j logger */
+ public static final Logger log = Logger.getLogger(DepositManager.class);
- /** The SWORD service implementation */
- private SWORDService swordService;
+ /** The SWORD service implementation */
+ private SWORDService swordService;
- /**
- * Construct a new DepositManager using the given instantiation of
- * the SWORD service implementation
- *
- * @param service
- */
- public DepositManager(SWORDService service)
- {
- this.swordService = service;
- log.debug("Created instance of DepositManager");
- }
+ /**
+ * Construct a new DepositManager using the given instantiation of
+ * the SWORD service implementation
+ *
+ * @param service
+ */
+ public DepositManager(SWORDService service)
+ {
+ this.swordService = service;
+ log.debug("Created instance of DepositManager");
+ }
- public DSpaceObject getDepositTarget(Deposit deposit)
- throws DSpaceSWORDException, SWORDErrorException
- {
- SWORDUrlManager urlManager = swordService.getUrlManager();
- Context context = swordService.getContext();
+ public DSpaceObject getDepositTarget(Deposit deposit)
+ throws DSpaceSWORDException, SWORDErrorException
+ {
+ SWORDUrlManager urlManager = swordService.getUrlManager();
+ Context context = swordService.getContext();
- // get the target collection
- String loc = deposit.getLocation();
- DSpaceObject dso = urlManager.getDSpaceObject(context, loc);
+ // get the target collection
+ String loc = deposit.getLocation();
+ DSpaceObject dso = urlManager.getDSpaceObject(context, loc);
- swordService.message("Performing deposit using location: " + loc);
+ swordService.message("Performing deposit using location: " + loc);
- if (dso instanceof Collection)
- {
- CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
- swordService.message("Location resolves to collection with handle: " + dso.getHandle() +
- " and name: " + collectionService.getName((Collection) dso));
- }
- else if (dso instanceof Item)
- {
- swordService.message("Location resolves to item with handle: " + dso.getHandle());
- }
+ if (dso instanceof Collection)
+ {
+ CollectionService collectionService = ContentServiceFactory
+ .getInstance().getCollectionService();
+ swordService.message(
+ "Location resolves to collection with handle: " +
+ dso.getHandle() +
+ " and name: " +
+ collectionService.getName((Collection) dso));
+ }
+ else if (dso instanceof Item)
+ {
+ swordService.message("Location resolves to item with handle: " +
+ dso.getHandle());
+ }
- return dso;
- }
+ return dso;
+ }
- /**
- * Once this object is fully prepared, this method will execute
- * the deposit process. The returned DepositRequest can be
- * used then to assemble the SWORD response.
- *
- * @return the response to the deposit request
- * @throws DSpaceSWORDException
- */
- public DepositResponse deposit(Deposit deposit)
- throws DSpaceSWORDException, SWORDErrorException, SWORDAuthenticationException
- {
- // start the timer, and initialise the verboseness of the request
- Date start = new Date();
- swordService.message("Initialising verbose deposit");
+ /**
+ * Once this object is fully prepared, this method will execute
+ * the deposit process. The returned DepositRequest can be
+ * used then to assemble the SWORD response.
+ *
+ * @return the response to the deposit request
+ * @throws DSpaceSWORDException
+ */
+ public DepositResponse deposit(Deposit deposit)
+ throws DSpaceSWORDException, SWORDErrorException,
+ SWORDAuthenticationException
+ {
+ // start the timer, and initialise the verboseness of the request
+ Date start = new Date();
+ swordService.message("Initialising verbose deposit");
- // get the things out of the service that we need
- SWORDContext swordContext = swordService.getSwordContext();
- Context context = swordService.getContext();
+ // get the things out of the service that we need
+ SWORDContext swordContext = swordService.getSwordContext();
+ Context context = swordService.getContext();
- // get the deposit target
- DSpaceObject dso = this.getDepositTarget(deposit);
+ // get the deposit target
+ DSpaceObject dso = this.getDepositTarget(deposit);
- // find out if the supplied SWORDContext can submit to the given
- // dspace object
- SWORDAuthenticator auth = new SWORDAuthenticator();
- if (!auth.canSubmit(swordService, deposit, dso))
- {
- // throw an exception if the deposit can't be made
- String oboEmail = "none";
- if (swordContext.getOnBehalfOf() != null)
- {
- oboEmail = swordContext.getOnBehalfOf().getEmail();
- }
- log.info(LogManager.getHeader(context, "deposit_failed_authorisation", "user=" +
- swordContext.getAuthenticated().getEmail() + ",on_behalf_of=" + oboEmail));
- throw new SWORDAuthenticationException("Cannot submit to the given collection with this context");
- }
+ // find out if the supplied SWORDContext can submit to the given
+ // dspace object
+ SWORDAuthenticator auth = new SWORDAuthenticator();
+ if (!auth.canSubmit(swordService, deposit, dso))
+ {
+ // throw an exception if the deposit can't be made
+ String oboEmail = "none";
+ if (swordContext.getOnBehalfOf() != null)
+ {
+ oboEmail = swordContext.getOnBehalfOf().getEmail();
+ }
+ log.info(LogManager
+ .getHeader(context, "deposit_failed_authorisation",
+ "user=" +
+ swordContext.getAuthenticated().getEmail() +
+ ",on_behalf_of=" + oboEmail));
+ throw new SWORDAuthenticationException(
+ "Cannot submit to the given collection with this context");
+ }
- // make a note of the authentication in the verbose string
- swordService.message("Authenticated user: " + swordContext.getAuthenticated().getEmail());
- if (swordContext.getOnBehalfOf() != null)
- {
- swordService.message("Depositing on behalf of: " + swordContext.getOnBehalfOf().getEmail());
- }
+ // make a note of the authentication in the verbose string
+ swordService.message("Authenticated user: " +
+ swordContext.getAuthenticated().getEmail());
+ if (swordContext.getOnBehalfOf() != null)
+ {
+ swordService.message("Depositing on behalf of: " +
+ swordContext.getOnBehalfOf().getEmail());
+ }
- // determine which deposit engine we initialise
- Depositor dep = null;
- if (dso instanceof Collection)
- {
- swordService.message("Initialising depositor for an Item in a Collection");
- dep = new CollectionDepositor(swordService, dso);
- }
- else if (dso instanceof Item)
- {
- swordService.message("Initialising depositor for a Bitstream in an Item");
- dep = new ItemDepositor(swordService, dso);
- }
+ // determine which deposit engine we initialise
+ Depositor dep = null;
+ if (dso instanceof Collection)
+ {
+ swordService.message(
+ "Initialising depositor for an Item in a Collection");
+ dep = new CollectionDepositor(swordService, dso);
+ }
+ else if (dso instanceof Item)
+ {
+ swordService.message(
+ "Initialising depositor for a Bitstream in an Item");
+ dep = new ItemDepositor(swordService, dso);
+ }
- if (dep == null)
- {
- log.error("The specified deposit target does not exist, or is not a collection or an item");
- throw new DSpaceSWORDException("Deposit target is not a collection or an item");
- }
+ if (dep == null)
+ {
+ log.error(
+ "The specified deposit target does not exist, or is not a collection or an item");
+ throw new DSpaceSWORDException(
+ "Deposit target is not a collection or an item");
+ }
DepositResult result = null;
@@ -160,7 +176,7 @@ public class DepositManager
{
storePackageAsFile(deposit);
}
- catch(IOException e2)
+ catch (IOException e2)
{
log.warn("Unable to store SWORD package as file: " + e);
}
@@ -168,58 +184,64 @@ public class DepositManager
throw e;
}
- // now construct the deposit response. The response will be
- // CREATED if the deposit is in the archive, or ACCEPTED if
- // the deposit is in the workflow. We use a separate record
- // for the handle because DSpace will not supply the Item with
- // a record of the handle straight away.
- String handle = result.getHandle();
- int state = Deposit.CREATED;
- if (StringUtils.isBlank(handle))
- {
- state = Deposit.ACCEPTED;
- }
-
- DepositResponse response = new DepositResponse(state);
- response.setLocation(result.getMediaLink());
+ // now construct the deposit response. The response will be
+ // CREATED if the deposit is in the archive, or ACCEPTED if
+ // the deposit is in the workflow. We use a separate record
+ // for the handle because DSpace will not supply the Item with
+ // a record of the handle straight away.
+ String handle = result.getHandle();
+ int state = Deposit.CREATED;
+ if (StringUtils.isBlank(handle))
+ {
+ state = Deposit.ACCEPTED;
+ }
- DSpaceATOMEntry dsatom = null;
- if (result.getItem() != null)
- {
- swordService.message("Initialising ATOM entry generator for an Item");
- dsatom = new ItemEntryGenerator(swordService);
- }
- else if (result.getBitstream() != null)
- {
- swordService.message("Initialising ATOM entry generator for a Bitstream");
- dsatom = new BitstreamEntryGenerator(swordService);
- }
- if (dsatom == null)
- {
- log.error("The deposit failed, see exceptions for explanation");
- throw new DSpaceSWORDException("Result of deposit did not yield an Item or a Bitstream");
- }
- SWORDEntry entry = dsatom.getSWORDEntry(result, deposit);
+ DepositResponse response = new DepositResponse(state);
+ response.setLocation(result.getMediaLink());
- // if this was a no-op, we need to remove the files we just
- // deposited, and abort the transaction
- if (deposit.isNoOp())
- {
- dep.undoDeposit(result);
- swordService.message("NoOp Requested: Removed all traces of submission");
- }
-
- entry.setNoOp(deposit.isNoOp());
+ DSpaceATOMEntry dsatom = null;
+ if (result.getItem() != null)
+ {
+ swordService
+ .message("Initialising ATOM entry generator for an Item");
+ dsatom = new ItemEntryGenerator(swordService);
+ }
+ else if (result.getBitstream() != null)
+ {
+ swordService.message(
+ "Initialising ATOM entry generator for a Bitstream");
+ dsatom = new BitstreamEntryGenerator(swordService);
+ }
+ if (dsatom == null)
+ {
+ log.error("The deposit failed, see exceptions for explanation");
+ throw new DSpaceSWORDException(
+ "Result of deposit did not yield an Item or a Bitstream");
+ }
+ SWORDEntry entry = dsatom.getSWORDEntry(result, deposit);
- Date finish = new Date();
- long delta = finish.getTime() - start.getTime();
- swordService.message("Total time for deposit processing: " + delta + " ms");
- entry.setVerboseDescription(swordService.getVerboseDescription().toString());
+ // if this was a no-op, we need to remove the files we just
+ // deposited, and abort the transaction
+ if (deposit.isNoOp())
+ {
+ dep.undoDeposit(result);
+ swordService.message(
+ "NoOp Requested: Removed all traces of submission");
+ }
- response.setEntry(entry);
-
- return response;
- }
+ entry.setNoOp(deposit.isNoOp());
+
+ Date finish = new Date();
+ long delta = finish.getTime() - start.getTime();
+ swordService
+ .message("Total time for deposit processing: " + delta + " ms");
+ entry.setVerboseDescription(
+ swordService.getVerboseDescription().toString());
+
+ response.setEntry(entry);
+
+ return response;
+ }
/**
* Store original package on disk and companion file containing SWORD headers as found in the deposit object
@@ -234,22 +256,27 @@ public class DepositManager
File dir = new File(path);
if (!dir.exists() || !dir.isDirectory())
{
- throw new IOException("Directory does not exist for writing packages on ingest error.");
+ throw new IOException(
+ "Directory does not exist for writing packages on ingest error.");
}
- String filenameBase = "sword-" + deposit.getUsername() + "-" + (new Date()).getTime();
+ String filenameBase =
+ "sword-" + deposit.getUsername() + "-" + (new Date()).getTime();
File packageFile = new File(path, filenameBase);
File headersFile = new File(path, filenameBase + "-headers");
- InputStream is = new BufferedInputStream(new FileInputStream(deposit.getFile()));
- OutputStream fos = new BufferedOutputStream(new FileOutputStream(packageFile));
+ InputStream is = new BufferedInputStream(
+ new FileInputStream(deposit.getFile()));
+ OutputStream fos = new BufferedOutputStream(
+ new FileOutputStream(packageFile));
Utils.copy(is, fos);
fos.close();
is.close();
//write companion file with headers
- PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(headersFile)));
+ PrintWriter pw = new PrintWriter(
+ new BufferedWriter(new FileWriter(headersFile)));
pw.println("Content-Disposition=" + deposit.getContentDisposition());
pw.println("Content-Type=" + deposit.getContentType());
diff --git a/dspace-sword/src/main/java/org/dspace/sword/DepositResult.java b/dspace-sword/src/main/java/org/dspace/sword/DepositResult.java
index 54037cf46f..0a8a4cd95e 100644
--- a/dspace-sword/src/main/java/org/dspace/sword/DepositResult.java
+++ b/dspace-sword/src/main/java/org/dspace/sword/DepositResult.java
@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -14,87 +14,86 @@ import org.dspace.content.Bitstream;
* The DSpace class for representing the results of a deposit
* request. This class can be used to hold all of the relevant
* components required to later build the SWORD response
- *
+ *
* @author Richard Jones
*
*/
public class DepositResult
{
- /** the handle assigned to the item, if available */
- private String handle;
-
- /** the item created during deposit */
- private Item item;
+ /** the handle assigned to the item, if available */
+ private String handle;
- /** Bitstream created as a result of the deposit */
- private Bitstream bitstream;
+ /** the item created during deposit */
+ private Item item;
- /** The treatment of the item during deposit */
- private String treatment;
+ /** Bitstream created as a result of the deposit */
+ private Bitstream bitstream;
- /** The media linkto the created object */
- private String mediaLink;
+ /** The treatment of the item during deposit */
+ private String treatment;
+ /** The media linkto the created object */
+ private String mediaLink;
- public Bitstream getBitstream()
- {
- return bitstream;
- }
+ public Bitstream getBitstream()
+ {
+ return bitstream;
+ }
- public void setBitstream(Bitstream bitstream)
- {
- this.bitstream = bitstream;
- }
+ public void setBitstream(Bitstream bitstream)
+ {
+ this.bitstream = bitstream;
+ }
- public String getTreatment()
- {
- return treatment;
- }
+ public String getTreatment()
+ {
+ return treatment;
+ }
- public void setTreatment(String treatment)
- {
- this.treatment = treatment;
- }
+ public void setTreatment(String treatment)
+ {
+ this.treatment = treatment;
+ }
- /**
- * @return the item
- */
- public Item getItem()
- {
- return item;
- }
-
- /**
- * @param item the item to set
- */
- public void setItem(Item item)
- {
- this.item = item;
- }
+ /**
+ * @return the item
+ */
+ public Item getItem()
+ {
+ return item;
+ }
- /**
- * @return the handle
- */
- public String getHandle()
- {
- return handle;
- }
+ /**
+ * @param item the item to set
+ */
+ public void setItem(Item item)
+ {
+ this.item = item;
+ }
- /**
- * @param handle the item handle
- */
- public void setHandle(String handle)
- {
- this.handle = handle;
- }
+ /**
+ * @return the handle
+ */
+ public String getHandle()
+ {
+ return handle;
+ }
- public String getMediaLink()
- {
- return mediaLink;
- }
+ /**
+ * @param handle the item handle
+ */
+ public void setHandle(String handle)
+ {
+ this.handle = handle;
+ }
- public void setMediaLink(String mediaLink)
- {
- this.mediaLink = mediaLink;
- }
+ public String getMediaLink()
+ {
+ return mediaLink;
+ }
+
+ public void setMediaLink(String mediaLink)
+ {
+ this.mediaLink = mediaLink;
+ }
}
diff --git a/dspace-sword/src/main/java/org/dspace/sword/Depositor.java b/dspace-sword/src/main/java/org/dspace/sword/Depositor.java
index 8eb5291171..b63c8d27cb 100644
--- a/dspace-sword/src/main/java/org/dspace/sword/Depositor.java
+++ b/dspace-sword/src/main/java/org/dspace/sword/Depositor.java
@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -18,38 +18,40 @@ import org.purl.sword.base.SWORDErrorException;
*/
public abstract class Depositor
{
- /**
- * The sword service implementation
- */
- protected SWORDService swordService;
+ /**
+ * The sword service implementation
+ */
+ protected SWORDService swordService;
- /**
- * Construct a new Depositor with the given sword service on the given
- * dspace object. It is anticipated that extensions of this class will
- * specialise in certain kinds of dspace object
- *
- * @param swordService
- * @param dso
- */
- public Depositor(SWORDService swordService, DSpaceObject dso)
- {
- this.swordService = swordService;
- }
+ /**
+ * Construct a new Depositor with the given sword service on the given
+ * dspace object. It is anticipated that extensions of this class will
+ * specialise in certain kinds of dspace object
+ *
+ * @param swordService
+ * @param dso
+ */
+ public Depositor(SWORDService swordService, DSpaceObject dso)
+ {
+ this.swordService = swordService;
+ }
- /**
- * Execute the deposit process with the given sword deposit.
- *
- * @param deposit
- * @throws SWORDErrorException
- * @throws DSpaceSWORDException
- */
- public abstract DepositResult doDeposit(Deposit deposit) throws SWORDErrorException, DSpaceSWORDException;
+ /**
+ * Execute the deposit process with the given sword deposit.
+ *
+ * @param deposit
+ * @throws SWORDErrorException
+ * @throws DSpaceSWORDException
+ */
+ public abstract DepositResult doDeposit(Deposit deposit)
+ throws SWORDErrorException, DSpaceSWORDException;
- /**
- * Undo any changes to the archive effected by the deposit
- *
- * @param result
- * @throws DSpaceSWORDException
- */
- public abstract void undoDeposit(DepositResult result) throws DSpaceSWORDException;
+ /**
+ * Undo any changes to the archive effected by the deposit
+ *
+ * @param result
+ * @throws DSpaceSWORDException
+ */
+ public abstract void undoDeposit(DepositResult result)
+ throws DSpaceSWORDException;
}
diff --git a/dspace-sword/src/main/java/org/dspace/sword/ItemCollectionGenerator.java b/dspace-sword/src/main/java/org/dspace/sword/ItemCollectionGenerator.java
index 85dd99bfda..5e8b01fdfa 100644
--- a/dspace-sword/src/main/java/org/dspace/sword/ItemCollectionGenerator.java
+++ b/dspace-sword/src/main/java/org/dspace/sword/ItemCollectionGenerator.java
@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -24,84 +24,89 @@ import java.util.List;
*/
public class ItemCollectionGenerator extends ATOMCollectionGenerator
{
- protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
+ protected ItemService itemService = ContentServiceFactory.getInstance()
+ .getItemService();
- public ItemCollectionGenerator(SWORDService service)
- {
- super(service);
- }
+ public ItemCollectionGenerator(SWORDService service)
+ {
+ super(service);
+ }
- /**
- * Build the collection around the give DSpaceObject. If the object
- * is not an instance of a DSpace Item this method will throw an
- * exception.
- *
- * @param dso the dso for which the collection should be build
- * @throws DSpaceSWORDException if the dso is not an instance of Item
- */
- public Collection buildCollection(DSpaceObject dso) throws DSpaceSWORDException
- {
- if (!(dso instanceof Item))
- {
- throw new DSpaceSWORDException("Incorrect ATOMCollectionGenerator instantiated");
- }
+ /**
+ * Build the collection around the give DSpaceObject. If the object
+ * is not an instance of a DSpace Item this method will throw an
+ * exception.
+ *
+ * @param dso the dso for which the collection should be build
+ * @throws DSpaceSWORDException if the dso is not an instance of Item
+ */
+ public Collection buildCollection(DSpaceObject dso)
+ throws DSpaceSWORDException
+ {
+ if (!(dso instanceof Item))
+ {
+ throw new DSpaceSWORDException(
+ "Incorrect ATOMCollectionGenerator instantiated");
+ }
- // get the things we need out of the service
- SWORDConfiguration swordConfig = swordService.getSwordConfig();
- SWORDUrlManager urlManager = swordService.getUrlManager();
- Context context = swordService.getContext();
+ // get the things we need out of the service
+ SWORDConfiguration swordConfig = swordService.getSwordConfig();
+ SWORDUrlManager urlManager = swordService.getUrlManager();
+ Context context = swordService.getContext();
- Item item = (Item) dso;
- Collection scol = new Collection();
+ Item item = (Item) dso;
+ Collection scol = new Collection();
- // prepare the parameters to be put in the sword collection
- String location = urlManager.getDepositLocation(item);
- scol.setLocation(location);
+ // prepare the parameters to be put in the sword collection
+ String location = urlManager.getDepositLocation(item);
+ scol.setLocation(location);
- // the item title is the sword collection title, or "untitled" otherwise
- String title = "Untitled";
- List
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -29,103 +29,122 @@ import java.util.List;
public class ItemDepositor extends Depositor
{
- protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
- protected BundleService bundleService = ContentServiceFactory.getInstance().getBundleService();
- protected BitstreamService bitstreamService = ContentServiceFactory.getInstance().getBitstreamService();
- protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService();
+ protected ItemService itemService = ContentServiceFactory.getInstance()
+ .getItemService();
- private Item item;
+ protected BundleService bundleService = ContentServiceFactory.getInstance()
+ .getBundleService();
- public ItemDepositor(SWORDService swordService, DSpaceObject dso)
- throws DSpaceSWORDException
- {
- super(swordService, dso);
+ protected BitstreamService bitstreamService = ContentServiceFactory
+ .getInstance().getBitstreamService();
- if (!(dso instanceof Item))
- {
- throw new DSpaceSWORDException("You tried to initialise the item depositor with something" +
- "other than an item object");
- }
+ protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory
+ .getInstance().getBitstreamFormatService();
- this.item = (Item) dso;
- }
+ private Item item;
- public DepositResult doDeposit(Deposit deposit) throws SWORDErrorException, DSpaceSWORDException
- {
- // get the things out of the service that we need
- Context context = swordService.getContext();
- SWORDConfiguration swordConfig = swordService.getSwordConfig();
- SWORDUrlManager urlManager = swordService.getUrlManager();
+ public ItemDepositor(SWORDService swordService, DSpaceObject dso)
+ throws DSpaceSWORDException
+ {
+ super(swordService, dso);
- // FIXME: the spec is unclear what to do in this situation. I'm going
- // the throw a 415 (ERROR_CONTENT) until further notice
- //
- // determine if this is an acceptable file format
- if (!swordConfig.isAcceptableContentType(context, deposit.getContentType(), item))
- {
- throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT,
- "Unacceptable content type in deposit request: " + deposit.getContentType());
- }
+ if (!(dso instanceof Item))
+ {
+ throw new DSpaceSWORDException(
+ "You tried to initialise the item depositor with something" +
+ "other than an item object");
+ }
- // determine if this is an acceptable packaging type for the deposit
- // if not, we throw a 415 HTTP error (Unsupported Media Type, ERROR_CONTENT)
- if (!swordConfig.isSupportedMediaType(deposit.getPackaging(), this.item))
- {
- throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT,
- "Unacceptable packaging type in deposit request: " + deposit.getPackaging());
- }
+ this.item = (Item) dso;
+ }
- // Obtain the relevant ingester from the factory
- SWORDIngester si = SWORDIngesterFactory.getInstance(context, deposit, item);
- swordService.message("Loaded ingester: " + si.getClass().getName());
+ public DepositResult doDeposit(Deposit deposit)
+ throws SWORDErrorException, DSpaceSWORDException
+ {
+ // get the things out of the service that we need
+ Context context = swordService.getContext();
+ SWORDConfiguration swordConfig = swordService.getSwordConfig();
+ SWORDUrlManager urlManager = swordService.getUrlManager();
- // do the deposit
- DepositResult result = si.ingest(swordService, deposit, item);
- swordService.message("Archive ingest completed successfully");
+ // FIXME: the spec is unclear what to do in this situation. I'm going
+ // the throw a 415 (ERROR_CONTENT) until further notice
+ //
+ // determine if this is an acceptable file format
+ if (!swordConfig
+ .isAcceptableContentType(context, deposit.getContentType(),
+ item))
+ {
+ throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT,
+ "Unacceptable content type in deposit request: " +
+ deposit.getContentType());
+ }
- // if there's an item availalble, and we want to keep the original
- // then do that
- try
- {
- if (swordConfig.isKeepOriginal())
- {
- swordService.message("DSpace will store an original copy of the deposit file, " +
- "as well as attaching it to the item");
+ // determine if this is an acceptable packaging type for the deposit
+ // if not, we throw a 415 HTTP error (Unsupported Media Type, ERROR_CONTENT)
+ if (!swordConfig
+ .isSupportedMediaType(deposit.getPackaging(), this.item))
+ {
+ throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT,
+ "Unacceptable packaging type in deposit request: " +
+ deposit.getPackaging());
+ }
- // in order to be allowed to add the file back to the item, we need to ignore authorisations
- // for a moment
- context.turnOffAuthorisationSystem();
+ // Obtain the relevant ingester from the factory
+ SWORDIngester si = SWORDIngesterFactory
+ .getInstance(context, deposit, item);
+ swordService.message("Loaded ingester: " + si.getClass().getName());
- String bundleName = ConfigurationManager.getProperty("sword-server", "bundle.name");
- if (StringUtils.isBlank(bundleName))
- {
- bundleName = "SWORD";
- }
+ // do the deposit
+ DepositResult result = si.ingest(swordService, deposit, item);
+ swordService.message("Archive ingest completed successfully");
- List
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -28,252 +28,275 @@ import java.util.List;
*/
public class ItemEntryGenerator extends DSpaceATOMEntry
{
- /** logger */
- private static Logger log = Logger.getLogger(ItemEntryGenerator.class);
+ /** logger */
+ private static Logger log = Logger.getLogger(ItemEntryGenerator.class);
- protected HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
- protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
+ protected HandleService handleService = HandleServiceFactory.getInstance()
+ .getHandleService();
- protected ItemEntryGenerator(SWORDService service)
- {
- super(service);
- }
+ protected ItemService itemService = ContentServiceFactory.getInstance()
+ .getItemService();
- /**
- * Add all the subject classifications from the bibliographic
- * metadata.
- *
- */
- protected void addCategories()
- {
- List
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -14,28 +14,29 @@ import org.dspace.core.ConfigurationManager;
/**
* Simple servlet to load in DSpace and log4j configurations. Should always be
* started up before other servlets (use
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -21,53 +21,56 @@ import org.dspace.content.Bitstream;
*/
public class MediaEntryManager
{
- /** sword service implementation */
- private SWORDService swordService;
+ /** sword service implementation */
+ private SWORDService swordService;
- public MediaEntryManager(SWORDService swordService)
- {
- this.swordService = swordService;
- }
+ public MediaEntryManager(SWORDService swordService)
+ {
+ this.swordService = swordService;
+ }
- /**
- * Get the media entry for the given URL request. If the URL is
- * unavailable this method will throw the appropriate SWORD errors,
- * with DSpace custom URLs.
- *
- * @param url
- * @throws DSpaceSWORDException
- * @throws SWORDErrorException
- */
- public AtomDocumentResponse getMediaEntry(String url)
- throws DSpaceSWORDException, SWORDErrorException
- {
- SWORDUrlManager urlManager = swordService.getUrlManager();
+ /**
+ * Get the media entry for the given URL request. If the URL is
+ * unavailable this method will throw the appropriate SWORD errors,
+ * with DSpace custom URLs.
+ *
+ * @param url
+ * @throws DSpaceSWORDException
+ * @throws SWORDErrorException
+ */
+ public AtomDocumentResponse getMediaEntry(String url)
+ throws DSpaceSWORDException, SWORDErrorException
+ {
+ SWORDUrlManager urlManager = swordService.getUrlManager();
- AtomDocumentResponse response = new AtomDocumentResponse(200);
+ AtomDocumentResponse response = new AtomDocumentResponse(200);
- if (url == null || urlManager.isBaseMediaLinkUrl(url))
- {
- // we are dealing with a default media-link, indicating that something
- // is wrong
+ if (url == null || urlManager.isBaseMediaLinkUrl(url))
+ {
+ // we are dealing with a default media-link, indicating that something
+ // is wrong
- // FIXME: what do we actually do about this situation?
- // throwing an error for the time being
- throw new SWORDErrorException(DSpaceSWORDErrorCodes.MEDIA_UNAVAILABLE, "The media link you requested is not available");
- }
+ // FIXME: what do we actually do about this situation?
+ // throwing an error for the time being
+ throw new SWORDErrorException(
+ DSpaceSWORDErrorCodes.MEDIA_UNAVAILABLE,
+ "The media link you requested is not available");
+ }
- // extract the thing that we are trying to get a media entry on
- DSpaceObject dso = urlManager.extractDSpaceObject(url);
+ // extract the thing that we are trying to get a media entry on
+ DSpaceObject dso = urlManager.extractDSpaceObject(url);
- // now, the media entry should always be to an actual file, so we only care that this is a bitstream
- if (!(dso instanceof Bitstream))
- {
- throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL, "The url you provided does not resolve to an appropriate object");
- }
+ // now, the media entry should always be to an actual file, so we only care that this is a bitstream
+ if (!(dso instanceof Bitstream))
+ {
+ throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL,
+ "The url you provided does not resolve to an appropriate object");
+ }
- // now construct the atom entry for the bitstream
- DSpaceATOMEntry dsatom = new BitstreamEntryGenerator(swordService);
- SWORDEntry entry = dsatom.getSWORDEntry(dso);
- response.setEntry(entry);
- return response;
- }
+ // now construct the atom entry for the bitstream
+ DSpaceATOMEntry dsatom = new BitstreamEntryGenerator(swordService);
+ SWORDEntry entry = dsatom.getSWORDEntry(dso);
+ response.setEntry(entry);
+ return response;
+ }
}
diff --git a/dspace-sword/src/main/java/org/dspace/sword/SWORDAuthentication.java b/dspace-sword/src/main/java/org/dspace/sword/SWORDAuthentication.java
index 05b141af64..995e832986 100644
--- a/dspace-sword/src/main/java/org/dspace/sword/SWORDAuthentication.java
+++ b/dspace-sword/src/main/java/org/dspace/sword/SWORDAuthentication.java
@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -16,25 +16,26 @@ import org.dspace.authenticate.AuthenticationMethod;
/**
* This class offers a thin wrapper for the default DSpace
* authentication module for the SWORD implementation
- *
+ *
* @author Richard Jones
*
*/
public class SWORDAuthentication
{
- /**
- * Does the given username and password authenticate for the
- * given DSpace Context?
- *
- * @param context
- * @param un
- * @param pw
- * @return true if yes, false if not
- */
- public boolean authenticates(Context context, String un, String pw)
- {
- AuthenticationService authService = AuthenticateServiceFactory.getInstance().getAuthenticationService();
- int auth = authService.authenticate(context, un, pw, null, null);
- return auth == AuthenticationMethod.SUCCESS;
- }
+ /**
+ * Does the given username and password authenticate for the
+ * given DSpace Context?
+ *
+ * @param context
+ * @param un
+ * @param pw
+ * @return true if yes, false if not
+ */
+ public boolean authenticates(Context context, String un, String pw)
+ {
+ AuthenticationService authService = AuthenticateServiceFactory
+ .getInstance().getAuthenticationService();
+ int auth = authService.authenticate(context, un, pw, null, null);
+ return auth == AuthenticationMethod.SUCCESS;
+ }
}
diff --git a/dspace-sword/src/main/java/org/dspace/sword/SWORDAuthenticator.java b/dspace-sword/src/main/java/org/dspace/sword/SWORDAuthenticator.java
index 2bb71705e4..d6e10d38ed 100644
--- a/dspace-sword/src/main/java/org/dspace/sword/SWORDAuthenticator.java
+++ b/dspace-sword/src/main/java/org/dspace/sword/SWORDAuthenticator.java
@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -41,71 +41,84 @@ import java.util.ArrayList;
/**
* This class offers a thin wrapper for the default DSpace
* authentication module for the SWORD implementation
- *
+ *
* @author Richard Jones
*
*/
public class SWORDAuthenticator
{
- /** logger */
- private static Logger log = Logger.getLogger(SWORDAuthenticator.class);
+ /** logger */
+ private static Logger log = Logger.getLogger(SWORDAuthenticator.class);
- protected AuthenticationService authenticationService = AuthenticateServiceFactory.getInstance().getAuthenticationService();
- protected AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
- protected EPersonService ePersonService = EPersonServiceFactory.getInstance().getEPersonService();
- protected CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
- protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
- protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
+ protected AuthenticationService authenticationService = AuthenticateServiceFactory
+ .getInstance().getAuthenticationService();
- /**
- * Does the given username and password authenticate for the
- * given DSpace Context?
- *
- * @param context
- * @param un
- * @param pw
- * @return true if yes, false if not
- */
- public boolean authenticates(Context context, String un, String pw)
- {
- int auth = authenticationService.authenticate(context, un, pw, null, null);
- return auth == AuthenticationMethod.SUCCESS;
- }
+ protected AuthorizeService authorizeService = AuthorizeServiceFactory
+ .getInstance().getAuthorizeService();
- /**
- * Construct the context object member variable of this class
- * using the passed IP address as part of the loggable
- * information
- *
- * @param ip the ip address of the incoming request
- * @throws org.purl.sword.base.SWORDException
- */
- private Context constructContext(String ip)
- throws SWORDException
- {
- Context context = new Context();
- // Set the session ID and IP address
- context.setExtraLogInfo("session_id=0:ip_addr=" + ip);
+ protected EPersonService ePersonService = EPersonServiceFactory
+ .getInstance().getEPersonService();
- return context;
- }
+ protected CommunityService communityService = ContentServiceFactory
+ .getInstance().getCommunityService();
- /**
- * Authenticate the given service document request. This extracts
- * the appropriate information from the request and forwards to the
- * appropriate authentication method.
- *
- * @param request
- * @throws SWORDException
- * @throws SWORDErrorException
- * @throws SWORDAuthenticationException
- */
- public SWORDContext authenticate(ServiceDocumentRequest request)
- throws SWORDException, SWORDErrorException, SWORDAuthenticationException
- {
- Context context = this.constructContext(request.getIPAddress());
- SWORDContext sc;
- try
+ protected CollectionService collectionService = ContentServiceFactory
+ .getInstance().getCollectionService();
+
+ protected ItemService itemService = ContentServiceFactory.getInstance()
+ .getItemService();
+
+ /**
+ * Does the given username and password authenticate for the
+ * given DSpace Context?
+ *
+ * @param context
+ * @param un
+ * @param pw
+ * @return true if yes, false if not
+ */
+ public boolean authenticates(Context context, String un, String pw)
+ {
+ int auth = authenticationService
+ .authenticate(context, un, pw, null, null);
+ return auth == AuthenticationMethod.SUCCESS;
+ }
+
+ /**
+ * Construct the context object member variable of this class
+ * using the passed IP address as part of the loggable
+ * information
+ *
+ * @param ip the ip address of the incoming request
+ * @throws org.purl.sword.base.SWORDException
+ */
+ private Context constructContext(String ip)
+ throws SWORDException
+ {
+ Context context = new Context();
+ // Set the session ID and IP address
+ context.setExtraLogInfo("session_id=0:ip_addr=" + ip);
+
+ return context;
+ }
+
+ /**
+ * Authenticate the given service document request. This extracts
+ * the appropriate information from the request and forwards to the
+ * appropriate authentication method.
+ *
+ * @param request
+ * @throws SWORDException
+ * @throws SWORDErrorException
+ * @throws SWORDAuthenticationException
+ */
+ public SWORDContext authenticate(ServiceDocumentRequest request)
+ throws SWORDException, SWORDErrorException,
+ SWORDAuthenticationException
+ {
+ Context context = this.constructContext(request.getIPAddress());
+ SWORDContext sc;
+ try
{
sc = this.authenticate(context, request);
}
@@ -117,25 +130,26 @@ public class SWORDAuthenticator
}
throw e;
}
- return sc;
- }
+ return sc;
+ }
- /**
- * Authenticate the given ATOM document request. This extracts the
- * appropriate information from the request, and forwards to the
- * appropriate authentication method.
- *
- * @param request
- * @throws SWORDException
- * @throws SWORDErrorException
- * @throws SWORDAuthenticationException
- */
- public SWORDContext authenticate(AtomDocumentRequest request)
- throws SWORDException, SWORDErrorException, SWORDAuthenticationException
- {
- Context context = this.constructContext(request.getIPAddress());
- SWORDContext sc = null;
- try
+ /**
+ * Authenticate the given ATOM document request. This extracts the
+ * appropriate information from the request, and forwards to the
+ * appropriate authentication method.
+ *
+ * @param request
+ * @throws SWORDException
+ * @throws SWORDErrorException
+ * @throws SWORDAuthenticationException
+ */
+ public SWORDContext authenticate(AtomDocumentRequest request)
+ throws SWORDException, SWORDErrorException,
+ SWORDAuthenticationException
+ {
+ Context context = this.constructContext(request.getIPAddress());
+ SWORDContext sc = null;
+ try
{
sc = this.authenticate(context, request);
}
@@ -147,58 +161,66 @@ public class SWORDAuthenticator
}
throw e;
}
- return sc;
+ return sc;
}
- /**
- * Authenticate the incoming service document request. Calls:
- *
- * authenticatate(username, password, onBehalfOf)
- *
- * @param request
- * @return a SWORDContext object containing the relevant users
- * @throws org.purl.sword.base.SWORDAuthenticationException
- * @throws SWORDException
- */
- private SWORDContext authenticate(Context context, AtomDocumentRequest request)
- throws SWORDAuthenticationException, SWORDException, SWORDErrorException
- {
- return this.authenticate(context, request.getUsername(), request.getPassword(), null, request.getIPAddress());
- }
+ /**
+ * Authenticate the incoming service document request. Calls:
+ *
+ * authenticatate(username, password, onBehalfOf)
+ *
+ * @param request
+ * @return a SWORDContext object containing the relevant users
+ * @throws org.purl.sword.base.SWORDAuthenticationException
+ * @throws SWORDException
+ */
+ private SWORDContext authenticate(Context context,
+ AtomDocumentRequest request)
+ throws SWORDAuthenticationException, SWORDException,
+ SWORDErrorException
+ {
+ return this.authenticate(context, request.getUsername(),
+ request.getPassword(), null, request.getIPAddress());
+ }
- /**
- * Authenticate the incoming service document request. Calls:
- *
- * authenticatate(username, password, onBehalfOf)
- *
- * @param request
- * @return a SWORDContext object containing the relevant users
- * @throws org.purl.sword.base.SWORDAuthenticationException
- * @throws SWORDException
- */
- private SWORDContext authenticate(Context context, ServiceDocumentRequest request)
- throws SWORDAuthenticationException, SWORDException, SWORDErrorException
- {
- return this.authenticate(context, request.getUsername(), request.getPassword(), request.getOnBehalfOf(), request.getIPAddress());
- }
+ /**
+ * Authenticate the incoming service document request. Calls:
+ *
+ * authenticatate(username, password, onBehalfOf)
+ *
+ * @param request
+ * @return a SWORDContext object containing the relevant users
+ * @throws org.purl.sword.base.SWORDAuthenticationException
+ * @throws SWORDException
+ */
+ private SWORDContext authenticate(Context context,
+ ServiceDocumentRequest request)
+ throws SWORDAuthenticationException, SWORDException,
+ SWORDErrorException
+ {
+ return this.authenticate(context, request.getUsername(),
+ request.getPassword(), request.getOnBehalfOf(),
+ request.getIPAddress());
+ }
- /**
- * Authenticate the deposit request.
- *
- * @param deposit
- * @throws SWORDException
- * @throws SWORDErrorException
- * @throws SWORDAuthenticationException
- */
- public SWORDContext authenticate(Deposit deposit)
- throws SWORDException, SWORDErrorException, SWORDAuthenticationException
- {
- Context context = this.constructContext(deposit.getIPAddress());
- SWORDContext sc = null;
- try
- {
- sc = this.authenticate(context, deposit);
- }
+ /**
+ * Authenticate the deposit request.
+ *
+ * @param deposit
+ * @throws SWORDException
+ * @throws SWORDErrorException
+ * @throws SWORDAuthenticationException
+ */
+ public SWORDContext authenticate(Deposit deposit)
+ throws SWORDException, SWORDErrorException,
+ SWORDAuthenticationException
+ {
+ Context context = this.constructContext(deposit.getIPAddress());
+ SWORDContext sc = null;
+ try
+ {
+ sc = this.authenticate(context, deposit);
+ }
catch (SWORDException | SWORDErrorException | RuntimeException | SWORDAuthenticationException e)
{
if (context != null && context.isValid())
@@ -207,849 +229,918 @@ public class SWORDAuthenticator
}
throw e;
}
- return sc;
- }
-
- /**
- * Authenticate the incoming deposit request. Calls:
- *
- * authenticate(username, password, onBehalfOf)
- *
- * @param deposit
- * @return a SWORDContext object containing the relevant users
- * @throws SWORDAuthenticationException
- * @throws SWORDException
- */
- private SWORDContext authenticate(Context context, Deposit deposit)
- throws SWORDAuthenticationException, SWORDException, SWORDErrorException
- {
- return this.authenticate(context, deposit.getUsername(), deposit.getPassword(), deposit.getOnBehalfOf(), deposit.getIPAddress());
- }
-
- /**
- * Authenticate the given username/password pair, in conjunction with
- * the onBehalfOf user. The rules are that the username/password pair
- * must successfully authenticate the user, and the onBehalfOf user
- * must exist in the user database.
- *
- * @param un
- * @param pw
- * @param obo
- * @return a SWORD context holding the various user information
- * @throws SWORDAuthenticationException
- * @throws SWORDException
- */
- private SWORDContext authenticate(Context context, String un, String pw, String obo, String ip)
- throws SWORDAuthenticationException, SWORDException, SWORDErrorException
- {
- // smooth out the OnBehalfOf request, so that empty strings are
- // treated as null
- if ("".equals(obo))
- {
- obo = null;
- }
-
- // first find out if we support on-behalf-of deposit
- boolean mediated = ConfigurationManager.getBooleanProperty("sword-server", "on-behalf-of.enable");
- if (!mediated && obo != null)
- {
- // user is trying to do a mediated deposit on a repository which does not support it
- log.error("Attempted mediated deposit on service not configured to do so");
- throw new SWORDErrorException(ErrorCodes.MEDIATION_NOT_ALLOWED, "Mediated deposit to this service is not permitted");
- }
-
- log.info(LogManager.getHeader(context, "sword_authenticate", "username=" + un + ",on_behalf_of=" + obo));
-
- try
- {
- // attempt to authenticate the primary user
- SWORDContext sc = new SWORDContext();
- EPerson ep = null;
- boolean authenticated = false;
- if (this.authenticates(context, un, pw))
- {
- // if authenticated, obtain the eperson object
- ep = context.getCurrentUser();
-
- if (ep != null)
- {
- authenticated = true;
- sc.setAuthenticated(ep);
- // Set any special groups - invoke the authentication mgr.
- List
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -46,71 +46,80 @@ public class SWORDConfiguration
{
/** logger */
- public static final Logger log = Logger.getLogger(SWORDConfiguration.class);
+ public static final Logger log = Logger.getLogger(SWORDConfiguration.class);
- protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService();
+ protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory
+ .getInstance().getBitstreamFormatService();
- /** whether we can support noOp */
- private boolean noOp = true;
+ /** whether we can support noOp */
+ private boolean noOp = true;
- /** whether we can be verbose */
- private boolean verbose = true;
+ /** whether we can be verbose */
+ private boolean verbose = true;
- /** what our default max upload size is */
- private int maxUploadSize = -1;
+ /** what our default max upload size is */
+ private int maxUploadSize = -1;
- /** do we support mediation */
- private boolean mediated = false;
+ /** do we support mediation */
+ private boolean mediated = false;
- /** should we keep the original package as bitstream */
- private boolean keepOriginal = false;
+ /** should we keep the original package as bitstream */
+ private boolean keepOriginal = false;
- /** item bundle in which sword deposits are stored */
- private String swordBundle = "SWORD";
-
- /** should we keep the original package as a file on ingest error */
- private boolean keepPackageOnFailedIngest = false;
-
- /** location of directory to store packages on ingest error */
- private String failedPackageDir = null;
+ /** item bundle in which sword deposits are stored */
+ private String swordBundle = "SWORD";
+
+ /** should we keep the original package as a file on ingest error */
+ private boolean keepPackageOnFailedIngest = false;
+
+ /** location of directory to store packages on ingest error */
+ private String failedPackageDir = null;
/** Accepted formats */
private List
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -31,157 +31,157 @@ import org.dspace.eperson.EPerson;
*
* and not from any of the other context retrieval methods in this
* class
- *
+ *
* @author Richard Jones
*
*/
-public class SWORDContext
+public class SWORDContext
{
- /** The primary authenticated user for the request */
- private EPerson authenticated = null;
-
- /** The onBehalfOf user for the request */
- private EPerson onBehalfOf = null;
+ /** The primary authenticated user for the request */
+ private EPerson authenticated = null;
- /** The primary context, representing the on behalf of user if exists, and the authenticated user if not */
- private Context context;
+ /** The onBehalfOf user for the request */
+ private EPerson onBehalfOf = null;
- /** the context for the authenticated user, which may not, therefore, be the primary context also */
- private Context authenticatorContext;
+ /** The primary context, representing the on behalf of user if exists, and the authenticated user if not */
+ private Context context;
- /**
- * @return the authenticated user
- */
- public EPerson getAuthenticated()
- {
- return authenticated;
- }
+ /** the context for the authenticated user, which may not, therefore, be the primary context also */
+ private Context authenticatorContext;
- /**
- * @param authenticated the eperson to set
- */
- public void setAuthenticated(EPerson authenticated)
- {
- this.authenticated = authenticated;
- }
+ /**
+ * @return the authenticated user
+ */
+ public EPerson getAuthenticated()
+ {
+ return authenticated;
+ }
- /**
- * @return the onBehalfOf user
- */
- public EPerson getOnBehalfOf()
- {
- return onBehalfOf;
- }
+ /**
+ * @param authenticated the eperson to set
+ */
+ public void setAuthenticated(EPerson authenticated)
+ {
+ this.authenticated = authenticated;
+ }
- /**
- * @param onBehalfOf the eperson to set
- */
- public void setOnBehalfOf(EPerson onBehalfOf)
- {
- this.onBehalfOf = onBehalfOf;
- }
+ /**
+ * @return the onBehalfOf user
+ */
+ public EPerson getOnBehalfOf()
+ {
+ return onBehalfOf;
+ }
- /**
- * Returns the most appropriate context for operations on the
- * database. This is the on-behalf-of user's context if the
- * user exists, or the authenticated user's context otherwise.
- */
- public Context getContext()
- {
- return context;
- }
+ /**
+ * @param onBehalfOf the eperson to set
+ */
+ public void setOnBehalfOf(EPerson onBehalfOf)
+ {
+ this.onBehalfOf = onBehalfOf;
+ }
- public void setContext(Context context)
- {
- this.context = context;
- }
+ /**
+ * Returns the most appropriate context for operations on the
+ * database. This is the on-behalf-of user's context if the
+ * user exists, or the authenticated user's context otherwise.
+ */
+ public Context getContext()
+ {
+ return context;
+ }
- /**
- * Get the context of the user who authenticated. This should only be
- * used for authentication purposes. If there is an on-behalf-of user,
- * that context should be used to write database changes. Use:
- *
- * getContext()
- *
- * on this class instead.
- */
- public Context getAuthenticatorContext()
- {
- return authenticatorContext;
- }
+ public void setContext(Context context)
+ {
+ this.context = context;
+ }
- public void setAuthenticatorContext(Context authenticatorContext)
- {
- this.authenticatorContext = authenticatorContext;
- }
+ /**
+ * Get the context of the user who authenticated. This should only be
+ * used for authentication purposes. If there is an on-behalf-of user,
+ * that context should be used to write database changes. Use:
+ *
+ * getContext()
+ *
+ * on this class instead.
+ */
+ public Context getAuthenticatorContext()
+ {
+ return authenticatorContext;
+ }
- /**
- * Get the context of the on-behalf-of user. This method should only
- * be used for authentication purposes. In all other cases, use:
- *
- * getContext()
- *
- * on this class instead. If there is no on-behalf-of user, this
- * method will return null.
- */
- public Context getOnBehalfOfContext()
- {
- // return the obo context if this is an obo deposit, else return null
- if (this.onBehalfOf != null)
- {
- return context;
- }
- return null;
- }
+ public void setAuthenticatorContext(Context authenticatorContext)
+ {
+ this.authenticatorContext = authenticatorContext;
+ }
- /**
- * Abort all of the contexts held by this class. No changes will
- * be written to the database
- */
- public void abort()
- {
- // abort both contexts
- if (context != null && context.isValid())
- {
- context.abort();
- }
+ /**
+ * Get the context of the on-behalf-of user. This method should only
+ * be used for authentication purposes. In all other cases, use:
+ *
+ * getContext()
+ *
+ * on this class instead. If there is no on-behalf-of user, this
+ * method will return null.
+ */
+ public Context getOnBehalfOfContext()
+ {
+ // return the obo context if this is an obo deposit, else return null
+ if (this.onBehalfOf != null)
+ {
+ return context;
+ }
+ return null;
+ }
- if (authenticatorContext != null && authenticatorContext.isValid())
- {
- authenticatorContext.abort();
- }
- }
+ /**
+ * Abort all of the contexts held by this class. No changes will
+ * be written to the database
+ */
+ public void abort()
+ {
+ // abort both contexts
+ if (context != null && context.isValid())
+ {
+ context.abort();
+ }
- /**
- * Commit the primary context held by this class, and abort the authenticated
- * user's context if it is different. This ensures that only changes written
- * through the appropriate user's context is persisted, and all other
- * operations are flushed. You should, in general, not try to commit the contexts directly
- * when using the sword api.
- *
- * @throws DSpaceSWORDException
- */
- public void commit()
- throws DSpaceSWORDException
- {
- try
- {
- // commit the primary context
- if (context != null && context.isValid())
- {
- context.complete();
- }
+ if (authenticatorContext != null && authenticatorContext.isValid())
+ {
+ authenticatorContext.abort();
+ }
+ }
- // the secondary context is for filtering permissions by only, and is
- // never committed, so we abort here
- if (authenticatorContext != null && authenticatorContext.isValid())
- {
- authenticatorContext.abort();
- }
- }
- catch (SQLException e)
- {
- throw new DSpaceSWORDException(e);
- }
- }
+ /**
+ * Commit the primary context held by this class, and abort the authenticated
+ * user's context if it is different. This ensures that only changes written
+ * through the appropriate user's context is persisted, and all other
+ * operations are flushed. You should, in general, not try to commit the contexts directly
+ * when using the sword api.
+ *
+ * @throws DSpaceSWORDException
+ */
+ public void commit()
+ throws DSpaceSWORDException
+ {
+ try
+ {
+ // commit the primary context
+ if (context != null && context.isValid())
+ {
+ context.complete();
+ }
+
+ // the secondary context is for filtering permissions by only, and is
+ // never committed, so we abort here
+ if (authenticatorContext != null && authenticatorContext.isValid())
+ {
+ authenticatorContext.abort();
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new DSpaceSWORDException(e);
+ }
+ }
}
diff --git a/dspace-sword/src/main/java/org/dspace/sword/SWORDIngester.java b/dspace-sword/src/main/java/org/dspace/sword/SWORDIngester.java
index 0993d1f2c1..8ff203e38e 100644
--- a/dspace-sword/src/main/java/org/dspace/sword/SWORDIngester.java
+++ b/dspace-sword/src/main/java/org/dspace/sword/SWORDIngester.java
@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -16,19 +16,21 @@ import org.purl.sword.base.SWORDErrorException;
* Interface behind which can be implemented ingest mechanisms
* for SWORD deposit requests. Instances of this class should
* be obtained via the SWORDIngesterFactory class.
- *
+ *
* @author Richard Jones
*
*/
public interface SWORDIngester
{
- /**
- * Ingest the package as described in the given Deposit object
- * within the given DSpace Context
- *
- * @param deposit
- * @return the result of the deposit
- * @throws DSpaceSWORDException
- */
- DepositResult ingest(SWORDService service, Deposit deposit, DSpaceObject target) throws DSpaceSWORDException, SWORDErrorException;
+ /**
+ * Ingest the package as described in the given Deposit object
+ * within the given DSpace Context
+ *
+ * @param deposit
+ * @return the result of the deposit
+ * @throws DSpaceSWORDException
+ */
+ DepositResult ingest(SWORDService service, Deposit deposit,
+ DSpaceObject target)
+ throws DSpaceSWORDException, SWORDErrorException;
}
diff --git a/dspace-sword/src/main/java/org/dspace/sword/SWORDIngesterFactory.java b/dspace-sword/src/main/java/org/dspace/sword/SWORDIngesterFactory.java
index ef6a2bd2d0..23860b01b7 100644
--- a/dspace-sword/src/main/java/org/dspace/sword/SWORDIngesterFactory.java
+++ b/dspace-sword/src/main/java/org/dspace/sword/SWORDIngesterFactory.java
@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -20,48 +20,56 @@ import org.purl.sword.base.ErrorCodes;
/**
* Factory class which will mint objects conforming to the
* SWORDIngester interface.
- *
+ *
* @author Richard Jones
*
*/
public class SWORDIngesterFactory
{
- /**
- * Generate an object which conforms to the SWORDIngester interface.
- * This Factory method may use the given DSpace context and the given
- * SWORD Deposit request to decide on the most appropriate implementation
- * of the interface to return.
- *
- * To configure how this method will respond, configure the package ingester
- * for the appropriate media types and defaults. See the sword configuration
- * documentation for more details.
- *
- * @param context
- * @param deposit
- * @throws DSpaceSWORDException
- */
- public static SWORDIngester getInstance(Context context, Deposit deposit, DSpaceObject dso)
+ /**
+ * Generate an object which conforms to the SWORDIngester interface.
+ * This Factory method may use the given DSpace context and the given
+ * SWORD Deposit request to decide on the most appropriate implementation
+ * of the interface to return.
+ *
+ * To configure how this method will respond, configure the package ingester
+ * for the appropriate media types and defaults. See the sword configuration
+ * documentation for more details.
+ *
+ * @param context
+ * @param deposit
+ * @throws DSpaceSWORDException
+ */
+ public static SWORDIngester getInstance(Context context, Deposit deposit,
+ DSpaceObject dso)
throws DSpaceSWORDException, SWORDErrorException
{
- if (dso instanceof Collection)
- {
- SWORDIngester ingester = (SWORDIngester) PluginManager.getNamedPlugin("sword-server", SWORDIngester.class, deposit.getPackaging());
- if (ingester == null)
- {
- throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT, "No ingester configured for this package type");
- }
- return ingester;
- }
- else if (dso instanceof Item)
- {
- SWORDIngester ingester = (SWORDIngester) PluginManager.getNamedPlugin("sword-server", SWORDIngester.class, "SimpleFileIngester");
- if (ingester == null)
- {
- throw new DSpaceSWORDException("SimpleFileIngester is not configured in plugin manager");
- }
- return ingester;
- }
+ if (dso instanceof Collection)
+ {
+ SWORDIngester ingester = (SWORDIngester) PluginManager
+ .getNamedPlugin("sword-server", SWORDIngester.class,
+ deposit.getPackaging());
+ if (ingester == null)
+ {
+ throw new SWORDErrorException(ErrorCodes.ERROR_CONTENT,
+ "No ingester configured for this package type");
+ }
+ return ingester;
+ }
+ else if (dso instanceof Item)
+ {
+ SWORDIngester ingester = (SWORDIngester) PluginManager
+ .getNamedPlugin("sword-server", SWORDIngester.class,
+ "SimpleFileIngester");
+ if (ingester == null)
+ {
+ throw new DSpaceSWORDException(
+ "SimpleFileIngester is not configured in plugin manager");
+ }
+ return ingester;
+ }
- throw new DSpaceSWORDException("No ingester could be found which works for this DSpace Object");
- }
+ throw new DSpaceSWORDException(
+ "No ingester could be found which works for this DSpace Object");
+ }
}
diff --git a/dspace-sword/src/main/java/org/dspace/sword/SWORDMETSIngester.java b/dspace-sword/src/main/java/org/dspace/sword/SWORDMETSIngester.java
index 47f41b3bb4..4d708d8c3a 100644
--- a/dspace-sword/src/main/java/org/dspace/sword/SWORDMETSIngester.java
+++ b/dspace-sword/src/main/java/org/dspace/sword/SWORDMETSIngester.java
@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -32,127 +32,148 @@ import org.purl.sword.base.SWORDErrorException;
public class SWORDMETSIngester implements SWORDIngester
{
- private SWORDService swordService;
- protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
+ private SWORDService swordService;
- /** Log4j logger */
- public static final Logger log = Logger.getLogger(SWORDMETSIngester.class);
+ protected ItemService itemService = ContentServiceFactory.getInstance()
+ .getItemService();
- /* (non-Javadoc)
- * @see org.dspace.sword.SWORDIngester#ingest(org.dspace.core.Context, org.purl.sword.base.Deposit)
- */
- public DepositResult ingest(SWORDService service, Deposit deposit, DSpaceObject dso)
- throws DSpaceSWORDException, SWORDErrorException
- {
- try
- {
- // first, make sure this is the right kind of ingester, and set the collection
- if (!(dso instanceof Collection))
- {
- throw new DSpaceSWORDException("Tried to run an ingester on wrong target type");
- }
- Collection collection = (Collection) dso;
+ /** Log4j logger */
+ public static final Logger log = Logger.getLogger(SWORDMETSIngester.class);
- // now set the sword service
- swordService = service;
+ /* (non-Javadoc)
+ * @see org.dspace.sword.SWORDIngester#ingest(org.dspace.core.Context, org.purl.sword.base.Deposit)
+ */
+ public DepositResult ingest(SWORDService service, Deposit deposit,
+ DSpaceObject dso)
+ throws DSpaceSWORDException, SWORDErrorException
+ {
+ try
+ {
+ // first, make sure this is the right kind of ingester, and set the collection
+ if (!(dso instanceof Collection))
+ {
+ throw new DSpaceSWORDException(
+ "Tried to run an ingester on wrong target type");
+ }
+ Collection collection = (Collection) dso;
- // get the things out of the service that we need
- Context context = swordService.getContext();
+ // now set the sword service
+ swordService = service;
- // get deposited file as InputStream
- File depositFile = deposit.getFile();
+ // get the things out of the service that we need
+ Context context = swordService.getContext();
- // load the plugin manager for the required configuration
- String cfg = ConfigurationManager.getProperty("sword-server", "mets-ingester.package-ingester");
- if (cfg == null || "".equals(cfg))
- {
- cfg = "METS"; // default to METS
- }
- swordService.message("Using package manifest format: " + cfg);
-
- PackageIngester pi = (PackageIngester) PluginManager.getNamedPlugin(PackageIngester.class, cfg);
- swordService.message("Loaded package ingester: " + pi.getClass().getName());
-
- // the licence is either in the zip or the mets manifest. Either way
- // it's none of our business here
- String licence = null;
-
- // Initialize parameters to packager
- PackageParameters params = new PackageParameters();
+ // get deposited file as InputStream
+ File depositFile = deposit.getFile();
+
+ // load the plugin manager for the required configuration
+ String cfg = ConfigurationManager.getProperty("sword-server",
+ "mets-ingester.package-ingester");
+ if (cfg == null || "".equals(cfg))
+ {
+ cfg = "METS"; // default to METS
+ }
+ swordService.message("Using package manifest format: " + cfg);
+
+ PackageIngester pi = (PackageIngester) PluginManager
+ .getNamedPlugin(PackageIngester.class, cfg);
+ swordService.message(
+ "Loaded package ingester: " + pi.getClass().getName());
+
+ // the licence is either in the zip or the mets manifest. Either way
+ // it's none of our business here
+ String licence = null;
+
+ // Initialize parameters to packager
+ PackageParameters params = new PackageParameters();
// Force package ingester to respect Collection workflows
params.setWorkflowEnabled(true);
// Should restore mode be enabled, i.e. keep existing handle?
- if (ConfigurationManager.getBooleanProperty("sword-server", "restore-mode.enable",false))
+ if (ConfigurationManager
+ .getBooleanProperty("sword-server", "restore-mode.enable",
+ false))
{
params.setRestoreModeEnabled(true);
}
// Whether or not to use the collection template
- params.setUseCollectionTemplate(ConfigurationManager.getBooleanProperty("mets.default.ingest.useCollectionTemplate", false));
-
- // ingest the item from the temp file
- DSpaceObject ingestedObject = pi.ingest(context, collection, depositFile, params, licence);
- if (ingestedObject == null)
- {
- swordService.message("Failed to ingest the package; throwing exception");
- throw new SWORDErrorException(DSpaceSWORDErrorCodes.UNPACKAGE_FAIL, "METS package ingester failed to unpack package");
- }
-
- //Verify we have an Item as a result -- SWORD can only ingest Items
- if (!(ingestedObject instanceof Item))
- {
- throw new DSpaceSWORDException("DSpace Ingester returned wrong object type -- not an Item result.");
- }
- else
- {
- //otherwise, we have an item, and a workflow should have already been started for it.
- swordService.message("Workflow process started");
- }
-
- // get reference to item so that we can report on it
- Item installedItem = (Item)ingestedObject;
-
- // update the item metadata to inclue the current time as
- // the updated date
- this.setUpdatedDate(context, installedItem);
-
- // DSpace ignores the slug value as suggested identifier, but
- // it does store it in the metadata
- this.setSlug(installedItem, deposit.getSlug());
-
- // in order to write these changes, we need to bypass the
- // authorisation briefly, because although the user may be
- // able to add stuff to the repository, they may not have
- // WRITE permissions on the archive.
- context.turnOffAuthorisationSystem();
- itemService.update(context, installedItem);
- context.restoreAuthSystemState();
-
- // for some reason, DSpace will not give you the handle automatically,
- // so we have to look it up
- HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
- String handle = handleService.findHandle(context, installedItem);
-
- swordService.message("Ingest successful");
- swordService.message("Item created with internal identifier: " + installedItem.getID());
- if (handle != null)
- {
- swordService.message("Item created with external identifier: " + handle);
- }
- else
- {
- swordService.message("No external identifier available at this stage (item in workflow)");
- }
-
- DepositResult dr = new DepositResult();
- dr.setItem(installedItem);
- dr.setHandle(handle);
- dr.setTreatment(this.getTreatment());
-
- return dr;
- }
+ params.setUseCollectionTemplate(ConfigurationManager
+ .getBooleanProperty(
+ "mets.default.ingest.useCollectionTemplate",
+ false));
+
+ // ingest the item from the temp file
+ DSpaceObject ingestedObject = pi
+ .ingest(context, collection, depositFile, params, licence);
+ if (ingestedObject == null)
+ {
+ swordService.message(
+ "Failed to ingest the package; throwing exception");
+ throw new SWORDErrorException(
+ DSpaceSWORDErrorCodes.UNPACKAGE_FAIL,
+ "METS package ingester failed to unpack package");
+ }
+
+ //Verify we have an Item as a result -- SWORD can only ingest Items
+ if (!(ingestedObject instanceof Item))
+ {
+ throw new DSpaceSWORDException(
+ "DSpace Ingester returned wrong object type -- not an Item result.");
+ }
+ else
+ {
+ //otherwise, we have an item, and a workflow should have already been started for it.
+ swordService.message("Workflow process started");
+ }
+
+ // get reference to item so that we can report on it
+ Item installedItem = (Item) ingestedObject;
+
+ // update the item metadata to inclue the current time as
+ // the updated date
+ this.setUpdatedDate(context, installedItem);
+
+ // DSpace ignores the slug value as suggested identifier, but
+ // it does store it in the metadata
+ this.setSlug(installedItem, deposit.getSlug());
+
+ // in order to write these changes, we need to bypass the
+ // authorisation briefly, because although the user may be
+ // able to add stuff to the repository, they may not have
+ // WRITE permissions on the archive.
+ context.turnOffAuthorisationSystem();
+ itemService.update(context, installedItem);
+ context.restoreAuthSystemState();
+
+ // for some reason, DSpace will not give you the handle automatically,
+ // so we have to look it up
+ HandleService handleService = HandleServiceFactory.getInstance()
+ .getHandleService();
+ String handle = handleService.findHandle(context, installedItem);
+
+ swordService.message("Ingest successful");
+ swordService.message("Item created with internal identifier: " +
+ installedItem.getID());
+ if (handle != null)
+ {
+ swordService.message(
+ "Item created with external identifier: " + handle);
+ }
+ else
+ {
+ swordService.message(
+ "No external identifier available at this stage (item in workflow)");
+ }
+
+ DepositResult dr = new DepositResult();
+ dr.setItem(installedItem);
+ dr.setHandle(handle);
+ dr.setTreatment(this.getTreatment());
+
+ return dr;
+ }
catch (RuntimeException re)
{
log.error("caught exception: ", re);
@@ -165,123 +186,142 @@ public class SWORDMETSIngester implements SWORDIngester
}
}
- /**
- * Add the current date to the item metadata. This looks up
- * the field in which to store this metadata in the configuration
- * sword.updated.field
- *
- *
- * @param context
- * @param item
- * @throws DSpaceSWORDException
- */
- private void setUpdatedDate(Context context, Item item)
- throws DSpaceSWORDException
- {
- String field = ConfigurationManager.getProperty("sword-server", "updated.field");
- if (field == null || "".equals(field))
- {
- throw new DSpaceSWORDException("No configuration, or configuration is invalid for: sword.updated.field");
- }
+ /**
+ * Add the current date to the item metadata. This looks up
+ * the field in which to store this metadata in the configuration
+ * sword.updated.field
+ *
+ *
+ * @param context
+ * @param item
+ * @throws DSpaceSWORDException
+ */
+ private void setUpdatedDate(Context context, Item item)
+ throws DSpaceSWORDException
+ {
+ String field = ConfigurationManager
+ .getProperty("sword-server", "updated.field");
+ if (field == null || "".equals(field))
+ {
+ throw new DSpaceSWORDException(
+ "No configuration, or configuration is invalid for: sword.updated.field");
+ }
- MetadataFieldInfo dc = this.configToDC(field, null);
- try {
- itemService.clearMetadata(context, item, dc.schema, dc.element, dc.qualifier, Item.ANY);
- DCDate date = new DCDate(new Date());
- itemService.addMetadata(context, item, dc.schema, dc.element, dc.qualifier, null, date.toString());
- } catch (SQLException e) {
- log.error("Caught exception: ", e);
- throw new DSpaceSWORDException(e);
- }
+ MetadataFieldInfo dc = this.configToDC(field, null);
+ try
+ {
+ itemService.clearMetadata(context, item, dc.schema, dc.element,
+ dc.qualifier, Item.ANY);
+ DCDate date = new DCDate(new Date());
+ itemService.addMetadata(context, item, dc.schema, dc.element,
+ dc.qualifier, null, date.toString());
+ }
+ catch (SQLException e)
+ {
+ log.error("Caught exception: ", e);
+ throw new DSpaceSWORDException(e);
+ }
- swordService.message("Updated date added to response from item metadata where available");
- }
-
- /**
- * Store the given slug value (which is used for suggested identifiers,
- * and which DSpace ignores) in the item metadata. This looks up the
- * field in which to store this metadata in the configuration
- * sword.slug.field
- *
- * @param item
- * @param slugVal
- * @throws DSpaceSWORDException
- */
- private void setSlug(Item item, String slugVal)
- throws DSpaceSWORDException
- {
- // if there isn't a slug value, don't set it
- if (slugVal == null)
- {
- return;
- }
-
- String field = ConfigurationManager.getProperty("sword-server", "slug.field");
- if (field == null || "".equals(field))
- {
- throw new DSpaceSWORDException("No configuration, or configuration is invalid for: sword.slug.field");
- }
+ swordService.message(
+ "Updated date added to response from item metadata where available");
+ }
- MetadataFieldInfo mfi = this.configToDC(field, null);
- try {
- itemService.clearMetadata(swordService.getContext(), item, mfi.schema, mfi.element, mfi.qualifier, Item.ANY);
- itemService.addMetadata(swordService.getContext(), item, mfi.schema, mfi.element, mfi.qualifier, null, slugVal);
- } catch (SQLException e) {
- log.error("Caught exception: ", e);
- throw new DSpaceSWORDException(e);
- }
+ /**
+ * Store the given slug value (which is used for suggested identifiers,
+ * and which DSpace ignores) in the item metadata. This looks up the
+ * field in which to store this metadata in the configuration
+ * sword.slug.field
+ *
+ * @param item
+ * @param slugVal
+ * @throws DSpaceSWORDException
+ */
+ private void setSlug(Item item, String slugVal)
+ throws DSpaceSWORDException
+ {
+ // if there isn't a slug value, don't set it
+ if (slugVal == null)
+ {
+ return;
+ }
- swordService.message("Slug value set in response where available");
- }
-
- /**
- * utility method to turn given metadata fields of the form
- schema.element.qualifier into Metadatum objects which can be
- used to access metadata in items.
- *
- * The def parameter should be null, * or "" depending on how
- you intend to use the Metadatum object
- *
- * @param config
- * @param def
- * @return
- */
- private MetadataFieldInfo configToDC(String config, String def)
- {
- MetadataFieldInfo mfi = new MetadataFieldInfo();
- mfi.schema = def;
- mfi.element= def;
- mfi.qualifier = def;
-
- StringTokenizer stz = new StringTokenizer(config, ".");
- mfi.schema = stz.nextToken();
- mfi.element = stz.nextToken();
- if (stz.hasMoreTokens())
- {
- mfi.qualifier = stz.nextToken();
- }
-
- return mfi;
- }
+ String field = ConfigurationManager
+ .getProperty("sword-server", "slug.field");
+ if (field == null || "".equals(field))
+ {
+ throw new DSpaceSWORDException(
+ "No configuration, or configuration is invalid for: sword.slug.field");
+ }
- /**
- * The human readable description of the treatment this ingester has
- * put the deposit through
- *
- * @return
- * @throws DSpaceSWORDException
- */
- private String getTreatment() throws DSpaceSWORDException
- {
- return "The package has been deposited into DSpace. Each file has been unpacked " +
- "and provided with a unique identifier. The metadata in the manifest has been " +
- "extracted and attached to the DSpace item, which has been provided with " +
- "an identifier leading to an HTML splash page.";
- }
+ MetadataFieldInfo mfi = this.configToDC(field, null);
+ try
+ {
+ itemService
+ .clearMetadata(swordService.getContext(), item, mfi.schema,
+ mfi.element, mfi.qualifier, Item.ANY);
+ itemService.addMetadata(swordService.getContext(), item, mfi.schema,
+ mfi.element, mfi.qualifier, null, slugVal);
+ }
+ catch (SQLException e)
+ {
+ log.error("Caught exception: ", e);
+ throw new DSpaceSWORDException(e);
+ }
- private class MetadataFieldInfo {
- private String schema;
- private String element;
- private String qualifier;
- }
+ swordService.message("Slug value set in response where available");
+ }
+
+ /**
+ * utility method to turn given metadata fields of the form
+ schema.element.qualifier into Metadatum objects which can be
+ used to access metadata in items.
+ *
+ * The def parameter should be null, * or "" depending on how
+ you intend to use the Metadatum object
+ *
+ * @param config
+ * @param def
+ * @return
+ */
+ private MetadataFieldInfo configToDC(String config, String def)
+ {
+ MetadataFieldInfo mfi = new MetadataFieldInfo();
+ mfi.schema = def;
+ mfi.element = def;
+ mfi.qualifier = def;
+
+ StringTokenizer stz = new StringTokenizer(config, ".");
+ mfi.schema = stz.nextToken();
+ mfi.element = stz.nextToken();
+ if (stz.hasMoreTokens())
+ {
+ mfi.qualifier = stz.nextToken();
+ }
+
+ return mfi;
+ }
+
+ /**
+ * The human readable description of the treatment this ingester has
+ * put the deposit through
+ *
+ * @return
+ * @throws DSpaceSWORDException
+ */
+ private String getTreatment() throws DSpaceSWORDException
+ {
+ return "The package has been deposited into DSpace. Each file has been unpacked " +
+ "and provided with a unique identifier. The metadata in the manifest has been " +
+ "extracted and attached to the DSpace item, which has been provided with " +
+ "an identifier leading to an HTML splash page.";
+ }
+
+ private class MetadataFieldInfo
+ {
+ private String schema;
+
+ private String element;
+
+ private String qualifier;
+ }
}
diff --git a/dspace-sword/src/main/java/org/dspace/sword/SWORDProperties.java b/dspace-sword/src/main/java/org/dspace/sword/SWORDProperties.java
index ce26394d5a..c3a405f264 100644
--- a/dspace-sword/src/main/java/org/dspace/sword/SWORDProperties.java
+++ b/dspace-sword/src/main/java/org/dspace/sword/SWORDProperties.java
@@ -2,15 +2,15 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword;
public interface SWORDProperties
{
- /** The version of the SWORD service we are offering */
- public static final String VERSION = "1.3";
+ /** The version of the SWORD service we are offering */
+ public static final String VERSION = "1.3";
- public static final String SOFTWARE_URI = "http://www.dspace.org/ns/sword/1.3.1";
+ public static final String SOFTWARE_URI = "http://www.dspace.org/ns/sword/1.3.1";
}
diff --git a/dspace-sword/src/main/java/org/dspace/sword/SWORDService.java b/dspace-sword/src/main/java/org/dspace/sword/SWORDService.java
index 639e26d4aa..e7030facba 100644
--- a/dspace-sword/src/main/java/org/dspace/sword/SWORDService.java
+++ b/dspace-sword/src/main/java/org/dspace/sword/SWORDService.java
@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -34,164 +34,168 @@ import org.purl.sword.base.Deposit;
*/
public class SWORDService
{
- /** Log4j logging instance */
- public static final Logger log = Logger.getLogger(SWORDService.class);
+ /** Log4j logging instance */
+ public static final Logger log = Logger.getLogger(SWORDService.class);
- protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService();
+ protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory
+ .getInstance().getBitstreamFormatService();
- /** The SWORD context of the request */
- private SWORDContext swordContext;
+ /** The SWORD context of the request */
+ private SWORDContext swordContext;
- /** The configuration of the sword server instance */
- private SWORDConfiguration swordConfig;
+ /** The configuration of the sword server instance */
+ private SWORDConfiguration swordConfig;
- /** The URL Generator */
- private SWORDUrlManager urlManager;
+ /** The URL Generator */
+ private SWORDUrlManager urlManager;
- /** a holder for the messages coming through from the implementation */
- private StringBuilder verboseDescription = new StringBuilder();
+ /** a holder for the messages coming through from the implementation */
+ private StringBuilder verboseDescription = new StringBuilder();
- /** is this a verbose operation */
- private boolean verbose = false;
+ /** is this a verbose operation */
+ private boolean verbose = false;
- /** date formatter */
- private SimpleDateFormat dateFormat;
+ /** date formatter */
+ private SimpleDateFormat dateFormat;
- /**
- * Construct a new service instance around the given authenticated
- * sword context
- *
- * @param sc
- */
- public SWORDService(SWORDContext sc)
- {
- this.swordContext = sc;
- this.swordConfig = new SWORDConfiguration();
- this.urlManager = new SWORDUrlManager(this.swordConfig, this.swordContext.getContext());
- dateFormat = new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss.S]");
- }
+ /**
+ * Construct a new service instance around the given authenticated
+ * sword context
+ *
+ * @param sc
+ */
+ public SWORDService(SWORDContext sc)
+ {
+ this.swordContext = sc;
+ this.swordConfig = new SWORDConfiguration();
+ this.urlManager = new SWORDUrlManager(this.swordConfig,
+ this.swordContext.getContext());
+ dateFormat = new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss.S]");
+ }
- public SWORDUrlManager getUrlManager()
- {
- return urlManager;
- }
+ public SWORDUrlManager getUrlManager()
+ {
+ return urlManager;
+ }
- public void setUrlManager(SWORDUrlManager urlManager)
- {
- this.urlManager = urlManager;
- }
+ public void setUrlManager(SWORDUrlManager urlManager)
+ {
+ this.urlManager = urlManager;
+ }
- public SWORDContext getSwordContext()
- {
- return swordContext;
- }
+ public SWORDContext getSwordContext()
+ {
+ return swordContext;
+ }
- public void setSwordContext(SWORDContext swordContext)
- {
- this.swordContext = swordContext;
- }
+ public void setSwordContext(SWORDContext swordContext)
+ {
+ this.swordContext = swordContext;
+ }
- public SWORDConfiguration getSwordConfig()
- {
- return swordConfig;
- }
+ public SWORDConfiguration getSwordConfig()
+ {
+ return swordConfig;
+ }
- public void setSwordConfig(SWORDConfiguration swordConfig)
- {
- this.swordConfig = swordConfig;
- }
+ public void setSwordConfig(SWORDConfiguration swordConfig)
+ {
+ this.swordConfig = swordConfig;
+ }
- public Context getContext()
- {
- return this.swordContext.getContext();
- }
+ public Context getContext()
+ {
+ return this.swordContext.getContext();
+ }
- public boolean isVerbose()
- {
- return verbose;
- }
+ public boolean isVerbose()
+ {
+ return verbose;
+ }
- public void setVerbose(boolean verbose)
- {
- this.verbose = verbose;
- }
+ public void setVerbose(boolean verbose)
+ {
+ this.verbose = verbose;
+ }
- public StringBuilder getVerboseDescription()
- {
- return verboseDescription;
- }
+ public StringBuilder getVerboseDescription()
+ {
+ return verboseDescription;
+ }
- /**
- * shortcut to registering a message with the verboseDescription
- * member variable. This checks to see if the request is
- * verbose, meaning we don't have to do it inline and break nice
- * looking code up
- *
- * @param message
- */
- public void message(String message)
- {
- // build the processing message
- String msg = dateFormat.format(new Date()) + " " + message + "; \n\n";
+ /**
+ * shortcut to registering a message with the verboseDescription
+ * member variable. This checks to see if the request is
+ * verbose, meaning we don't have to do it inline and break nice
+ * looking code up
+ *
+ * @param message
+ */
+ public void message(String message)
+ {
+ // build the processing message
+ String msg = dateFormat.format(new Date()) + " " + message + "; \n\n";
- // if this is a verbose deposit, then log it
- if (this.verbose)
- {
- verboseDescription.append(msg);
- }
+ // if this is a verbose deposit, then log it
+ if (this.verbose)
+ {
+ verboseDescription.append(msg);
+ }
- // add to server logs anyway
- log.info(msg);
- }
+ // add to server logs anyway
+ log.info(msg);
+ }
- /**
- * Construct the most appropriate filename for the incoming deposit.
- *
- * @param context
- * @param deposit
- * @param original
- * @throws DSpaceSWORDException
- */
- public String getFilename(Context context, Deposit deposit, boolean original)
- throws DSpaceSWORDException
- {
- try
- {
- BitstreamFormat bf = bitstreamFormatService.findByMIMEType(context, deposit.getContentType());
- List
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -31,530 +31,559 @@ import java.util.List;
*/
public class SWORDUrlManager
{
- /** the sword configuration */
- private SWORDConfiguration config;
+ /** the sword configuration */
+ private SWORDConfiguration config;
- /** the active dspace context */
- private Context context;
- protected HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
- protected BitstreamService bitstreamService = ContentServiceFactory.getInstance().getBitstreamService();
+ /** the active dspace context */
+ private Context context;
- public SWORDUrlManager(SWORDConfiguration config, Context context)
- {
- this.config = config;
- this.context = context;
- }
+ protected HandleService handleService = HandleServiceFactory.getInstance()
+ .getHandleService();
- /**
- * Get the generator URL for ATOM entry documents. This can be
- * overridden from the default in configuration.
- */
- public String getGeneratorUrl()
- {
- String cfg = ConfigurationManager.getProperty("sword-server", "generator.url");
- if (cfg == null || "".equals(cfg))
- {
- return SWORDProperties.SOFTWARE_URI;
- }
- return cfg;
- }
+ protected BitstreamService bitstreamService = ContentServiceFactory
+ .getInstance().getBitstreamService();
- /**
- * Obtain the deposit URL for the given collection. These URLs
- * should not be considered persistent, but will remain consistent
- * unless configuration changes are made to DSpace
- *
- * @param collection
- * @return The Deposit URL
- * @throws DSpaceSWORDException
- */
- public String getDepositLocation(Collection collection)
- throws DSpaceSWORDException
- {
- return this.getBaseDepositUrl() + "/" + collection.getHandle();
- }
+ public SWORDUrlManager(SWORDConfiguration config, Context context)
+ {
+ this.config = config;
+ this.context = context;
+ }
- /**
- * Obtain the deposit URL for the given item. These URLs
- * should not be considered persistent, but will remain consistent
- * unless configuration changes are made to DSpace
- *
- * @param item
- * @return The Deposit URL
- * @throws DSpaceSWORDException
- */
- public String getDepositLocation(Item item)
- throws DSpaceSWORDException
- {
- return this.getBaseDepositUrl() + "/" + item.getHandle();
- }
+ /**
+ * Get the generator URL for ATOM entry documents. This can be
+ * overridden from the default in configuration.
+ */
+ public String getGeneratorUrl()
+ {
+ String cfg = ConfigurationManager
+ .getProperty("sword-server", "generator.url");
+ if (cfg == null || "".equals(cfg))
+ {
+ return SWORDProperties.SOFTWARE_URI;
+ }
+ return cfg;
+ }
- /**
- * Obtain the deposit URL for the given community. These URLs
- * should not be considered persistent, but will remain consistent
- * unless configuration changes are made to DSpace
- *
- * @param community
- * @return The Deposit URL
- * @throws DSpaceSWORDException
- */
- public String getDepositLocation(Community community)
- throws DSpaceSWORDException
- {
- // FIXME: there is no deposit url for communities yet, so this could
- // be misleading
- return this.getBaseDepositUrl() + "/" + community.getHandle();
- }
+ /**
+ * Obtain the deposit URL for the given collection. These URLs
+ * should not be considered persistent, but will remain consistent
+ * unless configuration changes are made to DSpace
+ *
+ * @param collection
+ * @return The Deposit URL
+ * @throws DSpaceSWORDException
+ */
+ public String getDepositLocation(Collection collection)
+ throws DSpaceSWORDException
+ {
+ return this.getBaseDepositUrl() + "/" + collection.getHandle();
+ }
- /**
- * Obtain the collection which is represented by the given
- * URL
- *
- * @param context the DSpace context
- * @param location the URL to resolve to a collection
- * @return The collection to which the url resolves
- * @throws DSpaceSWORDException
- */
- // FIXME: we need to generalise this to DSpaceObjects, so that we can support
- // Communities, Collections and Items separately
- public Collection getCollection(Context context, String location)
- throws DSpaceSWORDException, SWORDErrorException
- {
- try
- {
- String baseUrl = this.getBaseDepositUrl();
- if (baseUrl.length() == location.length())
- {
- throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL, "The deposit URL is incomplete");
- }
- String handle = location.substring(baseUrl.length());
- if (handle.startsWith("/"))
- {
- handle = handle.substring(1);
- }
- if ("".equals(handle))
- {
- throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL, "The deposit URL is incomplete");
- }
+ /**
+ * Obtain the deposit URL for the given item. These URLs
+ * should not be considered persistent, but will remain consistent
+ * unless configuration changes are made to DSpace
+ *
+ * @param item
+ * @return The Deposit URL
+ * @throws DSpaceSWORDException
+ */
+ public String getDepositLocation(Item item)
+ throws DSpaceSWORDException
+ {
+ return this.getBaseDepositUrl() + "/" + item.getHandle();
+ }
- DSpaceObject dso = handleService.resolveToObject(context, handle);
+ /**
+ * Obtain the deposit URL for the given community. These URLs
+ * should not be considered persistent, but will remain consistent
+ * unless configuration changes are made to DSpace
+ *
+ * @param community
+ * @return The Deposit URL
+ * @throws DSpaceSWORDException
+ */
+ public String getDepositLocation(Community community)
+ throws DSpaceSWORDException
+ {
+ // FIXME: there is no deposit url for communities yet, so this could
+ // be misleading
+ return this.getBaseDepositUrl() + "/" + community.getHandle();
+ }
- if (!(dso instanceof Collection))
- {
- throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL, "The deposit URL does not resolve to a valid collection");
- }
+ /**
+ * Obtain the collection which is represented by the given
+ * URL
+ *
+ * @param context the DSpace context
+ * @param location the URL to resolve to a collection
+ * @return The collection to which the url resolves
+ * @throws DSpaceSWORDException
+ */
+ // FIXME: we need to generalise this to DSpaceObjects, so that we can support
+ // Communities, Collections and Items separately
+ public Collection getCollection(Context context, String location)
+ throws DSpaceSWORDException, SWORDErrorException
+ {
+ try
+ {
+ String baseUrl = this.getBaseDepositUrl();
+ if (baseUrl.length() == location.length())
+ {
+ throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL,
+ "The deposit URL is incomplete");
+ }
+ String handle = location.substring(baseUrl.length());
+ if (handle.startsWith("/"))
+ {
+ handle = handle.substring(1);
+ }
+ if ("".equals(handle))
+ {
+ throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL,
+ "The deposit URL is incomplete");
+ }
- return (Collection) dso;
- }
- catch (SQLException e)
- {
- // log.error("Caught exception:", e);
- throw new DSpaceSWORDException("There was a problem resolving the collection", e);
- }
- }
+ DSpaceObject dso = handleService.resolveToObject(context, handle);
- /**
- * Obtain the collection which is represented by the given
- * URL
- *
- * @param context the DSpace context
- * @param location the URL to resolve to a collection
- * @return The collection to which the url resolves
- * @throws DSpaceSWORDException
- */
- public DSpaceObject getDSpaceObject(Context context, String location)
- throws DSpaceSWORDException, SWORDErrorException
- {
- try
- {
- String baseUrl = this.getBaseDepositUrl();
- if (baseUrl.length() == location.length())
- {
- throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL, "The deposit URL is incomplete");
- }
- String handle = location.substring(baseUrl.length());
- if (handle.startsWith("/"))
- {
- handle = handle.substring(1);
- }
- if ("".equals(handle))
- {
- throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL, "The deposit URL is incomplete");
- }
+ if (!(dso instanceof Collection))
+ {
+ throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL,
+ "The deposit URL does not resolve to a valid collection");
+ }
- DSpaceObject dso = handleService.resolveToObject(context, handle);
+ return (Collection) dso;
+ }
+ catch (SQLException e)
+ {
+ // log.error("Caught exception:", e);
+ throw new DSpaceSWORDException(
+ "There was a problem resolving the collection", e);
+ }
+ }
- if (!(dso instanceof Collection) && !(dso instanceof Item))
- {
- throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL, "The deposit URL does not resolve to a valid deposit target");
- }
+ /**
+ * Obtain the collection which is represented by the given
+ * URL
+ *
+ * @param context the DSpace context
+ * @param location the URL to resolve to a collection
+ * @return The collection to which the url resolves
+ * @throws DSpaceSWORDException
+ */
+ public DSpaceObject getDSpaceObject(Context context, String location)
+ throws DSpaceSWORDException, SWORDErrorException
+ {
+ try
+ {
+ String baseUrl = this.getBaseDepositUrl();
+ if (baseUrl.length() == location.length())
+ {
+ throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL,
+ "The deposit URL is incomplete");
+ }
+ String handle = location.substring(baseUrl.length());
+ if (handle.startsWith("/"))
+ {
+ handle = handle.substring(1);
+ }
+ if ("".equals(handle))
+ {
+ throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL,
+ "The deposit URL is incomplete");
+ }
- return dso;
- }
- catch (SQLException e)
- {
- // log.error("Caught exception:", e);
- throw new DSpaceSWORDException("There was a problem resolving the collection", e);
- }
- }
+ DSpaceObject dso = handleService.resolveToObject(context, handle);
- /**
- * Construct the service document URL for the given object, which will
- * be supplied in the sword:service element of other service document
- * entries.
- *
- * @param community
- * @throws DSpaceSWORDException
- */
- public String constructSubServiceUrl(Community community)
- throws DSpaceSWORDException
- {
- String base = this.getBaseServiceDocumentUrl();
- String handle = community.getHandle();
- return base + "/" + handle;
- }
+ if (!(dso instanceof Collection) && !(dso instanceof Item))
+ {
+ throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL,
+ "The deposit URL does not resolve to a valid deposit target");
+ }
- /**
- * Construct the service document URL for the given object, which will
- * be supplied in the sword:service element of other service document
- * entries.
- *
- * @param collection
- * @throws DSpaceSWORDException
- */
- public String constructSubServiceUrl(Collection collection)
- throws DSpaceSWORDException
- {
- String base = this.getBaseServiceDocumentUrl();
- String handle = collection.getHandle();
- return base + "/" + handle;
- }
+ return dso;
+ }
+ catch (SQLException e)
+ {
+ // log.error("Caught exception:", e);
+ throw new DSpaceSWORDException(
+ "There was a problem resolving the collection", e);
+ }
+ }
- /**
- * Extract a DSpaceObject from the given URL. If this method is unable to
- * locate a meaningful and appropriate DSpace object it will throw the
- * appropriate SWORD error.
- * @param url
- * @throws DSpaceSWORDException
- * @throws SWORDErrorException
- */
- public DSpaceObject extractDSpaceObject(String url)
- throws DSpaceSWORDException, SWORDErrorException
- {
- try
- {
- String sdBase = this.getBaseServiceDocumentUrl();
- String mlBase = this.getBaseMediaLinkUrl();
+ /**
+ * Construct the service document URL for the given object, which will
+ * be supplied in the sword:service element of other service document
+ * entries.
+ *
+ * @param community
+ * @throws DSpaceSWORDException
+ */
+ public String constructSubServiceUrl(Community community)
+ throws DSpaceSWORDException
+ {
+ String base = this.getBaseServiceDocumentUrl();
+ String handle = community.getHandle();
+ return base + "/" + handle;
+ }
- if (url.startsWith(sdBase))
- {
- // we are dealing with a service document request
-
- // first, let's find the beginning of the handle
- url = url.substring(sdBase.length());
- if (url.startsWith("/"))
- {
- url = url.substring(1);
- }
- if (url.endsWith("/"))
- {
- url = url.substring(0, url.length() - 1);
- }
+ /**
+ * Construct the service document URL for the given object, which will
+ * be supplied in the sword:service element of other service document
+ * entries.
+ *
+ * @param collection
+ * @throws DSpaceSWORDException
+ */
+ public String constructSubServiceUrl(Collection collection)
+ throws DSpaceSWORDException
+ {
+ String base = this.getBaseServiceDocumentUrl();
+ String handle = collection.getHandle();
+ return base + "/" + handle;
+ }
- DSpaceObject dso = handleService.resolveToObject(context, url);
- if (dso instanceof Collection || dso instanceof Community)
- {
- return dso;
- }
- else
- {
- throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL,
- "Service Document request does not refer to a DSpace Collection or Community");
- }
- }
- else if (url.startsWith(mlBase))
- {
- // we are dealing with a bitstream media link
+ /**
+ * Extract a DSpaceObject from the given URL. If this method is unable to
+ * locate a meaningful and appropriate DSpace object it will throw the
+ * appropriate SWORD error.
+ * @param url
+ * @throws DSpaceSWORDException
+ * @throws SWORDErrorException
+ */
+ public DSpaceObject extractDSpaceObject(String url)
+ throws DSpaceSWORDException, SWORDErrorException
+ {
+ try
+ {
+ String sdBase = this.getBaseServiceDocumentUrl();
+ String mlBase = this.getBaseMediaLinkUrl();
- // find the index of the "/bitstream/" segment of the url
- int bsi = url.indexOf("/bitstream/");
+ if (url.startsWith(sdBase))
+ {
+ // we are dealing with a service document request
- // subtsring the url from the end of this "/bitstream/" string, to get the bitstream id
- String bsid = url.substring(bsi + 11);
+ // first, let's find the beginning of the handle
+ url = url.substring(sdBase.length());
+ if (url.startsWith("/"))
+ {
+ url = url.substring(1);
+ }
+ if (url.endsWith("/"))
+ {
+ url = url.substring(0, url.length() - 1);
+ }
- // strip off extraneous slashes
- if (bsid.endsWith("/"))
- {
- bsid = bsid.substring(0, url.length() - 1);
- }
- return bitstreamService.findByIdOrLegacyId(context, bsid);
- }
- else
- {
- throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL,
- "Unable to recognise URL as a valid service document: " + url);
- }
- }
- catch (SQLException e)
- {
- throw new DSpaceSWORDException(e);
- }
- }
+ DSpaceObject dso = handleService.resolveToObject(context, url);
+ if (dso instanceof Collection || dso instanceof Community)
+ {
+ return dso;
+ }
+ else
+ {
+ throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL,
+ "Service Document request does not refer to a DSpace Collection or Community");
+ }
+ }
+ else if (url.startsWith(mlBase))
+ {
+ // we are dealing with a bitstream media link
- /**
- * Get the base URL for service document requests.
- *
- * @throws DSpaceSWORDException
- */
- public String getBaseServiceDocumentUrl()
- throws DSpaceSWORDException
- {
- String depositUrl = ConfigurationManager.getProperty("sword-server", "servicedocument.url");
- if (depositUrl == null || "".equals(depositUrl))
- {
- String dspaceUrl = ConfigurationManager.getProperty("dspace.baseUrl");
- if (dspaceUrl == null || "".equals(dspaceUrl))
- {
- throw new DSpaceSWORDException("Unable to construct service document urls, due to missing/invalid " +
- "config in sword.servicedocument.url and/or dspace.baseUrl");
- }
+ // find the index of the "/bitstream/" segment of the url
+ int bsi = url.indexOf("/bitstream/");
+
+ // subtsring the url from the end of this "/bitstream/" string, to get the bitstream id
+ String bsid = url.substring(bsi + 11);
+
+ // strip off extraneous slashes
+ if (bsid.endsWith("/"))
+ {
+ bsid = bsid.substring(0, url.length() - 1);
+ }
+ return bitstreamService.findByIdOrLegacyId(context, bsid);
+ }
+ else
+ {
+ throw new SWORDErrorException(DSpaceSWORDErrorCodes.BAD_URL,
+ "Unable to recognise URL as a valid service document: " +
+ url);
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new DSpaceSWORDException(e);
+ }
+ }
+
+ /**
+ * Get the base URL for service document requests.
+ *
+ * @throws DSpaceSWORDException
+ */
+ public String getBaseServiceDocumentUrl()
+ throws DSpaceSWORDException
+ {
+ String depositUrl = ConfigurationManager
+ .getProperty("sword-server", "servicedocument.url");
+ if (depositUrl == null || "".equals(depositUrl))
+ {
+ String dspaceUrl = ConfigurationManager
+ .getProperty("dspace.baseUrl");
+ if (dspaceUrl == null || "".equals(dspaceUrl))
+ {
+ throw new DSpaceSWORDException(
+ "Unable to construct service document urls, due to missing/invalid " +
+ "config in sword.servicedocument.url and/or dspace.baseUrl");
+ }
try
{
URL url = new URL(dspaceUrl);
- depositUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), "/sword/servicedocument").toString();
+ depositUrl = new URL(url.getProtocol(), url.getHost(),
+ url.getPort(), "/sword/servicedocument").toString();
}
catch (MalformedURLException e)
{
- throw new DSpaceSWORDException("Unable to construct service document urls, due to invalid dspace.baseUrl " +
- e.getMessage(),e);
+ throw new DSpaceSWORDException(
+ "Unable to construct service document urls, due to invalid dspace.baseUrl " +
+ e.getMessage(), e);
}
+ }
+ return depositUrl;
+ }
- }
- return depositUrl;
- }
-
- /**
- * Get the base deposit URL for the DSpace SWORD implementation. This
- * is effectively the URL of the servlet which deals with deposit
- * requests, and is used as the basis for the individual Collection
- * URLs
- *
- * If the configuration sword.deposit.url is set, this will be returned,
- * but if not, it will construct the url as follows:
- *
- * [dspace.baseUrl]/sword/deposit
- *
- * where dspace.baseUrl is also in the configuration file.
- *
- * @return the base URL for sword deposit
- * @throws DSpaceSWORDException
- */
- public String getBaseDepositUrl()
- throws DSpaceSWORDException
- {
- String depositUrl = ConfigurationManager.getProperty("sword-server", "deposit.url");
- if (depositUrl == null || "".equals(depositUrl))
- {
- String dspaceUrl = ConfigurationManager.getProperty("dspace.baseUrl");
- if (dspaceUrl == null || "".equals(dspaceUrl))
- {
- throw new DSpaceSWORDException("Unable to construct deposit urls, due to missing/invalid config in " +
- "sword.deposit.url and/or dspace.baseUrl");
- }
+ /**
+ * Get the base deposit URL for the DSpace SWORD implementation. This
+ * is effectively the URL of the servlet which deals with deposit
+ * requests, and is used as the basis for the individual Collection
+ * URLs
+ *
+ * If the configuration sword.deposit.url is set, this will be returned,
+ * but if not, it will construct the url as follows:
+ *
+ * [dspace.baseUrl]/sword/deposit
+ *
+ * where dspace.baseUrl is also in the configuration file.
+ *
+ * @return the base URL for sword deposit
+ * @throws DSpaceSWORDException
+ */
+ public String getBaseDepositUrl()
+ throws DSpaceSWORDException
+ {
+ String depositUrl = ConfigurationManager
+ .getProperty("sword-server", "deposit.url");
+ if (depositUrl == null || "".equals(depositUrl))
+ {
+ String dspaceUrl = ConfigurationManager
+ .getProperty("dspace.baseUrl");
+ if (dspaceUrl == null || "".equals(dspaceUrl))
+ {
+ throw new DSpaceSWORDException(
+ "Unable to construct deposit urls, due to missing/invalid config in " +
+ "sword.deposit.url and/or dspace.baseUrl");
+ }
try
{
URL url = new URL(dspaceUrl);
- depositUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), "/sword/deposit").toString();
+ depositUrl = new URL(url.getProtocol(), url.getHost(),
+ url.getPort(), "/sword/deposit").toString();
}
catch (MalformedURLException e)
{
- throw new DSpaceSWORDException("Unable to construct deposit urls, due to invalid dspace.baseUrl " +
- e.getMessage(),e);
+ throw new DSpaceSWORDException(
+ "Unable to construct deposit urls, due to invalid dspace.baseUrl " +
+ e.getMessage(), e);
}
+ }
+ return depositUrl;
+ }
- }
- return depositUrl;
- }
+ /**
+ * Is the given URL the base service document URL?
+ *
+ * @param url
+ * @throws DSpaceSWORDException
+ */
+ public boolean isBaseServiceDocumentUrl(String url)
+ throws DSpaceSWORDException
+ {
+ return this.getBaseServiceDocumentUrl().equals(url);
+ }
- /**
- * Is the given URL the base service document URL?
- *
- * @param url
- * @throws DSpaceSWORDException
- */
- public boolean isBaseServiceDocumentUrl(String url)
- throws DSpaceSWORDException
- {
- return this.getBaseServiceDocumentUrl().equals(url);
- }
+ /**
+ * Is the given URL the base media link URL?
+ *
+ * @param url
+ * @throws DSpaceSWORDException
+ */
+ public boolean isBaseMediaLinkUrl(String url)
+ throws DSpaceSWORDException
+ {
+ return this.getBaseMediaLinkUrl().equals(url);
+ }
- /**
- * Is the given URL the base media link URL?
- *
- * @param url
- * @throws DSpaceSWORDException
- */
- public boolean isBaseMediaLinkUrl(String url)
- throws DSpaceSWORDException
- {
- return this.getBaseMediaLinkUrl().equals(url);
- }
+ /**
+ * Central location for constructing usable URLs for DSpace bitstreams.
+ * There is no place in the main DSpace code base for doing this.
+ *
+ * @param bitstream
+ * @throws DSpaceSWORDException
+ */
+ public String getBitstreamUrl(Bitstream bitstream)
+ throws DSpaceSWORDException
+ {
+ try
+ {
+ List
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -26,148 +26,170 @@ import java.util.List;
public class ServiceDocumentManager
{
- protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
- protected CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
+ protected CollectionService collectionService = ContentServiceFactory
+ .getInstance().getCollectionService();
- private SWORDService swordService;
+ protected CommunityService communityService = ContentServiceFactory
+ .getInstance().getCommunityService();
- private SWORDAuthenticator swordAuth;
+ private SWORDService swordService;
- public ServiceDocumentManager(SWORDService service)
- {
- this.swordService = service;
- this.swordAuth = new SWORDAuthenticator();
- }
+ private SWORDAuthenticator swordAuth;
- /**
- * Obtain the service document for the repository based on the
- * DSpace context and the SWORD context which must be set for
- * this object prior to calling this method.
- *
- * @return The service document based on the context of the request
- * @throws DSpaceSWORDException
- */
- public ServiceDocument getServiceDocument()
- throws DSpaceSWORDException, SWORDErrorException
- {
- return this.getServiceDocument(null);
- }
+ public ServiceDocumentManager(SWORDService service)
+ {
+ this.swordService = service;
+ this.swordAuth = new SWORDAuthenticator();
+ }
- public ServiceDocument getServiceDocument(String url)
- throws DSpaceSWORDException, SWORDErrorException
- {
- // extract the things we need from the service
- Context context = swordService.getContext();
- SWORDContext swordContext = swordService.getSwordContext();
- SWORDConfiguration swordConfig = swordService.getSwordConfig();
- SWORDUrlManager urlManager = swordService.getUrlManager();
+ /**
+ * Obtain the service document for the repository based on the
+ * DSpace context and the SWORD context which must be set for
+ * this object prior to calling this method.
+ *
+ * @return The service document based on the context of the request
+ * @throws DSpaceSWORDException
+ */
+ public ServiceDocument getServiceDocument()
+ throws DSpaceSWORDException, SWORDErrorException
+ {
+ return this.getServiceDocument(null);
+ }
- // construct the ATOM collection generators that we might use
- ATOMCollectionGenerator comGen = new CommunityCollectionGenerator(swordService);
- ATOMCollectionGenerator colGen = new CollectionCollectionGenerator(swordService);
- ATOMCollectionGenerator itemGen = new ItemCollectionGenerator(swordService);
+ public ServiceDocument getServiceDocument(String url)
+ throws DSpaceSWORDException, SWORDErrorException
+ {
+ // extract the things we need from the service
+ Context context = swordService.getContext();
+ SWORDContext swordContext = swordService.getSwordContext();
+ SWORDConfiguration swordConfig = swordService.getSwordConfig();
+ SWORDUrlManager urlManager = swordService.getUrlManager();
- // first check that the context and sword context have
- // been set
- if (context == null)
- {
- throw new DSpaceSWORDException("The Context is null; please set it before calling getServiceDocument");
- }
+ // construct the ATOM collection generators that we might use
+ ATOMCollectionGenerator comGen = new CommunityCollectionGenerator(
+ swordService);
+ ATOMCollectionGenerator colGen = new CollectionCollectionGenerator(
+ swordService);
+ ATOMCollectionGenerator itemGen = new ItemCollectionGenerator(
+ swordService);
- if (swordContext == null)
- {
- throw new DSpaceSWORDException("The SWORD Context is null; please set it before calling getServiceDocument");
- }
+ // first check that the context and sword context have
+ // been set
+ if (context == null)
+ {
+ throw new DSpaceSWORDException(
+ "The Context is null; please set it before calling getServiceDocument");
+ }
- // construct a new service document
- Service service = new Service(SWORDProperties.VERSION, swordConfig.isNoOp(), swordConfig.isVerbose());
+ if (swordContext == null)
+ {
+ throw new DSpaceSWORDException(
+ "The SWORD Context is null; please set it before calling getServiceDocument");
+ }
- // set the max upload size
- service.setMaxUploadSize(swordConfig.getMaxUploadSize());
+ // construct a new service document
+ Service service = new Service(SWORDProperties.VERSION,
+ swordConfig.isNoOp(), swordConfig.isVerbose());
+
+ // set the max upload size
+ service.setMaxUploadSize(swordConfig.getMaxUploadSize());
// Set the generator
this.addGenerator(service);
- //
- if (url == null || urlManager.isBaseServiceDocumentUrl(url))
- {
- // we are dealing with the default service document
+ //
+ if (url == null || urlManager.isBaseServiceDocumentUrl(url))
+ {
+ // we are dealing with the default service document
- // set the title of the workspace as per the name of the DSpace installation
- String ws = ConfigurationManager.getProperty("dspace.name");
- Workspace workspace = new Workspace();
- workspace.setTitle(ws);
+ // set the title of the workspace as per the name of the DSpace installation
+ String ws = ConfigurationManager.getProperty("dspace.name");
+ Workspace workspace = new Workspace();
+ workspace.setTitle(ws);
- // next thing to do is determine whether the default is communities or collections
- boolean swordCommunities = ConfigurationManager.getBooleanProperty("sword-server", "expose-communities");
+ // next thing to do is determine whether the default is communities or collections
+ boolean swordCommunities = ConfigurationManager
+ .getBooleanProperty("sword-server", "expose-communities");
- if (swordCommunities)
- {
- List
* http://www.dspace.org/license/
*/
package org.dspace.sword;
@@ -39,10 +39,17 @@ import java.util.List;
public class SimpleFileIngester implements SWORDIngester
{
- protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
- protected BundleService bundleService = ContentServiceFactory.getInstance().getBundleService();
- protected BitstreamService bitstreamService = ContentServiceFactory.getInstance().getBitstreamService();
- protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService();
+ protected ItemService itemService = ContentServiceFactory.getInstance()
+ .getItemService();
+
+ protected BundleService bundleService = ContentServiceFactory.getInstance()
+ .getBundleService();
+
+ protected BitstreamService bitstreamService = ContentServiceFactory
+ .getInstance().getBitstreamService();
+
+ protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory
+ .getInstance().getBitstreamFormatService();
/**
* Perform the ingest using the given deposit object onto the specified
@@ -54,46 +61,49 @@ public class SimpleFileIngester implements SWORDIngester
* @throws DSpaceSWORDException
* @throws SWORDErrorException
*/
- public DepositResult ingest(SWORDService service, Deposit deposit, DSpaceObject target)
- throws DSpaceSWORDException, SWORDErrorException
- {
- try
- {
- if (!(target instanceof Item))
- {
- throw new DSpaceSWORDException("SimpleFileIngester can only be loaded for deposit onto DSpace Items");
- }
- Item item = (Item) target;
+ public DepositResult ingest(SWORDService service, Deposit deposit,
+ DSpaceObject target)
+ throws DSpaceSWORDException, SWORDErrorException
+ {
+ try
+ {
+ if (!(target instanceof Item))
+ {
+ throw new DSpaceSWORDException(
+ "SimpleFileIngester can only be loaded for deposit onto DSpace Items");
+ }
+ Item item = (Item) target;
- // now set the sword service
+ // now set the sword service
SWORDService swordService = service;
- // get the things out of the service that we need
- Context context = swordService.getContext();
- SWORDUrlManager urlManager = swordService.getUrlManager();
+ // get the things out of the service that we need
+ Context context = swordService.getContext();
+ SWORDUrlManager urlManager = swordService.getUrlManager();
- List
* http://www.dspace.org/license/
*/
@@ -22,9 +22,11 @@ import java.util.Properties;
public class AbstractSimpleDC
{
protected HashMap
* http://www.dspace.org/license/
*/
package org.dspace.sword2;
@@ -24,172 +24,210 @@ import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;
-public abstract class AbstractSwordContentIngester implements SwordContentIngester
+public abstract class AbstractSwordContentIngester
+ implements SwordContentIngester
{
- public static final Logger log = Logger.getLogger(AbstractSwordContentIngester.class);
+ public static final Logger log = Logger
+ .getLogger(AbstractSwordContentIngester.class);
- protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService();
- protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
+ protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory
+ .getInstance().getBitstreamFormatService();
- public DepositResult ingest(Context context, Deposit deposit, DSpaceObject dso, VerboseDescription verboseDescription)
- throws DSpaceSwordException, SwordError, SwordAuthException, SwordServerException
+ protected ItemService itemService = ContentServiceFactory.getInstance()
+ .getItemService();
+
+ public DepositResult ingest(Context context, Deposit deposit,
+ DSpaceObject dso, VerboseDescription verboseDescription)
+ throws DSpaceSwordException, SwordError, SwordAuthException,
+ SwordServerException
{
return this.ingest(context, deposit, dso, verboseDescription, null);
}
- public DepositResult ingest(Context context, Deposit deposit, DSpaceObject dso, VerboseDescription verboseDescription, DepositResult result)
- throws DSpaceSwordException, SwordError, SwordAuthException, SwordServerException
+ public DepositResult ingest(Context context, Deposit deposit,
+ DSpaceObject dso, VerboseDescription verboseDescription,
+ DepositResult result)
+ throws DSpaceSwordException, SwordError, SwordAuthException,
+ SwordServerException
{
if (dso instanceof Collection)
{
- return this.ingestToCollection(context, deposit, (Collection) dso, verboseDescription, result);
+ return this.ingestToCollection(context, deposit, (Collection) dso,
+ verboseDescription, result);
}
else if (dso instanceof Item)
{
- return this.ingestToItem(context, deposit, (Item) dso, verboseDescription, result);
+ return this.ingestToItem(context, deposit, (Item) dso,
+ verboseDescription, result);
}
return null;
}
- public abstract DepositResult ingestToCollection(Context context, Deposit deposit, Collection collection, VerboseDescription verboseDescription, DepositResult result)
- throws DSpaceSwordException, SwordError, SwordAuthException, SwordServerException;
+ public abstract DepositResult ingestToCollection(Context context,
+ Deposit deposit, Collection collection,
+ VerboseDescription verboseDescription, DepositResult result)
+ throws DSpaceSwordException, SwordError, SwordAuthException,
+ SwordServerException;
- public abstract DepositResult ingestToItem(Context context, Deposit deposit, Item item, VerboseDescription verboseDescription, DepositResult result)
- throws DSpaceSwordException, SwordError, SwordAuthException, SwordServerException;
+ public abstract DepositResult ingestToItem(Context context, Deposit deposit,
+ Item item, VerboseDescription verboseDescription,
+ DepositResult result)
+ throws DSpaceSwordException, SwordError, SwordAuthException,
+ SwordServerException;
- protected BitstreamFormat getFormat(Context context, String fileName)
- throws SQLException
- {
- String fext = null;
- int lastDot = fileName.lastIndexOf(".");
- if (lastDot > -1)
- {
- fext = fileName.substring(lastDot + 1);
- }
+ protected BitstreamFormat getFormat(Context context, String fileName)
+ throws SQLException
+ {
+ String fext = null;
+ int lastDot = fileName.lastIndexOf(".");
+ if (lastDot > -1)
+ {
+ fext = fileName.substring(lastDot + 1);
+ }
- if (fext == null)
- {
- return null;
- }
+ if (fext == null)
+ {
+ return null;
+ }
- List
* http://www.dspace.org/license/
*/
package org.dspace.sword2;
@@ -13,17 +13,18 @@ import org.swordapp.server.SwordCollection;
/**
* @author Richard Jones
- *
+ *
* Define an abstract interface for classes wishing to generate ATOM Collections
* for SWORD service documents
*/
public interface AtomCollectionGenerator
{
- /**
- * Build the ATOM Collection which represents the given DSpace Object.
- *
- * @param dso
- * @throws DSpaceSwordException
- */
- public SwordCollection buildCollection(Context context, DSpaceObject dso, SwordConfigurationDSpace config) throws DSpaceSwordException;
+ /**
+ * Build the ATOM Collection which represents the given DSpace Object.
+ *
+ * @param dso
+ * @throws DSpaceSwordException
+ */
+ public SwordCollection buildCollection(Context context, DSpaceObject dso,
+ SwordConfigurationDSpace config) throws DSpaceSwordException;
}
diff --git a/dspace-swordv2/src/main/java/org/dspace/sword2/AtomStatementDisseminator.java b/dspace-swordv2/src/main/java/org/dspace/sword2/AtomStatementDisseminator.java
index 3e7e6ae5c9..ef68a6fdf7 100644
--- a/dspace-swordv2/src/main/java/org/dspace/sword2/AtomStatementDisseminator.java
+++ b/dspace-swordv2/src/main/java/org/dspace/sword2/AtomStatementDisseminator.java
@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword2;
@@ -20,50 +20,58 @@ import org.swordapp.server.SwordServerException;
import java.util.List;
-public class AtomStatementDisseminator extends GenericStatementDisseminator implements SwordStatementDisseminator
+public class AtomStatementDisseminator extends GenericStatementDisseminator
+ implements SwordStatementDisseminator
{
- protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
-
- public Statement disseminate(Context context, Item item) throws DSpaceSwordException, SwordError, SwordServerException
- {
- SwordUrlManager urlManager = new SwordUrlManager(new SwordConfigurationDSpace(), context);
- String feedUri = urlManager.getAtomStatementUri(item);
+ protected ItemService itemService = ContentServiceFactory.getInstance()
+ .getItemService();
- String authorField = ConfigurationManager.getProperty("swordv2-server", "author.field");
- String titleField = ConfigurationManager.getProperty("swordv2-server", "title.field");
- String updatedField = ConfigurationManager.getProperty("swordv2-server", "updated.field");
+ public Statement disseminate(Context context, Item item)
+ throws DSpaceSwordException, SwordError, SwordServerException
+ {
+ SwordUrlManager urlManager = new SwordUrlManager(
+ new SwordConfigurationDSpace(), context);
+ String feedUri = urlManager.getAtomStatementUri(item);
- String author = this.stringMetadata(item, authorField);
- String title = this.stringMetadata(item, titleField);
- String updated = this.stringMetadata(item, updatedField);
+ String authorField = ConfigurationManager
+ .getProperty("swordv2-server", "author.field");
+ String titleField = ConfigurationManager
+ .getProperty("swordv2-server", "title.field");
+ String updatedField = ConfigurationManager
+ .getProperty("swordv2-server", "updated.field");
- Statement s = new AtomStatement(feedUri, author, title, updated);
- this.populateStatement(context, item, s);
- return s;
- }
+ String author = this.stringMetadata(item, authorField);
+ String title = this.stringMetadata(item, titleField);
+ String updated = this.stringMetadata(item, updatedField);
- private String stringMetadata(Item item, String field)
- {
- if (field == null)
- {
- return null;
- }
+ Statement s = new AtomStatement(feedUri, author, title, updated);
+ this.populateStatement(context, item, s);
+ return s;
+ }
- List
* http://www.dspace.org/license/
*/
package org.dspace.sword2;
@@ -33,154 +33,177 @@ import java.util.List;
public class BinaryContentIngester extends AbstractSwordContentIngester
{
- protected WorkspaceItemService workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService();
- protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
- protected BundleService bundleService = ContentServiceFactory.getInstance().getBundleService();
- protected BitstreamService bitstreamService = ContentServiceFactory.getInstance().getBitstreamService();
+ protected WorkspaceItemService workspaceItemService = ContentServiceFactory
+ .getInstance().getWorkspaceItemService();
- public DepositResult ingestToCollection(Context context, Deposit deposit, Collection collection, VerboseDescription verboseDescription, DepositResult result)
- throws DSpaceSwordException, SwordError, SwordAuthException, SwordServerException
- {
- try
- {
- // decide whether we have a new item or an existing one
- Item item = null;
- WorkspaceItem wsi = null;
- if (result != null)
- {
- item = result.getItem();
- }
- else
- {
- result = new DepositResult();
- }
- if (item == null)
- {
- // simple zip ingester uses the item template, since there is no native metadata
- wsi = workspaceItemService.create(context, collection, true);
- item = wsi.getItem();
- }
+ protected ItemService itemService = ContentServiceFactory.getInstance()
+ .getItemService();
- Bitstream bs = itemService.createSingleBitstream(context, deposit.getInputStream(), item);
- BitstreamFormat format = this.getFormat(context, deposit.getFilename());
- bs.setName(context, deposit.getFilename());
- bs.setFormat(context, format);
- bitstreamService.update(context, bs);
+ protected BundleService bundleService = ContentServiceFactory.getInstance()
+ .getBundleService();
- // now we have an item in the workspace, and we need to consider adding some metadata to it,
- // but since the binary file didn't contain anything, what do we do?
- itemService.addMetadata(context, item, "dc", "title", null, null, "Untitled: " + deposit.getFilename());
- itemService.addMetadata(context, item, "dc", "description", null, null, "Zip file deposted by SWORD without accompanying metadata");
+ protected BitstreamService bitstreamService = ContentServiceFactory
+ .getInstance().getBitstreamService();
- // update the item metadata to inclue the current time as
- // the updated date
- this.setUpdatedDate(context, item, verboseDescription);
+ public DepositResult ingestToCollection(Context context, Deposit deposit,
+ Collection collection, VerboseDescription verboseDescription,
+ DepositResult result)
+ throws DSpaceSwordException, SwordError, SwordAuthException,
+ SwordServerException
+ {
+ try
+ {
+ // decide whether we have a new item or an existing one
+ Item item = null;
+ WorkspaceItem wsi = null;
+ if (result != null)
+ {
+ item = result.getItem();
+ }
+ else
+ {
+ result = new DepositResult();
+ }
+ if (item == null)
+ {
+ // simple zip ingester uses the item template, since there is no native metadata
+ wsi = workspaceItemService.create(context, collection, true);
+ item = wsi.getItem();
+ }
- // DSpace ignores the slug value as suggested identifier, but
- // it does store it in the metadata
- this.setSlug(context, item, deposit.getSlug(), verboseDescription);
-
- // in order to write these changes, we need to bypass the
- // authorisation briefly, because although the user may be
- // able to add stuff to the repository, they may not have
- // WRITE permissions on the archive.
- context.turnOffAuthorisationSystem();
- itemService.update(context, item);
- context.restoreAuthSystemState();
-
- verboseDescription.append("Ingest successful");
- verboseDescription.append("Item created with internal identifier: " + item.getID());
-
- result.setItem(item);
- result.setTreatment(this.getTreatment());
- result.setOriginalDeposit(bs);
-
- return result;
- }
- catch (AuthorizeException e)
- {
- throw new SwordAuthException(e);
- }
- catch (SQLException | IOException e)
- {
- throw new DSpaceSwordException(e);
- }
- }
-
- public DepositResult ingestToItem(Context context, Deposit deposit, Item item, VerboseDescription verboseDescription, DepositResult result)
- throws DSpaceSwordException, SwordError, SwordAuthException, SwordServerException
- {
- try
- {
- if (result == null)
- {
- result = new DepositResult();
- }
- result.setItem(item);
-
- // get the original bundle
- List
* http://www.dspace.org/license/
*/
package org.dspace.sword2;
@@ -29,106 +29,114 @@ import java.util.List;
*/
public class CollectionCollectionGenerator implements AtomCollectionGenerator
{
- private static Logger log = Logger.getLogger(CommunityCollectionGenerator.class);
+ private static Logger log = Logger
+ .getLogger(CommunityCollectionGenerator.class);
- protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
+ protected CollectionService collectionService = ContentServiceFactory
+ .getInstance().getCollectionService();
- /**
- * Build the collection for the given DSpaceObject. In this implementation,
- * if the object is not a DSpace COllection, it will throw an exception
- * @param dso
- * @return
- * @throws DSpaceSwordException
- */
- public SwordCollection buildCollection(Context context, DSpaceObject dso, SwordConfigurationDSpace swordConfig)
- throws DSpaceSwordException
- {
- if (!(dso instanceof org.dspace.content.Collection))
- {
- log.error("buildCollection passed argument which is not of type Collection");
- throw new DSpaceSwordException("Incorrect ATOMCollectionGenerator instantiated");
- }
+ /**
+ * Build the collection for the given DSpaceObject. In this implementation,
+ * if the object is not a DSpace COllection, it will throw an exception
+ * @param dso
+ * @return
+ * @throws DSpaceSwordException
+ */
+ public SwordCollection buildCollection(Context context, DSpaceObject dso,
+ SwordConfigurationDSpace swordConfig)
+ throws DSpaceSwordException
+ {
+ if (!(dso instanceof org.dspace.content.Collection))
+ {
+ log.error(
+ "buildCollection passed argument which is not of type Collection");
+ throw new DSpaceSwordException(
+ "Incorrect ATOMCollectionGenerator instantiated");
+ }
- // get the things we need out of the service
- SwordUrlManager urlManager = swordConfig.getUrlManager(context, swordConfig);
+ // get the things we need out of the service
+ SwordUrlManager urlManager = swordConfig
+ .getUrlManager(context, swordConfig);
- Collection col = (Collection) dso;
- SwordCollection scol = new SwordCollection();
+ Collection col = (Collection) dso;
+ SwordCollection scol = new SwordCollection();
- // prepare the parameters to be put in the sword collection
- String location = urlManager.getDepositLocation(col);
+ // prepare the parameters to be put in the sword collection
+ String location = urlManager.getDepositLocation(col);
- // collection title is just its name
- String title = collectionService.getName(col);
+ // collection title is just its name
+ String title = collectionService.getName(col);
- // the collection policy is the licence to which the collection adheres
- String collectionPolicy = collectionService.getLicense(col);
+ // the collection policy is the licence to which the collection adheres
+ String collectionPolicy = collectionService.getLicense(col);
- // FIXME: what is the treatment? Doesn't seem appropriate for DSpace
- // String treatment = " ";
+ // FIXME: what is the treatment? Doesn't seem appropriate for DSpace
+ // String treatment = " ";
- // abstract is the short description of the collection
- List
* http://www.dspace.org/license/
*/
package org.dspace.sword2;
import org.apache.log4j.Logger;
-import org.dspace.authorize.AuthorizeException;
-import org.dspace.content.Bitstream;
-import org.dspace.content.BitstreamFormat;
-import org.dspace.content.Bundle;
import org.dspace.content.Collection;
-import org.dspace.content.DSpaceObject;
-import org.dspace.content.Item;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.CollectionService;
-import org.dspace.core.*;
-import org.swordapp.server.AuthCredentials;
-import org.swordapp.server.CollectionDepositManager;
-import org.swordapp.server.Deposit;
-import org.swordapp.server.DepositReceipt;
-import org.swordapp.server.SwordAuthException;
-import org.swordapp.server.SwordConfiguration;
-import org.swordapp.server.SwordError;
-import org.swordapp.server.SwordServerException;
-import org.swordapp.server.UriRegistry;
+import org.dspace.core.Context;
+import org.dspace.core.LogManager;
+import org.swordapp.server.*;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.BufferedWriter;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.sql.SQLException;
-import java.text.SimpleDateFormat;
import java.util.Date;
-public class CollectionDepositManagerDSpace extends DSpaceSwordAPI implements CollectionDepositManager
+public class CollectionDepositManagerDSpace extends DSpaceSwordAPI
+ implements CollectionDepositManager
{
- /** logger */
- private static Logger log = Logger.getLogger(CollectionDepositManagerDSpace.class);
- protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
+ /**
+ * logger
+ */
+ private static Logger log = Logger
+ .getLogger(CollectionDepositManagerDSpace.class);
- private VerboseDescription verboseDescription = new VerboseDescription();
+ protected CollectionService collectionService = ContentServiceFactory
+ .getInstance().getCollectionService();
- public DepositReceipt createNew(String collectionUri, Deposit deposit, AuthCredentials authCredentials, SwordConfiguration swordConfig)
- throws SwordError, SwordServerException, SwordAuthException
- {
- // start the timer
- Date start = new Date();
+ private VerboseDescription verboseDescription = new VerboseDescription();
- // store up the verbose description, which we can then give back at the end if necessary
- this.verboseDescription.append("Initialising verbose deposit");
+ public DepositReceipt createNew(String collectionUri, Deposit deposit,
+ AuthCredentials authCredentials, SwordConfiguration swordConfig)
+ throws SwordError, SwordServerException, SwordAuthException
+ {
+ // start the timer
+ Date start = new Date();
- SwordContext sc = null;
- SwordConfigurationDSpace config = (SwordConfigurationDSpace) swordConfig;
+ // store up the verbose description, which we can then give back at the end if necessary
+ this.verboseDescription.append("Initialising verbose deposit");
- try
- {
- // first authenticate the request
- // note: this will build our various DSpace contexts for us
- sc = this.doAuth(authCredentials);
- Context context = sc.getContext();
+ SwordContext sc = null;
+ SwordConfigurationDSpace config = (SwordConfigurationDSpace) swordConfig;
- if (log.isDebugEnabled())
- {
- log.debug(LogManager.getHeader(context, "sword_create_new", ""));
- }
+ try
+ {
+ // first authenticate the request
+ // note: this will build our various DSpace contexts for us
+ sc = this.doAuth(authCredentials);
+ Context context = sc.getContext();
- // get the deposit target
- Collection collection = this.getDepositTarget(context, collectionUri, config);
+ if (log.isDebugEnabled())
+ {
+ log.debug(
+ LogManager.getHeader(context, "sword_create_new", ""));
+ }
+
+ // get the deposit target
+ Collection collection = this
+ .getDepositTarget(context, collectionUri, config);
if (collection == null)
{
throw new SwordError(404);
}
- // Ensure that this method is allowed
- WorkflowManager wfm = WorkflowManagerFactory.getInstance();
- wfm.createResource(context, collection);
+ // Ensure that this method is allowed
+ WorkflowManager wfm = WorkflowManagerFactory.getInstance();
+ wfm.createResource(context, collection);
- // find out if the supplied SWORDContext can submit to the given
- // dspace object
+ // find out if the supplied SWORDContext can submit to the given
+ // dspace object
SwordAuthenticator auth = new SwordAuthenticator();
- if (!auth.canSubmit(sc, collection, this.verboseDescription))
- {
- // throw an exception if the deposit can't be made
- String oboEmail = "none";
- if (sc.getOnBehalfOf() != null)
- {
- oboEmail = sc.getOnBehalfOf().getEmail();
- }
- log.info(LogManager.getHeader(context, "deposit_failed_authorisation", "user=" +
- sc.getAuthenticated().getEmail() + ",on_behalf_of=" + oboEmail));
- throw new SwordAuthException("Cannot submit to the given collection with this context");
- }
+ if (!auth.canSubmit(sc, collection, this.verboseDescription))
+ {
+ // throw an exception if the deposit can't be made
+ String oboEmail = "none";
+ if (sc.getOnBehalfOf() != null)
+ {
+ oboEmail = sc.getOnBehalfOf().getEmail();
+ }
+ log.info(LogManager
+ .getHeader(context, "deposit_failed_authorisation",
+ "user=" +
+ sc.getAuthenticated().getEmail() +
+ ",on_behalf_of=" + oboEmail));
+ throw new SwordAuthException(
+ "Cannot submit to the given collection with this context");
+ }
- // make a note of the authentication in the verbose string
- this.verboseDescription.append("Authenticated user: " + sc.getAuthenticated().getEmail());
- if (sc.getOnBehalfOf() != null)
- {
- this.verboseDescription.append("Depositing on behalf of: " + sc.getOnBehalfOf().getEmail());
- }
+ // make a note of the authentication in the verbose string
+ this.verboseDescription.append("Authenticated user: " +
+ sc.getAuthenticated().getEmail());
+ if (sc.getOnBehalfOf() != null)
+ {
+ this.verboseDescription.append("Depositing on behalf of: " +
+ sc.getOnBehalfOf().getEmail());
+ }
- DepositResult result = null;
- try
- {
- if (deposit.isBinaryOnly())
- {
- result = this.createNewFromBinary(sc, collection, deposit, authCredentials, config);
- }
- else if (deposit.isEntryOnly())
- {
- result = this.createNewFromEntry(sc, collection, deposit, authCredentials, config);
- }
- else if (deposit.isMultipart())
- {
- result = this.createNewFromMultipart(sc, collection, deposit, authCredentials, config);
- }
- }
- catch(DSpaceSwordException e)
- {
- if (config.isKeepPackageOnFailedIngest())
- {
- try
- {
- if (deposit.isBinaryOnly())
- {
- this.storePackageAsFile(deposit, authCredentials, config);
- }
- else if (deposit.isEntryOnly())
- {
- this.storeEntryAsFile(deposit, authCredentials, config);
- }
- else if (deposit.isMultipart())
- {
- this.storePackageAsFile(deposit, authCredentials, config);
- this.storeEntryAsFile(deposit, authCredentials, config);
- }
- }
- catch(IOException e2)
- {
- log.warn("Unable to store SWORD package as file: " + e);
- }
- }
- throw e;
- }
- catch(SwordError e)
- {
- if (config.isKeepPackageOnFailedIngest())
- {
- try
- {
- if (deposit.isBinaryOnly())
- {
- this.storePackageAsFile(deposit, authCredentials, config);
- }
- else if (deposit.isEntryOnly())
- {
- this.storeEntryAsFile(deposit, authCredentials, config);
- }
- else if (deposit.isMultipart())
- {
- this.storePackageAsFile(deposit, authCredentials, config);
- this.storeEntryAsFile(deposit, authCredentials, config);
- }
- }
- catch(IOException e2)
- {
- log.warn("Unable to store SWORD package as file: " + e);
- }
- }
- throw e;
- }
+ DepositResult result = null;
+ try
+ {
+ if (deposit.isBinaryOnly())
+ {
+ result = this.createNewFromBinary(sc, collection, deposit,
+ authCredentials, config);
+ }
+ else if (deposit.isEntryOnly())
+ {
+ result = this.createNewFromEntry(sc, collection, deposit,
+ authCredentials, config);
+ }
+ else if (deposit.isMultipart())
+ {
+ result = this
+ .createNewFromMultipart(sc, collection, deposit,
+ authCredentials, config);
+ }
+ }
+ catch (DSpaceSwordException | SwordError e)
+ {
+ if (config.isKeepPackageOnFailedIngest())
+ {
+ try
+ {
+ if (deposit.isBinaryOnly())
+ {
+ this.storePackageAsFile(deposit, authCredentials,
+ config);
+ }
+ else if (deposit.isEntryOnly())
+ {
+ this.storeEntryAsFile(deposit, authCredentials,
+ config);
+ }
+ else if (deposit.isMultipart())
+ {
+ this.storePackageAsFile(deposit, authCredentials,
+ config);
+ this.storeEntryAsFile(deposit, authCredentials,
+ config);
+ }
+ }
+ catch (IOException e2)
+ {
+ log.warn("Unable to store SWORD package as file: " + e);
+ }
+ }
+ throw e;
+ }
// now we've produced a deposit, we need to decide on its workflow state
wfm.resolveState(context, deposit, result, this.verboseDescription);
- ReceiptGenerator genny = new ReceiptGenerator();
- DepositReceipt receipt = genny.createReceipt(context, result, config);
+ ReceiptGenerator genny = new ReceiptGenerator();
+ DepositReceipt receipt = genny
+ .createReceipt(context, result, config);
- Date finish = new Date();
- long delta = finish.getTime() - start.getTime();
+ Date finish = new Date();
+ long delta = finish.getTime() - start.getTime();
- this.verboseDescription.append("Total time for deposit processing: " + delta + " ms");
+ this.verboseDescription
+ .append("Total time for deposit processing: " + delta +
+ " ms");
this.addVerboseDescription(receipt, this.verboseDescription);
- // if something hasn't killed it already (allowed), then complete the transaction
- sc.commit();
+ // if something hasn't killed it already (allowed), then complete the transaction
+ sc.commit();
- return receipt;
- }
- catch (DSpaceSwordException e)
- {
- log.error("caught exception:", e);
- throw new SwordServerException("There was a problem depositing the item", e);
- }
- finally
- {
- // this is a read operation only, so there's never any need to commit the context
- if (sc != null)
- {
- sc.abort();
- }
- }
- }
+ return receipt;
+ }
+ catch (DSpaceSwordException e)
+ {
+ log.error("caught exception:", e);
+ throw new SwordServerException(
+ "There was a problem depositing the item", e);
+ }
+ finally
+ {
+ // this is a read operation only, so there's never any need to commit the context
+ if (sc != null)
+ {
+ sc.abort();
+ }
+ }
+ }
- protected DepositResult createNewFromBinary(SwordContext swordContext, Collection collection, Deposit deposit, AuthCredentials authCredentials, SwordConfigurationDSpace swordConfig)
- throws DSpaceSwordException, SwordError, SwordAuthException, SwordServerException
- {
- // get the things out of the service that we need
- Context context = swordContext.getContext();
- SwordUrlManager urlManager = swordConfig.getUrlManager(swordContext.getContext(), swordConfig);
+ protected DepositResult createNewFromBinary(SwordContext swordContext,
+ Collection collection, Deposit deposit,
+ AuthCredentials authCredentials,
+ SwordConfigurationDSpace swordConfig)
+ throws DSpaceSwordException, SwordError, SwordAuthException,
+ SwordServerException
+ {
+ // get the things out of the service that we need
+ Context context = swordContext.getContext();
+ SwordUrlManager urlManager = swordConfig
+ .getUrlManager(swordContext.getContext(), swordConfig);
// is the content acceptable? If not, this will throw an error
this.isAcceptable(swordConfig, context, deposit, collection);
- // Obtain the relevant ingester from the factory
- SwordContentIngester si = SwordIngesterFactory.getContentInstance(context, deposit, collection);
- this.verboseDescription.append("Loaded ingester: " + si.getClass().getName());
+ // Obtain the relevant ingester from the factory
+ SwordContentIngester si = SwordIngesterFactory
+ .getContentInstance(context, deposit, collection);
+ this.verboseDescription
+ .append("Loaded ingester: " + si.getClass().getName());
- // do the deposit
- DepositResult result = si.ingest(context, deposit, collection, this.verboseDescription);
- this.verboseDescription.append("Archive ingest completed successfully");
+ // do the deposit
+ DepositResult result = si
+ .ingest(context, deposit, collection, this.verboseDescription);
+ this.verboseDescription.append("Archive ingest completed successfully");
- // store the originals (this code deals with the possibility that that's not required)
- this.storeOriginals(swordConfig, context, this.verboseDescription, deposit, result);
+ // store the originals (this code deals with the possibility that that's not required)
+ this.storeOriginals(swordConfig, context, this.verboseDescription,
+ deposit, result);
- return result;
- }
+ return result;
+ }
- protected DepositResult createNewFromEntry(SwordContext swordContext, Collection collection, Deposit deposit, AuthCredentials authCredentials, SwordConfigurationDSpace swordConfig)
- throws DSpaceSwordException, SwordError, SwordAuthException, SwordServerException
- {
- // get the things out of the service that we need
- Context context = swordContext.getContext();
- SwordUrlManager urlManager = swordConfig.getUrlManager(swordContext.getContext(), swordConfig);
+ protected DepositResult createNewFromEntry(SwordContext swordContext,
+ Collection collection, Deposit deposit,
+ AuthCredentials authCredentials,
+ SwordConfigurationDSpace swordConfig)
+ throws DSpaceSwordException, SwordError, SwordAuthException,
+ SwordServerException
+ {
+ // get the things out of the service that we need
+ Context context = swordContext.getContext();
+ SwordUrlManager urlManager = swordConfig
+ .getUrlManager(swordContext.getContext(), swordConfig);
- // Obtain the relevant ingester from the factory
- SwordEntryIngester si = SwordIngesterFactory.getEntryInstance(context, deposit, collection);
- this.verboseDescription.append("Loaded ingester: " + si.getClass().getName());
+ // Obtain the relevant ingester from the factory
+ SwordEntryIngester si = SwordIngesterFactory
+ .getEntryInstance(context, deposit, collection);
+ this.verboseDescription
+ .append("Loaded ingester: " + si.getClass().getName());
- // do the deposit
- DepositResult result = si.ingest(context, deposit, collection, this.verboseDescription);
- this.verboseDescription.append("Archive ingest completed successfully");
+ // do the deposit
+ DepositResult result = si
+ .ingest(context, deposit, collection, this.verboseDescription);
+ this.verboseDescription.append("Archive ingest completed successfully");
- // store the originals (this code deals with the possibility that that's not required)
- this.storeOriginals(swordConfig, context, this.verboseDescription, deposit, result);
+ // store the originals (this code deals with the possibility that that's not required)
+ this.storeOriginals(swordConfig, context, this.verboseDescription,
+ deposit, result);
- return result;
- }
+ return result;
+ }
- protected DepositResult createNewFromMultipart(SwordContext swordContext, Collection collection, Deposit deposit, AuthCredentials authCredentials, SwordConfigurationDSpace swordConfig)
- throws DSpaceSwordException, SwordError, SwordAuthException, SwordServerException
- {
- // get the things out of the service that we need
- Context context = swordContext.getContext();
- SwordUrlManager urlManager = swordConfig.getUrlManager(swordContext.getContext(), swordConfig);
+ protected DepositResult createNewFromMultipart(SwordContext swordContext,
+ Collection collection, Deposit deposit,
+ AuthCredentials authCredentials,
+ SwordConfigurationDSpace swordConfig)
+ throws DSpaceSwordException, SwordError, SwordAuthException,
+ SwordServerException
+ {
+ // get the things out of the service that we need
+ Context context = swordContext.getContext();
+ SwordUrlManager urlManager = swordConfig
+ .getUrlManager(swordContext.getContext(), swordConfig);
- // is the content acceptable? If not, this will throw an error
+ // is the content acceptable? If not, this will throw an error
this.isAcceptable(swordConfig, context, deposit, collection);
- // Obtain the relevant content ingester from the factory
- SwordContentIngester sci = SwordIngesterFactory.getContentInstance(context, deposit, collection);
- this.verboseDescription.append("Loaded content ingester: " + sci.getClass().getName());
+ // Obtain the relevant content ingester from the factory
+ SwordContentIngester sci = SwordIngesterFactory
+ .getContentInstance(context, deposit, collection);
+ this.verboseDescription
+ .append("Loaded content ingester: " + sci.getClass().getName());
// obtain the relevant entry intester from the factory
- SwordEntryIngester sei = SwordIngesterFactory.getEntryInstance(context, deposit, collection);
- this.verboseDescription.append("Loaded entry ingester: " + sei.getClass().getName());
+ SwordEntryIngester sei = SwordIngesterFactory
+ .getEntryInstance(context, deposit, collection);
+ this.verboseDescription
+ .append("Loaded entry ingester: " + sei.getClass().getName());
DepositResult result;
if (swordConfig.isEntryFirst())
{
// do the entry deposit
- result = sei.ingest(context, deposit, collection, this.verboseDescription);
+ result = sei.ingest(context, deposit, collection,
+ this.verboseDescription);
// do the content deposit
- result = sci.ingest(context, deposit, collection, this.verboseDescription, result);
- this.verboseDescription.append("Archive ingest completed successfully");
+ result = sci.ingest(context, deposit, collection,
+ this.verboseDescription, result);
+ this.verboseDescription
+ .append("Archive ingest completed successfully");
}
else
{
// do the content deposit
- result = sci.ingest(context, deposit, collection, this.verboseDescription);
+ result = sci.ingest(context, deposit, collection,
+ this.verboseDescription);
// do the entry deposit
- result = sei.ingest(context, deposit, collection, this.verboseDescription, result, false);
- this.verboseDescription.append("Archive ingest completed successfully");
+ result = sei.ingest(context, deposit, collection,
+ this.verboseDescription, result, false);
+ this.verboseDescription
+ .append("Archive ingest completed successfully");
}
// store the originals (this code deals with the possibility that that's not required)
- this.storeOriginals(swordConfig, context, this.verboseDescription, deposit, result);
+ this.storeOriginals(swordConfig, context, this.verboseDescription,
+ deposit, result);
- return result;
- }
+ return result;
+ }
- protected Collection getDepositTarget(Context context, String depositUrl, SwordConfigurationDSpace config)
- throws DSpaceSwordException, SwordError
- {
- SwordUrlManager urlManager = config.getUrlManager(context, config);
+ protected Collection getDepositTarget(Context context, String depositUrl,
+ SwordConfigurationDSpace config)
+ throws DSpaceSwordException, SwordError
+ {
+ SwordUrlManager urlManager = config.getUrlManager(context, config);
- // get the target collection
- Collection collection = urlManager.getCollection(context, depositUrl);
+ // get the target collection
+ Collection collection = urlManager.getCollection(context, depositUrl);
if (collection == null)
{
throw new SwordError(404);
}
- this.verboseDescription.append("Performing deposit using deposit URL: " + depositUrl);
+ this.verboseDescription
+ .append("Performing deposit using deposit URL: " + depositUrl);
- this.verboseDescription.append("Location resolves to collection with handle: " + collection.getHandle() +
- " and name: " + collectionService.getName(collection));
+ this.verboseDescription
+ .append("Location resolves to collection with handle: " +
+ collection.getHandle() +
+ " and name: " + collectionService.getName(collection));
- return collection;
- }
+ return collection;
+ }
}
diff --git a/dspace-swordv2/src/main/java/org/dspace/sword2/CollectionListManagerDSpace.java b/dspace-swordv2/src/main/java/org/dspace/sword2/CollectionListManagerDSpace.java
index b565cc990f..144c15786e 100644
--- a/dspace-swordv2/src/main/java/org/dspace/sword2/CollectionListManagerDSpace.java
+++ b/dspace-swordv2/src/main/java/org/dspace/sword2/CollectionListManagerDSpace.java
@@ -2,12 +2,11 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword2;
-
import org.apache.abdera.Abdera;
import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.model.Entry;
@@ -32,37 +31,45 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-public class CollectionListManagerDSpace extends DSpaceSwordAPI implements CollectionListManager
+public class CollectionListManagerDSpace extends DSpaceSwordAPI
+ implements CollectionListManager
{
- protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
- protected WorkspaceItemService workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService();
- protected BasicWorkflowItemService basicWorkflowItemService = BasicWorkflowServiceFactory.getInstance().getBasicWorkflowItemService();
+ protected ItemService itemService = ContentServiceFactory.getInstance()
+ .getItemService();
- public Feed listCollectionContents(IRI colIRI, AuthCredentials authCredentials, SwordConfiguration swordConfig)
- throws SwordServerException, SwordError, SwordAuthException
- {
- SwordContext sc = null;
- try
- {
- SwordConfigurationDSpace config = (SwordConfigurationDSpace) swordConfig;
- sc = this.doAuth(authCredentials);
- Context context = sc.getContext();
- SwordUrlManager urlManager = config.getUrlManager(context, config);
+ protected WorkspaceItemService workspaceItemService = ContentServiceFactory
+ .getInstance().getWorkspaceItemService();
- Collection collection = urlManager.getCollection(context, colIRI.toString());
+ protected BasicWorkflowItemService basicWorkflowItemService = BasicWorkflowServiceFactory
+ .getInstance().getBasicWorkflowItemService();
+
+ public Feed listCollectionContents(IRI colIRI,
+ AuthCredentials authCredentials, SwordConfiguration swordConfig)
+ throws SwordServerException, SwordError, SwordAuthException
+ {
+ SwordContext sc = null;
+ try
+ {
+ SwordConfigurationDSpace config = (SwordConfigurationDSpace) swordConfig;
+ sc = this.doAuth(authCredentials);
+ Context context = sc.getContext();
+ SwordUrlManager urlManager = config.getUrlManager(context, config);
+
+ Collection collection = urlManager
+ .getCollection(context, colIRI.toString());
if (collection == null)
{
throw new SwordError(404);
}
- List
* http://www.dspace.org/license/
*/
package org.dspace.sword2;
@@ -25,68 +25,77 @@ import java.util.List;
public class CommunityCollectionGenerator implements AtomCollectionGenerator
{
- private static Logger log = Logger.getLogger(CommunityCollectionGenerator.class);
+ private static Logger log = Logger
+ .getLogger(CommunityCollectionGenerator.class);
- protected HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
- protected CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
+ protected HandleService handleService = HandleServiceFactory.getInstance()
+ .getHandleService();
- public SwordCollection buildCollection(Context context, DSpaceObject dso, SwordConfigurationDSpace swordConfig)
- throws DSpaceSwordException
- {
- if (!(dso instanceof Community))
- {
- log.error("buildCollection passed something other than a Community object");
- throw new DSpaceSwordException("Incorrect ATOMCollectionGenerator instantiated");
- }
+ protected CommunityService communityService = ContentServiceFactory
+ .getInstance().getCommunityService();
- // get the things we need out of the service
- SwordUrlManager urlManager = swordConfig.getUrlManager(context, swordConfig);
+ public SwordCollection buildCollection(Context context, DSpaceObject dso,
+ SwordConfigurationDSpace swordConfig)
+ throws DSpaceSwordException
+ {
+ if (!(dso instanceof Community))
+ {
+ log.error(
+ "buildCollection passed something other than a Community object");
+ throw new DSpaceSwordException(
+ "Incorrect ATOMCollectionGenerator instantiated");
+ }
- Community com = (Community) dso;
- SwordCollection scol = new SwordCollection();
+ // get the things we need out of the service
+ SwordUrlManager urlManager = swordConfig
+ .getUrlManager(context, swordConfig);
- // prepare the parameters to be put in the sword collection
- String location = urlManager.getDepositLocation(com);
- if (location == null)
- {
- location = handleService.getCanonicalForm(com.getHandle());
- }
- scol.setLocation(location);
+ Community com = (Community) dso;
+ SwordCollection scol = new SwordCollection();
- // collection title is just the community name
- String title = communityService.getName(com);
- if (StringUtils.isNotBlank(title))
- {
- scol.setTitle(title);
- }
+ // prepare the parameters to be put in the sword collection
+ String location = urlManager.getDepositLocation(com);
+ if (location == null)
+ {
+ location = handleService.getCanonicalForm(com.getHandle());
+ }
+ scol.setLocation(location);
- // FIXME: the community has no obvious licence
- // the collection policy is the licence to which the collection adheres
- // String collectionPolicy = col.getLicense();
+ // collection title is just the community name
+ String title = communityService.getName(com);
+ if (StringUtils.isNotBlank(title))
+ {
+ scol.setTitle(title);
+ }
- // abstract is the short description of the collection
- List
* http://www.dspace.org/license/
*/
package org.dspace.sword2;
@@ -31,51 +31,64 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-public class ContainerManagerDSpace extends DSpaceSwordAPI implements ContainerManager
+public class ContainerManagerDSpace extends DSpaceSwordAPI
+ implements ContainerManager
{
- private static Logger log = Logger.getLogger(ContainerManagerDSpace.class);
+ private static Logger log = Logger.getLogger(ContainerManagerDSpace.class);
- protected AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
- protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
- protected WorkflowItemService workflowItemService = WorkflowServiceFactory.getInstance().getWorkflowItemService();
- protected WorkspaceItemService workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService();
+ protected AuthorizeService authorizeService = AuthorizeServiceFactory
+ .getInstance().getAuthorizeService();
- private VerboseDescription verboseDescription = new VerboseDescription();
+ protected CollectionService collectionService = ContentServiceFactory
+ .getInstance().getCollectionService();
- public boolean isStatementRequest(String editIRI, Map
* http://www.dspace.org/license/
*/
package org.dspace.sword2;
-
import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Bitstream;
@@ -55,14 +54,21 @@ public class DSpaceSwordAPI
{
private static Logger log = Logger.getLogger(DSpaceSwordAPI.class);
- protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
- protected BundleService bundleService = ContentServiceFactory.getInstance().getBundleService();
- protected BitstreamService bitstreamService = ContentServiceFactory.getInstance().getBitstreamService();
- protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService();
+ protected ItemService itemService = ContentServiceFactory.getInstance()
+ .getItemService();
- public SwordContext noAuthContext()
- throws DSpaceSwordException
- {
+ protected BundleService bundleService = ContentServiceFactory.getInstance()
+ .getBundleService();
+
+ protected BitstreamService bitstreamService = ContentServiceFactory
+ .getInstance().getBitstreamService();
+
+ protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory
+ .getInstance().getBitstreamFormatService();
+
+ public SwordContext noAuthContext()
+ throws DSpaceSwordException
+ {
SwordContext sc = new SwordContext();
Context context = new Context();
sc.setContext(context);
@@ -84,9 +90,14 @@ public class DSpaceSwordAPI
SwordContext sc = auth.authenticate(authCredentials);
// log the request
- String un = authCredentials.getUsername() != null ? authCredentials.getUsername() : "NONE";
- String obo = authCredentials.getOnBehalfOf() != null ? authCredentials.getOnBehalfOf() : "NONE";
- log.info(LogManager.getHeader(sc.getContext(), "sword_auth_request", "username=" + un + ",on_behalf_of=" + obo));
+ String un = authCredentials.getUsername() != null ?
+ authCredentials.getUsername() :
+ "NONE";
+ String obo = authCredentials.getOnBehalfOf() != null ?
+ authCredentials.getOnBehalfOf() :
+ "NONE";
+ log.info(LogManager.getHeader(sc.getContext(), "sword_auth_request",
+ "username=" + un + ",on_behalf_of=" + obo));
return sc;
}
@@ -139,7 +150,8 @@ public class DSpaceSwordAPI
if (components[1].trim().startsWith("q="))
{
// "type;q"
- q = Float.parseFloat(components[1].trim().substring(2)); //strip the "q=" from the start of the q value
+ q = Float.parseFloat(components[1].trim().substring(
+ 2)); //strip the "q=" from the start of the q value
// if the q value is the highest one we've seen so far, record it
if (q > highest_q)
@@ -157,7 +169,8 @@ public class DSpaceSwordAPI
{
// "type;params;q"
params = components[1].trim();
- q = Float.parseFloat(components[1].trim().substring(2)); // strip the "q=" from the start of the q value
+ q = Float.parseFloat(components[1].trim().substring(
+ 2)); // strip the "q=" from the start of the q value
// if the q value is the highest one we've seen so far, record it
if (q > highest_q)
@@ -211,7 +224,7 @@ public class DSpaceSwordAPI
// otherwise, we have to calculate the q value using the following equation which creates a q value "qv"
// within "q_range" of 1.0 [the first part of the eqn] based on the fraction of the way through the total
// accept header list scaled by the q_range [the second part of the eqn]
- float nq = (1 - q_range) + (((-1 * qv)/counter) * q_range);
+ float nq = (1 - q_range) + (((-1 * qv) / counter) * q_range);
if (sorted.containsKey(nq))
{
sorted.get(nq).add(contentType);
@@ -228,28 +241,36 @@ public class DSpaceSwordAPI
return sorted;
}
- public void isAcceptable(SwordConfigurationDSpace swordConfig, Context context, Deposit deposit, DSpaceObject dso)
+ public void isAcceptable(SwordConfigurationDSpace swordConfig,
+ Context context, Deposit deposit, DSpaceObject dso)
throws SwordError, DSpaceSwordException
{
// determine if this is an acceptable file format
- if (!swordConfig.isAcceptableContentType(context, deposit.getMimeType(), dso))
+ if (!swordConfig
+ .isAcceptableContentType(context, deposit.getMimeType(), dso))
{
- log.error("Unacceptable content type detected: " + deposit.getMimeType() + " for object " + dso.getID());
+ log.error("Unacceptable content type detected: " +
+ deposit.getMimeType() + " for object " + dso.getID());
throw new SwordError(UriRegistry.ERROR_CONTENT,
- "Unacceptable content type in deposit request: " + deposit.getMimeType());
+ "Unacceptable content type in deposit request: " +
+ deposit.getMimeType());
}
// determine if this is an acceptable packaging type for the deposit
// if not, we throw a 415 HTTP error (Unsupported Media Type, ERROR_CONTENT)
if (!swordConfig.isAcceptedPackaging(deposit.getPackaging(), dso))
{
- log.error("Unacceptable packaging type detected: " + deposit.getPackaging() + " for object " + dso.getID());
+ log.error("Unacceptable packaging type detected: " +
+ deposit.getPackaging() + " for object " + dso.getID());
throw new SwordError(UriRegistry.ERROR_CONTENT,
- "Unacceptable packaging type in deposit request: " + deposit.getPackaging());
+ "Unacceptable packaging type in deposit request: " +
+ deposit.getPackaging());
}
}
- public void storeOriginals(SwordConfigurationDSpace swordConfig, Context context, VerboseDescription verboseDescription, Deposit deposit, DepositResult result)
+ public void storeOriginals(SwordConfigurationDSpace swordConfig,
+ Context context, VerboseDescription verboseDescription,
+ Deposit deposit, DepositResult result)
throws DSpaceSwordException, SwordServerException
{
// if there's an item availalble, and we want to keep the original
@@ -258,14 +279,16 @@ public class DSpaceSwordAPI
{
if (swordConfig.isKeepOriginal())
{
- verboseDescription.append("DSpace will store an original copy of the deposit, " +
- "as well as ingesting the item into the archive");
+ verboseDescription
+ .append("DSpace will store an original copy of the deposit, " +
+ "as well as ingesting the item into the archive");
// in order to be allowed to add the file back to the item, we need to ignore authorisations
// for a moment
context.turnOffAuthorisationSystem();
- String bundleName = ConfigurationManager.getProperty("swordv2-server", "bundle.name");
+ String bundleName = ConfigurationManager
+ .getProperty("swordv2-server", "bundle.name");
if (bundleName == null || "".equals(bundleName))
{
bundleName = "SWORD";
@@ -283,20 +306,26 @@ public class DSpaceSwordAPI
}
if (swordBundle == null)
{
- swordBundle = bundleService.create(context, item, bundleName);
+ swordBundle = bundleService
+ .create(context, item, bundleName);
}
if (deposit.isMultipart() || deposit.isEntryOnly())
{
String entry = deposit.getSwordEntry().toString();
- ByteArrayInputStream bais = new ByteArrayInputStream(entry.getBytes());
- Bitstream entryBitstream = bitstreamService.create(context, swordBundle, bais);
+ ByteArrayInputStream bais = new ByteArrayInputStream(
+ entry.getBytes());
+ Bitstream entryBitstream = bitstreamService
+ .create(context, swordBundle, bais);
- String fn = this.createEntryFilename(context, deposit, true);
+ String fn = this
+ .createEntryFilename(context, deposit, true);
entryBitstream.setName(context, fn);
- entryBitstream.setDescription(context, "Original SWORD entry document");
+ entryBitstream.setDescription(context,
+ "Original SWORD entry document");
- BitstreamFormat bf = bitstreamFormatService.findByMIMEType(context, "application/xml");
+ BitstreamFormat bf = bitstreamFormatService
+ .findByMIMEType(context, "application/xml");
if (bf != null)
{
entryBitstream.setFormat(context, bf);
@@ -304,7 +333,8 @@ public class DSpaceSwordAPI
bitstreamService.update(context, entryBitstream);
- verboseDescription.append("Original entry stored as " + fn + ", in item bundle " + swordBundle);
+ verboseDescription.append("Original entry stored as " + fn +
+ ", in item bundle " + swordBundle);
}
if (deposit.isMultipart() || deposit.isBinaryOnly())
@@ -316,7 +346,8 @@ public class DSpaceSwordAPI
try
{
fis = deposit.getInputStream();
- bitstream = bitstreamService.create(context, swordBundle, fis);
+ bitstream = bitstreamService
+ .create(context, swordBundle, fis);
}
finally
{
@@ -334,9 +365,11 @@ public class DSpaceSwordAPI
}
bitstream.setName(context, fn);
- bitstream.setDescription(context, "Original SWORD deposit file");
+ bitstream.setDescription(context,
+ "Original SWORD deposit file");
- BitstreamFormat bf = bitstreamFormatService.findByMIMEType(context, deposit.getMimeType());
+ BitstreamFormat bf = bitstreamFormatService
+ .findByMIMEType(context, deposit.getMimeType());
if (bf != null)
{
bitstream.setFormat(context, bf);
@@ -349,7 +382,9 @@ public class DSpaceSwordAPI
// shouldn't mess with it
result.setOriginalDeposit(bitstream);
}
- verboseDescription.append("Original deposit stored as " + fn + ", in item bundle " + swordBundle);
+ verboseDescription
+ .append("Original deposit stored as " + fn +
+ ", in item bundle " + swordBundle);
}
bundleService.update(context, swordBundle);
@@ -374,12 +409,14 @@ public class DSpaceSwordAPI
* @param original
* @throws DSpaceSwordException
*/
- public String createFilename(Context context, Deposit deposit, boolean original)
+ public String createFilename(Context context, Deposit deposit,
+ boolean original)
throws DSpaceSwordException
{
try
{
- BitstreamFormat bf = bitstreamFormatService.findByMIMEType(context, deposit.getMimeType());
+ BitstreamFormat bf = bitstreamFormatService
+ .findByMIMEType(context, deposit.getMimeType());
List
* http://www.dspace.org/license/
*/
package org.dspace.sword2;
@@ -12,31 +12,31 @@ import org.swordapp.server.SwordServerException;
/**
* This Exception class can be thrown by the internals of the
* DSpace SWORD implementation
- *
+ *
* @author Richard Jones
*
*/
public class DSpaceSwordException extends Exception
{
- public DSpaceSwordException()
- {
- super();
- }
+ public DSpaceSwordException()
+ {
+ super();
+ }
- public DSpaceSwordException(String arg0, Throwable arg1)
- {
- super(arg0, arg1);
- }
+ public DSpaceSwordException(String arg0, Throwable arg1)
+ {
+ super(arg0, arg1);
+ }
- public DSpaceSwordException(String arg0)
- {
- super(arg0);
- }
+ public DSpaceSwordException(String arg0)
+ {
+ super(arg0);
+ }
- public DSpaceSwordException(Throwable arg0)
- {
- super(arg0);
- }
+ public DSpaceSwordException(Throwable arg0)
+ {
+ super(arg0);
+ }
}
diff --git a/dspace-swordv2/src/main/java/org/dspace/sword2/DSpaceUriRegistry.java b/dspace-swordv2/src/main/java/org/dspace/sword2/DSpaceUriRegistry.java
index 9df390e306..256311a276 100644
--- a/dspace-swordv2/src/main/java/org/dspace/sword2/DSpaceUriRegistry.java
+++ b/dspace-swordv2/src/main/java/org/dspace/sword2/DSpaceUriRegistry.java
@@ -2,42 +2,50 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword2;
public class DSpaceUriRegistry
{
- public static final String DSPACE_SWORD_NS = "http://www.dspace.org/ns/sword/2.0/";
+ public static final String DSPACE_SWORD_NS = "http://www.dspace.org/ns/sword/2.0/";
- /** if unpackaging the package fails */
- public static final String UNPACKAGE_FAIL = DSPACE_SWORD_NS + "errors/UnpackageFail";
+ /** if unpackaging the package fails */
+ public static final String UNPACKAGE_FAIL =
+ DSPACE_SWORD_NS + "errors/UnpackageFail";
- /** if the url of the request does not resolve to something meaningful */
- public static final String BAD_URL = DSPACE_SWORD_NS + "errors/BadUrl";
+ /** if the url of the request does not resolve to something meaningful */
+ public static final String BAD_URL = DSPACE_SWORD_NS + "errors/BadUrl";
- /** if the media requested is unavailable */
- public static final String MEDIA_UNAVAILABLE = DSPACE_SWORD_NS + "errors/MediaUnavailable";
+ /** if the media requested is unavailable */
+ public static final String MEDIA_UNAVAILABLE =
+ DSPACE_SWORD_NS + "errors/MediaUnavailable";
/* additional codes */
/** Invalid package */
- public static final String PACKAGE_ERROR = DSPACE_SWORD_NS + "errors/PackageError";
+ public static final String PACKAGE_ERROR =
+ DSPACE_SWORD_NS + "errors/PackageError";
/** Missing resources in package */
- public static final String PACKAGE_VALIDATION_ERROR = DSPACE_SWORD_NS + "errors/PackageValidationError";
+ public static final String PACKAGE_VALIDATION_ERROR =
+ DSPACE_SWORD_NS + "errors/PackageValidationError";
/** Crosswalk error */
- public static final String CROSSWALK_ERROR = DSPACE_SWORD_NS + "errors/CrosswalkError";
+ public static final String CROSSWALK_ERROR =
+ DSPACE_SWORD_NS + "errors/CrosswalkError";
/** Invalid collection for linking */
- public static final String COLLECTION_LINK_ERROR = DSPACE_SWORD_NS + "errors/CollectionLinkError";
+ public static final String COLLECTION_LINK_ERROR =
+ DSPACE_SWORD_NS + "errors/CollectionLinkError";
/** Database or IO Error when installing new item */
- public static final String REPOSITORY_ERROR = DSPACE_SWORD_NS + "errors/RepositoryError";
+ public static final String REPOSITORY_ERROR =
+ DSPACE_SWORD_NS + "errors/RepositoryError";
// FIXME: this is being withdrawn from all 406 responses for the time being, in preference
// for ErrorContent as per the spec (whether that is right or wrong)
- public static final String NOT_ACCEPTABLE = DSPACE_SWORD_NS + "errors/NotAcceptable";
+ public static final String NOT_ACCEPTABLE =
+ DSPACE_SWORD_NS + "errors/NotAcceptable";
}
diff --git a/dspace-swordv2/src/main/java/org/dspace/sword2/DepositResult.java b/dspace-swordv2/src/main/java/org/dspace/sword2/DepositResult.java
index 166633f6f7..78e4b8ef6e 100644
--- a/dspace-swordv2/src/main/java/org/dspace/sword2/DepositResult.java
+++ b/dspace-swordv2/src/main/java/org/dspace/sword2/DepositResult.java
@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
- *
+ *
* http://www.dspace.org/license/
*/
package org.dspace.sword2;
@@ -17,61 +17,61 @@ import java.util.Map;
* The DSpace class for representing the results of a deposit
* request. This class can be used to hold all of the relevant
* components required to later build the SWORD response
- *
+ *
* @author Richard Jones
*
*/
public class DepositResult
{
- /** the item created during deposit */
- private Item item;
+ /** the item created during deposit */
+ private Item item;
- /** Bitstream created as a result of the deposit */
- private Bitstream originalDeposit;
+ /** Bitstream created as a result of the deposit */
+ private Bitstream originalDeposit;
- private List
* http://www.dspace.org/license/
*/
package org.dspace.sword2;
@@ -26,7 +26,8 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
-public class FeedContentDisseminator extends AbstractSimpleDC implements SwordContentDisseminator
+public class FeedContentDisseminator extends AbstractSimpleDC
+ implements SwordContentDisseminator
{
public InputStream disseminate(Context context, Item item)
throws DSpaceSwordException, SwordError, SwordServerException
@@ -43,10 +44,13 @@ public class FeedContentDisseminator extends AbstractSimpleDC implements SwordCo
{
if (Constants.CONTENT_BUNDLE_NAME.equals(bundle.getName()))
{
- List
* http://www.dspace.org/license/
*/
package org.dspace.sword2;
@@ -24,135 +24,152 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-public abstract class GenericStatementDisseminator implements SwordStatementDisseminator
+public abstract class GenericStatementDisseminator
+ implements SwordStatementDisseminator
{
- protected SwordUrlManager urlManager;
+ protected SwordUrlManager urlManager;
- protected void populateStatement(Context context, Item item, Statement statement)
- throws DSpaceSwordException
- {
- this.urlManager = new SwordUrlManager(new SwordConfigurationDSpace(), context);
+ protected void populateStatement(Context context, Item item,
+ Statement statement)
+ throws DSpaceSwordException
+ {
+ this.urlManager = new SwordUrlManager(new SwordConfigurationDSpace(),
+ context);
List