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)
80698: Merged WAT1 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 78457: ACE-1582: - Fixed facet's custom properties. - Made the GET facets web-script to be accessed by all authenticated users rather than just the Search-Admin/Network-Admin users. - Fixed FacetRestApiTests and added more tests. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@82996 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -20,16 +20,22 @@
|
||||
package org.alfresco.repo.web.scripts.solr.facet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.repo.search.impl.solr.facet.SolrFacetModel;
|
||||
import org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties;
|
||||
import org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties.CustomProperties;
|
||||
import org.alfresco.repo.search.impl.solr.facet.SolrFacetService;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -48,6 +54,8 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
*/
|
||||
public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeWebScript
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(AbstractSolrFacetConfigAdminWebScript.class);
|
||||
|
||||
protected static final String PARAM_FILTER_ID = "filterID";
|
||||
protected static final String PARAM_FACET_QNAME = "facetQName";
|
||||
protected static final String PARAM_DISPLAY_NAME = "displayName";
|
||||
@@ -60,6 +68,9 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
protected static final String PARAM_SCOPED_SITES = "scopedSites";
|
||||
protected static final String PARAM_INDEX = "index";
|
||||
protected static final String PARAM_IS_ENABLED = "isEnabled";
|
||||
protected static final String PARAM_CUSTOM_PROPERTIES = "customProperties";
|
||||
protected static final String CUSTOM_PARAM_NAME = "name";
|
||||
protected static final String CUSTOM_PARAM_VALUE = "value";
|
||||
|
||||
protected SolrFacetService facetService;
|
||||
|
||||
@@ -124,7 +135,8 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
scopedSites.add(site);
|
||||
}
|
||||
}
|
||||
|
||||
final JSONObject customPropJsonObj = getValue(JSONObject.class, json.opt(PARAM_CUSTOM_PROPERTIES), null);
|
||||
Set<CustomProperties> customProps = getCustomProperties(customPropJsonObj);
|
||||
SolrFacetProperties fp = new SolrFacetProperties.Builder()
|
||||
.filterID(filterID)
|
||||
.facetQName(facetQName)
|
||||
@@ -136,7 +148,8 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
.sortBy(sortBy)
|
||||
.scope(scope)
|
||||
.isEnabled(isEnabled)
|
||||
.scopedSites(scopedSites).build();
|
||||
.scopedSites(scopedSites)
|
||||
.customProperties(customProps).build();
|
||||
return fp;
|
||||
}
|
||||
catch (IOException e)
|
||||
@@ -151,7 +164,7 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
|
||||
private <T> T getValue(Class<T> clazz, Object value, T defaultValue) throws JSONException
|
||||
{
|
||||
if (value == null)
|
||||
if (JSONObject.NULL.equals(value))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -166,5 +179,99 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
}
|
||||
}
|
||||
|
||||
private Set<CustomProperties> getCustomProperties(JSONObject customPropsJsonObj) throws JSONException
|
||||
{
|
||||
if (customPropsJsonObj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
JSONArray keys = customPropsJsonObj.names();
|
||||
if (keys == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Set<CustomProperties> customProps = new HashSet<>(keys.length());
|
||||
for (int i = 0, length = keys.length(); i < length; i++)
|
||||
{
|
||||
JSONObject jsonObj = customPropsJsonObj.getJSONObject((String) keys.get(i));
|
||||
|
||||
QName name = resolveToQName(getValue(String.class, jsonObj.opt(CUSTOM_PARAM_NAME), null));
|
||||
validateMandatoryCustomProps(name, CUSTOM_PARAM_NAME);
|
||||
|
||||
Serializable value = null;
|
||||
Object customPropValue = jsonObj.opt(CUSTOM_PARAM_VALUE);
|
||||
validateMandatoryCustomProps(customPropValue, CUSTOM_PARAM_VALUE);
|
||||
|
||||
if(customPropValue instanceof JSONArray)
|
||||
{
|
||||
JSONArray array = (JSONArray) customPropValue;
|
||||
ArrayList<Serializable> list = new ArrayList<>(array.length());
|
||||
for(int j = 0; j < array.length(); j++)
|
||||
{
|
||||
list.add(getSerializableValue(array.get(j)));
|
||||
}
|
||||
value = list;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = getSerializableValue(customPropValue);
|
||||
}
|
||||
|
||||
customProps.add(new CustomProperties(name, value));
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled() && customProps.size() > 0)
|
||||
{
|
||||
logger.debug("Processed custom properties:" + customProps);
|
||||
}
|
||||
|
||||
return customProps;
|
||||
}
|
||||
|
||||
private void validateMandatoryCustomProps(Object obj, String paramName) throws JSONException
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
throw new JSONException("Invalid JSONObject in the Custom Properties JSON. [" + paramName + "] cannot be null.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Serializable getSerializableValue(Object object) throws JSONException
|
||||
{
|
||||
if (!(object instanceof Serializable))
|
||||
{
|
||||
throw new JSONException("Invalid value in the Custom Properties JSON. [" + object + "] must be an instance of Serializable.");
|
||||
}
|
||||
return (Serializable) object;
|
||||
}
|
||||
|
||||
private QName resolveToQName(String qnameStr) throws JSONException
|
||||
{
|
||||
QName typeQName = null;
|
||||
if (qnameStr == null)
|
||||
{
|
||||
return typeQName;
|
||||
}
|
||||
if(qnameStr.charAt(0) == QName.NAMESPACE_BEGIN && qnameStr.indexOf("solrfacetcustomproperty") < 0)
|
||||
{
|
||||
throw new JSONException("Invalid name in the Custom Properties JSON. Namespace URL must be [" + SolrFacetModel.SOLR_FACET_CUSTOM_PROPERTY_URL + "]");
|
||||
}
|
||||
else if(qnameStr.charAt(0) == QName.NAMESPACE_BEGIN)
|
||||
{
|
||||
typeQName = QName.createQName(qnameStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
typeQName = QName.createQName(SolrFacetModel.SOLR_FACET_CUSTOM_PROPERTY_URL, qnameStr);
|
||||
}
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Resolved facet's custom property name [" + qnameStr + "] into [" + typeQName + "]");System.out.println("QQQQQQQQQQQQQQQQQQQQQQQQQQQQQ:Resolved facet's custom property name [" + qnameStr + "] into [" + typeQName + "]");
|
||||
}
|
||||
return typeQName;
|
||||
}
|
||||
|
||||
abstract protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache);
|
||||
}
|
||||
|
@@ -39,6 +39,13 @@ public class SolrFacetConfigAdminGet extends AbstractSolrFacetConfigAdminWebScri
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(SolrFacetConfigAdminGet.class);
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(final WebScriptRequest req, final Status status, final Cache cache)
|
||||
{
|
||||
// Allow all authenticated users view the filters
|
||||
return unprotectedExecuteImpl(req, status, cache);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
|
Reference in New Issue
Block a user