DS-3551 "ContextAwareDisseminationCrosswalk" + Javadoc expactations of DisseminationCrosswalk interface

This commit is contained in:
Jonas Van Goolen
2017-04-21 13:13:06 +02:00
parent aef0f52a5b
commit d917b3158d
4 changed files with 63 additions and 14 deletions

View File

@@ -0,0 +1,44 @@
/**
* 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.content.crosswalk;
import org.dspace.core.Context;
import java.sql.SQLException;
/**
* Created by jonas - jonas@atmire.com on 21/04/17.
* Implementation of the {@link DisseminationCrosswalk} interface that enables the ability to set a Context manually
*/
public abstract class ContextAwareDisseminationCrosswalk implements DisseminationCrosswalk{
private Context context;
private boolean contextCreatedInternally = false;
public void setContext(Context context){
this.context = context;
}
public Context getContext() throws SQLException {
if(context == null|| !context.isValid()){
context=new Context();
contextCreatedInternally = true;
}
return context;
}
public void handleContextCleanup() throws SQLException {
if(contextCreatedInternally){
context.complete();
}else{
context.commit();
}
}
}

View File

@@ -7,15 +7,15 @@
*/
package org.dspace.content.crosswalk;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.jdom.Element;
import org.jdom.Namespace;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
/**
* Dissemination Crosswalk plugin -- translate DSpace native
* metadata into an external XML format.
@@ -107,6 +107,9 @@ public interface DisseminationCrosswalk
* Execute crosswalk, returning one XML root element as
* a JDOM <code>Element</code> object.
* This is typically the root element of a document.
* Note that, if the implementing class is of type "{@link org.dspace.content.crosswalk.ContextAwareDisseminationCrosswalk}"
* and a context is present in the method call, you should set the context before calling this method. -> "{@link org.dspace.content.crosswalk.ContextAwareDisseminationCrosswalk#setContext(org.dspace.core.Context)}"
* The implementing class should then use the "{@link ContextAwareDisseminationCrosswalk#getContext()}" and "{@link ContextAwareDisseminationCrosswalk#handleContextCleanup()}" to retrieve and commit/complete the context respectively
* <p>
*
* @param dso the DSpace Object whose metadata to export.

View File

@@ -46,7 +46,7 @@ import java.util.*;
* @author Tim Donohue
* @version $Revision: 2108 $
*/
public class METSRightsCrosswalk
public class METSRightsCrosswalk extends ContextAwareDisseminationCrosswalk
implements IngestionCrosswalk, DisseminationCrosswalk
{
/** log4j category */
@@ -289,16 +289,16 @@ public class METSRightsCrosswalk
* @throws IOException
* @throws SQLException
* @throws AuthorizeException
* @deprecated Do not use this method, please opt for "{@link #disseminateElement(Context context,DSpaceObject dso)}" instead, as this does not internally need to create a new Context
* @deprecated Do not use this method, please opt for "{@link #disseminateElement(Context context, DSpaceObject dso)}" instead, as this does not internally need to create a new Context
*/
@Override
@Deprecated
public Element disseminateElement(DSpaceObject dso)
throws CrosswalkException,
IOException, SQLException, AuthorizeException {
Context context = new Context();
Context context = getContext();
Element element = disseminateElement(context, dso);
context.complete();
handleContextCleanup();
return element;
}
@@ -684,4 +684,5 @@ public class METSRightsCrosswalk
// return -1 to signify failure (as 0 = READ permissions)
return -1;
}
}

View File

@@ -15,9 +15,9 @@ import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.*;
import org.dspace.content.authority.Choices;
import org.dspace.content.crosswalk.ContextAwareDisseminationCrosswalk;
import org.dspace.content.crosswalk.CrosswalkException;
import org.dspace.content.crosswalk.DisseminationCrosswalk;
import org.dspace.content.crosswalk.METSRightsCrosswalk;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.dspace.core.Context;
@@ -650,11 +650,12 @@ public class ItemAdapter extends AbstractAdapter
private Element disseminateElement(DisseminationCrosswalk crosswalk, DSpaceObject dso) throws CrosswalkException, IOException, SQLException, AuthorizeException {
Element dissemination;
if (crosswalk instanceof METSRightsCrosswalk) {
dissemination = ((METSRightsCrosswalk)crosswalk).disseminateElement(context,dso);
} else {
dissemination = crosswalk.disseminateElement(dso);
if(crosswalk instanceof ContextAwareDisseminationCrosswalk)
{
((ContextAwareDisseminationCrosswalk)crosswalk).setContext(context);
}
dissemination = crosswalk.disseminateElement(dso);
return dissemination;
}
@@ -885,7 +886,7 @@ public class ItemAdapter extends AbstractAdapter
SAXFilter filter = new SAXFilter(contentHandler, lexicalHandler, namespaces);
// Allow the basics for XML
filter.allowIgnorableWhitespace().allowCharacters().allowCDATA().allowPrefixMappings();
// Special option, only allow elements below the second level to pass through. This
// Sp@ecial option, only allow elements below the second level to pass through. This
// will trim out the METS declaration and only leave the actual METS parts to be
// included.
filter.allowElements(1);