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) {