mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)
80509: Merged WAT1 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 74144: ACE-1582: added: - more facet props to the Model and the related JSON response - GET one facet API - Sorting by facet index git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@82806 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -51,6 +51,7 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
protected static final String PARAM_FILTER_ID = "filterID";
|
||||
protected static final String PARAM_FACET_QNAME = "facetQName";
|
||||
protected static final String PARAM_DISPLAY_NAME = "displayName";
|
||||
protected static final String PARAM_DISPLAY_CONTROL = "displayControl";
|
||||
protected static final String PARAM_MAX_FILTERS = "maxFilters";
|
||||
protected static final String PARAM_HIT_THRESHOLD = "hitThreshold";
|
||||
protected static final String PARAM_MIN_FILTER_VALUE_LENGTH = "minFilterValueLength";
|
||||
@@ -105,13 +106,14 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
|
||||
final QName facetQName = QName.createQName(facetQNameStr);
|
||||
final String displayName = json.getString(PARAM_DISPLAY_NAME);
|
||||
final String displayControl = json.getString(PARAM_DISPLAY_CONTROL);
|
||||
final int maxFilters = json.getInt(PARAM_MAX_FILTERS);
|
||||
final int hitThreshold = json.getInt(PARAM_HIT_THRESHOLD);
|
||||
final int minFilterValueLength = json.getInt(PARAM_MIN_FILTER_VALUE_LENGTH);
|
||||
final String sortBy = json.getString(PARAM_SORT_BY);
|
||||
final String scope = json.getString(PARAM_SCOPE);
|
||||
final int index = json.getInt(PARAM_INDEX);
|
||||
final boolean isEnabled = json.getBoolean(PARAM_IS_ENABLED);
|
||||
final int index = getValue(Integer.class, json.opt(PARAM_INDEX), 0); //FIXME get the index from the service
|
||||
final boolean isEnabled = getValue(Boolean.class, json.opt(PARAM_IS_ENABLED), true);
|
||||
JSONArray scopedSitesJsonArray = json.getJSONArray(PARAM_SCOPED_SITES);
|
||||
Set<String> scopedSites = null;
|
||||
if (scopedSitesJsonArray != null)
|
||||
@@ -128,6 +130,7 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
.filterID(filterID)
|
||||
.facetQName(facetQName)
|
||||
.displayName(displayName)
|
||||
.displayControl(displayControl)
|
||||
.maxFilters(maxFilters)
|
||||
.hitThreshold(hitThreshold)
|
||||
.minFilterValueLength(minFilterValueLength)
|
||||
@@ -148,5 +151,22 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T getValue(Class<T> clazz, Object value, T defaultValue) throws JSONException
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return clazz.cast(value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new JSONException("JSONObject[" + value +"] is not an instance of [" + clazz.getName() +"]");
|
||||
}
|
||||
}
|
||||
|
||||
abstract protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache);
|
||||
}
|
||||
|
@@ -19,7 +19,9 @@
|
||||
|
||||
package org.alfresco.repo.web.scripts.solr.facet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties;
|
||||
@@ -27,6 +29,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
@@ -41,15 +44,30 @@ public class SolrFacetConfigAdminGet extends AbstractSolrFacetConfigAdminWebScri
|
||||
@Override
|
||||
protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
Map<String, SolrFacetProperties> filters = facetService.getFacets();
|
||||
// get the filterID parameter.
|
||||
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||
String filterID = templateVars.get("filterID");
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>(1);
|
||||
|
||||
model.put("filters", filters);
|
||||
if (filterID == null)
|
||||
{
|
||||
List<SolrFacetProperties> filters = new ArrayList<>(facetService.getFacets().values());
|
||||
model.put("filters", filters);
|
||||
}
|
||||
else
|
||||
{
|
||||
SolrFacetProperties fp = facetService.getFacet(filterID);
|
||||
if (fp == null)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Filter not found");
|
||||
}
|
||||
model.put("filter", fp);
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Retrieved all available facets: " + filters);
|
||||
logger.debug("Retrieved all available facets: " + model.values());
|
||||
}
|
||||
|
||||
return model;
|
||||
|
Reference in New Issue
Block a user