From 591af247494bbf91f55a862dab01502102fd63e3 Mon Sep 17 00:00:00 2001 From: hjkhjk54 Date: Tue, 11 Oct 2011 15:49:19 +0000 Subject: [PATCH] Updates for n3 editing and freemarker conversion. Also fixing propDelete.jsp's reference to freemarker configuration loading to include correct method call. --- .../freemarker/DeletePropertyController.java | 72 ++++++++--- .../VTwo/EditConfigurationUtils.java | 20 +++ .../n3editing/VTwo/EditConfigurationVTwo.java | 3 +- ...aultAddMissingIndividualFormGenerator.java | 8 +- .../EditRequestDispatchController.java | 47 ++++--- .../controller/PostEditCleanupController.java | 120 ++++++++++++++++++ .../controller/ProcessRdfFormController.java | 45 +------ .../edit/EditConfigurationTemplateModel.java | 52 +++++++- webapp/web/edit/forms/propDelete.jsp | 4 +- .../edit/forms/confirmDeletePropertyForm.ftl | 38 ++++++ .../forms/defaultAddMissingIndividualForm.ftl | 12 +- .../edit/forms/defaultDataPropertyForm.ftl | 6 +- .../edit/forms/defaultDeletePropertyForm.ftl | 22 ++-- .../forms/defaultOfferCreateNewOptionForm.ftl | 15 ++- .../edit/forms/defaultPropertyForm.ftl | 4 +- 15 files changed, 356 insertions(+), 112 deletions(-) create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/PostEditCleanupController.java create mode 100644 webapp/web/templates/freemarker/edit/forms/confirmDeletePropertyForm.ftl diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/DeletePropertyController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/DeletePropertyController.java index 571779afd..f602becd2 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/DeletePropertyController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/DeletePropertyController.java @@ -6,7 +6,7 @@ import java.util.HashMap; import java.util.Map; import java.util.List; import java.util.ArrayList; - +import java.net.URLEncoder; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; @@ -37,6 +37,7 @@ import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.vocabulary.RDF; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; import edu.cornell.mannlib.vitro.webapp.beans.DataProperty; @@ -75,9 +76,7 @@ public class DeletePropertyController extends FreemarkerHttpServlet { } else { processDataProperty(vreq); } - //Get subject, predicate uri , - //Redirect - //return new TemplateResponseValues(editConfig.getTemplate(), map); + String redirectUrl = getRedirectUrl(vreq); return new RedirectResponseValues(redirectUrl, HttpServletResponse.SC_SEE_OTHER); } @@ -89,8 +88,8 @@ public class DeletePropertyController extends FreemarkerHttpServlet { String predicateUri = EditConfigurationUtils.getPredicateUri(vreq); int hashIndex = predicateUri.lastIndexOf("#"); String localName = predicateUri.substring(hashIndex + 1); - String redirectUrl = "/entity?uri=" + subjectUri; - return null; + String redirectUrl = "/entity?uri=" + URLEncoder.encode(subjectUri); + return redirectUrl + "#" + URLEncoder.encode(localName); } @@ -113,7 +112,8 @@ public class DeletePropertyController extends FreemarkerHttpServlet { return "In delete property controller, could not find object property " + predicateUri; } } else { - DataProperty prop = EditConfigurationUtils.getDataProperty(vreq); + DataProperty prop = getDataProperty(vreq); + if(prop == null) { return "In delete property controller, could not find data property " + predicateUri; } @@ -123,6 +123,18 @@ public class DeletePropertyController extends FreemarkerHttpServlet { } + private DataProperty getDataProperty(VitroRequest vreq) { + //This is the standard mechanism but note that datapropStmtDelete uses wdf with user aware + + //DataProperty prop = EditConfigurationUtils.getDataProperty(vreq); + String editorUri = EditN3Utils.getEditorUri(vreq); + WebappDaoFactory wdf = vreq.getWebappDaoFactory().getUserAwareDaoFactory(editorUri); + DataProperty prop = wdf.getDataPropertyDao().getDataPropertyByURI( + EditConfigurationUtils.getPredicateUri(vreq)); + return prop; + } + + private TemplateResponseValues doErrorMessage(String errorMessage) { HashMap map = new HashMap(); map.put("errorMessage", errorMessage); @@ -137,33 +149,51 @@ public class DeletePropertyController extends FreemarkerHttpServlet { } private void deleteDataPropertyStatement(VitroRequest vreq) { - Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq); - //TODO: if null, need to throw or show error - int dataHash = getDataHash(vreq); + String subjectUri = EditConfigurationUtils.getSubjectUri(vreq); String predicateUri = EditConfigurationUtils.getPredicateUri(vreq); + + int dataHash = EditConfigurationUtils.getDataHash(vreq); DataPropertyStatement dps = EditConfigurationUtils.getDataPropertyStatement(vreq, vreq.getSession(), dataHash, predicateUri); WebappDaoFactory wdf = vreq.getWebappDaoFactory(); + + + if(dps != null) { + logDataPropertyDeletionMessages(dps); + processDataPropertyStatement(dps, subjectUri, predicateUri); wdf.getDataPropertyStatementDao().deleteDataPropertyStatement(dps); } } - private int getDataHash(VitroRequest vreq) { - int dataHash = 0; - String datapropKey = EditConfigurationUtils.getDataPropKey(vreq); - if (datapropKey!=null && datapropKey.trim().length()>0) { - try { - dataHash = Integer.parseInt(datapropKey); - } catch (NumberFormatException ex) { - log.error("Cannot decode incoming dataprop key str " + datapropKey + "as integer hash"); - //throw new JspException("Cannot decode incoming datapropKey String value "+datapropKeyStr+" as an integer hash in datapropStmtDelete.jsp"); - } + private void processDataPropertyStatement( + DataPropertyStatement dps, String subjectUri, String predicateUri) { + //if no individual Uri set to subject uri + if( dps.getIndividualURI() == null || dps.getIndividualURI().trim().length() == 0){ + log.debug("adding missing subjectURI to DataPropertyStatement" ); + dps.setIndividualURI( subjectUri ); + } + //if no predicate, set predicate uri + if( dps.getDatapropURI() == null || dps.getDatapropURI().trim().length() == 0){ + log.debug("adding missing datapropUri to DataPropertyStatement"); + dps.setDatapropURI( predicateUri ); } - return dataHash; } + private void logDataPropertyDeletionMessages(DataPropertyStatement dps) { + log.debug("attempting to delete dataPropertyStatement: subjectURI <" + dps.getIndividualURI() +">"); + log.debug( "predicateURI <" + dps.getDatapropURI() + ">"); + log.debug( "literal \"" + dps.getData() + "\"" ); + log.debug( "lang @" + (dps.getLanguage() == null ? "null" : dps.getLanguage())); + log.debug( "datatype ^^" + (dps.getDatatypeURI() == null ? "null" : dps.getDatatypeURI() )); + + } + + + + + //process object property private void processObjectProperty(VitroRequest vreq) { ObjectProperty prop = EditConfigurationUtils.getObjectProperty(vreq); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java index 14d20d618..13f73c626 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationUtils.java @@ -8,12 +8,16 @@ import java.util.Map; import javax.servlet.http.HttpSession; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import com.hp.hpl.jena.rdf.model.Model; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash; +import edu.cornell.mannlib.vitro.webapp.web.templatemodels.edit.EditConfigurationTemplateModel; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.beans.DataProperty; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; @@ -21,6 +25,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; public class EditConfigurationUtils { + private static Log log = LogFactory.getLog(EditConfigurationUtils.class); protected static final String MULTI_VALUED_EDIT_SUBMISSION = "MultiValueEditSubmission"; @@ -158,5 +163,20 @@ public class EditConfigurationUtils { } return dps; } + + //TODO: Include get object property statement + public static int getDataHash(VitroRequest vreq) { + int dataHash = 0; + String datapropKey = EditConfigurationUtils.getDataPropKey(vreq); + if (datapropKey!=null && datapropKey.trim().length()>0) { + try { + dataHash = Integer.parseInt(datapropKey); + } catch (NumberFormatException ex) { + log.error("Cannot decode incoming dataprop key str " + datapropKey + "as integer hash"); + //throw new JspException("Cannot decode incoming datapropKey String value "+datapropKeyStr+" as an integer hash in datapropStmtDelete.jsp"); + } + } + return dataHash; + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationVTwo.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationVTwo.java index 26c61d8ff..4d16514d5 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationVTwo.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/EditConfigurationVTwo.java @@ -118,7 +118,7 @@ public class EditConfigurationVTwo { EditN3GeneratorVTwo n3generator; - private List modelChangePreprocessors = Collections.emptyList(); + private List modelChangePreprocessors; private List editSubmissionPreprocessors = Collections.emptyList(); @@ -157,6 +157,7 @@ public class EditConfigurationVTwo { queryModelSelector = StandardModelSelector.selector; resourceModelSelector = StandardModelSelector.selector; wdfSelectorForOptons = StandardWDFSelector.selector; + modelChangePreprocessors = new LinkedList(); } //Make copy of edit configuration object diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultAddMissingIndividualFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultAddMissingIndividualFormGenerator.java index 8033a1555..afa373f93 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultAddMissingIndividualFormGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultAddMissingIndividualFormGenerator.java @@ -237,7 +237,7 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati //asserted types string buffer is empty in the original jsp //TODO: Review original comments in jsp to see what could go here //n3Optional.add(getN3AssertedTypes(vreq)); - n3Optional.add(getFlagURI(vreq)); + n3Optional.add("?" + objectVarName + " rdf:type " + getFlagURI(vreq)); return n3Optional; } @@ -386,8 +386,10 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati //if object property if(EditConfigurationUtils.isObjectProperty(EditConfigurationUtils.getPredicateUri(vreq), vreq)){ Individual objectIndividual = EditConfigurationUtils.getObjectIndividual(vreq); - if(isForwardToCreateButEdit(vreq) || - objectIndividual != null) { + if(!isReplaceWithNew(vreq) && + (isForwardToCreateButEdit(vreq) || + objectIndividual != null) + ) { editConfiguration.prepareForObjPropUpdate(model); } else { //new object to be created diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java index 8b053c2be..7099a531a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java @@ -49,8 +49,7 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet { final String DEFAULT_DATA_FORM = "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultDataPropertyFormGenerator"; //TODO: Create this generator final String RDFS_LABEL_FORM = ""; - final String DEFAULT_ERROR_FORM = "error.jsp"; - final String DEFAULT_ADD_INDIVIDUAL = "defaultAddMissingIndividualForm.jsp"; + final String DEFAULT_DELETE_FORM = "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultDeleteGenerator"; @Override protected ResponseValues processRequest(VitroRequest vreq) { @@ -61,9 +60,11 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet { if(isErrorCondition(vreq)){ return doHelp(vreq, getErrorMessage(vreq)); } - //TODO: Check if skip edit form needs to go here or elsewhere - //in case form needs to be redirected b/c of special individuals - // processSkipEditForm(vreq); + + //if edit form needs to be skipped to object instead + if(isSkipEditForm(vreq)) { + return processSkipEditForm(vreq); + } //Get the edit generator name String editConfGeneratorName = processEditConfGeneratorName(vreq); @@ -132,8 +133,12 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet { String editConfGeneratorName = DEFAULT_OBJ_FORM; String predicateUri = getPredicateUri(vreq); String formParam = getFormParam(vreq); + //Handle deletion before any of the other cases + if(isDeleteForm(vreq)) { + editConfGeneratorName = DEFAULT_DELETE_FORM; + } // *** handle the case where the form is specified as a request parameter *** - if( predicateUri == null && ( formParam != null && !formParam.isEmpty()) ){ + else if( predicateUri == null && ( formParam != null && !formParam.isEmpty()) ){ //form parameter must be a fully qualified java class name of a EditConfigurationVTwoGenerator implementation. editConfGeneratorName = formParam; } else if(isVitroLabel(predicateUri)) { //in case of data property @@ -170,10 +175,9 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet { } - - //TODO: Implement below correctly or integrate - private ResponseValues processSkipEditForm(VitroRequest vreq) { - //Certain predicates may be annotated to change the behavior of the edit + //if skip edit form + private boolean isSkipEditForm(VitroRequest vreq) { + //Certain predicates may be annotated to change the behavior of the edit //link. Check for this annotation and, if present, simply redirect //to the normal individual display for the object URI instead of bringing //up an editing form. @@ -183,16 +187,19 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet { WebappDaoFactory wdf = vreq.getWebappDaoFactory(); String predicateUri = vreq.getParameter("predicateUri"); boolean isEditOfExistingStmt = isEditOfExistingStmt(vreq); - - if ( isEditOfExistingStmt && (wdf.getObjectPropertyDao().skipEditForm(predicateUri)) ) { - log.debug("redirecting to object for predicate " + predicateUri); - String redirectPage = vreq.getContextPath() + "/individual"; - redirectPage += "uri=" + URLEncoder.encode(vreq.getParameter("objectUri")) + - "&relatedSubjectUri=" + URLEncoder.encode(vreq.getParameter("subjectUri")) + - "&relatingPredicateUri=" + URLEncoder.encode(vreq.getParameter("predicateUri")); - return new RedirectResponseValues(redirectPage, HttpServletResponse.SC_SEE_OTHER); - } - return null; + return (isEditOfExistingStmt && (wdf.getObjectPropertyDao().skipEditForm(predicateUri))); + } + + //TODO: Implement below correctly or integrate + private ResponseValues processSkipEditForm(VitroRequest vreq) { + String redirectPage = vreq.getContextPath() + "/individual"; + String objectUri = EditConfigurationUtils.getObjectUri(vreq); + String subjectUri = EditConfigurationUtils.getSubjectUri(vreq); + String predicateUri = EditConfigurationUtils.getPredicateUri(vreq); + redirectPage += "uri=" + URLEncoder.encode(objectUri) + + "&relatedSubjectUri=" + URLEncoder.encode(subjectUri) + + "&relatingPredicateUri=" + URLEncoder.encode(predicateUri); + return new RedirectResponseValues(redirectPage, HttpServletResponse.SC_SEE_OTHER); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/PostEditCleanupController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/PostEditCleanupController.java new file mode 100644 index 000000000..f27c48ca8 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/PostEditCleanupController.java @@ -0,0 +1,120 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +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.HttpSession; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +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.freemarker.FreemarkerHttpServlet; +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.Route; +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.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.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.ProcessRdfForm; +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 + * to perform an edit. + * + * TODO: rename this class ProcessN3Edit + */ +public class PostEditCleanupController extends FreemarkerHttpServlet{ + + private Log log = LogFactory.getLog(PostEditCleanupController.class); + + + //bdc34: this is likely to become a servlet instead of a jsp. + // You can get a reference to the servlet from the context. + // this will need to be converted from a jsp to something else + + @Override + protected ResponseValues processRequest(VitroRequest vreq) { + EditConfigurationVTwo configuration = EditConfigurationVTwo.getConfigFromSession(vreq.getSession(), vreq); + if(configuration == null) + throw new Error("No edit configuration found."); + + //get the EditSubmission + MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq.getParameterMap(), configuration); + String entityToReturnTo = ProcessRdfForm.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); + if( session != null ) { + EditConfigurationVTwo editConfig = EditConfigurationVTwo.getConfigFromSession(session,vreq); + //In order to support back button resubmissions, don't remove the editConfig from session. + //EditConfiguration.clearEditConfigurationInSession(session, editConfig); + + MultiValueEditSubmission editSub = EditSubmissionUtils.getEditSubmissionFromSession(session,editConfig); + EditSubmissionUtils.clearEditSubmissionInSession(session, editSub); + + //Get prop local name if it exists + String predicateLocalName = Utilities.getPredicateLocalName(editConfig); + + //Get url pattern + urlPattern = Utilities.getPostEditUrlPattern(vreq, editConfig); + predicateAnchor = Utilities.getPredicateAnchorPostEdit(urlPattern, predicateLocalName); + if(predicateAnchor != null && !predicateAnchor.isEmpty()) { + vreq.setAttribute("predicateAnchor", predicateAnchor); + + } + + } + + //Redirect appropriately + if( resourceToRedirectTo != null ){ + ParamMap paramMap = new ParamMap(); + paramMap.put("uri", resourceToRedirectTo); + paramMap.put("extra","true"); //for ie6 + return new RedirectResponseValues( UrlBuilder.getPath(urlPattern,paramMap) + predicateAnchor ); + } else if ( !urlPattern.endsWith("individual") && !urlPattern.endsWith("entity") ){ + return new RedirectResponseValues( urlPattern ); + } + return new RedirectResponseValues( UrlBuilder.getUrl(Route.LOGIN) ); + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java index e448155f1..868301bf7 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/ProcessRdfFormController.java @@ -65,7 +65,6 @@ public class ProcessRdfFormController extends FreemarkerHttpServlet{ //bdc34: this is likely to become a servlet instead of a jsp. // You can get a reference to the servlet from the context. // this will need to be converted from a jsp to something else - public static final String POST_EDIT_CLEANUP_JSP = "postEditCleanUp.jsp"; @Override protected ResponseValues processRequest(VitroRequest vreq) { @@ -111,7 +110,7 @@ public class ProcessRdfFormController extends FreemarkerHttpServlet{ String entityToReturnTo = ProcessRdfForm.processEntityToReturnTo(configuration, submission, vreq); //For data property processing, need to update edit configuration for back button ProcessRdfForm.updateEditConfigurationForBackButton(configuration, submission, vreq, writeModel); - return doPostEdit(vreq, entityToReturnTo); + return PostEditCleanupController.doPostEdit(vreq, entityToReturnTo); } //In case of back button confusion @@ -208,49 +207,7 @@ public class ProcessRdfFormController extends FreemarkerHttpServlet{ } return null; //no errors } - - //TODO: Is this the equivalent of post Edit Cleanup - //Also do we wish to continue setting attributes on the request? - private RedirectResponseValues doPostEdit(VitroRequest vreq, String resourceToRedirectTo ) { - String urlPattern = null; - String predicateAnchor = ""; - HttpSession session = vreq.getSession(false); - if( session != null ) { - EditConfigurationVTwo editConfig = EditConfigurationVTwo.getConfigFromSession(session,vreq); - //In order to support back button resubmissions, don't remove the editConfig from session. - //EditConfiguration.clearEditConfigurationInSession(session, editConfig); - - MultiValueEditSubmission editSub = EditSubmissionUtils.getEditSubmissionFromSession(session,editConfig); - EditSubmissionUtils.clearEditSubmissionInSession(session, editSub); - - //Get prop local name if it exists - String predicateLocalName = Utilities.getPredicateLocalName(editConfig); - - //Get url pattern - urlPattern = Utilities.getPostEditUrlPattern(vreq, editConfig); - predicateAnchor = Utilities.getPredicateAnchorPostEdit(urlPattern, predicateLocalName); - if(predicateAnchor != null && !predicateAnchor.isEmpty()) { - vreq.setAttribute("predicateAnchor", predicateAnchor); - - } - - } - - //Redirect appropriately - if( resourceToRedirectTo != null ){ - ParamMap paramMap = new ParamMap(); - paramMap.put("uri", resourceToRedirectTo); - paramMap.put("extra","true"); //for ie6 - return new RedirectResponseValues( UrlBuilder.getPath(urlPattern,paramMap) + predicateAnchor ); - } else if ( !urlPattern.endsWith("individual") && !urlPattern.endsWith("entity") ){ - return new RedirectResponseValues( urlPattern ); - } - - - return new RedirectResponseValues( UrlBuilder.getUrl(Route.LOGIN) ); - - } //Move to EditN3Utils but keep make new uris here public static class Utilities { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/edit/EditConfigurationTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/edit/EditConfigurationTemplateModel.java index 3b217f519..6ed90e83b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/edit/EditConfigurationTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/edit/EditConfigurationTemplateModel.java @@ -346,6 +346,37 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel { return getObjectPredicateProperty().getOfferCreateNewOption(); } + public String getPropertyName() { + if(isObjectProperty()) { + return getPropertyPublicDomainTitle().toLowerCase(); + } + if(isDataProperty()) { + return getPropertyPublicName(); + } + return null; + } + + //TODO: Implement statement display + public Map getStatementDisplay() { + Map statementDisplay = new HashMap(); + if(isDataProperty()) { + statementDisplay.put("dataValue", getDataLiteralValuesAsString()); + } else { + //Expecting statement parameters to be passed in + Map params = vreq.getParameterMap(); + for (Object key : params.keySet()) { + String keyString = (String) key; //key.toString() + if (keyString.startsWith("statement_")) { + keyString = keyString.replaceFirst("statement_", ""); + String value = ( (String[]) params.get(key))[0]; + statementDisplay.put(keyString, value); + } + } + + } + return statementDisplay; + } + //TODO:Check where this logic should actually go, copied from input element formatting tag public Map getOfferTypesCreateNew() { WebappDaoFactory wdf = vreq.getWebappDaoFactory(); @@ -444,8 +475,19 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel { return getMainEditUrl() + "?" + vreq.getQueryString(); } + //this url is for canceling + public String getCancelUrl() { + String editKey = editConfig.getEditKey(); + return vreq.getContextPath() + "/postEditCleanupController?editKey=" + editKey + "&cancel=true"; + } + public String getMainEditUrl() { - return "/edit/editRequestDispatch"; + return vreq.getContextPath() + "/editRequestDispatch"; + } + + //Get confirm deletion url + public String getDeleteProcessingUrl() { + return vreq.getContextPath() + "/deletePropertyController"; } //TODO: Check if this logic is correct and delete prohibited does not expect a specific value @@ -471,4 +513,12 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel { } } + public String getVitroNsProperty() { + String vitroNsProp = vreq.getParameter("vitroNsProp"); + if(vitroNsProp == null) { + vitroNsProp = ""; + } + return vitroNsProp; + } + } diff --git a/webapp/web/edit/forms/propDelete.jsp b/webapp/web/edit/forms/propDelete.jsp index f3914bae6..5e0ed83d2 100644 --- a/webapp/web/edit/forms/propDelete.jsp +++ b/webapp/web/edit/forms/propDelete.jsp @@ -130,9 +130,7 @@ public WebappDaoFactory getUnfilteredDaoFactory() { //map.putAll(FreemarkerHttpServlet.getDirectives()); //map.putAll(FreemarkerHttpServlet.getMethods()); ServletContext context = getServletContext(); - FreemarkerConfigurationLoader loader = - FreemarkerConfigurationLoader.getFreemarkerConfigurationLoader(context); - FreemarkerConfiguration fmConfig = loader.getConfig(vreq); + FreemarkerConfiguration fmConfig = FreemarkerConfigurationLoader.getConfig(vreq, context); fmConfig.resetRequestSpecificSharedVariables(); TemplateProcessingHelper helper = new TemplateProcessingHelper(fmConfig, vreq, context); statementDisplay = helper.processTemplateToString(templateName, map); diff --git a/webapp/web/templates/freemarker/edit/forms/confirmDeletePropertyForm.ftl b/webapp/web/templates/freemarker/edit/forms/confirmDeletePropertyForm.ftl new file mode 100644 index 000000000..1b988a356 --- /dev/null +++ b/webapp/web/templates/freemarker/edit/forms/confirmDeletePropertyForm.ftl @@ -0,0 +1,38 @@ +<#assign toBeDeletedClass = "dataProp" /> +<#if editConfiguration.objectProperty = true> + <#assign toBeDeletedClass = "objProp" /> + +<#assign statement = editConfiguration.statementDisplay /> +
+ +
+ <#if editConfiguration.objectProperty = true> + <#if statement.object?has_content> + <#include "propStatement-default.ftl" /> + + <#else> + ${statement.dataValue} + +
+ + + + <#if editConfiguration.dataProperty = true> + + + <#else> + + + + +

+ + or + Cancel +

+ +
\ No newline at end of file diff --git a/webapp/web/templates/freemarker/edit/forms/defaultAddMissingIndividualForm.ftl b/webapp/web/templates/freemarker/edit/forms/defaultAddMissingIndividualForm.ftl index 33dbeb5e6..e3a23ca07 100644 --- a/webapp/web/templates/freemarker/edit/forms/defaultAddMissingIndividualForm.ftl +++ b/webapp/web/templates/freemarker/edit/forms/defaultAddMissingIndividualForm.ftl @@ -1,7 +1,7 @@ <#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> <#assign formTitle> - ${editConfiguration.propertyPublicDomainTitle} entry for ${editConfiguration.subjectName} + "${editConfiguration.propertyPublicDomainTitle}" entry for ${editConfiguration.subjectName} <#if editConfiguration.objectUri?has_content> <#assign formTitle>Edit ${formTitle} @@ -13,11 +13,15 @@
- +
+
- -
+ or + Cancel + +
diff --git a/webapp/web/templates/freemarker/edit/forms/defaultDataPropertyForm.ftl b/webapp/web/templates/freemarker/edit/forms/defaultDataPropertyForm.ftl index 6c4d542c9..a6046f45e 100644 --- a/webapp/web/templates/freemarker/edit/forms/defaultDataPropertyForm.ftl +++ b/webapp/web/templates/freemarker/edit/forms/defaultDataPropertyForm.ftl @@ -14,9 +14,13 @@ id="${editConfiguration.dataLiteral}" name="${editConfiguration.dataLiteral}" value="${literalValues}"/> +
- + + or + Cancel
+ diff --git a/webapp/web/templates/freemarker/edit/forms/defaultDeletePropertyForm.ftl b/webapp/web/templates/freemarker/edit/forms/defaultDeletePropertyForm.ftl index 429285bb4..bfb3eb804 100644 --- a/webapp/web/templates/freemarker/edit/forms/defaultDeletePropertyForm.ftl +++ b/webapp/web/templates/freemarker/edit/forms/defaultDeletePropertyForm.ftl @@ -3,29 +3,35 @@ - + <#if editConfiguration.dataProperty = true> - - Cancel +
+ +
+ <#--The original jsp included vinput tag with cancel=empty string for case where both select from existing and offer create new option are true below - so leaving as Cancel for now but unclear as to what the result would have been--> + so leaving as Cancel for first option but not second below--> <#if editConfiguration.objectProperty = true> <#if editConfiguration.propertySelectFromExisting = false && editConfiguration.propertyOfferCreateNewOption = false> - - Cancel +
+ + or + Cancel +
<#if editConfiguration.propertySelectFromExisting = true && editConfiguration.propertyOfferCreateNewOption = true> - - Cancel +
+ +
diff --git a/webapp/web/templates/freemarker/edit/forms/defaultOfferCreateNewOptionForm.ftl b/webapp/web/templates/freemarker/edit/forms/defaultOfferCreateNewOptionForm.ftl index 2287fc6f1..ad67a0bef 100644 --- a/webapp/web/templates/freemarker/edit/forms/defaultOfferCreateNewOptionForm.ftl +++ b/webapp/web/templates/freemarker/edit/forms/defaultOfferCreateNewOptionForm.ftl @@ -4,11 +4,18 @@

Please create a new entry.

+ + <#if editConfiguration.objectUri?has_content> + <#assign objectUri = editConfiguration.objectUri> + <#else> + <#assign objectUri = ""/> + + <#assign typesList = editConfiguration.offerTypesCreateNew /> -
+ - + - - - Cancel +
\ No newline at end of file diff --git a/webapp/web/templates/freemarker/edit/forms/defaultPropertyForm.ftl b/webapp/web/templates/freemarker/edit/forms/defaultPropertyForm.ftl index c609a3eaf..4cec0905b 100644 --- a/webapp/web/templates/freemarker/edit/forms/defaultPropertyForm.ftl +++ b/webapp/web/templates/freemarker/edit/forms/defaultPropertyForm.ftl @@ -20,7 +20,9 @@
- + + or + Cancel