diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DataPropertyStatementDao.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DataPropertyStatementDao.java index 947de3bda..ff795fa83 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DataPropertyStatementDao.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/DataPropertyStatementDao.java @@ -41,6 +41,8 @@ public interface DataPropertyStatementDao { int insertNewDataPropertyStatement(DataPropertyStatement dataPropertyStatement ); List getDataPropertyValuesForIndividualByProperty(Individual subject, DataProperty property); + + List getDataPropertyValuesForIndividualByProperty(String subjectUri, String propertyUri); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/DataPropertyStatementDaoFiltering.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/DataPropertyStatementDaoFiltering.java index 33a294058..63540bd0f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/DataPropertyStatementDaoFiltering.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/DataPropertyStatementDaoFiltering.java @@ -99,4 +99,10 @@ class DataPropertyStatementDaoFiltering extends BaseFiltering implements DataPro return innerDataPropertyStatementDao.getDataPropertyValuesForIndividualByProperty(subject, property); } + @Override + // RY What about filtering? + public List getDataPropertyValuesForIndividualByProperty(String subjectUri, String propertyUri) { + return innerDataPropertyStatementDao.getDataPropertyValuesForIndividualByProperty(subjectUri, propertyUri); + } + } \ No newline at end of file diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyStatementDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyStatementDaoJena.java index f7575d7cc..807d55d75 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyStatementDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyStatementDaoJena.java @@ -285,17 +285,20 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro 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 getDataPropertyValuesForIndividualByProperty(Individual subject, DataProperty property) { + return getDataPropertyValuesForIndividualByProperty(subject.getURI(), property.getURI()); + } + + @Override + public List getDataPropertyValuesForIndividualByProperty(String subjectUri, String propertyUri) { 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(); bindings.add("subject", ResourceFactory.createResource(subjectUri)); bindings.add("property", ResourceFactory.createResource(propertyUri)); @@ -319,6 +322,6 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro dataset.getLock().leaveCriticalSection(); w.close(); } - return values; + return values; } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyStatementTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyStatementTemplateModel.java index 5417b9b69..65eb6bb1c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyStatementTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/DataPropertyStatementTemplateModel.java @@ -2,7 +2,6 @@ package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; -import java.util.ArrayList; import java.util.List; 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.beans.DataPropertyStatement; 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.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.web.templatemodels.BaseTemplateModel; public class DataPropertyStatementTemplateModel extends PropertyStatementTemplateModel { @@ -35,6 +36,22 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat super(subjectUri, propertyUri, policyHelper); 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 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 DataPropertyStatement dps = new DataPropertyStatementImpl(subjectUri, propertyUri, value.getLexicalForm()); @@ -50,13 +67,16 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat } // Determine whether the statement can be deleted - action = new DropDataPropStmt(dps); - if (policyHelper.isAuthorizedAction(action)) { - markDeletable(); - } - } + if ( ! propertyUri.equals(VitroVocabulary.LABEL)) { + action = new DropDataPropStmt(dps); + if (policyHelper.isAuthorizedAction(action)) { + markDeletable(); + } + } + } } + /* Access methods for templates */ public String getValue() { @@ -73,6 +93,10 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat if (! isDeletable()) { params.put("deleteProhibited", "prohibited"); } + // + if (propertyUri.equals(VitroVocabulary.LABEL)) { + params.put("vitroNsProp", "true"); + } editUrl = UrlBuilder.getUrl(EDIT_PATH, params); } return editUrl; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java index a618f27b1..b5acf4431 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/GroupedPropertyList.java @@ -45,22 +45,13 @@ public class GroupedPropertyList extends BaseTemplateModel { private Individual subject; private VitroRequest vreq; private WebappDaoFactory wdf; - private LoginStatusBean loginStatusBean; + private List groups; - GroupedPropertyList(Individual subject, VitroRequest vreq, LoginStatusBean loginStatusBean) { + GroupedPropertyList(Individual subject, VitroRequest vreq, EditingPolicyHelper policyHelper) { this.subject = subject; this.vreq = vreq; 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. List propertyList = new ArrayList(); @@ -80,7 +71,7 @@ public class GroupedPropertyList extends BaseTemplateModel { // 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. // RY In future, we should limit this to properties that the user CAN add properties to. - if (userCanEditThisProfile) { + if (policyHelper != null) { mergeAllPossibleObjectProperties(objectPropertyList, propertyList); } @@ -96,7 +87,7 @@ public class GroupedPropertyList extends BaseTemplateModel { propertyList.add(dp); } - if (userCanEditThisProfile) { + if (policyHelper != null) { 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") protected void sort(List propertyList) { try { @@ -160,7 +140,6 @@ public class GroupedPropertyList extends BaseTemplateModel { private void mergeAllPossibleObjectProperties(List objectPropertyList, List propertyList) { PropertyInstanceDao piDao = wdf.getPropertyInstanceDao(); - // RY *** Does this exclude properties in the excluded namespaces already? If not, need same test as above Collection allPropInstColl = piDao.getAllPossiblePropInstForIndividual(subject.getURI()); if (allPropInstColl != null) { for (PropertyInstance pi : allPropInstColl) { @@ -189,7 +168,6 @@ public class GroupedPropertyList extends BaseTemplateModel { protected void mergeAllPossibleDataProperties(List propertyList) { DataPropertyDao dpDao = wdf.getDataPropertyDao(); - // RY *** Does this exclude properties in the excluded namespaces already? If not, need same test as above Collection allDatapropColl = dpDao.getAllPossibleDatapropsForIndividual(subject.getURI()); if (allDatapropColl != null) { for (DataProperty dp : allDatapropColl ) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java index 08994664d..98f7143bb 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/IndividualTemplateModel.java @@ -7,18 +7,14 @@ import java.util.List; import org.apache.commons.logging.Log; 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.vitro.webapp.beans.Individual; 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.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.dao.WebappDaoFactory; +import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep; import edu.cornell.mannlib.vitro.webapp.web.ViewFinder; import edu.cornell.mannlib.vitro.webapp.web.ViewFinder.ClassView; @@ -35,6 +31,7 @@ public class IndividualTemplateModel extends BaseTemplateModel { protected UrlBuilder urlBuilder; protected GroupedPropertyList propertyList = null; protected LoginStatusBean loginStatusBean = null; + private EditingPolicyHelper policyHelper = null; public IndividualTemplateModel(Individual individual, VitroRequest vreq) { this.individual = individual; @@ -49,7 +46,24 @@ public class IndividualTemplateModel extends BaseTemplateModel { this.loginStatusBean = loginStatusBean; // Needed for getting portal-sensitive urls. Remove if multi-portal support is removed. 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 */ @@ -146,7 +160,7 @@ public class IndividualTemplateModel extends BaseTemplateModel { public GroupedPropertyList getPropertyList() { if (propertyList == null) { - propertyList = new GroupedPropertyList(individual, vreq, loginStatusBean); + propertyList = new GroupedPropertyList(individual, vreq, policyHelper); } return propertyList; } @@ -169,10 +183,15 @@ public class IndividualTemplateModel extends BaseTemplateModel { * declare new methods here that are not declared in the Individual interface. */ - public String getName() { + public String getName() { return individual.getName(); } + public DataPropertyStatementTemplateModel getNameStatement() { + String propertyUri = VitroVocabulary.LABEL; + return new DataPropertyStatementTemplateModel(getUri(), propertyUri, vreq, policyHelper); + } + public String getMoniker() { return individual.getMoniker(); } @@ -181,14 +200,6 @@ public class IndividualTemplateModel extends BaseTemplateModel { return individual.getURI(); } - public String getDescription() { - return individual.getDescription(); - } - - public String getBlurb() { - return individual.getBlurb(); - } - public List getKeywords() { return individual.getKeywords(); } @@ -202,6 +213,14 @@ public class IndividualTemplateModel extends BaseTemplateModel { return individual.getLocalName(); } - + @Deprecated + public String getDescription() { + return individual.getDescription(); + } + + @Deprecated + public String getBlurb() { + return individual.getBlurb(); + } } diff --git a/webapp/web/edit/editDatapropStmtRequestDispatch.jsp b/webapp/web/edit/editDatapropStmtRequestDispatch.jsp index 4bff231ab..2f3cd1ef7 100644 --- a/webapp/web/edit/editDatapropStmtRequestDispatch.jsp +++ b/webapp/web/edit/editDatapropStmtRequestDispatch.jsp @@ -58,7 +58,7 @@ String command = vreq.getParameter("cmd"); 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 ) { log.error("required subjectUri parameter missing"); diff --git a/webapp/web/templates/freemarker/body/individual/individual.ftl b/webapp/web/templates/freemarker/body/individual/individual.ftl index 94bee1615..d50f07cb0 100644 --- a/webapp/web/templates/freemarker/body/individual/individual.ftl +++ b/webapp/web/templates/freemarker/body/individual/individual.ftl @@ -26,7 +26,9 @@ <#else>

<#-- Label --> - ${individual.name} + <#assign label = individual.nameStatement> + ${label.value} + <@p.editingLinks label editing /> <#-- Moniker --> <#if individual.moniker?has_content> diff --git a/webapp/web/templates/freemarker/lib/lib-datetime.ftl b/webapp/web/templates/freemarker/lib/lib-datetime.ftl index f2e2d36ec..c991b25a2 100644 --- a/webapp/web/templates/freemarker/lib/lib-datetime.ftl +++ b/webapp/web/templates/freemarker/lib/lib-datetime.ftl @@ -101,8 +101,9 @@ <#-- Convert the string dateTimeString to a datetime object --> <#function toDateTime dateTimeString> <#-- First convert the datetime string to a string format that Freemarker - understands, then to a datetime object --> - <#return dateTimeString?replace("T", " ")?replace("Z", "")?datetime("yyyy-MM-dd HH:mm:ss")> + understands, then to a datetime object. For now, strip away a time zone rather + than displaying it. --> + <#return dateTimeString?replace("T", " ")?replace("Z.*$", "", "r")?datetime("yyyy-MM-dd HH:mm:ss")> <#-- Apply a precision and format type to format a datetime -->