diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHash.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHash.java index d28a74181..8477fa3bb 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHash.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHash.java @@ -55,6 +55,7 @@ public class RdfLiteralHash { return hashMe.hashCode(); } + /** * @param stmt * @param hash @@ -122,18 +123,9 @@ public class RdfLiteralHash { Statement stmt = stmts.nextStatement(); RDFNode node = stmt.getObject(); if ( node.isLiteral() ){ - Literal lit = (Literal)node.as(Literal.class); - String value = lit.getLexicalForm(); - String lang = lit.getLanguage(); - String datatypeURI = lit.getDatatypeURI(); - dps = new DataPropertyStatementImpl(); - dps.setDatatypeURI(datatypeURI); - dps.setLanguage(lang); - dps.setData(value); - dps.setDatapropURI(stmt.getPredicate().toString()); - dps.setIndividualURI(ind.getURI()); + dps = makeDataPropertyStatementFromStatement(stmt, node); if (doesStmtMatchHash(dps, hash)) { - break; + return dps; } } } @@ -142,7 +134,63 @@ public class RdfLiteralHash { } finally{ stmts.close(); } - return dps; + return null; } + public static int makeVitroNsLiteralHash( Individual subject, String predicateUri, String value, Model model) { + + String subjectUri = subject.getURI(); + + StmtIterator stmts = model.listStatements(model.createResource(subjectUri), + model.getProperty(predicateUri), + (RDFNode) null); + DataPropertyStatement dps = null; + int hash = 0; + int count = 0; + try { + while (stmts.hasNext()) { + Statement stmt = stmts.nextStatement(); + RDFNode node = stmt.getObject(); + if (node.isLiteral()) { + count++; + dps = makeDataPropertyStatementFromStatement(stmt, node); + hash = makeRdfLiteralHash(dps); + } + } + } finally { + stmts.close(); + } + + if( count == 1 ) { + return hash; + } else if( count == 0 ){ + log.debug("No data property statement for " + + "subject:" + subjectUri + "\npredicate:" + predicateUri + "\nvalue: " + value); + throw new IllegalArgumentException("Could not create RdfLiteralHash because " + + "there was no data property statement with the given value."); + } else{ + log.debug("Multiple data property statements for " + + "subject:" + subjectUri + "\npredicate:" + predicateUri + "\nvalue: " + value); + throw new IllegalArgumentException("Could not create RdfLiteralHash because " + + "there were multiple data property statements with the given value."); + } + } + + private static DataPropertyStatement makeDataPropertyStatementFromStatement(Statement statement, RDFNode node) { + + Literal lit = (Literal) node.as(Literal.class); + String value = lit.getLexicalForm(); + String lang = lit.getLanguage(); + String datatypeUri = lit.getDatatypeURI(); + + DataPropertyStatement dps = new DataPropertyStatementImpl(); + dps.setDatatypeURI(datatypeUri); + dps.setLanguage(lang); + dps.setData(value); + dps.setDatapropURI(statement.getPredicate().getURI()); + dps.setIndividualURI(statement.getSubject().getURI()); + + return dps; + } + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/PropertyEditLinks.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/PropertyEditLinks.java index 36dce9cc8..ce68befde 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/PropertyEditLinks.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/jsptags/PropertyEditLinks.java @@ -20,6 +20,8 @@ import javax.servlet.jsp.tagext.TagSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import com.hp.hpl.jena.rdf.model.Model; + import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.identifier.ServletIdentifierBundleFactory; import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyList; @@ -132,8 +134,8 @@ public class PropertyEditLinks extends TagSupport{ DataProperty prop = (DataProperty)item; // a DataProperty populated for this subject individual links = doDataProp( prop, entity, themeDir,policyToAccess(ids, policy, entity.getURI(), prop), contextPath ) ; } else if (item instanceof String && data != null) { - DataPropertyStatement dps = (DataPropertyStatement) new DataPropertyStatementImpl(entity.getURI(), (String)item, data); - links = doVitroNamespaceProp( dps, themeDir, policyToAccess(ids, policy, dps), contextPath ); + DataPropertyStatement dps = (DataPropertyStatement) new DataPropertyStatementImpl(entity.getURI(), (String)item, data); + links = doVitroNamespaceProp( dps, entity, themeDir, policyToAccess(ids, policy, dps), contextPath ); } else { log.error("PropertyEditLinks cannot make links for an object of type "+item.getClass().getName()); return SKIP_BODY; @@ -158,10 +160,6 @@ public class PropertyEditLinks extends TagSupport{ return SKIP_BODY; } - -// private String getNameFromUri(String predicateUri) { -// return predicateUri.substring(predicateUri.lastIndexOf('#')+1); -// } protected LinkStruct[] doDataProp(DataProperty dprop, Individual entity, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { if( allowedAccessTypeArray == null || dprop == null || allowedAccessTypeArray.length == 0 ) { @@ -310,21 +308,22 @@ public class PropertyEditLinks extends TagSupport{ return links; } - protected LinkStruct[] doVitroNamespaceProp(DataPropertyStatement dpropStmt, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { + protected LinkStruct[] doVitroNamespaceProp(DataPropertyStatement dpropStmt, Individual subject, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) { if( allowedAccessTypeArray == null || dpropStmt == null || allowedAccessTypeArray.length == 0 ) { log.debug("Null or empty access type array for vitro namespace property " + dpropStmt.getDatapropURI()); return empty_array; } - - LinkStruct[] links = new LinkStruct[2]; - - String subjectUri = dpropStmt.getIndividualURI(); + + String subjectUri = subject.getURI(); String predicateUri = dpropStmt.getDatapropURI(); + String value = dpropStmt.getData(); + Model model = (Model)pageContext.getServletContext().getAttribute("jenaOntModel"); - String dpropHash = String.valueOf(RdfLiteralHash.makeRdfLiteralHash( dpropStmt )); + String dpropHash = String.valueOf(RdfLiteralHash.makeVitroNsLiteralHash( subject, predicateUri, value, model )); String dispatchUrl = contextPath + "edit/editDatapropStmtRequestDispatch.jsp"; + LinkStruct[] links = new LinkStruct[2]; int index = 0; boolean deleteAllowed = ( contains( allowedAccessTypeArray, EditLinkAccess.DELETE ) && diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHashTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHashTest.java index e8ac7336b..1cdae48e2 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHashTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/n3editing/RdfLiteralHashTest.java @@ -2,6 +2,7 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing; +import java.io.StringReader; import java.util.ArrayList; import java.util.List; @@ -9,9 +10,15 @@ import junit.framework.Assert; import org.junit.Test; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.vocabulary.XSD; + 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.beans.IndividualImpl; +import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; public class RdfLiteralHashTest { @@ -179,5 +186,28 @@ public class RdfLiteralHashTest { Assert.assertNull(stmt); } + + @Test + public void testgetVitroNsPropertyStatement(){ + String n3 = + "@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" + + "@prefix ex: . \n" + + "@prefix rdf: . \n"+ + "@prefix rdfs: .\n"+ + " ex:bob vitro:moniker \"great\"^^<"+XSD.xstring.getURI()+"> ." ; + + Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3"); + + Individual bob = new IndividualImpl(); + bob.setURI("http://example.com/bob"); + + int hash = RdfLiteralHash.makeVitroNsLiteralHash(bob,VitroVocabulary.MONIKER, "great", model); + DataPropertyStatement stmt = RdfLiteralHash.getVitroNsPropertyStmtByHash(bob, model, hash); + + Assert.assertEquals("great", stmt.getData()); + Assert.assertEquals(XSD.xstring.getURI(), stmt.getDatatypeURI()); + Assert.assertEquals(VitroVocabulary.MONIKER, stmt.getDatapropURI()); + Assert.assertEquals("http://example.com/bob", stmt.getIndividualURI()); + } } diff --git a/webapp/web/edit/editDatapropStmtRequestDispatch.jsp b/webapp/web/edit/editDatapropStmtRequestDispatch.jsp index 7576423f2..4d5f090a4 100644 --- a/webapp/web/edit/editDatapropStmtRequestDispatch.jsp +++ b/webapp/web/edit/editDatapropStmtRequestDispatch.jsp @@ -55,7 +55,7 @@ String formParam = vreq.getParameter("editForm"); String command = vreq.getParameter("cmd"); - String vitroNsProp = vreq.getParameter("vitroNsProp"); + String vitroNsProp = (String) vreq.getParameter("vitroNsProp"); boolean isVitroNsProp = (vitroNsProp != null && vitroNsProp.equals("true")) ? true : false; if( subjectUri == null || subjectUri.trim().length() == 0 ) { @@ -67,13 +67,11 @@ throw new Error("predicateUri was empty, it is required by editDatapropStmtRequestDispatch"); } - /* since we have the URIs let's put the individual, data property, and optional data property statement in the request */ - + // Since we have the URIs let's put the individual, data property, and optional data property statement in the request vreq.setAttribute("subjectUri", subjectUri); vreq.setAttribute("subjectUriJson", MiscWebUtils.escape(subjectUri)); vreq.setAttribute("predicateUri", predicateUri); vreq.setAttribute("predicateUriJson", MiscWebUtils.escape(predicateUri)); - //vreq.setAttribute("vitroNsProp", vitroNsProp); WebappDaoFactory wdf = vreq.getWebappDaoFactory(); diff --git a/webapp/web/edit/forms/datapropStmtDelete.jsp b/webapp/web/edit/forms/datapropStmtDelete.jsp index de990bf3e..5831d267f 100644 --- a/webapp/web/edit/forms/datapropStmtDelete.jsp +++ b/webapp/web/edit/forms/datapropStmtDelete.jsp @@ -23,7 +23,11 @@ if( session == null) throw new Error("need to have session"); if (!VitroRequestPrep.isSelfEditing(request) && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) {%> - + +<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.StandardModelSelector"%> +<%@page import="com.hp.hpl.jena.shared.Lock"%> +<%@page import="com.hp.hpl.jena.ontology.OntModel"%> +<%@page import="edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent"%> <% } String subjectUri = request.getParameter("subjectUri"); @@ -51,13 +55,13 @@ if( subject == null ) throw new Error("could not find subject " + subjectUri); request.setAttribute("subjectName",subject.getName()); - String vitroNsProp = vreq.getParameter("vitroNsProp"); - boolean isVitroNsProp = vitroNsProp != null && vitroNsProp.equals("true") ? true : false; - String dataValue=null; Model model = (Model)application.getAttribute("jenaOntModel"); - + + String vitroNsProp = vreq.getParameter("vitroNsProp"); + boolean isVitroNsProp = vitroNsProp != null && vitroNsProp.equals("true") ? true : false; + DataPropertyStatement dps = RdfLiteralHash.getPropertyStmtByHash(subject, dataHash, model, isVitroNsProp); if( log.isDebugEnabled() ){ @@ -78,8 +82,25 @@ if (dps!=null) { dataValue = dps.getData().trim(); - if( request.getParameter("y") != null ) { //do the delete - wdf.getDataPropertyStatementDao().deleteDataPropertyStatement(dps);%> + + //do the delete + if( request.getParameter("y") != null ) { + if( isVitroNsProp ){ + OntModel writeModel = (new StandardModelSelector()).getModel(request, application); + writeModel.enterCriticalSection(Lock.WRITE); + try{ + writeModel.getBaseModel().notifyEvent(new EditEvent(editorUri,true)); + writeModel.remove( + writeModel.getResource(subjectUri), + writeModel.getProperty(predicateUri), + writeModel.createLiteral(dps.getData())); + }finally{ + writeModel.leaveCriticalSection(); + } + }else{ + wdf.getDataPropertyStatementDao().deleteDataPropertyStatement(dps); + } + %> <%-- grab the predicate URI and trim it down to get the Local Name so we can send the user back to the appropriate property --%> @@ -99,7 +120,7 @@ - + diff --git a/webapp/web/edit/forms/defaultVitroNsPropForm.jsp b/webapp/web/edit/forms/defaultVitroNsPropForm.jsp index 33ff5be6e..941d9c446 100644 --- a/webapp/web/edit/forms/defaultVitroNsPropForm.jsp +++ b/webapp/web/edit/forms/defaultVitroNsPropForm.jsp @@ -126,7 +126,6 @@ - diff --git a/webapp/web/templates/entity/entityBasic.jsp b/webapp/web/templates/entity/entityBasic.jsp index 9ea606e93..ae7a0ab87 100644 --- a/webapp/web/templates/entity/entityBasic.jsp +++ b/webapp/web/templates/entity/entityBasic.jsp @@ -25,16 +25,16 @@ Individual entity = (Individual)request.getAttribute("entity"); %> - - <% - try { - VitroRequest vreq = new VitroRequest(request); - entity = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI((String)request.getAttribute("myEntityURI")); - System.out.println("entityBasic rendering "+entity.getURI()); - } catch (Exception e) { - e.printStackTrace(); - } - %> + + <% + try { + VitroRequest vreq = new VitroRequest(request); + entity = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI((String)request.getAttribute("myEntityURI")); + System.out.println("entityBasic rendering "+entity.getURI()); + } catch (Exception e) { + e.printStackTrace(); + } + %> <% @@ -82,16 +82,6 @@ if (VitroRequestPrep.isSelfEditing(request) || LoginFormBean.loggedIn(request, L - - - - - - - - - -
@@ -99,68 +89,75 @@ if (VitroRequestPrep.isSelfEditing(request) || LoginFormBean.loggedIn(request, L
-
- - -

${relatingPredicate.domainPublic} for ${relatedSubject.name}

- - - - -

← return to ${relatedSubject.name}

-
- -
-
-

${entity.name}

- - ${labelEditLinks} +
+ + +

${relatingPredicate.domainPublic} for ${relatedSubject.name}

+ + + + +

← return to ${relatedSubject.name}

+
+ +
+
+

${entity.name}

+ + -
-
- - -
-
- ${entity.moniker} - - ${monikerEditLinks} - -
-
-
- - <%-- Show the add link --%> - -
-
-
-
+
+
+ + +
+
+ ${entity.moniker} + + + +
+
+
+ + <%-- Show the add link --%> + +
+
+
+
- - +
+
+ +
+
+
@@ -172,12 +169,37 @@ if (VitroRequestPrep.isSelfEditing(request) || LoginFormBean.loggedIn(request, L
-
${entity.citation}
+
+
+
${entity.citation}
+ + + +
+
-
${entity.blurb}
-
${entity.description}
+ +
+
+
${entity.blurb}
+ + + +
+
+
+ +
+
+
${entity.description}
+ + + +
+
+
@@ -196,13 +218,19 @@ if (VitroRequestPrep.isSelfEditing(request) || LoginFormBean.loggedIn(request, L -

-

${entity.citation}
+
+
+
${entity.citation}
+ + + +
+
-

Keywords: ${entity.keywordString}

+

Keywords: ${entity.keywordString}

${requestScope.servletButtons}