NIHVIVO-143 Front end deletion of moniker through the "delete" link: fixed bugs. Also added edit links for other vitro namespace properties on the individual page, but some are not working yet.

This commit is contained in:
rjy7 2010-03-18 21:04:19 +00:00
parent 79c46a4aec
commit e8c272e4ff
7 changed files with 246 additions and 123 deletions

View file

@ -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;
}
}

View file

@ -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 ) &&

View file

@ -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: <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()+"> ." ;
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());
}
}

View file

@ -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();

View file

@ -23,7 +23,11 @@
if( session == null)
throw new Error("need to have session");
if (!VitroRequestPrep.isSelfEditing(request) && !LoginFormBean.loggedIn(request, LoginFormBean.NON_EDITOR)) {%>
<c:redirect url="<%= Controllers.LOGIN %>" />
<%@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"%><c:redirect url="<%= Controllers.LOGIN %>" />
<% }
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 --%>
<c:set var="predicateUri" value="${param.predicateUri}" />
@ -99,7 +120,7 @@
<input type="hidden" name="datapropKey" value="${param.datapropKey}"/>
<input type="hidden" name="y" value="1"/>
<input type="hidden" name="cmd" value="delete"/>
<input type="hidden" name="vitroNsProp" value="<%= vitroNsProp %>" />
<input type="hidden" name="vitroNsProp" value="${param.vitroNsProp}" />
<v:input type="submit" id="submit" value="Delete" cancel="${param.subjectUri}" />
</form>
<jsp:include page="${postForm}"/>

View file

@ -126,7 +126,6 @@
<c:set var="propertyLabel" value="${propertyName == 'label' ? 'name' : propertyName}" />
<c:set var="submitLabel" value="Edit ${propertyLabel}" />
<c:set var="title" scope="request" value="Edit the ${propertyLabel} of ${subject.name}:" />
<c:set var="vitroNsProp" scope="request" value="true" />
<jsp:include page="${preForm}"/>

View file

@ -25,16 +25,16 @@ Individual entity = (Individual)request.getAttribute("entity");
%>
<c:if test="${!empty entityURI}">
<c:set var="myEntityURI" scope="request" value="${entityURI}"/>
<%
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();
}
%>
<c:set var="myEntityURI" scope="request" value="${entityURI}"/>
<%
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();
}
%>
</c:if>
<%
@ -82,16 +82,6 @@ if (VitroRequestPrep.isSelfEditing(request) || LoginFormBean.loggedIn(request, L
<c:set var="typeUri" value="http://www.w3.org/1999/02/22-rdf-syntax-ns#type" />
<c:set var="vitroNsUri" value="http://vitro.mannlib.cornell.edu/ns/vitro/0.7#" />
<c:if test="${showEdits}">
<c:set var="labelEditLinks"><edLnk:editLinks item="${labelUri}" data="${entity.name}" icons="false"/></c:set>
<c:set var="monikerEditLinks"><edLnk:editLinks item="${vitroNsUri}moniker" data="${entity.moniker}" icons="false"/></c:set>
<c:set var="blurbEditLinks"><edLnk:editLinks item="${vitroNsUri}blurb" data="${entity.blurb}" icons="false"/></c:set>
<c:set var="citationEditLinks"><edLnk:editLinks item="${vitroNsUri}citation" data="${entity.citation}" icons="false"/></c:set>
<c:set var="descriptionEditLinks"><edLnk:editLinks item="${vitroNsUri}description" data="${entity.description}" icons="false"/></c:set>
<c:set var="timekeyEditLinks"><edLnk:editLinks item="${vitroNsUri}timekey" data="${entity.timekey}" icons="false"/></c:set>
<c:set var="urlEditLinks"><edLnk:editLinks item="${vitroNsUri}url" data="${entity.url}" icons="false"/></c:set>
</c:if>
<c:set var='themeDir'><c:out value='${portalBean.themeDir}' /></c:set>
<div id="content">
@ -99,68 +89,75 @@ if (VitroRequestPrep.isSelfEditing(request) || LoginFormBean.loggedIn(request, L
<div class='contents entity'>
<div id="labelAndMoniker">
<c:choose>
<c:when test="${!empty relatedSubject}">
<h2><p:process>${relatingPredicate.domainPublic} for ${relatedSubject.name}</p:process></h2>
<c:url var="backToSubjectLink" value="/entity">
<c:param name="home" value="${portalBean.portalId}"/>
<c:param name="uri" value="${relatedSubject.URI}"/>
</c:url>
<p><a href="${backToSubjectLink}">&larr; return to ${relatedSubject.name}</a></p>
</c:when>
<c:otherwise>
<div class="vitroNsPropertyValue" id="label">
<div class="statementWrap">
<h2><p:process>${entity.name}</p:process></h2>
<c:if test="${!empty labelEditLinks}">
<span class="editLinks">${labelEditLinks}</span>
<div id="labelAndMoniker">
<c:choose>
<c:when test="${!empty relatedSubject}">
<h2><p:process>${relatingPredicate.domainPublic} for ${relatedSubject.name}</p:process></h2>
<c:url var="backToSubjectLink" value="/entity">
<c:param name="home" value="${portalBean.portalId}"/>
<c:param name="uri" value="${relatedSubject.URI}"/>
</c:url>
<p><a href="${backToSubjectLink}">&larr; return to ${relatedSubject.name}</a></p>
</c:when>
<c:otherwise>
<div class="datatypePropertyValue" id="label">
<div class="statementWrap">
<h2><p:process>${entity.name}</p:process></h2>
<c:if test="${showEdits}">
<span class="editLinks"><edLnk:editLinks item="${labelUri}" data="${entity.name}" icons="false"/></span>
</c:if>
</div>
</div>
<c:choose>
<c:when test="${!empty entity.moniker}">
<div class="vitroNsPropertyValue" id="moniker">
<div class="statementWrap">
<p:process><em class="moniker">${entity.moniker}</em></p:process>
<c:if test="${!empty monikerEditLinks}">
<span class="editLinks">${monikerEditLinks}</span>
</c:if>
</div>
</div>
</c:when>
<c:otherwise>
<%-- Show the add link --%>
</c:otherwise>
</c:choose>
</c:otherwise>
</c:choose>
</div><!-- entity label -->
</div>
</div>
<c:choose>
<c:when test="${!empty entity.moniker}">
<div class="datatypePropertyValue" id="moniker">
<div class="statementWrap">
<p:process><em class="moniker">${entity.moniker}</em></p:process>
<c:if test="${showEdits}">
<span class="editLinks"><edLnk:editLinks item="${vitroNsUri}moniker" data="${entity.moniker}" icons="false"/></span>
</c:if>
</div>
</div>
</c:when>
<c:otherwise>
<%-- Show the add link --%>
</c:otherwise>
</c:choose>
</c:otherwise>
</c:choose>
</div><!-- labelAndMoniker -->
<c:if test="${ (!empty entity.anchor) || (!empty entity.linksList) }">
<ul class="externalLinks">
<c:if test="${!empty entity.anchor}">
<c:choose>
<c:when test="${!empty entity.url}">
<c:url var="entityUrl" value="${entity.url}" />
<li class="primary"><a class="externalLink" href="<c:out value="${entityUrl}"/>"><p:process>${entity.anchor}</p:process></a></li>
</c:when>
<c:otherwise>
<li class="primary"><span class="externalLink"><p:process>${entity.anchor}</p:process></span></li>
</c:otherwise>
</c:choose>
</c:if>
<c:if test="${!empty entity.linksList }">
<c:forEach items="${entity.linksList}" var='link' varStatus="count">
<c:url var="linkUrl" value="${link.url}" />
<c:choose>
<c:when test="${empty entity.url && count.first==true}"><li class="first"></c:when>
<c:otherwise><li></c:otherwise>
</c:choose>
<a class="externalLink" href="<c:out value="${linkUrl}"/>"><p:process>${link.anchor}</p:process></a></li>
</c:forEach>
</c:if>
</ul>
</c:if>
<div class="datatypePropertyValue">
<div class="statementWrap">
<ul class="externalLinks">
<c:if test="${!empty entity.anchor}">
<c:choose>
<c:when test="${!empty entity.url}">
<c:url var="entityUrl" value="${entity.url}" />
<li class="primary"><a class="externalLink" href="<c:out value="${entityUrl}"/>"><p:process>${entity.anchor}</p:process></a></li>
</c:when>
<c:otherwise>
<li class="primary"><span class="externalLink"><p:process>${entity.anchor}</p:process></span></li>
</c:otherwise>
</c:choose>
<c:if test="${showEdits}">
<span class="editLinks"><edLnk:editLinks item="${vitroNsUri}url" data="${entity.url}" icons="false"/></span>
</c:if>
</c:if>
<c:if test="${!empty entity.linksList }">
<c:forEach items="${entity.linksList}" var='link' varStatus="count">
<c:url var="linkUrl" value="${link.url}" />
<c:choose>
<c:when test="${empty entity.url && count.first==true}"><li class="first"></c:when>
<c:otherwise><li></c:otherwise>
</c:choose>
<a class="externalLink" href="<c:out value="${linkUrl}"/>"><p:process>${link.anchor}</p:process></a></li>
</c:forEach>
</c:if>
</ul>
</div>
</div>
</c:if>
<c:if test="${!empty entity.imageThumb}">
<div class="thumbnail">
<c:if test="${!empty entity.imageFile}">
@ -172,12 +169,37 @@ if (VitroRequestPrep.isSelfEditing(request) || LoginFormBean.loggedIn(request, L
<c:if test="${!empty entity.imageFile}"></a></c:if>
</div>
<c:if test="${!empty entity.citation}">
<div class="citation">${entity.citation}</div>
<div class="datatypePropertyValue">
<div class="statementWrap">
<div class="citation">${entity.citation}</div>
<c:if test="${showEdits}">
<span class="editLinks"><edLnk:editLinks item="${vitroNsUri}citation" data="${entity.citation}" icons="false"/></span>
</c:if>
</div>
</div>
</c:if>
</c:if>
<p:process>
<div class='description'>${entity.blurb}</div>
<div class='description'>${entity.description}</div>
<c:if test="${!empty entity.blurb}">
<div class="datatypePropertyValue">
<div class="statementWrap">
<div class="description">${entity.blurb}</div>
<c:if test="${showEdits}">
<span class="editLinks"><edLnk:editLinks item="${vitroNsUri}blurb" data="${entity.blurb}" icons="false"/></span>
</c:if>
</div>
</div>
</c:if>
<c:if test="${!empty entity.description}">
<div class="datatypePropertyValue">
<div class="statementWrap">
<div class="description">${entity.description}</div>
<c:if test="${showEdits}">
<span class="editLinks"><edLnk:editLinks item="${vitroNsUri}description" data="${entity.description}" icons="false"/></span>
</c:if>
</div>
</div>
</c:if>
</p:process>
<c:choose>
<c:when test="${showEdits}">
@ -196,13 +218,19 @@ if (VitroRequestPrep.isSelfEditing(request) || LoginFormBean.loggedIn(request, L
</c:import>
</c:otherwise>
</c:choose>
<p/>
<p:process>
<c:if test="${(!empty entity.citation) && (empty entity.imageThumb)}">
<div class="citation">${entity.citation}</div>
<div class="datatypePropertyValue">
<div class="statementWrap">
<div class="citation">${entity.citation}</div>
<c:if test="${showEdits}">
<span class="editLinks"><edLnk:editLinks item="${vitroNsUri}citation" data="${entity.citation}" icons="false"/></span>
</c:if>
</div>
</div>
</c:if>
<c:if test="${!empty entity.keywordString}">
<p id="keywords">Keywords: ${entity.keywordString}</p>
<p id="keywords">Keywords: ${entity.keywordString}</p>
</c:if>
</p:process>
${requestScope.servletButtons}