NIHVIVO-2466 Prepare for special handling of rdfs:label in property display on profile page

This commit is contained in:
ryounes 2011-06-03 19:59:15 +00:00
parent 452510b1a4
commit bcf889028b
4 changed files with 57 additions and 19 deletions

View file

@ -6,8 +6,6 @@ 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.auth.policy.PolicyHelper;
@ -132,18 +130,8 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
* DataProperty from it. It cannot be handled the way the vitro links and vitro public image
* are handled like ordinary ObjectProperty instances.
*/
public DataPropertyStatementTemplateModel getNameStatement() {
String propertyUri = VitroVocabulary.LABEL; // rdfs:label
DataPropertyStatementTemplateModel dpstm = new DataPropertyStatementTemplateModel(getUri(), propertyUri, vreq, policyHelper);
// If the individual has no rdfs:label, return the local name. It will not be editable (this replicates previous behavior;
// perhaps we would want to allow a label to be added. But such individuals do not usually have their profiles viewed or
// edited directly.
if (dpstm.getValue() == null) {
dpstm.setValue(getLocalName());
}
return dpstm;
public NameStatementTemplateModel getNameStatement() {
return new NameStatementTemplateModel(getUri(), vreq, policyHelper);
}
/* These methods simply forward to the methods of the wrapped individual. It would be desirable to

View file

@ -26,7 +26,7 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
private static final Log log = LogFactory.getLog(DataPropertyStatementTemplateModel.class);
private static final String EDIT_PATH = "edit/editDatapropStmtRequestDispatch.jsp";
private String value = null;
protected String value = null;
// Used for editing
private String dataPropHash = null;
@ -64,7 +64,7 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
this.value = value;
}
private void setEditAccess(Literal value, EditingPolicyHelper policyHelper) {
protected void setEditAccess(Literal value, EditingPolicyHelper policyHelper) {
if (policyHelper != null) { // we're editing
DataPropertyStatement dps = new DataPropertyStatementImpl(subjectUri, propertyUri, value.getLexicalForm());

View file

@ -0,0 +1,50 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
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 com.hp.hpl.jena.rdf.model.Literal;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
public class NameStatementTemplateModel extends
DataPropertyStatementTemplateModel {
private static final Log log = LogFactory.getLog(NameStatementTemplateModel.class);
/*
* This method handles the special case where we are creating a DataPropertyStatementTemplateModel outside the GroupedPropertyList.
* Specifically, it allows rdfs:label to be treated like a data property statement and thus have editing links. It is not possible
* to handle rdfs:label like vitro links and vitroPublic image, because it is not possible to construct a DataProperty from
* rdfs:label.
*/
NameStatementTemplateModel(String subjectUri, VitroRequest vreq, EditingPolicyHelper policyHelper) {
super(subjectUri, VitroVocabulary.LABEL, vreq, policyHelper);
DataPropertyStatementDao dpsDao = vreq.getWebappDaoFactory().getDataPropertyStatementDao();
List<Literal> literals = dpsDao.getDataPropertyValuesForIndividualByProperty(subjectUri, VitroVocabulary.LABEL);
// Make sure the subject has a value for this property
if (literals.size() > 0) {
Literal literal = literals.get(0);
value = literal.getLexicalForm();
setEditAccess(literal, policyHelper);
} else {
// If the individual has no rdfs:label, use the local name. It will not be editable (this replicates previous behavior;
// perhaps we would want to allow a label to be added. But such individuals do not usually have their profiles viewed or
// edited directly.
URI uri = new URIImpl(subjectUri);
value = uri.getLocalName();
}
}
}

View file

@ -107,7 +107,7 @@ public class UserAccountsDaoJenaTest extends AbstractTestClass {
@Test
public void getUserAccountByUriWrongType() {
UserAccount u = dao.getUserAccountByUri(URI_ROLE1);
System.out.println(u);
//System.out.println(u);
assertNull("null result", u);
}
@ -329,7 +329,7 @@ public class UserAccountsDaoJenaTest extends AbstractTestClass {
StmtIterator stmts = ontModel.listStatements();
while (stmts.hasNext()) {
Statement stmt = stmts.next();
System.out.println(formatStatement(stmt));
//System.out.println(formatStatement(stmt));
}
}