NIHVIVO-1332 Add edit and delete links for data property statements
This commit is contained in:
parent
e5b43812f1
commit
c51f65c2ab
10 changed files with 116 additions and 47 deletions
|
@ -26,14 +26,13 @@ import org.json.JSONException;
|
|||
import org.json.JSONObject;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.TabEntitiesController.PageRecord;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.SelectListGenerator;
|
||||
|
@ -202,13 +201,13 @@ public class JSONServlet extends VitroHttpServlet {
|
|||
}
|
||||
|
||||
String getDataPropertyValue(Individual ind, DataProperty dp, WebappDaoFactory wdf){
|
||||
List<DataPropertyStatement> stmts = wdf.getDataPropertyStatementDao()
|
||||
.getDataPropertyStatementsForIndividualByProperty(ind, dp);
|
||||
if( stmts == null || stmts.isEmpty() )
|
||||
List<Literal> values = wdf.getDataPropertyStatementDao()
|
||||
.getDataPropertyValuesForIndividualByProperty(ind, dp);
|
||||
if( values == null || values.isEmpty() )
|
||||
return "";
|
||||
else{
|
||||
if( stmts.get(0) != null )
|
||||
return stmts.get(0).getData();
|
||||
if( values.get(0) != null )
|
||||
return values.get(0).getLexicalForm();
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
|
||||
Individual individual = null;
|
||||
try {
|
||||
individual = getEntityFromRequest(vreq);
|
||||
individual = getIndividualFromRequest(vreq);
|
||||
} catch (Throwable th) {
|
||||
return doHelp();
|
||||
}
|
||||
|
@ -285,7 +285,7 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
|
||||
@return null on failure.
|
||||
*/
|
||||
public static Individual getEntityFromRequest(VitroRequest vreq) {
|
||||
public static Individual getIndividualFromRequest(VitroRequest vreq) {
|
||||
String netIdStr = null;
|
||||
Individual entity = null;
|
||||
IndividualDao iwDao = vreq.getWebappDaoFactory().getIndividualDao();
|
||||
|
|
|
@ -5,6 +5,8 @@ package edu.cornell.mannlib.vitro.webapp.dao;
|
|||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
|
@ -38,7 +40,7 @@ public interface DataPropertyStatementDao {
|
|||
|
||||
int insertNewDataPropertyStatement(DataPropertyStatement dataPropertyStatement );
|
||||
|
||||
List<DataPropertyStatement> getDataPropertyStatementsForIndividualByProperty(Individual subject, DataProperty property);
|
||||
List<Literal> getDataPropertyValuesForIndividualByProperty(Individual subject, DataProperty property);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2,14 +2,17 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.filtering;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.*;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||
import net.sf.jga.fn.UnaryFunctor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||
|
||||
class DataPropertyStatementDaoFiltering extends BaseFiltering implements DataPropertyStatementDao{
|
||||
final DataPropertyStatementDao innerDataPropertyStatementDao;
|
||||
final VitroFilters filters;
|
||||
|
@ -92,8 +95,8 @@ class DataPropertyStatementDaoFiltering extends BaseFiltering implements DataPro
|
|||
|
||||
@Override
|
||||
// RY What about filtering?
|
||||
public List<DataPropertyStatement> getDataPropertyStatementsForIndividualByProperty(Individual subject, DataProperty property) {
|
||||
return innerDataPropertyStatementDao.getDataPropertyStatementsForIndividualByProperty(subject, property);
|
||||
public List<Literal> getDataPropertyValuesForIndividualByProperty(Individual subject, DataProperty property) {
|
||||
return innerDataPropertyStatementDao.getDataPropertyValuesForIndividualByProperty(subject, property);
|
||||
}
|
||||
|
||||
}
|
|
@ -289,7 +289,7 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
|
|||
/*
|
||||
* SPARQL-based method for getting the individual's values for a single data property.
|
||||
*/
|
||||
public List<DataPropertyStatement> getDataPropertyStatementsForIndividualByProperty(Individual subject, DataProperty property) {
|
||||
public List<Literal> getDataPropertyValuesForIndividualByProperty(Individual subject, DataProperty property) {
|
||||
log.debug("dataPropertyValueQueryString:\n" + dataPropertyValueQueryString);
|
||||
log.debug("dataPropertyValueQuery:\n" + dataPropertyValueQuery);
|
||||
|
||||
|
@ -301,8 +301,7 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
|
|||
bindings.add("property", ResourceFactory.createResource(propertyUri));
|
||||
|
||||
// Run the SPARQL query to get the properties
|
||||
List<DataPropertyStatement> statements =
|
||||
new ArrayList<DataPropertyStatement>();
|
||||
List<Literal> values = new ArrayList<Literal>();
|
||||
DatasetWrapper w = dwf.getDatasetWrapper();
|
||||
Dataset dataset = w.getDataset();
|
||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||
|
@ -314,14 +313,12 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
|
|||
while (results.hasNext()) {
|
||||
QuerySolution sol = results.next();
|
||||
Literal value = sol.getLiteral("value");
|
||||
DataPropertyStatement dps = new DataPropertyStatementImpl(
|
||||
subjectUri, propertyUri, value.getLexicalForm());
|
||||
statements.add(dps);
|
||||
values.add(value);
|
||||
}
|
||||
} finally {
|
||||
dataset.getLock().leaveCriticalSection();
|
||||
w.close();
|
||||
}
|
||||
return statements;
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,37 +2,103 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.DropDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.EditDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
||||
|
||||
public class DataPropertyStatementTemplateModel extends BaseTemplateModel {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DataPropertyStatementTemplateModel.class);
|
||||
private static final String EDIT_PATH = "edit/editDatapropStmtRequestDispatch.jsp";
|
||||
|
||||
private DataPropertyStatement statement;
|
||||
private EditingPolicyHelper policyHelper;
|
||||
private static enum EditAccess {
|
||||
EDIT, DELETE;
|
||||
}
|
||||
|
||||
DataPropertyStatementTemplateModel(DataPropertyStatement statement, EditingPolicyHelper policyHelper) {
|
||||
this.statement = statement;
|
||||
this.policyHelper = policyHelper;
|
||||
private Literal value;
|
||||
|
||||
// Used for editing
|
||||
private String subjectUri = null;
|
||||
private String propertyUri = null;
|
||||
private List<EditAccess> editAccessList = null;
|
||||
private String dataPropHash = null;
|
||||
|
||||
DataPropertyStatementTemplateModel(String subjectUri, String propertyUri,
|
||||
Literal value2, EditingPolicyHelper policyHelper) {
|
||||
|
||||
this.value = value2;
|
||||
|
||||
if (policyHelper != null) {
|
||||
this.subjectUri = subjectUri;
|
||||
this.propertyUri = propertyUri;
|
||||
|
||||
DataPropertyStatement dps = new DataPropertyStatementImpl(subjectUri, propertyUri, value.getLexicalForm());
|
||||
// Language and datatype are needed to get the correct hash value
|
||||
dps.setLanguage(value.getLanguage());
|
||||
dps.setDatatypeURI(value.getDatatypeURI());
|
||||
this.dataPropHash = String.valueOf(RdfLiteralHash.makeRdfLiteralHash(dps));
|
||||
|
||||
editAccessList = new ArrayList<EditAccess>();
|
||||
|
||||
// Determine whether the statement can be edited
|
||||
RequestedAction action = new EditDataPropStmt(dps);
|
||||
if (policyHelper.isAuthorizedAction(action)) {
|
||||
editAccessList.add(EditAccess.EDIT);
|
||||
}
|
||||
|
||||
// Determine whether the statement can be deleted
|
||||
action = new DropDataPropStmt(dps);
|
||||
if (policyHelper.isAuthorizedAction(action)) {
|
||||
editAccessList.add(EditAccess.DELETE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Access methods for templates */
|
||||
|
||||
public String getValue() {
|
||||
return statement.getData();
|
||||
return value.getLexicalForm();
|
||||
}
|
||||
|
||||
public String getEditUrl() {
|
||||
String editUrl = "";
|
||||
if (editAccessList.contains(EditAccess.EDIT)) {
|
||||
ParamMap params = new ParamMap(
|
||||
"subjectUri", subjectUri,
|
||||
"predicateUri", propertyUri,
|
||||
"datapropKey", dataPropHash);
|
||||
if (! editAccessList.contains(EditAccess.DELETE)) {
|
||||
params.put("deleteProhibited", "prohibited");
|
||||
}
|
||||
editUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
||||
}
|
||||
return editUrl;
|
||||
}
|
||||
|
||||
public String getDeleteUrl() {
|
||||
String deleteUrl = "";
|
||||
if (editAccessList.contains(EditAccess.DELETE)) {
|
||||
ParamMap params = new ParamMap(
|
||||
"subjectUri", subjectUri,
|
||||
"predicateUri", propertyUri,
|
||||
"datapropKey", dataPropHash,
|
||||
"cmd", "delete");
|
||||
deleteUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
||||
}
|
||||
return deleteUrl;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,13 +8,12 @@ import java.util.List;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
|
@ -38,18 +37,17 @@ public class DataPropertyTemplateModel extends PropertyTemplateModel {
|
|||
// Determine whether a new statement can be added
|
||||
if (policyHelper != null) {
|
||||
RequestedAction action = new AddDataPropStmt(subjectUri, propertyUri,RequestActionConstants.SOME_LITERAL, null, null);
|
||||
PolicyDecision decision = policyHelper.getPolicyDecision(action);
|
||||
if( decision != null && decision.getAuthorized() == Authorization.AUTHORIZED ) {
|
||||
if (policyHelper.isAuthorizedAction(action)) {
|
||||
addAccess = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the data property statements via a sparql query
|
||||
DataPropertyStatementDao dpDao = vreq.getWebappDaoFactory().getDataPropertyStatementDao();
|
||||
List<DataPropertyStatement> dpStatements = dpDao.getDataPropertyStatementsForIndividualByProperty(subject, dp);
|
||||
statements = new ArrayList<DataPropertyStatementTemplateModel>(dpStatements.size());
|
||||
for (DataPropertyStatement dps : dpStatements) {
|
||||
statements.add(new DataPropertyStatementTemplateModel(dps, policyHelper));
|
||||
List<Literal> values = dpDao.getDataPropertyValuesForIndividualByProperty(subject, dp);
|
||||
statements = new ArrayList<DataPropertyStatementTemplateModel>(values.size());
|
||||
for (Literal value : values) {
|
||||
statements.add(new DataPropertyStatementTemplateModel(subjectUri, propertyUri, value, policyHelper));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.ServletIdentifierBundleF
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyList;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.RequestPolicyList;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyIface;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
|
@ -52,7 +53,13 @@ public class EditingPolicyHelper {
|
|||
}
|
||||
}
|
||||
|
||||
protected PolicyDecision getPolicyDecision(RequestedAction action) {
|
||||
protected boolean isAuthorizedAction(RequestedAction action) {
|
||||
PolicyDecision decision = getPolicyDecision(action);
|
||||
return (decision != null && decision.getAuthorized() == Authorization.AUTHORIZED);
|
||||
}
|
||||
|
||||
|
||||
private PolicyDecision getPolicyDecision(RequestedAction action) {
|
||||
return policy.isAuthorized(ids, action);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,15 +55,13 @@ public class ObjectPropertyStatementTemplateModel extends BaseTemplateModel {
|
|||
|
||||
// Determine whether the statement can be edited
|
||||
RequestedAction action = new EditObjPropStmt(objectPropertyStatement);
|
||||
PolicyDecision decision = policyHelper.getPolicyDecision(action);
|
||||
if (decision != null && decision.getAuthorized() == Authorization.AUTHORIZED) {
|
||||
if (policyHelper.isAuthorizedAction(action)) {
|
||||
editAccessList.add(EditAccess.EDIT);
|
||||
}
|
||||
|
||||
// Determine whether the statement can be deleted
|
||||
action = new DropObjectPropStmt(subjectUri, propertyUri, objectUri);
|
||||
decision = policyHelper.getPolicyDecision(action);
|
||||
if (decision != null && decision.getAuthorized() == Authorization.AUTHORIZED) {
|
||||
if (policyHelper.isAuthorizedAction(action)) {
|
||||
editAccessList.add(EditAccess.DELETE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,8 +88,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
// Determine whether a new statement can be added
|
||||
if (policyHelper != null) {
|
||||
RequestedAction action = new AddObjectPropStmt(subjectUri, propertyUri, RequestActionConstants.SOME_URI);
|
||||
PolicyDecision decision = policyHelper.getPolicyDecision(action);
|
||||
if( decision != null && decision.getAuthorized() == Authorization.AUTHORIZED ) {
|
||||
if (policyHelper.isAuthorizedAction(action)) {
|
||||
addAccess = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue