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
This commit is contained in:
Will Abson
2014-09-03 16:14:31 +00:00
parent 31dd6cfa6e
commit 1e6ba3e86c
3 changed files with 77 additions and 14 deletions

View File

@@ -2,12 +2,14 @@
<shortname>PUT Faceted-Search Config</shortname> <shortname>PUT Faceted-Search Config</shortname>
<description> <description>
<![CDATA[ <![CDATA[
Put (update) faceted-search configt Put (update) faceted-search config<br/>
This REST endpoint supports two forms of resource updates:<br/>
http://<host>:<port>/alfresco/api/solr/facet-config <br/>
http://<host>:<port>/alfresco/api/solr/facet-config<br/>
Example body to this web script: <br/>
This will perform an update of the Facet properties. Example body to this web script:<br/>
<br/>
<pre>
{ {
"filterID" : "filter_content_size", "filterID" : "filter_content_size",
"facetQName" : "{http://www.alfresco.org/model/content/1.0}content.size", "facetQName" : "{http://www.alfresco.org/model/content/1.0}content.size",
@@ -25,13 +27,19 @@
], ],
"index" : 6, // optional "index" : 6, // optional
"isEnabled" : true // optional "isEnabled" : true // optional
} }</pre><br/>
Notes: Notes:
- user must be an Admin, member of Alfresco_Search_Administrators group or a Network Admin for given network/tenant - user must be an Admin, member of Alfresco_Search_Administrators group or a Network Admin for given network/tenant
<br/>
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.<br/>
+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.
]]> ]]>
</description> </description>
<url>/api/solr/facet-config</url> <url>/api/solr/facet-config</url>
<url>/api/solr/facet-config/{filterID}?relativePos={relativePos?}</url>
<format default="json">argument</format> <format default="json">argument</format>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>

View File

@@ -1819,7 +1819,7 @@
</property> </property>
</bean> </bean>
<!-- Get/Post/Put/Delete Solr Facetnfig --> <!-- Get/Post/Put/Delete Solr FacetConfig -->
<bean id="baseSolrFacetConfigAdminWebscript" abstract="true" parent="webscript"> <bean id="baseSolrFacetConfigAdminWebscript" abstract="true" parent="webscript">
<property name="facetService" ref="solrFacetService"/> <property name="facetService" ref="solrFacetService"/>
</bean> </bean>

View File

@@ -20,9 +20,13 @@
package org.alfresco.repo.web.scripts.solr.facet; package org.alfresco.repo.web.scripts.solr.facet;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; 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.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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.Cache;
@@ -39,10 +43,61 @@ public class SolrFacetConfigAdminPut extends AbstractSolrFacetConfigAdminWebScri
{ {
private static final Log logger = LogFactory.getLog(SolrFacetConfigAdminPost.class); 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 @Override
protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache) protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache)
{ {
final String relativePosString = req.getParameter(PARAM_RELATIVE_POS);
try try
{
if (relativePosString != null)
{
// 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<String, String> 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<SolrFacetProperties> facets = facetService.getFacets();
List<String> facetIDs = CollectionUtils.transform(facets, new Function<SolrFacetProperties, String>()
{
@Override public String apply(SolrFacetProperties value)
{
return value.getFilterID();
}
});
List<String> 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); SolrFacetProperties fp = parseRequestForFacetProperties(req);
facetService.updateFacet(fp); facetService.updateFacet(fp);
@@ -51,7 +106,7 @@ public class SolrFacetConfigAdminPut extends AbstractSolrFacetConfigAdminWebScri
{ {
logger.debug("Updated facet node: " + fp); logger.debug("Updated facet node: " + fp);
} }
}
} }
catch (Throwable t) catch (Throwable t)
{ {