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:
parent
ac97b5792a
commit
1077f283d6
7 changed files with 77 additions and 28 deletions
|
@ -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.Keyword;
|
||||
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;
|
||||
|
||||
public interface IndividualDao extends ObjectSourceIface {
|
||||
|
@ -135,6 +136,8 @@ public interface IndividualDao extends ObjectSourceIface {
|
|||
* @throws InsertException Could not create a URI
|
||||
*/
|
||||
String getUnusedURI(Individual individual) throws InsertException;
|
||||
|
||||
EditLiteral getLabelEditLiteral(String individualUri);
|
||||
|
||||
@Deprecated
|
||||
public abstract Individual getIndividualByExternalId(int externalIdType,
|
||||
|
|
|
@ -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.InsertException;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
||||
|
||||
|
||||
class IndividualDaoFiltering extends BaseFiltering implements IndividualDao{
|
||||
|
@ -242,4 +243,10 @@ class IndividualDaoFiltering extends BaseFiltering implements IndividualDao{
|
|||
return innerIndividualDao.getUnusedURI(individual);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EditLiteral getLabelEditLiteral(String individualUri) {
|
||||
return innerIndividualDao.getLabelEditLiteral(individualUri);
|
||||
}
|
||||
|
||||
}
|
|
@ -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.IndividualDeletionEvent;
|
||||
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 {
|
||||
|
||||
|
@ -1047,5 +1048,20 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -776,12 +776,17 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
|||
}
|
||||
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
|
||||
* label, or NULL if not found.
|
||||
*/
|
||||
public Literal getLabelLiteral(OntResource r) {
|
||||
protected Literal getLabelLiteral(OntResource r) {
|
||||
Literal labelLiteral = null;
|
||||
r.getOntModel().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
|
|
|
@ -29,7 +29,7 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
|
|||
protected String value = null;
|
||||
|
||||
// Used for editing
|
||||
private String dataPropHash = null;
|
||||
protected String dataPropHash = null;
|
||||
//Useful in case additional params to be retrieved for URL
|
||||
private VitroRequest vitroRequest= null;
|
||||
|
||||
|
@ -84,7 +84,7 @@ public class DataPropertyStatementTemplateModel extends PropertyStatementTemplat
|
|||
}
|
||||
|
||||
// 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) ) {
|
||||
action = new DropDataPropStmt(dps);
|
||||
if (policyHelper.isAuthorizedAction(action)) {
|
||||
|
|
|
@ -9,16 +9,21 @@ import org.apache.commons.logging.LogFactory;
|
|||
import org.openrdf.model.URI;
|
||||
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 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.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.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.edit.EditLiteral;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
||||
|
||||
public class NameStatementTemplateModel extends
|
||||
DataPropertyStatementTemplateModel {
|
||||
|
@ -27,43 +32,49 @@ public class NameStatementTemplateModel extends
|
|||
|
||||
/*
|
||||
* 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.
|
||||
* Specifically, it allows rdfs:label to be treated like a data property statement and thus have editing links.
|
||||
*/
|
||||
NameStatementTemplateModel(String subjectUri, VitroRequest vreq, EditingPolicyHelper policyHelper) {
|
||||
super(subjectUri, VitroVocabulary.LABEL, vreq, policyHelper);
|
||||
|
||||
Literal literal = null;
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
|
||||
// Use the same methods to get the label that are used elsewhere in the application, to
|
||||
// guarantee consistent results for individuals with multiple labels.
|
||||
// RY The problem here is we have a WebappDaoFactoryFiltering instead of WebappDaoFactoryJena.
|
||||
if (wdf instanceof WebappDaoFactoryJena) {
|
||||
WebappDaoFactoryJena wdfj = (WebappDaoFactoryJena) wdf;
|
||||
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);
|
||||
}
|
||||
}
|
||||
// NIHVIVO-2466 Use the same methods to get the label that are used elsewhere in the
|
||||
// application, to guarantee consistent results for individuals with multiple labels
|
||||
// across the application.
|
||||
IndividualDao iDao = wdf.getIndividualDao();
|
||||
EditLiteral literal = iDao.getLabelEditLiteral(subjectUri);
|
||||
|
||||
if (literal != null) {
|
||||
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;
|
||||
// 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.
|
||||
// edited directly.)
|
||||
URI uri = new URIImpl(subjectUri);
|
||||
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.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue