/** * Generate the cache validity object. * * <p>The validity object will include the collection being viewed and all recently submitted * items. This does not include the community / collection hierarch, when this changes they will * not be reflected in the cache. */ public SourceValidity getValidity() { if (this.validity == null) { try { DSpaceValidity validity = new DSpaceValidity(); DSpaceObject dso = HandleUtil.obtainHandle(objectModel); if (dso != null) { // Add the actual collection; validity.add(dso); } // add recently submitted items, serialize solr query contents. DiscoverResult response = getQueryResponse(dso); validity.add("numFound:" + response.getDspaceObjects().size()); for (DSpaceObject resultDso : response.getDspaceObjects()) { validity.add(resultDso); } for (String facetField : response.getFacetResults().keySet()) { validity.add(facetField); List<DiscoverResult.FacetResult> facetValues = response.getFacetResults().get(facetField); for (DiscoverResult.FacetResult facetValue : facetValues) { validity.add(facetValue.getAsFilterQuery() + facetValue.getCount()); } } this.validity = validity.complete(); } catch (Exception e) { // Just ignore all errors and return an invalid cache. } // TODO: dependent on tags as well :) } return this.validity; }
@Override public void addBody(Body body) throws SAXException, WingException, UIException, SQLException, IOException, AuthorizeException { Request request = ObjectModelHelper.getRequest(objectModel); DSpaceObject dso = HandleUtil.obtainHandle(objectModel); // Set up the major variables // Collection collection = (Collection) dso; // Build the collection viewer division. // Make sure we get our results queryResults = getQueryResponse(dso); if (this.queryResults != null) { Map<String, List<DiscoverResult.FacetResult>> facetFields = this.queryResults.getFacetResults(); if (facetFields == null) { facetFields = new LinkedHashMap<String, List<DiscoverResult.FacetResult>>(); } // facetFields.addAll(this.queryResults.getFacetDates()); if (facetFields.size() > 0) { String facetField = String.valueOf(facetFields.keySet().toArray(new String[facetFields.size()])[0]); java.util.List<DiscoverResult.FacetResult> values = facetFields.get(facetField); if (values != null && 0 < values.size()) { Division results = body.addDivision("browse-by-" + facetField + "-results", "primary"); results.setHead( message( "xmlui.ArtifactBrowser.AbstractSearch.type_" + request.getParameter(FACET_FIELD) + "_browse")); // Find our faceting offset int offSet = queryArgs.getFacetOffset(); if (offSet == -1) { offSet = 0; } // Only show the nextpageurl if we have at least one result following our current results String nextPageUrl = null; if (values.size() == (DEFAULT_PAGE_SIZE + 1)) { nextPageUrl = getNextPageURL(request); } results.setSimplePagination( (int) queryResults.getDspaceObjects().size(), offSet + 1, (offSet + (values.size() - 1)), getPreviousPageURL(request), nextPageUrl); Table singleTable = results.addTable( "browse-by-" + facetField + "-results", (int) (queryResults.getDspaceObjects().size() + 1), 1); List<String> filterQueries = new ArrayList<String>(); if (request.getParameterValues("fq") != null) { filterQueries = Arrays.asList(request.getParameterValues("fq")); } for (int i = 0; i < values.size(); i++) { DiscoverResult.FacetResult value = values.get(i); String displayedValue = value.getDisplayedValue(); String filterQuery = value.getAsFilterQuery(); // if(field.getGap() != null){ // //We have a date get the year so we can display it // DateFormat simpleDateformat = new // SimpleDateFormat("yyyy"); // displayedValue = // simpleDateformat.format(SolrServiceImpl.toDate(displayedValue)); // filterQuery = // ClientUtils.escapeQueryChars(value.getFacetField().getName()) + ":" + displayedValue // + "*"; // } Cell cell = singleTable.addRow().addCell(); // No use in selecting the same filter twice if (filterQueries.contains(filterQuery)) { cell.addContent(displayedValue + " (" + value.getCount() + ")"); } else { cell.addXref( contextPath + (dso == null ? "" : "/handle/" + dso.getHandle()) + "/discover?" + "&fq=" + URLEncoder.encode(filterQuery, "UTF-8") + (request.getQueryString() != null ? "&" + request.getQueryString() : ""), displayedValue + " (" + value.getCount() + ")"); } } } } } // DSpaceObject dso = HandleUtil.obtainHandle(objectModel); /* if (dso != null) { if (dso instanceof Collection) { browseContext.addItem().addXref(contextPath + "/discovery/?q=search.resourcetype%3A2+AND+location%3Al" + dso.getID(), T_head_this_collection ); } if (dso instanceof Community) { browseContext.addItem().addXref(contextPath + "/discovery/?q=search.resourcetype%3A2+AND+location%3Am" + dso.getID(), T_head_this_community ); } } browseGlobal.addItem().addXref(contextPath + "/discovery/?q=search.resourcetype%3A2", T_head_all_of_dspace ); */ }