NIHVIVO-3186 first attempts -- auto-complete for Person does not work.

This commit is contained in:
j2blake 2011-11-21 18:28:14 +00:00
parent d90e69d2c4
commit bb56822519
2 changed files with 324 additions and 78 deletions

View file

@ -4,7 +4,7 @@
<#import "lib-vivo-form.ftl" as lvf>
<#if editConfig.object?has_content>
<#if editConfiguration.objectUri?has_content>
<#assign editMode = "edit">
<#else>
<#assign editMode = "add">
@ -23,49 +23,77 @@
<#assign requiredHint = "<span class='requiredHint'> *</span>" />
<#assign yearHint = "<span class='hint'>(YYYY)</span>" />
<#if editMode = “ERROR”>
<div>This form is unable to handle the editing of this position because it is associated with
multiple Position individuals.</div>
<#else>
<#assign positionTitleValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "positionTitle") />
<#assign positionTypeValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "positionType") />
<#assign personLabelValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "personLabel") />
<h2>${titleVerb}&nbsp;educational training entry for ${subjectName}</h2>
<#if errorTitleFieldIsEmpty??>
<#assign errorMessage = "Enter a position title." />
<#if editSubmission?has_content && editSubmission.submissionExists = true && editSubmission.validationErrors?has_content>
<#assign submissionErrors = editSubmission.validationErrors/>
</#if>
<#if errorTypeFieldIsEmpty??>
<#assign errorMessage = "Select a position type." />
</#if>
<h2>${titleVerb}&nbsp;educational training entry for ${editConfiguration.subjectName}</h2>
<#if errorMessage?has_content>
<#if submissionErrors?has_content>
<section id="error-alert" role="alert">
<img src="${urls.images}/iconAlert.png" width="24" height="24" alert="Error alert icon" />
<p>${errorMessage}</p>
<p>
<#if lvf.submissionErrorExists(editSubmission, "positionTitle")>
Please enter a value in the Position Title field.
</#if>
<#if lvf.submissionErrorExists(editSubmission, "positionType")>
Please select a value in the Position Type field.
</#if>
<#if lvf.submissionErrorExists(editSubmission, "personLabel")>
Please enter a value in the Person field.
</#if>
<#list submissionErrors?keys as errorFieldName>
<#if errorFieldName == "startField">
<#if submissionErrors[errorFieldName]?contains("before")>
The Start Year must be earlier than the End Year.
<#else>
${submissionErrors[errorFieldName]}
</#if>
<br />
<#elseif errorFieldName == "endField">
<#if submissionErrors[errorFieldName]?contains("after")>
The End Year must be later than the Start Year.
<#else>
${submissionErrors[errorFieldName]}
</#if>
</#if>
</#list>
</p>
</section>
</#if>
<section id="organizationHasPositionHistory" role="region">
<@lvf.unsupportedBrowser urls.base/>
<@lvf.unsupportedBrowser urls.base/>
<form id="organizationHasPositionHistory" class="customForm noIE67" action="${submitUrl}" role="add/edit position history">
<p>
<label for="positionTitle">Position Title ${requiredHint}</label>
<input size="30" type="text" id="positionTitle" name="positionTitle" value="${positionTitle}" />
<input size="30" type="text" id="positionTitle" name="positionTitle" value="${positionTitleValue}" />
</p>
<label for="positionType">Position Type ${requiredHint}</label>
<#assign posnTypeOpts = editConfiguration.pageData.positionType />
<select id="positionType" name="positionType">
<option value="" selected="selected">Select one</option>
<#list rangeOptionKeys as key>
<opton value="${key}"
<#if editConfiguration.objectUri?has_content && editConfiguration.object.Uri = key>selected</#if>
<#if (posnTypeOpts?keys)??>
<#list posnTypeOpts?keys as key>
<#if positionTypeValue?has_content && positionTypeValue = key>
<option value="${key}" selected >${posnTypeOpts[key]}</option>
<#else>
<option value="${key}">${posnTypeOpts[key]}</option>
</#if>
</#list>
</#if>
</select>
<p>
<label for="relatedIndLabel">Person</label>
<input class="acSelector" size="50" type="text" id="relatedIndLabel" name="orgLabel" value="${orgLabel}" />
<input class="acSelector" size="50" type="text" id="relatedIndLabel" name="personLabel" value="${personLabelValue}" />
</p>
<div class="acSelection">
@ -74,43 +102,45 @@
<span class="acSelectionInfo"></span>
<a href="/vivo/individual?uri=" class="verifyMatch">(Verify this match)</a>
</p>
<input class="acUriReceiver" type="hidden" id="${roleActivityUri}" name="org" value="" />
<input class="acLabelReceiver" type="hidden" id="existingPersonLabel" name="existingPersonLabel" value="${personLabel}" />
<input class="acUriReceiver" type="hidden" id="personUri" name="org" value="" />
<input class="acLabelReceiver" type="hidden" id="existingPersonLabel" name="existingPersonLabel" value="${personLabelValue}" />
</div>
<label for="startField">Start Year ${yearHint}</label>
<fieldset class="dateTime" >
<input class="text-field" name="startField-year" id="startField-year" type="text" value="${startYear}" size="4" maxlength="4" />
</fieldset>
<label for="endField">End Year ${yearHint}</label>
<fieldset class="dateTime">
<input class="text-field" name="endField-year" id="endField-year" type="text" value="${endYear}" size="4" maxlength="4" />
</fieldset>
<#--Need to draw edit elements for dates here-->
<#assign htmlForElements = editConfiguration.pageData.htmlForElements />
<#if htmlForElements?keys?seq_contains("startField")>
<label class="dateTime" for="startField">Start</label>
${htmlForElements["startField"]} ${yearHint}
</#if>
<br/>
<#if htmlForElements?keys?seq_contains("endField")>
<label class="dateTime" for="endField">End</label>
${htmlForElements["endField"]} ${yearHint}
</#if>
<#--End draw elements-->
<p class="submit">
<input type="hidden" name = "editKey" value="${???}"/>
<input type="submit" id="submit" value="editConfiguration.submitLabel"/><span class="or"> or </span><a class="cancel" href="${editConfiguration.cancelUrl}">Cancel</a>
<input type="hidden" id="editKey" name="editKey" value="${editKey}" />
<input type="submit" id="submit" value="${submitButtonText}"/>
<span class="or"> or </span><a class="cancel" href="${cancelUrl}">Cancel</a>
</p>
<p id="requiredLegend" class="requiredHint">* required fields</p>
</form>
</form>
<script type="text/javascript">
var customFormData = {
<script type="text/javascript">
var customFormData = {
acUrl: '${urls.base}/autocomplete?tokenize=true&stem=true',
editMode: '${editMode}',
submitButtonTextType: 'compound',
defaultTypeName: 'person'
};
</script>
};
</script>
</section>
</#if>
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/js/jquery-ui/css/smoothness/jquery-ui-1.8.9.custom.css" />')}
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/edit/forms/css/customForm.css" />')}
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/edit/forms/css/customFormWithAutocomplete.css" />')}
@ -121,4 +151,3 @@ ${scripts.add('<script type="text/javascript" src="${urls.base}/js/jquery-ui/js/
'<script type="text/javascript" src="${urls.base}/js/extensions/String.js"></script>',
'<script type="text/javascript" src="${urls.base}/js/jquery_plugins/jquery.bgiframe.pack.js"></script>',
'<script type="text/javascript" src="${urls.base}/edit/forms/js/customFormWithAutocomplete.js"></script>')}

View file

@ -1,18 +1,235 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
import java.util.Arrays;
import javax.servlet.http.HttpSession;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
import com.hp.hpl.jena.vocabulary.RDFS;
import com.hp.hpl.jena.vocabulary.XSD;
public class OrganizationHasPositionHistoryGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator {
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary.Precision;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeIntervalValidationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
public class OrganizationHasPositionHistoryGenerator extends VivoBaseGenerator
implements EditConfigurationGenerator {
private final static String NS_VIVO_CORE = "http://vivoweb.org/ontology/core#";
private final static String URI_RDFS_LABEL = RDFS.label.getURI();
private static final String URI_PRECISION_NONE = Precision.NONE.uri();
private static final String URI_PRECISION_YEAR = Precision.YEAR.uri();
private final static String URI_POSITION_CLASS = vivoCore("Position");
private final static String URI_POSITION_FOR_PERSON = vivoCore("positionForPerson");
private final static String URI_INTERVAL_FOR_POSITION = vivoCore("dateTimeInterval");
private final static String URI_DATE_TIME_INTERVAL_CLASS = vivoCore("DateTimeInterval");
private final static String URI_DATE_TIME_VALUE_CLASS = vivoCore("DateTimeValue");
private final static String URI_DATE_TIME_VALUE = vivoCore("dateTime");
private final static String URI_DATE_TIME_PRECISION = vivoCore("dateTimePrecision");
private final static String URI_INTERVAL_TO_START = vivoCore("start");
private final static String URI_INTERVAL_TO_END = vivoCore("end");
private static String vivoCore(String localName) {
return NS_VIVO_CORE + localName;
}
private static final String QUERY_EXISTING_POSITION_TITLE = "SELECT ?existingPositionTitle WHERE { \n"
+ "?position <" + URI_RDFS_LABEL + "> ?existingPositionTitle . }";
private static final String QUERY_EXISTING_POSITION_TYPE = "SELECT ?existingPositionType WHERE { \n"
+ " ?position a ?existingPositionType . }";
private static final String QUERY_EXISTING_PERSON_LABEL = String.format(
"SELECT ?existingPersonLabel WHERE { \n"
+ " ?position <%1$s> ?existingPerson . \n"
+ " ?existingPerson <%2$s> ?existingPersonLabel . }",
URI_POSITION_FOR_PERSON, URI_RDFS_LABEL);
private static final String QUERY_EXISTING_INTERVAL_NODE = String.format(
"SELECT ?existingIntervalNode WHERE { \n"
+ " ?position <%1$s> ?existingIntervalNode . \n"
+ " ?existingIntervalNode a <%2$s> . }",
URI_INTERVAL_FOR_POSITION, URI_DATE_TIME_INTERVAL_CLASS);
private static final String QUERY_EXISTING_START_NODE = String.format(
"SELECT ?existingStartNode WHERE { \n"
+ " ?position <%1$s> ?intervalNode .\n"
+ " ?intervalNode a <%2$s> ;\n"
+ " <%3$s> ?existingStartNode . \n"
+ " ?existingStartNode a <%4$s> . }",
URI_INTERVAL_FOR_POSITION, URI_DATE_TIME_INTERVAL_CLASS,
URI_INTERVAL_TO_START, URI_DATE_TIME_VALUE_CLASS);
private static final String QUERY_EXISTING_START_VALUE = String.format(
"SELECT ?existingDateStart WHERE { \n"
+ " ?position <%1$s> ?intervalNode .\n"
+ " ?intervalNode a <%2$s> ; \n"
+ " <%3$s> ?startNode . \n"
+ " ?startNode a <%4$s> ; \n"
+ " <%5$s> ?existingDateStart . }",
URI_INTERVAL_FOR_POSITION, URI_DATE_TIME_INTERVAL_CLASS,
URI_INTERVAL_TO_START, URI_DATE_TIME_VALUE_CLASS,
URI_DATE_TIME_VALUE);
private static final String QUERY_EXISTING_START_PRECISION = String.format(
"SELECT ?existingStartPrecision WHERE { \n"
+ " ?position <%1$s> ?intervalNode .\n"
+ " ?intervalNode a <%2$s> ;\n"
+ " <%3$s> ?startNode . \n"
+ " ?startNode a <%4$s> ; \n"
+ " <%5$s> ?existingStartPrecision . }",
URI_INTERVAL_FOR_POSITION, URI_DATE_TIME_INTERVAL_CLASS,
URI_INTERVAL_TO_START, URI_DATE_TIME_VALUE_CLASS,
URI_DATE_TIME_PRECISION);
private static final String QUERY_EXISTING_END_VALUE = String
.format("SELECT ?existingDateEnd WHERE { \n"
+ " ?position <%1$s> ?intervalNode .\n"
+ " ?intervalNode a <%2$s> ; \n"
+ " <%3$s> ?endNode . \n"
+ " ?endNode a <%4$s> ; \n"
+ " <%5$s> ?existingDateEnd . }",
URI_INTERVAL_FOR_POSITION, URI_DATE_TIME_INTERVAL_CLASS,
URI_INTERVAL_TO_END, URI_DATE_TIME_VALUE_CLASS,
URI_DATE_TIME_VALUE);
private static final String QUERY_EXISTING_END_PRECISION = String.format(
"SELECT ?existingEndPrecision WHERE { \n"
+ " ?position <%1$s> ?intervalNode .\n"
+ " ?intervalNode a <%2$s> ;\n"
+ " <%3$s> ?endNode . \n" + " ?endNode a <%4$s> ; \n"
+ " <%5$s> ?existingEndPrecision . }",
URI_INTERVAL_FOR_POSITION, URI_DATE_TIME_INTERVAL_CLASS,
URI_INTERVAL_TO_END, URI_DATE_TIME_VALUE_CLASS,
URI_DATE_TIME_PRECISION);
private static final String QUERY_EXISTING_END_NODE = String.format(
"SELECT ?existingEndNode WHERE { \n"
+ " ?position <%1$s> ?intervalNode .\n"
+ " ?intervalNode a <%2$s> ;\n"
+ " <%3$s> ?existingEndNode . \n"
+ " ?existingEndNode a <%4$s> .}",
URI_INTERVAL_FOR_POSITION, URI_DATE_TIME_INTERVAL_CLASS,
URI_INTERVAL_TO_END, URI_DATE_TIME_VALUE_CLASS);
private static final String N3_NEW_POSITION = ""
+ "@prefix core: <http://vivoweb.org/ontology/core#> . \n"
+ "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"
+ "\n" //
+ "?organization core:organizationForPosition ?position . \n"
+ "\n" //
+ "?position a core:Position , ?positionType ; \n"
+ " rdfs:label ?positionTitle ; \n"
+ " core:positionInOrganization ?organization ; \n"
+ " core:positionForPerson ?person . \n" //
+ "\n" //
+ "?person core:personInPosition ?position .";
private static final String N3_NEW_START_NODE = ""
+ "@prefix core: <http://vivoweb.org/ontology/core#> . \n"
+ "\n" //
+ "?position core:dateTimeInterval ?intervalNode . \n"
+ "\n" //
+ "?intervalNode a core:DateTimeInterval ; \n"
+ " core:start ?startNode . \n "
+ "\n" //
+ "?startNode a core:DateTimeValue ; \n"
+ " core:dateTime ?startField-value ; \n"
+ " core:dateTimePrecision ?startField-precision . ";
private static final String N3_NEW_END_NODE = ""
+ "@prefix core: <http://vivoweb.org/ontology/core#> . \n"
+ "\n" //
+ "?position core:dateTimeInterval ?intervalNode . \n"
+ "\n" //
+ "?intervalNode a core:DateTimeInterval ; \n"
+ " core:end ?endNode . \n "
+ "\n" //
+ "?endNode a core:DateTimeValue ; \n"
+ " core:dateTime ?endField-value ; \n"
+ " core:dateTimePrecision ?endField-precision . ";
@Override
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
HttpSession session) {
// TODO Auto-generated method stub
throw new Error(this.getClass().getName() + " is not yet implement");
}
EditConfigurationVTwo conf = new EditConfigurationVTwo();
initBasics(conf, vreq);
initPropertyParameters(vreq, session, conf);
initObjectPropForm(conf, vreq);
conf.setVarNameForSubject("organization");
conf.setVarNameForPredicate("predicate");
conf.setVarNameForObject("position");
conf.setTemplate("organizationHasPositionHistory.ftl");
conf.setN3Required(Arrays.asList(N3_NEW_POSITION));
conf.setN3Optional(Arrays.asList(N3_NEW_START_NODE, N3_NEW_END_NODE));
conf.addNewResource("position", DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("person", DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("intervalNode", DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("startNode", DEFAULT_NS_FOR_NEW_RESOURCE);
conf.addNewResource("endNode", DEFAULT_NS_FOR_NEW_RESOURCE);
conf.setUrisOnform(Arrays.asList("position", "positionType"));
conf.addSparqlForExistingUris("positionType",
QUERY_EXISTING_POSITION_TYPE);
conf.addSparqlForExistingUris("intervalNode",
QUERY_EXISTING_INTERVAL_NODE);
conf.addSparqlForExistingUris("startNode", QUERY_EXISTING_START_NODE);
conf.addSparqlForExistingUris("endNode", QUERY_EXISTING_END_NODE);
conf.setLiteralsOnForm(Arrays.asList("positionTitle", "personLabel"));
conf.addSparqlForExistingLiteral("positionTitle",
QUERY_EXISTING_POSITION_TITLE);
conf.addSparqlForExistingLiteral("personLabel",
QUERY_EXISTING_PERSON_LABEL);
conf.addSparqlForExistingLiteral("startField-value",
QUERY_EXISTING_START_VALUE);
conf.addSparqlForExistingUris("startField-precision",
QUERY_EXISTING_START_PRECISION);
conf.addSparqlForExistingLiteral("endField-value",
QUERY_EXISTING_END_VALUE);
conf.addSparqlForExistingUris("endField-precision",
QUERY_EXISTING_END_PRECISION);
conf.addField(new FieldVTwo()
.setName("positionType")
.setOptionsType(
FieldVTwo.OptionsType.CHILD_VCLASSES_WITH_PARENT)
.setObjectClassUri(URI_POSITION_CLASS)
.setValidators(list("nonempty")));
conf.addField(new FieldVTwo().setName("positionTitle")
.setRangeDatatypeUri(XSD.xstring.toString())
.setValidators(list("nonempty")));
conf.addField(new FieldVTwo().setName("personLabel")
.setRangeDatatypeUri(XSD.xstring.toString())
.setValidators(list("nonempty")));
FieldVTwo startField = new FieldVTwo().setName("startField");
conf.addField(startField.setEditElement(new DateTimeWithPrecisionVTwo(
startField, URI_PRECISION_YEAR, URI_PRECISION_NONE)));
FieldVTwo endField = new FieldVTwo().setName("endField");
conf.addField(endField.setEditElement(new DateTimeWithPrecisionVTwo(
endField, URI_PRECISION_YEAR, URI_PRECISION_NONE)));
conf.addValidator(new DateTimeIntervalValidationVTwo("startField",
"endField"));
return conf;
}
}