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 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.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.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 {
|
||||
|
||||
private static final Log log = LogFactory.getLog(RdfLiteralHash.class.getName());
|
||||
|
@ -27,7 +28,7 @@ public class RdfLiteralHash {
|
|||
* @param stmt
|
||||
* @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)
|
||||
&&
|
||||
(stmt.getDatatypeURI() != null && stmt.getDatatypeURI().trim().length() > 0 ) )
|
||||
|
@ -76,22 +77,22 @@ 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 hash
|
||||
* @param model
|
||||
* @param isVitroNsProp
|
||||
* @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
|
||||
// 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) {
|
||||
|
||||
public static DataPropertyStatement getPropertyStmtByHash(Individual ind, String predicateUri, int hash, Model model) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -110,11 +111,13 @@ public class RdfLiteralHash {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param ind, may be null and getDataPropertyStatements() may return null.
|
||||
* @param ind, may be null
|
||||
* @param hash
|
||||
* @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;
|
||||
StmtIterator stmts = model.listStatements(model.createResource(ind.getURI()),
|
||||
|
@ -139,9 +142,10 @@ public class RdfLiteralHash {
|
|||
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 predicateUri = VitroVocabulary.LABEL;
|
||||
|
||||
StmtIterator stmts = model.listStatements(model.createResource(subjectUri),
|
||||
model.getProperty(predicateUri),
|
||||
|
|
|
@ -188,33 +188,30 @@ public class RdfLiteralHashTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetVitroNsPropertyStatement(){
|
||||
public void testGetRdfsLabelStatementByHash(){
|
||||
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \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"+
|
||||
" 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");
|
||||
|
||||
Individual bob = new IndividualImpl();
|
||||
bob.setURI("http://example.com/bob");
|
||||
|
||||
String propertyUri = VitroVocabulary.MONIKER;
|
||||
|
||||
int hash = RdfLiteralHash.makeVitroNsLiteralHash(bob, propertyUri, "great", model);
|
||||
DataPropertyStatement stmt = RdfLiteralHash.getVitroNsPropertyStmtByHash(bob, propertyUri, model, hash);
|
||||
int hash = RdfLiteralHash.makeRdfsLabelLiteralHash(bob, "Smith, Bob", model);
|
||||
DataPropertyStatement stmt = RdfLiteralHash.getRdfsLabelStatementByHash(bob, model, hash);
|
||||
|
||||
String data = stmt.getData();
|
||||
String datatypeUri = stmt.getDatatypeURI();
|
||||
String predicateUri = stmt.getDatapropURI();
|
||||
String subjectUri = stmt.getIndividualURI();
|
||||
|
||||
Assert.assertEquals("great", data);
|
||||
Assert.assertEquals("Smith, Bob", data);
|
||||
Assert.assertEquals(XSD.xstring.getURI(), datatypeUri);
|
||||
Assert.assertEquals(VitroVocabulary.MONIKER, predicateUri);
|
||||
Assert.assertEquals(VitroVocabulary.LABEL, predicateUri);
|
||||
Assert.assertEquals("http://example.com/bob", subjectUri);
|
||||
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
************************************** */
|
||||
|
||||
final String DEFAULT_DATA_FORM = "defaultDatapropForm.jsp";
|
||||
final String DEFAULT_VITRO_NS_FORM = "defaultVitroNsDataPropForm.jsp";
|
||||
final String DEFAULT_ERROR_FORM = "error.jsp";
|
||||
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
|
@ -58,14 +57,6 @@
|
|||
String formParam = vreq.getParameter("editForm");
|
||||
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 ) {
|
||||
log.error("required subjectUri parameter missing");
|
||||
throw new Error("subjectUri was empty, it is required by editDatapropStmtRequestDispatch");
|
||||
|
@ -92,8 +83,9 @@
|
|||
|
||||
DataProperty dataproperty = wdf.getDataPropertyDao().getDataPropertyByURI( predicateUri );
|
||||
if( dataproperty == null) {
|
||||
// No dataproperty will be returned for a vitro ns prop, but we shouldn't throw an error.
|
||||
if (!isVitroNsProp) {
|
||||
// No dataproperty will be returned for rdfs:label, but we shouldn't throw an error.
|
||||
// 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");
|
||||
throw new Error("editDatapropStmtRequest.jsp: Could not find DataProperty in model: " + predicateUri);
|
||||
}
|
||||
|
@ -120,7 +112,7 @@
|
|||
DataPropertyStatement dps = null;
|
||||
if( dataHash != 0) {
|
||||
Model model = (Model)application.getAttribute("jenaOntModel");
|
||||
dps = RdfLiteralHash.getPropertyStmtByHash(subject, predicateUri, dataHash, model, isVitroNsProp);
|
||||
dps = RdfLiteralHash.getPropertyStmtByHash(subject, predicateUri, dataHash, model);
|
||||
|
||||
if (dps==null) {
|
||||
log.error("No match to existing data property \""+predicateUri+"\" statement for subject \""+subjectUri+"\" via key "+datapropKeyStr);
|
||||
|
@ -160,8 +152,8 @@
|
|||
if (formParam != null) {
|
||||
form = formParam;
|
||||
}
|
||||
else if (isVitroNsProp) { // dataproperty is null here
|
||||
form = DEFAULT_VITRO_NS_FORM;
|
||||
else if (predicateUri.equals(VitroVocabulary.LABEL)) { // dataproperty is null here
|
||||
form = "rdfsLabelForm.jsp";
|
||||
}
|
||||
else {
|
||||
form = dataproperty.getCustomEntryForm();
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
%>
|
||||
<%
|
||||
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);
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
|
@ -41,6 +40,8 @@
|
|||
String propertyName = predicateUri.substring(predicateUri.lastIndexOf("#")+1);
|
||||
vreq.setAttribute("propertyName", propertyName);
|
||||
|
||||
log.debug("Starting defaultVitroNsPropForm.jsp for property " + predicateUri);
|
||||
|
||||
DataPropertyStatement dps = (DataPropertyStatement)vreq.getAttribute("dataprop");
|
||||
|
||||
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");
|
||||
int dpropHash = Integer.parseInt(editConfig.getDatapropKey());
|
||||
String vitroNsProp = vreq.getParameter("vitroNsProp");
|
||||
boolean isVitroNsProp = vitroNsProp != null && vitroNsProp.equals("true");
|
||||
DataPropertyStatement dps = RdfLiteralHash.getPropertyStmtByHash(subject, editConfig.getPredicateUri(), dpropHash, model, isVitroNsProp);
|
||||
DataPropertyStatement dps = RdfLiteralHash.getPropertyStmtByHash(subject, editConfig.getPredicateUri(), dpropHash, model);
|
||||
|
||||
if (dps != null)
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue