From 47b5e4ae52771b1bc7530017ce2f0f200bdfe4a0 Mon Sep 17 00:00:00 2001 From: rjy7 Date: Fri, 4 Mar 2011 19:24:27 +0000 Subject: [PATCH] NIHVIVO-1554 Removed controllers and jsps that have been superceded by Freemarker controllers and templates --- webapp/config/web.xml | 23 - .../vitro/webapp/beans/ObjectProperty.java | 3 - .../webapp/controller/AboutController.java | 50 -- .../webapp/controller/BrowseController.java | 331 ------- .../webapp/controller/CommentsController.java | 89 -- .../vitro/webapp/controller/Controllers.java | 28 +- .../webapp/controller/EntityController.java | 720 --------------- .../controller/EntityListController.java | 321 ------- .../EntityMergedPropertyListController.java | 823 ------------------ .../EntityPropertyListController.java | 74 -- .../vitro/webapp/controller/JSONServlet.java | 10 +- .../webapp/controller/OntologyController.java | 1 - .../freemarker/IndividualListController.java | 173 +++- .../jena/TabIndividualRelationDaoJena.java | 23 +- .../controller/PagedSearchController.java | 640 -------------- .../search/controller/SearchController.java | 648 -------------- .../controller/EntityControllerTest.java | 26 - webapp/web/templates/browse/browseGroup.jsp | 89 -- .../templates/browse/portalFlagChoices.jsp | 201 ----- webapp/web/templates/entity/entityAdmin.jsp | 48 - webapp/web/templates/entity/entityBasic.jsp | 315 ------- .../web/templates/entity/entityCitation.jsp | 20 - .../templates/entity/entityKeywordsList.jsp | 62 -- webapp/web/templates/entity/entityList.jsp | 108 --- .../entity/entityListForGalleryTab.jsp | 61 -- .../entity/entityMergedPropsList.jsp | 401 --------- .../entity/entityMergedPropsListUngrouped.jsp | 336 ------- .../templates/entity/entity_inject_head.jsp | 47 - webapp/web/templates/entity/linkShortView.jsp | 54 -- webapp/web/templates/parts/search_error.jsp | 10 - webapp/web/templates/parts/thankyou.jsp | 28 - .../web/templates/search/searchBadQuery.jsp | 35 - webapp/web/templates/search/searchBasic.jsp | 157 ---- webapp/web/templates/search/searchFailed.jsp | 35 - webapp/web/templates/search/searchForm.jsp | 45 - webapp/web/templates/search/searchGroup.jsp | 54 -- webapp/web/templates/search/searchPaged.jsp | 177 ---- webapp/web/templates/search/searchTips.jsp | 18 - 38 files changed, 183 insertions(+), 6101 deletions(-) delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/controller/AboutController.java delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/controller/BrowseController.java delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/controller/CommentsController.java delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityController.java delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityListController.java delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityMergedPropertyListController.java delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityPropertyListController.java delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java delete mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/SearchController.java delete mode 100644 webapp/test/edu/cornell/mannlib/vitro/webapp/controller/EntityControllerTest.java delete mode 100644 webapp/web/templates/browse/browseGroup.jsp delete mode 100644 webapp/web/templates/browse/portalFlagChoices.jsp delete mode 100644 webapp/web/templates/entity/entityAdmin.jsp delete mode 100644 webapp/web/templates/entity/entityBasic.jsp delete mode 100644 webapp/web/templates/entity/entityCitation.jsp delete mode 100644 webapp/web/templates/entity/entityKeywordsList.jsp delete mode 100644 webapp/web/templates/entity/entityList.jsp delete mode 100644 webapp/web/templates/entity/entityListForGalleryTab.jsp delete mode 100644 webapp/web/templates/entity/entityMergedPropsList.jsp delete mode 100644 webapp/web/templates/entity/entityMergedPropsListUngrouped.jsp delete mode 100644 webapp/web/templates/entity/entity_inject_head.jsp delete mode 100644 webapp/web/templates/entity/linkShortView.jsp delete mode 100755 webapp/web/templates/parts/search_error.jsp delete mode 100644 webapp/web/templates/parts/thankyou.jsp delete mode 100644 webapp/web/templates/search/searchBadQuery.jsp delete mode 100644 webapp/web/templates/search/searchBasic.jsp delete mode 100644 webapp/web/templates/search/searchFailed.jsp delete mode 100644 webapp/web/templates/search/searchForm.jsp delete mode 100644 webapp/web/templates/search/searchGroup.jsp delete mode 100644 webapp/web/templates/search/searchPaged.jsp delete mode 100644 webapp/web/templates/search/searchTips.jsp diff --git a/webapp/config/web.xml b/webapp/config/web.xml index d86552d52..817f4b5d9 100644 --- a/webapp/config/web.xml +++ b/webapp/config/web.xml @@ -1124,29 +1124,6 @@ 5 - - ontology edu.cornell.mannlib.vitro.webapp.controller.OntologyController diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/ObjectProperty.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/ObjectProperty.java index f33e1d1fe..f34d64ae3 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/ObjectProperty.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/ObjectProperty.java @@ -10,7 +10,6 @@ import java.util.Date; import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -19,8 +18,6 @@ import org.openrdf.model.impl.URIImpl; import com.hp.hpl.jena.datatypes.xsd.XSDDatatype; -import edu.cornell.mannlib.vitro.webapp.controller.EntityController; - /** * a class representing an object property * diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/AboutController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/AboutController.java deleted file mode 100644 index d01a807d2..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/AboutController.java +++ /dev/null @@ -1,50 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.controller; - -import java.io.IOException; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import edu.cornell.mannlib.vitro.webapp.beans.Portal; - -public class AboutController extends VitroHttpServlet { - - private static final Log log = LogFactory.getLog(AboutController.class.getName()); - - public void doGet( HttpServletRequest request, HttpServletResponse response ) - throws IOException, ServletException { - try { - super.doGet(request,response); - VitroRequest vreq = new VitroRequest(request); - Portal portal = vreq.getPortal(); - - request.setAttribute("title", "About " + portal.getAppName()); - request.setAttribute("aboutText", portal.getAboutText()); - request.setAttribute("acknowledgeText", portal.getAcknowledgeText()); - request.setAttribute("bodyJsp", "/about.jsp"); - - RequestDispatcher rd = - request.getRequestDispatcher(Controllers.BASIC_JSP); - rd.forward(request, response); - - } catch (Throwable e) { - log.error("AboutController could not forward to view."); - log.error(e.getMessage()); - log.error(e.getStackTrace()); - } - } - - public void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - doGet(request, response); - } - - -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/BrowseController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/BrowseController.java deleted file mode 100644 index 77ab06f0b..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/BrowseController.java +++ /dev/null @@ -1,331 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.controller; - -import com.hp.hpl.jena.ontology.OntModel; -import com.hp.hpl.jena.rdf.listeners.StatementListener; -import com.hp.hpl.jena.rdf.model.Statement; -import com.hp.hpl.jena.vocabulary.RDF; -import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean; -import edu.cornell.mannlib.vitro.webapp.beans.Portal; -import edu.cornell.mannlib.vitro.webapp.beans.VClass; -import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; -import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao; -import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; -import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; -import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering; -import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils; -import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters; -import edu.cornell.mannlib.vitro.webapp.flags.PortalFlag; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.joda.time.DateTime; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; - - -public class BrowseController extends VitroHttpServlet { - static final long serialVersionUID=2006030721126L; - - private transient ConcurrentHashMap _groupListMap - = new ConcurrentHashMap(); - private transient ConcurrentLinkedQueue _rebuildQueue - = new ConcurrentLinkedQueue(); - private RebuildGroupCacheThread _cacheRebuildThread; - - private static final Log log = LogFactory.getLog(BrowseController.class.getName()); - - public void init(javax.servlet.ServletConfig servletConfig) - throws javax.servlet.ServletException { - super.init(servletConfig); - ServletContext sContext = servletConfig.getServletContext(); - - //BJL23: I'll work on a strategy for avoiding all this craziness. - OntModel model = (OntModel)sContext.getAttribute("jenaOntModel"); - OntModel baseModel = (OntModel)sContext.getAttribute("baseOntModel"); - OntModel infModel = (OntModel)sContext.getAttribute("inferenceOntModel"); - - BrowseControllerChangeListener bccl = new BrowseControllerChangeListener(this); - model.register(bccl); - baseModel.register(bccl); - infModel.register(bccl); - - _rebuildQueue.add(REBUILD_EVERY_PORTAL); - _cacheRebuildThread = new RebuildGroupCacheThread(this); - _cacheRebuildThread.setDaemon(true); - _cacheRebuildThread.start(); - _cacheRebuildThread.informOfQueueChange(); - } - - public void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException,IOException { - doGet(request, response); - } - - /** - * @author bdc34 adapted by jc55 - */ - public void doGet( HttpServletRequest request, HttpServletResponse response ) - throws IOException, ServletException { - try { - //call doGet of super-class (that would be VitroHttpServlet). - super.doGet(request, response); - VitroRequest vreq = new VitroRequest(request); - - if( vreq.getParameter("clearcache") != null ) //mainly for debugging - clearGroupCache(); - - PortalFlag portalState= vreq.getPortalFlag(); - - List groups = getGroups(vreq.getWebappDaoFactory().getVClassGroupDao(), vreq.getPortal().getPortalId()); - if( groups == null || groups.isEmpty() ) - request.setAttribute("classgroupsIsEmpty", true); - - - // stick the data in the requestScope - request.setAttribute("classgroups",groups); - request.setAttribute("portalState",portalState); - - request.setAttribute("title","Index to "+vreq.getPortal().getAppName()+" Contents"); - - request.setAttribute("bodyJsp",Controllers.BROWSE_GROUP_JSP); - //request.setAttribute("bodyJsp",Controllers.DEBUG_JSP); - - //FINALLY: send off to the BASIC_JSP to get turned into HTML - RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); - // run directly to body for testing: RequestDispatcher rd = request.getRequestDispatcher(Controllers.BROWSE_GROUP_JSP); - rd.forward(request, response); - } catch (Throwable e) { - log.debug("BrowseController.doGet(): "+ e); - request.setAttribute("javax.servlet.jsp.jspException",e); - RequestDispatcher rd = request.getRequestDispatcher("/error.jsp"); - rd.forward(request, response); - } - } - - public void destroy(){ - _cacheRebuildThread.kill(); - } - - private List getGroups( VClassGroupDao vcgDao, int portalId ){ - List grp = _groupListMap.get(portalId); - if( grp == null ){ - log.debug("needed to build vclassGroups for portal " + portalId); - // Get all classgroups, each populated with a list of their member vclasses - List groups = vcgDao.getPublicGroupsWithVClasses(ORDER_BY_DISPLAYRANK, !INCLUDE_UNINSTANTIATED, INCLUDE_ENTITY_COUNT); - - // now cull out the groups with no populated classes - //removeUnpopulatedClasses( groups); - vcgDao.removeUnpopulatedGroups(groups); - - _groupListMap.put(portalId, groups); - return groups; - } else { - return grp; - } - } - - private static boolean ORDER_BY_DISPLAYRANK = true; - private static boolean INCLUDE_UNINSTANTIATED = true; - private static boolean INCLUDE_ENTITY_COUNT = true; - -// private void removeUnpopulatedClasses( List groups){ -// if( groups == null || groups.size() == 0 ) return; -// for( VClassGroup grp : groups ){ -// ListIterator it = grp.listIterator(); -// while(it.hasNext()){ -// VClass claz = (VClass)it.next(); -// if( claz.getEntityCount() < 1 ) -// it.remove(); -// } -// } -// } - - void requestCacheUpdate(String portalUri){ - log.debug("requesting update for portal " + portalUri); - _rebuildQueue.add(portalUri); - _cacheRebuildThread.informOfQueueChange(); - } - - protected synchronized void refreshGroupCache() { - long start = System.currentTimeMillis(); - try{ - boolean rebuildAll = false; - HashSet portalURIsToRebuild = new HashSet(); - String portalUri; - while ( null != (portalUri = _rebuildQueue.poll()) ){ - if( portalUri.equals(REBUILD_EVERY_PORTAL)){ - rebuildAll = true; - _rebuildQueue.clear(); - break; - }else{ - portalURIsToRebuild.add(portalUri); - } - } - - ServletContext sContext = getServletConfig().getServletContext(); - ApplicationBean appBean = new ApplicationBean(); - WebappDaoFactory wdFactory = (WebappDaoFactory)sContext.getAttribute("webappDaoFactory"); - if( wdFactory == null ){ - log.error("Unable to rebuild cache: could not get 'webappDaoFactory' from Servletcontext"); - return; - } - - Collection portals; - if( rebuildAll ){ - portals = wdFactory.getPortalDao().getAllPortals(); - } else { - portals = new LinkedList(); - for( String uri : portalURIsToRebuild){ - Portal p =wdFactory.getPortalDao().getPortalByURI(uri); - if( p!= null) - portals.add(wdFactory.getPortalDao().getPortalByURI(uri)); - } - } - - for(Portal portal : portals){ - rebuildCacheForPortal(portal,appBean,wdFactory); - } - log.info("rebuilt ClassGroup cache in " + (System.currentTimeMillis() - start) + " msec"); - }catch (Exception ex){ - log.error("could not rebuild cache", ex); - } - } - - protected synchronized void rebuildCacheForPortalUri(String uri){ - ServletContext sContext = getServletConfig().getServletContext(); - WebappDaoFactory wdFactory = (WebappDaoFactory)sContext.getAttribute("webappDaoFactory"); - if( wdFactory == null ){ - log.error("Unable to rebuild cache: could not get 'webappDaoFactory' from Servletcontext"); - return; - } - ApplicationBean appBean = new ApplicationBean(); - Portal portal = wdFactory.getPortalDao().getPortalByURI(uri); - rebuildCacheForPortal(portal,appBean,wdFactory); - } - - protected synchronized void rebuildCacheForPortal(Portal portal, ApplicationBean appBean, WebappDaoFactory wdFactory){ - VitroFilters vFilters = null; - - if( portal.isFlag1Filtering() ){ - PortalFlag pflag = new PortalFlag(portal.getPortalId()); - if( vFilters == null) - vFilters = VitroFilterUtils.getFilterFromPortalFlag(pflag); - else - vFilters = vFilters.and( VitroFilterUtils.getFilterFromPortalFlag(pflag)); - } - WebappDaoFactory filteringDaoFactory ; - if( vFilters !=null ){ - filteringDaoFactory = new WebappDaoFactoryFiltering(wdFactory,vFilters); - }else{ - filteringDaoFactory = wdFactory; - } - _groupListMap.remove(portal.getPortalId()); - getGroups(filteringDaoFactory.getVClassGroupDao(),portal.getPortalId()); - } - - private void clearGroupCache(){ - _groupListMap = new ConcurrentHashMap(); - } - - /* ****************** Jena Model Change Listener***************************** */ - private class BrowseControllerChangeListener extends StatementListener { - private BrowseController controller = null; - public BrowseControllerChangeListener(BrowseController controller){ - this.controller=controller; - } - - public void addedStatement(Statement stmt) { - checkAndDoUpdate(stmt); - } - - public void removedStatement(Statement stmt) { - checkAndDoUpdate(stmt); - } - - private void checkAndDoUpdate(Statement stmt){ - if( stmt==null ) return; - if( log.isDebugEnabled()){ - log.debug("subject: " + stmt.getSubject().getURI()); - log.debug("predicate: " + stmt.getPredicate().getURI()); - } - if( RDF.type.getURI().equals( stmt.getPredicate().getURI()) ){ - requestCacheUpdate(REBUILD_EVERY_PORTAL); - } else if( VitroVocabulary.PORTAL_FLAG1FILTERING.equals( stmt.getPredicate().getURI())){ - requestCacheUpdate(stmt.getSubject().getURI()); - } else if( VitroVocabulary.IN_CLASSGROUP.equals( stmt.getPredicate().getURI() )){ - requestCacheUpdate(REBUILD_EVERY_PORTAL); - } - } - } - /* ******************** RebuildGroupCacheThread **************** */ - protected class RebuildGroupCacheThread extends Thread { - BrowseController controller; - boolean die = false; - boolean queueChange = false; - long queueChangeMills = 0; - private boolean awareOfQueueChange = false; - - RebuildGroupCacheThread(BrowseController controller) { - super("RebuildGroupCacheThread"); - this.controller = controller; - } - public void run() { - while(true){ - try{ - synchronized (this){ - if( _rebuildQueue.isEmpty() ){ - log.debug("rebuildGroupCacheThread.run() -- queye empty, sleep"); - wait(1000 * 60 ); - } - if( die ) { - log.debug("doing rebuildGroupCacheThread.run() -- die()"); - return; - } - if( queueChange && !awareOfQueueChange){ - log.debug("rebuildGroupCacheThread.run() -- awareOfQueueChange, delay start of rebuild"); - awareOfQueueChange = true; - wait(200); - } - } - - if( awareOfQueueChange && System.currentTimeMillis() - queueChangeMills > 200){ - log.debug("rebuildGroupCacheThread.run() -- refreshGroupCache()"); - controller.refreshGroupCache(); - synchronized( this){ - queueChange = false; - } - awareOfQueueChange = false; - }else { - synchronized( this ){ - wait(200); - } - } - } catch(InterruptedException e){} - } - - - } - - synchronized void informOfQueueChange(){ - queueChange = true; - queueChangeMills = System.currentTimeMillis(); - this.notifyAll(); - } - - synchronized void kill(){ - die = true; - notifyAll(); - } - } - - protected static String REBUILD_EVERY_PORTAL ="Rebuild every portal."; -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/CommentsController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/CommentsController.java deleted file mode 100644 index dc21bfd12..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/CommentsController.java +++ /dev/null @@ -1,89 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.controller; - -import java.io.IOException; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean; -import edu.cornell.mannlib.vitro.webapp.beans.Portal; -import edu.cornell.mannlib.vitro.webapp.controller.ContactMailServlet; - -/** - * Controller for comments ("contact us") page - * * @author bjl23 - */ -public class CommentsController extends VitroHttpServlet{ - - @Override - public void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - doGet(request, response); - } - - @Override - public void doGet( HttpServletRequest request, HttpServletResponse response ) - throws IOException, ServletException { - super.doGet(request,response); - VitroRequest vreq = new VitroRequest(request); - try { - //this try block passes any errors to error.jsp - if (!ContactMailServlet.isSmtpHostConfigured(request)) { - request.setAttribute("title", "Comments and Feedback Form"); - request.setAttribute("bodyJsp", "/contact_err.jsp");// <<< this is where the body gets set - request.setAttribute("ERR","This application has not yet been configured to send mail -- " + - "smtp host has not been specified in the configuration properties file."); - RequestDispatcher errd = request.getRequestDispatcher(Controllers.BASIC_JSP); - errd.forward(request, response); - } - ApplicationBean appBean=vreq.getAppBean(); - Portal portalBean=vreq.getPortal(); - - if ( (appBean.getMaxSharedPortalId()-appBean.getMinSharedPortalId()) > 1 - && ( (portalBean.getPortalId() >= appBean.getMinSharedPortalId() - && portalBean.getPortalId() <= appBean.getMaxSharedPortalId() ) - || portalBean.getPortalId() == appBean.getSharedPortalFlagNumeric() ) - ) { - request.setAttribute("portalType","CALSResearch"); - } else - if (portalBean.getAppName().equalsIgnoreCase("CALS Impact")){ - request.setAttribute("portalType", "CALSImpact"); - } else if (portalBean.getAppName().equalsIgnoreCase("VIVO")) { - request.setAttribute("portalType", "VIVO"); - } else { - request.setAttribute("portalType", "clone"); - } - - request.setAttribute("siteName",portalBean.getAppName()); - request.setAttribute("scripts","/js/commentsForm.jsp"); - - if (request.getHeader("Referer") == null) - request.getSession().setAttribute("commentsFormReferer","none"); - else - request.getSession().setAttribute("commentsFormReferer",request.getHeader("Referer")); - - - request.setAttribute("portalId",Integer.valueOf(portalBean.getPortalId())); - - request.setAttribute("title", portalBean.getAppName()+" Comments and Feedback Form"); - request.setAttribute("bodyJsp", "/commentsForm.jsp");// <<< this is where the body gets set - request.setAttribute("portalBean",portalBean); - - RequestDispatcher rd = - request.getRequestDispatcher(Controllers.BASIC_JSP); - rd.forward(request, response); - - } catch (Throwable e) { - // This is how we use an error.jsp - //it expects javax.servlet.jsp.jspException to be set to the - //exception so that it can display the info out of that. - request.setAttribute("javax.servlet.jsp.jspException", e); - RequestDispatcher rd = request.getRequestDispatcher("/error.jsp"); - rd.include(request, response); - } - } -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/Controllers.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/Controllers.java index 8c755addd..c2b22abac 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/Controllers.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/Controllers.java @@ -22,13 +22,9 @@ public class Controllers { public static final String ABOUT = "/about"; public static final String CONTACT_URL = "/comments"; public static final String TERMS_OF_USE_URL = "/termsOfUse"; - public static final String SEARCH_URL = "/search"; - + public static final String SEARCH_URL = "/search"; public static final String ENTITY = "/entity"; - public static final String ENTITY_PROP_LIST = "/entityPropList"; - public static final String ENTITY_LIST = "/entitylist"; - public static final String BROWSE_CONTROLLER = "browsecontroller"; public static final String RETRY_URL = "editForm"; public static final String TAB_ENTITIES = "/TabEntitiesController"; @@ -43,26 +39,16 @@ public class Controllers { public static final String TAB = "/index.jsp"; - public static final String BASIC_JSP = "/templates/page/basicPage.jsp"; public static final String DEBUG_JSP = "/templates/page/debug.jsp"; public static final Object BODY_MSG = "/templates/page/bodyMsg.jsp"; - public static final String ENTITY_JSP = "/templates/entity/entityBasic.jsp"; - public static final String ENTITY_PROP_LIST_JSP = "templates/entity/entityPropsList.jsp"; - public static final String ENTITY_DATAPROP_LIST_JSP = "templates/entity/entityDatapropsList.jsp"; - public static final String ENTITY_MERGED_PROP_LIST_GROUPED_JSP = "templates/entity/entityMergedPropsList.jsp"; public static final String DASHBOARD_PROP_LIST_JSP = "edit/dashboardPropsList.jsp"; - public static final String ENTITY_MERGED_PROP_LIST_UNGROUPED_JSP = "templates/entity/entityMergedPropsListUngrouped.jsp"; - - public static final String ENTITY_KEYWORDS_LIST_JSP = "templates/entity/entityKeywordsList.jsp"; public static final String ENTITY_EDITABLE_JSP = "templates/entity/entityEditable.jsp"; public static final String ENTITY_EDITABLE_PROP_LIST_JSP = "templates/entity/entityEditablePropsList.jsp"; - public static final String ENTITY_LIST_JSP = "templates/entity/entityList.jsp"; public static final String ENTITY_LIST_FOR_TABS_JSP = "templates/entity/entityListForTabs.jsp"; - public static final String TAB_ENTITIES_LIST_GALLERY_JSP = "templates/entity/entityListForGalleryTab.jsp"; public static final String ENTITY_NOT_FOUND_JSP = "templates/error/entityNotFound.jsp"; public static final String TAB_BASIC_JSP = "/templates/tabs/tabBasic.jsp"; @@ -70,15 +56,6 @@ public class Controllers { public static final String ALPHA_INDEX_JSP = "/templates/alpha/alphaIndex.jsp"; - public static final String SEARCH_BASIC_JSP = "/templates/search/searchBasic.jsp"; - public static final String SEARCH_PAGED_JSP = "/templates/search/searchPaged.jsp"; - public static final String SEARCH_FAILED_JSP = "/templates/search/searchFailed.jsp"; - public static final String SEARCH_GROUP_JSP = "/templates/search/searchGroup.jsp"; - public static final Object SEARCH_FORM_JSP = "/templates/search/searchForm.jsp"; - public static final Object SEARCH_BAD_QUERY_JSP = "/templates/search/searchBadQuery.jsp"; - - public static final String BROWSE_GROUP_JSP = "/templates/browse/browseGroup.jsp"; - public static final String HORIZONTAL_JSP = "/templates/edit/fetch/horizontal.jsp"; public static final String VERTICAL_JSP = "/templates/edit/fetch/vertical.jsp"; @@ -88,9 +65,6 @@ public class Controllers { public static final String VCLASS_RETRY_URL = "vclass_retry"; public static final String TOGGLE_SCRIPT_ELEMENT = ""; - - public static final Object SEARCH_ERROR_JSP = "/templates/parts/search_error.jsp"; - //public static final String TAB_ENTITIES_LIST_JSP = "templates/tab/tabEntities.jsp"; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityController.java deleted file mode 100644 index 87808c552..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityController.java +++ /dev/null @@ -1,720 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.controller; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import com.hp.hpl.jena.datatypes.TypeMapper; -import com.hp.hpl.jena.ontology.OntModel; -import com.hp.hpl.jena.rdf.model.Literal; -import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.rdf.model.ModelFactory; -import com.hp.hpl.jena.rdf.model.Property; -import com.hp.hpl.jena.rdf.model.RDFNode; -import com.hp.hpl.jena.rdf.model.Resource; -import com.hp.hpl.jena.shared.Lock; -import com.hp.hpl.jena.vocabulary.RDF; -import com.hp.hpl.jena.vocabulary.RDFS; - -import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean; -import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; -import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; -import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; -import edu.cornell.mannlib.vitro.webapp.beans.Portal; -import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration; -import edu.cornell.mannlib.vitro.webapp.beans.VClass; -import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; -import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao; -import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo; -import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQuery; -import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQueryWrapper; -import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper; -import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory; -import edu.cornell.mannlib.vitro.webapp.web.ContentType; -import edu.cornell.mannlib.vitro.webapp.web.jsptags.StringProcessorTag; - -/** - * Handles requests for entity information. - * Calls EntityPropertyListController to draw property list. - * - * @author bdc34 - * - */ -public class EntityController extends VitroHttpServlet { - private static final Log log = LogFactory.getLog(EntityController.class.getName()); - - private String default_jsp = Controllers.BASIC_JSP; - private String default_body_jsp = Controllers.ENTITY_JSP; - private ApplicationBean appBean; - - public void doGet( HttpServletRequest req, HttpServletResponse res ) - throws IOException, ServletException { - try { - super.doGet(req, res); - - VitroRequest vreq = new VitroRequest(req); - //get URL without hostname or servlet context - String url = req.getRequestURI().substring(req.getContextPath().length()); - - //Check to see if the request is for a non-information resource, redirect if it is. - String redirectURL = checkForRedirect ( url, req.getHeader("accept") ); - if( redirectURL != null ){ - doRedirect( req, res, redirectURL ); - return; - } - - ContentType rdfFormat = checkForLinkedDataRequest(url,req.getHeader("accept")); - if( rdfFormat != null ){ - doRdf( vreq, res, rdfFormat ); - return; - } - - Individual indiv = null; - try{ - indiv = getEntityFromRequest( vreq); - }catch(Throwable th){ - doHelp(res); - return; - } - - if( indiv == null || checkForHidden(vreq, indiv) || checkForSunset(vreq, indiv)){ - doNotFound(vreq, res); - return; - } - - // If this is an uploaded file, redirect to its "alias URL". - String aliasUrl = getAliasUrlForBytestreamIndividual(req, indiv); - if (aliasUrl != null) { - res.sendRedirect(req.getContextPath() + aliasUrl); - return; - } - - doHtml( vreq, res , indiv); - return; - - } catch (Throwable e) { - log.error(e, e); - req.setAttribute("javax.servlet.jsp.jspException",e); - RequestDispatcher rd = req.getRequestDispatcher("/error.jsp"); - rd.forward(req, res); - } - } - - private void doHtml(VitroRequest vreq, HttpServletResponse res, Individual indiv) throws ServletException, IOException { - IndividualDao iwDao = vreq.getWebappDaoFactory().getIndividualDao(); - ObjectPropertyDao opDao = vreq.getWebappDaoFactory().getObjectPropertyDao(); - - //Check if a "relatedSubjectUri" parameter has been supplied, and, - //if so, retrieve the related individual.t - //Some individuals make little sense standing alone and should - //be displayed in the context of their relationship to another. - String relatedSubjectUri = vreq.getParameter("relatedSubjectUri"); - if (relatedSubjectUri != null) { - Individual relatedSubjectInd = iwDao.getIndividualByURI(relatedSubjectUri); - if (relatedSubjectInd != null) { - vreq.setAttribute("relatedSubject", relatedSubjectInd); - } - } - String relatingPredicateUri = vreq.getParameter("relatingPredicateUri"); - if (relatingPredicateUri != null) { - ObjectProperty relatingPredicateProp = opDao.getObjectPropertyByURI(relatingPredicateUri); - if (relatingPredicateProp != null) { - vreq.setAttribute("relatingPredicate", relatingPredicateProp); - } - } - - indiv.setKeywords(iwDao.getKeywordsForIndividualByMode(indiv.getURI(),"visible")); - indiv.sortForDisplay(); - - String vclassName = "unknown"; - String customView = null; - String customCss = null; - if( indiv.getVClass() != null ){ - vclassName = indiv.getVClass().getName(); - List clasList = indiv.getVClasses(true); - for (VClass clas : clasList) { - customView = clas.getCustomDisplayView(); - if (customView != null) { - if (customView.length()>0) { - vclassName = clas.getName(); // reset entity vclassname to name of class where a custom view - log.debug("Found direct class ["+clas.getName()+"] with custom view "+customView+"; resetting entity vclassName to this class"); - break; - } else { - customView = null; - } - } - } - if (customView == null) { //still - clasList = indiv.getVClasses(false); - for (VClass clas : clasList) { - customView = clas.getCustomDisplayView(); - if (customView != null) { - if (customView.length()>0) { - // note that NOT changing entity vclassName here yet - log.debug("Found inferred class ["+clas.getName()+"] with custom view "+customView); - break; - } else { - customView = null; - } - } - } - } - } else if (indiv.getVClassURI() != null) { - log.debug("Individual " + indiv.getURI() + " with class URI " + - indiv.getVClassURI() + ": no class found with that URI"); - } - if (customView!=null) { - // RY Transitional hack: ignore Freemarker templates so we can load old individual page with default display view - if (customView.endsWith(".ftl")) { - customView = null; - } - // insert test for whether a css files of the same name exists, and populate the customCss string for use when construction the header - } - String netid = iwDao.getNetId(indiv.getURI()); - - vreq.setAttribute("netid", netid); - vreq.setAttribute("vclassName", vclassName); - vreq.setAttribute("entity",indiv); - Portal portal = vreq.getPortal(); - vreq.setAttribute("portal",String.valueOf(portal)); - String view= getViewFromRequest(vreq); - if( view == null){ - if (customView == null) { - view = default_jsp; - vreq.setAttribute("bodyJsp", Controllers.ENTITY_JSP); - log.debug("no custom view and no view parameter in request for rendering "+indiv.getName()); - } else { - view = default_jsp; - log.debug("setting custom view templates/entity/"+ customView + " for rendering "+indiv.getName()); - vreq.setAttribute("bodyJsp", "/templates/entity/"+customView); - } - vreq.setAttribute("entityPropsListJsp",Controllers.ENTITY_PROP_LIST_JSP); - vreq.setAttribute("entityDatapropsListJsp",Controllers.ENTITY_DATAPROP_LIST_JSP); - vreq.setAttribute("entityMergedPropsListJsp",Controllers.ENTITY_MERGED_PROP_LIST_GROUPED_JSP); - vreq.setAttribute("entityKeywordsListJsp",Controllers.ENTITY_KEYWORDS_LIST_JSP); - } else { - log.debug("Found view parameter "+view+" in request for rendering "+indiv.getName()); - } - //set title before we do the highlighting so we don't get markup in it. - vreq.setAttribute("title",indiv.getName()); - //setup highlighter for search terms - checkForSearch(vreq, indiv); - - // set CSS and script elements - String contextPath = ""; - if (vreq.getContextPath().length()>1) { - contextPath = vreq.getContextPath(); - } - String css = "\n" - + " \n"; - if (customCss!=null) { - css += customCss; - } - - if( indiv.getURI().startsWith( vreq.getWebappDaoFactory().getDefaultNamespace() )){ - vreq.setAttribute("entityLinkedDataURL", indiv.getURI() + "/" + indiv.getLocalName() + ".rdf"); - } - - vreq.setAttribute("css",css); - vreq.setAttribute("scripts", "/templates/entity/entity_inject_head.jsp"); - - RequestDispatcher rd = vreq.getRequestDispatcher( view ); - rd.forward(vreq,res); - } - - private void doRdf(VitroRequest vreq, HttpServletResponse res, - ContentType rdfFormat) throws IOException, ServletException { - - Individual indiv = getEntityFromRequest(vreq); - if( indiv == null ){ - doNotFound(vreq, res); - return; - } - - OntModel ontModel = null; - HttpSession session = vreq.getSession(false); - if( session != null ) - ontModel =(OntModel)session.getAttribute("jenaOntModel"); - if( ontModel == null) - ontModel = (OntModel)getServletContext().getAttribute("jenaOntModel"); - - Model newModel; - newModel = getRDF(indiv, ontModel, ModelFactory.createDefaultModel(), 0); - - res.setContentType(rdfFormat.getMediaType()); - String format = ""; - if ( RDFXML_MIMETYPE.equals(rdfFormat.getMediaType())) - format = "RDF/XML"; - else if( N3_MIMETYPE.equals(rdfFormat.getMediaType())) - format = "N3"; - else if ( TTL_MIMETYPE.equals(rdfFormat.getMediaType())) - format ="TTL"; - - newModel.write( res.getOutputStream(), format ); - } - - private void doRedirect(HttpServletRequest req, HttpServletResponse res, - String redirectURL) { - //It seems like there must be a more standard way to do a redirect in tomcat. - String hn = req.getHeader("Host"); - if (req.isSecure()) { - res.setHeader("Location", res.encodeURL("https://" + hn - + req.getContextPath() + redirectURL)); - log.info("doRedirect by using HTTPS"); - } else { - res.setHeader("Location", res.encodeURL("http://" + hn - + req.getContextPath() + redirectURL)); - log.info("doRedirect by using HTTP"); - } - res.setStatus(res.SC_SEE_OTHER); - } - - private static Pattern LINKED_DATA_URL = Pattern.compile("^/individualold/([^/]*)$"); - private static Pattern NS_PREFIX_URL = Pattern.compile("^/individualold/([^/]*)/([^/]*)$"); - - /** - Gets the entity id from the request. - Works for the following styles of URLs: - - /individual?id=individualLocalName - /individual?entityId=individualLocalName - /individual?uri=urlencodedURI - /individual?nedit=bdc34 - /individual?nedIt=bdc34 - /individual/nsprefix/localname - /individual/localname - /individual/localname/localname.rdf - /individual/localname/localname.n3 - /individual/localname/localname.ttl - /individual/localname/localname.html - - @return null on failure. - */ - public static Individual getEntityFromRequest(VitroRequest vreq) { - String netIdStr = null; - Individual entity = null; - IndividualDao iwDao = vreq.getWebappDaoFactory().getIndividualDao(); - - String entityIdStr = vreq.getParameter("id"); - if (entityIdStr == null || entityIdStr.equals("")) - entityIdStr = vreq.getParameter("entityId"); - - if( entityIdStr != null){ - try { - String entityURI = vreq.getWebappDaoFactory().getDefaultNamespace()+"individual"+entityIdStr; - entity = iwDao.getIndividualByURI(entityURI); - } catch ( Exception e ) { - log.warn("Could not parse entity id: " + entityIdStr); - return null; - } - return entity; - } - - String entityURIStr = vreq.getParameter("uri"); - if (entityURIStr != null) { - try { - entity = iwDao.getIndividualByURI(entityURIStr); - } catch (Exception e) { - log.warn("Could not retrieve entity "+entityURIStr); - return null; - } - return entity; - } - - //get URL without hostname or servlet context - String url = vreq.getRequestURI().substring(vreq.getContextPath().length()); - - /* check for parts of URL that indicate request for RDF - http://vivo.cornell.edu/individual/n23/n23.rdf - http://vivo.cornell.edu/individual/n23/n23.n3 - http://vivo.cornell.edu/individual/n23/n23.ttl */ - String uri = null; - Matcher m = RDF_REQUEST.matcher(url); - if( m.matches() && m.groupCount() == 1) - uri = m.group(1); - m = N3_REQUEST.matcher(url); - if( m.matches() && m.groupCount() == 1) - uri = m.group(1); - m = TTL_REQUEST.matcher(url); - if( m.matches() && m.groupCount() == 1) - uri= m.group(1); - m = HTML_REQUEST.matcher(url); - if( m.matches() && m.groupCount() == 1) - uri= m.group(1); - if( uri != null ) - return iwDao.getIndividualByURI(vreq.getWebappDaoFactory().getDefaultNamespace() + uri); - - // see if we can get the URI from a name space prefix and a local name - Matcher prefix_match = NS_PREFIX_URL.matcher(url); - if( prefix_match.matches() && prefix_match.groupCount() == 2){ - String prefix = prefix_match.group(1); - String localName = prefix_match.group(2); - - //String[] requestParts = requestURI.split("/individual/"); - //String[] URIParts = requestParts[1].split("/"); - //String localName = URIParts[1]; - - String namespace = ""; - NamespaceMapper namespaceMapper = NamespaceMapperFactory.getNamespaceMapper(vreq.getSession().getServletContext()); - String t; - namespace = ( (t = namespaceMapper.getNamespaceForPrefix(prefix)) != null) ? t : ""; - - return iwDao.getIndividualByURI(namespace+localName); - } - - // see if we can get a local name - Matcher linkedDataMatch = LINKED_DATA_URL.matcher(url); - if( linkedDataMatch.matches() && linkedDataMatch.groupCount() == 1){ - String localName = linkedDataMatch.group(1); - String ns = vreq.getWebappDaoFactory().getDefaultNamespace(); - return iwDao.getIndividualByURI( ns + localName ); - } - - //so we try to get the netid - netIdStr = vreq.getParameter("netId"); - if (netIdStr==null || netIdStr.equals("")) - netIdStr = vreq.getParameter("netid"); - if ( netIdStr != null ){ - SelfEditingConfiguration sec = SelfEditingConfiguration.getBean(vreq); - uri = sec.getIndividualUriFromUsername(iwDao, netIdStr); - return iwDao.getIndividualByURI(uri); - } - - return null; - } - - - private static Pattern URI_PATTERN = Pattern.compile("^/individualold/([^/]*)$"); - //Redirect if the request is for http://hostname/individual/localname - // if accept is nothing or text/html redirect to ??? - // if accept is some RDF thing redirect to the URL for RDF - private String checkForRedirect(String url, String acceptHeader) { - Matcher m = URI_PATTERN.matcher(url); - if( m.matches() && m.groupCount() == 1 ){ - ContentType c = checkForLinkedDataRequest(url, acceptHeader); - if( c != null ){ - String redirectUrl = "/individualold/" + m.group(1) + "/" + m.group(1) ; - if( RDFXML_MIMETYPE.equals( c.getMediaType()) ){ - return redirectUrl + ".rdf"; - }else if( N3_MIMETYPE.equals( c.getMediaType() )){ - return redirectUrl + ".n3"; - }else if( TTL_MIMETYPE.equals( c.getMediaType() )){ - return redirectUrl + ".ttl"; - }//else send them to html - } - //else redirect to HTML representation - return "/display/" + m.group(1) ; - }else{ - return null; - } - } - - private static Pattern RDF_REQUEST = Pattern.compile("^/individualold/([^/]*)/\\1.rdf$"); - private static Pattern N3_REQUEST = Pattern.compile("^/individualold/([^/]*)/\\1.n3$"); - private static Pattern TTL_REQUEST = Pattern.compile("^/individualold/([^/]*)/\\1.ttl$"); - private static Pattern HTML_REQUEST = Pattern.compile("^/displayold/([^/]*)$"); - - /** - * @return null if this is not a linked data request, returns content type if it is a - * linked data request. - */ - protected ContentType checkForLinkedDataRequest(String url, String acceptHeader) { - try { - //check the accept header - if (acceptHeader != null) { - List actualContentTypes = new ArrayList(); - actualContentTypes.add(new ContentType( XHTML_MIMETYPE )); - actualContentTypes.add(new ContentType( HTML_MIMETYPE )); - - actualContentTypes.add(new ContentType( RDFXML_MIMETYPE )); - actualContentTypes.add(new ContentType( N3_MIMETYPE )); - actualContentTypes.add(new ContentType( TTL_MIMETYPE )); - - - ContentType best = ContentType.getBestContentType(acceptHeader,actualContentTypes); - if (best!=null && ( - RDFXML_MIMETYPE.equals(best.getMediaType()) || - N3_MIMETYPE.equals(best.getMediaType()) || - TTL_MIMETYPE.equals(best.getMediaType()) )) - return best; - } - - /* - * check for parts of URL that indicate request for RDF - http://vivo.cornell.edu/individual/n23/n23.rdf - http://vivo.cornell.edu/individual/n23/n23.n3 - http://vivo.cornell.edu/individual/n23/n23.ttl - */ - - Matcher m = RDF_REQUEST.matcher(url); - if( m.matches() ) - return new ContentType(RDFXML_MIMETYPE); - m = N3_REQUEST.matcher(url); - if( m.matches() ) - return new ContentType(N3_MIMETYPE); - m = TTL_REQUEST.matcher(url); - if( m.matches() ) - return new ContentType(TTL_MIMETYPE); - - } catch (Throwable th) { - log.error("problem while checking accept header " , th); - } - return null; - } - - private boolean checkForSunset(VitroRequest vreq, Individual entity) { - // TODO Auto-generated method stub - return false; - } - - private boolean checkForHidden(VitroRequest vreq, Individual entity){ - // TODO Auto-generated method stub - return false; - } - - /** - * If this entity represents a File Bytestream, get its alias URL so we can - * properly serve the file contents. - */ - private String getAliasUrlForBytestreamIndividual(HttpServletRequest req, Individual entity) - throws IOException { - FileInfo fileInfo = FileInfo.instanceFromBytestreamUri(new VitroRequest( - req).getWebappDaoFactory(), entity.getURI()); - if (fileInfo == null) { - log.trace("Entity '" + entity.getURI() + "' is not a bytestream."); - return null; - } - - String url = fileInfo.getBytestreamAliasUrl(); - log.debug("Alias URL for '" + entity.getURI() + "' is '" + url + "'"); - - if (entity.getURI().equals(url)) { - // Avoid a tight loop; if the alias URL is equal to the URI, then - // don't recognize it as a File Bytestream. - return null; - } else { - return url; - } - } - - private Model getRDF(Individual entity, OntModel contextModel, Model newModel, int recurseDepth ) { - Resource subj = newModel.getResource(entity.getURI()); - - List dstates = entity.getDataPropertyStatements(); - //System.out.println("data: "+dstates.size()); - TypeMapper typeMapper = TypeMapper.getInstance(); - for (DataPropertyStatement ds: dstates) { - Property dp = newModel.getProperty(ds.getDatapropURI()); - Literal lit = null; - if ((ds.getLanguage()) != null && (ds.getLanguage().length()>0)) { - lit = newModel.createLiteral(ds.getData(),ds.getLanguage()); - } else if ((ds.getDatatypeURI() != null) && (ds.getDatatypeURI().length()>0)) { - lit = newModel.createTypedLiteral(ds.getData(),typeMapper.getSafeTypeByName(ds.getDatatypeURI())); - } else { - lit = newModel.createLiteral(ds.getData()); - } - newModel.add(newModel.createStatement(subj, dp, lit)); - } - - if( recurseDepth < 5 ){ - List ostates = entity.getObjectPropertyStatements(); - for (ObjectPropertyStatement os: ostates) { - ObjectProperty objProp = os.getProperty(); - Property op = newModel.getProperty(os.getPropertyURI()); - Resource obj = newModel.getResource(os.getObjectURI()); - newModel.add(newModel.createStatement(subj, op, obj)); - if( objProp.getStubObjectRelation() ) - newModel.add(getRDF(os.getObject(), contextModel, newModel, recurseDepth + 1)); - } - } - - newModel = getLabelAndTypes(entity, contextModel, newModel ); - return newModel; - } - - /* Get the properties that are difficult to get via a filtered WebappDaoFactory. */ - private Model getLabelAndTypes(Individual entity, Model ontModel, Model newModel){ - for( VClass vclass : entity.getVClasses()){ - newModel.add(newModel.getResource(entity.getURI()), RDF.type, newModel.getResource(vclass.getURI())); - } - - ontModel.enterCriticalSection(Lock.READ); - try { - newModel.add(ontModel.listStatements(ontModel.getResource(entity.getURI()), RDFS.label, (RDFNode)null)); - } finally { - ontModel.leaveCriticalSection(); - } - - return newModel; - } - - - private void checkForSearch(HttpServletRequest req, Individual ent) { - if (req.getSession().getAttribute("LastQuery") != null) { - VitroQueryWrapper qWrap = (VitroQueryWrapper) req.getSession() - .getAttribute("LastQuery"); - if (qWrap.getRequestCount() > 0 && qWrap.getQuery() != null) { - VitroQuery query = qWrap.getQuery(); - - //set query text so we can get it in JSP - req.setAttribute("querytext", query.getTerms()); - - //setup highlighting for output - StringProcessorTag.putStringProcessorInRequest(req, qWrap.getHighlighter()); - - qWrap.setRequestCount(qWrap.getRequestCount() - 1); - } else { - req.getSession().removeAttribute("LastQuery"); - } - } - } - - private Pattern badrequest= Pattern.compile(".*([&\\?=]|\\.\\.).*"); - - public String getViewFromRequest(HttpServletRequest request){ - String viewParam = request.getParameter("view"); - if( viewParam != null ){ - if( badrequest.matcher(viewParam).matches() ){ - log.debug("request for a non-default view was bad: " + viewParam); - return null; - }else{ - log.debug("view request : " + viewParam); - return viewParam; - } - } - return null; - } - - public void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException,IOException { - doGet(request, response); - } - - private void doHelp(HttpServletResponse res) - throws IOException, ServletException { - ServletOutputStream out = res.getOutputStream(); - res.setContentType("text/html; charset=UTF-8"); - out.println("

Quick Notes on using entity:

"); - out.println("

id is the id of the entity to query for. netid also works.

"); - out.println(""); - } - - private void doNotFound(HttpServletRequest req, HttpServletResponse res) - throws IOException, ServletException { - VitroRequest vreq = new VitroRequest(req); - Portal portal = vreq.getPortal(); - ApplicationBean appBean = ApplicationBean.getAppBean(getServletContext()); - int allPortalId = appBean.getAllPortalFlagNumeric(); - - //If an Individual is not found, there is possibility that it - //was requested from a portal where it was not visible. - //In this case redirect to the all portal. - try{ - Portal allPortal = - vreq.getWebappDaoFactory().getPortalDao().getPortal(allPortalId); - // there must be a portal defined with the ID of the all portal - // for this to work - if( portal.getPortalId() != allPortalId && allPortal != null ) { - - //bdc34: - // this is hard coded to get the all portal - // I didn't find a way to get the id of the all portal - // it is likely that redirecting will not work in non VIVO clones - String portalPrefix = null; - String portalParam = null; - if( allPortal != null && allPortal.getUrlprefix() != null ) - portalPrefix = allPortal.getUrlprefix(); - else - portalParam = "home=" + allPortalId; - - String queryStr = req.getQueryString(); - if( queryStr == null && portalParam != null && !"".equals(portalParam)){ - queryStr = portalParam; - } else { - if( portalParam != null && !"".equals(portalParam)) - queryStr = queryStr + "&" + portalParam; - } - if( queryStr != null && !queryStr.startsWith("?") ) - queryStr = "?" + queryStr; - - StringBuilder url = new StringBuilder(); - url.append( req.getContextPath() ); - if( req.getContextPath() != null && !req.getContextPath().endsWith("/")) - url.append('/'); - - if( portalPrefix != null && !"".equals(portalPrefix)) - url.append( portalPrefix ).append('/'); - - String servletPath = req.getServletPath(); - String spath = ""; - if( servletPath != null ){ - if( servletPath.startsWith("/") ) - spath = servletPath.substring(1); - else - spath = servletPath; - } - - if( spath != null && !"".equals(spath)) - url.append( spath ); - - if( req.getPathInfo() != null ) - url.append( req.getPathInfo() ); - - if( queryStr != null && !"".equals(queryStr )) - url.append( queryStr ); - - res.sendRedirect(url.toString()); - return; - } - }catch(Throwable th){ - log.error("could not do a redirect", th); - } - - //set title before we do the highlighting so we don't get markup in it. - req.setAttribute("title","not found"); - res.setStatus(HttpServletResponse.SC_NOT_FOUND); - - String css = "" - + ""; - req.setAttribute("css",css); - - req.setAttribute("bodyJsp","/"+Controllers.ENTITY_NOT_FOUND_JSP); - - RequestDispatcher rd = req.getRequestDispatcher(Controllers.BASIC_JSP); - rd.forward(req,res); - } - - private String forURL(String frag) - { - String result = null; - try - { - result = URLEncoder.encode(frag, "UTF-8"); - } catch (UnsupportedEncodingException ex) { - throw new RuntimeException("UTF-8 not supported", ex); - } - return result; - } - - private class HelpException extends Throwable{} - private class EntityNotFoundException extends Throwable{} -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityListController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityListController.java deleted file mode 100644 index 3c0901b27..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityListController.java +++ /dev/null @@ -1,321 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.controller; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.lucene.document.Document; -import org.apache.lucene.index.CorruptIndexException; -import org.apache.lucene.index.Term; -import org.apache.lucene.search.BooleanClause; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.PrefixQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.ScoreDoc; -import org.apache.lucene.search.Sort; -import org.apache.lucene.search.TermQuery; -import org.apache.lucene.search.TopDocs; - -import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.beans.Portal; -import edu.cornell.mannlib.vitro.webapp.beans.VClass; -import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; -import edu.cornell.mannlib.vitro.webapp.controller.TabEntitiesController.PageRecord; -import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; -import edu.cornell.mannlib.vitro.webapp.flags.FlagException; -import edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc; -import edu.cornell.mannlib.vitro.webapp.search.lucene.LuceneIndexFactory; -import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils; - -public class EntityListController extends VitroHttpServlet { - - public static final int ENTITY_LIST_CONTROLLER_MAX_RESULTS = 30000; - public static final int INDIVIDUALS_PER_PAGE = 30; - - long startTime = -1; - - private static final Log log = LogFactory.getLog(EntityListController.class.getName()); - - /** - * This generates a list of entities and then sends that - * off to a jsp to be displayed. - * - * Expected parameters: - * - * Expected Attributes: - * entity - set to entity to display properties for. - * - * @author bdc34 - */ - public void doGet( HttpServletRequest req, HttpServletResponse res ) - throws IOException, ServletException { - startTime = System.currentTimeMillis(); // TODO: remove - try { - super.doGet(req, res); - VitroRequest vreq = new VitroRequest(req); - Object obj = req.getAttribute("vclass"); - VClass vclass=null; - if( obj == null ) { // look for vitroclass id parameter - String vitroClassIdStr=req.getParameter("vclassId"); - if (vitroClassIdStr!=null && !vitroClassIdStr.equals("")) { - try { - vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vitroClassIdStr); - if (vclass == null) { - log.error("Couldn't retrieve vclass "+vitroClassIdStr); - res.sendRedirect(Controllers.BROWSE_CONTROLLER+"?"+req.getQueryString()); - } - } catch (Exception ex) { - throw new HelpException("EntityListController: request parameter 'vclassId' must be a URI string"); - } - } - } else if (obj instanceof VClass) { - vclass = (VClass)obj; - } else { - throw new HelpException("EntityListController: attribute 'vclass' must be of type " - + VClass.class.getName() ); - } - - if (vclass!=null) - doVClass(vreq, res, vclass); - else - log.debug("no vclass found for " + obj); - - } catch (HelpException help){ - doHelp(res); - } catch (Throwable e) { - req.setAttribute("javax.servlet.jsp.jspException",e); - RequestDispatcher rd = req.getRequestDispatcher("/error.jsp"); - rd.forward(req, res); - } - } - - public void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException,IOException { - doGet(request, response); - } - - /** - * Perform the actions needed for the entity list jsp. - * @param request - * @param res - * @param vclass - * @throws ServletException - * @throws IOException - */ - private void doVClass(VitroRequest request, HttpServletResponse res, VClass vclass) - throws ServletException, IOException, FlagException { - - Map results = getResultsForVClass( - vclass.getURI(), - getPageParameter(request), - getAlphaParamter(request), - request.getPortal(), - request.getWebappDaoFactory().getPortalDao().isSinglePortal(), - request.getWebappDaoFactory().getIndividualDao(), - getServletContext()); - - /* copy values from results in to request attributes */ - request.setAttribute("entities", results.get("entities")); - request.setAttribute("count",results.get("count")); - request.setAttribute("totalCount",results.get("totalCount")); - request.setAttribute("alpha",results.get("alpha")); - request.setAttribute("showPages",results.get("showPages")); - request.setAttribute("pages",results.get("pages")); - - /* Setup any additional attributes that are needed */ - request.setAttribute("servlet",Controllers.ENTITY_LIST); - request.setAttribute("vclassId", vclass.getURI()); - request.setAttribute("controllerParam","vclassId=" + URLEncoder.encode(vclass.getURI(),"UTF-8")); - request.setAttribute("showAlpha","1"); - request.setAttribute("letters",Controllers.getLetters()); - - VClassGroup classGroup=vclass.getGroup(); - if (classGroup==null) { - request.setAttribute("title",vclass.getName()/* + " ("+vclass.getEntityCount()+")"*/); - } else { - request.setAttribute("title",classGroup.getPublicName()); - request.setAttribute("subTitle",vclass.getName()/* + " ("+vclass.getEntityCount()+")"*/); - } - - //FINALLY: send off to the BASIC_JSP to get turned into html - request.setAttribute("bodyJsp",Controllers.ENTITY_LIST_JSP); - RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); - - // use this for more direct debugging: RequestDispatcher rd = request.getRequestDispatcher(Controllers.ENTITY_LIST_JSP); - res.setContentType("text/html; charset=UTF-8"); - request.setAttribute("pageTime", System.currentTimeMillis()-startTime); - rd.include(request,res); - } - - /** - * This method is now called in a couple of places. It should be refactored - * into a DAO or similar object. - */ - public static Map getResultsForVClass(String vclassURI, int page, String alpha, Portal portal, boolean isSinglePortal, IndividualDao indDao, ServletContext context) - throws CorruptIndexException, IOException, ServletException{ - Map rvMap = new HashMap(); - - int portalId = 1; - if( portal != null ) - portalId = portal.getPortalId(); - - //make lucene query for this rdf:type - Query query = getQuery(vclassURI,alpha, isSinglePortal, portalId); - - //execute lucene query for individuals of the specified type - IndexSearcher index = LuceneIndexFactory.getIndexSearcher(context); - TopDocs docs = null; - try{ - docs = index.search(query, null, - ENTITY_LIST_CONTROLLER_MAX_RESULTS, - new Sort(Entity2LuceneDoc.term.NAMELOWERCASE)); - }catch(Throwable th){ - log.error("Could not run search. " + th.getMessage()); - docs = null; - } - - if( docs == null ) - throw new ServletException("Could not run search in EntityListController"); - - //get list of individuals for the search results - int size = docs.totalHits; - log.debug("Number of search results: " + size); - - // don't get all the results, only get results for the requestedSize - List individuals = new ArrayList(INDIVIDUALS_PER_PAGE); - int individualsAdded = 0; - int ii = (page-1)*INDIVIDUALS_PER_PAGE; - while( individualsAdded < INDIVIDUALS_PER_PAGE && ii < size ){ - ScoreDoc hit = docs.scoreDocs[ii]; - if (hit != null) { - Document doc = index.doc(hit.doc); - if (doc != null) { - String uri = doc.getField(Entity2LuceneDoc.term.URI).stringValue(); - Individual ind = indDao.getIndividualByURI( uri ); - if( ind != null ){ - individuals.add( ind ); - individualsAdded++; - } - } else { - log.warn("no document found for lucene doc id " + hit.doc); - } - } else { - log.debug("hit was null"); - } - ii++; - } - - rvMap.put("count", size); - - if( size > INDIVIDUALS_PER_PAGE ){ - rvMap.put("showPages", Boolean.TRUE); - List pageRecords = TabEntitiesController.makePagesList(size, INDIVIDUALS_PER_PAGE, page); - rvMap.put("pages", pageRecords); - }else{ - rvMap.put("showPages", Boolean.FALSE); - rvMap.put("pages", Collections.emptyList()); - } - - rvMap.put("alpha",alpha); - - rvMap.put("totalCount", size); - rvMap.put("entities",individuals); - if (individuals == null) - log.debug("entities list is null for vclass " + vclassURI ); - - return rvMap; - } - - private static BooleanQuery getQuery(String vclassUri, String alpha , boolean isSinglePortal, int portalId){ - BooleanQuery query = new BooleanQuery(); - try{ - //query term for rdf:type - query.add( - new TermQuery( new Term(Entity2LuceneDoc.term.RDFTYPE, vclassUri)), - BooleanClause.Occur.MUST ); - - //check for portal filtering - if( ! isSinglePortal ){ - if( portalId < 16 ){ //could be a normal portal - query.add( - new TermQuery( new Term(Entity2LuceneDoc.term.PORTAL, Integer.toString(1 << portalId ))), - BooleanClause.Occur.MUST); - }else{ //could be a combined portal - BooleanQuery tabQueries = new BooleanQuery(); - Long[] ids= FlagMathUtils.numeric2numerics(portalId); - for( Long id : ids){ - tabQueries.add( - new TermQuery( new Term(Entity2LuceneDoc.term.PORTAL,id.toString()) ), - BooleanClause.Occur.SHOULD); - } - query.add(tabQueries,BooleanClause.Occur.MUST); - } - } - - //Add alpha filter if it is needed - Query alphaQuery = null; - if( alpha != null && !"".equals(alpha) && alpha.length() == 1){ - alphaQuery = - new PrefixQuery(new Term(Entity2LuceneDoc.term.NAMELOWERCASE, alpha.toLowerCase())); - query.add(alphaQuery,BooleanClause.Occur.MUST); - } - - log.debug("Query: " + query); - return query; - }catch (Exception ex){ - log.error(ex,ex); - return new BooleanQuery(); - } - } - - public static int getPageParameter(VitroRequest request) { - String pageStr = request.getParameter("page"); - if( pageStr != null ){ - try{ - return Integer.parseInt(pageStr); - }catch(NumberFormatException nfe){ - log.debug("could not parse page parameter"); - return 1; - } - }else{ - return 1; - } - } - - public static String getAlphaParamter(VitroRequest request){ - return request.getParameter("alpha"); - } - - private void doHelp(HttpServletResponse res) - throws IOException, ServletException { - ServletOutputStream out = res.getOutputStream(); - res.setContentType("text/html; charset=UTF-8"); - out.println("

Quick Notes on using EntityList:

"); - out.println("

request.attributes 'entities' must be set by servlet before calling." - +" It must be a List of Entity objects

"); - out.println(""); - } - - private class HelpException extends Throwable{ - public HelpException(String string) { - super(string); - } - } -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityMergedPropertyListController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityMergedPropertyListController.java deleted file mode 100644 index 259dea21c..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityMergedPropertyListController.java +++ /dev/null @@ -1,823 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.controller; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import net.sf.jga.fn.UnaryFunctor; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import edu.cornell.mannlib.vitro.webapp.beans.DataProperty; -import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; -import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; -import edu.cornell.mannlib.vitro.webapp.beans.Property; -import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup; -import edu.cornell.mannlib.vitro.webapp.beans.PropertyInstance; -import edu.cornell.mannlib.vitro.webapp.beans.VClass; -import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao; -import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao; -import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao; -import edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao; -import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; -import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; -import edu.cornell.mannlib.vitro.webapp.servlet.setup.PropertyMaskingSetup; - -public class EntityMergedPropertyListController extends VitroHttpServlet { - - /** - * This gets the Entity object in the requestScope "entity" and - * sets up a merged property list for it. This merged list includes - * Object and Data properties. - * - * After that a jsp is called to draw the data. - * - * Expected parameters: - * - * Expected Attributes: - * entity - set to entity to display properties for. - * - * @author jc55 forked this file from EntityPropertyListController - */ - - private static final Log log = LogFactory.getLog(EntityMergedPropertyListController.class.getName()); - private static final int MAX_GROUP_DISPLAY_RANK = 99; - private static final String VIVO_CORE_NAMESPACE = "http://vivoweb.org/ontology/core#"; - - /** Don't include these properties in the list. */ - private static final Collection SUPPRESSED_OBJECT_PROPERTIES = Collections - .unmodifiableCollection(Arrays - .asList(new String[] { VitroVocabulary.IND_MAIN_IMAGE })); - - public void doGet( HttpServletRequest request, HttpServletResponse res ) - throws IOException, ServletException { - - VitroRequest req = new VitroRequest(request); - - try { - super.doGet(req, res); - Object obj = req.getAttribute("entity"); - if( obj == null || !(obj instanceof Individual)) - throw new HelpException("EntityMergedPropertyListController requires request.attribute 'entity' to be of" - +" type " + Individual.class.getName() ); - Individual subject =(Individual)obj; - subject = filterFromContext( subject ); - - // determine whether are just displaying populated properties or also interleaving unpopulated ones - boolean editMode = false; - String modeStr = req.getParameter("mode"); - if (modeStr != null && modeStr.indexOf("edit")>=0) { - editMode = true; - } - - boolean groupedMode = false; - String groupedStr = req.getParameter("grouped"); - if (groupedStr != null && groupedStr.equalsIgnoreCase("true")) { - groupedMode = true; - } - - String groupForUngroupedProperties = null; - String unassignedStr = req.getParameter("unassignedPropsGroupName"); - if (unassignedStr != null && unassignedStr.length()>0) { - groupForUngroupedProperties = unassignedStr; - //pass this on to entityMergedPropsList.jsp - req.setAttribute("unassignedPropsGroupName", unassignedStr); - log.debug("found temp group parameter \""+unassignedStr+"\" for unassigned properties"); - } - - // set up a new list for the combined object and data properties - VitroRequest vreq = new VitroRequest(req); - WebappDaoFactory wdf = vreq.getWebappDaoFactory(); - PropertyGroupDao pgDao = null; - List groupsList = null; - if (groupedMode) { - pgDao = wdf.getPropertyGroupDao(); - groupsList = pgDao.getPublicGroups(false); // may be returned empty but not null - } - - List mergedPropertyList = new ArrayList(); - // now first get the properties this entity actually has, presumably populated with statements - List objectPropertyList = subject.getObjectPropertyList(); - - for (ObjectProperty op : objectPropertyList) { - if (!SUPPRESSED_OBJECT_PROPERTIES.contains(op)) { - op.setLabel(op.getDomainPublic()); - mergedPropertyList.add(op); - }else{ - log.debug("suppressed " + op.getURI()); - } - } - - if (editMode) { - // for the full list, in order to show empty properties, now need to merge in new ObjectProperty objects with null objectPropertyStatements - PropertyInstanceDao piDao = wdf.getPropertyInstanceDao(); - ObjectPropertyDao opDao = wdf.getObjectPropertyDao(); - Collection allPropInstColl = piDao.getAllPossiblePropInstForIndividual(subject.getURI()); - if (allPropInstColl != null) { - for (PropertyInstance pi : allPropInstColl) { - if (pi!=null) { - if (!alreadyOnObjectPropertyList(objectPropertyList,pi)) { - ObjectProperty op = opDao.getObjectPropertyByURI(pi.getPropertyURI()); - if (op == null) { - log.error("ObjectProperty op returned null from opDao.getObjectPropertyByURI()"); - } else if (op.getURI() == null) { - log.error("ObjectProperty op returned with null propertyURI from opDao.getObjectPropertyByURI()"); - } else if (!alreadyOnPropertyList(mergedPropertyList,op)) { - op.setLabel(op.getDomainPublic()); - mergedPropertyList.add(op); - } - } - } else { - log.error("a property instance in the Collection created by PropertyInstanceDao.getAllPossiblePropInstForIndividual() is unexpectedly null"); - } - } - } else { - log.error("a null Collection is returned from PropertyInstanceDao.getAllPossiblePropInstForIndividual()"); - } - } - - // now do much the same with data properties: get the list of populated data properties, then add in placeholders for missing ones - List dataPropertyList = subject.getDataPropertyList(); - for (DataProperty dp : dataPropertyList) { - dp.setLabel(dp.getPublicName()); - mergedPropertyList.add(dp); - } - - if (editMode) { - DataPropertyDao dpDao = wdf.getDataPropertyDao(); - Collection allDatapropColl = dpDao.getAllPossibleDatapropsForIndividual(subject.getURI()); - if (allDatapropColl != null) { - for (DataProperty dp : allDatapropColl ) { - if (dp!=null) { - if (dp.getURI() == null) { - log.error("DataProperty dp returned with null propertyURI from dpDao.getAllPossibleDatapropsForIndividual()"); - } else if (!alreadyOnPropertyList(mergedPropertyList,dp)) { - dp.setLabel(dp.getPublicName()); - mergedPropertyList.add(dp); - } - } else { - log.error("a data property in the Collection created in DataPropertyDao.getAllPossibleDatapropsForIndividual() is unexpectedly null)"); - } - } - } else { - log.error("a null Collection is returned from DataPropertyDao.getAllPossibleDatapropsForIndividual())"); - } - } - - if (mergedPropertyList!=null) { - try { - Collections.sort(mergedPropertyList,new PropertyRanker(vreq)); - } catch (Exception ex) { - log.error("Exception sorting merged property list: " + ex.getMessage()); - } - - //deal with collateBySubclass annotations on object properties - mergedPropertyList = collateBySubclass( mergedPropertyList ); - - if (groupedMode) { - int groupsCount=0; - try { - groupsCount = populateGroupsListWithProperties(pgDao,groupsList,mergedPropertyList,groupForUngroupedProperties); - } catch (Exception ex) { - log.error("Exception on trying to populate groups list with properties: "+ex.getMessage()); - ex.printStackTrace(); - } - try { - int removedCount = pgDao.removeUnpopulatedGroups(groupsList); - if (removedCount == 0) { - log.warn("Of "+groupsCount+" groups, none removed by removeUnpopulatedGroups"); - /* } else { - log.warn("Of "+groupsCount+" groups, "+removedCount+" removed by removeUnpopulatedGroups"); */ - } - groupsCount -= removedCount; - req.setAttribute("groupsCount", new Integer(groupsCount)); - if (groupsCount > 0) { //still - for (PropertyGroup g : groupsList) { - int statementCount=0; - if (g.getPropertyList()!=null && g.getPropertyList().size()>0) { - for (Property p : g.getPropertyList()) { - if (p instanceof ObjectProperty) { - ObjectProperty op = (ObjectProperty)p; - List opStmts = op.getObjectPropertyStatements(); - if (op.getObjectPropertyStatements()!=null && opStmts.size()>0) { - statementCount += opStmts.size(); - - // If not collated, we need to apply custom sorting now. - applyCustomSortToUncollatedProperty(op, opStmts); - } - - - } - } - } - g.setStatementCount(statementCount); - } - } - } catch (Exception ex) { - log.error("Exception on trying to prune groups list with properties: "+ex.getMessage()); - } - mergedPropertyList.clear(); - - } else { // ungrouped mode - for (Property p : mergedPropertyList) { - if (p instanceof ObjectProperty) { - ObjectProperty op = (ObjectProperty)p; - applyCustomSortToUncollatedProperty(op, op.getObjectPropertyStatements()); - } - } - } - } - - if (groupedMode) { - req.setAttribute("groupsList",groupsList); - } else { - UnaryFunctor,List> entityPropertyListFilter = PropertyMaskingSetup.getEntityPropertyListFilter(getServletContext()); - if (entityPropertyListFilter != null) { - mergedPropertyList = entityPropertyListFilter.fn(mergedPropertyList); - } - - req.setAttribute("mergedList",mergedPropertyList); - } - - req.setAttribute("entity",subject); - - RequestDispatcher rd = req.getRequestDispatcher(groupedMode ? Controllers.ENTITY_MERGED_PROP_LIST_GROUPED_JSP : Controllers.ENTITY_MERGED_PROP_LIST_UNGROUPED_JSP); - rd.include(req,res); - } catch (HelpException help){ - doHelp(res); - } catch (Throwable e) { - req.setAttribute("javax.servlet.jsp.jspException",e); - log.error("exception thrown: "+e.getMessage()); - RequestDispatcher rd = req.getRequestDispatcher("/error.jsp"); - // rd.forward(req, res); response has already been committed - rd.include(req, res); - } - } - - - - public void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException,IOException { - doGet(request, response); - } - - private boolean alreadyOnObjectPropertyList(List opList, PropertyInstance pi) { - if (pi.getPropertyURI() == null) { - return false; - } - for (ObjectProperty op : opList) { - if (op.getURI() != null && op.getURI().equals(pi.getPropertyURI())) { - return op.isSubjectSide() == pi.getSubjectSide(); - } - } - return false; - } - - private boolean alreadyOnPropertyList(List propsList, Property p) { - if (p.getURI() == null) { - log.error("Property p has no propertyURI in alreadyOnPropertyList()"); - return true; // don't add to list - } - for (Property ptest : propsList) { - if (ptest.getURI() != null && ptest.getURI().equals(p.getURI())) { - return true; - } - } - return false; - } - - private int populateGroupsListWithProperties(PropertyGroupDao pgDao, List groupsList, List mergedPropertyList, String unassignedGroupName) { - int count = groupsList.size(); - PropertyGroup tempGroup = null; - if (unassignedGroupName!=null) { - tempGroup = pgDao.createDummyPropertyGroup(unassignedGroupName,MAX_GROUP_DISPLAY_RANK); - log.debug("creating temp property group "+unassignedGroupName+" for any unassigned properties"); - } - switch (count) { - case 0: log.warn("groupsList has no groups on entering populateGroupsListWithProperties(); will create a new group \"other\""); - break; - case 1: break; - default: try { - Collections.sort(groupsList); - } catch (Exception ex) { - log.error("Exception on sorting groupsList in populateGroupsListWithProperties()"); - } - } - if (count==0 && unassignedGroupName!=null) { - groupsList.add(tempGroup); - } - for (PropertyGroup pg : groupsList) { - if (pg.getPropertyList().size()>0) { - pg.getPropertyList().clear(); - } - for (Property p : mergedPropertyList) { - if (p.getURI() == null) { - log.error("Property p has null URI in populateGroupsListWithProperties()"); - } else if (p.getGroupURI()==null) { - if (tempGroup!=null) { // not assigned any group yet and are creating a group for unassigned properties - if (!alreadyOnPropertyList(tempGroup.getPropertyList(),p)) { - tempGroup.getPropertyList().add(p); - log.debug("adding property "+p.getLabel()+" to members of temp group "+unassignedGroupName); - } - } // otherwise don't put that property on the list - } else if (p.getGroupURI().equals(pg.getURI())) { - if (!alreadyOnPropertyList(pg.getPropertyList(),p)) { - pg.getPropertyList().add(p); - } - } - } - if (pg.getPropertyList().size()>1) { - try { - Collections.sort(pg.getPropertyList(),new Property.DisplayComparatorIgnoringPropertyGroup()); - } catch (Exception ex) { - log.error("Exception sorting property group "+pg.getName()+" property list: "+ex.getMessage()); - } - } - } - if (count>0 && tempGroup!=null && tempGroup.getPropertyList().size()>0) { - groupsList.add(tempGroup); - } - count = groupsList.size(); - return count; - } - - private void doHelp(HttpServletResponse res) - throws IOException, ServletException { - ServletOutputStream out = res.getOutputStream(); - res.setContentType("text/html; charset=UTF-8"); - out.println("

Quick Notes on using EntityMergedPropList:

"); - out.println("

request.attributes 'entity' must be set by Entity servlet before calling." - +" It should already be 'filled out.'

"); - out.println(""); - } - - private class HelpException extends Throwable{ - - public HelpException(String string) { - super(string); - } - } - - private class PropertyRanker implements Comparator { - VitroRequest vreq; - WebappDaoFactory wdf; - PropertyGroupDao pgDao; - - - private PropertyRanker(VitroRequest vreq) { - this.vreq = vreq; - this.wdf = vreq.getWebappDaoFactory(); - this.pgDao = wdf.getPropertyGroupDao(); - } - - public int compare (Object o1, Object o2) { - Property p1 = (Property) o1; - Property p2 = (Property) o2; - - // sort first by property group rank; if the same, then sort by property rank - final int MAX_GROUP_RANK=99; - - int p1GroupRank=MAX_GROUP_RANK; - try { - if (p1.getGroupURI()!=null) { - PropertyGroup pg1 = pgDao.getGroupByURI(p1.getGroupURI()); - if (pg1!=null) { - p1GroupRank=pg1.getDisplayRank(); - } - } - } catch (Exception ex) { - log.error("Cannot retrieve p1GroupRank for group "+p1.getLabel()); - } - - int p2GroupRank=MAX_GROUP_RANK; - try { - if (p2.getGroupURI()!=null) { - PropertyGroup pg2 = pgDao.getGroupByURI(p2.getGroupURI()); - if (pg2!=null) { - p2GroupRank=pg2.getDisplayRank(); - } - } - } catch (Exception ex) { - log.error("Cannot retrieve p2GroupRank for group "+p2.getLabel()); - } - - // int diff = pgDao.getGroupByURI(p1.getGroupURI()).getDisplayRank() - pgDao.getGroupByURI(p2.getGroupURI()).getDisplayRank(); - int diff=p1GroupRank - p2GroupRank; - if (diff==0) { - diff = determineDisplayRank(p1) - determineDisplayRank(p2); - if (diff==0) { - return p1.getLabel().compareTo(p2.getLabel()); - } else { - return diff; - } - } - return diff; - } - - private int determineDisplayRank(Property p) { - if (p instanceof DataProperty) { - DataProperty dp = (DataProperty)p; - return dp.getDisplayTier(); - } else if (p instanceof ObjectProperty) { - ObjectProperty op = (ObjectProperty)p; - String tierStr = op.getDomainDisplayTier(); // no longer used: p.isSubjectSide() ? op.getDomainDisplayTier() : op.getRangeDisplayTier(); - try { - return Integer.parseInt(tierStr); - } catch (NumberFormatException ex) { - log.error("Cannot decode object property display tier value "+tierStr+" as an integer"); - } - } else { - log.error("Property is of unknown class in PropertyRanker()"); - } - return 0; - } - } - - private List collateBySubclass(List mergedPropertyList) { - for( Property prop : mergedPropertyList){ - if( prop instanceof ObjectProperty ) { - ObjectProperty op = (ObjectProperty) prop; - if (op.getCollateBySubclass() ){ - log.debug("Collating property " + prop.getURI() + " by subclass"); - collateBySubclass(op); - } else { - - } - } - } - return mergedPropertyList; - } - - /** - * Sort the object property statements for each property so that they - * are sorted first by subclass and then by rdfs:label. - * - * This will be tricky since "subclass" is vaguely defined. Here directly - * asserted classes are used. - */ - private void collateBySubclass(ObjectProperty prop) { - - List orgStmtList = getStatementsToCollate(prop); - - if( orgStmtList == null ) { - return; - } - - Map directClasses = getDirectClasses( getObjectsFromStmts( orgStmtList ) ); - - //don't do collateBySubclass if there is only one class - if( directClasses.size() < 2 ) { - // rjy7 Removed this, so we still get the heading for the single populated subclass - //prop.setCollateBySubclass(false); //this overrides the value from the model - // Still need to apply custom sort. Since we no longer set collateBySubclass to false, - // we won't know in applyCustomSortToUncollatedProperty whether the statements have - // been sorted or not, so we must do that now. - applyCustomSortToUncollatedStatements(prop, orgStmtList); - } else { - - log.debug("statements for object property: " + orgStmtList.size()); - //get list of direct classes and sort them - List vclasses = new LinkedList(directClasses.values()); - Collections.sort( - vclasses, - new Comparator(){ - public int compare(VClass o1, VClass o2) { - return o1.getName().compareTo(o2.getName()); - } - }); - - //order object property statements by sorted direct class list - List sortedStmtList = new LinkedList(); - for (VClass clazz : vclasses) { - // get all obj prop stmts with objects of this class - List stmtsForClass = new ArrayList(); - - log.debug("statements for object property: " + orgStmtList.size()); - Iterator it = orgStmtList.iterator(); - while( it.hasNext()){ - ObjectPropertyStatement stmt = it.next(); - //if (stmt.getObject().getVClasses(true).contains(clazz)) { - - Individual obj = stmt.getObject(); - List vclassesForObj = obj.getVClasses(true); - if (vclassesForObj != null && vclassesForObj.contains(clazz)) { - log.debug("adding " + stmt + " to class " - + clazz.getURI()); - log.debug("subjectURI " + stmt.getSubjectURI() - + " objectURI" + stmt.getObject().getURI()); - log.debug("stmtsForclass size: " - + stmtsForClass.size()); - log.debug("stmtsForclass size: " - + stmtsForClass.size()); - - stmtsForClass.add(stmt); - } - } - - //bdc34: What do we do if a object individual is directly asserted to two different - //types? For now we just show them in whichever type shows up first. related to NIHVIVO-876 - orgStmtList.removeAll(stmtsForClass); - - sortStatements(prop, stmtsForClass); - - log.debug("stmtsForclass size after sort: " - + stmtsForClass.size()); - log.debug("sortedStmtList size before add: " - + sortedStmtList.size()); - - sortedStmtList.addAll(stmtsForClass); - - log.debug("sortedStmtList size after add: " - + sortedStmtList.size()); - } - prop.setObjectPropertyStatements(sortedStmtList); - } - - } - - private List getStatementsToCollate(ObjectProperty prop) { - List statements = prop.getObjectPropertyStatements(); - - if (statements != null) { - String propertyUri = prop.getURI(); - - if (propertyUri.equals(VIVO_CORE_NAMESPACE + "authorInAuthorship")) { - return getStatementsForRelatedIndividuals(statements, VIVO_CORE_NAMESPACE + "linkedInformationResource"); - } - } - return statements; - } - - private List getStatementsForRelatedIndividuals(List statements, String op) { - - List relatedStatements = new ArrayList(statements.size()); - - for (ObjectPropertyStatement statement : statements) { - Individual object = statement.getObject(); - List statementsForObject = object.getObjectPropertyStatements(op); - // Could be empty for statements with no linked individual. - if ( ! statementsForObject.isEmpty() ) { - relatedStatements.add(statementsForObject.get(0)); - } - } - - return relatedStatements; - } - - private void sortStatements(ObjectProperty prop, List statements) { - - if (statements.size() < 2) { - return; - } - - if (!applyCustomSort(prop, statements)) { - Collections.sort(statements, - new Comparator() { - public int compare(ObjectPropertyStatement o1, - ObjectPropertyStatement o2) { - return o1.getObject().getName().compareTo( - o2.getObject().getName()); - } - } - ); - } - } - - // rjy7 Quick and dirty fix to achieve custom sorting for specific properties in the VIVO ontology. - // See NIHVIVO-426, NIHVIVO-1158, NIHVIVO-1160. Some of these involve sorting on data properties of an - // individual two graph edges away from the individual being displayed, for which there is currently - // no provision. A better strategy will be designed and implemented in a later version, in particular - // one that does not involve hard-coded references to the VIVO ontology in the Vitro core. - private boolean applyCustomSort(ObjectProperty prop, List statements) { - - String propertyUri = prop.getURI(); - - // Positions in an organization - if (propertyUri.equals(VIVO_CORE_NAMESPACE + "organizationForPosition")) { - sortByRelatedIndividualName(statements, VIVO_CORE_NAMESPACE + "positionForPerson"); - return true; - } - - // Person's positions - if (propertyUri.equals(VIVO_CORE_NAMESPACE + "personInPosition")) { - sortReverseChron(statements, VIVO_CORE_NAMESPACE + "endYear", VIVO_CORE_NAMESPACE + "startYear"); - return true; - } - - // Person's publications - // Note that, due to the custom collation, the object property statements actually have predicate - // linkedInformationResource. The property being sorted is still authorInAuthorship, however. - if (propertyUri.equals(VIVO_CORE_NAMESPACE + "authorInAuthorship")) { - sortByYearAndName(statements, VIVO_CORE_NAMESPACE + "year"); - return true; - } - - return false; - } - - private void applyCustomSortToUncollatedProperty(ObjectProperty op, List opStmts) { - if (!op.getCollateBySubclass()) { - applyCustomSortToUncollatedStatements(op, opStmts); - } - } - - // Apply custom sorting to an uncollated property. If the property is collated, the custom sorting has already - // been applied to each subclass listing individually. - private void applyCustomSortToUncollatedStatements(ObjectProperty op, List opStmts) { - if (applyCustomSort(op, opStmts)) { - op.setObjectPropertyStatements(opStmts); - } - } - - private void sortReverseChron(List statements, String endYearPredicate, String startYearPredicate) { - // 1. Sort by end year descending, nulls first - // 2. Then by start year descending, nulls last - // 3. No sorting for entries with no start or end year - just put at the bottom in random order - final String endYearProperty = endYearPredicate; - final String startYearProperty = startYearPredicate; - Collections.sort(statements, new Comparator() { - public int compare(ObjectPropertyStatement left, ObjectPropertyStatement right) { - - Individual objLeft = left.getObject(); - - String endLeftValue = objLeft.getDataValue(endYearProperty); - Integer endLeft = endLeftValue == null ? null : Integer.valueOf(endLeftValue); - - String startLeftValue = objLeft.getDataValue(startYearProperty); - Integer startLeft = startLeftValue == null ? null : Integer.valueOf(startLeftValue); - - Individual objRight = right.getObject(); - - String endRightValue = objRight.getDataValue(endYearProperty); - Integer endRight = endRightValue == null ? null : Integer.valueOf(endRightValue); - - String startRightValue = objRight.getDataValue(startYearProperty); - Integer startRight = startRightValue == null ? null : Integer.valueOf(startRightValue); - - // No sorting for entries with no start or end year - just put at the bottom in random order - if (endLeft == null && startLeft == null) { - return 1; - } - if (endRight == null && startRight == null) { - return -1; - } - - // First sort by end year - // A null end year precedes - // But if both end years are null, compare start years - if ( ! (endLeft == null && endRight == null) ) { - if (endLeft == null) { - return -1; - } - if (endRight == null) { - return 1; - } - - int endComp = endLeft.compareTo(endRight); - if (endComp != 0) { - return 0 - endComp; - } - } - - // If end years are equal, sort by start year - // A null start year follows - if (startLeft == null) { - return 1; - } - if (startRight == null) { - return -1; - } - - return 0 - startLeft.compareTo(startRight); - } - }); - } - - private void sortByYearAndName(List statements, String yearPredicate) { - // 1. Sort by year descending, nulls at end - // 2. If years are the same, sort by name - final String yearProperty = yearPredicate; - Collections.sort(statements, new Comparator() { - public int compare(ObjectPropertyStatement left, ObjectPropertyStatement right) { - - Individual indLeft = left.getObject(); - String leftYearValue = indLeft.getDataValue(yearProperty); - Integer leftYear = leftYearValue == null ? null : Integer.valueOf(leftYearValue); - - Individual indRight = right.getObject(); - String rightYearValue = indRight.getDataValue(yearProperty); - Integer rightYear = rightYearValue == null ? null : Integer.valueOf(rightYearValue); - - // First sort by year, nulls at end - // But if both null, sort by name - if ( ! (leftYear == null && rightYear == null) ) { - if (leftYear == null) { - return 1; - } - if (rightYear == null) { - return -1; - } - - int yearComp = leftYear.compareTo(rightYear); - if (yearComp != 0) { - return 0 - yearComp; - } - } - - // If years are equal, sort by publication name - return indLeft.getName().compareTo(indRight.getName()); - } - }); - } - - // Sort statements by the name of the individual on the other side of the context node. - private void sortByRelatedIndividualName(List statements, String predicateUri) { - - final String propertyUri = predicateUri; - Collections.sort(statements, new Comparator() { - public int compare(ObjectPropertyStatement left, ObjectPropertyStatement right) { - - Individual indLeft = left.getObject().getRelatedIndividual(propertyUri); - Individual indRight = right.getObject().getRelatedIndividual(propertyUri); - - if (indLeft == null) { - return indRight == null ? 0 : 1; - } - if (indRight == null) { - return -1; - } - - return indLeft.getName().compareTo(indRight.getName()); - } - }); - } - - private List getObjectsFromStmts(List orgStmtList) { - List individuals = new LinkedList(); - for( ObjectPropertyStatement stmt : orgStmtList ){ - individuals.add( stmt.getObject() ); - } - return individuals; - } - - private Map getDirectClasses(List objectsFromStmts) { - Map directClasses = new HashMap(); - - for (Individual ind : objectsFromStmts) { - for (VClass clazz : ind.getVClasses(true)) { - directClasses.put(clazz.getURI(),clazz); - } - } - return directClasses; - } - - /** - * Look for filter in servlet context and filter properties with it if there is one. - * - * This allows a vitro instance to have specialized filtering for display. It was originally - * created to deal with problems caused by custom short views. - * * - * @param objectPropertyList - * @param wdf - * @return - */ - private Individual filterFromContext(Individual ind ) { - try{ - UnaryFunctor filter = getMergedPropertyListFilter(getServletContext()); - if( filter == null ) - return ind; - else - return filter.fn(ind); - }catch(Throwable t){ - log.error(t,t); - } - return ind; - } - - public static void setMergedPropertyListFilter( UnaryFunctorfn, ServletContext sc){ - sc.setAttribute("EntityMergedPropertyListController.toFilteringIndividual", fn); - } - - public static UnaryFunctor getMergedPropertyListFilter( ServletContext sc){ - return(UnaryFunctor)sc.getAttribute("EntityMergedPropertyListController.toFilteringIndividual"); - } -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityPropertyListController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityPropertyListController.java deleted file mode 100644 index 36398cf52..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityPropertyListController.java +++ /dev/null @@ -1,74 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.controller; - -import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.beans.Individual; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -public class EntityPropertyListController extends VitroHttpServlet { - - /** - * This gets the Entity object in the requestScope "entity" and - * sets up the property list for it. After that a jsp is - * called to draw the data. - * - * Expected parameters: - * - * Expected Attributes: - * entity - set to entity to display properties for. - * - * @author bdc34 - */ - public void doGet( HttpServletRequest req, HttpServletResponse res ) - throws IOException, ServletException { - try { - //we don't need to call super because this method does no DAO calls. - //super.doGet(req, res); - Object obj = req.getAttribute("entity"); - if( obj == null || !(obj instanceof Individual)) - throw new HelpException("EntityPropertyListController requires request.attribute 'entity' to be of" - +" type " + Individual.class.getName() ); - Individual entity =(Individual)obj; - //sort property list in display order - entity.sortForDisplay(); - req.setAttribute("entity",entity); - - RequestDispatcher rd = req.getRequestDispatcher(Controllers.ENTITY_PROP_LIST_JSP); - rd.include(req,res); - } catch (HelpException help){ - doHelp(res); - } catch (Throwable e) { - req.setAttribute("javax.servlet.jsp.jspException",e); - RequestDispatcher rd = req.getRequestDispatcher("/error.jsp"); - rd.forward(req, res); - } - } - - public void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException,IOException { - doGet(request, response); - } - - private void doHelp(HttpServletResponse res) - throws IOException, ServletException { - ServletOutputStream out = res.getOutputStream(); - res.setContentType("text/html; charset=UTF-8"); - out.println("

Quick Notes on using EntityPropList:

"); - out.println("

request.attributes 'entity' must be set by Entity servlet before calling." - +" It should already be 'filled out.'

"); - out.println(""); - } - - private class HelpException extends Throwable{ - - public HelpException(String string) { - super(string); - }} -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/JSONServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/JSONServlet.java index a864f2396..697a7e905 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/JSONServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/JSONServlet.java @@ -8,7 +8,6 @@ import java.io.Writer; import java.net.URLEncoder; import java.util.ArrayList; import java.util.Enumeration; -import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.ListIterator; @@ -35,6 +34,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; import edu.cornell.mannlib.vitro.webapp.controller.TabEntitiesController.PageRecord; +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListController; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; @@ -43,8 +43,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.SelectListGenerator; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; -import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassGroupTemplateModel; -import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassTemplateModel; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel; /** @@ -222,9 +220,9 @@ public class JSONServlet extends VitroHttpServlet { .put("name",vclass.getName())); if (vclass != null) { - String alpha = EntityListController.getAlphaParamter(vreq); - int page = EntityListController.getPageParameter(vreq); - Map map = EntityListController.getResultsForVClass( + String alpha = IndividualListController.getAlphaParameter(vreq); + int page = IndividualListController.getPageParameter(vreq); + Map map = IndividualListController.getResultsForVClass( vclass.getURI(), page, alpha, diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/OntologyController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/OntologyController.java index 03fe1a202..fd0bcc61b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/OntologyController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/OntologyController.java @@ -47,7 +47,6 @@ public class OntologyController extends VitroHttpServlet{ private static final Log log = LogFactory.getLog(OntologyController.class.getName()); private String default_jsp = Controllers.BASIC_JSP; - private String default_body_jsp = Controllers.ENTITY_JSP; private ApplicationBean appBean; public void doPost(HttpServletRequest request, HttpServletResponse response) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java index 4d1ff2193..af8cef175 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java @@ -2,23 +2,45 @@ package edu.cornell.mannlib.vitro.webapp.controller.freemarker; +import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.lucene.document.Document; +import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.index.Term; +import org.apache.lucene.search.BooleanClause; +import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.PrefixQuery; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.ScoreDoc; +import org.apache.lucene.search.Sort; +import org.apache.lucene.search.TermQuery; +import org.apache.lucene.search.TopDocs; import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.beans.Portal; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; -import edu.cornell.mannlib.vitro.webapp.controller.EntityListController; +import edu.cornell.mannlib.vitro.webapp.controller.TabEntitiesController; import edu.cornell.mannlib.vitro.webapp.controller.TabEntitiesController.PageRecord; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; +import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; +import edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc; +import edu.cornell.mannlib.vitro.webapp.search.lucene.LuceneIndexFactory; +import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils; import edu.cornell.mannlib.vitro.webapp.utils.StringUtils; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ListedIndividualTemplateModel; import freemarker.ext.beans.BeansWrapper; @@ -32,6 +54,9 @@ public class IndividualListController extends FreemarkerHttpServlet { private static final long serialVersionUID = 1L; private static final Log log = LogFactory.getLog(IndividualListController.class.getName()); + public static final int ENTITY_LIST_CONTROLLER_MAX_RESULTS = 30000; + public static final int INDIVIDUALS_PER_PAGE = 30; + private static final String TEMPLATE_DEFAULT = "individualList.ftl"; @Override @@ -69,9 +94,9 @@ public class IndividualListController extends FreemarkerHttpServlet { body.put("vclassId", vclass.getURI()); if (vclass != null) { - String alpha = EntityListController.getAlphaParamter(vreq); - int page = EntityListController.getPageParameter(vreq); - Map map = EntityListController.getResultsForVClass( + String alpha = getAlphaParameter(vreq); + int page = getPageParameter(vreq); + Map map = getResultsForVClass( vclass.getURI(), page, alpha, @@ -132,4 +157,144 @@ public class IndividualListController extends FreemarkerHttpServlet { super(string); } } + + public static String getAlphaParameter(VitroRequest request){ + return request.getParameter("alpha"); + } + + public static int getPageParameter(VitroRequest request) { + String pageStr = request.getParameter("page"); + if( pageStr != null ){ + try{ + return Integer.parseInt(pageStr); + }catch(NumberFormatException nfe){ + log.debug("could not parse page parameter"); + return 1; + } + }else{ + return 1; + } + } + + /** + * This method is now called in a couple of places. It should be refactored + * into a DAO or similar object. + */ + public static Map getResultsForVClass(String vclassURI, int page, String alpha, Portal portal, boolean isSinglePortal, IndividualDao indDao, ServletContext context) + throws CorruptIndexException, IOException, ServletException{ + Map rvMap = new HashMap(); + + int portalId = 1; + if( portal != null ) + portalId = portal.getPortalId(); + + //make lucene query for this rdf:type + Query query = getQuery(vclassURI,alpha, isSinglePortal, portalId); + + //execute lucene query for individuals of the specified type + IndexSearcher index = LuceneIndexFactory.getIndexSearcher(context); + TopDocs docs = null; + try{ + docs = index.search(query, null, + ENTITY_LIST_CONTROLLER_MAX_RESULTS, + new Sort(Entity2LuceneDoc.term.NAMELOWERCASE)); + }catch(Throwable th){ + log.error("Could not run search. " + th.getMessage()); + docs = null; + } + + if( docs == null ) + throw new ServletException("Could not run search in IndividualListController"); + + //get list of individuals for the search results + int size = docs.totalHits; + log.debug("Number of search results: " + size); + + // don't get all the results, only get results for the requestedSize + List individuals = new ArrayList(INDIVIDUALS_PER_PAGE); + int individualsAdded = 0; + int ii = (page-1)*INDIVIDUALS_PER_PAGE; + while( individualsAdded < INDIVIDUALS_PER_PAGE && ii < size ){ + ScoreDoc hit = docs.scoreDocs[ii]; + if (hit != null) { + Document doc = index.doc(hit.doc); + if (doc != null) { + String uri = doc.getField(Entity2LuceneDoc.term.URI).stringValue(); + Individual ind = indDao.getIndividualByURI( uri ); + if( ind != null ){ + individuals.add( ind ); + individualsAdded++; + } + } else { + log.warn("no document found for lucene doc id " + hit.doc); + } + } else { + log.debug("hit was null"); + } + ii++; + } + + rvMap.put("count", size); + + if( size > INDIVIDUALS_PER_PAGE ){ + rvMap.put("showPages", Boolean.TRUE); + List pageRecords = TabEntitiesController.makePagesList(size, INDIVIDUALS_PER_PAGE, page); + rvMap.put("pages", pageRecords); + }else{ + rvMap.put("showPages", Boolean.FALSE); + rvMap.put("pages", Collections.emptyList()); + } + + rvMap.put("alpha",alpha); + + rvMap.put("totalCount", size); + rvMap.put("entities",individuals); + if (individuals == null) + log.debug("entities list is null for vclass " + vclassURI ); + + return rvMap; + } + + private static BooleanQuery getQuery(String vclassUri, String alpha , boolean isSinglePortal, int portalId){ + BooleanQuery query = new BooleanQuery(); + try{ + //query term for rdf:type + query.add( + new TermQuery( new Term(Entity2LuceneDoc.term.RDFTYPE, vclassUri)), + BooleanClause.Occur.MUST ); + + //check for portal filtering + if( ! isSinglePortal ){ + if( portalId < 16 ){ //could be a normal portal + query.add( + new TermQuery( new Term(Entity2LuceneDoc.term.PORTAL, Integer.toString(1 << portalId ))), + BooleanClause.Occur.MUST); + }else{ //could be a combined portal + BooleanQuery tabQueries = new BooleanQuery(); + Long[] ids= FlagMathUtils.numeric2numerics(portalId); + for( Long id : ids){ + tabQueries.add( + new TermQuery( new Term(Entity2LuceneDoc.term.PORTAL,id.toString()) ), + BooleanClause.Occur.SHOULD); + } + query.add(tabQueries,BooleanClause.Occur.MUST); + } + } + + //Add alpha filter if it is needed + Query alphaQuery = null; + if( alpha != null && !"".equals(alpha) && alpha.length() == 1){ + alphaQuery = + new PrefixQuery(new Term(Entity2LuceneDoc.term.NAMELOWERCASE, alpha.toLowerCase())); + query.add(alphaQuery,BooleanClause.Occur.MUST); + } + + log.debug("Query: " + query); + return query; + }catch (Exception ex){ + log.error(ex,ex); + return new BooleanQuery(); + } + } + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/TabIndividualRelationDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/TabIndividualRelationDaoJena.java index e3d931320..83aa6be1c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/TabIndividualRelationDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/TabIndividualRelationDaoJena.java @@ -2,6 +2,12 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.rdf.model.Resource; @@ -9,27 +15,16 @@ import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.util.iterator.ClosableIterator; import com.hp.hpl.jena.vocabulary.RDF; + import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Tab; import edu.cornell.mannlib.vitro.webapp.beans.TabIndividualRelation; -import edu.cornell.mannlib.vitro.webapp.controller.EntityController; -import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.TabIndividualRelationDao; -import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; +import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; public class TabIndividualRelationDaoJena extends JenaBaseDao implements TabIndividualRelationDao { - private static final Log log = LogFactory.getLog(EntityController.class.getName()); + private static final Log log = LogFactory.getLog(TabIndividualRelationDaoJena.class.getName()); public TabIndividualRelationDaoJena(WebappDaoFactoryJena wadf) { super(wadf); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java deleted file mode 100644 index 6eb4ad8fc..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java +++ /dev/null @@ -1,640 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.search.controller; - -import java.io.IOException; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.lucene.analysis.Analyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.apache.lucene.index.CorruptIndexException; -import org.apache.lucene.index.Term; -import org.apache.lucene.queryParser.ParseException; -import org.apache.lucene.queryParser.QueryParser; -import org.apache.lucene.search.BooleanClause; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TermQuery; -import org.apache.lucene.search.TopDocs; -import org.apache.lucene.search.WildcardQuery; - -import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.beans.Portal; -import edu.cornell.mannlib.vitro.webapp.beans.VClass; -import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; -import edu.cornell.mannlib.vitro.webapp.controller.Controllers; -import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet; -import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; -import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; -import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; -import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao; -import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; -import edu.cornell.mannlib.vitro.webapp.flags.PortalFlag; -import edu.cornell.mannlib.vitro.webapp.search.SearchException; -import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQuery; -import edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc; -import edu.cornell.mannlib.vitro.webapp.search.lucene.LuceneIndexFactory; -import edu.cornell.mannlib.vitro.webapp.search.lucene.LuceneSetup; -import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils; - -/** - * PagedSearchController is the new search controller that interacts - * directly with the lucene API and returns paged, relevance ranked results. - * - * @author bdc34 - * - */ -public class PagedSearchController extends VitroHttpServlet { - private static final Log log = LogFactory.getLog(PagedSearchController.class.getName()); - String NORESULT_MSG = "The search returned no results."; - private int defaultHitsPerPage = 25; - private int defaultMaxSearchSize= 1000; - - public void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - doGet(request, response); - } - - public void doGet(HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException { - try { - super.doGet(request,response); - VitroRequest vreq = new VitroRequest(request); - Portal portal = vreq.getPortal(); - PortalFlag portalFlag = vreq.getPortalFlag(); - - //make sure an IndividualDao is available - if( vreq.getWebappDaoFactory() == null - || vreq.getWebappDaoFactory().getIndividualDao() == null ){ - log.error("makeUsableBeans() could not get IndividualDao "); - doSearchError(request, response, "Could not access Model", portalFlag); - return; - } - IndividualDao iDao = vreq.getWebappDaoFactory().getIndividualDao(); - VClassGroupDao grpDao = vreq.getWebappDaoFactory().getVClassGroupDao(); - VClassDao vclassDao = vreq.getWebappDaoFactory().getVClassDao(); - String alphaFilter = vreq.getParameter("alpha"); - - int startIndex = 0; - try{ - startIndex = Integer.parseInt(request.getParameter("startIndex")); - }catch (Throwable e) { - startIndex = 0; - } - log.debug("startIndex is " + startIndex); - - int hitsPerPage = defaultHitsPerPage; - try{ - hitsPerPage = Integer.parseInt(request.getParameter("hitsPerPage")); - } catch (Throwable e) { - hitsPerPage = defaultHitsPerPage; - } - log.debug("hitsPerPage is " + hitsPerPage); - - int maxHitSize = defaultMaxSearchSize; - if( startIndex >= defaultMaxSearchSize - hitsPerPage ) - maxHitSize = startIndex + defaultMaxSearchSize; - if( alphaFilter != null ){ - maxHitSize = maxHitSize * 2; - hitsPerPage = maxHitSize; - } - log.debug("maxHitSize is " + maxHitSize); - - String qtxt = vreq.getParameter(VitroQuery.QUERY_PARAMETER_NAME); - Analyzer analyzer = getAnalyzer(getServletContext()); - - Query query = null; - try { - query = getQuery(vreq, portalFlag, analyzer, qtxt); - } catch (ParseException e) { - log.warn("Query parse exception: " + e); - doBadQuery(qtxt, request, response); - return; - } - - log.debug("query for '" + qtxt +"' is " + query.toString()); - - IndexSearcher searcherForRequest = LuceneIndexFactory.getIndexSearcher(getServletContext()); - - TopDocs topDocs = null; - try{ - topDocs = searcherForRequest.search(query,null,maxHitSize); - }catch(Throwable t){ - log.error("in first pass at search: " + t); - // this is a hack to deal with odd cases where search and index threads interact - try{ - wait(150); - topDocs = searcherForRequest.search(query,null,maxHitSize); - }catch (Exception ex){ - log.error(ex); - String msg = makeBadSearchMessage(qtxt,ex.getMessage()); - if(msg == null ) msg = "

The search request contained errors.

"; - doFailedSearch(request, response, msg, qtxt); - return; - } - } - - if( topDocs == null || topDocs.scoreDocs == null){ - log.error("topDocs for a search was null"); - String msg = "

The search request contained errors.

"; - doFailedSearch(request, response, msg, qtxt); - return; - } - - int hitsLength = topDocs.scoreDocs.length; - if ( hitsLength < 1 ){ - doFailedSearch(request, response, NORESULT_MSG, qtxt); - return; - } - log.debug("found "+hitsLength+" hits"); - - int lastHitToShow = 0; - if((startIndex + hitsPerPage) > hitsLength ) - lastHitToShow = hitsLength; - else - lastHitToShow = startIndex + hitsPerPage - 1; - - List beans = new LinkedList(); - for(int i=startIndex; i= startIndex) && (i <= lastHitToShow) ){ - Document doc = searcherForRequest.doc(topDocs.scoreDocs[i].doc); - String uri = doc.get(Entity2LuceneDoc.term.URI); - Individual ent = iDao.getIndividualByURI(uri); - if(ent != null ){ - Listvcs = ent.getVClasses() ; - if( vcs != null && !vcs.isEmpty() ){ - beans.add(ent); - log.debug("found individual for search hit in model" + uri ); - }else{ - log.debug("filtered out classless individual from search results" + uri); - } - }else{ - log.debug("could not find individual for search hit in model " + uri); - } - } - }catch(Exception e){ - log.error("problem getting usable Individuals from search " + - "hits" + e.getMessage()); - } - } - - //search request for no classgroup and no type so add classgroup search refinement links. - if( request.getParameter("classgroup") == null && request.getParameter("type") == null){ - request.setAttribute("classgroups", - getClassGroups(grpDao, topDocs, searcherForRequest)); - request.setAttribute("refinment", ""); - }else{ - - //search request for a classgroup so add rdf:type search refinement links - //but try to filter out classes that are subclasses - if( request.getParameter("classgroup") != null && request.getParameter("type") == null ){ - request.setAttribute("types", - getVClasses(vclassDao,topDocs,searcherForRequest)); - request.setAttribute("refinment", "&classgroup=" - + URLEncoder.encode(request.getParameter("classgroup"),"UTF-8")); - }else{ - if( alphaFilter != null && !"".equals(alphaFilter)){ - request.setAttribute("alphas", getAlphas(topDocs, searcherForRequest)); - alphaSortIndividuals(beans); - }else{ - request.setAttribute("refinment", "&type=" - + URLEncoder.encode(request.getParameter("type"),"UTF-8")); - } - } - } - - //stick the results in the requestScope and prepare to forward to JSP - request.setAttribute("beans", beans); - - request.setAttribute("title", qtxt+" - "+portal.getAppName()+" Search Results" ); - request.setAttribute("bodyJsp", Controllers.SEARCH_PAGED_JSP); - request.setAttribute("querytext", qtxt); - request.setAttribute("startIndex", startIndex); - request.setAttribute("hitsPerPage", hitsPerPage); - request.setAttribute("hitsLength", hitsLength); - request.setAttribute("maxHitSize", maxHitSize); - String param = request.getParameter("classgroup"); - if(param != null && !"".equals(param)){ - VClassGroup grp = grpDao.getGroupByURI(param); - if( grp != null && grp.getPublicName() != null ) - request.setAttribute("classgroupName", grp.getPublicName()); - } - param = request.getParameter("type"); - if(param != null && !"".equals(param)){ - VClass type = vclassDao.getVClassByURI(param); - if( type != null && type.getName() != null ) - request.setAttribute("typeName", type.getName()); - } - -// VitroQueryWrapper queryWrapper = -// new VitroQueryWrapper(query, -// (VitroHighlighter)searcher.getHighlighter(query), -// 2, time); -// request.getSession(true).setAttribute("LastQuery", queryWrapper); -// log.debug("query wrapper created"); - - request.getRequestDispatcher(Controllers.BASIC_JSP).forward(request,response); - } catch (Throwable e) { - log.error("PagedSearchController.doGet(): " + e, e); - doSearchError(request, response, e.getMessage(), null); - return; - } - } - - private void alphaSortIndividuals(List beans) { - Collections.sort(beans, new Comparator< Individual >(){ - public int compare(Individual o1, Individual o2) { - if( o1 == null || o1.getName() == null ) - return 1; - else - return o1.getName().compareTo(o2.getName()); - }}); - } - - private List getAlphas(TopDocs topDocs, IndexSearcher searcher) { - Set alphas = new HashSet(); - for(int i=0;i 0) - alphas.add( name.substring(0, 1)); - } catch (CorruptIndexException e) { - log.debug("Could not get alphas for document",e); - } catch (IOException e) { - log.debug("Could not get alphas for document",e); - } - - } - return new ArrayList(alphas); - } - - /** - * Get the class groups represented for the individuals in the topDocs. - */ - private List getClassGroups(VClassGroupDao grpDao, TopDocs topDocs, - IndexSearcher searcherForRequest) { - LinkedHashMap grpMap = grpDao.getClassGroupMap(); - int n = grpMap.size(); - - HashSet classGroupsInHits = new HashSet(n); - int grpsFound = 0; - - for(int i=0; i grpsFound ;i++){ - try{ - Document doc = searcherForRequest.doc(topDocs.scoreDocs[i].doc); - Field[] grps = doc.getFields(Entity2LuceneDoc.term.CLASSGROUP_URI); - if(grps != null || grps.length > 0){ - for(int j=0;j= n ) - break; - } - } - } - }catch(Exception e){ - log.error("problem getting VClassGroups from search hits " - + e.getMessage()); - } - } - - List classgroupURIs= Collections.list(Collections.enumeration(classGroupsInHits)); - List classgroups = new ArrayList( classgroupURIs.size() ); - for(String cgUri: classgroupURIs){ - if( cgUri != null && ! "".equals(cgUri) ){ - VClassGroup vcg = grpDao.getGroupByURI( cgUri ); - if( vcg == null ){ - log.debug("could not get classgroup for URI " + cgUri); - }else{ - classgroups.add(vcg); - } - } - } - grpDao.sortGroupList(classgroups); - return classgroups; - } - - private List getVClasses(VClassDao vclassDao, TopDocs topDocs, - IndexSearcher searherForRequest){ - HashSet typesInHits = getVClassUrisForHits(topDocs,searherForRequest); - List classes = new ArrayList(typesInHits.size()); - - Iterator it = typesInHits.iterator(); - while(it.hasNext()){ - String typeUri = it.next(); - try{ - if( VitroVocabulary.OWL_THING.equals(typeUri)) - continue; - VClass type = vclassDao.getVClassByURI(typeUri); - if( ! type.isAnonymous() && - type.getName() != null && !"".equals(type.getName()) && - type.getGroupURI() != null ) //don't display classes that aren't in classgroups - classes.add(type); - }catch(Exception ex){ - if( log.isDebugEnabled() ) - log.debug("could not add type " + typeUri, ex); - } - } - Collections.sort(classes, new Comparator(){ - public int compare(VClass o1, VClass o2) { - return o1.compareTo(o2); - }}); - return classes; - } - - private HashSet getVClassUrisForHits(TopDocs topDocs, - IndexSearcher searcherForRequest){ - HashSet typesInHits = new HashSet(); - for(int i=0; i MAX_QUERY_LENGTH ){ - log.debug("The search was too long. The maximum " + - "query length is " + MAX_QUERY_LENGTH ); - return null; - } - QueryParser parser = getQueryParser(analyzer); - - query = parser.parse(querystr); - - String alpha = request.getParameter("alpha"); - if( alpha != null && !"".equals(alpha) && alpha.length() == 1){ - BooleanQuery boolQuery = new BooleanQuery(); - boolQuery.add( query, BooleanClause.Occur.MUST ); - boolQuery.add( - new WildcardQuery(new Term(Entity2LuceneDoc.term.NAME, alpha+'*')), - BooleanClause.Occur.MUST); - query = boolQuery; - } - - //check if this is classgroup filtered - Object param = request.getParameter("classgroup"); - if( param != null && !"".equals(param)){ - BooleanQuery boolQuery = new BooleanQuery(); - boolQuery.add( query, BooleanClause.Occur.MUST); - boolQuery.add( new TermQuery( - new Term(Entity2LuceneDoc.term.CLASSGROUP_URI, - (String)param)), - BooleanClause.Occur.MUST); - query = boolQuery; - } - - //check if this is rdf:type filtered - param = request.getParameter("type"); - if( param != null && !"".equals(param)){ - BooleanQuery boolQuery = new BooleanQuery(); - boolQuery.add( query, BooleanClause.Occur.MUST); - boolQuery.add( new TermQuery( - new Term(Entity2LuceneDoc.term.RDFTYPE, - (String)param)), - BooleanClause.Occur.MUST); - query = boolQuery; - } - - //if we have a flag/portal query then we add - //it by making a BooelanQuery. - Query flagQuery = makeFlagQuery( portalState ); - if( flagQuery != null ){ - BooleanQuery boolQuery = new BooleanQuery(); - boolQuery.add( query, BooleanClause.Occur.MUST); - boolQuery.add( flagQuery, BooleanClause.Occur.MUST); - query = boolQuery; - } - - log.debug("Query: " + query); - - } catch (ParseException e) { - throw new ParseException(e.getMessage()); - } catch (Exception ex){ - throw new SearchException(ex.getMessage()); - } - - return query; - } - - @SuppressWarnings("static-access") - private QueryParser getQueryParser(Analyzer analyzer){ - //defaultSearchField indicates which field search against when there is no term - //indicated in the query string. - //The analyzer is needed so that we use the same analyzer on the search queries as - //was used on the text that was indexed. - QueryParser qp = new QueryParser(defaultSearchField,analyzer); - //this sets the query parser to AND all of the query terms it finds. - qp.setDefaultOperator(QueryParser.AND_OPERATOR); - //set up the map of stemmed field names -> unstemmed field names -// HashMap map = new HashMap(); -// map.put(Entity2LuceneDoc.term.ALLTEXT,Entity2LuceneDoc.term.ALLTEXTUNSTEMMED); -// qp.setStemmedToUnstemmed(map); - return qp; - } - - /** - * Makes a flag based query clause. This is where searches can filtered - * by portal. - * - * If you think that search is not working correctly with protals and - * all that kruft then this is a method you want to look at. - * - * It only takes into account "the portal flag" and flag1Exclusive must - * be set. Where does that stuff get set? Look in vitro.flags.PortalFlag - * - * One thing to keep in mind with portal filtering and search is that if - * you want to search a portal that is different then the portal the user - * is 'in' then the home parameter should be set to force the user into - * the new portal. - * - * Ex. Bob requests the search page for vivo in portal 3. You want to - * have a drop down menu so bob can search the all CALS protal, id 60. - * You need to have a home=60 on your search form. If you don't set - * home=60 with your search query, then the search will not be in the - * all portal AND the WebappDaoFactory will be filtered to only show - * things in portal 3. - * - * Notice: flag1 as a parameter is ignored. bdc34 2009-05-22. - */ - @SuppressWarnings("static-access") - private Query makeFlagQuery( PortalFlag flag){ - if( flag == null || !flag.isFilteringActive() - || flag.getFlag1DisplayStatus() == flag.SHOW_ALL_PORTALS ) - return null; - - // make one term for each bit in the numeric flag that is set - Collection terms = new LinkedList(); - int portalNumericId = flag.getFlag1Numeric(); - Long[] bits = FlagMathUtils.numeric2numerics(portalNumericId); - for (Long bit : bits) { - terms.add(new TermQuery(new Term(Entity2LuceneDoc.term.PORTAL, Long - .toString(bit)))); - } - - // make a boolean OR query for all of those terms - BooleanQuery boolQuery = new BooleanQuery(); - if (terms.size() > 0) { - for (TermQuery term : terms) { - boolQuery.add(term, BooleanClause.Occur.SHOULD); - } - return boolQuery; - } else { - //we have no flags set, so no flag filtering - return null; - } - } - - private void doBadQuery(String queryStr, HttpServletRequest request, - HttpServletResponse response) - throws ServletException, IOException { - Portal portal = (new VitroRequest(request)).getPortal(); - request.setAttribute("title", "Search "+portal.getAppName()); - request.setAttribute("bodyJsp", Controllers.SEARCH_BAD_QUERY_JSP); - request.setAttribute("queryStr", queryStr); - - RequestDispatcher rd = request - .getRequestDispatcher(Controllers.BASIC_JSP); - rd.forward(request, response); - } - - private void doFailedSearch(HttpServletRequest request, - HttpServletResponse response, String message, String querytext) - throws ServletException, IOException { - Portal portal = (new VitroRequest(request)).getPortal(); - if( querytext != null ){ - request.setAttribute("querytext", querytext); - request.setAttribute("title", querytext+" - "+portal.getAppName()+" Search" ); - }else{ - request.setAttribute("title", portal.getAppName()+" Search" ); - request.setAttribute("querytext", ""); - } - if( message != null && message.length() > 0) - request.setAttribute("message", message); - - request.setAttribute("bodyJsp", Controllers.SEARCH_FAILED_JSP); - RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); - rd.forward(request, response); - } - - - /** - * Makes a message to display to user for a bad search term. - * @param query - * @param exceptionMsg - */ - private String makeBadSearchMessage(String querytext, String exceptionMsg){ - String rv = ""; - try{ - //try to get the column in the search term that is causing the problems - int coli = exceptionMsg.indexOf("column"); - if( coli == -1) return ""; - int numi = exceptionMsg.indexOf(".", coli+7); - if( numi == -1 ) return ""; - String part = exceptionMsg.substring(coli+7,numi ); - int i = Integer.parseInt(part) - 1; - - // figure out where to cut preview and post-view - int errorWindow = 5; - int pre = i - errorWindow; - if (pre < 0) - pre = 0; - int post = i + errorWindow; - if (post > querytext.length()) - post = querytext.length(); - // log.warn("pre: " + pre + " post: " + post + " term len: - // " + term.length()); - - // get part of the search term before the error and after - String before = querytext.substring(pre, i); - String after = ""; - if (post > i) - after = querytext.substring(i + 1, post); - - rv = "The search term had an error near " - + before + "" + querytext.charAt(i) - + "" + after + ""; - } catch (Throwable ex) { - return ""; - } - return rv; - } - - @SuppressWarnings("unchecked") - private HashSet getDataPropertyBlacklist(){ - HashSetdpBlacklist = (HashSet) - getServletContext().getAttribute(LuceneSetup.SEARCH_DATAPROPERTY_BLACKLIST); - return dpBlacklist; - } - - @SuppressWarnings("unchecked") - private HashSet getObjectPropertyBlacklist(){ - HashSetopBlacklist = (HashSet) - getServletContext().getAttribute(LuceneSetup.SEARCH_OBJECTPROPERTY_BLACKLIST); - return opBlacklist; - } - - private void doSearchError(HttpServletRequest request, - HttpServletResponse response, String message, Object object) - throws ServletException, IOException { - Portal portal = (new VitroRequest(request)).getPortal(); - - request.setAttribute("bodyJsp", Controllers.SEARCH_ERROR_JSP); - RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); - rd.forward(request, response); - } - private final String defaultSearchField = "ALLTEXT"; - public static final int MAX_QUERY_LENGTH = 500; - -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/SearchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/SearchController.java deleted file mode 100644 index 74c4f72c1..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/SearchController.java +++ /dev/null @@ -1,648 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.search.controller; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import edu.cornell.mannlib.vitro.webapp.beans.Individual; -import edu.cornell.mannlib.vitro.webapp.beans.Portal; -import edu.cornell.mannlib.vitro.webapp.beans.Tab; -import edu.cornell.mannlib.vitro.webapp.beans.VClass; -import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; -import edu.cornell.mannlib.vitro.webapp.beans.VClassList; -import edu.cornell.mannlib.vitro.webapp.controller.Controllers; -import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet; -import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; -import edu.cornell.mannlib.vitro.webapp.flags.PortalFlag; -import edu.cornell.mannlib.vitro.webapp.search.SearchException; -import edu.cornell.mannlib.vitro.webapp.search.beans.Searcher; -import edu.cornell.mannlib.vitro.webapp.search.beans.VitroHighlighter; -import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQuery; -import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQueryFactory; -import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQueryWrapper; - -/** - * This controller will execute the search and process - * the search resutls into entites. Those entites will be stuffed - * into the request scope and the controll will be passed to a - * jsp for rendering html. - * - * -- What are the parameters that this servlet uses? - * This servlet uses the PortalFlag to represent which portal and how - * the portals will be accounted for in the search. So you should look - * at edu.cornell.mannlib.vitro.flags.PortalFlag to find out what http parameters - * cause it to be set to what states. - * - * Here is a quick run down of the interesting ones: - * filter - if set to 'false' no flag filtering will happen - * flag1 - if set to 'nofiltering' no flag filtering will happen - * querytext - query text to use for search. - * - * This controller will 1) use VitroServlet to process the httpRequest - * for parameters 2) build a query and execute it on the - * index 3) take the results of the query, which are just entity ids, - * and turn them into short entities 4) highlight the entities. - * 5) sort into ClassGroups 6) stick into the request scope. - * - * - * This controller will do the searing for any kind of search - * back end. There are two things that make this possible: 1 - * interfaces, 2 stashing a pointer to the instance of the search - * that we intend to use. - * - * 1) an interface is a definition of method signatures with no - * code. This is similar to a c header file. It allows us to define - * a set of methods we can call without having to know what will - * happen for us to get the outputs of those methods. - * - * 2) Once we have this we need a way to get an instantiated object - * that implements the interface we are interested in using. There - * are different ways of doing this. We will just get an object out - * of the application scope. This object was set when the context - * started up and can be set in the web.xml. See LuceneSetup.java - * for an example. - * - * @deprecated Use PagedSearchController instead. - */ -public class SearchController extends VitroHttpServlet{ - private static final Log log = LogFactory.getLog(SearchController.class.getName()); - String NORESULT_MSG = "The search returned no results."; - - public void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - doGet(request, response); - } - - /** - * - * - * @author bdc34 - */ - public void doGet(HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException { - try { - //this will set up the portal flag, which is where the search query - //will get ALL of the information about portal filtering. - super.doGet(request,response); - VitroRequest vreq = new VitroRequest(request); - Portal portal = vreq.getPortal(); - PortalFlag portalFlag = vreq.getPortalFlag(); - - // //////////////////////////////////////////////////////////////////// - // FIRST: we want to get the search object - // All that we know about it is that it implements the Searcher - // interface. - ServletContext context = getServletContext(); - Searcher searcher = (Searcher) context.getAttribute(Searcher.class.getName()); - - // /////////////////////////////////////////////////////////////////// - // NEXT: we make a query. The searcher object has a method that - // makes a - // query for us. This allows the search object to implement specific - // transformations from the request to the query. - // Possible improvement: make some kind of standard queryRequest - // object that all QueryFactory objs take. - - VitroQueryFactory qFactory = searcher.getQueryFactory(); - VitroQuery query = qFactory.getQuery(vreq, portalFlag); - - // qFactory.getQuery() will return null when there is not enough - // information in the request to make a query. - if (query == null ) { - doNoQuery(request, response); - return; - } - - // //////////////////////////////////////////////////////////////////// - // Now we want to do the search - long start = System.currentTimeMillis(); - List hits = null; - try{ - hits = searcher.search(query); - }catch(Throwable t){ - log.error("in first pass at search: " + t); - // this is a hack to deal with odd cases where search and index threads interact - try{ - Thread.currentThread().sleep(150); - hits = searcher.search(query); - }catch (SearchException ex){ - log.error(ex); - String msg = makeBadSearchMessage(query,ex.getMessage()); - if(msg == null ) msg = "

The search request contained errors.

"; - doFailedSearch(request, response, msg, query); - return; - } - } - - long end = System.currentTimeMillis(); - long time=end-start; - - if (hits == null || hits.size() < 1) { - doFailedSearch(request, response, NORESULT_MSG, query); - return; - } - log.debug("found "+hits+" hits"); - - // now we have hits which are only entity ids - // so convert the hits to usable entity beans - List beans = makeUsableBeans(hits,vreq); - log.debug("makeUsableBeans() succeeded"); - - //sort by ClassGroup and the sort the ClassGroups - Map collatedListOfLists = null; - if (beans != null && beans.size() > 0) { // collate entities - collatedListOfLists = collate(beans,vreq); // sort each classgroup - // list by a default - // setting if available - // sort each class group - collatedListOfLists = sortClassGroups(collatedListOfLists); - } - log.debug("sort by classgroups succeeded"); - - VClassGroup.removeEmptyClassGroups(collatedListOfLists); - log.debug("empty classgroups removed"); - collateClassGroupsByVClass(collatedListOfLists.values()); - log.debug("classgroups collated"); - - //Now collatedLitOfLists has Map of VCLassGroups - //and each VClassGroup has a list of VCLassList, each with a list of entities. - - //attempt to do highlighting - try { - beans = highlightBeans( beans , searcher.getHighlighter(query) ); - } catch (Exception e) { - log.error("Error highlighting search result beans", e); - } - log.debug("beans highlighted"); - - // //////////////////////////////////////////////////////////////////// - // stick the data in the requestScope and sessionScope - - // stick the results in the requestScope: - request.setAttribute("collatedResultsLists", collatedListOfLists); - request.setAttribute("collatedGroupNames", collatedListOfLists - .keySet()); - - String terms = query.getTerms(); - - request.setAttribute("title", terms+" - "+portal.getAppName()+" Search Results" ); - request.setAttribute("bodyJsp", Controllers.SEARCH_BASIC_JSP); - request.setAttribute("css", Controllers.TOGGLE_SCRIPT_ELEMENT); - request.setAttribute("querytext", terms); - - VitroQueryWrapper queryWrapper = - new VitroQueryWrapper(query, - (VitroHighlighter)searcher.getHighlighter(query), - 2, time); - request.getSession(true).setAttribute("LastQuery", queryWrapper); - - log.debug("query wrapper created"); - - // //////////////////////////////////////////////////////////////////// - // FINALLY: send off to the BASIC_JSP to get turned into html - - RequestDispatcher rd = request - .getRequestDispatcher(Controllers.BASIC_JSP); - rd.forward(request, response); - } catch (Throwable e) { - log.error("SearchController.doGet(): " + e); - doSearchError(request, response, e.getMessage(), null); - return; - } - } - - private void doSearchError(HttpServletRequest request, - HttpServletResponse response, String message, Object object) - throws ServletException, IOException { - Portal portal = (new VitroRequest(request)).getPortal(); - - request.setAttribute("bodyJsp", Controllers.SEARCH_ERROR_JSP); - RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); - rd.forward(request, response); - } - - private List highlightBeans(List beans, VitroHighlighter highlighter) { - Iterator it = beans.iterator(); - while(it.hasNext()){ - Object obj = it.next(); - if( obj instanceof Individual){ - Individual ent = (Individual)obj; - highlighter.fragmentHighlight(ent); - } - } - return beans; - } - - private void doNoQuery(HttpServletRequest request, - HttpServletResponse response) - throws ServletException, IOException { - Portal portal = (new VitroRequest(request)).getPortal(); - request.setAttribute("title", "Search "+portal.getAppName()); - request.setAttribute("bodyJsp", Controllers.SEARCH_FORM_JSP); - - RequestDispatcher rd = request - .getRequestDispatcher(Controllers.BASIC_JSP); - rd.forward(request, response); - } - - private void doFailedSearch(HttpServletRequest request, - HttpServletResponse response, String message, VitroQuery query) - throws ServletException, IOException { - Portal portal = (new VitroRequest(request)).getPortal(); - if( query != null ){ - String terms = query.getTerms(); - request.setAttribute("querytext", terms); - request.setAttribute("title", terms+" - "+portal.getAppName()+" Search" ); - }else{ - request.setAttribute("title", portal.getAppName()+" Search" ); - request.setAttribute("querytext", ""); - } - if( message != null && message.length() > 0) - request.setAttribute("message", message); - - request.setAttribute("bodyJsp", Controllers.SEARCH_FAILED_JSP); - RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); - rd.forward(request, response); - } - - - /** - * Makes a message to display to user for a bad search term. - * @param query - * @param exceptionMsg - */ - private String makeBadSearchMessage(VitroQuery query, String exceptionMsg){ - String term = query.getTerms(); - String rv = ""; - try{ - //try to get the column in the search term that is causing the problems - int coli = exceptionMsg.indexOf("column"); - if( coli == -1) return ""; - int numi = exceptionMsg.indexOf(".", coli+7); - if( numi == -1 ) return ""; - String part = exceptionMsg.substring(coli+7,numi ); - int i = Integer.parseInt(part) - 1; - - // figure out where to cut preview and post-view - int errorWindow = 5; - int pre = i - errorWindow; - if (pre < 0) - pre = 0; - int post = i + errorWindow; - if (post > term.length()) - post = term.length(); - // log.warn("pre: " + pre + " post: " + post + " term len: - // " + term.length()); - - // get part of the search term before the error and after - String before = term.substring(pre, i); - String after = ""; - if (post > i) - after = term.substring(i + 1, post); - - rv = "The search term had an error near " - + before + "" + term.charAt(i) - + "" + after + ""; - } catch (Throwable ex) { - return ""; - } - return rv; - } - - /** - * Upgrades beans using individual entity upgrade(). - * - * @param hits - * @return - */ - @SuppressWarnings("unchecked") - private List makeUsableBeans(List hits,VitroRequest vreq) { - if (hits == null || hits.size() == 0) { - return new ArrayList(); - } - LinkedList beans = new LinkedList(); - Iterator it = hits.iterator(); - while (it.hasNext()) { - try { - Object obj = it.next(); - if (obj != null) { - obj = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(((Individual)obj).getURI()); - //null would indicate that the entity that was found in - //the search index is no longer in the system. - if( obj != null ) { - beans.add(obj); - } - } - } catch (Exception e) { - log.error(e.getStackTrace()); - } - } - return beans; - } - - public static final String NO_GRP_FOUND = "others"; - - public static final String TABS = "tabs"; - - /** - * Make a map of VClassGroup objs to Lists of entites. There will also be a - * map from TABS -> a List of tabs and NO_CLASSGRP_FOUND -> a list of - * Entities where the class or classgroup could not be found. - * - * @param beans - * @return - */ - private Map /* of List */collate(List beans, VitroRequest vreq) { - if (beans == null || beans.size() == 0) { - return new HashMap(); - } - /* make a hash map of VClassGroup -> List[ ent, ent , ent ... ] */ - Map groups = vreq.getWebappDaoFactory().getVClassGroupDao().getClassGroupMap(); - Map groupsByURI = makeGroupURIBasedMap(groups); - - VClass vclass = null; - VClassGroup tabs = null, other = null; - Iterator it = beans.iterator(); - while (it.hasNext()) { - Object obj = it.next(); - if (obj instanceof Individual){ - vclass = (VClass)((Individual) obj).getVClass(); - if( vclass != null && vclass.getGroupURI() != null ){ - putInGroupsList(groupsByURI, vclass.getGroupURI(), obj); - } else { /* didn't find a group */ - if( !groupsByURI.containsKey("vitro://NullClassGroup") ){ - other = new VClassGroup("vitro://NullClassGroup",NO_GRP_FOUND); - groupsByURI.put("vitro://NullClassGroup", other); - groups.put(NO_GRP_FOUND,other); - } - putInGroupsList(groupsByURI, "vitro://NullClassGroup", obj); - } - } else if (obj instanceof Tab) { - if( !groupsByURI.containsKey("vitro://NullTabGroup") ){ - tabs = new VClassGroup("vitro://NullTabGroup",TABS); - groupsByURI.put(0, tabs ); - groups.put(TABS,tabs); - } - putInGroupsList(groupsByURI, null, obj); - } - } - return groups; - } - - private void putInGroupsList(Map groupsById, String key, Object obj) { - List classList = (List) groupsById.get(key); - if (classList == null) {/* make new list if this is a new grp */ - classList = new LinkedList(); - groupsById.put(key, classList); - } - classList.add(obj); - } - - /** - * Make a new map from the Integer() -> VClassGroup. - * @param groups - * @return - */ - private Map makeGroupURIBasedMap( Map groups){ - LinkedHashMap map= - new LinkedHashMap(); - for( Object obj: groups.values() ){ - if( !(obj instanceof VClassGroup) ) - throw new Error("VitroRequest.getWebappDaoFactory().getVClassGroupDao().getClassGroupMap() returned something other than a VClassGroup"); - VClassGroup grp = (VClassGroup)obj; - map.put(grp.getURI() , grp ); - } - return map; - } - - - - /** - * Collate a Collection of Entities into VClassLists. - * Sort the vclasses. - * - * @param ents - * @return - */ - @SuppressWarnings({ "unused", "unchecked" }) - private LinkedList /*VClassList*/ collateVClasses(Collection ents){ - log.debug("in collateVClasses "); - if( ents == null ) return null; - Map vclasses = new HashMap( ); - Iterator it = ents.iterator(); - while( it.hasNext()){ - Individual ent = (Individual) it.next(); - if(vclasses.containsKey(ent.getVClassURI()+"")){ - vclasses.get(ent.getVClassURI()+"").getEntities().add(ent); - }else{ - List a = new LinkedList(); - a.add(ent); - VClass waVClass = (VClass)ent.getVClass(); - VClassList vcl = null; - if (waVClass==null) { - VClass vcw = new VClass(); - vcw.setURI("vitro://UnknownClass"); - vcw.setName("Unknown Class"); - vcl = new VClassList(vcw,a); - } else { - vcl = new VClassList(waVClass,a); - } - - vclasses.put(ent.getVClassURI()+"", vcl); - } - } - LinkedList vclassList = new LinkedList(vclasses.values()); - - if( log.isDebugEnabled() ){ - it = vclassList.iterator(); - while(it.hasNext()){ - log.debug(((VClass)it.next()).getName()); - } - } - - //This is the object that will compare vclasses for - //sort order in the search results - - Comparator vclassComparator = new Comparator(){ - public int compare(Object o1, Object o2) { - if( o1 == null && o2 == null) return 0; - if( o1 == null ) return 1; - if( o2 == null ) return -1; - - if( o1 instanceof VClass && o2 instanceof VClass) - return compare((VClass) o1, (VClass) o2); - //what to do when we don't know what we have: - return o2.hashCode() - o1.hashCode(); - - } - private int compare(VClass v1, VClass v2){ - if( v1== null && v2 == null ) return 0; - if( v1 == null ) return -1; - if( v2 == null ) return 1; - if( v1.getURI().equals(v2.getURI()) )return 0; - - //check if display ranks are different - int v1rank=v1.getDisplayRank(); - int v2rank=v2.getDisplayRank(); - - if( v1rank == v2rank ) - //same rank, sort by vclass name - return v1.getName().compareToIgnoreCase( v2.getName()); - - //bdc34: this is not working as I expect it to - // This is what I think: - // comparators should return 0 same; -1 2nd object is first; - // +1 1st object should be first - // - // vclass rank should work such that display Rank 1 get to go first, - // 99 gets to go last. All vclasses with the same rank should get - // alpha sorting. - // - // So I would guess that returning +1 when v1.disRank < v2.disRank - // would make sense but that seems to be worng. - // - // I tried the other way and things seem to work correctly. - // I might just be confused about the values that Comparator - // object should return - - if( v1rank > v2rank ) - return 1; - else - return -1; - } - }; - Collections.sort(vclassList,vclassComparator); - if( log.isDebugEnabled()){ - it = vclassList.iterator(); - while(it.hasNext()){ - log.debug(((VClass)it.next()).getName()); - } - } - return vclassList; - } - - private void collateClassGroupsByVClass( Collection cGrps ){ - if( cGrps == null ) return; - Iterator it = cGrps.iterator(); - while(it.hasNext()){ - VClassGroup grp = (VClassGroup) it.next(); - List vclassLists = collateVClasses( grp ); - grp.clear(); - grp.addAll(vclassLists); - } - } - - /** - * Try to sort the classGroup lists. For each item in the map, check if it - * is a collection, if yes, try to sort as if things in the list are Entity - * objects. - * - * @return - */ - private Map /* of List */sortClassGroups(Map classGroups) { - if( classGroups == null || classGroups.values() == null ) - return classGroups; - - //first we sort the entities in each grouup. - Iterator it = classGroups.values().iterator(); - - //wow, I have to sit down and learn this generic stuff. - Comparator entComparator = new Comparator(){ - public int compare(Object o1, Object o2) { - if( o1 == null && o2 == null) return 0; - if( o1 == null ) return 1; - if( o2 == null ) return -1; - - if( o1 instanceof VClass && o2 instanceof VClass) - return compareClasses(((VClass) o1), ((VClass) o2)); - - if( o1 instanceof Individual && o2 instanceof Individual) - return compareEnts((Individual)o1, (Individual)o2); - if( o1 instanceof Individual && ! (o2 instanceof Individual)) - return -1; - if( !(o1 instanceof Individual) && o2 instanceof Individual) - return 1; - //what to do when we don't know what we have: - return o2.hashCode() - o1.hashCode(); - - } - //here we sort entities - private int compareEnts(Individual o1, Individual o2){ - int vclassCompare = compareClasses((VClass) o1.getVClass(), - (VClass) o2.getVClass() ); - //sort by vclass first, then by entity name - if( vclassCompare != 0 ) - return vclassCompare; - else - return ((o1.getName()==null)?"":o1.getName()).compareToIgnoreCase((o2.getName()==null)?"": o2.getName()); - } - - private int compareClasses(VClass v1, VClass v2){ - if( v1== null && v2 == null ) return 0; - if( v1 == null ) return -1; - if( v2 == null ) return 1; - if( v1.getURI().equals(v2.getURI()) )return 0; - - //check if display ranks are different - int v1DisplayRank=v1.getDisplayRank(), - v2DisplayRank=v2.getDisplayRank(); - int displayRankDiff = v2DisplayRank - v1DisplayRank; - - if( displayRankDiff != 0 ) return displayRankDiff; - - //same rank, sort by vclass name - return v1.getName().compareToIgnoreCase( v2.getName()); - } - }; - - while(it.hasNext()){ - Object obj = it.next(); - if(!( obj instanceof Collection)) - continue; //skip this one if it is not a collection - List >entList = (List>)obj; - Collections.sort(entList, entComparator); - } - -// //now we sort the classgroups -// Comparator cgComparator = new Comparator(){ -// public int compare(Object o1, Object o2){ -// if( o1 == null && o2 == null) return 0; -// if( o1 == null ) return 1; -// if( o2 == null ) return -1; -// -// if( o1 instanceof ClassGroup && o2 instanceof ClassGroup) -// return compare((ClassGroup)o1, (ClassGroup)o2); -// if( o1 instanceof ClassGroup && ! (o2 instanceof ClassGroup)) -// return -1; -// if( !(o1 instanceof ClassGroup) && o2 instanceof ClassGroup) -// return 1; -// //what to do when we don't know what we have: -// return o2.hashCode() - o1.hashCode(); -// } -// private int compare(ClassGroup c1, ClassGroup c2){ -// return 0; -// } -// }; - return classGroups; - } - -} diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/EntityControllerTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/EntityControllerTest.java deleted file mode 100644 index b3f95fc27..000000000 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/EntityControllerTest.java +++ /dev/null @@ -1,26 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.controller; - -import org.junit.Assert; -import org.junit.Test; - -import edu.cornell.mannlib.vitro.webapp.web.ContentType; - - -public class EntityControllerTest { - - @Test - public void testAcceptHeader(){ - EntityController entityController = new EntityController(); - - /* Check to see if vitro would send RDF/XML to tabulator */ - String tabulatorsAcceptHeader = - "text/xml,application/xml,application/xhtml+xml,text/html;q=0.5,text/plain;q=0.5," + - "image/png,*/*;q=0.1," + - "application/rdf+xml;q=1.0,text/n3;q=0.4"; - ContentType result = entityController.checkForLinkedDataRequest("http://notUsedInThisTestCase.com/bogus",tabulatorsAcceptHeader); - Assert.assertTrue( result != null ); - Assert.assertTrue( "application/rdf+xml".equals( result.toString()) ); - } -} diff --git a/webapp/web/templates/browse/browseGroup.jsp b/webapp/web/templates/browse/browseGroup.jsp deleted file mode 100644 index 55b29853e..000000000 --- a/webapp/web/templates/browse/browseGroup.jsp +++ /dev/null @@ -1,89 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClassGroup,edu.cornell.mannlib.vitro.webapp.beans.VClass" %> -<%@ page import="java.net.URLEncoder" %> -<%@ page import="java.util.Collection" %> -<%@ page import="java.util.Iterator" %> -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %><%/* this odd thing points to something in web.xml */ %> -<%@ page errorPage="/error.jsp"%> - -<%@page import="com.hp.hpl.jena.vocabulary.OWL"%> -<% /*********************************************** - Display Browse Results (the "Index" menu command) - - request.attributes: - a List with the name "classgroups" - collatedGroupNames - additionalParameterStr - - request.parameters: - None yet. - - Consider sticking < % = MiscWebUtils.getReqInfo(request) % > in the html output - for debugging info. - - **********************************************/ -if (request.getAttribute("classgroups") == null){ - String e="browsesGroup.jsp expects that request attribute 'classgroups' be set to a List of classgroups to display."; - throw new JspException(e); -} -if (request.getAttribute("portalState") == null){ - String e="browsesGroup.jsp expects that request attribute 'portalState' be set to a portal state [PortalFlag] object."; - throw new JspException(e); -} - -String additionalParameterStr = ""; //we expect this to already be encoded as a url. -if(request.getAttribute("passthru") != null){ - additionalParameterStr = (String)request.getAttribute("passthru"); -} - -if( request.getAttribute("classgroupsIsEmpty") != null && ((Boolean)request.getAttribute("classgroupsIsEmpty")) == true){ - %> - -
-

There not yet any items in the system.

-
-<% } else { %> -
-
- - - -
- <% - Collection classgroupList = (Collection) request.getAttribute("classgroups"); - if (classgroupList != null) { - Iterator groupIter = classgroupList.iterator(); - Object groupObj = null; - while (groupIter.hasNext()) { - groupObj = groupIter.next(); - if (groupObj != null && groupObj instanceof VClassGroup) { - VClassGroup theGroup = (VClassGroup) groupObj; %> -

<%=theGroup.getPublicName()%>

- <% if (theGroup.getVitroClassList()!=null && theGroup.getVitroClassList().size()>0) {%> -
    - <% Iterator classIter=theGroup.getVitroClassList().iterator(); - Object classObj=null; - while (classIter.hasNext()) { - classObj = classIter.next(); - if (classObj!=null && classObj instanceof VClass) { - VClass theClass=(VClass)classObj; - //filter out owl:Thing - if( theClass.getName() == null || OWL.Thing.getURI().equals(theClass.getURI())) - continue; - String linkStr=response.encodeURL("entitylist"); - if (theClass.getURI() == null) - theClass.setURI("null://null"); - String queryStr="?vclassId="+URLEncoder.encode(theClass.getURI(),"UTF-8")+additionalParameterStr; %> -
  • <%=theClass.getName()%> (<%=theClass.getEntityCount()%>)
  • - <% } - }%> -
- <% } else {%> -
  • no entities
- <% } - } - } - }%> -
-<% } %> \ No newline at end of file diff --git a/webapp/web/templates/browse/portalFlagChoices.jsp b/webapp/web/templates/browse/portalFlagChoices.jsp deleted file mode 100644 index ad0334a8b..000000000 --- a/webapp/web/templates/browse/portalFlagChoices.jsp +++ /dev/null @@ -1,201 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ page import="java.lang.Integer"%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.flags.PortalFlagChoices" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.flags.AuthFlag" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.flags.PortalFlag" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Portal" %> -<%@ page errorPage="/error.jsp"%> - -<% - /*********************************************** - Display A Form for filling out Portal Flags - - request.attributes: - PortalFlag object via attribute "portalState". - request.parameters: - None yet. - - Consider sticking < % = MiscWebUtils.getReqInfo(request) % > in the html output for debugging info. - - This was written by jc55 and split into this file from browseGroups.jsp by bdc34. - **********************************************/ - PortalFlag portalFilterState = (PortalFlag) request.getAttribute("portalFlag"); - if (portalFilterState == null) { - String e = "portalFlagChoices.jsp expects that request attribute 'portalFlag' be set to a portal state [PortalFlag] object."; - throw new JspException(e); - } - AuthFlag authFlag = (AuthFlag) request.getAttribute("authFlag"); - if (authFlag == null) { - String e = "portalFlagChoices.jsp expects that request attribute 'authFlag' be set to a authorization state [AuthFlag] object."; - throw new JspException(e); - } - ApplicationBean appBean = (ApplicationBean) request.getAttribute("appBean"); - if (appBean == null) { - String e = "portalFlagChoices.jsp expects request attribute 'appBean' be set to an application bean object"; - throw new JspException(e); - } - Portal portal = (Portal) request.getAttribute("portalBean"); - if( portal == null ) - portal = new Portal(); - int portalId = portal.getPortalId(); -%> - - -<% -String width1Str=request.getParameter("width1"); -int width1=14; -if (width1Str!=null && !width1Str.equals("")) { - try { - width1=Integer.parseInt(width1Str); - } catch (NumberFormatException ex) { - throw new JspException("Error: width1 parameter cannot be decoded as integer in portalFlagChoices.jsp"); - } -} -%> - -
- - -<% -// Draw the appropriate checkboxes if they have been populated -// We are dealing with 3 situations for showing portal options in browsing: -// #1 For normal browsing (not in one of the application's shared portals [the CALS research portals] the user has 2 radio button choices: -// ___ [portal appName] only OR ___ don't filter -// -// #2 When browsing in one of the application's shared portals [1 of the 4 CALS research portals or the composite "All CALS Research" portal], -// the user has the same number of checkbox choices as there are shared portals (e.g, 4 for CALS) -// Optionally limit to: -// ___ New life sciences ___ Environmental sciences ___ Land grant mission ___ Applied social sciences -// -// #3 When an editor has logged in and starts browsing, all portals with an id less <= the application's maxPortalId are always shown as options -// unless filters are turned completely off by an incoming request parameter - -boolean haveFlag1Choices=false; -if (appBean.isFlag1Active()&& appBean.getFlag1List()!=null && appBean.getFlag1List().size()>1) { - if (portalFilterState.getFlag1DisplayStatus()==PortalFlag.SHOW_SHARED_PORTALS || authFlag.getUserSecurityLevel()>=ApplicationBean.FILTER_SECURITY_LEVEL) { - haveFlag1Choices=true;%> - - - -<% } -} -String actionStr=request.getParameter("action"); -boolean haveFlag2Choices=false; -if (appBean.isFlag2Active() && appBean.getFlag2List()!=null - && appBean.getFlag2List().size()>1 - && (actionStr==null || (actionStr.equals("browse") && authFlag.getUserSecurityLevel()>=ApplicationBean.FILTER_SECURITY_LEVEL))) { - haveFlag2Choices=true;%> - - <% -} - -boolean haveFlag3Choices=false; -if (appBean.isFlag3Active() && appBean.getFlag3List()!=null - && appBean.getFlag3List().size()>1 - && (actionStr==null || (actionStr.equals("browse") && authFlag.getUserSecurityLevel()>=ApplicationBean.FILTER_SECURITY_LEVEL))) { - haveFlag3Choices=true;%> - - <% -} - -//if (actionStr!=null && actionStr.equals("browse")){ -if (haveFlag1Choices || haveFlag2Choices || haveFlag3Choices) {%> - <% -}%> -
- /> limit to - /> omit - - <%=PortalFlagChoices.getFlag1Choices(portalFilterState,appBean,portalId)%> -
- /> limit to - /> omit - - <%=PortalFlagChoices.getFlag2Choices(portalFilterState, appBean)%> -
- /> limit to - /> omit - - <%=PortalFlagChoices.getFlag3Choices(portalFilterState,appBean,portal)%> -
- filter as indicated above -<% if (authFlag.getUserSecurityLevel()>=appBean.FILTER_SECURITY_LEVEL) {%> - don't filter at all<% - }%> -
- -
diff --git a/webapp/web/templates/entity/entityAdmin.jsp b/webapp/web/templates/entity/entityAdmin.jsp deleted file mode 100644 index b38e1a7fe..000000000 --- a/webapp/web/templates/entity/entityAdmin.jsp +++ /dev/null @@ -1,48 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean"%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.flags.PortalFlagChoices" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> -<%@page import="edu.cornell.mannlib.vedit.beans.LoginStatusBean"%> -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> -<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> -<%@ page errorPage="/error.jsp"%> -<% /*********************************************** - Displays the little group of things at the bottom of the page - for administrators and editors. - - request.attributes: - an Entity object with the name "entity" - - - request.parameters: - None, should only work with requestScope attributes for security reasons. - - Consider sticking < % = MiscWebUtils.getReqInfo(request) % > in the html output - for debugging info. - - bdc34 2006-01-22 created - **********************************************/ - Individual entity=(Individual)request.getAttribute("entity"); - if (entity == null){ - String e="entityAdmin.jsp expects that request attribute 'entity' be set to the Entity object to display."; - throw new JspException(e); - } -%> -<% if ( LoginStatusBean.getBean(request).isLoggedInAtLeast(LoginStatusBean.EDITOR)) { %> -<%/* just moving this into page scope for easy use */ %> - -
-

Admin Panel

-
- - - - - edit this individual -

Resource URI:

-
-
-<% } %> - diff --git a/webapp/web/templates/entity/entityBasic.jsp b/webapp/web/templates/entity/entityBasic.jsp deleted file mode 100644 index 8ac507d53..000000000 --- a/webapp/web/templates/entity/entityBasic.jsp +++ /dev/null @@ -1,315 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission" %> -<%@ page import="edu.cornell.mannlib.vedit.beans.LoginStatusBean" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest"%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Link" %> - -<%@ page import="org.apache.commons.logging.Log" %> -<%@ page import="org.apache.commons.logging.LogFactory" %> - -<%@ page import="java.util.List" %> - -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> -<%@ taglib uri="http://vitro.mannlib.cornell.edu/vitro/tags/StringProcessorTag" prefix="p" %> -<%@ taglib uri="http://vitro.mannlib.cornell.edu/vitro/tags/PropertyEditLink" prefix="edLnk" %> - -<%@ page errorPage="/error.jsp"%> -<%! -public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.templates.entity.entityBasic.jsp"); -%> -<% - log.debug("Starting entityBasic.jsp"); - Individual entity = (Individual)request.getAttribute("entity"); -%> - - - - - - - - <% - try { - VitroRequest vreq = new VitroRequest(request); - entity = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI((String)request.getAttribute("myEntityURI")); - } catch (Exception e) { - e.printStackTrace(); - } - %> - - -<% - -if (entity == null){ - String e="entityBasic.jsp expects that request attribute 'entity' be set to the Entity object to display."; - throw new JspException(e); -} - -boolean showSelfEdits = VitroRequestPrep.isSelfEditing(request); -boolean showCuratorEdits = LoginStatusBean.getBean(request).isLoggedInAtLeast(LoginStatusBean.CURATOR); -if (showSelfEdits || showCuratorEdits) { - request.setAttribute("showEdits",Boolean.TRUE); -} -%> - - - - -<% - //anytime we are at an entity page we shouldn't have an editing config or submission - session.removeAttribute("editjson"); - EditConfiguration.clearAllConfigsInSession(session); - EditSubmission.clearAllEditSubmissionsInSession(session); -%> - -<%/* just moving this into page scope for easy use */ %> - - - - - - - -
-
- - -
- -
- - -

${relatingPredicate.domainPublic} for ${relatedSubject.name}

- - - - -

← return to ${relatedSubject.name}

-
- - - <%-- Label --%> -
-
-

${entity.name}

- - - ${editLinks} - -
-
- - <%-- Moniker--%> - -
-
-
- ${entity.moniker} -
-
-
-
- -
-
-
- - - - - - <%-- Thumbnail --%> - - - - - - -
-

image

- ${imageLinks} -
-
-
- -
-
-
-
- - - ${imageLinks} - -
-
-
-
-
- <%-- hasImage --%> -
-
-
-
- - - - - ${imageLinks} - -
-
-
-
- -
-
- - <%-- Links --%> - - - - - <%-- Description --%> - <%-- - - - - - - - - -
-

description

${editLinksForNewDesc} - - - -
-
-
-
${entity.description}
- - ${editLinksForExistingDesc} - -
-
-
-
- -
-
-
- --%> - - <%-- Ontology properties --%> - - - - <%-- unless a value is provided, properties not assigned to a group will not have a tab or appear on the page --%> - - - - <%-- Blurb --%> - -
-
-
-
${entity.blurb}
-
-
-
-
- - <%-- Citation, if no thumbnail --%> - - - - - <%-- Keywords --%> - -

Keywords: ${entity.keywordString}

-
- - ${requestScope.servletButtons} - - -
-
-
- - - diff --git a/webapp/web/templates/entity/entityCitation.jsp b/webapp/web/templates/entity/entityCitation.jsp deleted file mode 100644 index 8176a78e6..000000000 --- a/webapp/web/templates/entity/entityCitation.jsp +++ /dev/null @@ -1,20 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary" %> -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> - -<%-- vitro:citation is no longer being used see NIHVIVO-503 if there is a different property for - the citation it may be added here. --%> - -<%-- - -
-
-
-
${entity.citation}
-
-
-
-
- - --%> \ No newline at end of file diff --git a/webapp/web/templates/entity/entityKeywordsList.jsp b/webapp/web/templates/entity/entityKeywordsList.jsp deleted file mode 100644 index 5e3c1d9f1..000000000 --- a/webapp/web/templates/entity/entityKeywordsList.jsp +++ /dev/null @@ -1,62 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> -<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> -<%@ taglib uri="http://vitro.mannlib.cornell.edu/vitro/tags/PropertyEditLink" prefix="edLnk" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.KeywordProperty" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.KeywordDao" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Keyword" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.KeywordIndividualRelation" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.KeywordIndividualRelationDao" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %> -<%@ page import="org.apache.commons.logging.Log" %> -<%@ page import="org.apache.commons.logging.LogFactory" %> -<%@ page import="java.util.Iterator" %> -<%@ page import="java.util.List" %> -<%@ taglib uri="http://vitro.mannlib.cornell.edu/vitro/tags/StringProcessorTag" prefix="p" %> -<%@ taglib prefix="vitro" uri="/WEB-INF/tlds/VitroUtils.tld" %> - -<%! -public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.templates.entity.entityKeywordsList.jsp"); -%> - - - -<% -Individual ent = (Individual)request.getAttribute("entity"); -if (ent==null) { - log.error("No incoming entity in entityKeywordsList.jsp"); -} -VitroRequest vreq = new VitroRequest(request); -KeywordProperty kProp = new KeywordProperty("has keyword","keywords",0,null); -WebappDaoFactory wdf = vreq.getWebappDaoFactory(); -KeywordIndividualRelationDao kirDao = wdf.getKeys2EntsDao(); -KeywordDao kDao = wdf.getKeywordDao(); -List kirs = kirDao.getKeywordIndividualRelationsByIndividualURI(ent.getURI()); -if (kirs != null) { - int keyCount=0; - Iterator kirIt = kirs.iterator(); - while (kirIt.hasNext()) { - KeywordIndividualRelation kir = (KeywordIndividualRelation) kirIt.next(); - if (kir.getKeyId() > 0) { - Keyword k = kDao.getKeywordById(kir.getKeyId()); - if (k != null) { - ++keyCount; - if (keyCount==1) {%> -

Keywords

-
-<% } else { %> - -<% }%> - -<% } - } - }%> -
<% -} -%> - diff --git a/webapp/web/templates/entity/entityList.jsp b/webapp/web/templates/entity/entityList.jsp deleted file mode 100644 index f039e49fc..000000000 --- a/webapp/web/templates/entity/entityList.jsp +++ /dev/null @@ -1,108 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%> -<%@ taglib uri="http://vitro.mannlib.cornell.edu/vitro/tags/StringProcessorTag" prefix="p" %> - -<%@ page errorPage="/error.jsp"%> -<% /*********************************************** - Display a List of Entities in the most basic fashion. - - request.attributes: - a List of Entity objects with the name "entities" - portal id as "portal" - - request.parameters: - None yet. - - Consider sticking < % = MiscWebUtils.getReqInfo(request) % > in the html output for debugging info. - - bdc34 2006-01-27 created - **********************************************/ - if (request.getAttribute("entities") == null){ - String e="entityList.jsp expects that request attribute 'entities' be set to a List of Entity objects."; - throw new JspException(e); - } -%> -<%/* just moving this into page scope for easy use */ %> - - - - -
-
- -
-

${title}

-

${subTitle}"

- -<% /*

${pageTime} milliseconds

*/ %> - - -
    - -
  • - - - - - - - - - - - - - | - - - - - - - - - - <%-- decide here whether to render a link on the included page by setting individualUrl in the request scope --%> - - - - - - - - - - - - | - - - - - - - - - - - - | - - - - -
  • -
    -
-
- -<% /* add supplementary text provided by controllers such as "CoAuthorServlet" */ %> - - ${requestScope.suppText} - - - - -
-
\ No newline at end of file diff --git a/webapp/web/templates/entity/entityListForGalleryTab.jsp b/webapp/web/templates/entity/entityListForGalleryTab.jsp deleted file mode 100644 index 1bb45ffa8..000000000 --- a/webapp/web/templates/entity/entityListForGalleryTab.jsp +++ /dev/null @@ -1,61 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ page import="java.util.*,edu.cornell.mannlib.vitro.webapp.beans.Individual"%> -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%><%/* this odd thing points to something in web.xml */ %> -<%@ page errorPage="/error.jsp"%> -<% /*********************************************** - Display a List of Entities in the most basic fashion. - - request.attributes: - a List of Entity objects with the name "entities" - portal id as "portal" - - request.parameters: - "rows" is number of rows in gallery table - "columns" is number of columns in gallery table - - Consider sticking < % = MiscWebUtils.getReqInfo(request) % > in the html output for debugging info. - - bdc34 2006-01-27 created - **********************************************/ - if (request.getAttribute("entities") == null){ - String e="entityListForTabs.jsp expects that request attribute 'entities' be set to a List of Entity objects."; - throw new JspException(e); - } -%> -<%/* just moving this into page scope for easy use */ %> - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - " > - ${ent.name} - -
- - diff --git a/webapp/web/templates/entity/entityMergedPropsList.jsp b/webapp/web/templates/entity/entityMergedPropsList.jsp deleted file mode 100644 index c950d10e5..000000000 --- a/webapp/web/templates/entity/entityMergedPropsList.jsp +++ /dev/null @@ -1,401 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> -<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> -<%@ taglib uri="http://vitro.mannlib.cornell.edu/vitro/tags/PropertyEditLink" prefix="edLnk" %> -<%@ taglib uri="http://vitro.mannlib.cornell.edu/vitro/tags/StringProcessorTag" prefix="p" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Portal" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.PropertyInstance" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Property" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.KeywordProperty" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash" %> -<%@ page import="java.util.Collection" %> -<%@ page import="java.util.Collections" %> -<%@ page import="java.util.Comparator" %> -<%@ page import="java.util.List" %> -<%@ page import="java.util.ArrayList" %> -<%@ page import="java.util.Iterator" %> -<%@ page import="java.util.HashSet" %> -<%@ page import="org.apache.commons.logging.Log" %> -<%@ page import="org.apache.commons.logging.LogFactory" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %> -<%@ page import="edu.cornell.mannlib.vedit.beans.LoginStatusBean" %> - -<%@page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%> -<%! -public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.templates.entity.entityMergedPropsList.jsp"); -%> -<% if( VitroRequestPrep.isSelfEditing(request) ) { - log.debug("setting showSelfEdits true");%> - -<% } - if (LoginStatusBean.getBean(request).isLoggedIn()) { - log.debug("setting showCuratorEdits true");%> - - -<% } - String unassignedPropGroupName=null; - String unassignedName = (String) request.getAttribute("unassignedPropsGroupName"); - if (unassignedName != null && unassignedName.length()>0) { - unassignedPropGroupName=unassignedName; - log.debug("found temp group attribute \""+unassignedName+"\" for unassigned properties"); - }%> - <%-- just moving this into page scope for easy use --%> - <%-- likewise --%> - -<% Individual subject = (Individual) request.getAttribute("entity"); - if (subject==null) { - throw new Error("Subject individual must be in request scope for entityMergedPropsList.jsp"); - } - - - // Nick wants not to use explicit parameters to trigger visibility of a div, but for now we don't just want to always show the 1st one - String openingGroupLocalName = (String) request.getParameter("curgroup"); - VitroRequest vreq = new VitroRequest(request); - // added to permit distinguishing links outside the current portal - int currentPortalId = -1; - Portal currentPortal = vreq.getPortal(); - if (currentPortal!=null) { - currentPortalId = currentPortal.getPortalId(); - } - - WebappDaoFactory wdf = vreq.getWebappDaoFactory(); - PropertyGroupDao pgDao = wdf.getPropertyGroupDao(); - ArrayList groupsList = (ArrayList) request.getAttribute("groupsList"); - if (groupsList!=null && groupsList.size()>0) { // first do the list of headers - if (groupsList.size()==1) { - for (PropertyGroup pg : groupsList) { - if (unassignedPropGroupName != null && !unassignedPropGroupName.equalsIgnoreCase(pg.getName())) { - log.debug("only one group ["+pg.getName() +"] so rendering without group headers"); - } - request.setAttribute("mergedList",pg.getPropertyList()); - } - %><% - return; - }%> - - <%-- -
    -<% for (PropertyGroup pg : groupsList ) { - if (openingGroupLocalName == null || openingGroupLocalName.equals("")) { - openingGroupLocalName = pg.getLocalName(); - } - String styleStr = "display: inline;"; - if (openingGroupLocalName.equals(pg.getLocalName())) {%> -
  • <%=pg.getName()%>
  • -<% } else { %> -
  • <%=pg.getName()%>
  • -<% } - } %> -
- --%> - - -<% // now display the properties themselves, by group - for (PropertyGroup g : groupsList) {%> - - - - - - <%-- Getting the count of properties in each group --%> - - - <% int propTotal = g.getPropertyList().size(); %> - - - -
-

<%=g.getName()%>

-
-<% for (Property p : g.getPropertyList()) {%> -<% if (p instanceof ObjectProperty) { - ObjectProperty op = (ObjectProperty)p;%> - - - - - - - - - - - <%-- rjy7 We have a logic problem here: if the custom short view dictates that the item NOT be rendered, - and because of this there are NO items to render, we shouldn't show the label when not in edit mode. - Example: people ( = positionHistory) of an organization don't render if the position end date is in the past. - So the organization might not have any current people, in which case we shouldn't show the "people" label. - We need to compute objRows on the basis of the rendering, not the number of objectPropertyStatements. - See NIHVIVO-512. --%> - - - - <%-- nac26 Changing the test on objRows here to be GTE so that properties marked with an update level of "nobody" are still rendered --%> - - - -
-

${objProp.label}

- - <%-- Verbose property display additions for object properties, using context variable verbosePropertyListing --%> - - - - - - - - - - - - - - - - - - - - - - - - <% PropertyGroup pg = pgDao.getGroupByURI(op.getGroupURI()); - if (pg!=null && pg.getName()!=null) { - request.setAttribute("groupName",pg.getName());%> - ${localName} (object property); display tier ${displayTier} within group ${groupName}; display level: ${displayCue}; update level: ${updateCue} - <% } else {%> - ${localName} (object property); display tier ${displayTier}; display level: ${displayCue}; update level: ${updateCue} - <% } %> - - - ${localName} (object property); display tier ${displayTier}; display level: ${displayCue}; update level: ${updateCue} - - - - <%-- end Verbose property display additions for object properties --%> - - - - - <% /* arbitrary limit if value is unset, i.e. -1 */ %> - - - -
    - - - - - - - - - - - - - - - - -
-
- - - -
  • -
    ${collateCurrentClassName}
    -
      - - -
    • - - - - - - - <% String customShortView = MiscWebUtils.getCustomShortView(request); %> - - - - - - - - - - - - - - - - - - - - ${editLinks} - (non-editable) - -
    • - -
  • - -
    -
    -<% } else if (p instanceof DataProperty) { - DataProperty dp = (DataProperty)p;%> - - - - - - - - - - - -
    -

    ${dataProp.label}

    - - - - <%-- just put in a single "edit" link, not an "add" link that expands to reveal edit/delete links --%> - - ${editLinks} - (non-editable) - - <%-- creates an add link, even if displayLimit is unset, i.e. -1 --%> - - - - - - <%-- Verbose property display additions for data properties, using context variable verbosePropertyListing --%> - - - - - - - - - - - - - - - - - - - - - - - - <% PropertyGroup pg = pgDao.getGroupByURI(dp.getGroupURI()); - if (pg!=null && pg.getName()!=null) { - request.setAttribute("groupName",pg.getName());%> - ${localName} (data property); display tier ${displayTier} within group ${groupName}; display level: ${displayCue}; update level: ${updateCue} - <% } else {%> - ${localName} (data property); display tier ${displayTier}; display level: ${displayCue}; update level: ${updateCue} - <% } %> - - - ${localName} (data property); display tier ${displayTier}; display level: ${displayCue}; update level: ${updateCue} - - - - <%-- end Verbose property display additions for data properties --%> - - - <%-- set to an arbitrary but high positive limit if unset on property, i.e. -1 --%> - - - - <%-- don't leave just one statement to expand --%> - - - <%-- c:if test="${displayLimit < 0}"> - -
    -
      -
      - - - - - - ${dataPropertyStmt.data} - - - ${editLinks} - (non-editable) - - - - -
    • - ${dataPropertyStmt.data} - - - - ${editLinks} - (non-editable) - - -
    • -
      -
      -
      -
      - -
      -
    - -
    -
    -
    - -<% } else { // keyword property -- ignore - if (p instanceof KeywordProperty) {%> -

    Not expecting keyword properties here.

    -<% } else { - log.warn("unexpected unknown property type found");%> -

    Unknown property type found

    -<% } - } - - %><% - - } // end for (Property p : g.getPropertyList() - %> -
    -
    -
    - - back to top - -<% } // end for (PropertyGroup g : groupsList) - } else { - log.debug("incoming groups list with merged properties not found as request attribute for subject "+subject.getName()+"\n"); - } -%> \ No newline at end of file diff --git a/webapp/web/templates/entity/entityMergedPropsListUngrouped.jsp b/webapp/web/templates/entity/entityMergedPropsListUngrouped.jsp deleted file mode 100644 index 70d78854c..000000000 --- a/webapp/web/templates/entity/entityMergedPropsListUngrouped.jsp +++ /dev/null @@ -1,336 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> -<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> -<%@ taglib uri="http://vitro.mannlib.cornell.edu/vitro/tags/StringProcessorTag" prefix="p" %> -<%@ taglib uri="http://vitro.mannlib.cornell.edu/vitro/tags/PropertyEditLink" prefix="edLnk" %> - -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Portal" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.PropertyInstanceDao" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.PropertyInstance" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Property" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.KeywordProperty" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataProperty" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VClassDao" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.VClass" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %> -<%@ page import="edu.cornell.mannlib.vedit.beans.LoginStatusBean" %> -<%@page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%> - -<%@ page import="java.util.Collection" %> -<%@ page import="java.util.Collections" %> -<%@ page import="java.util.Comparator" %> -<%@ page import="java.util.List" %> -<%@ page import="java.util.ArrayList" %> -<%@ page import="java.util.Iterator" %> -<%@ page import="java.util.HashSet" %> -<%@page import="java.util.LinkedList"%> -<%@page import="java.util.Set"%> - -<%@ page import="org.apache.commons.logging.Log" %> -<%@ page import="org.apache.commons.logging.LogFactory" %> - -<%! -public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.templates.entity.entityMergedPropsList.jsp"); -%> - -<% if( VitroRequestPrep.isSelfEditing(request) ) { - log.debug("setting showSelfEdits true");%> - -<% } - if (LoginStatusBean.getBean(request).isLoggedIn()) { - log.debug("setting showCuratorEdits true");%> - -<% }%> - <%-- just moving this into page scope for easy use --%> - <%-- likewise --%> - -<% Individual subject = (Individual) request.getAttribute("entity"); - if (subject==null) { - throw new Error("Subject individual must be in request scope for dashboardPropsList.jsp"); - } - // Nick wants not to use explicit parameters to trigger visibility of a div, but for now we don't just want to always show the 1st one - String openingGroupLocalName = (String) request.getParameter("curgroup"); - VitroRequest vreq = new VitroRequest(request); - // added to permit distinguishing links outside the current portal - int currentPortalId = -1; - Portal currentPortal = vreq.getPortal(); - if (currentPortal!=null) { - currentPortalId = currentPortal.getPortalId(); - } - - WebappDaoFactory wdf = vreq.getWebappDaoFactory(); - PropertyGroupDao pgDao = wdf.getPropertyGroupDao(); - VClassDao vcDao = wdf.getVClassDao(); - - ArrayList propsList = (ArrayList) request.getAttribute("mergedList"); - for (Property p : propsList) {%> - -<% if (p instanceof ObjectProperty) { - ObjectProperty op = (ObjectProperty)p;%> - - - - - - - - - - - - - - - - -
    -

    ${objProp.label}

    - - - <%-- Verbose property display additions for object properties, using context variable verbosePropertyListing --%> - - - - - - - - - - - - - - - - - - - - - - - -<% PropertyGroup pg = pgDao.getGroupByURI(op.getGroupURI()); - if (pg!=null && pg.getName()!=null) { - request.setAttribute("groupName",pg.getName());%> - ${localName} (object property); display tier ${displayTier} within group ${groupName}; display level: ${displayCue}; update level: ${updateCue} -<% } else {%> - ${localName} (object property); display tier ${displayTier}; display level: ${displayCue}; update level: ${updateCue} -<% } %> - - - ${localName} (object property); display tier ${displayTier}; display level: ${displayCue}; update level: ${updateCue} - - - - <%-- end Verbose property display additions for object properties --%> - - - - <% /* arbitrary limit if value is unset, i.e. -1 */ %> - - - -
      - - - - - - - - - - - - - - - - - -
    -
    - - - -
  • -
    ${collateCurrentClassName}
    -
      - - -
    • - - - - - - - <% - String customShortView = MiscWebUtils.getCustomShortView(request); - %> - - - - - - - - - - - - - - - - - - - ${editLinks}  - (non-editable) - - -
    • - - -
    -
  • - -
    -
    -<% } else if (p instanceof DataProperty) { - DataProperty dp = (DataProperty)p;%> - - - - - - - - - - - - -
    -

    ${dataProp.label}

    - - <%-- Verbose property display additions for data properties, using context variable verbosePropertyListing --%> - - - - - - - - - - - - - - - - - - - - - - - - <% PropertyGroup pg = pgDao.getGroupByURI(dp.getGroupURI()); - if (pg!=null && pg.getName()!=null) { - request.setAttribute("groupName",pg.getName());%> - ${localName} (data property); display tier ${displayTier} within group ${groupName}; display level: ${displayCue}; update level: ${updateCue} - <% } else {%> - ${localName} (data property); display tier ${displayTier}; display level: ${displayCue}; update level: ${updateCue} - <% } %> - - - ${localName} (data property); display tier ${displayTier}; display level: ${displayCue}; update level: ${updateCue} - - - - <%-- end Verbose property display additions for data properties --%> - - - - <% /* arbitrary limit if value is unset, i.e. -1 */ %> - - - -
    - -
      - - -
      - - - -
    - -
    -
    - - -<% } else { // keyword property -- ignore - if (p instanceof KeywordProperty) {%> -

    Not expecting keyword properties here.

    -<% } else { - log.warn("unexpected unknown property type found");%> -

    Unknown property type found

    -<% } - } - } // end for (Property p : g.getPropertyList() -%> diff --git a/webapp/web/templates/entity/entity_inject_head.jsp b/webapp/web/templates/entity/entity_inject_head.jsp deleted file mode 100644 index 3047f5122..000000000 --- a/webapp/web/templates/entity/entity_inject_head.jsp +++ /dev/null @@ -1,47 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> - -<% /*********************************************** - This file is used to inject and -****************************************************/ %> - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/webapp/web/templates/entity/linkShortView.jsp b/webapp/web/templates/entity/linkShortView.jsp deleted file mode 100644 index a7228b02c..000000000 --- a/webapp/web/templates/entity/linkShortView.jsp +++ /dev/null @@ -1,54 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> -<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Link" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> -<%@ page import="org.apache.commons.logging.Log" %> -<%@ page import="org.apache.commons.logging.LogFactory" %> - -<%! -public static Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.webapp.jsp.templates.entity.linkShortView.jsp"); -%> - -<%-- this comes in as an attribute called "individual" but the object has to be created as a Link using the Link dao getLinkByURI() method in order to render correctly - when the link uri may sometimes be of XSD type anyURI and sometimes of XSD type string --%> -<% -Individual ind = (Individual)request.getAttribute("individual"); -WebappDaoFactory wdf = (WebappDaoFactory)getServletContext().getAttribute("webappDaoFactory"); -if (wdf!=null) { - Link link = wdf.getLinksDao().getLinkByURI(ind.getURI()); - if (link!=null) { - request.setAttribute("linkIndividual", link); - } else { - log.error("Cannot create linkIndividual from individual "+ind.getUrl()); - } -} else { - log.error("Cannot create WebappDaoFactory in linkShortView.jsp"); -}%> - - - - - - - - - - ">${linkIndividual.anchor} - - - - - - - - - - - - - - - diff --git a/webapp/web/templates/parts/search_error.jsp b/webapp/web/templates/parts/search_error.jsp deleted file mode 100755 index 3260f9ad4..000000000 --- a/webapp/web/templates/parts/search_error.jsp +++ /dev/null @@ -1,10 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - - -
    -

    There was an error in the system; your search could not be processed. Please try again later or contact us.

    -
    - - - - diff --git a/webapp/web/templates/parts/thankyou.jsp b/webapp/web/templates/parts/thankyou.jsp deleted file mode 100644 index caff5f850..000000000 --- a/webapp/web/templates/parts/thankyou.jsp +++ /dev/null @@ -1,28 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ page language="java" %> -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %><%/* this odd thing points to something in web.xml */ %> -<%@ page import="java.util.*" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Portal" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> - -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%> - -<% -VitroRequest vreq = new VitroRequest(request); -Portal portalBean=vreq.getPortal(); -%> - - - - -<%-- Need to get the context --%> - - -
    -

    Feedback

    - mailbox
    - -

    Thank you for contacting our curation and development team. We will respond to your inquiry as soon as possible.

    -

    Click to return to the home page.

    -
    diff --git a/webapp/web/templates/search/searchBadQuery.jsp b/webapp/web/templates/search/searchBadQuery.jsp deleted file mode 100644 index bed52f467..000000000 --- a/webapp/web/templates/search/searchBadQuery.jsp +++ /dev/null @@ -1,35 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %><%/* this odd thing points to something in web.xml */ %> -<%@ page errorPage="/error.jsp"%> -<% /*********************************************** - Used when the search results are empty. - - request.attributes: - - request.parameters: - None yet. - - Consider sticking < % = MiscWebUtils.getReqInfo(request) % > in the html output - for debugging info. - - **********************************************/ -%> - - - - - - -
    -
    -

    - - -

    - - -
    -
    diff --git a/webapp/web/templates/search/searchBasic.jsp b/webapp/web/templates/search/searchBasic.jsp deleted file mode 100644 index 961cbfaae..000000000 --- a/webapp/web/templates/search/searchBasic.jsp +++ /dev/null @@ -1,157 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ page import="java.util.*"%> -<%@ page import="java.net.URLEncoder"%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.*" %> - -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %><%/* this odd thing points to something in web.xml */ %> -<%@ page errorPage="/error.jsp"%> -<% -/*********************************************** - Display a}x9n;:[ - Search Results - - request.attributes: - a Map object with the name "collatedResultsLists" - collatedGroupNames - request.parameters: - None yet. - - Consider sticking < % = MiscWebUtils.getReqInfo(request) % > in the html output - for debugging info. - - **********************************************/ - if (request.getAttribute("collatedResultsLists") == null) { - String e = "searchBaisc.jsp expects that request attribute " + - "'collatedResultsLists' be set to a Map of Lists of results to display."; - throw new JspException(e); - } - if (request.getAttribute("collatedGroupNames") == null) { - String e = "searchBaisc.jsp expects that request attribute " - + "'collatedGroupNames' be set to a list of keys in collatedResultsLists."; - throw new JspException(e); - } - - int switchdivs = 0; // for making IDs for the plus-icon expansion divs - - edu.cornell.mannlib.vitro.webapp.beans.Portal portal = (Portal) request.getAttribute("portalBean"); - int portalId = portal.getPortalId(); - - Map results = (Map) request.getAttribute("collatedResultsLists"); - - out.println("
    "); - - //do classgroup toc - Iterator it = results.keySet().iterator(); - out.println("

    Jump to results of type: "); - while (it.hasNext()) { - Object key = it.next(); - VClassGroup grp = (VClassGroup) results.get(key); - out.println(" " + key + " "); - } - out.println("

    "); - - //get each ClassGroup - it = results.keySet().iterator(); - while (it.hasNext()) { - Object key = it.next(); - VClassGroup grp = (VClassGroup) results.get(key); - out.println("

    " + key + "

    "); - - //get each VClassList - Iterator it2 = grp.iterator(); - while (it2.hasNext()) { - VClassList vcl = (VClassList) it2.next(); - - int resultSetSize = vcl.getEntities().size(); - int displayLimit = vcl.getDisplayLimit(); - if (resultSetSize - displayLimit == 1) - ++displayLimit; - boolean hiddenDivStarted = false; - - out.println("

    " + vcl.getName() + " (" + resultSetSize + ")

    "); - out.println("
      "); - - List ents = vcl.getEntities(); - if (ents == null || ents.size() == 0) - out.println("
    • none
    • "); - else { - //get each entity - Iterator it3 = ents.iterator(); - int count = 0; - while (it3.hasNext()) { - Individual ent = (Individual) it3.next(); - ++count; - String escapedURIStr = ""; - try { - escapedURIStr = URLEncoder.encode(ent.getURI(),"UTF-8"); - } catch (Exception e) { - /*unsupported encoding?*/ - } - out.println("
    • "); - out.println("" + ent.getName().replaceAll("&","&") + ""); - if (ent.getMoniker() != null && ent.getMoniker().length() > 0) { - out.println(" | " + ent.getMoniker().replaceAll("&","&")); - } - if (portal.getPortalId() == 6) { //show anchors in impact portal for submitter's name - if (ent.getAnchor() != null && ent.getAnchor().length() > 0) { - out.println(" | " + ent.getAnchor() + ""); - } - } - /* if (portal.getAppName().equalsIgnoreCase("VIVO") || portal.getAppName().equalsIgnoreCase("Research")) { - //Medha's desired display - if (ent.getUrl() != null && ent.getUrl().length() > 0) { - out.println(" | " - + ent.getAnchor().replaceAll("&","&") + ""); - } else if (ent.getAnchor() != null && ent.getAnchor().length() > 0) { - out.println(" | " + ent.getAnchor().replaceAll("&","&") + ""); - } - List linksList = ent.getLinksList(); - if (linksList != null) { - Iterator lit = linksList.iterator(); - while (lit.hasNext()) { - Link l = (Link) lit.next(); - if (l.getUrl() != null && l.getUrl().length() > 0) { - out.println(" | " - + l.getAnchor().replaceAll("&","&") + ""); - } else { - out.println(" | " + l.getAnchor().replaceAll("&","&") + ""); - } - } - } - } else { //show the Google-like excerpt */ - if (ent.getDescription() != null && ent.getDescription().length() > 0) { - out.println("
      " + ent.getDescription() + "
      "); - } - /* } */ - out.println("
    • "); - int remaining = resultSetSize - count; - if (count == displayLimit && remaining > 0) { - hiddenDivStarted = true; switchdivs++; %> -
    - -<% out.println(" "); - } - } // END while it3.hasNext() - if (!hiddenDivStarted) { - out.println(""); - } - } // END else have entities - } // END while it2.hasNext() -} // END while it.hasNext() -%> -
    diff --git a/webapp/web/templates/search/searchFailed.jsp b/webapp/web/templates/search/searchFailed.jsp deleted file mode 100644 index a68a45e3a..000000000 --- a/webapp/web/templates/search/searchFailed.jsp +++ /dev/null @@ -1,35 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %><%/* this odd thing points to something in web.xml */ %> -<%@ page errorPage="/error.jsp"%> -<% /*********************************************** - Used when the search results are empty. - - request.attributes: - - request.parameters: - None yet. - - Consider sticking < % = MiscWebUtils.getReqInfo(request) % > in the html output - for debugging info. - - **********************************************/ -%> - - - - - - -
    -
    -

    - - -

    - - -
    -
    diff --git a/webapp/web/templates/search/searchForm.jsp b/webapp/web/templates/search/searchForm.jsp deleted file mode 100644 index 1c886b320..000000000 --- a/webapp/web/templates/search/searchForm.jsp +++ /dev/null @@ -1,45 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean" %> -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %><%/* this odd thing points to something in web.xml */ %> - -<% /*********************************************** - Used to display a search form. - - request.attributes: - - request.parameters: - None yet. - - Consider sticking < % = MiscWebUtils.getReqInfo(request) % > in the html output - for debugging info. - - **********************************************/ -%> - - - - - - -
    - -
    -
    -

    Search

    - - - -

    -
    -
    -
    - -
    - -
    - diff --git a/webapp/web/templates/search/searchGroup.jsp b/webapp/web/templates/search/searchGroup.jsp deleted file mode 100644 index 1477b32a3..000000000 --- a/webapp/web/templates/search/searchGroup.jsp +++ /dev/null @@ -1,54 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %><%/* this odd thing points to something in web.xml */ %> -<%@ page errorPage="/error.jsp"%> -<% /*********************************************** - Display a single search result group - - request.attributes: - a List with objects with the named "entities" - a ClassGroup object named "classgroup" - - request.parameters: - None yet. - - Consider sticking < % = MiscWebUtils.getReqInfo(request) % > in the html output - for debugging info. - **********************************************/ - if (request.getAttribute("entities") == null){ - String e="searchGroup.jsp expects that request attribute 'entities' be set to the Entity object to display."; - throw new JspException(e); - } - if (request.getAttribute("classgroup") == null){ - String e="searchGroup.jsp expects that request attribute 'classgroup' be set to the Entity object to display."; - throw new JspException(e); - } -%> -<%/* just moving this into page scope for easy use */ %> - - - - - -
    -

    - - - ${entity.anchor} - - - | - - - - - <%/* here we import the properties for the entity */ %> -
    - -
    - -
    diff --git a/webapp/web/templates/search/searchPaged.jsp b/webapp/web/templates/search/searchPaged.jsp deleted file mode 100644 index 9b604099a..000000000 --- a/webapp/web/templates/search/searchPaged.jsp +++ /dev/null @@ -1,177 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ page import="java.util.*"%> -<%@ page import="java.net.URLEncoder"%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.*" %> -<%@ page import="org.apache.commons.lang.StringEscapeUtils" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Portal" %> -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> -<%@ page errorPage="/error.jsp"%> - -<% -/*********************************************** - Display Paged Search Results - - request.attributes: - List object with the name "beans" - request.parameters: - None yet. - ********************************************* */ - - if (request.getAttribute("beans") == null) { - String e = "searchBaisc.jsp expects that request attribute " + - "'beans' be set to a List of Individuals to display."; - throw new JspException(e); - } - Portal portal = (Portal) request.getAttribute("portalBean"); - String portalParm = "&home=" + portal.getPortalId(); - - - -%> -
    -

    Search Results for '' - - limited to type '${requestScope.classgroupName}' - - limited to type '${requestScope.typeName}' -

    -
    -<% - - if( request.getAttribute("classgroups") != null ){ - %>
    Show only results of this type: <% - List groups = (List) request.getAttribute("classgroups"); - Iterator it = groups.iterator(); - - while(it.hasNext()){ - VClassGroup grp = (VClassGroup)it.next(); - out.println(""); - out.println(StringEscapeUtils.escapeHtml(grp.getPublicName())); - out.println(""); - } - out.println("
    "); - } - - -if( request.getAttribute("types") != null ){ - %>
    Show only results of this sub-type: <% - List types = (List) request.getAttribute("types"); - Iterator it = types.iterator(); - - while(it.hasNext()){ - VClass type = (VClass)it.next(); - out.println(""); - out.println(StringEscapeUtils.escapeHtml(type.getName())); - out.println(""); - } - out.println("
    "); -} - - /* generate search result list */ - List beans = (List) request.getAttribute("beans"); - Iterator it = beans.iterator(); - out.println("
      "); - - while (it.hasNext()) { - Individual ent = (Individual) it.next(); - String escapedURIStr = ""; - try { - escapedURIStr = URLEncoder.encode(ent.getURI(),"UTF-8"); - } catch (Exception e) { } // unsupported encoding? - - out.println("
    • "); - out.print("" - + StringEscapeUtils.escapeHtml( ent.getName() ) - + " "); - - if (ent.getMoniker() != null && ent.getMoniker().length() > 0) - out.println(" | " + StringEscapeUtils.escapeHtml(ent.getMoniker())); - - // For now, custom search views just add additional information to the name and moniker - String searchViewPrefix = "/templates/search/"; - String customSearchView = null; - for (VClass type : ent.getVClasses(true)) { // first get directly asserted class(es) - if (type!=null) { - customSearchView = type.getCustomSearchView(); - if (customSearchView!=null && customSearchView.length()>0 ) { - // NOTE we are NOT putting "individualURL" in the request scope - // An included custom search view jsp can optionally implement a test for "individualURL" - // as a way to optionally render additional text as a link - // SEE entityList.jsp and searchViewWithTimekey.jsp as an example - request.setAttribute("individual",ent); %> - | -<% request.removeAttribute("individual"); - // TODO: figure out which of the directly asserted classes should have precedence; for now, just take the 1st - break; // have to break because otherwise customSearchView may get reset to null and trigger more evaluation - } - } - } - if (customSearchView == null ) { // try inferred classes, too - for (VClass type : ent.getVClasses()) { - if (type!=null) { - customSearchView = type.getCustomSearchView(); - if (customSearchView!=null && customSearchView.length()>0 ) { - // SEE NOTE just above - request.setAttribute("individual",ent); - %><% - request.removeAttribute("individual"); - //TODO: figure out which of the inferred classes should have precedence; for now, just take the 1st - break; - } - } - } - } - - if (ent.getDescription() != null && ent.getDescription().length() > 0) { - out.println("
      " + ent.getDescription() + "
      "); - } - - out.println("
    • "); - } // END while it.hasNext() - out.println("
    "); - - /* generate pageing list */ - int startIndex = (Integer)request.getAttribute("startIndex"); - int hitsPerPage = (Integer)request.getAttribute("hitsPerPage"); - int hitsLength = (Integer)request.getAttribute("hitsLength"); - int maxHitSize = (Integer)request.getAttribute("maxHitSize"); - String basePageUrl = - request.getContextPath() + "/search?querytext=" - +URLEncoder.encode(request.getParameter("querytext"),"UTF-8") + - request.getAttribute("refinement"); - - out.println("
    "); - out.println("Pages:"); - for(int i=0; i= (startIndex) && i < (startIndex+ hitsPerPage)?"class='currentPage'":""; - out.println("" + ((i/hitsPerPage) + 1) + ""); - }else{ - out.println("more..."); - break; - } - } - out.println("
    "); -%> -
    -
    \ No newline at end of file diff --git a/webapp/web/templates/search/searchTips.jsp b/webapp/web/templates/search/searchTips.jsp deleted file mode 100644 index e4437aef4..000000000 --- a/webapp/web/templates/search/searchTips.jsp +++ /dev/null @@ -1,18 +0,0 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -

    Search Tips

    -
      -
    • Use short, single terms unless your searches are returning too many results
    • -
    • When you enter more than one term, the search will look for records containing all of them unless you add the word "OR" between your terms.
    • -
    • "NOT" can help limit searches -- e.g., climate NOT change
    • -
    • Except for boolean operators, searches are not case-sensitive, so "Geneva" and "geneva" are equivalent
    • -
    • Enclose a phrase in quotes (") to search for the whole phrase, not individual words (e.g., "protein folding") -- both leading and ending quotes are required
    • -
    • Phrase searches may be combined with boolean operators: "climate change" OR "global warming"
    • -
    • The search uses stemming by default so that close word variations will also be found (e.g., "sequence" also matches "sequences" and "sequencing"). - Use the wildcard * character to match wider variation (e.g., nano* to match both - nanotechnology and nanofabrication), but note that searching uses stemmed, or shortened, versions of words, - so "cogniti*" finds nothing while "cognit*" finds both cognitive and cognition
    • -
    • If you're not sure of the spelling, put a ~ at the end -- e.g., cabage~ finds cabbage, - steven~ finds Stephen and Stefan (as well as a few unwanted extra words)
    • -
    • To match a person or unit's primary entry, enter name: Smith or name: Biology
    • -
    \ No newline at end of file