Updates for N3Editing

This commit is contained in:
hjkhjk54 2011-10-17 19:05:30 +00:00
parent 8fc35cf66c
commit 94091c668e
10 changed files with 148 additions and 64 deletions

View file

@ -109,7 +109,15 @@ public class EditConfigurationUtils {
} }
public static String getFormUrl(VitroRequest vreq) { 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";
} }

View file

@ -69,6 +69,7 @@ public class MultiValueEditSubmission {
String[] valuesArray = queryParameters.get( var ); String[] valuesArray = queryParameters.get( var );
//String uri = null; //String uri = null;
List<String> values = (valuesArray != null) ? Arrays.asList(valuesArray) : null; List<String> values = (valuesArray != null) ? Arrays.asList(valuesArray) : null;
if( values != null && values.size() > 0){
//Iterate through the values and check to see if they should be added or removed from form //Iterate through the values and check to see if they should be added or removed from form
urisFromForm.put(var, values); urisFromForm.put(var, values);
for(String uri : values) { for(String uri : values) {
@ -77,24 +78,9 @@ public class MultiValueEditSubmission {
urisFromForm.remove(var); 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 { } else {
log.debug("No value found for query parameter " + var); 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<String,List<Literal>>(); this.literalsFromForm =new HashMap<String,List<Literal>>();
@ -122,25 +108,6 @@ public class MultiValueEditSubmission {
} }
} }
literalsFromForm.put(var, literalsArray); 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{ }else{
log.debug("could not find value for parameter " + var ); log.debug("could not find value for parameter " + var );

View file

@ -97,6 +97,7 @@ public class ProcessRdfForm {
// //
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
public static AdditionsAndRetractions createNewStatement(EditConfigurationVTwo editConfiguration , MultiValueEditSubmission submission, VitroRequest vreq){ public static AdditionsAndRetractions createNewStatement(EditConfigurationVTwo editConfiguration , MultiValueEditSubmission submission, VitroRequest vreq){
varToNewResource = null;
//Get all assertions //Get all assertions
List<Model> assertions = populateAssertions(editConfiguration, submission, vreq); List<Model> assertions = populateAssertions(editConfiguration, submission, vreq);
//Retractions should be empty anyway but the method should take care of that //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) { public static AdditionsAndRetractions editExistingStatement(EditConfigurationVTwo editConfiguration, MultiValueEditSubmission submission, VitroRequest vreq) {
varToNewResource = null;
List<Model> fieldAssertions = populateAssertions(editConfiguration, submission, vreq); List<Model> fieldAssertions = populateAssertions(editConfiguration, submission, vreq);
List<Model> fieldRetractions = populateRetractions(editConfiguration, submission, vreq); List<Model> fieldRetractions = populateRetractions(editConfiguration, submission, vreq);
return getMinimalChanges(new AdditionsAndRetractions(fieldAssertions, fieldRetractions)); return getMinimalChanges(new AdditionsAndRetractions(fieldAssertions, fieldRetractions));

View file

@ -126,7 +126,7 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati
private Map<String, String> generateNewResources(VitroRequest vreq) { private Map<String, String> generateNewResources(VitroRequest vreq) {
HashMap<String, String> newResources = new HashMap<String, String>(); HashMap<String, String> newResources = new HashMap<String, String>();
//TODO: Get default namespace //TODO: Get default namespace
String defaultNamespace = ""; String defaultNamespace = vreq.getWebappDaoFactory().getDefaultNamespace();
newResources.put(objectVarName, defaultNamespace + "individual"); newResources.put(objectVarName, defaultNamespace + "individual");
return newResources; return newResources;
} }
@ -211,10 +211,9 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati
//Handles both object and data property //Handles both object and data property
private List<String> generateN3Required(VitroRequest vreq) { private List<String> generateN3Required(VitroRequest vreq) {
List<String> n3ForEdit = new ArrayList<String>(); List<String> n3ForEdit = new ArrayList<String>();
n3ForEdit.addAll(getN3Prefixes()); n3ForEdit.add(getN3PrefixesAsString() + "\n" + getN3ForName());
n3ForEdit.add(getN3ForName());
n3ForEdit.add("?subject ?predicate ?" + objectVarName + " ."); n3ForEdit.add("?subject ?predicate ?" + objectVarName + " .");
n3ForEdit.add("?" + objectVarName + " rdf:type " + getRangeClassUri(vreq) + " . "); n3ForEdit.add(getN3PrefixesAsString() + "\n" + "?" + objectVarName + " rdf:type <" + getRangeClassUri(vreq) + "> . ");
return n3ForEdit; return n3ForEdit;
} }
@ -225,19 +224,23 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati
return prefixStrings; return prefixStrings;
} }
private String getN3PrefixesAsString() {
String prefixes = StringUtils.join(getN3Prefixes(), "\n");
return prefixes;
}
private String getN3ForName() { private String getN3ForName() {
return "?" + objectVarName + " rdfs:label ?name"; return "?" + objectVarName + " rdfs:label ?name .";
} }
private List<String> generateN3Optional(VitroRequest vreq) { private List<String> generateN3Optional(VitroRequest vreq) {
//flag uri and asserted types need to be added here //flag uri and asserted types need to be added here
List<String> n3Optional = new ArrayList<String>(); List<String> n3Optional = new ArrayList<String>();
n3Optional.addAll(getN3Prefixes());
n3Optional.add("?" + objectVarName + " ?inverseProp ?subject ."); n3Optional.add("?" + objectVarName + " ?inverseProp ?subject .");
//asserted types string buffer is empty in the original jsp //asserted types string buffer is empty in the original jsp
//TODO: Review original comments in jsp to see what could go here //TODO: Review original comments in jsp to see what could go here
//n3Optional.add(getN3AssertedTypes(vreq)); //n3Optional.add(getN3AssertedTypes(vreq));
n3Optional.add("?" + objectVarName + " rdf:type " + getFlagURI(vreq)); n3Optional.add(getN3PrefixesAsString() + "\n" + "?" + objectVarName + " rdf:type <" + getFlagURI(vreq) + "> . ");
return n3Optional; return n3Optional;
} }
@ -260,6 +263,11 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati
private void setUrisAndLiteralsInScope(EditConfigurationVTwo editConfiguration) { private void setUrisAndLiteralsInScope(EditConfigurationVTwo editConfiguration) {
HashMap<String, List<String>> urisInScope = new HashMap<String, List<String>>(); HashMap<String, List<String>> urisInScope = new HashMap<String, List<String>>();
//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.setUrisInScope(urisInScope);
editConfiguration.setLiteralsInScope(new HashMap<String, List<Literal>>()); editConfiguration.setLiteralsInScope(new HashMap<String, List<Literal>>());
} }

View file

@ -67,9 +67,83 @@ public class DefaultDeleteGenerator implements EditConfigurationGenerator {
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
HttpSession session) { HttpSession session) {
EditConfigurationVTwo editConfiguration = EditConfigurationVTwo.getConfigFromSession(session, vreq); 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 //Set template to be confirm delete
if(editConfiguration == null) {
editConfiguration = setupEditConfiguration(vreq, session);
}
editConfiguration.setTemplate(template); editConfiguration.setTemplate(template);
return editConfiguration; 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("");
}
} }

View file

@ -90,6 +90,8 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
templateData.put("title", "Edit"); templateData.put("title", "Edit");
templateData.put("submitUrl", getSubmissionUrl(vreq)); templateData.put("submitUrl", getSubmissionUrl(vreq));
templateData.put("editKey", editConfig.getEditKey()); 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); return new TemplateResponseValues(template, templateData);
}catch(Throwable th){ }catch(Throwable th){

View file

@ -114,7 +114,7 @@ public class PostEditCleanupController extends FreemarkerHttpServlet{
} else if ( !urlPattern.endsWith("individual") && !urlPattern.endsWith("entity") ){ } else if ( !urlPattern.endsWith("individual") && !urlPattern.endsWith("entity") ){
return new RedirectResponseValues( urlPattern ); return new RedirectResponseValues( urlPattern );
} }
return new RedirectResponseValues( UrlBuilder.getUrl(Route.LOGIN) ); return new RedirectResponseValues( Route.LOGIN );
} }
} }

View file

@ -360,7 +360,7 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
public Map<String, String> getStatementDisplay() { public Map<String, String> getStatementDisplay() {
Map<String, String> statementDisplay = new HashMap<String, String>(); Map<String, String> statementDisplay = new HashMap<String, String>();
if(isDataProperty()) { if(isDataProperty()) {
statementDisplay.put("dataValue", getDataLiteralValuesAsString()); statementDisplay.put("dataValue", getDataLiteralValuesFromParameter());
} else { } else {
//Expecting statement parameters to be passed in //Expecting statement parameters to be passed in
Map params = vreq.getParameterMap(); Map params = vreq.getParameterMap();
@ -377,6 +377,22 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
return statementDisplay; return statementDisplay;
} }
//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 //TODO:Check where this logic should actually go, copied from input element formatting tag
public Map<String, String> getOfferTypesCreateNew() { public Map<String, String> getOfferTypesCreateNew() {
WebappDaoFactory wdf = vreq.getWebappDaoFactory(); WebappDaoFactory wdf = vreq.getWebappDaoFactory();
@ -472,17 +488,17 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
} }
public String getCurrentUrl() { 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 //this url is for canceling
public String getCancelUrl() { public String getCancelUrl() {
String editKey = editConfig.getEditKey(); String editKey = editConfig.getEditKey();
return vreq.getContextPath() + "/postEditCleanupController?editKey=" + editKey + "&cancel=true"; return EditConfigurationUtils.getCancelUrlBase(vreq) + "?editKey=" + editKey + "&cancel=true";
}
public String getMainEditUrl() {
return vreq.getContextPath() + "/editRequestDispatch";
} }
//Get confirm deletion url //Get confirm deletion url

View file

@ -29,10 +29,14 @@
</#if> </#if>
<#if editConfiguration.objectProperty = true>
<p class="submit"> <p class="submit">
</#if>
<input type="submit" id="delete" value="Delete"/> <input type="submit" id="delete" value="Delete"/>
<span class="or"> or </span> or
<a title="Cancel" href="${editConfiguration.cancelUrl}">Cancel</a> <a class="cancel" title="Cancel" href="${editConfiguration.cancelUrl}">Cancel</a>
<#if editConfiguration.objectProperty = true>
</p> </p>
</#if>
</form> </form>

View file

@ -5,10 +5,13 @@
</#assign> </#assign>
<#if editConfiguration.objectUri?has_content> <#if editConfiguration.objectUri?has_content>
<#assign formTitle>Edit ${formTitle} </#assign> <#assign formTitle>Edit ${formTitle} </#assign>
<#assign submitLabel>Save changes</#assign>
<#else> <#else>
<#assign formTitle>Create ${formTitle} </#assign> <#assign formTitle>Create ${formTitle} </#assign>
<#assign submitLabel>Create "${editConfiguration.propertyPublicDomainTitle}" entry</#assign>
</#if> </#if>
<h2>${formTitle}</h2> <h2>${formTitle}</h2>
<form class="editForm" action = "${submitUrl}"> <form class="editForm" action = "${submitUrl}">
@ -17,7 +20,7 @@
<br/> <br/>
<div style="margin-top: 0.2em"> <div style="margin-top: 0.2em">
<input type="submit" id="submit" value="${editConfiguration.submitLabel}" <input type="submit" id="submit" value="${submitLabel}"
<span class="or"> or </span> <span class="or"> or </span>
<a title="Cancel" href="${editConfiguration.cancelUrl}">Cancel</a> <a title="Cancel" href="${editConfiguration.cancelUrl}">Cancel</a>
</div> </div>