updates to associated concept and user defined concept generators, related preprocessors, css, and javascript file
This commit is contained in:
parent
c3d1d16d9b
commit
b54b8c566d
8 changed files with 645 additions and 107 deletions
|
@ -1,29 +1,29 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
.terminology .column {
|
||||
.concepts .column {
|
||||
float:left;
|
||||
padding-right:3px;
|
||||
|
||||
}
|
||||
|
||||
.terminology .row {
|
||||
.concepts .row {
|
||||
clear:both;
|
||||
float:left;
|
||||
border-bottom: 1px solid #5F6464;
|
||||
}
|
||||
|
||||
.termLabel {
|
||||
.conceptLabel {
|
||||
width:220px;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
.termType {
|
||||
.conceptType {
|
||||
width: 40px;
|
||||
}
|
||||
.termDefinition{
|
||||
.conceptDefinition{
|
||||
width:400px;
|
||||
}
|
||||
|
||||
form#addTerminologyForm {
|
||||
form#addConceptForm {
|
||||
display:none;
|
||||
}
|
268
productMods/edit/forms/js/addConcept.js
Normal file
268
productMods/edit/forms/js/addConcept.js
Normal file
|
@ -0,0 +1,268 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
var addConceptForm = {
|
||||
|
||||
/* *** Initial page setup *** */
|
||||
|
||||
onLoad: function() {
|
||||
|
||||
if (this.disableFormInUnsupportedBrowsers()) {
|
||||
return;
|
||||
}
|
||||
this.mixIn();
|
||||
this.initObjects();
|
||||
this.initPage();
|
||||
},
|
||||
|
||||
disableFormInUnsupportedBrowsers: function() {
|
||||
var disableWrapper = $('#ie67DisableWrapper');
|
||||
|
||||
// Check for unsupported browsers only if the element exists on the page
|
||||
if (disableWrapper.length) {
|
||||
if (vitro.browserUtils.isIELessThan8()) {
|
||||
disableWrapper.show();
|
||||
$('.noIE67').hide();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
mixIn: function() {
|
||||
// Mix in the custom form utility methods
|
||||
$.extend(this, vitro.customFormUtils);
|
||||
// Get the custom form data from the page
|
||||
$.extend(this, customFormData);
|
||||
},
|
||||
// On page load, create references for easy access to form elements.
|
||||
initObjects: function() {
|
||||
|
||||
this.form = $('#addConceptForm');
|
||||
this.showFormButtonWrapper = $('#showAddForm');
|
||||
this.submit = this.form.find(':submit');
|
||||
this.cancel = this.form.find('.cancel');
|
||||
//Add term
|
||||
this.addConceptButton = $('#showAddFormButton');
|
||||
//section where results should be displayed
|
||||
this.selectedConcept = $('#selectedConcept');
|
||||
//input for search term form
|
||||
this.searchTerm = $('#searchTerm');
|
||||
this.searchSubmit = $('#searchButton');
|
||||
this.vocabSource = $('#source');
|
||||
//Hidden inputs for eventual submission
|
||||
this.externalConceptURI = $('#conceptNode');
|
||||
this.externalConceptLabel = $('#conceptLabel');
|
||||
this.externalConceptSource = $('#conceptSource');
|
||||
//remove links
|
||||
this.removeTermLinks = $('a.remove');
|
||||
this.errors = $('#errors');
|
||||
},
|
||||
|
||||
initPage: function() {
|
||||
this.initConceptData();
|
||||
this.bindEventListeners();
|
||||
|
||||
},
|
||||
bindEventListeners: function() {
|
||||
this.searchSubmit.click(function() {
|
||||
addConceptForm.submitSearchTerm();
|
||||
addConceptForm.clearErrors();
|
||||
return false;
|
||||
});
|
||||
|
||||
this.form.submit(function() {
|
||||
return addConceptForm.prepareSubmit();
|
||||
});
|
||||
|
||||
this.addTermButton.click(function() {
|
||||
addConceptForm.initForm();
|
||||
|
||||
});
|
||||
this.removeConceptLinks.click(function() {
|
||||
addConceptForm.removeExistingConcept(this);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
initForm: function() {
|
||||
// Hide the button that shows the form
|
||||
this.showFormButtonWrapper.hide();
|
||||
this.clearSearchResults();
|
||||
|
||||
this.cancel.unbind('click');
|
||||
this.cancel.bind('click', function() {
|
||||
//show only list of existing terms and hide adding term form
|
||||
addConceptForm.showConceptListOnlyView();
|
||||
return false;
|
||||
});
|
||||
|
||||
// Show the form
|
||||
this.form.show();
|
||||
},
|
||||
// On page load, associate data with each existing term element. Then we don't
|
||||
// have to keep retrieving data from or modifying the DOM as we manipulate the
|
||||
// authorships.
|
||||
initConceptData: function() {
|
||||
$('.existingConcept').each(function(index) {
|
||||
$(this).data(existingConceptsData[index]);
|
||||
$(this).data('position', index+1);
|
||||
});
|
||||
},
|
||||
clearSearchResults:function() {
|
||||
$('#selectedConcept').empty();
|
||||
},
|
||||
clearErrors:function() {
|
||||
addConceptForm.errors.empty();
|
||||
},
|
||||
showConceptListOnlyView: function() {
|
||||
this.hideForm();
|
||||
this.showFormButtonWrapper.show();
|
||||
},
|
||||
submitSearchTerm: function() {
|
||||
//Get value of search term
|
||||
var searchValue = this.searchTerm.val();
|
||||
this.entryTerm.val(searchValue);
|
||||
var dataServiceUrl = addConceptForm.dataServiceUrl + "?searchTerm=" + encodeURIComponent(searchValue);
|
||||
$.getJSON(dataServiceUrl, function(results) {
|
||||
if ( results.array.length == 0 ) {
|
||||
alert("results not correct length");
|
||||
} else {
|
||||
//array is an array of objects representing concept information
|
||||
//loop through and find all the best matches
|
||||
|
||||
var bestMatchResults = addConceptForm.parseResults(results.array);
|
||||
var numberMatches = bestMatchResults.length;
|
||||
var i;
|
||||
//For each result, display
|
||||
var htmlAdd = "";
|
||||
if(numberMatches > 0) {
|
||||
htmlAdd = "<ul class='dd' id='concepts' name='concepts'>";
|
||||
htmlAdd+= addConceptForm.addResultsHeader();
|
||||
for(i = 0; i < numberMatches; i++) {
|
||||
var conceptResult = bestMatchResults[i];
|
||||
var conceptId = conceptResult.conceptId;
|
||||
var label = conceptResult.label;
|
||||
var definition = conceptResult.definition;
|
||||
var definedBy = conceptResult.definedBy;
|
||||
var type = conceptResult.type;
|
||||
var uri = conceptResult.uri;
|
||||
htmlAdd+= addConceptForm.generateIndividualTermDisplay(uri, label, definition, type, definedBy);
|
||||
}
|
||||
htmlAdd+= "</ul>";
|
||||
} else {
|
||||
htmlAdd+= "<p>No search results found.</p>";
|
||||
}
|
||||
$('#selectedConcept').html(htmlAdd);
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
parseResults:function(resultsArray) {
|
||||
//Loop through array and check if this is the best match
|
||||
var arrayLen = resultsArray.length;
|
||||
var bestMatchResults = new Array();
|
||||
var i;
|
||||
for(i = 0; i < arrayLen; i++) {
|
||||
var concept = resultsArray[i];
|
||||
if(concept.bestMatch == "true") {
|
||||
bestMatchResults.push(concept);
|
||||
}
|
||||
}
|
||||
return bestMatchResults;
|
||||
},
|
||||
addResultsHeader:function() {
|
||||
var htmlAdd = "<li class='terminology'><div class='row'><span class='column conceptLabel'>Label (Type) </span><span class='column conceptDefinition'>Definition</span></div></li>";
|
||||
return htmlAdd;
|
||||
},
|
||||
hideSearchResults:function() {
|
||||
this.selectedConcept.hide();
|
||||
},
|
||||
prepareSubmit:function() {
|
||||
var checkedElements = $("#CUI:checked");
|
||||
if(!addConceptForm.validateConceptSelection(checkedElements)) {
|
||||
return false;
|
||||
}
|
||||
var i;
|
||||
var len = checkedElements.length;
|
||||
var checkedConcept, checkedConceptElement, conceptLabel, conceptSource;
|
||||
var conceptNodes = [];
|
||||
var conceptLabels = [];
|
||||
var conceptSources = [];
|
||||
|
||||
checkedElements.each(function() {
|
||||
checkedConceptElement = $(this);
|
||||
checkedConcept = checkedTermElement.val();
|
||||
conceptLabel = checkedConceptElement.attr("label");
|
||||
conceptSource = checkedConceptElement.attr("conceptDefinedBy");
|
||||
conceptNodes.push(checkedConcept);
|
||||
conceptLabels.push(termLabel);
|
||||
conceptSources.push(conceptSource);
|
||||
});
|
||||
this.externalConceptURI.val(conceptNodes);
|
||||
this.externalConceptLabel.val(conceptLabels);
|
||||
this.externalConceptSource.val(conceptSources);
|
||||
return true;
|
||||
},
|
||||
generateIndividualTermDisplay: function(cuiURI, label, definition, type, definedBy) {
|
||||
var htmlAdd = "<li class='concepts'>" +
|
||||
"<div class='row'>" +
|
||||
"<span class='column conceptLabel'>" +
|
||||
"<input type='checkbox' id='CUI' name='CUI' value='" + cuiURI + "' label='" + label + "' conceptType='" + type + "' conceptDefinedBy='" + definedBy + "'/>" +
|
||||
label + " (" + type + ")</span>" +
|
||||
"<span class='column conceptDefinition'>" + definition + "</span>" +
|
||||
"</div>" +
|
||||
"</li>";
|
||||
return htmlAdd;
|
||||
}, validateConceptSelection:function(checkedElements) {
|
||||
var numberElements = checkedElements.length;
|
||||
if(numberElements < 1) {
|
||||
addConceptForm.errors.html("<p class='validationError'>Please select at least one term from search results to add or click cancel.</p>");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}, removeExistingConcept: function(link) {
|
||||
var removeLast = false,
|
||||
message = 'Are you sure you want to remove this term?';
|
||||
|
||||
if (!confirm(message)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($(link)[0] === $('.remove:last')[0]) {
|
||||
removeLast = true;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: $(link).attr('href'),
|
||||
type: 'POST',
|
||||
data: {
|
||||
deletion: $(link).parents('.existingConcept').data('conceptNodeUri')
|
||||
},
|
||||
dataType: 'json',
|
||||
context: link, // context for callback
|
||||
complete: function(request, status) {
|
||||
var existingConcept,
|
||||
conceptNodeUri;
|
||||
|
||||
if (status === 'success') {
|
||||
|
||||
existingConcept = $(this).parents('.existingConcept');
|
||||
existingConcept.fadeOut(400, function() {
|
||||
var numConcepts;
|
||||
// For undo link: add to a deletedAuthorships array
|
||||
// Remove from the DOM
|
||||
$(this).remove();
|
||||
// Actions that depend on the author having been removed from the DOM:
|
||||
numConcepts = $('.existingConcept').length; // retrieve the length after removing authorship from the DOM
|
||||
});
|
||||
|
||||
} else {
|
||||
alert('Error processing request: term not removed');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
addConceptForm.onLoad();
|
||||
});
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
<%@ page import="com.hp.hpl.jena.rdf.model.Model" %>
|
||||
<%@ page import="com.hp.hpl.jena.vocabulary.XSD" %>
|
||||
<%@ page import="com.hp.hpl.jena.vocabulary.RDFS" %>
|
||||
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyComparator" %>
|
||||
|
@ -219,12 +220,12 @@ SPARQL queries for existing values. --%>
|
|||
for ( Individual termNode : terminologyAnnotationNodes ) {
|
||||
request.setAttribute("termNodeUri", termNode.getURI());
|
||||
//Get label and type only as mirroring authorship where labels but no links for individuals incoldued
|
||||
DataPropertyStatement termLabelStatement = termNode.getDataPropertyStatement(termLabelUri);
|
||||
DataPropertyStatement termLabelStatement = termNode.getDataPropertyStatement(RDFS.label.getURI());
|
||||
String termLabel = termLabelStatement.getData();
|
||||
request.setAttribute("termLabel", termLabel);
|
||||
DataPropertyStatement termTypeStatement = termNode.getDataPropertyStatement(termTypeUri);
|
||||
String termType = termTypeStatement.getData();
|
||||
request.setAttribute("termType", termType);
|
||||
//request.setAttribute("termLabel", termLabel);
|
||||
//DataPropertyStatement termTypeStatement = termNode.getDataPropertyStatement(termTypeUri);
|
||||
//String termType = termTypeStatement.getData();
|
||||
request.setAttribute("termType", "fake");
|
||||
%>
|
||||
<li class="existingTerm">
|
||||
<%-- span.author will be used in the next phase, when we display a message that the author has been
|
||||
|
|
|
@ -37,20 +37,22 @@
|
|||
|
||||
|
||||
|
||||
<ul id="existingTerms" >
|
||||
<ul id="existingConcepts" >
|
||||
|
||||
<script type="text/javascript">
|
||||
var existingTermsData = [];
|
||||
var existingConceptsData = [];
|
||||
</script>
|
||||
|
||||
<#list existingConcepts as existingConcept>
|
||||
<li class="existingTerm">
|
||||
<li class="existingConcept">
|
||||
|
||||
<span class="term">
|
||||
<span class="concept">
|
||||
|
||||
<span class="termWrapper">
|
||||
<span class="termLabel">
|
||||
${existingConcept.conceptLabel}
|
||||
<span class="conceptWrapper">
|
||||
<span class="conceptLabel"> ${existingConcept.conceptLabel}
|
||||
<#if existingConcept.vocabURI?has_content && existingConcept.vocabLabel?has_content>
|
||||
(${existingConcept.vocabLabel})
|
||||
</#if>
|
||||
</span>
|
||||
</span>
|
||||
<a href="${urls.base}/edit/primitiveDelete" class="remove">Remove</a>
|
||||
|
@ -58,7 +60,7 @@
|
|||
</li>
|
||||
|
||||
<script type="text/javascript">
|
||||
existingTermsData.push({
|
||||
existingConceptsData.push({
|
||||
"conceptNodeUri": "${existingConcept.conceptURI}",
|
||||
"conceptLabel": "${existingConcept.conceptLabel}"
|
||||
});
|
||||
|
@ -74,25 +76,26 @@
|
|||
</#if>
|
||||
|
||||
<div id="showAddForm">
|
||||
<input type="submit" value="Add Term" id="showAddFormButton" name="showAddFormButton"> or
|
||||
<input type="submit" value="Add Concept" id="showAddFormButton" name="showAddFormButton"> or
|
||||
<a class="cancel" href="${cancelUrl}">Return</a>
|
||||
</div>
|
||||
<form id="addTerminologyForm" class="customForm" action="${urls.base}/edit/processTerminologyAnnotation">
|
||||
<form id="addConceptForm" class="customForm" action="${submitUrl}">
|
||||
|
||||
<#list sources as source>
|
||||
<input type="radio" name="source" value="${source.uri}" role="radio" <#if selectedSource = source.uri>checked</#if> />
|
||||
<input type="radio" id="source" name="source" value="${source.uri}" role="radio" <#if selectedSource = source.uri>checked</#if> />
|
||||
<label class="inline" for="${source.label}"> ${source.label}</label>
|
||||
<br />
|
||||
</#list>
|
||||
|
||||
<p class="inline">
|
||||
<input type="text" id="searchTerm" label="Search UMLS Terms" class="acSelector" size="35" />
|
||||
<input type="text" id="searchTerm" label="Search" class="acSelector" size="35" />
|
||||
<input type="button" id="searchButton" name="searchButton" value="Search"/>
|
||||
</p>
|
||||
<input type="hidden" id="externalConceptURI" name="externalConceptURI" value=""/> <!-- Field value populated by JavaScript -->
|
||||
<input type="hidden" id="externalConceptLabel" name="externalConceptLabel" value="" /> <!-- Field value populated by JavaScript -->
|
||||
|
||||
<div id="selectedTerm" name="selectedTerm" class="acSelection">
|
||||
<input type="hidden" id="conceptNode" name="conceptNode" value=""/> <!-- Field value populated by JavaScript -->
|
||||
<input type="hidden" id="ConceptLabel" name="conceptLabel" value="" /> <!-- Field value populated by JavaScript -->
|
||||
<!--TODO: Change this so this is populated by the javascript-->
|
||||
<input type="hidden" id="conceptSource" name="conceptSource" value="" /> <!-- Field value populated by JavaScript -->
|
||||
<div id="selectedConcept" name="selectedConcept" class="acSelection">
|
||||
<%-- RY maybe make this a label and input field. See what looks best. --%>
|
||||
<p class="inline">
|
||||
</p>
|
||||
|
@ -118,8 +121,12 @@
|
|||
};
|
||||
</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" />')}
|
||||
|
||||
${scripts.add('<script type="text/javascript" src="${urls.base}/edit/forms/js/addTerminology.js"></script>')}
|
||||
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/edit/forms/css/addConcept.css" />')}
|
||||
|
||||
${scripts.add('<script type="text/javascript" src="${urls.base}/edit/forms/js/addConcept.js"></script>')}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -11,13 +11,12 @@
|
|||
<h2>Add Your Own Concept</h2>
|
||||
|
||||
|
||||
<form id="addUserDefinedConceptForm" class="editForm" action = "${submitUrl}" method="post">
|
||||
<form id="addUserDefinedConceptForm" class="customForm noIE67" action = "${submitUrl}" method="post">
|
||||
<input type="hidden" name="editKey" id="editKey" value="${editKey}" role="input" />
|
||||
<#--Autocomplete for looking up existing skos concepts -->
|
||||
<p>
|
||||
<p>
|
||||
<label for="relatedIndLabel">Concept <span class='requiredHint'> *</span></label>
|
||||
<input class="acSelector" size="50" type="text" id="relatedIndLabel" name="conceptLabel"
|
||||
<#if (disabledVal?length > 0)>disabled="${disabledVal}"</#if> value="" />
|
||||
<input class="acSelector" size="50" type="text" id="relatedIndLabel" name="conceptLabel" value="" />
|
||||
</p>
|
||||
|
||||
<div class="acSelection">
|
||||
|
@ -42,13 +41,14 @@
|
|||
|
||||
</form>
|
||||
|
||||
<#assign sparqlQueryUrl = "/ajax/sparqlQuery" >
|
||||
<#assign sparqlQueryUrl = "${urls.base}/ajax/sparqlQuery" >
|
||||
|
||||
<script type="text/javascript">
|
||||
var customFormData = {
|
||||
sparqlForAcFilter: '${sparqlForAcFilter}',
|
||||
sparqlQueryUrl: '${sparqlQueryUrl}',
|
||||
acUrl: '${urls.base}/autocomplete?tokenize=true',
|
||||
acType: 'http://www.w3.org/2004/02/skos/core#Concept',
|
||||
submitButtonTextType: 'simple',
|
||||
editMode: 'add',
|
||||
defaultTypeName: 'concept' // used in repair mode to generate button text
|
||||
|
|
|
@ -41,6 +41,7 @@ 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.configuration.preprocessors.AddAssociatedConceptsPreprocessor;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.RoleToActivityPredicatePreprocessor;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditN3GeneratorVTwo;
|
||||
|
@ -147,20 +148,20 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
return "@prefix core: <http://vivoweb.org/ontology/core#> .";
|
||||
}
|
||||
|
||||
//TODO: Check if single string or multiple strings - check rdfslabel form etc. for prefix
|
||||
//processing
|
||||
//The only string always required is that linking the subject to the concept node
|
||||
//Since the concept node from an external vocabulary may already be in the system
|
||||
//The label and is defined by may already be defined and don't require re-saving
|
||||
private List<String> generateN3Required(VitroRequest vreq) {
|
||||
return list(
|
||||
getPrefixesString() + "\n" +
|
||||
"?subject ?predicate ?conceptNode .\n" +
|
||||
"?conceptNode <" + RDFS.label.getURI() + "> ?conceptLabel .\n" +
|
||||
"?conceptNode <" + RDFS.isDefinedBy.getURI() + "> ?vocabURI ."
|
||||
"?subject ?predicate ?conceptNode .\n"
|
||||
);
|
||||
}
|
||||
|
||||
//Don't think there's any n3 optional here
|
||||
private List<String> generateN3Optional() {
|
||||
return list(
|
||||
return list("?conceptNode <" + RDFS.label.getURI() + "> ?conceptLabel .\n" +
|
||||
"?conceptNode <" + RDFS.isDefinedBy.getURI() + "> ?conceptSource ."
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -220,8 +221,8 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
List<String> urisOnForm = new ArrayList<String>();
|
||||
List<String> literalsOnForm = new ArrayList<String>();
|
||||
//The URI of the node that defines the concept
|
||||
urisOnForm.add("conceptURI");
|
||||
urisOnForm.add("vocabURI");
|
||||
urisOnForm.add("conceptNode");
|
||||
urisOnForm.add("conceptSource");
|
||||
//Also need to add the label of the concept
|
||||
literalsOnForm.add("conceptLabel");
|
||||
editConfiguration.setLiteralsOnForm(literalsOnForm);
|
||||
|
@ -236,54 +237,12 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
private void setSparqlQueries(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
//Sparql queries defining retrieval of literals etc.
|
||||
editConfiguration.setSparqlForAdditionalLiteralsInScope(new HashMap<String, String>());
|
||||
|
||||
Map<String, String> urisInScope = new HashMap<String, String>();
|
||||
editConfiguration.setSparqlForAdditionalUrisInScope(urisInScope);
|
||||
|
||||
editConfiguration.setSparqlForExistingLiterals(generateSparqlForExistingLiterals(vreq));
|
||||
editConfiguration.setSparqlForExistingUris(generateSparqlForExistingUris(vreq));
|
||||
editConfiguration.setSparqlForAdditionalUrisInScope(new HashMap<String, String>());
|
||||
editConfiguration.setSparqlForExistingLiterals(new HashMap<String, String>());
|
||||
editConfiguration.setSparqlForExistingUris(new HashMap<String, String>());
|
||||
}
|
||||
|
||||
|
||||
//Get page uri for object
|
||||
private HashMap<String, String> generateSparqlForExistingUris(VitroRequest vreq) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
//Existing uris here might include is defined by
|
||||
//map.put("vocabURI", getExistingVocabURIQuery());
|
||||
return map;
|
||||
}
|
||||
|
||||
private String getExistingVocabURIQuery() {
|
||||
String query = "SELECT ?existingVocabURI \n " +
|
||||
"WHERE { \n" +
|
||||
"?conceptNode <" + RDFS.isDefinedBy.getURI() + "> ?existingVocabURI ."
|
||||
+ "}";
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private HashMap<String, String> generateSparqlForExistingLiterals(VitroRequest vreq) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
//Queries for existing concept label
|
||||
//Vocab uri label is something that can be retrieved
|
||||
map.put("conceptLabel", getConceptLabelQuery());
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String getConceptLabelQuery() {
|
||||
String query = "SELECT ?existingConceptLabel \n " +
|
||||
"WHERE { \n" +
|
||||
"?conceptNode <" + RDFS.label.getURI() + "> ?existingConceptLabel ."
|
||||
+ "}";
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Set Fields and supporting methods
|
||||
|
@ -300,7 +259,7 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
VitroRequest vreq) {
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName("conceptNode").
|
||||
setValidators(new ArrayList<String>()).
|
||||
setValidators(list("nonempty")).
|
||||
setOptionsType("UNDEFINED"));
|
||||
|
||||
}
|
||||
|
@ -310,9 +269,7 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
private void setVocabURIField(EditConfigurationVTwo editConfiguration,
|
||||
VitroRequest vreq) {
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName("vocabURI").
|
||||
setValidators(new ArrayList<String>()).
|
||||
setOptionsType("UNDEFINED"));
|
||||
setName("conceptSource"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -321,27 +278,19 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
VitroRequest vreq) {
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName("conceptLabel").
|
||||
setValidators(new ArrayList<String>()).
|
||||
setOptionsType("UNDEFINED").
|
||||
setRangeDatatypeUri(XSD.xstring.toString())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Add preprocessor
|
||||
|
||||
private void addPreprocessors(EditConfigurationVTwo editConfiguration, WebappDaoFactory wadf) {
|
||||
//Will be a completely different type of preprocessor
|
||||
/*
|
||||
//An Edit submission preprocessor for enabling addition of multiple terms for a single search
|
||||
|
||||
editConfiguration.addEditSubmissionPreprocessor(
|
||||
new RoleToActivityPredicatePreprocessor(editConfiguration, wadf));
|
||||
*/
|
||||
new AddAssociatedConceptsPreprocessor(editConfiguration));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -351,9 +300,10 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
//Existing concepts should probably be a hash map or a hash map of classes
|
||||
//with URI of concept node to label and information about existing URI
|
||||
//This would be a sparql query and would need to be run here?
|
||||
//For test purposes
|
||||
//-------------------->For test purposes
|
||||
List<AssociatedConceptInfo> testInfo = new ArrayList<AssociatedConceptInfo>();
|
||||
testInfo.add(new AssociatedConceptInfo("testLabel", "testURI", "testVocabURI", "testVocabLabel"));
|
||||
testInfo.add(new AssociatedConceptInfo("testLabel", "testURI", "testVocabURI", "testVocabLabel", null));
|
||||
testInfo.add(new AssociatedConceptInfo("user defined label", "testUserURI", null, null, "http://www.w3.org/2004/02/skos/core#Concept"));
|
||||
formSpecificData.put("existingConcepts", testInfo);
|
||||
//Return url for adding user defined concept
|
||||
formSpecificData.put("userDefinedConceptUrl", getUserDefinedConceptUrl(vreq));
|
||||
|
@ -376,11 +326,13 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
private String conceptURI;
|
||||
private String vocabURI;
|
||||
private String vocabLabel;
|
||||
public AssociatedConceptInfo(String inputLabel, String inputURI, String inputVocabURI, String inputVocabLabel) {
|
||||
private String type; //In case of SKOS concept, will have skos concept type
|
||||
public AssociatedConceptInfo(String inputLabel, String inputURI, String inputVocabURI, String inputVocabLabel, String inputType) {
|
||||
this.conceptLabel = inputLabel;
|
||||
this.conceptURI = inputURI;
|
||||
this.vocabURI = inputVocabURI;
|
||||
this.vocabLabel = inputVocabLabel;
|
||||
this.type = inputType;
|
||||
}
|
||||
|
||||
//Getters
|
||||
|
@ -400,6 +352,10 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
return vocabLabel;
|
||||
}
|
||||
|
||||
public String getType(){
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -292,16 +292,17 @@ public class AddUserDefinedConceptGenerator extends VivoBaseGenerator implement
|
|||
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
|
||||
formSpecificData.put("sparqlForAcFilter", getSparqlForAcFilter(vreq));
|
||||
formSpecificData.put("conceptType", SKOSConceptType);
|
||||
editConfiguration.setFormSpecificData(formSpecificData);
|
||||
}
|
||||
|
||||
|
||||
public String getSparqlForAcFilter(VitroRequest vreq) {
|
||||
String subject = EditConfigurationUtils.getSubjectUri(vreq);
|
||||
|
||||
String predicate = EditConfigurationUtils.getPredicateUri(vreq);
|
||||
String query = "PREFIX core:<" + vivoCore + "> " +
|
||||
"SELECT ?conceptNode WHERE { " +
|
||||
"<" + subject + "> ?predicate ?conceptNode ." +
|
||||
"<" + subject + "> <" + predicate + "> ?conceptNode ." +
|
||||
"?conceptNode <" + VitroVocabulary.RDF_TYPE + "> <" + SKOSConceptType + "> . }";
|
||||
return query;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,305 @@
|
|||
/* $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.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||
import com.hp.hpl.jena.vocabulary.XSD;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.BaseEditSubmissionPreprocessorVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmission;
|
||||
|
||||
public class AddAssociatedConceptsPreprocessor extends
|
||||
BaseEditSubmissionPreprocessorVTwo {
|
||||
|
||||
protected static final Log log = LogFactory
|
||||
.getLog(AddAssociatedConceptsPreprocessor.class.getName());
|
||||
|
||||
// Field names/variables names for n3 - these will have numbers added as
|
||||
// suffix if more than one term
|
||||
private static String conceptNodeBase = "conceptNode";
|
||||
private static String sourceBase = "conceptSource";
|
||||
private static String labelBase = "conceptLabel";
|
||||
//Also storing submission
|
||||
private static MultiValueEditSubmission submission = null;
|
||||
|
||||
// String datatype
|
||||
|
||||
// Will be editing the edit configuration as well as edit submission here
|
||||
|
||||
public AddAssociatedConceptsPreprocessor(EditConfigurationVTwo editConfig) {
|
||||
super(editConfig);
|
||||
}
|
||||
|
||||
public void preprocess(MultiValueEditSubmission inputSubmission) {
|
||||
submission = inputSubmission;
|
||||
// Get the input elements for concept node and concept label as well
|
||||
// as vocab uri (which is based on thge
|
||||
// For query parameters, check whether CUI
|
||||
String conceptNodeValues = getConceptNodeValues();
|
||||
|
||||
if (conceptNodeValues != null) {
|
||||
String[] conceptNodes = convertDelimitedStringToArray(conceptNodeValues);
|
||||
int numberConcepts = conceptNodes.length;
|
||||
if (numberConcepts > 1) {
|
||||
processConceptNodes(numberConcepts);
|
||||
}
|
||||
|
||||
} else {
|
||||
log.error("No concept nodes were added from the service");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void processConceptNodes(int numberConcepts) {
|
||||
//There are no "new" resources b/c the concept nodes are URIs from external vocabularies
|
||||
// Add N3Required
|
||||
addN3Required(numberConcepts);
|
||||
// Add URIs on Form and Add Literals On Form
|
||||
addLiteralsAndUrisOnForm(numberConcepts);
|
||||
// Add fields
|
||||
addFields(numberConcepts);
|
||||
//Add input values to submission
|
||||
addInputsToSubmission(numberConcepts);
|
||||
|
||||
}
|
||||
|
||||
//This is where the actual values will be submitted as if they were separate input fields
|
||||
//Each field name will correspond to the names of the fileds/uris on form/literals on form
|
||||
//generated here
|
||||
|
||||
private void addInputsToSubmission(int numberConcepts) {
|
||||
//This will essentially manufacture a set of query parameters
|
||||
//And will add the appropriate fields to the multivalue submission
|
||||
addConceptNodeInputs(numberConcepts);
|
||||
addConceptSourceInputs(numberConcepts);
|
||||
addConceptLabelInputs(numberConcepts);
|
||||
|
||||
}
|
||||
|
||||
private void addConceptNodeInputs(int numberConcepts) {
|
||||
//Get the current value
|
||||
String conceptNodeValues = getConceptNodeValues();
|
||||
String[] conceptNodes = convertDelimitedStringToArray(conceptNodeValues);
|
||||
if(conceptNodes != null && conceptNodes.length == numberConcepts) {
|
||||
int i;
|
||||
for(i = 1; i <= numberConcepts; i++) {
|
||||
int suffix = i;
|
||||
String conceptInputName = conceptNodeBase + suffix;
|
||||
String[] nodeValues = new String[1];
|
||||
nodeValues[0] = conceptNodes[i];
|
||||
//Add value for uri to form
|
||||
submission.addUriToForm(editConfiguration, conceptInputName, nodeValues);
|
||||
}
|
||||
} else if(conceptNodes != null && conceptNodes.length != numberConcepts){
|
||||
log.error("Number of concept nodes did not match the number of concepts to be added");
|
||||
} else{
|
||||
log.error("Concept nodes returned were null");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void addConceptSourceInputs(int numberConcepts) {
|
||||
String conceptSourceValues = getConceptSourceValues();
|
||||
String[] conceptSources = convertDelimitedStringToArray(conceptSourceValues);
|
||||
if(conceptSources != null && conceptSources.length == numberConcepts) {
|
||||
int i;
|
||||
for(i = 1; i <= numberConcepts; i++) {
|
||||
int suffix = i;
|
||||
String conceptInputName = sourceBase + suffix;
|
||||
String[] sourceValues = new String[1];
|
||||
sourceValues[0] = conceptSources[i];
|
||||
//Add value for uri to form
|
||||
submission.addUriToForm(editConfiguration, conceptInputName, sourceValues);
|
||||
}
|
||||
} else if(conceptSources != null && conceptSources.length != numberConcepts){
|
||||
log.error("Number of concept nodes did not match the number of concepts to be added");
|
||||
} else{
|
||||
log.error("Concept nodes returned were null");
|
||||
}
|
||||
}
|
||||
|
||||
private void addConceptLabelInputs(int numberConcepts) {
|
||||
String conceptLabelValues = getConceptLabelValues();
|
||||
String[] labels = convertDelimitedStringToArray(conceptLabelValues);
|
||||
if(labels != null && labels.length == numberConcepts) {
|
||||
int i;
|
||||
for(i = 1; i <= numberConcepts; i++) {
|
||||
int suffix = i;
|
||||
String labelInputName = labelBase + suffix;
|
||||
String[] labelValues = new String[1];
|
||||
labelValues[0] = labels[i];
|
||||
//TODO: Check if there are no funky typed information also stored
|
||||
//At this point the field should already have been added to edit configuration
|
||||
FieldVTwo labelField = editConfiguration.getField(labelInputName);
|
||||
if(labelField != null) {
|
||||
submission.addLiteralToForm(editConfiguration, labelField, labelInputName, labelValues);
|
||||
} else {
|
||||
log.error("Corresponding field for " + labelInputName + " was not added to edit configuration");
|
||||
}
|
||||
|
||||
}
|
||||
} else if(labels != null && labels.length != numberConcepts){
|
||||
log.error("Number of concept labels did not match the number of concepts to be added");
|
||||
} else{
|
||||
log.error("Concept labels returned were null");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void addFields(int numberConcepts) {
|
||||
//Clear out all fields in edit configuration first
|
||||
editConfiguration.setFields(new HashMap<String, FieldVTwo>());
|
||||
int index;
|
||||
// First one already included in generator so add additional ones here
|
||||
for (index = 1; index <= numberConcepts; index++) {
|
||||
int suffix = index + 1;
|
||||
String conceptNode = conceptNodeBase + suffix;
|
||||
String label = labelBase + suffix;
|
||||
String source = sourceBase + suffix;
|
||||
|
||||
addConceptNodeField(conceptNode);
|
||||
addLabelField(label);
|
||||
addSourceField(source);
|
||||
}
|
||||
}
|
||||
|
||||
private void addConceptNodeField(String conceptNode) {
|
||||
List<String> validators = new ArrayList<String>();
|
||||
validators.add("nonempty");
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName(conceptNode).
|
||||
setValidators(validators));
|
||||
}
|
||||
|
||||
private void addLabelField(String label) {
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName(label).
|
||||
setRangeDatatypeUri(XSD.xstring.toString())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private void addSourceField(String source) {
|
||||
editConfiguration.addField(new FieldVTwo().
|
||||
setName(source));
|
||||
|
||||
}
|
||||
|
||||
//original literals on form: label, uris on form: conceptNode and conceptSource
|
||||
//This will overwrite the original values in the edit configuration
|
||||
private void addLiteralsAndUrisOnForm(int numberTerms) {
|
||||
List<String> urisOnForm = new ArrayList<String>();
|
||||
List<String> literalsOnForm = new ArrayList<String>();
|
||||
|
||||
int index;
|
||||
|
||||
// First one already included so add new ones here
|
||||
for (index = 1; index <= numberTerms; index++) {
|
||||
int suffix = index;
|
||||
String conceptNode = conceptNodeBase + suffix;
|
||||
String label = labelBase + suffix;
|
||||
String source = sourceBase + suffix;
|
||||
urisOnForm.add(conceptNode);
|
||||
urisOnForm.add(source);
|
||||
literalsOnForm.add(label);
|
||||
}
|
||||
editConfiguration.setUrisOnform(urisOnForm);
|
||||
editConfiguration.setLiteralsOnForm(literalsOnForm);
|
||||
}
|
||||
|
||||
// N3 being reproduced
|
||||
/*
|
||||
* ?subject ?predicate ?conceptNode .
|
||||
*/
|
||||
//This will overwrite the original with the set of new n3 required
|
||||
private void addN3Required(int numberConcepts) {
|
||||
// List<String> n3Required = editConfig.getN3Required();
|
||||
List<String> n3Required = new ArrayList<String>();
|
||||
int index;
|
||||
String nodeBase = "?" + conceptNodeBase;
|
||||
String labelVar = "?" + labelBase;
|
||||
String sourceVar = "?" + sourceBase;
|
||||
String prefixStr = "@prefix core: <http://vivoweb.org/ontology/core#> .";
|
||||
// First one already included so add new ones here
|
||||
for (index = 1; index <= numberConcepts; index++) {
|
||||
int suffix = index;
|
||||
String node = nodeBase + suffix;
|
||||
String n3String = prefixStr;
|
||||
n3String += "?subject ?predicate " + node + " . ";
|
||||
n3Required.add(n3String);
|
||||
}
|
||||
editConfiguration.setN3Required(n3Required);
|
||||
}
|
||||
//Add n3 optional
|
||||
|
||||
private void addN3Optional(int numberConcepts) {
|
||||
List<String> n3Optional = new ArrayList<String>();
|
||||
int index;
|
||||
String nodeBase = "?" + conceptNodeBase;
|
||||
String labelVar = "?" + labelBase;
|
||||
String sourceVar = "?" + sourceBase;
|
||||
String prefixStr = "@prefix core: <http://vivoweb.org/ontology/core#> .";
|
||||
// First one already included so add new ones here
|
||||
for (index = 1; index <= numberConcepts; index++) {
|
||||
int suffix = index;
|
||||
String node = nodeBase + suffix;
|
||||
String label = labelVar + suffix;
|
||||
String source = sourceVar + suffix;
|
||||
String n3String = prefixStr;
|
||||
n3String += node + " <" + RDFS.label.getURI() + "> " + label + " .\n" +
|
||||
node + " <" + RDFS.isDefinedBy.getURI() + "> " + source + " .";
|
||||
n3Optional.add(n3String);
|
||||
}
|
||||
//Already have n3 required so need to add to that
|
||||
|
||||
editConfiguration.setN3Optional(n3Optional);
|
||||
}
|
||||
|
||||
private String[] convertDelimitedStringToArray(String inputString) {
|
||||
String[] inputArray = new String[1];
|
||||
if (inputString.indexOf(",") != -1) {
|
||||
inputArray = inputString.split(",");
|
||||
} else {
|
||||
inputArray[0] = inputString;
|
||||
}
|
||||
return inputArray;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private String getConceptNodeValues() {
|
||||
Map<String, List<String>> urisFromForm = submission.getUrisFromForm();
|
||||
List<String> conceptNodes = urisFromForm.get("conceptNode");
|
||||
return (String) getFirstElement(conceptNodes);
|
||||
}
|
||||
|
||||
private String getConceptSourceValues() {
|
||||
Map<String, List<String>> urisFromForm = submission.getUrisFromForm();
|
||||
return (String) getFirstElement(urisFromForm.get("conceptSource"));
|
||||
}
|
||||
|
||||
private String getConceptLabelValues() {
|
||||
Map<String, List<Literal>> literalsFromForm = submission.getLiteralsFromForm();
|
||||
Map<String, List<String>> transformed = EditConfigurationUtils.transformLiteralMap(literalsFromForm);
|
||||
return (String) getFirstElement(transformed.get("conceptLabel"));
|
||||
|
||||
}
|
||||
|
||||
private Object getFirstElement(List inputList) {
|
||||
if(inputList == null || inputList.size() == 0)
|
||||
return null;
|
||||
return inputList.get(0);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue