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
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
</tr>
|
||||
</table>
|
||||
|
||||
<c:if test="true"> <!-- test="${requestScope.user.roleURI == 1 }"> -->
|
||||
<c:if test="${application.selfEditingPolicyWasSetup}"> <!-- test="${requestScope.user.roleURI == 1 }"> -->
|
||||
|
||||
<h3 class="associate">Associate user account with a person</h3>
|
||||
<table class="form-background" border="0" cellpadding="2" cellspacing="2">
|
||||
|
|
|
@ -32,7 +32,8 @@
|
|||
<%@ page import="org.apache.commons.logging.LogFactory" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %>
|
||||
<%@ page import="edu.cornell.mannlib.vedit.beans.LoginFormBean" %>
|
||||
<jsp:useBean id="loginHandler" class="edu.cornell.mannlib.vedit.beans.LoginFormBean" scope="session" />
|
||||
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%><jsp:useBean id="loginHandler" class="edu.cornell.mannlib.vedit.beans.LoginFormBean" scope="session" />
|
||||
<%!
|
||||
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.templates.entity.entityMergedPropsList.jsp");
|
||||
%>
|
||||
|
@ -161,25 +162,13 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.
|
|||
<c:set var="opStmt" value="${objPropertyStmt}" scope="request"/>
|
||||
<c:url var="propertyLink" value="/entity">
|
||||
<c:param name="home" value="${portal.portalId}"/>
|
||||
<c:param name="uri" value="${objPropertyStmt.object.URI}"/>
|
||||
<%--
|
||||
<% ObjectPropertyStatement oStmt = (ObjectPropertyStatement)request.getAttribute("opStmt");
|
||||
if (oStmt!=null) {
|
||||
Individual obj= (Individual)oStmt.getObject();
|
||||
if (obj != null) {
|
||||
if (!obj.doesFlag1Match(currentPortalId)) {%>
|
||||
<c:param name="jump" value="true"/>
|
||||
<% }
|
||||
}
|
||||
}%>
|
||||
--%>
|
||||
<c:param name="uri" value="${objPropertyStmt.object.URI}"/>
|
||||
</c:url>
|
||||
|
||||
<% String customShortView = MiscWebUtils.getCustomShortView(request); %>
|
||||
<c:set var="altRenderJsp" value="<%= customShortView %>" />
|
||||
<c:remove var="opStmt" scope="request"/>
|
||||
<c:forEach items="${objPropertyStmt.object.VClasses}" var="type">
|
||||
<c:if test="${!empty type.customShortView}">
|
||||
<c:set var="altRenderJsp" value="${type.customShortView}"/>
|
||||
</c:if>
|
||||
</c:forEach>
|
||||
|
||||
<c:choose>
|
||||
<c:when test="${!empty altRenderJsp}">
|
||||
<c:set scope="request" var="individual" value="${objPropertyStmt.object}"/>
|
||||
|
|
|
@ -39,7 +39,8 @@
|
|||
<%@ page import="org.apache.commons.logging.LogFactory" %>
|
||||
|
||||
<%@page import="java.util.LinkedList"%>
|
||||
<%@page import="java.util.Set"%><jsp:useBean id="loginHandler" class="edu.cornell.mannlib.vedit.beans.LoginFormBean" scope="session" />
|
||||
<%@page import="java.util.Set"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%><jsp:useBean id="loginHandler" class="edu.cornell.mannlib.vedit.beans.LoginFormBean" scope="session" />
|
||||
<%!
|
||||
public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.templates.entity.entityMergedPropsList.jsp");
|
||||
%>
|
||||
|
@ -191,7 +192,7 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.
|
|||
<c:param name="uri" value="${objPropertyStmt.object.URI}"/>
|
||||
</c:url>
|
||||
<%
|
||||
String customShortView = getCustomShortView(request, vcDao);
|
||||
String customShortView = MiscWebUtils.getCustomShortView(request);
|
||||
%>
|
||||
<c:set var="altRenderJsp" value="<%= customShortView %>" />
|
||||
<c:remove var="opStmt" scope="request"/>
|
||||
|
@ -347,41 +348,3 @@ public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.
|
|||
}
|
||||
} // end for (Property p : g.getPropertyList()
|
||||
%>
|
||||
|
||||
<%!
|
||||
// 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.
|
||||
private String getCustomShortView(HttpServletRequest request, VClassDao vcDao) {
|
||||
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.
|
||||
vclassLoop: 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;
|
||||
}
|
||||
%>
|
||||
|
|
Loading…
Add table
Reference in a new issue