Adding DirectRedirectResponseValues and EditConfiguration.urlToReturnTo
This commit is contained in:
parent
af9dab5863
commit
b09f9af74f
6 changed files with 158 additions and 86 deletions
|
@ -196,6 +196,9 @@ public class UrlBuilder {
|
||||||
return getUrl(path);
|
return getUrl(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: document this as it is used all over the app
|
||||||
|
//does this append the context? What if params is null?
|
||||||
|
//What if you want a route that isn't in Route?
|
||||||
public static String getUrl(Route route, ParamMap params) {
|
public static String getUrl(Route route, ParamMap params) {
|
||||||
return getUrl(route.path(), params);
|
return getUrl(route.path(), params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This could be called the "Redirect to where I say, damm it" ResponseValue.
|
||||||
|
*
|
||||||
|
* It redirects to the URL specified. It does not attempt to add a
|
||||||
|
* context node. This is useful when you want to redirect to a URL
|
||||||
|
* created by the UrlBuilder which uses statics to sneak a context
|
||||||
|
* into the URL strings it creates.
|
||||||
|
*
|
||||||
|
* @author bdc34
|
||||||
|
*/
|
||||||
|
public class DirectRedirectResponseValues extends RedirectResponseValues {
|
||||||
|
|
||||||
|
/** This will redirect to the url. It will not add the context to the url.*/
|
||||||
|
public DirectRedirectResponseValues(String url, int statusCode) {
|
||||||
|
super(url, statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This will redirect to the url. It will not add the context to the url.*/
|
||||||
|
public DirectRedirectResponseValues(String url){
|
||||||
|
super(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does not add context.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected String getRedirectUrl(String url) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,10 +5,19 @@ package edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Also see DirectRedirectResponseValues
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class RedirectResponseValues extends BaseResponseValues {
|
public class RedirectResponseValues extends BaseResponseValues {
|
||||||
|
|
||||||
private final String redirectUrl;
|
private final String redirectUrl;
|
||||||
|
|
||||||
|
//TODO: document this. What does this do and mean?
|
||||||
|
//should redirectUrl have the context? Or is the context added?
|
||||||
|
//If the context is added, what if we already have it because
|
||||||
|
//UrlBuilder was used?
|
||||||
|
//what about an off site redirect? Maybe check for a magic "://" ?
|
||||||
public RedirectResponseValues(String redirectUrl) {
|
public RedirectResponseValues(String redirectUrl) {
|
||||||
this.redirectUrl = getRedirectUrl(redirectUrl);
|
this.redirectUrl = getRedirectUrl(redirectUrl);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +36,7 @@ public class RedirectResponseValues extends BaseResponseValues {
|
||||||
return this.redirectUrl;
|
return this.redirectUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRedirectUrl(String redirectUrl) {
|
protected String getRedirectUrl(String redirectUrl) {
|
||||||
return redirectUrl.contains("://") ? redirectUrl : UrlBuilder.getUrl(redirectUrl);
|
return redirectUrl.contains("://") ? redirectUrl : UrlBuilder.getUrl(redirectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,6 +114,12 @@ public class EditConfigurationVTwo {
|
||||||
* the edit. */
|
* the edit. */
|
||||||
String entityToReturnTo;
|
String entityToReturnTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this value is not null, it will force the edit to return to the specified
|
||||||
|
* URL from the PostEditCleanupController after an edit or a cancel. This string does not get values substituted in.
|
||||||
|
*/
|
||||||
|
String urlToReturnTo = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* formUrl saves the URL that was used to request the form so that it can be
|
* formUrl saves the URL that was used to request the form so that it can be
|
||||||
* reissued if a form validation fails and the client can be redirected back
|
* reissued if a form validation fails and the client can be redirected back
|
||||||
|
@ -985,5 +991,12 @@ public class EditConfigurationVTwo {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUrlToReturnTo(String url){
|
||||||
|
this.urlToReturnTo = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrlToReturnTo() {
|
||||||
|
return this.urlToReturnTo;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,57 +2,25 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.controller;
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.controller;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Property;
|
|
||||||
|
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
|
||||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.DirectRedirectResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.RedirectResponseValues;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.RedirectResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.AdditionsAndRetractions;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditSubmissionUtils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditSubmissionUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmission;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmission;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.N3EditUtils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.N3EditUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.ProcessRdfForm;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.controller.ProcessRdfFormController.Utilities;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.controller.ProcessRdfFormController.Utilities;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
|
||||||
/**
|
/**
|
||||||
* This servlet will process EditConfigurations with query parameters
|
* This servlet will process EditConfigurations with query parameters
|
||||||
* to perform an edit.
|
* to perform an edit.
|
||||||
|
@ -70,21 +38,77 @@ public class PostEditCleanupController extends FreemarkerHttpServlet{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
doPostEditCleanup( vreq );
|
||||||
|
return doPostEditRedirect( vreq, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a redirect after an edit.
|
||||||
|
* @param vreq - should have an edit configuration in attributes or session
|
||||||
|
* @param entityToReturnTo - may be null
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected static ResponseValues doPostEditRedirect( VitroRequest vreq , String entityToReturnTo){
|
||||||
|
EditConfigurationVTwo editConfig = EditConfigurationVTwo.getConfigFromSession(vreq.getSession(), vreq);
|
||||||
|
if(editConfig == null)
|
||||||
|
throw new Error("No edit configuration found.");
|
||||||
|
|
||||||
|
// If there is a urlToReturnTo that takes precedence
|
||||||
|
if( editConfig.getUrlToReturnTo() != null && ! editConfig.getUrlToReturnTo().trim().isEmpty()){
|
||||||
|
//this does not get value substitution or the predicate anchor
|
||||||
|
return new DirectRedirectResponseValues( editConfig.getUrlToReturnTo() );
|
||||||
|
}
|
||||||
|
|
||||||
|
//The submission for getting the entity to return to is not retrieved from the session but needs
|
||||||
|
//to be created - as it is in processRdfForm3.jsp
|
||||||
|
//TODO: this will not work if there entityToReturnTo has a new resource URI
|
||||||
|
MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq.getParameterMap(), editConfig);
|
||||||
|
if( entityToReturnTo == null )
|
||||||
|
entityToReturnTo = N3EditUtils.processEntityToReturnTo(editConfig, submission, vreq);
|
||||||
|
|
||||||
|
//Get url pattern
|
||||||
|
String urlPattern = Utilities.getPostEditUrlPattern(vreq, editConfig);
|
||||||
|
|
||||||
|
//Redirect appropriately
|
||||||
|
if( entityToReturnTo != null ){
|
||||||
|
|
||||||
|
//Try to redirect to the entityToReturnTo
|
||||||
|
ParamMap paramMap = new ParamMap();
|
||||||
|
paramMap.put("uri", entityToReturnTo);
|
||||||
|
paramMap.put("extra","true"); //for ie6
|
||||||
|
String path = UrlBuilder.getPath(urlPattern,paramMap);
|
||||||
|
path += getPredicateAnchor( vreq, editConfig );
|
||||||
|
return new RedirectResponseValues( path );
|
||||||
|
|
||||||
|
} else if ( !urlPattern.endsWith("individual") && !urlPattern.endsWith("entity") ){
|
||||||
|
|
||||||
|
//Try to redirect to just the EditConfig.UrlPattern
|
||||||
|
//since it doesn't seem to be for the profile page
|
||||||
|
return new RedirectResponseValues( urlPattern );
|
||||||
|
|
||||||
|
}else if( editConfig.getSubjectUri() != null ){
|
||||||
|
|
||||||
|
//Try to redirect to the EditConf.subjectUri profile page
|
||||||
|
//since things seem a little odd.
|
||||||
|
ParamMap paramMap = new ParamMap();
|
||||||
|
paramMap.put("uri", editConfig.getSubjectUri() );
|
||||||
|
paramMap.put("extra","true"); //for ie6
|
||||||
|
String path = UrlBuilder.getPath( UrlBuilder.Route.INDIVIDUAL, paramMap);
|
||||||
|
path += getPredicateAnchor( vreq, editConfig );
|
||||||
|
return new RedirectResponseValues( path );
|
||||||
|
|
||||||
|
}else{
|
||||||
|
//Not sure where to go
|
||||||
|
return new RedirectResponseValues( Route.LOGIN );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void doPostEditCleanup( VitroRequest vreq ) {
|
||||||
EditConfigurationVTwo configuration = EditConfigurationVTwo.getConfigFromSession(vreq.getSession(), vreq);
|
EditConfigurationVTwo configuration = EditConfigurationVTwo.getConfigFromSession(vreq.getSession(), vreq);
|
||||||
if(configuration == null)
|
if(configuration == null)
|
||||||
throw new Error("No edit configuration found.");
|
throw new Error("No edit configuration found.");
|
||||||
|
|
||||||
//The submission for getting the entity to return to is not retrieved from the session but needs
|
|
||||||
//to be created - as it is in processRdfForm3.jsp
|
|
||||||
MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq.getParameterMap(), configuration);
|
|
||||||
String entityToReturnTo = N3EditUtils.processEntityToReturnTo(configuration, submission, vreq);
|
|
||||||
return doPostEdit(vreq, entityToReturnTo);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static RedirectResponseValues doPostEdit(VitroRequest vreq, String resourceToRedirectTo ) {
|
|
||||||
String urlPattern = null;
|
|
||||||
String predicateAnchor = "";
|
|
||||||
HttpSession session = vreq.getSession(false);
|
HttpSession session = vreq.getSession(false);
|
||||||
if( session != null ) {
|
if( session != null ) {
|
||||||
EditConfigurationVTwo editConfig = EditConfigurationVTwo.getConfigFromSession(session,vreq);
|
EditConfigurationVTwo editConfig = EditConfigurationVTwo.getConfigFromSession(session,vreq);
|
||||||
|
@ -93,34 +117,30 @@ public class PostEditCleanupController extends FreemarkerHttpServlet{
|
||||||
//Here, edit submission is retrieved so it can be cleared out in case it exists
|
//Here, edit submission is retrieved so it can be cleared out in case it exists
|
||||||
MultiValueEditSubmission editSub = EditSubmissionUtils.getEditSubmissionFromSession(session,editConfig);
|
MultiValueEditSubmission editSub = EditSubmissionUtils.getEditSubmissionFromSession(session,editConfig);
|
||||||
EditSubmissionUtils.clearEditSubmissionInSession(session, editSub);
|
EditSubmissionUtils.clearEditSubmissionInSession(session, editSub);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a attribute to the request to indicate which predicate was edited.
|
||||||
|
* This attribute is used by some controllers to send the browser to the
|
||||||
|
* place on the page relevant to the predicate.
|
||||||
|
*
|
||||||
|
* Never returns null, it will return an empty string if there is nothing.
|
||||||
|
*/
|
||||||
|
public static String getPredicateAnchor( HttpServletRequest req, EditConfigurationVTwo config){
|
||||||
|
if( req == null || config == null )
|
||||||
|
return "";
|
||||||
|
|
||||||
//Get prop local name if it exists
|
//Get prop local name if it exists
|
||||||
String predicateLocalName = Utilities.getPredicateLocalName(editConfig);
|
String predicateLocalName = Utilities.getPredicateLocalName(config);
|
||||||
|
|
||||||
//Get url pattern
|
|
||||||
urlPattern = Utilities.getPostEditUrlPattern(vreq, editConfig);
|
|
||||||
predicateAnchor = Utilities.getPredicateAnchorPostEdit(urlPattern, predicateLocalName);
|
|
||||||
if(predicateAnchor != null && !predicateAnchor.isEmpty()) {
|
|
||||||
vreq.setAttribute("predicateAnchor", predicateAnchor);
|
|
||||||
|
|
||||||
|
if( predicateLocalName != null && predicateLocalName.length() > 0){
|
||||||
|
String predicateAnchor = "#" + predicateLocalName;
|
||||||
|
req.setAttribute("predicateAnchor", predicateAnchor);
|
||||||
|
return predicateAnchor;
|
||||||
|
}else{
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Redirect appropriately
|
|
||||||
if( resourceToRedirectTo != null ){
|
|
||||||
ParamMap paramMap = new ParamMap();
|
|
||||||
paramMap.put("uri", resourceToRedirectTo);
|
|
||||||
paramMap.put("extra","true"); //for ie6
|
|
||||||
String path = UrlBuilder.getPath(urlPattern,paramMap);
|
|
||||||
if(predicateAnchor != null) {
|
|
||||||
path += predicateAnchor;
|
|
||||||
}
|
|
||||||
return new RedirectResponseValues( path );
|
|
||||||
} else if ( !urlPattern.endsWith("individual") && !urlPattern.endsWith("entity") ){
|
|
||||||
return new RedirectResponseValues( urlPattern );
|
|
||||||
}
|
|
||||||
return new RedirectResponseValues( Route.LOGIN );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,8 @@ public class ProcessRdfFormController extends FreemarkerHttpServlet{
|
||||||
|
|
||||||
//For data property processing, need to update edit configuration for back button
|
//For data property processing, need to update edit configuration for back button
|
||||||
N3EditUtils.updateEditConfigurationForBackButton(configuration, submission, vreq, writeModel);
|
N3EditUtils.updateEditConfigurationForBackButton(configuration, submission, vreq, writeModel);
|
||||||
return PostEditCleanupController.doPostEdit(vreq, entityToReturnTo);
|
PostEditCleanupController.doPostEditCleanup(vreq);
|
||||||
|
return PostEditCleanupController.doPostEditRedirect(vreq, entityToReturnTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
//In case of back button confusion
|
//In case of back button confusion
|
||||||
|
@ -306,15 +307,7 @@ public class ProcessRdfFormController extends FreemarkerHttpServlet{
|
||||||
return resourceToRedirectTo;
|
return resourceToRedirectTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getPredicateAnchorPostEdit(String urlPattern,
|
|
||||||
String predicateLocalName) {
|
|
||||||
String predicateAnchor = null;
|
|
||||||
if( urlPattern.endsWith("individual") || urlPattern.endsWith("entity") ){
|
|
||||||
if( predicateLocalName != null && predicateLocalName.length() > 0){
|
|
||||||
predicateAnchor = "#" + predicateLocalName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return predicateAnchor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue