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:
parent
79c46a4aec
commit
e8c272e4ff
7 changed files with 246 additions and 123 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 ) &&
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue