This commit is contained in:
hjkhjk54 2011-11-02 14:56:54 +00:00
parent b4263c3176
commit dc08fbea1a
7 changed files with 1524 additions and 7 deletions

View file

@ -924,6 +924,7 @@
<url-pattern>/contact</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>JSON Service</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.JsonServlet</servlet-class>

View file

@ -7,14 +7,19 @@ roleDescriptor.
The other required values (roleType, optionsType, objectClassUri, and literalOptions are
set in the JAVA class corresponding to the form, e.g. AddClinicalRoleToPersonGenerator.java.
Optional values can be set, but each of these has default values
Optional values can be set in Freemarker, but each of these has default values
set in addRoleToPersonTwoStage.ftl:
buttonText
typeSelectorLabel
numDateFields
showRoleLAbelField
roleExamples-->
roleExamples
Optional values set in JAVA include
ShowRoleLabelField
ActivityToRolePredicate
RoleToActivityPredicate
-->
<#--Variable assignments for Add Clinical Role To Person-->

View file

@ -0,0 +1,195 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#--Retrieve certain edit configuration information-->
<#assign editMode = editConfiguration.pageData.editMode />
<#assign literalValues = editConfiguration.existingLiteralValues />
<#assign uriValues = editConfiguration.existingUriValues />
<#assign htmlForElements = editConfiguration.pageData.htmlForElements />
<#assign showRoleLabelField = editConfiguration.pageData.showRoleLabelField />
<#--Freemarker variables with default values that can be overridden by specific forms-->
<#--buttonText, typeSelectorLabel, numDateFields, roleExamples-->
<#if !buttonText?has_content>
<#assign buttonText = roleDescriptor />
</#if>
<#if !typeSelectorLabel?has_content>
<#assign typeSelectorLabel = roleDescriptor />
</#if>
<#if !numDateFields?has_content>
<#assign numDateFields = 2 />
</#if>
<#if !roleExamples?has_content>
<#assign roleExamples = "" />
</#if>
<#--Setting values for titleVerb, submitButonText, and disabled Value-->
<#if editConfiguration.objectUri?has_content>
<#assign titleVerb = "Edit"/>
<#assign submitButtonText>Edit ${buttonText}</#assign>
<#if editMode = "repair">
<#assign disabledVal = ""/>
<#else>
<#assign disabledVal = "disabled"/>
</#if>
<#else>
<#assign titleVerb = "Create"/>
<#assign submitButtonText>${buttonText}</#assign>
<#assign disabledVal = ""/>
<#assign editMode = "add" />
</#if>
<#--Get existing value for specific data literals and uris-->
<#--Get selected activity type value if it exists, this is alternative to below-->
<#assign activityTypeValue = ""/>
<#if uriValues?keys?seq_contains("roleActivityType") && (uriValues.roleActivityType?size > 0)>
<#assign activityTypeValue = uriValues.roleActivityType[0] />
</#if>
<#--Get activity label value-->
<#assign activityLabelValue = "" />
<#if literalValues?keys?seq_contains("activityLabel") && (literalValues.activityLabel?size > 0)>
<#assign activityLabelValue = literalValues.activityLabel[0] />
</#if>
<#--Get role label-->
<#assign roleLabel = "" />
<#if literalValues?keys?seq_contains("roleLabel") && (literalValues.roleLabel?size > 0) >
<#assign roleLabel = literalValues.roleLabel[0] />
</#if>
<h2>${titleVerb}&nbsp;${roleDescriptor} entry for ${editConfiguration.subjectName}</h2>
<#--Display error messages if any-->
<#if errorNameFieldIsEmpty??>
<#assign errorMessage = "Enter a name for the ." />
</#if>
<#if errorRoleFieldIsEmpty??>
<#assign errorMessage = "Specify a role for this ." />
</#if>
<#if errorMessage?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>
</section>
</#if>
<section id="add${roleDescriptor?capitalize}RoleToPersonTwoStage" role="region">
<form id="add${roleDescriptor?capitalize}RoleToPersonTwoStage" class="customForm noIE67" action="${submitUrl}" role="add/edit grant role">
<p class="inline"><label for="typeSelector">${roleDescriptor?capitalize} Type <span class='requiredHint'> *</span></label>
<select id="typeSelector" name="roleActivityType"
<#if disabledVal?has_content>
disabled = "${disabledVal}"
</#if>
>
<#--Code below allows for selection of first 'select one' option if no activity type selected-->
<#if activityTypeValue?has_content>
<#assign selectedActivityType = activityTypeValue />
<#else>
<#assign selectedActivityType = "" />
</#if>
<#assign roleActivityTypeSelect = editConfiguration.pageData.roleActivityType />
<#assign roleActivityTypeKeys = roleActivityTypeSelect?keys />
<#list roleActivityTypeKeys as key>
<option value="${key}"
<#if selectedActivityType = key>selected</#if>
>
${roleActivityTypeSelect[key]}
</option>
</#list>
</select>
</p>
<div class="fullViewOnly">
<p>
<label for="relatedIndLabel">${roleDescriptor?capitalize} Name <span class='requiredHint'> *</span></label>
<input class="acSelector" size="50" type="text" id="relatedIndLabel" name="activityLabel" value="${activityLabelValue}"
<#if disabledVal?has_content>
disabled=${disabledVal}
</#if>
/>
</p>
<input type="hidden" id="roleToActivityPredicate" name="roleToActivityPredicate" value="" />
<!--Populated or modified by JavaScript based on type of activity, type returned from AJAX request-->
<#if editMode = "edit">
<input type="hidden" id="roleActivityType" name="roleActivityType" value="${activityTypeValue}"/>
<input type="hidden" id="activityLabel" name="activityLabel" value="${activityLabelValue}}"/>
</#if>
<div class="acSelection">
<p class="inline">
<label>Selected ${roleDescriptor?capitalize}:</label>
<span class="acSelectionInfo"></span>
<a href="/vivo/individual?uri=" class="verifyMatch">(Verify this match)</a>
</p>
<input class="acUriReceiver" type="hidden" id="roleActivityUri" name="roleActivity" value="" />
<!-- Field value populated by JavaScript -->
</div>
<#if showRoleLabelField = true>
<p><label for="roleLabel">Role in ### <span class='requiredHint'> *</span> ${roleExamples}</label>
<input size="50" type="text" id="roleLabel" name="roleLabel" value="${roleLabel}" />
</p>
</#if>
<#if numDateFields == 1 >
<#--Generated html is a map with key name mapping to html string-->
<#if htmlForElements?keys?seq_contains("startField")>
<label for="startField">Start Year <span class='hint'>(YYYY)</span></label>
${htmlForElements["startField"]}
</#if>
<#else>
<h4>Years of Participation in ${roleDescriptor?capitalize}</h4>
<#if htmlForElements?keys?seq_contains("startField")>
<label for="startField">Start Year <span class='hint'>(YYYY)</span></label>
${htmlForElements["startField"]}
</#if>
<#if htmlForElements?keys?seq_contains("endField")>
<label for="endField">End Year <span class='hint'>(YYYY)</span></label>
${htmlForElements["endField"]}
</#if>
</#if>
</div>
<input type="hidden" id="editKey" name="editKey" value="${editKey} />
<p class="submit">
<input type="submit" id="submit" value="${submitButtonText}"/><span class="or"> or <a class="cancel" href="${cancelUrl}">Cancel</a>
</p>
<p id="requiredLegend" class="requiredHint">* required fields</p>
</form>
<#--Specifying form-specific script and adding stylesheets and scripts-->
<script type="text/javascript">
var customFormData = {
acUrl: '${urls.base}/autocomplete?tokenize=true',
editMode: '${editMode}',
submitButtonTextType: 'compound',
defaultTypeName: 'activity' // used in repair mode, to generate button text and org name field label
};
</script>
${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" />')}
${scripts.add('<script type="text/javascript" src="${urls.base}/js/jquery-ui/js/jquery-ui-1.8.9.custom.min.js"></script>')}
${scripts.add('<script type="text/javascript" src="${urls.base}/js/customFormUtils.js"></script>')}
${scripts.add('<script type="text/javascript" src="${urls.base}/edit/forms/js/customFormWithAutocomplete.js"></script>')}
</section>

View file

@ -0,0 +1,123 @@
/* $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 java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.vocabulary.RDFS;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.XSD;
import com.hp.hpl.jena.ontology.OntModel;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
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.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditN3GeneratorVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.SelectListGeneratorVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils;
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.DateTimeIntervalValidation;
/**
* Generates the edit configuration for adding a Role to a Person.
Stage one is selecting the type of the non-person thing
associated with the Role with the intention of reducing the
number of Individuals that the user has to select from.
Stage two is selecting the non-person Individual to associate
with the Role.
This is intended to create a set of statements like:
?person core:hasResearchActivityRole ?newRole.
?newRole rdf:type core:ResearchActivityRole ;
roleToActivityPredicate ?someActivity .
?someActivity rdf:type core:ResearchActivity .
?someActivity rdfs:label "activity title" .
Each subclass of the abstract two stage Generator class will have the option of overriding certain
methods, and must always implement the following methods:
getRoleType
getRoleActivityTypeOptionsType
getRoleActivityTypeObjectClassUri
getRoleActivityTypeLiteralOptions
*
*/
public class AddClinicalRoleToPersonGenerator extends AddRoleToPersonTwoStageGenerator {
private Log log = LogFactory.getLog(AddClinicalRoleToPersonGenerator.class);
private static String template = "addClinicalRoleToPerson.ftl";
//Should this be overridden
@Override
protected void setTemplate(EditConfigurationVTwo editConfiguration,
VitroRequest vreq) {
editConfiguration.setTemplate(template);
}
//The default activityToRolePredicate and roleToActivityPredicates are
//correct for this subclass so they don't need to be overwritten
//role type will always be set based on particular form
public String getRoleType(VitroRequest vreq) {
//TODO: Get dynamic way of including vivoweb ontology
return "http://vivoweb.org/ontology/core#ClinicalRole";
}
//Each subclass generator will return its own type of option here:
//whether literal hardcoded, based on class group, or subclasses of a specific class
//The latter two will apparently lend some kind of uri to objectClassUri ?
public RoleActivityOptionTypes getRoleActivityTypeOptionsType(VitroRequest vreq) {
return RoleActivityOptionTypes.HARDCODED_LITERALS;
}
//This too will depend on the specific subclass of generator
public String getRoleActivityTypeObjectClassUri(VitroRequest vreq) {
return null;
}
//Clinical role involves hard-coded options for the "right side" of the role or activity
protected HashMap<String, String> getRoleActivityTypeLiteralOptions(VitroRequest vreq) {
HashMap<String, String> literalOptions = new HashMap<String, String>();
literalOptions.put("", "Select one");
literalOptions.put("http://vivoweb.org/ontology/core#Project", "Project");
literalOptions.put("http://vivoweb.org/ontology/core#Service","Service");
return literalOptions;
}
//isShowRoleLabelField remains true for this so doesn't need to be overwritten
}

View file

@ -0,0 +1,168 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.vocabulary.XSD;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.shared.Lock;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmission;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
import org.vivoweb.webapp.util.ModelUtils;
public class RoleToActivityPredicatePreprocessor implements ModelChangePreprocessor {
private static final Log log = LogFactory.getLog(CreateLabelFromNameFields.class.getName());
public RoleToActivityPredicatePreprocessor() {
super();
}
public void preprocess(Model retractionsModel, Model additionsModel, HttpServletRequest request) {
//Query for all statements using the original roleIn predicate replace
//with the appropriate roleRealizedIn or roleContributesTo
//In addition, need to ensure the inverse predicate is also set correctly
try {
VitroRequest vreq = new VitroRequest(request);
WebappDaoFactory wadf = vreq.getWebappDaoFactory();
replacePredicates(retractionsModel, wadf);
replacePredicates(additionsModel, wadf);
} catch (Exception e) {
log.error("Error retrieving name values from edit submission.");
}
}
private void replacePredicates(Model inputModel, WebappDaoFactory wadf) {
executeQueryAndReplace(inputModel, wadf);
}
private void executeQueryAndReplace(Model inputModel, WebappDaoFactory wadf) {
String queryString= getRoleAndActivityQuery();
Query query = QueryFactory.create(queryString);
QueryExecution qe = QueryExecutionFactory.create(query, inputModel);
ResultSet rs = qe.execSelect();
while(rs.hasNext()) {
QuerySolution qs = rs.nextSolution();
Resource role = null, activity = null, mostSpecificType = null;
role = getResourceFromSolution(qs, "role");
activity = getResourceFromSolution(qs, "activity");
mostSpecificType = getResourceFromSolution(qs, "mostSpecificType");
//Within the input model, replace predicate linking role and activity and vice versa
//based on the most specific type of the activity
replacePredicatesForRoleAndActivity(inputModel, role, activity, mostSpecificType, wadf);
}
}
private void replacePredicatesForRoleAndActivity(Model inputModel,
Resource role, Resource activity, Resource mostSpecificType,
WebappDaoFactory wadf) {
Property roleToActivityPredicate = ResourceFactory.createProperty(getGenericRoleToActivityPredicate());
Property activityToRolePredicate = ResourceFactory.createProperty(getGenericActivityToRolePredicate());
if(role != null && activity != null && mostSpecificType != null) {
ObjectProperty newRoleToActivityProperty = getCorrectProperty(mostSpecificType.getURI(), wadf);
String propertyURI = newRoleToActivityProperty.getURI();
String inversePropertyURI = newRoleToActivityProperty.getURIInverse();
//Remove all the old statements connecting role and activity
inputModel.enterCriticalSection(Lock.WRITE);
try {
Model removeRoleToActivityModel = ModelFactory.createDefaultModel();
removeRoleToActivityModel.add(inputModel.listStatements(
role,
roleToActivityPredicate,
activity));
Model removeActivityToRoleModel = ModelFactory.createDefaultModel();
removeActivityToRoleModel.add(inputModel.listStatements(
activity,
activityToRolePredicate,
role));
//Add statements
inputModel.add(inputModel.createStatement(
role,
ResourceFactory.createProperty(propertyURI),
activity));
inputModel.add(inputModel.createStatement(
activity,
ResourceFactory.createProperty(inversePropertyURI),
role));
//Remove all roleToActivityPredicates and replace with the new predicate
inputModel.remove(removeRoleToActivityModel);
//Remove all activity to role predicates and replace with new predicate
inputModel.remove(removeActivityToRoleModel);
} catch(Exception ex) {
log.error("Exception occurred in replacing predicates in model ", ex);
} finally {
inputModel.leaveCriticalSection();
}
}
}
private ObjectProperty getCorrectProperty(String uri, WebappDaoFactory wadf) {
//ObjectProperty correctProperty = ModelUtils.getPropertyForRoleInClass(uri, wadf);
ObjectProperty op = new ObjectProperty();
op.setURI( "http://vivoweb.org/ontology/core#roleRealizedIn");
op.setURIInverse("http://vivoweb.org/ontology/core#realizedRole");
return op;
}
private String getRoleAndActivityQuery() {
String roleToActivityPredicate = getGenericRoleToActivityPredicate();
String query = "PREFIX core: <http://vivoweb.org/ontology/core#>" +
"SELECT ?role ?activity ?mostSpecificType WHERE { ?role <" + roleToActivityPredicate + "> ?activity . \n" +
"?activity <" + VitroVocabulary.RDF_TYPE + "> ?mostSpecificType. \n" +
"}";
return query;
}
private Resource getResourceFromSolution(QuerySolution qs, String variableName) {
Resource resource = null;
if(qs.get(variableName) != null && qs.get(variableName).isResource()) {
resource = qs.getResource(variableName);
}
return resource;
}
//Values used in the forms
private static String getGenericRoleToActivityPredicate() {
return "http://vivoweb.org/ontology/core#roleIn";
}
private static String getGenericActivityToRolePredicate() {
return "http://vivoweb.org/ontology/core#relatedRole";
}
}

View file

@ -19,10 +19,10 @@ public class ModelUtils {
private static final Log log = LogFactory.getLog(ModelUtils.class.getName());
private static final String processPropertyURI = "http://vivoweb.org/ontology/core#roleRealizedIn";
private static final String processPropertyInverseURI = "http://vivoweb.org/ontology/core#realizedRole";
private static final String nonProcessPropertyURI = "http://vivoweb.org/ontology/core#roleContributesTo";
private static final String nonProcessPropertyInverseURI = "http://vivoweb.org/ontology/core#ContributingRole";
public static final String processPropertyURI = "http://vivoweb.org/ontology/core#roleRealizedIn";
public static final String processPropertyInverseURI = "http://vivoweb.org/ontology/core#realizedRole";
public static final String nonProcessPropertyURI = "http://vivoweb.org/ontology/core#roleContributesTo";
public static final String nonProcessPropertyInverseURI = "http://vivoweb.org/ontology/core#ContributingRole";
private static Set<String> processClass = new HashSet<String>();
static {