From b871a4fa7aa27f0ce0cf765b97b8c40e4ef855ce Mon Sep 17 00:00:00 2001 From: William Welling Date: Fri, 22 Jan 2016 10:00:20 -0600 Subject: [PATCH] Fixed search metadata export by passing query and filter to processQuery of AbstractSearch. --- .../aspect/discovery/AbstractSearch.java | 11 +- .../xmlui/aspect/discovery/Navigation.java | 126 ++++-------------- .../cocoon/AbstractDSpaceTransformer.java | 2 +- .../cocoon/SearchMetadataExportReader.java | 60 ++++----- .../resources/aspects/Discovery/sitemap.xmap | 6 +- dspace-xmlui/src/main/webapp/sitemap.xmap | 22 +++ 6 files changed, 82 insertions(+), 145 deletions(-) diff --git a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/discovery/AbstractSearch.java b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/discovery/AbstractSearch.java index 2d6d081a79..2d4db15a32 100644 --- a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/discovery/AbstractSearch.java +++ b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/discovery/AbstractSearch.java @@ -731,22 +731,17 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer implement * * @param scope the dspace object parent */ - public DiscoverQuery prepareQuery(DSpaceObject scope) throws UIException, SearchServiceException { + public DiscoverQuery prepareQuery(DSpaceObject scope, String query, String[] fqs) throws UIException, SearchServiceException { this.queryArgs = new DiscoverQuery(); - // possibly an argument int page = getParameterPage(); - - String query = getQuery(); - + // Escape any special characters in this user-entered query query = DiscoveryUIUtils.escapeQueryChars(query); List filterQueries = new ArrayList(); - String[] fqs = getFilterQueries(); - if (fqs != null) { filterQueries.addAll(Arrays.asList(fqs)); @@ -850,7 +845,7 @@ public abstract class AbstractSearch extends AbstractDSpaceTransformer implement return; } - this.queryResults = SearchUtils.getSearchService().search(context, scope, prepareQuery(scope)); + this.queryResults = SearchUtils.getSearchService().search(context, scope, prepareQuery(scope, getQuery(), getFilterQueries())); } /** diff --git a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/discovery/Navigation.java b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/discovery/Navigation.java index 64bbd41f16..7e4b90a278 100644 --- a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/discovery/Navigation.java +++ b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/aspect/discovery/Navigation.java @@ -20,26 +20,13 @@ import org.apache.excalibur.source.impl.validity.NOPValidity; import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer; import org.dspace.app.xmlui.utils.HandleUtil; import org.dspace.app.xmlui.utils.UIException; -import org.dspace.app.xmlui.utils.ContextUtil; -import org.dspace.app.xmlui.wing.Message; import org.dspace.app.xmlui.wing.WingException; -import org.dspace.app.xmlui.wing.element.List; import org.dspace.app.xmlui.wing.element.Options; import org.dspace.app.xmlui.wing.element.PageMeta; import org.dspace.authorize.AuthorizeException; -import org.dspace.authorize.factory.AuthorizeServiceFactory; -import org.dspace.authorize.service.AuthorizeService; -import org.dspace.core.ConfigurationManager; -import org.dspace.core.Context; -import org.dspace.content.Item; -import org.dspace.content.Collection; -import org.dspace.content.Community; import org.dspace.content.DSpaceObject; -import org.dspace.discovery.*; import org.xml.sax.SAXException; -import org.apache.log4j.Logger; - /** * Navigation that adds code needed for discovery search * @@ -49,18 +36,12 @@ import org.apache.log4j.Logger; */ public class Navigation extends AbstractDSpaceTransformer implements CacheableProcessingComponent { - private static final Logger log = Logger.getLogger(Navigation.class); - private static final Message T_context_head = message("xmlui.administrative.Navigation.context_head"); - private static final Message T_export_metadata = message("xmlui.administrative.Navigation.context_search_export_metadata"); - - private AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService(); - /** * Generate the unique caching key. * This key must be unique inside the space of this component. */ public Serializable getKey() { - try { + try { Request request = ObjectModelHelper.getRequest(objectModel); String key = request.getScheme() + request.getServerName() + request.getServerPort() + request.getSitemapURI() + request.getQueryString(); @@ -97,24 +78,24 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr * * language FIXME: add languages * - * context - export metadata if in discover + * context no context options are added. * * action no action options are added. */ public void addOptions(Options options) throws SAXException, WingException, UIException, SQLException, IOException, AuthorizeException { - Context context = ContextUtil.obtainContext(objectModel); - Request request = ObjectModelHelper.getRequest(objectModel); - - // code remnants left behind, probably can be deleted - - //List test = options.addList("browse"); - //List discovery = options.addList("discovery-search"); - //discovery.setHead("Discovery"); - //discovery.addItem().addXref(contextPath + "/discover" , "Discover"); +// DSpaceObject dso = HandleUtil.obtainHandle(objectModel); - /* +// List test = options.addList("browse"); + +// List discovery = options.addList("discovery-search"); + +// discovery.setHead("Discovery"); +// +// discovery.addItem().addXref(contextPath + "/discover" , "Discover"); + + /* List browse = options.addList("browse"); browse.setHead(T_head_browse); @@ -124,6 +105,7 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr browseGlobal.setHead(T_head_all_of_dspace); + if (dso != null) { if (dso instanceof Collection) @@ -136,80 +118,15 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr } } browseGlobal.addItem().addXref(contextPath + "/community-list", T_head_all_of_dspace ); - */ + */ /* regulate the ordering */ options.addList("discovery"); options.addList("browse"); options.addList("account"); + options.addList("context"); options.addList("administrative"); - - // get uri to see if using discovery and if under a specific handle - String uri = request.getSitemapURI(); - - // check value in dspace.cfg - String search_export_config = ConfigurationManager.getProperty("xmlui.search.metadata_export"); - - // get query - String query = decodeFromURL(request.getParameter("query")); - - // get scope, if not under handle returns null - String scope= request.getParameter("scope"); - - // used to serialize all query filters together - String filters = ""; - - // get all query filters - String[] fqs = DiscoveryUIUtils.getFilterQueries(ObjectModelHelper.getRequest(objectModel), context); - - if (fqs != null) - { - for(int i = 0; i < fqs.length; i++) { - if(i < fqs.length - 1) - filters += fqs[i] + ","; - else - filters += fqs[i]; - } - } - - if(uri.contains("discover")) { - // check scope - if(scope == null || "".equals(scope)) - scope = "/"; - // check query - if(query == null || "".equals(query)) - query = "*"; - // check if under a handle, already in discovery - if(uri.contains("handle")) { - scope = uri.replace("handle/", "").replace("/discover", ""); - } - // replace forward slash to pass through sitemap - try { - scope = scope.replace("/", "~"); - } - catch(NullPointerException e) { } - if(search_export_config != null) { - // some logging - - log.info("uri: " + uri); - log.info("query: " + query); - log.info("scope: " + scope); - log.info("filters: " + filters); - - if(search_export_config.equals("admin")) { - if(authorizeService.isAdmin(context)) { - List results = options.addList("context"); - results.setHead(T_context_head); - results.addItem().addXref(contextPath + "/discover/csv/" + query + "/" + scope + "/" + filters, T_export_metadata); - } - } - else if(search_export_config.equals("user") || search_export_config.equals("anonymous")){ - List results = options.addList("context"); - results.setHead(T_context_head); - results.addItem().addXref(contextPath + "/discover/csv/" + query + "/" + scope + "/" + filters, T_export_metadata); - } - } - } + } /** @@ -219,9 +136,14 @@ public class Navigation extends AbstractDSpaceTransformer implements CacheablePr WingException, UIException, SQLException, IOException, AuthorizeException { + // Add metadata for quick searches: - pageMeta.addMetadata("search", "simpleURL").addContent("/discover"); - pageMeta.addMetadata("search", "advancedURL").addContent(contextPath + "/discover"); + pageMeta.addMetadata("search", "simpleURL").addContent( + "/discover"); + pageMeta.addMetadata("search", "advancedURL").addContent( + contextPath + "/discover"); pageMeta.addMetadata("search", "queryField").addContent("query"); + } -} + +} \ No newline at end of file diff --git a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/cocoon/AbstractDSpaceTransformer.java b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/cocoon/AbstractDSpaceTransformer.java index a8702bea04..23e90fda40 100644 --- a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/cocoon/AbstractDSpaceTransformer.java +++ b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/cocoon/AbstractDSpaceTransformer.java @@ -110,7 +110,7 @@ public abstract class AbstractDSpaceTransformer extends AbstractWingTransformer "An error was encountered while processing the '"+this.getComponentName()+"' Wing based component: " + this.getClass().getName(), e); } - + /** What to add at the end of the body */ public void addBody(Body body) throws SAXException, WingException, UIException, SQLException, IOException, AuthorizeException, ProcessingException diff --git a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/cocoon/SearchMetadataExportReader.java b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/cocoon/SearchMetadataExportReader.java index 67938578c0..e856049227 100644 --- a/dspace-xmlui/src/main/java/org/dspace/app/xmlui/cocoon/SearchMetadataExportReader.java +++ b/dspace-xmlui/src/main/java/org/dspace/app/xmlui/cocoon/SearchMetadataExportReader.java @@ -10,8 +10,6 @@ package org.dspace.app.xmlui.cocoon; import java.io.IOException; import java.sql.SQLException; import java.util.*; -import java.util.Map; -import java.util.ArrayList; import javax.servlet.http.HttpServletResponse; @@ -67,9 +65,7 @@ import org.dspace.discovery.configuration.DiscoverySortFieldConfiguration; */ public class SearchMetadataExportReader extends AbstractReader implements Recyclable -{ - private static Logger log = Logger.getLogger(MetadataExportReader.class); - +{ /** * Messages to be sent when the user is not authorized to view * a particular bitstream. They will be redirected to the login @@ -98,23 +94,18 @@ public class SearchMetadataExportReader extends AbstractReader implements Recycl /** The Cocoon request */ protected Request request; + + + private static Logger log = Logger.getLogger(SearchMetadataExportReader.class); + + private AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService(); + private HandleService handleService = HandleServiceFactory.getInstance().getHandleService(); private DSpaceCSV csv = null; private String filename = null; private SimpleSearch simpleSearch = null; - - private AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService(); - - private HandleService handleService = HandleServiceFactory.getInstance().getHandleService(); - - - public SearchMetadataExportReader() { - simpleSearch = new SimpleSearch(); - } - - /** * Set up the export reader. * @@ -169,6 +160,8 @@ public class SearchMetadataExportReader extends AbstractReader implements Recycl } } + simpleSearch = new SimpleSearch(); + csv = exportMetadata(context, objectModel, query, scope, filters); filename = "search-results.csv"; @@ -217,27 +210,27 @@ public class SearchMetadataExportReader extends AbstractReader implements Recycl DiscoverQuery qArgs = new DiscoverQuery(); - try { - scopeString = scopeString.replace("~", "/"); - } - catch(NullPointerException e) { } - // Are we in a community or collection? + // Are we in a community or collection? DSpaceObject scope; - if (scopeString == null || "".equals(scopeString)) { - // get the search scope from the url handle + + if(scopeString != null && scopeString.length() > 0) { + scopeString = scopeString.replace("~", "/"); + // Get the search scope from the location parameter + scope = handleService.resolveToObject(context, scopeString); + } + else { + // get the search scope from the url handle scope = HandleUtil.obtainHandle(objectModel); - } - else { - // Get the search scope from the location parameter - scope = handleService.resolveToObject(context, scopeString); - } - + } + + // set the object model on the simple search object simpleSearch.objectModel = objectModel; + // prepare query from SimpleSearch object - qArgs = simpleSearch.prepareQuery(scope); + qArgs = simpleSearch.prepareQuery(scope, query, filters.split(",")); // no paging required qArgs.setStart(0); @@ -265,10 +258,13 @@ public class SearchMetadataExportReader extends AbstractReader implements Recycl // Log the attempt log.info(LogManager.getHeader(context, "metadataexport", "exporting_search")); - MetadataExport exporter = new MetadataExport(context, items.iterator(), false); + Iterator toExport = items.iterator(); + + MetadataExport exporter = new MetadataExport(context, toExport, false); // Perform the export - DSpaceCSV csv = exporter.export(); + DSpaceCSV csv = exporter.export(); + log.info(LogManager.getHeader(context, "metadataexport", "exported_file:search-results.csv")); return csv; diff --git a/dspace-xmlui/src/main/resources/aspects/Discovery/sitemap.xmap b/dspace-xmlui/src/main/resources/aspects/Discovery/sitemap.xmap index d4a895e808..3a7b360f8e 100644 --- a/dspace-xmlui/src/main/resources/aspects/Discovery/sitemap.xmap +++ b/dspace-xmlui/src/main/resources/aspects/Discovery/sitemap.xmap @@ -30,10 +30,10 @@ and searching the repository. - + @@ -76,7 +76,7 @@ and searching the repository. 3) Metadata about the search urls. --> - + + @@ -147,6 +148,7 @@ and searching the repository. + diff --git a/dspace-xmlui/src/main/webapp/sitemap.xmap b/dspace-xmlui/src/main/webapp/sitemap.xmap index b46c98a257..5c60d02483 100644 --- a/dspace-xmlui/src/main/webapp/sitemap.xmap +++ b/dspace-xmlui/src/main/webapp/sitemap.xmap @@ -192,8 +192,20 @@ + + + + + + + + + + + + @@ -391,6 +403,11 @@ + + + + + @@ -399,6 +416,11 @@ + + + + +