Fixing how shor views are found on entityMergedPropsList.jsp NIHVIVO-833
This commit is contained in:
parent
0d39c89da6
commit
bf7240b440
4 changed files with 69 additions and 61 deletions
|
@ -3,7 +3,10 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.web;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -15,6 +18,12 @@ import org.apache.commons.logging.LogFactory;
|
|||
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.impl.ModelCom;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
|
||||
public class MiscWebUtils {
|
||||
/**
|
||||
|
@ -51,7 +60,7 @@ public class MiscWebUtils {
|
|||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets an attribute from the request, if it is not null, and of Class String
|
||||
* print it to req.out, otherwise throw an exception.
|
||||
|
@ -70,7 +79,54 @@ public class MiscWebUtils {
|
|||
}
|
||||
return (String) contentObj;
|
||||
}
|
||||
|
||||
|
||||
// Get custom short view from either the object's class or one of its
|
||||
// superclasses.
|
||||
// This is needed because the inference update happens asynchronously, so
|
||||
// when a new
|
||||
// property has been added and the page is reloaded, the custom short view
|
||||
// from a
|
||||
// superclass may not have been inferred yet.
|
||||
public static String getCustomShortView(HttpServletRequest request) {
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
VClassDao vcDao = vreq.getWebappDaoFactory().getVClassDao();
|
||||
|
||||
String customShortView = null;
|
||||
Individual object = ((ObjectPropertyStatement) request
|
||||
.getAttribute("opStmt")).getObject();
|
||||
List<VClass> vclasses = object.getVClasses(true); // get directly
|
||||
// asserted vclasses
|
||||
Set<String> superClasses = new HashSet<String>();
|
||||
|
||||
// First try directly asserted classes, there is no useful decision
|
||||
// mechanism for
|
||||
// the case where two directly asserted classes have a custom short
|
||||
// view.
|
||||
for (VClass vclass : vclasses) {
|
||||
// Use this class's custom short view, if there is one
|
||||
customShortView = vclass.getCustomShortView();
|
||||
if (customShortView != null) {
|
||||
return customShortView;
|
||||
}
|
||||
// Otherwise, add superclass to list of vclasses to check for custom
|
||||
// short views
|
||||
String vclassUri = vclass.getURI();
|
||||
superClasses.addAll(vcDao.getAllSuperClassURIs(vclassUri));
|
||||
}
|
||||
|
||||
// Next try super classes. There is no useful decision mechanism for
|
||||
// the case where two super classes have a custom short view.
|
||||
for (String superClassUri : superClasses) {
|
||||
VClass vc = vcDao.getVClassByURI(superClassUri);
|
||||
customShortView = vc.getCustomShortView();
|
||||
if (customShortView != null) {
|
||||
return customShortView;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a table of the req attributes
|
||||
* @param req
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue