[DS-852] Split the License step into separate steps for Creative Commons and the site license

git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@6384 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Robin Taylor
2011-05-20 09:33:19 +00:00
parent 00ab827e80
commit e8775db14e
8 changed files with 368 additions and 197 deletions

View File

@@ -0,0 +1,144 @@
/**
* 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.submit.step;
import org.apache.log4j.Logger;
import org.dspace.app.util.SubmissionInfo;
import org.dspace.app.util.Util;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Item;
import org.dspace.content.LicenseUtils;
import org.dspace.core.Context;
import org.dspace.core.LogManager;
import org.dspace.eperson.EPerson;
import org.dspace.license.CreativeCommons;
import org.dspace.submit.AbstractProcessingStep;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
/**
* License step for DSpace Submission Process. Processes the
* user response to the license.
* <P>
* This class performs all the behind-the-scenes processing that
* this particular step requires. This class's methods are utilized
* by both the JSP-UI and the Manakin XML-UI
* <P>
*
* @see org.dspace.app.util.SubmissionConfig
* @see org.dspace.app.util.SubmissionStepConfig
* @see org.dspace.submit.AbstractProcessingStep
*
* @author Tim Donohue
* @version $Revision$
*/
public class CCLicenseStep extends AbstractProcessingStep
{
/***************************************************************************
* STATUS / ERROR FLAGS (returned by doProcessing() if an error occurs or
* additional user interaction may be required)
*
* (Do NOT use status of 0, since it corresponds to STATUS_COMPLETE flag
* defined in the JSPStepManager class)
**************************************************************************/
// user rejected the license
public static final int STATUS_LICENSE_REJECTED = 1;
/** log4j logger */
private static Logger log = Logger.getLogger(CCLicenseStep.class);
/**
* Do any processing of the information input by the user, and/or perform
* step processing (if no user interaction required)
* <P>
* It is this method's job to save any data to the underlying database, as
* necessary, and return error messages (if any) which can then be processed
* by the appropriate user interface (JSP-UI or XML-UI)
* <P>
* NOTE: If this step is a non-interactive step (i.e. requires no UI), then
* it should perform *all* of its processing in this method!
*
* @param context
* current DSpace context
* @param request
* current servlet request object
* @param response
* current servlet response object
* @param subInfo
* submission info object
* @return Status or error flag which will be processed by
* doPostProcessing() below! (if STATUS_COMPLETE or 0 is returned,
* no errors occurred!)
*/
public int doProcessing(Context context, HttpServletRequest request,
HttpServletResponse response, SubmissionInfo subInfo)
throws ServletException, IOException, SQLException,
AuthorizeException
{
String buttonPressed = Util.getSubmitButton(request, NEXT_BUTTON);
// RLR hack - need to distinguish between progress bar real submission
// (if cc_license_url exists, then users has accepted the CC License)
String ccLicenseUrl = request.getParameter("cc_license_url");
if (buttonPressed.equals("submit_no_cc"))
{
// Skipping the CC license - remove any existing license selection
CreativeCommons.removeLicense(context, subInfo.getSubmissionItem()
.getItem());
}
else if ((ccLicenseUrl != null) && (ccLicenseUrl.length() > 0))
{
Item item = subInfo.getSubmissionItem().getItem();
// save the CC license
CreativeCommons.setLicense(context, item, ccLicenseUrl);
}
// commit changes
context.commit();
// completed without errors
return STATUS_COMPLETE;
}
/**
* Retrieves the number of pages that this "step" extends over. This method
* is used to build the progress bar.
* <P>
* This method may just return 1 for most steps (since most steps consist of
* a single page). But, it should return a number greater than 1 for any
* "step" which spans across a number of HTML pages. For example, the
* configurable "Describe" step (configured using input-forms.xml) overrides
* this method to return the number of pages that are defined by its
* configuration file.
* <P>
* Steps which are non-interactive (i.e. they do not display an interface to
* the user) should return a value of 1, so that they are only processed
* once!
*
* @param request
* The HTTP Request
* @param subInfo
* The current submission information object
*
* @return the number of pages in this step
*/
public int getNumberOfPages(HttpServletRequest request,
SubmissionInfo subInfo) throws ServletException
{
return 1;
}
}

View File

@@ -86,45 +86,6 @@ public class LicenseStep extends AbstractProcessingStep
HttpServletResponse response, SubmissionInfo subInfo)
throws ServletException, IOException, SQLException,
AuthorizeException
{
// If creative commons licensing is enabled, then it is page #1
if (CreativeCommons.isEnabled()
&& AbstractProcessingStep.getCurrentPage(request) == 1)
{
// process Creative Commons license
// (and return any error messages encountered)
return processCC(context, request, response, subInfo);
}
// otherwise, if we came from general DSpace license
else
{
// process DSpace license (and return any error messages
// encountered)
return processLicense(context, request, response, subInfo);
}
}
/**
* Process the input from the license page
*
* @param context
* current DSpace context
* @param request
* current servlet request object
* @param response
* current servlet response object
* @param subInfo
* submission info object
*
* @return Status or error flag which will be processed by
* UI-related code! (if STATUS_COMPLETE or 0 is returned,
* no errors occurred!)
*/
protected int processLicense(Context context, HttpServletRequest request,
HttpServletResponse response, SubmissionInfo subInfo)
throws ServletException, IOException, SQLException,
AuthorizeException
{
String buttonPressed = Util.getSubmitButton(request, CANCEL_BUTTON);
@@ -183,53 +144,6 @@ public class LicenseStep extends AbstractProcessingStep
return STATUS_COMPLETE;
}
/**
* Process the input from the CC license page
*
* @param context
* current DSpace context
* @param request
* current servlet request object
* @param response
* current servlet response object
* @param subInfo
* submission info object
*
* @return Status or error flag which will be processed by
* doPostProcessing() below! (if STATUS_COMPLETE or 0 is returned,
* no errors occurred!)
*/
protected int processCC(Context context, HttpServletRequest request,
HttpServletResponse response, SubmissionInfo subInfo)
throws ServletException, IOException, SQLException,
AuthorizeException
{
String buttonPressed = Util.getSubmitButton(request, NEXT_BUTTON);
// RLR hack - need to distinguish between progress bar real submission
// (if cc_license_url exists, then users has accepted the CC License)
String ccLicenseUrl = request.getParameter("cc_license_url");
if (buttonPressed.equals("submit_no_cc"))
{
// Skipping the CC license - remove any existing license selection
CreativeCommons.removeLicense(context, subInfo.getSubmissionItem()
.getItem());
}
else if ((ccLicenseUrl != null) && (ccLicenseUrl.length() > 0))
{
Item item = subInfo.getSubmissionItem().getItem();
// save the CC license
CreativeCommons.setLicense(context, item, ccLicenseUrl);
}
// commit changes
context.commit();
// completed without errors
return STATUS_COMPLETE;
}
/**
* Retrieves the number of pages that this "step" extends over. This method
@@ -255,17 +169,9 @@ public class LicenseStep extends AbstractProcessingStep
*/
public int getNumberOfPages(HttpServletRequest request,
SubmissionInfo subInfo) throws ServletException
{
// if creative commons licensing is enabled,
// then there are 2 license pages
if (CreativeCommons.isEnabled())
{
return 2;
}
else
{
return 1;
}
}
}

View File

@@ -924,6 +924,7 @@ jsp.submit.no-theses.info4 = For more infor
jsp.submit.no-theses.info5 = Thank you for your interest in DSpace!
jsp.submit.no-theses.title = Theses Not Accepted in DSpace
jsp.submit.progressbar.complete = Complete
jsp.submit.progressbar.CClicense = License
jsp.submit.progressbar.describe = Describe
jsp.submit.progressbar.initial-questions = Describe
jsp.submit.progressbar.license = License

View File

@@ -0,0 +1,190 @@
/**
* 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.app.webui.submit.step;
import org.apache.log4j.Logger;
import org.dspace.app.util.SubmissionInfo;
import org.dspace.app.util.Util;
import org.dspace.app.webui.servlet.SubmissionController;
import org.dspace.app.webui.submit.JSPStep;
import org.dspace.app.webui.submit.JSPStepManager;
import org.dspace.app.webui.util.JSPManager;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Item;
import org.dspace.content.LicenseUtils;
import org.dspace.content.WorkspaceItem;
import org.dspace.core.Context;
import org.dspace.core.LogManager;
import org.dspace.license.CreativeCommons;
import org.dspace.submit.step.LicenseStep;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
/**
* License step for DSpace JSP-UI. Presents the user with license information
* required for all items submitted into DSpace.
* <P>
* This JSPStep class works with the SubmissionController servlet
* for the JSP-UI
* <P>
* The following methods are called in this order:
* <ul>
* <li>Call doPreProcessing() method</li>
* <li>If showJSP() was specified from doPreProcessing(), then the JSP
* specified will be displayed</li>
* <li>If showJSP() was not specified from doPreProcessing(), then the
* doProcessing() method is called an the step completes immediately</li>
* <li>Call doProcessing() method on appropriate AbstractProcessingStep after the user returns from the JSP, in order
* to process the user input</li>
* <li>Call doPostProcessing() method to determine if more user interaction is
* required, and if further JSPs need to be called.</li>
* <li>If there are more "pages" in this step then, the process begins again
* (for the new page).</li>
* <li>Once all pages are complete, control is forwarded back to the
* SubmissionController, and the next step is called.</li>
* </ul>
*
* @see org.dspace.app.webui.servlet.SubmissionController
* @see org.dspace.app.webui.submit.JSPStep
* @see org.dspace.submit.step.LicenseStep
*
* @author Tim Donohue
* @version $Revision$
*/
public class JSPCCLicenseStep extends JSPStep
{
/** JSP which displays Creative Commons license information * */
private static final String CC_LICENSE_JSP = "/submit/creative-commons.jsp";
/** JSP which displays information after a license is rejected * */
private static final String LICENSE_REJECT_JSP = "/submit/license-rejected.jsp";
/** log4j logger */
private static Logger log = Logger.getLogger(JSPCCLicenseStep.class);
/**
* Do any pre-processing to determine which JSP (if any) is used to generate
* the UI for this step. This method should include the gathering and
* validating of all data required by the JSP. In addition, if the JSP
* requires any variable to passed to it on the Request, this method should
* set those variables.
* <P>
* If this step requires user interaction, then this method must call the
* JSP to display, using the "showJSP()" method of the JSPStepManager class.
* <P>
* If this step doesn't require user interaction OR you are solely using
* Manakin for your user interface, then this method may be left EMPTY,
* since all step processing should occur in the doProcessing() method.
*
* @param context
* current DSpace context
* @param request
* current servlet request object
* @param response
* current servlet response object
* @param subInfo
* submission info object
*/
public void doPreProcessing(Context context, HttpServletRequest request,
HttpServletResponse response, SubmissionInfo subInfo)
throws ServletException, IOException, SQLException,
AuthorizeException
{
// Do we already have a CC license?
Item item = subInfo.getSubmissionItem().getItem();
boolean exists = CreativeCommons.hasLicense(context, item);
request.setAttribute("cclicense.exists", Boolean.valueOf(exists));
JSPStepManager.showJSP(request, response, subInfo, CC_LICENSE_JSP);
}
/**
* Do any post-processing after the step's backend processing occurred (in
* the doProcessing() method).
* <P>
* It is this method's job to determine whether processing completed
* successfully, or display another JSP informing the users of any potential
* problems/errors.
* <P>
* If this step doesn't require user interaction OR you are solely using
* Manakin for your user interface, then this method may be left EMPTY,
* since all step processing should occur in the doProcessing() method.
*
* @param context
* current DSpace context
* @param request
* current servlet request object
* @param response
* current servlet response object
* @param subInfo
* submission info object
* @param status
* any status/errors reported by doProcessing() method
*/
public void doPostProcessing(Context context, HttpServletRequest request,
HttpServletResponse response, SubmissionInfo subInfo, int status)
throws ServletException, IOException, SQLException,
AuthorizeException
{
String buttonPressed = Util.getSubmitButton(request, LicenseStep.CANCEL_BUTTON);
// JSP-UI Specific (only JSP UI has a "reject" button):
// License was explicitly rejected
if (buttonPressed.equals("submit_reject"))
{
// User has rejected license.
log.info(LogManager.getHeader(context, "reject_license",
subInfo.getSubmissionLogInfo()));
// If the license page was the 1st page in the Submission process,
// then delete the submission if they reject the license!
if (!subInfo.isInWorkflow()
&& (SubmissionController.getStepReached(subInfo) <= SubmissionController.FIRST_STEP))
{
WorkspaceItem wi = (WorkspaceItem) subInfo.getSubmissionItem();
wi.deleteAll();
// commit changes
context.commit();
}
// Show the license rejected page
JSPManager.showJSP(request, response, LICENSE_REJECT_JSP);
}
}
/**
* Return the URL path (e.g. /submit/review-metadata.jsp) of the JSP
* which will review the information that was gathered in this Step.
* <P>
* This Review JSP is loaded by the 'Verify' Step, in order to dynamically
* generate a submission verification page consisting of the information
* gathered in all the enabled submission steps.
*
* @param context
* current DSpace context
* @param request
* current servlet request object
* @param response
* current servlet response object
* @param subInfo
* submission info object
*/
public String getReviewJSP(Context context, HttpServletRequest request,
HttpServletResponse response, SubmissionInfo subInfo)
{
return NO_JSP; //signing off on license does not require reviewing
}
}

View File

@@ -104,16 +104,16 @@ public class JSPLicenseStep extends JSPStep
throws ServletException, IOException, SQLException,
AuthorizeException
{
// if creative commons licensing is enabled, then it is page #1
if (CreativeCommons.isEnabled() && LicenseStep.getCurrentPage(request) == 1)
{
showCCLicense(context, request, response, subInfo);
}
else
// otherwise load default DSpace license agreement
{
showLicense(context, request, response, subInfo);
}
String license = LicenseUtils.getLicenseText(
context.getCurrentLocale(), subInfo.getSubmissionItem()
.getCollection(),
subInfo.getSubmissionItem().getItem(), subInfo
.getSubmissionItem().getSubmitter());
request.setAttribute("license", license);
JSPStepManager.showJSP(request, response, subInfo, LICENSE_JSP);
}
/**
@@ -173,56 +173,6 @@ public class JSPLicenseStep extends JSPStep
}
/**
* Show the DSpace license page to the user
*
* @param context
* current DSpace context
* @param request
* the request object
* @param response
* the response object
* @param subInfo
* the SubmissionInfo object
*/
private void showLicense(Context context, HttpServletRequest request,
HttpServletResponse response, SubmissionInfo subInfo)
throws SQLException, ServletException, IOException
{
String license = LicenseUtils.getLicenseText(
context.getCurrentLocale(), subInfo.getSubmissionItem()
.getCollection(),
subInfo.getSubmissionItem().getItem(), subInfo
.getSubmissionItem().getSubmitter());
request.setAttribute("license", license);
JSPStepManager.showJSP(request, response, subInfo, LICENSE_JSP);
}
/**
* Show the Creative Commons license page to the user
*
* @param context
* current DSpace context
* @param request
* the request object
* @param response
* the response object
* @param subInfo
* the SubmissionInfo object
*/
private void showCCLicense(Context context, HttpServletRequest request,
HttpServletResponse response, SubmissionInfo subInfo)
throws SQLException, ServletException, IOException
{
// Do we already have a CC license?
Item item = subInfo.getSubmissionItem().getItem();
boolean exists = CreativeCommons.hasLicense(context, item);
request.setAttribute("cclicense.exists", Boolean.valueOf(exists));
JSPStepManager.showJSP(request, response, subInfo, CC_LICENSE_JSP);
}
/**
* Return the URL path (e.g. /submit/review-metadata.jsp) of the JSP
* which will review the information that was gathered in this Step.

View File

@@ -67,11 +67,7 @@ public class LicenseStep extends AbstractSubmissionStep
protected static final Message T_submit_complete =
message("xmlui.Submission.submit.LicenseStep.submit_complete");
/**
* Global reference to Creative Commons license page
* (this is used when CC Licensing is enabled in dspace.cfg)
**/
private CCLicenseStep ccLicenseStep = null;
/**
* Establish our required parameters, abstractStep will enforce these.
@@ -82,41 +78,10 @@ public class LicenseStep extends AbstractSubmissionStep
this.requireStep = true;
}
/**
* Check if this is actually the creative commons license step
*/
public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters)
throws ProcessingException, SAXException, IOException
{
super.setup(resolver,objectModel,src,parameters);
//if Creative Commons licensing is enabled, and
//we are on the 1st page of Licensing,
//then this is the CC License page
if (CreativeCommons.isEnabled() && this.getPage()==1)
{
ccLicenseStep = new CCLicenseStep();
ccLicenseStep.setup(resolver, objectModel, src, parameters);
}
else
{
ccLicenseStep = null;
}
}
public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException
{
// If Creative Commons licensing is enabled,
// and we've initialized the CC license Page
// then load the CreativeCommons page!
if (CreativeCommons.isEnabled() && ccLicenseStep!=null)
{
//add body for CC License page
ccLicenseStep.addBody(body);
return;
}
// Get the full text for the actuial licese
Collection collection = submission.getCollection();

View File

@@ -579,6 +579,7 @@
<message key="xmlui.Submission.submit.progressbar.upload">Upload</message>
<message key="xmlui.Submission.submit.progressbar.verify">Review</message>
<message key="xmlui.Submission.submit.progressbar.creative-commons">Creative Commons</message>
<message key="xmlui.Submission.submit.progressbar.CClicense">License</message>
<message key="xmlui.Submission.submit.progressbar.license">License</message>
<message key="xmlui.Submission.submit.progressbar.complete">Complete</message>

View File

@@ -218,7 +218,19 @@
<workflow-editable>true</workflow-editable>
</step>
<!--Step 5 will be to Sign off on the License-->
<!--Step 5 will be to select a Creative Commons License-->
<!-- Uncomment this step to allow the user to select a Creative Commons license -->
<!--
<step>
<heading>submit.progressbar.CClicense</heading>
<processing-class>org.dspace.submit.step.CCLicenseStep</processing-class>
<jspui-binding>org.dspace.app.webui.submit.step.JSPCCLicenseStep</jspui-binding>
<xmlui-binding>org.dspace.app.xmlui.aspect.submission.submit.CCLicenseStep</xmlui-binding>
<workflow-editable>false</workflow-editable>
</step>
-->
<!--Step 6 will be to Sign off on the License-->
<step>
<heading>submit.progressbar.license</heading>
<processing-class>org.dspace.submit.step.LicenseStep</processing-class>
@@ -227,6 +239,8 @@
<workflow-editable>false</workflow-editable>
</step>
</submission-process>
</submission-definitions>