NIHVIVO-2452 Remove general process for front-end vitro namespace property editing, and handle rdfs:label as the only exception.
This commit is contained in:
parent
f746534279
commit
3610974111
5 changed files with 38 additions and 46 deletions
|
@ -4,10 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
@ -17,6 +13,11 @@ import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
import com.hp.hpl.jena.rdf.model.Statement;
|
import com.hp.hpl.jena.rdf.model.Statement;
|
||||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
|
|
||||||
public class RdfLiteralHash {
|
public class RdfLiteralHash {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(RdfLiteralHash.class.getName());
|
private static final Log log = LogFactory.getLog(RdfLiteralHash.class.getName());
|
||||||
|
@ -27,7 +28,7 @@ public class RdfLiteralHash {
|
||||||
* @param stmt
|
* @param stmt
|
||||||
* @return a value between MIN_INTEGER and MAX_INTEGER
|
* @return a value between MIN_INTEGER and MAX_INTEGER
|
||||||
*/
|
*/
|
||||||
public static int makeRdfLiteralHash( DataPropertyStatement stmt ){
|
public static int makeRdfLiteralHash( DataPropertyStatement stmt ){
|
||||||
if( (stmt.getLanguage() != null && stmt.getLanguage().trim().length() > 0)
|
if( (stmt.getLanguage() != null && stmt.getLanguage().trim().length() > 0)
|
||||||
&&
|
&&
|
||||||
(stmt.getDatatypeURI() != null && stmt.getDatatypeURI().trim().length() > 0 ) )
|
(stmt.getDatatypeURI() != null && stmt.getDatatypeURI().trim().length() > 0 ) )
|
||||||
|
@ -76,23 +77,23 @@ public class RdfLiteralHash {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forward to either getDataPropertyStmtByHash or getVitroNsPropByHash, depending on the type of property.
|
* Forward to either getDataPropertyStmtByHash or getRdfsLabelStatementByHash, depending on the property.
|
||||||
* @param ind
|
* @param ind
|
||||||
* @param hash
|
* @param hash
|
||||||
* @param model
|
* @param model
|
||||||
* @param isVitroNsProp
|
|
||||||
* @return a DataPropertyStatement if found or null if not found
|
* @return a DataPropertyStatement if found or null if not found
|
||||||
*/
|
*/
|
||||||
// RY Instead of a code fork here, we should have a method of Individual getAllDataPropertyStatements() which
|
|
||||||
// doesn't filter out the vitro ns property statements. This would also simplify the front end editing of the vitro ns
|
public static DataPropertyStatement getPropertyStmtByHash(Individual ind, String predicateUri, int hash, Model model) {
|
||||||
// properties, because they wouldn't have to be a special case.
|
|
||||||
public static DataPropertyStatement getPropertyStmtByHash(Individual ind, String predicateUri, int hash, Model model, boolean isVitroNsProp) {
|
|
||||||
|
|
||||||
if (ind == null) return null;
|
if (ind == null) return null;
|
||||||
|
|
||||||
DataPropertyStatement dps = isVitroNsProp ? RdfLiteralHash.getVitroNsPropertyStmtByHash(ind, predicateUri, model, hash) :
|
|
||||||
RdfLiteralHash.getDataPropertyStmtByHash(ind, hash);
|
|
||||||
|
|
||||||
|
// RY Instead of a code fork here, we should have a method of Individual getAllDataPropertyStatements() which
|
||||||
|
// doesn't filter out rdfs:label.
|
||||||
|
DataPropertyStatement dps = predicateUri.equals(VitroVocabulary.LABEL)
|
||||||
|
? getRdfsLabelStatementByHash(ind, model, hash)
|
||||||
|
: getDataPropertyStmtByHash(ind, hash);
|
||||||
|
|
||||||
return dps;
|
return dps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,12 +111,14 @@ public class RdfLiteralHash {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param ind, may be null and getDataPropertyStatements() may return null.
|
* @param ind, may be null
|
||||||
* @param hash
|
* @param hash
|
||||||
* @return a DataPropertyStatement if found or null if not found
|
* @return a DataPropertyStatement if found or null if not found
|
||||||
*/
|
*/
|
||||||
public static DataPropertyStatement getVitroNsPropertyStmtByHash(Individual ind, String predicateUri, Model model, int hash) {
|
public static DataPropertyStatement getRdfsLabelStatementByHash(Individual ind, Model model, int hash) {
|
||||||
|
|
||||||
|
String predicateUri = VitroVocabulary.LABEL;
|
||||||
|
|
||||||
DataPropertyStatement dps = null;
|
DataPropertyStatement dps = null;
|
||||||
StmtIterator stmts = model.listStatements(model.createResource(ind.getURI()),
|
StmtIterator stmts = model.listStatements(model.createResource(ind.getURI()),
|
||||||
model.getProperty(predicateUri),
|
model.getProperty(predicateUri),
|
||||||
|
@ -139,9 +142,10 @@ public class RdfLiteralHash {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int makeVitroNsLiteralHash( Individual subject, String predicateUri, String value, Model model) {
|
public static int makeRdfsLabelLiteralHash( Individual subject, String value, Model model) {
|
||||||
|
|
||||||
String subjectUri = subject.getURI();
|
String subjectUri = subject.getURI();
|
||||||
|
String predicateUri = VitroVocabulary.LABEL;
|
||||||
|
|
||||||
StmtIterator stmts = model.listStatements(model.createResource(subjectUri),
|
StmtIterator stmts = model.listStatements(model.createResource(subjectUri),
|
||||||
model.getProperty(predicateUri),
|
model.getProperty(predicateUri),
|
||||||
|
|
|
@ -188,33 +188,30 @@ public class RdfLiteralHashTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetVitroNsPropertyStatement(){
|
public void testGetRdfsLabelStatementByHash(){
|
||||||
|
|
||||||
String n3 =
|
String n3 =
|
||||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
|
||||||
"@prefix ex: <http://example.com/> . \n" +
|
"@prefix ex: <http://example.com/> . \n" +
|
||||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"+
|
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"+
|
||||||
" ex:bob vitro:moniker \"great\"^^<"+XSD.xstring.getURI()+"> ." ;
|
" ex:bob rdfs:label \"Smith, Bob\"^^<"+XSD.xstring.getURI()+"> ." ;
|
||||||
|
|
||||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||||
|
|
||||||
Individual bob = new IndividualImpl();
|
Individual bob = new IndividualImpl();
|
||||||
bob.setURI("http://example.com/bob");
|
bob.setURI("http://example.com/bob");
|
||||||
|
|
||||||
String propertyUri = VitroVocabulary.MONIKER;
|
|
||||||
|
|
||||||
int hash = RdfLiteralHash.makeVitroNsLiteralHash(bob, propertyUri, "great", model);
|
int hash = RdfLiteralHash.makeRdfsLabelLiteralHash(bob, "Smith, Bob", model);
|
||||||
DataPropertyStatement stmt = RdfLiteralHash.getVitroNsPropertyStmtByHash(bob, propertyUri, model, hash);
|
DataPropertyStatement stmt = RdfLiteralHash.getRdfsLabelStatementByHash(bob, model, hash);
|
||||||
|
|
||||||
String data = stmt.getData();
|
String data = stmt.getData();
|
||||||
String datatypeUri = stmt.getDatatypeURI();
|
String datatypeUri = stmt.getDatatypeURI();
|
||||||
String predicateUri = stmt.getDatapropURI();
|
String predicateUri = stmt.getDatapropURI();
|
||||||
String subjectUri = stmt.getIndividualURI();
|
String subjectUri = stmt.getIndividualURI();
|
||||||
|
|
||||||
Assert.assertEquals("great", data);
|
Assert.assertEquals("Smith, Bob", data);
|
||||||
Assert.assertEquals(XSD.xstring.getURI(), datatypeUri);
|
Assert.assertEquals(XSD.xstring.getURI(), datatypeUri);
|
||||||
Assert.assertEquals(VitroVocabulary.MONIKER, predicateUri);
|
Assert.assertEquals(VitroVocabulary.LABEL, predicateUri);
|
||||||
Assert.assertEquals("http://example.com/bob", subjectUri);
|
Assert.assertEquals("http://example.com/bob", subjectUri);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
************************************** */
|
************************************** */
|
||||||
|
|
||||||
final String DEFAULT_DATA_FORM = "defaultDatapropForm.jsp";
|
final String DEFAULT_DATA_FORM = "defaultDatapropForm.jsp";
|
||||||
final String DEFAULT_VITRO_NS_FORM = "defaultVitroNsDataPropForm.jsp";
|
|
||||||
final String DEFAULT_ERROR_FORM = "error.jsp";
|
final String DEFAULT_ERROR_FORM = "error.jsp";
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
|
@ -58,14 +57,6 @@
|
||||||
String formParam = vreq.getParameter("editForm");
|
String formParam = vreq.getParameter("editForm");
|
||||||
String command = vreq.getParameter("cmd");
|
String command = vreq.getParameter("cmd");
|
||||||
|
|
||||||
String vitroNsProp = (String) vreq.getParameter("vitroNsProp");
|
|
||||||
|
|
||||||
boolean isVitroNsProp = false;
|
|
||||||
// On new Freemarker individual page, the editing link for rdfs:label doesn't get this url param attached
|
|
||||||
if ( "true".equals(vitroNsProp) || predicateUri.equals(VitroVocabulary.LABEL) ) {
|
|
||||||
isVitroNsProp = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( subjectUri == null || subjectUri.trim().length() == 0 ) {
|
if( subjectUri == null || subjectUri.trim().length() == 0 ) {
|
||||||
log.error("required subjectUri parameter missing");
|
log.error("required subjectUri parameter missing");
|
||||||
throw new Error("subjectUri was empty, it is required by editDatapropStmtRequestDispatch");
|
throw new Error("subjectUri was empty, it is required by editDatapropStmtRequestDispatch");
|
||||||
|
@ -92,8 +83,9 @@
|
||||||
|
|
||||||
DataProperty dataproperty = wdf.getDataPropertyDao().getDataPropertyByURI( predicateUri );
|
DataProperty dataproperty = wdf.getDataPropertyDao().getDataPropertyByURI( predicateUri );
|
||||||
if( dataproperty == null) {
|
if( dataproperty == null) {
|
||||||
// No dataproperty will be returned for a vitro ns prop, but we shouldn't throw an error.
|
// No dataproperty will be returned for rdfs:label, but we shouldn't throw an error.
|
||||||
if (!isVitroNsProp) {
|
// RY ** Consider instead getting rdfs:label included in what's returned
|
||||||
|
if (! predicateUri.equals(VitroVocabulary.LABEL)) {
|
||||||
log.error("Could not find data property '"+predicateUri+"' in model");
|
log.error("Could not find data property '"+predicateUri+"' in model");
|
||||||
throw new Error("editDatapropStmtRequest.jsp: Could not find DataProperty in model: " + predicateUri);
|
throw new Error("editDatapropStmtRequest.jsp: Could not find DataProperty in model: " + predicateUri);
|
||||||
}
|
}
|
||||||
|
@ -120,7 +112,7 @@
|
||||||
DataPropertyStatement dps = null;
|
DataPropertyStatement dps = null;
|
||||||
if( dataHash != 0) {
|
if( dataHash != 0) {
|
||||||
Model model = (Model)application.getAttribute("jenaOntModel");
|
Model model = (Model)application.getAttribute("jenaOntModel");
|
||||||
dps = RdfLiteralHash.getPropertyStmtByHash(subject, predicateUri, dataHash, model, isVitroNsProp);
|
dps = RdfLiteralHash.getPropertyStmtByHash(subject, predicateUri, dataHash, model);
|
||||||
|
|
||||||
if (dps==null) {
|
if (dps==null) {
|
||||||
log.error("No match to existing data property \""+predicateUri+"\" statement for subject \""+subjectUri+"\" via key "+datapropKeyStr);
|
log.error("No match to existing data property \""+predicateUri+"\" statement for subject \""+subjectUri+"\" via key "+datapropKeyStr);
|
||||||
|
@ -160,8 +152,8 @@
|
||||||
if (formParam != null) {
|
if (formParam != null) {
|
||||||
form = formParam;
|
form = formParam;
|
||||||
}
|
}
|
||||||
else if (isVitroNsProp) { // dataproperty is null here
|
else if (predicateUri.equals(VitroVocabulary.LABEL)) { // dataproperty is null here
|
||||||
form = DEFAULT_VITRO_NS_FORM;
|
form = "rdfsLabelForm.jsp";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
form = dataproperty.getCustomEntryForm();
|
form = dataproperty.getCustomEntryForm();
|
||||||
|
|
|
@ -30,8 +30,7 @@
|
||||||
%>
|
%>
|
||||||
<%
|
<%
|
||||||
org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("edu.cornell.mannlib.vitro.jsp.edit.forms.defaultVitroNsPropForm.jsp");
|
org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("edu.cornell.mannlib.vitro.jsp.edit.forms.defaultVitroNsPropForm.jsp");
|
||||||
log.debug("Starting defaultVitroNsPropForm.jsp");
|
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||||
vreq.setAttribute("defaultNamespace", wdf.getDefaultNamespace());
|
vreq.setAttribute("defaultNamespace", wdf.getDefaultNamespace());
|
||||||
|
@ -40,7 +39,9 @@
|
||||||
String predicateUri = vreq.getParameter("predicateUri");
|
String predicateUri = vreq.getParameter("predicateUri");
|
||||||
String propertyName = predicateUri.substring(predicateUri.lastIndexOf("#")+1);
|
String propertyName = predicateUri.substring(predicateUri.lastIndexOf("#")+1);
|
||||||
vreq.setAttribute("propertyName", propertyName);
|
vreq.setAttribute("propertyName", propertyName);
|
||||||
|
|
||||||
|
log.debug("Starting defaultVitroNsPropForm.jsp for property " + predicateUri);
|
||||||
|
|
||||||
DataPropertyStatement dps = (DataPropertyStatement)vreq.getAttribute("dataprop");
|
DataPropertyStatement dps = (DataPropertyStatement)vreq.getAttribute("dataprop");
|
||||||
|
|
||||||
String datapropKeyStr = vreq.getParameter("datapropKey");
|
String datapropKeyStr = vreq.getParameter("datapropKey");
|
|
@ -374,9 +374,7 @@ and set a flag in the request to indicate "back button confusion"
|
||||||
|
|
||||||
Model model = (Model)application.getAttribute("jenaOntModel");
|
Model model = (Model)application.getAttribute("jenaOntModel");
|
||||||
int dpropHash = Integer.parseInt(editConfig.getDatapropKey());
|
int dpropHash = Integer.parseInt(editConfig.getDatapropKey());
|
||||||
String vitroNsProp = vreq.getParameter("vitroNsProp");
|
DataPropertyStatement dps = RdfLiteralHash.getPropertyStmtByHash(subject, editConfig.getPredicateUri(), dpropHash, model);
|
||||||
boolean isVitroNsProp = vitroNsProp != null && vitroNsProp.equals("true");
|
|
||||||
DataPropertyStatement dps = RdfLiteralHash.getPropertyStmtByHash(subject, editConfig.getPredicateUri(), dpropHash, model, isVitroNsProp);
|
|
||||||
|
|
||||||
if (dps != null)
|
if (dps != null)
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue