NIHVIVO-149 An individual's name can now be edited from the front end.
This commit is contained in:
parent
e06c6d0cba
commit
f8726e8356
13 changed files with 287 additions and 94 deletions
|
@ -18,13 +18,6 @@ public class EditDataPropStmt implements RequestedAction {
|
|||
this.dataPropStmt = dps;
|
||||
}
|
||||
|
||||
public EditDataPropStmt(String subjectUri, String predicateUri, String data) {
|
||||
dataPropStmt = new DataPropertyStatementImpl();
|
||||
dataPropStmt.setIndividualURI(subjectUri);
|
||||
dataPropStmt.setDatapropURI(predicateUri);
|
||||
dataPropStmt.setData(data);
|
||||
}
|
||||
|
||||
public PolicyDecision accept(VisitingPolicyIface policy, IdentifierBundle whoToAuth) {
|
||||
return policy.visit(whoToAuth,this);
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.beans;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Property;
|
||||
|
||||
/**
|
||||
* a class representing an particular instance of a data property
|
||||
* a class representing a particular instance of a data property
|
||||
*
|
||||
*/
|
||||
public interface DataPropertyStatement {
|
||||
|
@ -20,7 +22,7 @@ public interface DataPropertyStatement {
|
|||
|
||||
public String getDatapropURI();
|
||||
|
||||
public void setDatapropURI(String datapropURI);
|
||||
public void setDatapropURI(String propertyURI);
|
||||
|
||||
public String getDatatypeURI();
|
||||
|
||||
|
|
|
@ -27,6 +27,12 @@ public class DataPropertyStatementImpl implements VitroTimeWindowedResource, Dat
|
|||
if( individual != null ){
|
||||
this.individualURI = individual.getURI();
|
||||
}
|
||||
}
|
||||
|
||||
public DataPropertyStatementImpl(String individualUri, String propertyUri, String data){
|
||||
individualURI = individualUri;
|
||||
datapropURI = propertyUri;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getIndividualURI() {
|
||||
|
|
|
@ -16,8 +16,7 @@ public class VitroVocabulary {
|
|||
* There are a lot of places we'd like to be able to use a bnode ID instead of a URI. The following special string
|
||||
* indicates that the local name of a 'URI' should actually be treated as a bnode ID.
|
||||
*/
|
||||
public static final String PSEUDO_BNODE_NS = "http://vitro.mannlib.cornell.edu/ns/bnode#";
|
||||
|
||||
public static final String PSEUDO_BNODE_NS = "http://vitro.mannlib.cornell.edu/ns/bnode#";
|
||||
|
||||
public static final String RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
|
||||
public static final String RDFS = "http://www.w3.org/2000/01/rdf-schema#";
|
||||
|
|
|
@ -5,12 +5,18 @@ 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 edu.cornell.mannlib.vitro.webapp.web.jsptags.InputElementFormattingTag;
|
||||
|
||||
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.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||
|
||||
public class RdfLiteralHash {
|
||||
|
||||
private static final Log log = LogFactory.getLog(RdfLiteralHash.class.getName());
|
||||
|
@ -87,4 +93,38 @@ public class RdfLiteralHash {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static DataPropertyStatement getVitroNsPropertyStmtByHash(Individual ind, Model model, int hash) {
|
||||
if (ind == null || model == null || hash == 0) {
|
||||
return null;
|
||||
}
|
||||
DataPropertyStatement dps = null;
|
||||
StmtIterator stmts = model.listStatements(model.createResource(ind.getURI()), null, (RDFNode)null);
|
||||
try {
|
||||
while (stmts.hasNext()) {
|
||||
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());
|
||||
|
||||
if (doesStmtMatchHash(dps, hash)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//} catch {
|
||||
|
||||
} finally{
|
||||
stmts.close();
|
||||
}
|
||||
return dps;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActio
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
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.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
|
@ -58,6 +59,7 @@ public class PropertyEditLinks extends TagSupport{
|
|||
Object item;
|
||||
String var;
|
||||
String icons;
|
||||
String data;
|
||||
|
||||
private static final Log log = LogFactory.getLog(PropertyEditLinks.class.getName());
|
||||
|
||||
|
@ -71,6 +73,9 @@ public class PropertyEditLinks extends TagSupport{
|
|||
|
||||
public void setIcons(String ic){ icons = ic; }
|
||||
public String getIcons(){ return icons; }
|
||||
|
||||
public void setData(String data){ this.data = data; }
|
||||
public String getData(){ return data; }
|
||||
|
||||
@Override
|
||||
public int doStartTag() throws JspException {
|
||||
|
@ -126,9 +131,9 @@ public class PropertyEditLinks extends TagSupport{
|
|||
} else if( item instanceof DataProperty ){
|
||||
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) {
|
||||
String predicateUri = (String) item;
|
||||
links = doVitroNamespaceProp( predicateUri, entity, themeDir, policyToAccess(ids, policy, entity.getURI(), predicateUri), 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 );
|
||||
} else {
|
||||
log.error("PropertyEditLinks cannot make links for an object of type "+item.getClass().getName());
|
||||
return SKIP_BODY;
|
||||
|
@ -153,6 +158,10 @@ 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 ) {
|
||||
|
@ -210,7 +219,7 @@ public class PropertyEditLinks extends TagSupport{
|
|||
LinkStruct[] links = new LinkStruct[2];
|
||||
int index=0;
|
||||
|
||||
String dpropHash = String.valueOf(RdfLiteralHash.makeRdfLiteralHash( dpropStmt ));
|
||||
String dpropHash = String.valueOf(RdfLiteralHash.makeRdfLiteralHash( dpropStmt ));
|
||||
|
||||
if( contains( allowedAccessTypeArray, EditLinkAccess.MODIFY ) ){
|
||||
log.debug("permission found to UPDATE data property statement "+dpropStmt.getDatapropURI()+" ("+dpropStmt.getData()+") so icon created");
|
||||
|
@ -230,11 +239,6 @@ public class PropertyEditLinks extends TagSupport{
|
|||
ls.setMouseoverText("edit this text");
|
||||
links[index] = ls; index++;
|
||||
|
||||
|
||||
// String imgUrl = makeRelativeHref( themeDir + "site_icons/pencil.gif");
|
||||
|
||||
// str += "<a class\"edit image\" href=" + url + " title=\"edit\">" +
|
||||
// "<img src=" + imgUrl + " alt=\"(edit)\"/></a>\n";
|
||||
} else {
|
||||
log.debug("NO permission to UPDATE this data property statement ("+dpropStmt.getDatapropURI()+") found in policy");
|
||||
}
|
||||
|
@ -251,10 +255,6 @@ public class PropertyEditLinks extends TagSupport{
|
|||
ls.setMouseoverText("delete this text");
|
||||
links[index] = ls; index++;
|
||||
|
||||
// String imgUrl = makeRelativeHref( themeDir + "site_icons/trashcan.gif");
|
||||
|
||||
// str += "<a class\"delete image\" href=" + url + " title=\"delete\">" +
|
||||
// "<img src=" + imgUrl + " alt=\"(delete)\"/></a>\n";
|
||||
} else {
|
||||
log.debug("NO permission to DELETE this data property statement ("+dpropStmt.getDatapropURI()+") found in policy");
|
||||
}
|
||||
|
@ -288,10 +288,6 @@ public class PropertyEditLinks extends TagSupport{
|
|||
ls.setMouseoverText("change this relationship");
|
||||
links[index] = ls; index++;
|
||||
|
||||
// String imgUrl = makeRelativeHref( themeDir + "site_icons/pencil.gif");
|
||||
|
||||
// str += "<a class\"edit image\" href=" + url + " title=\"edit\">" +
|
||||
// "<img src=" + imgUrl + " alt=\"(edit)\"/></a>\n";
|
||||
} else {
|
||||
log.debug("NO permission to UPDATE this object property statement ("+opropStmt.getPropertyURI()+") found in policy");
|
||||
}
|
||||
|
@ -318,28 +314,37 @@ public class PropertyEditLinks extends TagSupport{
|
|||
return links;
|
||||
}
|
||||
|
||||
protected LinkStruct[] doVitroNamespaceProp(String predicateUri, Individual entity, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) {
|
||||
|
||||
LinkStruct[] links = new LinkStruct[2];
|
||||
|
||||
if( allowedAccessTypeArray == null || predicateUri == null || allowedAccessTypeArray.length == 0 ) {
|
||||
log.debug("Null or empty access type array for vitro namespace property " + predicateUri);
|
||||
protected LinkStruct[] doVitroNamespaceProp(DataPropertyStatement dpropStmt, 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;
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
LinkStruct ls = new LinkStruct();
|
||||
|
||||
|
||||
LinkStruct[] links = new LinkStruct[2];
|
||||
|
||||
String subjectUri = dpropStmt.getIndividualURI();
|
||||
String predicateUri = dpropStmt.getDatapropURI();
|
||||
|
||||
String dpropHash = String.valueOf(RdfLiteralHash.makeRdfLiteralHash( dpropStmt ));
|
||||
String dispatchUrl = contextPath + "edit/editDatapropStmtRequestDispatch.jsp";
|
||||
|
||||
String propName = predicateUri.substring(predicateUri.lastIndexOf('#')+1);
|
||||
String editForm = "vitroNs" + StringUtils.capitalize(propName) + "Form.jsp";
|
||||
String propName = getNameFromUri(predicateUri);
|
||||
String editForm = "vitroNsEdit" + StringUtils.capitalize(propName) + "Form.jsp";
|
||||
|
||||
LinkStruct ls = new LinkStruct();
|
||||
int index = 0;
|
||||
|
||||
if ( contains( allowedAccessTypeArray, EditLinkAccess.MODIFY ) ){
|
||||
log.debug("Permission found to UPDATE vitro namespace property " + predicateUri);
|
||||
String url = makeRelativeHref(dispatchUrl,
|
||||
"subjectUri", entity.getURI(),
|
||||
"subjectUri", subjectUri,
|
||||
"predicateUri", predicateUri,
|
||||
"datapropKey", dpropHash,
|
||||
"vitroNsProp", "true",
|
||||
// RY If we use a single vitro ns form for all vitro ns props, we won't need the editForm param.
|
||||
// See if they can reasonably be combined into a single form, then have
|
||||
// editDatapropStmtRequestDispatch use a default vitro ns form if no custom form is specified.
|
||||
"editForm", editForm);
|
||||
ls.setHref(url);
|
||||
ls.setType("edit");
|
||||
|
@ -356,8 +361,10 @@ public class PropertyEditLinks extends TagSupport{
|
|||
if ( contains( allowedAccessTypeArray, EditLinkAccess.DELETE ) ){
|
||||
log.debug("Permission found to DELETE vitro namespace property " + predicateUri);
|
||||
String url = makeRelativeHref(dispatchUrl,
|
||||
"subjectUri", entity.getURI(),
|
||||
"predicateUri", predicateUri);
|
||||
"subjectUri", subjectUri,
|
||||
"predicateUri", predicateUri,
|
||||
"datapropKey", dpropHash,
|
||||
"editForm", editForm);
|
||||
ls.setHref(url);
|
||||
ls.setType("delete");
|
||||
ls.setMouseoverText("delete this property");
|
||||
|
@ -508,24 +515,24 @@ public class PropertyEditLinks extends TagSupport{
|
|||
return access;
|
||||
}
|
||||
|
||||
protected EditLinkAccess[] policyToAccess( IdentifierBundle ids, PolicyIface policy, String subjectUri, String propertyUri) {
|
||||
|
||||
ArrayList<EditLinkAccess> list = new ArrayList<EditLinkAccess>(2);
|
||||
|
||||
RequestedAction action = new EditDataPropStmt(subjectUri, propertyUri, (String) null);
|
||||
PolicyDecision dec = policy.isAuthorized(ids, action);
|
||||
if ( dec != null && dec.getAuthorized() == Authorization.AUTHORIZED ){
|
||||
list.add( EditLinkAccess.MODIFY);
|
||||
}
|
||||
|
||||
action = new DropDataPropStmt(subjectUri, propertyUri, (String) null);
|
||||
dec = policy.isAuthorized(ids, action);
|
||||
if( dec != null && dec.getAuthorized() == Authorization.AUTHORIZED ){
|
||||
list.add( EditLinkAccess.DELETE );
|
||||
}
|
||||
|
||||
return list.toArray(ACCESS_TEMPLATE);
|
||||
}
|
||||
// protected EditLinkAccess[] policyToAccess( IdentifierBundle ids, PolicyIface policy, String subjectUri, String propertyUri) {
|
||||
//
|
||||
// ArrayList<EditLinkAccess> list = new ArrayList<EditLinkAccess>(2);
|
||||
//
|
||||
// RequestedAction action = new EditDataPropStmt(subjectUri, propertyUri, (String) null);
|
||||
// PolicyDecision dec = policy.isAuthorized(ids, action);
|
||||
// if ( dec != null && dec.getAuthorized() == Authorization.AUTHORIZED ){
|
||||
// list.add( EditLinkAccess.MODIFY);
|
||||
// }
|
||||
//
|
||||
// action = new DropDataPropStmt(subjectUri, propertyUri, (String) null);
|
||||
// dec = policy.isAuthorized(ids, action);
|
||||
// if( dec != null && dec.getAuthorized() == Authorization.AUTHORIZED ){
|
||||
// list.add( EditLinkAccess.DELETE );
|
||||
// }
|
||||
//
|
||||
// return list.toArray(ACCESS_TEMPLATE);
|
||||
// }
|
||||
|
||||
public enum EditLinkAccess{ MODIFY, DELETE, ADDNEW, INFO, ADMIN };
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue