NIHVIVO-143 Allow adding a new moniker from the front end
This commit is contained in:
parent
87a97cd8df
commit
bcbe290c51
10 changed files with 146 additions and 39 deletions
|
@ -2,6 +2,11 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.vocabulary.XSD;
|
||||
import com.hp.hpl.jena.ontology.AnnotationProperty;
|
||||
|
||||
public class VitroVocabulary {
|
||||
|
@ -278,5 +283,28 @@ public class VitroVocabulary {
|
|||
public static final String NAMESPACE_ISCURRENTPREFIXMAPPING = vitroURI + "isCurrentPrefixMapping";
|
||||
|
||||
public static final String ONTOLOGY_PREFIX_ANNOT = vitroURI + "ontologyPrefixAnnot";
|
||||
|
||||
|
||||
|
||||
public static final List<String> VITRO_NS_PROPERTIES = Arrays.asList(BLURB, CITATION, DESCRIPTION, LABEL, LINK_ANCHOR, MONIKER, PRIMARY_LINK, RDF_TYPE, TIMEKEY);
|
||||
|
||||
public static String getVitroNsPropDatatypeUri(String propName) {
|
||||
Resource datatype = propName == TIMEKEY ? XSD.dateTime : XSD.xstring;
|
||||
return datatype.getURI();
|
||||
}
|
||||
|
||||
// public static final Map<String, String> VITRO_NS_PROPERTIES = new HashMap<String, String>() {
|
||||
// {
|
||||
// put(BLURB, XSD.xstring.getURI());
|
||||
// put(CITATION, XSD.xstring.getURI());
|
||||
// put(DESCRIPTION, XSD.xstring.getURI());
|
||||
// put(LABEL, XSD.xstring.getURI());
|
||||
// put(LINK_ANCHOR, XSD.xstring.getURI());
|
||||
// put(MONIKER, XSD.xstring.getURI());
|
||||
// put(PRIMARY_LINK, XSD.xstring.getURI());
|
||||
// put(RDF_TYPE, XSD.xstring.getURI());
|
||||
// put(TIMEKEY, XSD.dateTime.getURI());
|
||||
// }
|
||||
// };
|
||||
|
||||
}
|
||||
|
|
|
@ -86,11 +86,11 @@ public class RdfLiteralHash {
|
|||
// 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, int hash, Model model, boolean isVitroNsProp) {
|
||||
public static DataPropertyStatement getPropertyStmtByHash(Individual ind, String predicateUri, int hash, Model model, boolean isVitroNsProp) {
|
||||
|
||||
if (ind == null) return null;
|
||||
|
||||
DataPropertyStatement dps = isVitroNsProp ? RdfLiteralHash.getVitroNsPropertyStmtByHash(ind, model, hash) :
|
||||
DataPropertyStatement dps = isVitroNsProp ? RdfLiteralHash.getVitroNsPropertyStmtByHash(ind, predicateUri, model, hash) :
|
||||
RdfLiteralHash.getDataPropertyStmtByHash(ind, hash);
|
||||
|
||||
return dps;
|
||||
|
@ -114,10 +114,12 @@ public class RdfLiteralHash {
|
|||
* @param hash
|
||||
* @return a DataPropertyStatement if found or null if not found
|
||||
*/
|
||||
public static DataPropertyStatement getVitroNsPropertyStmtByHash(Individual ind, Model model, int hash) {
|
||||
public static DataPropertyStatement getVitroNsPropertyStmtByHash(Individual ind, String predicateUri, Model model, int hash) {
|
||||
|
||||
DataPropertyStatement dps = null;
|
||||
StmtIterator stmts = model.listStatements(model.createResource(ind.getURI()), null, (RDFNode)null);
|
||||
StmtIterator stmts = model.listStatements(model.createResource(ind.getURI()),
|
||||
model.getProperty(predicateUri),
|
||||
(RDFNode)null);
|
||||
try {
|
||||
while (stmts.hasNext()) {
|
||||
Statement stmt = stmts.nextStatement();
|
||||
|
|
|
@ -21,6 +21,8 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ServletIdentifierBundleFactory;
|
||||
|
@ -133,9 +135,15 @@ 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 && data != null) {
|
||||
DataPropertyStatement dps = (DataPropertyStatement) new DataPropertyStatementImpl(entity.getURI(), (String)item, data);
|
||||
links = doVitroNamespaceProp( dps, entity, themeDir, policyToAccess(ids, policy, dps), contextPath );
|
||||
} else if (item instanceof String && isVitroNsProp((String) item)) {
|
||||
String subjectUri = entity.getURI();
|
||||
if (data != null) { // links to edit or delete an existing value
|
||||
DataPropertyStatement dps = (DataPropertyStatement) new DataPropertyStatementImpl(subjectUri, (String)item, data);
|
||||
links = doVitroNamespacePropStmt( dps, entity, themeDir, policyToAccess(ids, policy, dps), contextPath );
|
||||
} else { // link to add a new value
|
||||
|
||||
links = doVitroNsProp( subjectUri, (String)item, themeDir, policyToAccess(ids, policy, subjectUri, (String)item), contextPath ) ;
|
||||
}
|
||||
} else {
|
||||
log.error("PropertyEditLinks cannot make links for an object of type "+item.getClass().getName());
|
||||
return SKIP_BODY;
|
||||
|
@ -160,6 +168,10 @@ public class PropertyEditLinks extends TagSupport{
|
|||
|
||||
return SKIP_BODY;
|
||||
}
|
||||
|
||||
private boolean isVitroNsProp(String predicateUri) {
|
||||
return VitroVocabulary.VITRO_NS_PROPERTIES.contains(predicateUri);
|
||||
}
|
||||
|
||||
protected LinkStruct[] doDataProp(DataProperty dprop, Individual entity, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) {
|
||||
if( allowedAccessTypeArray == null || dprop == null || allowedAccessTypeArray.length == 0 ) {
|
||||
|
@ -188,6 +200,39 @@ public class PropertyEditLinks extends TagSupport{
|
|||
return links;
|
||||
}
|
||||
|
||||
protected LinkStruct[] doVitroNsProp(String subjectUri, String propertyUri, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) {
|
||||
if( allowedAccessTypeArray == null || subjectUri == null || allowedAccessTypeArray.length == 0 ) {
|
||||
log.debug("null or empty access type array in doDataProp for vitro namespace property " + propertyUri + "; most likely just a property prohibited from editing");
|
||||
return empty_array;
|
||||
}
|
||||
LinkStruct[] links = new LinkStruct[1];
|
||||
|
||||
Model model = (Model)pageContext.getServletContext().getAttribute("jenaOntModel");
|
||||
StmtIterator stmts = model.listStatements(model.createResource(subjectUri),
|
||||
model.getProperty(propertyUri),
|
||||
(RDFNode) null);
|
||||
|
||||
if (stmts.hasNext()) {
|
||||
log.debug("not showing an \"add\" link for vitro namespace property " + propertyUri + " because it has a limit of 1");
|
||||
} else {
|
||||
if( contains( allowedAccessTypeArray, EditLinkAccess.ADDNEW ) ){
|
||||
log.debug("vitro namespace property "+propertyUri+" gets an \"add\" link");
|
||||
String url = makeRelativeHref(contextPath + "edit/editDatapropStmtRequestDispatch.jsp",
|
||||
"subjectUri", subjectUri,
|
||||
"predicateUri", propertyUri,
|
||||
"vitroNsProp", "true");
|
||||
LinkStruct ls = new LinkStruct();
|
||||
ls.setHref( url );
|
||||
ls.setType("add");
|
||||
ls.setMouseoverText("add a new entry");
|
||||
links[0] = ls;
|
||||
} else {
|
||||
log.debug("no add link generated for vitro namespace property "+propertyUri);
|
||||
}
|
||||
}
|
||||
return links;
|
||||
}
|
||||
|
||||
|
||||
protected LinkStruct[] doObjProp(ObjectProperty oprop, Individual entity, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) {
|
||||
if( allowedAccessTypeArray == null || oprop == null || allowedAccessTypeArray.length == 0 ) {
|
||||
|
@ -308,7 +353,7 @@ public class PropertyEditLinks extends TagSupport{
|
|||
return links;
|
||||
}
|
||||
|
||||
protected LinkStruct[] doVitroNamespaceProp(DataPropertyStatement dpropStmt, Individual subject, String themeDir, EditLinkAccess[] allowedAccessTypeArray, String contextPath) {
|
||||
protected LinkStruct[] doVitroNamespacePropStmt(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());
|
||||
|
@ -481,9 +526,16 @@ public class PropertyEditLinks extends TagSupport{
|
|||
}
|
||||
|
||||
protected EditLinkAccess[] policyToAccess( IdentifierBundle ids, PolicyIface policy, String subjectUri, DataProperty item) {
|
||||
|
||||
String propertyUri = item.getURI();
|
||||
return policyToAccess(ids, policy, subjectUri, propertyUri);
|
||||
}
|
||||
|
||||
protected EditLinkAccess[] policyToAccess( IdentifierBundle ids, PolicyIface policy, String subjectUri, String propertyUri) {
|
||||
|
||||
EditLinkAccess[] access;
|
||||
|
||||
RequestedAction action = new AddDataPropStmt(subjectUri, item.getURI(), RequestActionConstants.SOME_LITERAL, null, null);
|
||||
|
||||
RequestedAction action = new AddDataPropStmt(subjectUri, propertyUri, RequestActionConstants.SOME_LITERAL, null, null);
|
||||
PolicyDecision dec = policy.isAuthorized(ids, action);
|
||||
|
||||
if( dec != null && dec.getAuthorized() == Authorization.AUTHORIZED ){
|
||||
|
@ -494,7 +546,7 @@ public class PropertyEditLinks extends TagSupport{
|
|||
|
||||
return access;
|
||||
}
|
||||
|
||||
|
||||
public enum EditLinkAccess{ MODIFY, DELETE, ADDNEW, INFO, ADMIN };
|
||||
|
||||
public class LinkStruct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue