From 94091c668e75f88343ad47b0b574f373bbe6eaf8 Mon Sep 17 00:00:00 2001
From: hjkhjk54
Date: Mon, 17 Oct 2011 19:05:30 +0000
Subject: [PATCH] Updates for N3Editing
---
.../VTwo/EditConfigurationUtils.java | 10 ++-
.../VTwo/MultiValueEditSubmission.java | 51 +++----------
.../edit/n3editing/VTwo/ProcessRdfForm.java | 2 +
...aultAddMissingIndividualFormGenerator.java | 22 ++++--
.../generators/DefaultDeleteGenerator.java | 74 +++++++++++++++++++
.../EditRequestDispatchController.java | 2 +
.../controller/PostEditCleanupController.java | 2 +-
.../edit/EditConfigurationTemplateModel.java | 32 ++++++--
.../edit/forms/confirmDeletePropertyForm.ftl | 12 ++-
.../forms/defaultAddMissingIndividualForm.ftl | 5 +-
10 files changed, 148 insertions(+), 64 deletions(-)
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 13f73c626..630108cdc 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
@@ -109,7 +109,15 @@ public class EditConfigurationUtils {
}
public static String getFormUrl(VitroRequest vreq) {
- return vreq.getContextPath() + "/edit/editRequestDispatch?" + vreq.getQueryString();
+ return getEditUrl(vreq) + "?" + vreq.getQueryString();
+ }
+
+ public static String getEditUrl(VitroRequest vreq) {
+ return vreq.getContextPath() + "/editRequestDispatch";
+ }
+
+ public static String getCancelUrlBase(VitroRequest vreq) {
+ return vreq.getContextPath() + "/postEditCleanupController";
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/MultiValueEditSubmission.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/MultiValueEditSubmission.java
index 1234e8e6b..845c34b1b 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/MultiValueEditSubmission.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/MultiValueEditSubmission.java
@@ -69,32 +69,18 @@ public class MultiValueEditSubmission {
String[] valuesArray = queryParameters.get( var );
//String uri = null;
List values = (valuesArray != null) ? Arrays.asList(valuesArray) : null;
- //Iterate through the values and check to see if they should be added or removed from form
- urisFromForm.put(var, values);
- for(String uri : values) {
- if( uri != null && uri.length() == 0 && editConfig.getNewResources().containsKey(var) ){
- log.debug("A new resource URI will be made for var " + var + " since it was blank on the form.");
- urisFromForm.remove(var);
- }
- }
- /*
if( values != null && values.size() > 0){
- if( values.size() == 1 ) {
- uri = values.get(0);
- } else if( values.size() > 1 ){
- //TODO: Change this and above so array/list sent as uri and not single value
- uri = values.get(0);
- log.error("Cannot yet handle multiple URIs for a single field, using first URI on list");
- }
- urisFromForm.put(var,uri);
- } else {
+ //Iterate through the values and check to see if they should be added or removed from form
+ urisFromForm.put(var, values);
+ for(String uri : values) {
+ if( uri != null && uri.length() == 0 && editConfig.getNewResources().containsKey(var) ){
+ log.debug("A new resource URI will be made for var " + var + " since it was blank on the form.");
+ urisFromForm.remove(var);
+ }
+ }
+ } else {
log.debug("No value found for query parameter " + var);
}
- //check to see if a URI field from the form was blank but was intended to create a new URI
- if( uri != null && uri.length() == 0 && editConfig.getNewResources().containsKey(var) ){
- log.debug("A new resource URI will be made for var " + var + " since it was blank on the form.");
- urisFromForm.remove(var);
- }*/
}
this.literalsFromForm =new HashMap>();
@@ -122,25 +108,6 @@ public class MultiValueEditSubmission {
}
}
literalsFromForm.put(var, literalsArray);
- /*
- String value = valueList.get(0);
-
- // remove any characters that are not valid in XML 1.0
- // from user input so they don't cause problems
- // with model serialization
- value = EditN3Utils.stripInvalidXMLChars(value);
-
- if (!StringUtils.isEmpty(value)) {
- literalsFromForm.put(var, createLiteral(
- value,
- field.getRangeDatatypeUri(),
- field.getRangeLang()));
- }
-
- if(valueList != null && valueList.size() > 1 )
- log.debug("For field " + var +", cannot yet handle multiple " +
- "Literals for a single field, using first Literal on list");
- */
}else{
log.debug("could not find value for parameter " + var );
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfForm.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfForm.java
index 7dce8cf83..0e6d2502e 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfForm.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/ProcessRdfForm.java
@@ -97,6 +97,7 @@ public class ProcessRdfForm {
//
@SuppressWarnings("static-access")
public static AdditionsAndRetractions createNewStatement(EditConfigurationVTwo editConfiguration , MultiValueEditSubmission submission, VitroRequest vreq){
+ varToNewResource = null;
//Get all assertions
List assertions = populateAssertions(editConfiguration, submission, vreq);
//Retractions should be empty anyway but the method should take care of that
@@ -106,6 +107,7 @@ public class ProcessRdfForm {
}
public static AdditionsAndRetractions editExistingStatement(EditConfigurationVTwo editConfiguration, MultiValueEditSubmission submission, VitroRequest vreq) {
+ varToNewResource = null;
List fieldAssertions = populateAssertions(editConfiguration, submission, vreq);
List fieldRetractions = populateRetractions(editConfiguration, submission, vreq);
return getMinimalChanges(new AdditionsAndRetractions(fieldAssertions, fieldRetractions));
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 afa373f93..cc45ec86b 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
@@ -126,7 +126,7 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati
private Map generateNewResources(VitroRequest vreq) {
HashMap newResources = new HashMap();
//TODO: Get default namespace
- String defaultNamespace = "";
+ String defaultNamespace = vreq.getWebappDaoFactory().getDefaultNamespace();
newResources.put(objectVarName, defaultNamespace + "individual");
return newResources;
}
@@ -211,10 +211,9 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati
//Handles both object and data property
private List generateN3Required(VitroRequest vreq) {
List n3ForEdit = new ArrayList();
- n3ForEdit.addAll(getN3Prefixes());
- n3ForEdit.add(getN3ForName());
+ n3ForEdit.add(getN3PrefixesAsString() + "\n" + getN3ForName());
n3ForEdit.add("?subject ?predicate ?" + objectVarName + " .");
- n3ForEdit.add("?" + objectVarName + " rdf:type " + getRangeClassUri(vreq) + " . ");
+ n3ForEdit.add(getN3PrefixesAsString() + "\n" + "?" + objectVarName + " rdf:type <" + getRangeClassUri(vreq) + "> . ");
return n3ForEdit;
}
@@ -225,19 +224,23 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati
return prefixStrings;
}
+ private String getN3PrefixesAsString() {
+ String prefixes = StringUtils.join(getN3Prefixes(), "\n");
+ return prefixes;
+ }
+
private String getN3ForName() {
- return "?" + objectVarName + " rdfs:label ?name";
+ return "?" + objectVarName + " rdfs:label ?name .";
}
private List generateN3Optional(VitroRequest vreq) {
//flag uri and asserted types need to be added here
List n3Optional = new ArrayList();
- n3Optional.addAll(getN3Prefixes());
n3Optional.add("?" + objectVarName + " ?inverseProp ?subject .");
//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("?" + objectVarName + " rdf:type " + getFlagURI(vreq));
+ n3Optional.add(getN3PrefixesAsString() + "\n" + "?" + objectVarName + " rdf:type <" + getFlagURI(vreq) + "> . ");
return n3Optional;
}
@@ -260,6 +263,11 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati
private void setUrisAndLiteralsInScope(EditConfigurationVTwo editConfiguration) {
HashMap> urisInScope = new HashMap>();
+ //Add subject uri and predicate turo to uris in scope
+ urisInScope.put(editConfiguration.getVarNameForSubject(),
+ Arrays.asList(new String[]{editConfiguration.getSubjectUri()}));
+ urisInScope.put(editConfiguration.getVarNameForPredicate(),
+ Arrays.asList(new String[]{editConfiguration.getPredicateUri()}));
editConfiguration.setUrisInScope(urisInScope);
editConfiguration.setLiteralsInScope(new HashMap>());
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultDeleteGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultDeleteGenerator.java
index a93e1cd32..6f4bbb2a7 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultDeleteGenerator.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultDeleteGenerator.java
@@ -67,9 +67,83 @@ public class DefaultDeleteGenerator implements EditConfigurationGenerator {
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
HttpSession session) {
EditConfigurationVTwo editConfiguration = EditConfigurationVTwo.getConfigFromSession(session, vreq);
+ //Two paths for deletion: (i) from front page and (ii) from edit page of individual
+ //If (ii), edit configuration already exists but if (i) no edit configuration exists or is required for deletion
+ //so stub will be created that contains a minimal set of information
//Set template to be confirm delete
+ if(editConfiguration == null) {
+ editConfiguration = setupEditConfiguration(vreq, session);
+ }
editConfiguration.setTemplate(template);
return editConfiguration;
}
+ private EditConfigurationVTwo setupEditConfiguration(VitroRequest vreq, HttpSession session) {
+ EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
+ initProcessParameters(vreq, session, editConfiguration);
+ //set edit key for this as well
+ editConfiguration.setEditKey(editConfiguration.newEditKey(session));
+ return editConfiguration;
+
+ }
+
+ //Do need to know whether data or object property and how to handle that
+ private void initProcessParameters(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
+ subjectUri = EditConfigurationUtils.getSubjectUri(vreq);
+ predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
+ editConfiguration.setSubjectUri(subjectUri);
+ editConfiguration.setPredicateUri(predicateUri);
+ editConfiguration.setEntityToReturnTo(subjectUri);
+ editConfiguration.setUrlPatternToReturnTo("/individual");
+
+ if(EditConfigurationUtils.isObjectProperty(predicateUri, vreq)) {
+ //not concerned about remainder, can move into default obj prop form if required
+ this.initObjectParameters(vreq);
+ this.processObjectPropForm(vreq, editConfiguration);
+ } else {
+ this.initDataParameters(vreq, session);
+ this.processDataPropForm(vreq, editConfiguration);
+ }
+ }
+
+ private void initDataParameters(VitroRequest vreq, HttpSession session) {
+ datapropKeyStr = EditConfigurationUtils.getDataPropKey(vreq);
+ if( datapropKeyStr != null ){
+ try {
+ dataHash = Integer.parseInt(datapropKeyStr);
+ log.debug("Found a datapropKey in parameters and parsed it to int: " + dataHash);
+ } catch (NumberFormatException ex) {
+ //return doHelp(vreq, "Cannot decode incoming datapropKey value "+datapropKeyStr+" as an integer hash in EditDataPropStmtRequestDispatchController");
+ }
+ }
+ dps = EditConfigurationUtils.getDataPropertyStatement(vreq, session, dataHash, predicateUri);
+ }
+
+
+
+ private void initObjectParameters(VitroRequest vreq) {
+ //in case of object property
+ objectUri = EditConfigurationUtils.getObjectUri(vreq);
+ }
+
+ private void processObjectPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
+ editConfiguration.setObject(objectUri);
+ //this needs to be set for the editing to be triggered properly, otherwise the 'prepare' method
+ //pretends this is a data property editing statement and throws an error
+ //TODO: Check if null in case no object uri exists but this is still an object property
+ if(objectUri != null) {
+ editConfiguration.setObjectResource(true);
+ }
+ }
+
+ private void processDataPropForm(VitroRequest vreq, EditConfigurationVTwo editConfiguration) {
+ editConfiguration.setObjectResource(false);
+ //set data prop value, data prop key str,
+ editConfiguration.setDatapropKey((datapropKeyStr==null)?"":datapropKeyStr);
+ //original set datapropValue, which in this case would be empty string but no way here
+ editConfiguration.setDatapropValue("");
+ }
+
+
+
}
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 7099a531a..81f21433f 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
@@ -90,6 +90,8 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
templateData.put("title", "Edit");
templateData.put("submitUrl", getSubmissionUrl(vreq));
templateData.put("editKey", editConfig.getEditKey());
+ //This may change based on the particular generator? Check if true
+ templateData.put("bodyClasses", "formsEdit");
return new TemplateResponseValues(template, templateData);
}catch(Throwable th){
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
index f27c48ca8..c6fbbe008 100644
--- 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
@@ -114,7 +114,7 @@ public class PostEditCleanupController extends FreemarkerHttpServlet{
} else if ( !urlPattern.endsWith("individual") && !urlPattern.endsWith("entity") ){
return new RedirectResponseValues( urlPattern );
}
- return new RedirectResponseValues( UrlBuilder.getUrl(Route.LOGIN) );
+ return new RedirectResponseValues( Route.LOGIN );
}
}
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 6ed90e83b..c78fe2f9c 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
@@ -360,7 +360,7 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
public Map getStatementDisplay() {
Map statementDisplay = new HashMap();
if(isDataProperty()) {
- statementDisplay.put("dataValue", getDataLiteralValuesAsString());
+ statementDisplay.put("dataValue", getDataLiteralValuesFromParameter());
} else {
//Expecting statement parameters to be passed in
Map params = vreq.getParameterMap();
@@ -377,7 +377,23 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
return statementDisplay;
}
- //TODO:Check where this logic should actually go, copied from input element formatting tag
+ //Retrieves data propkey from parameter and gets appropriate data value
+ private String getDataLiteralValuesFromParameter() {
+ String dataValue = null;
+ //Get data hash
+ int dataHash = EditConfigurationUtils.getDataHash(vreq);
+ DataPropertyStatement dps = EditConfigurationUtils.getDataPropertyStatement(vreq,
+ vreq.getSession(),
+ dataHash,
+ EditConfigurationUtils.getPredicateUri(vreq));
+ if(dps != null) {
+ dataValue = dps.getData().trim();
+ }
+ return dataValue;
+
+ }
+
+ //TODO:Check where this logic should actually go, copied from input element formatting tag
public Map getOfferTypesCreateNew() {
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
ObjectProperty op =
@@ -472,17 +488,17 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
}
public String getCurrentUrl() {
- return getMainEditUrl() + "?" + vreq.getQueryString();
+ return EditConfigurationUtils.getEditUrl(vreq) + "?" + vreq.getQueryString();
+ }
+
+ public String getMainEditUrl() {
+ return EditConfigurationUtils.getEditUrl(vreq);
}
//this url is for canceling
public String getCancelUrl() {
String editKey = editConfig.getEditKey();
- return vreq.getContextPath() + "/postEditCleanupController?editKey=" + editKey + "&cancel=true";
- }
-
- public String getMainEditUrl() {
- return vreq.getContextPath() + "/editRequestDispatch";
+ return EditConfigurationUtils.getCancelUrlBase(vreq) + "?editKey=" + editKey + "&cancel=true";
}
//Get confirm deletion url
diff --git a/webapp/web/templates/freemarker/edit/forms/confirmDeletePropertyForm.ftl b/webapp/web/templates/freemarker/edit/forms/confirmDeletePropertyForm.ftl
index 1b988a356..5a50e5ed0 100644
--- a/webapp/web/templates/freemarker/edit/forms/confirmDeletePropertyForm.ftl
+++ b/webapp/web/templates/freemarker/edit/forms/confirmDeletePropertyForm.ftl
@@ -29,10 +29,14 @@
#if>
+ <#if editConfiguration.objectProperty = true>