Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)

84948: Merged PLATFORM1 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud)
      83656: Addition of standard paging to FacetableProperties result sets. Part of ACE-2639.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@85265 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2014-09-20 09:23:46 +00:00
parent bd2fec4451
commit 40eec10e44
4 changed files with 63 additions and 14 deletions

View File

@@ -4,8 +4,8 @@
<![CDATA[ <![CDATA[
Get limited property definition data for properties deemed to be facetable. Get limited property definition data for properties deemed to be facetable.
http://<host>:<port>/alfresco/api/facet/facetable-properties[?nsp=eg] http://<host>:<port>/alfresco/api/facet/facetable-properties[?nsp=eg&skipCount=50&maxItems=10]
http://<host>:<port>/alfresco/api/facet/classes/eg:aspectOrType/facetable-properties http://<host>:<port>/alfresco/api/facet/classes/eg:aspectOrType/facetable-properties[?skipCount=50&maxItems=10]
Example response from this web script: Example response from this web script:
@@ -32,8 +32,8 @@
} }
]]> ]]>
</description> </description>
<url>/api/facet/classes/{classname}/facetable-properties?nsp={namespacePrefix?}</url> <url>/api/facet/classes/{classname}/facetable-properties?nsp={namespacePrefix?}&amp;skipCount={skipCount?}&amp;maxItems={maxItems?}</url>
<url>/api/facet/facetable-properties?nsp={namespacePrefix?}</url> <url>/api/facet/facetable-properties?nsp={namespacePrefix?}&amp;skipCount={skipCount?}&amp;maxItems={maxItems?}</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

@@ -1,3 +1,4 @@
<#import "../generic-paged-results.lib.ftl" as genericPaging />
<#escape x as jsonUtils.encodeJSONString(x)> <#escape x as jsonUtils.encodeJSONString(x)>
{ {
"data" : { "data" : {
@@ -16,5 +17,7 @@
</#list> </#list>
] ]
} }
<@genericPaging.pagingJSON />
} }
</#escape> </#escape>

View File

@@ -250,5 +250,39 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
return typeQName; return typeQName;
} }
/**
* Retrieves the named parameter as an integer, if the parameter is not present the default value is returned.
*
* @param req The WebScript request
* @param paramName The name of parameter to look for.
* @param defaultValue The default value that should be returned if parameter is not present in request or is negative.
* @return The request parameter or default value
* @throws WebScriptException if the named parameter cannot be converted to int (HTTP rsp 400).
*/
protected int getNonNegativeIntParameter(WebScriptRequest req, String paramName, int defaultValue)
{
final String paramString = req.getParameter(paramName);
final int result;
if (paramString != null)
{
try
{
final int paramInt = Integer.valueOf(paramString);
if (paramInt < 0) { result = defaultValue; }
else { result = paramInt; }
}
catch (NumberFormatException e)
{
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
}
}
else { result = defaultValue; }
return result;
}
abstract protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache); abstract protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache);
} }

View File

@@ -24,13 +24,14 @@ import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.SortedSet;
import java.util.TreeSet;
import org.alfresco.repo.search.impl.solr.facet.SolrFacetService.FacetablePropertyData; import org.alfresco.repo.search.impl.solr.facet.SolrFacetService.FacetablePropertyData;
import org.alfresco.service.namespace.NamespaceException; import org.alfresco.service.namespace.NamespaceException;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.ModelUtil;
import org.alfresco.util.ScriptPagingDetails;
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;
@@ -49,6 +50,10 @@ public class FacetablePropertiesGet extends AbstractSolrFacetConfigAdminWebScrip
public static final Log logger = LogFactory.getLog(FacetablePropertiesGet.class); public static final Log logger = LogFactory.getLog(FacetablePropertiesGet.class);
public static final String PROPERTIES_KEY = "properties"; public static final String PROPERTIES_KEY = "properties";
private static final String MAX_ITEMS = "maxItems";
private static final String SKIP_COUNT = "skipCount";
private static final int DEFAULT_MAX_ITEMS_PER_PAGE = 50;
private static final String TEMPLATE_VAR_CLASSNAME = "classname"; private static final String TEMPLATE_VAR_CLASSNAME = "classname";
private static final String QUERY_PARAM_NAMESPACE = "nsp"; private static final String QUERY_PARAM_NAMESPACE = "nsp";
@@ -79,7 +84,7 @@ public class FacetablePropertiesGet extends AbstractSolrFacetConfigAdminWebScrip
final Map<String, Object> model = new HashMap<>(); final Map<String, Object> model = new HashMap<>();
final Set<FacetablePropertyData> facetableProperties; final SortedSet<FacetablePropertyData> facetableProperties;
if (contentClassQName == null) if (contentClassQName == null)
{ {
facetableProperties = facetService.getFacetableProperties(); facetableProperties = facetService.getFacetableProperties();
@@ -107,14 +112,21 @@ public class FacetablePropertiesGet extends AbstractSolrFacetConfigAdminWebScrip
}); });
} }
Set<FacetablePropertyData> filteredFacetableProperties = filter(facetableProperties, filters); List<FacetablePropertyData> filteredFacetableProperties = filter(facetableProperties, filters);
model.put(PROPERTIES_KEY, filteredFacetableProperties);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug("Retrieved " + facetableProperties.size() + " available facets; filtered to " + filteredFacetableProperties.size()); logger.debug("Retrieved " + facetableProperties.size() + " available facets; filtered to " + filteredFacetableProperties.size());
} }
// Create paging
ScriptPagingDetails paging = new ScriptPagingDetails(
getNonNegativeIntParameter(req, MAX_ITEMS, DEFAULT_MAX_ITEMS_PER_PAGE),
getNonNegativeIntParameter(req, SKIP_COUNT, 0));
model.put(PROPERTIES_KEY, ModelUtil.page(filteredFacetableProperties, paging));
model.put("paging", ModelUtil.buildPaging(paging));
return model; return model;
} }
@@ -125,12 +137,12 @@ public class FacetablePropertiesGet extends AbstractSolrFacetConfigAdminWebScrip
} }
/** /**
* This method returns a new Set instance containing only those {@link FacetablePropertyData data} that * This method returns a new List instance containing only those {@link FacetablePropertyData data} that
* satisfy all {@link ResultFilter filters}. * satisfy all {@link ResultFilter filters}.
*/ */
private Set<FacetablePropertyData> filter(Set<FacetablePropertyData> propsData, List<ResultFilter> filters) private List<FacetablePropertyData> filter(Collection<FacetablePropertyData> propsData, List<ResultFilter> filters)
{ {
Set<FacetablePropertyData> filteredResult = new TreeSet<>(); List<FacetablePropertyData> filteredResult = new ArrayList<>();
for (FacetablePropertyData prop : propsData) for (FacetablePropertyData prop : propsData)
{ {