NIHVIVO-2466 For individuals with multiple labels, ensure the same label is displayed on the profile page as elsewhere in the application (individuallist pages, menu pages, back end) by using the same method to get the label.

This commit is contained in:
ryounes 2011-06-10 21:37:50 +00:00
parent ac97b5792a
commit 1077f283d6
7 changed files with 77 additions and 28 deletions

View file

@ -10,6 +10,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.Keyword; import edu.cornell.mannlib.vitro.webapp.beans.Keyword;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface; import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface;
public interface IndividualDao extends ObjectSourceIface { public interface IndividualDao extends ObjectSourceIface {
@ -135,6 +136,8 @@ public interface IndividualDao extends ObjectSourceIface {
* @throws InsertException Could not create a URI * @throws InsertException Could not create a URI
*/ */
String getUnusedURI(Individual individual) throws InsertException; String getUnusedURI(Individual individual) throws InsertException;
EditLiteral getLabelEditLiteral(String individualUri);
@Deprecated @Deprecated
public abstract Individual getIndividualByExternalId(int externalIdType, public abstract Individual getIndividualByExternalId(int externalIdType,

View file

@ -19,6 +19,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.InsertException; import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
class IndividualDaoFiltering extends BaseFiltering implements IndividualDao{ class IndividualDaoFiltering extends BaseFiltering implements IndividualDao{
@ -242,4 +243,10 @@ class IndividualDaoFiltering extends BaseFiltering implements IndividualDao{
return innerIndividualDao.getUnusedURI(individual); return innerIndividualDao.getUnusedURI(individual);
} }
@Override
public EditLiteral getLabelEditLiteral(String individualUri) {
return innerIndividualDao.getLabelEditLiteral(individualUri);
}
} }

View file

@ -58,6 +58,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualCreationEvent; import edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualCreationEvent;
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualDeletionEvent; import edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualDeletionEvent;
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualUpdateEvent; import edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualUpdateEvent;
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
public class IndividualDaoJena extends JenaBaseDao implements IndividualDao { public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
@ -1047,5 +1048,20 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
return uri; return uri;
} }
@Override
// This method returns an EditLiteral rather than a Jena Literal, since IndividualDao
// should not reference Jena objects. (However, the problem isn't really solved
// because EditLiteral currently references the Jena API.)
public EditLiteral getLabelEditLiteral(String individualUri) {
Literal literal = getLabelLiteral(individualUri);
if (literal == null) {
return null;
}
String value = literal.getLexicalForm();
String datatype = literal.getDatatypeURI();
String lang = literal.getLanguage();
return new EditLiteral(value, datatype, lang);
}
} }

View file

@ -776,12 +776,17 @@ public class JenaBaseDao extends JenaBaseDaoCon {
} }
return label; return label;
} }
protected Literal getLabelLiteral(String individualUri) {
OntResource resource = webappDaoFactory.getOntModel().createOntResource(individualUri);
return getLabelLiteral(resource);
}
/** /**
* works through list of PREFERRED_LANGUAGES to find an appropriate * works through list of PREFERRED_LANGUAGES to find an appropriate
* label, or NULL if not found. * label, or NULL if not found.
*/ */
public Literal getLabelLiteral(OntResource r) { protected Literal getLabelLiteral(OntResource r) {
Literal labelLiteral = null; Literal labelLiteral = null;
r.getOntModel().enterCriticalSection(Lock.READ); r.getOntModel().enterCriticalSection(Lock.READ);
try { try {

View file

@ -29,7 +29,7 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
protected String value = null; protected String value = null;
// Used for editing // Used for editing
private String dataPropHash = null; protected String dataPropHash = null;
//Useful in case additional params to be retrieved for URL //Useful in case additional params to be retrieved for URL
private VitroRequest vitroRequest= null; private VitroRequest vitroRequest= null;
@ -84,7 +84,7 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
} }
// Determine whether the statement can be deleted // Determine whether the statement can be deleted
// Hack for rdfs:label - the policy doesn't prevent deletion // Hack for rdfs:label - the policy doesn't prevent deletion.
if ( ! propertyUri.equals(VitroVocabulary.LABEL) ) { if ( ! propertyUri.equals(VitroVocabulary.LABEL) ) {
action = new DropDataPropStmt(dps); action = new DropDataPropStmt(dps);
if (policyHelper.isAuthorizedAction(action)) { if (policyHelper.isAuthorizedAction(action)) {

View file

@ -9,16 +9,21 @@ import org.apache.commons.logging.LogFactory;
import org.openrdf.model.URI; import org.openrdf.model.URI;
import org.openrdf.model.impl.URIImpl; import org.openrdf.model.impl.URIImpl;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntResource;
import com.hp.hpl.jena.rdf.model.Literal; 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.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDao;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena; import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
public class NameStatementTemplateModel extends public class NameStatementTemplateModel extends
DataPropertyStatementTemplateModel { DataPropertyStatementTemplateModel {
@ -27,43 +32,49 @@ public class NameStatementTemplateModel extends
/* /*
* This method handles the special case where we are creating a DataPropertyStatementTemplateModel outside the GroupedPropertyList. * 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 * Specifically, it allows rdfs:label to be treated like a data property statement and thus have editing links.
* 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) { NameStatementTemplateModel(String subjectUri, VitroRequest vreq, EditingPolicyHelper policyHelper) {
super(subjectUri, VitroVocabulary.LABEL, vreq, policyHelper); super(subjectUri, VitroVocabulary.LABEL, vreq, policyHelper);
Literal literal = null;
WebappDaoFactory wdf = vreq.getWebappDaoFactory(); WebappDaoFactory wdf = vreq.getWebappDaoFactory();
// Use the same methods to get the label that are used elsewhere in the application, to // NIHVIVO-2466 Use the same methods to get the label that are used elsewhere in the
// guarantee consistent results for individuals with multiple labels. // application, to guarantee consistent results for individuals with multiple labels
// RY The problem here is we have a WebappDaoFactoryFiltering instead of WebappDaoFactoryJena. // across the application.
if (wdf instanceof WebappDaoFactoryJena) { IndividualDao iDao = wdf.getIndividualDao();
WebappDaoFactoryJena wdfj = (WebappDaoFactoryJena) wdf; EditLiteral literal = iDao.getLabelEditLiteral(subjectUri);
OntResource resource = wdfj.getOntModel().createOntResource(subjectUri);
JenaBaseDao baseDao = wdfj.getJenaBaseDao();
literal = baseDao.getLabelLiteral(resource);
} else {
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 = literals.get(0);
}
}
if (literal != null) { if (literal != null) {
value = literal.getLexicalForm(); value = literal.getLexicalForm();
setEditAccess(literal, policyHelper); setEditAccess(literal, policyHelper);
} else { } else {
// If the individual has no rdfs:label, use the local name. It will not be editable (this replicates previous behavior; // 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 // perhaps we would want to allow a label to be added. But such individuals do not usually have their profiles viewed or
// edited directly. // edited directly.)
URI uri = new URIImpl(subjectUri); URI uri = new URIImpl(subjectUri);
value = uri.getLocalName(); value = uri.getLocalName();
} }
} }
protected void setEditAccess(EditLiteral value, EditingPolicyHelper policyHelper) {
if (policyHelper != null) { // we're editing
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));
// Determine whether the statement can be edited
RequestedAction action = new EditDataPropStmt(dps);
if (policyHelper.isAuthorizedAction(action)) {
markEditable();
}
// The label cannot be deleted, so we don't need to check
// the policy for the delete action.
}
}
} }

View file

@ -14,6 +14,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Keyword;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.InsertException; import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
/** /**
* A minimal implementation of the IndividualDao. * A minimal implementation of the IndividualDao.
@ -237,4 +238,10 @@ public class IndividualDaoStub implements IndividualDao {
"IndividualDaoStub.getIndividualByExternalId() not implemented."); "IndividualDaoStub.getIndividualByExternalId() not implemented.");
} }
@Override
public EditLiteral getLabelEditLiteral(String individualUri) {
throw new RuntimeException(
"IndividualDaoStub.getLabelLiteral() not implemented.");
}
} }