From 1e6ba3e86c1160429e3a98da4e2749f26b8d5586 Mon Sep 17 00:00:00 2001 From: Will Abson Date: Wed, 3 Sep 2014 16:14:31 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud) 80643: Merged WAT1 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 76831: Enhancement to the /api/solr/facet-config REST endpoint to support facet reordering. If you add a query parameter like so: /api/solr/facet-config/{filterID}?relativePos={relativePos?} then the specified filterID will be moved by the specified relative position. '3' means move it 3 places down the list. '-1' means move it one place up the list. Note that currently you cannot provide a HTTP request body (JSON) at the same time as the relativePos param, in other words you cannot update the facet metadata and reposition in in one REST call. It is either or. We may enhance the webscript to support simultaneous edits of metadata and position at a future date. Also added automatic management of facet position on facet create and delete. New facets are put at the end of the list - this can easily be changed if it is not what's wanted. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@82937 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../solr-facet-config-admin.put.desc.xml | 22 ++++-- .../web-scripts-application-context.xml | 2 +- .../solr/facet/SolrFacetConfigAdminPut.java | 67 +++++++++++++++++-- 3 files changed, 77 insertions(+), 14 deletions(-) diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.put.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.put.desc.xml index 2de4bd15d7..65064b2602 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.put.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/solr/facet/solr-facet-config-admin.put.desc.xml @@ -2,12 +2,14 @@ PUT Faceted-Search Config :/alfresco/api/solr/facet-config - - Example body to this web script: - + Put (update) faceted-search config
+ This REST endpoint supports two forms of resource updates:
+
+ http://:/alfresco/api/solr/facet-config
+
+ This will perform an update of the Facet properties. Example body to this web script:
+
+
    {
              "filterID" : "filter_content_size",
              "facetQName" : "{http://www.alfresco.org/model/content/1.0}content.size",
@@ -25,13 +27,19 @@
               ],
              "index" : 6,  // optional
              "isEnabled" : true  // optional
-   }
+   }

Notes: - user must be an Admin, member of Alfresco_Search_Administrators group or a Network Admin for given network/tenant +
+ Alternatively, you can omit the request body as shown above and include a query parameter, relativePos, which + will not update the facet properties but will move the facet in the ordered list by the specified distance.
+ +2 means 'down two places'. -1 means 'up one place'. An attempt to move a facet beyond the end of the sequence will + simply move it to the end. ]]>
/api/solr/facet-config + /api/solr/facet-config/{filterID}?relativePos={relativePos?} argument user required diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index 6ac1d393ea..f22f959582 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1819,7 +1819,7 @@ - + diff --git a/source/java/org/alfresco/repo/web/scripts/solr/facet/SolrFacetConfigAdminPut.java b/source/java/org/alfresco/repo/web/scripts/solr/facet/SolrFacetConfigAdminPut.java index 9422293ed6..730fa7d701 100644 --- a/source/java/org/alfresco/repo/web/scripts/solr/facet/SolrFacetConfigAdminPut.java +++ b/source/java/org/alfresco/repo/web/scripts/solr/facet/SolrFacetConfigAdminPut.java @@ -20,9 +20,13 @@ package org.alfresco.repo.web.scripts.solr.facet; import java.util.HashMap; +import java.util.List; import java.util.Map; +import org.alfresco.repo.search.impl.solr.facet.Exceptions.UnrecognisedFacetId; import org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties; +import org.alfresco.util.collections.CollectionUtils; +import org.alfresco.util.collections.Function; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.extensions.webscripts.Cache; @@ -39,19 +43,70 @@ public class SolrFacetConfigAdminPut extends AbstractSolrFacetConfigAdminWebScri { private static final Log logger = LogFactory.getLog(SolrFacetConfigAdminPost.class); + protected static final String PARAM_RELATIVE_POS = "relativePos"; + protected static final String URL_PARAM_FILTER_ID = "filterID"; + @Override protected Map unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache) { + final String relativePosString = req.getParameter(PARAM_RELATIVE_POS); try { - SolrFacetProperties fp = parseRequestForFacetProperties(req); - facetService.updateFacet(fp); - - if (logger.isDebugEnabled()) + if (relativePosString != null) { - logger.debug("Updated facet node: " + fp); + // This is a request to 'move' (reposition) the specified facet. + + // We need the relative position that the facet will move. + final int relativePos; + + try { relativePos = Integer.parseInt(relativePosString); } + catch (NumberFormatException nfe) + { + throw new WebScriptException(Status.STATUS_BAD_REQUEST, + "Cannot move facet as could not parse relative position: '" + relativePosString + "'"); + } + + // And we need the filterID for the facet we're moving. + final Map templateVars = req.getServiceMatch().getTemplateVars(); + String filterId = templateVars.get(URL_PARAM_FILTER_ID); + + if (filterId == null) { throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Illegal null filterId"); } + + // So let's move the filter... + try + { + // Get the current sequence of filter IDs. + List facets = facetService.getFacets(); + List facetIDs = CollectionUtils.transform(facets, new Function() + { + @Override public String apply(SolrFacetProperties value) + { + return value.getFilterID(); + } + }); + + List reorderedIDs = CollectionUtils.moveRight(relativePos, filterId, facetIDs); + + this.facetService.reorderFacets(reorderedIDs); + + if (logger.isDebugEnabled()) { logger.debug("Moved facet " + filterId + " to relative position: " + relativePos); } + } + catch (UnrecognisedFacetId ufi) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Unrecognised filter ID: " + ufi.getFacetId()); + } + } + // TODO Allow for simultaneous move and update of facet. + else + { + SolrFacetProperties fp = parseRequestForFacetProperties(req); + facetService.updateFacet(fp); + + if (logger.isDebugEnabled()) + { + logger.debug("Updated facet node: " + fp); + } } - } catch (Throwable t) {