NIHVIVO-1332 Editing link for rdfs:label

This commit is contained in:
rjy7 2011-01-12 23:52:33 +00:00
parent cbda8cb95f
commit 50edcb5bbf
9 changed files with 95 additions and 60 deletions

View file

@ -42,5 +42,7 @@ public interface DataPropertyStatementDao {
List<Literal> getDataPropertyValuesForIndividualByProperty(Individual subject, DataProperty property); List<Literal> getDataPropertyValuesForIndividualByProperty(Individual subject, DataProperty property);
List<Literal> getDataPropertyValuesForIndividualByProperty(String subjectUri, String propertyUri);
} }

View file

@ -99,4 +99,10 @@ class DataPropertyStatementDaoFiltering extends BaseFiltering implements DataPro
return innerDataPropertyStatementDao.getDataPropertyValuesForIndividualByProperty(subject, property); return innerDataPropertyStatementDao.getDataPropertyValuesForIndividualByProperty(subject, property);
} }
@Override
// RY What about filtering?
public List<Literal> getDataPropertyValuesForIndividualByProperty(String subjectUri, String propertyUri) {
return innerDataPropertyStatementDao.getDataPropertyValuesForIndividualByProperty(subjectUri, propertyUri);
}
} }

View file

@ -285,17 +285,20 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
return l; return l;
} }
@Override
/* /*
* SPARQL-based method for getting the individual's values for a single data property. * SPARQL-based methods for getting the individual's values for a single data property.
*/ */
@Override
public List<Literal> getDataPropertyValuesForIndividualByProperty(Individual subject, DataProperty property) { public List<Literal> getDataPropertyValuesForIndividualByProperty(Individual subject, DataProperty property) {
return getDataPropertyValuesForIndividualByProperty(subject.getURI(), property.getURI());
}
@Override
public List<Literal> getDataPropertyValuesForIndividualByProperty(String subjectUri, String propertyUri) {
log.debug("dataPropertyValueQueryString:\n" + dataPropertyValueQueryString); log.debug("dataPropertyValueQueryString:\n" + dataPropertyValueQueryString);
log.debug("dataPropertyValueQuery:\n" + dataPropertyValueQuery); log.debug("dataPropertyValueQuery:\n" + dataPropertyValueQuery);
String subjectUri = subject.getURI();
String propertyUri = property.getURI();
QuerySolutionMap bindings = new QuerySolutionMap(); QuerySolutionMap bindings = new QuerySolutionMap();
bindings.add("subject", ResourceFactory.createResource(subjectUri)); bindings.add("subject", ResourceFactory.createResource(subjectUri));
bindings.add("property", ResourceFactory.createResource(propertyUri)); bindings.add("property", ResourceFactory.createResource(propertyUri));

View file

@ -2,7 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -15,10 +14,12 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.DropDataPr
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.EditDataPropStmt; 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.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; 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.controller.freemarker.UrlBuilder.ParamMap;
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
public class DataPropertyStatementTemplateModel extends PropertyStatementTemplateModel { public class DataPropertyStatementTemplateModel extends PropertyStatementTemplateModel {
@ -35,6 +36,22 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
super(subjectUri, propertyUri, policyHelper); super(subjectUri, propertyUri, policyHelper);
this.value = value; this.value = value;
setEditAccess(value, policyHelper);
}
DataPropertyStatementTemplateModel(String subjectUri, String propertyUri, VitroRequest vreq, EditingPolicyHelper policyHelper) {
super(subjectUri, propertyUri, policyHelper);
DataPropertyStatementDao dpsDao = vreq.getWebappDaoFactory().getDataPropertyStatementDao();
List<Literal> values = dpsDao.getDataPropertyValuesForIndividualByProperty(subjectUri, propertyUri);
value = values.get(0);
setEditAccess(value, policyHelper);
}
private void setEditAccess(Literal value, EditingPolicyHelper policyHelper) {
if (policyHelper != null) { // we're editing if (policyHelper != null) { // we're editing
DataPropertyStatement dps = new DataPropertyStatementImpl(subjectUri, propertyUri, value.getLexicalForm()); DataPropertyStatement dps = new DataPropertyStatementImpl(subjectUri, propertyUri, value.getLexicalForm());
@ -50,13 +67,16 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
} }
// Determine whether the statement can be deleted // Determine whether the statement can be deleted
action = new DropDataPropStmt(dps); if ( ! propertyUri.equals(VitroVocabulary.LABEL)) {
if (policyHelper.isAuthorizedAction(action)) { action = new DropDataPropStmt(dps);
markDeletable(); if (policyHelper.isAuthorizedAction(action)) {
markDeletable();
}
} }
} }
} }
/* Access methods for templates */ /* Access methods for templates */
public String getValue() { public String getValue() {
@ -73,6 +93,10 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
if (! isDeletable()) { if (! isDeletable()) {
params.put("deleteProhibited", "prohibited"); params.put("deleteProhibited", "prohibited");
} }
//
if (propertyUri.equals(VitroVocabulary.LABEL)) {
params.put("vitroNsProp", "true");
}
editUrl = UrlBuilder.getUrl(EDIT_PATH, params); editUrl = UrlBuilder.getUrl(EDIT_PATH, params);
} }
return editUrl; return editUrl;

View file

@ -45,22 +45,13 @@ public class GroupedPropertyList extends BaseTemplateModel {
private Individual subject; private Individual subject;
private VitroRequest vreq; private VitroRequest vreq;
private WebappDaoFactory wdf; private WebappDaoFactory wdf;
private LoginStatusBean loginStatusBean;
private List<PropertyGroupTemplateModel> groups; private List<PropertyGroupTemplateModel> groups;
GroupedPropertyList(Individual subject, VitroRequest vreq, LoginStatusBean loginStatusBean) { GroupedPropertyList(Individual subject, VitroRequest vreq, EditingPolicyHelper policyHelper) {
this.subject = subject; this.subject = subject;
this.vreq = vreq; this.vreq = vreq;
this.wdf = vreq.getWebappDaoFactory(); this.wdf = vreq.getWebappDaoFactory();
this.loginStatusBean = loginStatusBean;
// Determine whether we're editing or not.
boolean userCanEditThisProfile = getEditingStatus();
EditingPolicyHelper policyHelper = null;
if (userCanEditThisProfile) {
policyHelper = new EditingPolicyHelper(vreq, getServletContext());
}
// Create the property list for the subject. The properties will be put into groups later. // Create the property list for the subject. The properties will be put into groups later.
List<Property> propertyList = new ArrayList<Property>(); List<Property> propertyList = new ArrayList<Property>();
@ -80,7 +71,7 @@ public class GroupedPropertyList extends BaseTemplateModel {
// If editing this page, merge in object properties applicable to the individual that are currently // If editing this page, merge in object properties applicable to the individual that are currently
// unpopulated, so the properties are displayed to allow statements to be added to these properties. // unpopulated, so the properties are displayed to allow statements to be added to these properties.
// RY In future, we should limit this to properties that the user CAN add properties to. // RY In future, we should limit this to properties that the user CAN add properties to.
if (userCanEditThisProfile) { if (policyHelper != null) {
mergeAllPossibleObjectProperties(objectPropertyList, propertyList); mergeAllPossibleObjectProperties(objectPropertyList, propertyList);
} }
@ -96,7 +87,7 @@ public class GroupedPropertyList extends BaseTemplateModel {
propertyList.add(dp); propertyList.add(dp);
} }
if (userCanEditThisProfile) { if (policyHelper != null) {
mergeAllPossibleDataProperties(propertyList); mergeAllPossibleDataProperties(propertyList);
} }
@ -113,17 +104,6 @@ public class GroupedPropertyList extends BaseTemplateModel {
} }
/**
* Return true iff the user is editing.
* These tests may change once self-editing issues are straightened out. What we really need to know
* is whether the user can edit this profile, not whether in general he/she is an editor.
*/
private boolean getEditingStatus() {
boolean isSelfEditing = VitroRequestPrep.isSelfEditing(vreq);
boolean isCurator = loginStatusBean.isLoggedInAtLeast(LoginStatusBean.CURATOR);
return isSelfEditing || isCurator;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected void sort(List<Property> propertyList) { protected void sort(List<Property> propertyList) {
try { try {
@ -160,7 +140,6 @@ public class GroupedPropertyList extends BaseTemplateModel {
private void mergeAllPossibleObjectProperties(List<ObjectProperty> objectPropertyList, List<Property> propertyList) { private void mergeAllPossibleObjectProperties(List<ObjectProperty> objectPropertyList, List<Property> propertyList) {
PropertyInstanceDao piDao = wdf.getPropertyInstanceDao(); PropertyInstanceDao piDao = wdf.getPropertyInstanceDao();
// RY *** Does this exclude properties in the excluded namespaces already? If not, need same test as above
Collection<PropertyInstance> allPropInstColl = piDao.getAllPossiblePropInstForIndividual(subject.getURI()); Collection<PropertyInstance> allPropInstColl = piDao.getAllPossiblePropInstForIndividual(subject.getURI());
if (allPropInstColl != null) { if (allPropInstColl != null) {
for (PropertyInstance pi : allPropInstColl) { for (PropertyInstance pi : allPropInstColl) {
@ -189,7 +168,6 @@ public class GroupedPropertyList extends BaseTemplateModel {
protected void mergeAllPossibleDataProperties(List<Property> propertyList) { protected void mergeAllPossibleDataProperties(List<Property> propertyList) {
DataPropertyDao dpDao = wdf.getDataPropertyDao(); DataPropertyDao dpDao = wdf.getDataPropertyDao();
// RY *** Does this exclude properties in the excluded namespaces already? If not, need same test as above
Collection <DataProperty> allDatapropColl = dpDao.getAllPossibleDatapropsForIndividual(subject.getURI()); Collection <DataProperty> allDatapropColl = dpDao.getAllPossibleDatapropsForIndividual(subject.getURI());
if (allDatapropColl != null) { if (allDatapropColl != null) {
for (DataProperty dp : allDatapropColl ) { for (DataProperty dp : allDatapropColl ) {

View file

@ -7,18 +7,14 @@ import java.util.List;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.openrdf.model.URI;
import org.openrdf.model.impl.URIImpl;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.Link; import edu.cornell.mannlib.vitro.webapp.beans.Link;
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; 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.controller.freemarker.UrlBuilder.Route; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep; import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep;
import edu.cornell.mannlib.vitro.webapp.web.ViewFinder; import edu.cornell.mannlib.vitro.webapp.web.ViewFinder;
import edu.cornell.mannlib.vitro.webapp.web.ViewFinder.ClassView; import edu.cornell.mannlib.vitro.webapp.web.ViewFinder.ClassView;
@ -35,6 +31,7 @@ public class IndividualTemplateModel extends BaseTemplateModel {
protected UrlBuilder urlBuilder; protected UrlBuilder urlBuilder;
protected GroupedPropertyList propertyList = null; protected GroupedPropertyList propertyList = null;
protected LoginStatusBean loginStatusBean = null; protected LoginStatusBean loginStatusBean = null;
private EditingPolicyHelper policyHelper = null;
public IndividualTemplateModel(Individual individual, VitroRequest vreq) { public IndividualTemplateModel(Individual individual, VitroRequest vreq) {
this.individual = individual; this.individual = individual;
@ -49,8 +46,25 @@ public class IndividualTemplateModel extends BaseTemplateModel {
this.loginStatusBean = loginStatusBean; this.loginStatusBean = loginStatusBean;
// Needed for getting portal-sensitive urls. Remove if multi-portal support is removed. // Needed for getting portal-sensitive urls. Remove if multi-portal support is removed.
this.urlBuilder = new UrlBuilder(vreq.getPortal()); this.urlBuilder = new UrlBuilder(vreq.getPortal());
// If editing, create a helper object to check requested actions against policies
if (isEditable(loginStatusBean)) {
policyHelper = new EditingPolicyHelper(vreq, getServletContext());
}
} }
/**
* Return true iff the user is editing.
* These tests may change once self-editing issues are straightened out. What we really need to know
* is whether the user can edit this profile, not whether in general he/she is an editor.
*/
private boolean isEditable(LoginStatusBean loginStatusBean) {
boolean isSelfEditing = VitroRequestPrep.isSelfEditing(vreq);
boolean isCurator = loginStatusBean.isLoggedInAtLeast(LoginStatusBean.CURATOR);
return isSelfEditing || isCurator;
}
/* These methods perform some manipulation of the data returned by the Individual methods */ /* These methods perform some manipulation of the data returned by the Individual methods */
public String getProfileUrl() { public String getProfileUrl() {
@ -146,7 +160,7 @@ public class IndividualTemplateModel extends BaseTemplateModel {
public GroupedPropertyList getPropertyList() { public GroupedPropertyList getPropertyList() {
if (propertyList == null) { if (propertyList == null) {
propertyList = new GroupedPropertyList(individual, vreq, loginStatusBean); propertyList = new GroupedPropertyList(individual, vreq, policyHelper);
} }
return propertyList; return propertyList;
} }
@ -173,6 +187,11 @@ public class IndividualTemplateModel extends BaseTemplateModel {
return individual.getName(); return individual.getName();
} }
public DataPropertyStatementTemplateModel getNameStatement() {
String propertyUri = VitroVocabulary.LABEL;
return new DataPropertyStatementTemplateModel(getUri(), propertyUri, vreq, policyHelper);
}
public String getMoniker() { public String getMoniker() {
return individual.getMoniker(); return individual.getMoniker();
} }
@ -181,14 +200,6 @@ public class IndividualTemplateModel extends BaseTemplateModel {
return individual.getURI(); return individual.getURI();
} }
public String getDescription() {
return individual.getDescription();
}
public String getBlurb() {
return individual.getBlurb();
}
public List<String> getKeywords() { public List<String> getKeywords() {
return individual.getKeywords(); return individual.getKeywords();
} }
@ -202,6 +213,14 @@ public class IndividualTemplateModel extends BaseTemplateModel {
return individual.getLocalName(); return individual.getLocalName();
} }
@Deprecated
public String getDescription() {
return individual.getDescription();
}
@Deprecated
public String getBlurb() {
return individual.getBlurb();
}
} }

View file

@ -58,7 +58,7 @@
String command = vreq.getParameter("cmd"); String command = vreq.getParameter("cmd");
String vitroNsProp = (String) vreq.getParameter("vitroNsProp"); String vitroNsProp = (String) vreq.getParameter("vitroNsProp");
boolean isVitroNsProp = (vitroNsProp != null && vitroNsProp.equals("true")) ? true : false; boolean isVitroNsProp = "true".equals(vitroNsProp) ? true : false;
if( subjectUri == null || subjectUri.trim().length() == 0 ) { if( subjectUri == null || subjectUri.trim().length() == 0 ) {
log.error("required subjectUri parameter missing"); log.error("required subjectUri parameter missing");

View file

@ -26,7 +26,9 @@
<#else> <#else>
<h1 class="fn"> <h1 class="fn">
<#-- Label --> <#-- Label -->
${individual.name} <#assign label = individual.nameStatement>
${label.value}
<@p.editingLinks label editing />
<#-- Moniker --> <#-- Moniker -->
<#if individual.moniker?has_content> <#if individual.moniker?has_content>

View file

@ -101,8 +101,9 @@
<#-- Convert the string dateTimeString to a datetime object --> <#-- Convert the string dateTimeString to a datetime object -->
<#function toDateTime dateTimeString> <#function toDateTime dateTimeString>
<#-- First convert the datetime string to a string format that Freemarker <#-- First convert the datetime string to a string format that Freemarker
understands, then to a datetime object --> understands, then to a datetime object. For now, strip away a time zone rather
<#return dateTimeString?replace("T", " ")?replace("Z", "")?datetime("yyyy-MM-dd HH:mm:ss")> than displaying it. -->
<#return dateTimeString?replace("T", " ")?replace("Z.*$", "", "r")?datetime("yyyy-MM-dd HH:mm:ss")>
</#function> </#function>
<#-- Apply a precision and format type to format a datetime --> <#-- Apply a precision and format type to format a datetime -->