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)
80709: Merged WAT1 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 78667: ACE-1582: Made the facet config service and the relevant web scripts to accept single/multiple value(s) update (to support inline edits). git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@83007 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -19,9 +19,9 @@
|
||||
|
||||
package org.alfresco.repo.web.scripts.solr.facet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -29,7 +29,6 @@ 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;
|
||||
@@ -39,7 +38,6 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
@@ -100,69 +98,7 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
}
|
||||
}
|
||||
|
||||
protected SolrFacetProperties parseRequestForFacetProperties(WebScriptRequest req)
|
||||
{
|
||||
JSONObject json = null;
|
||||
try
|
||||
{
|
||||
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
|
||||
|
||||
final String filterID = json.getString(PARAM_FILTER_ID);
|
||||
final String facetQNameStr = json.getString(PARAM_FACET_QNAME);
|
||||
if (filterID == null || facetQNameStr == null)
|
||||
{
|
||||
String requiredProp = (filterID == null) ? "filterID" : "facetQName";
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, requiredProp + " not provided.");
|
||||
}
|
||||
|
||||
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 = getValue(String.class, json.opt(PARAM_SCOPE), "ALL");
|
||||
final boolean isEnabled = getValue(Boolean.class, json.opt(PARAM_IS_ENABLED), false);
|
||||
JSONArray scopedSitesJsonArray = getValue(JSONArray.class, json.opt(PARAM_SCOPED_SITES), null);
|
||||
Set<String> scopedSites = null;
|
||||
if (scopedSitesJsonArray != null)
|
||||
{
|
||||
scopedSites = new HashSet<String>(scopedSitesJsonArray.length());
|
||||
for (int i = 0, length = scopedSitesJsonArray.length(); i < length; i++)
|
||||
{
|
||||
String site = scopedSitesJsonArray.getString(i);
|
||||
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)
|
||||
.displayName(displayName)
|
||||
.displayControl(displayControl)
|
||||
.maxFilters(maxFilters)
|
||||
.hitThreshold(hitThreshold)
|
||||
.minFilterValueLength(minFilterValueLength)
|
||||
.sortBy(sortBy)
|
||||
.scope(scope)
|
||||
.isEnabled(isEnabled)
|
||||
.scopedSites(scopedSites)
|
||||
.customProperties(customProps).build();
|
||||
return fp;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", e);
|
||||
}
|
||||
catch (JSONException e)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", e);
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T getValue(Class<T> clazz, Object value, T defaultValue) throws JSONException
|
||||
protected <T> T getValue(Class<T> clazz, Object value, T defaultValue) throws JSONException
|
||||
{
|
||||
if (JSONObject.NULL.equals(value))
|
||||
{
|
||||
@@ -179,7 +115,7 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
}
|
||||
}
|
||||
|
||||
private Set<CustomProperties> getCustomProperties(JSONObject customPropsJsonObj) throws JSONException
|
||||
protected Set<CustomProperties> getCustomProperties(JSONObject customPropsJsonObj) throws JSONException
|
||||
{
|
||||
if (customPropsJsonObj == null)
|
||||
{
|
||||
@@ -188,9 +124,9 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
JSONArray keys = customPropsJsonObj.names();
|
||||
if (keys == null)
|
||||
{
|
||||
return null;
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
|
||||
Set<CustomProperties> customProps = new HashSet<>(keys.length());
|
||||
for (int i = 0, length = keys.length(); i < length; i++)
|
||||
{
|
||||
@@ -229,6 +165,22 @@ public abstract class AbstractSolrFacetConfigAdminWebScript extends DeclarativeW
|
||||
return customProps;
|
||||
}
|
||||
|
||||
protected Set<String> getScopedSites(JSONArray scopedSitesJsonArray) throws JSONException
|
||||
{
|
||||
if (scopedSitesJsonArray == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Set<String> scopedSites = new HashSet<String>(scopedSitesJsonArray.length());
|
||||
for (int i = 0, length = scopedSitesJsonArray.length(); i < length; i++)
|
||||
{
|
||||
String site = scopedSitesJsonArray.getString(i);
|
||||
scopedSites.add(site);
|
||||
}
|
||||
return scopedSites;
|
||||
}
|
||||
|
||||
private void validateMandatoryCustomProps(Object obj, String paramName) throws JSONException
|
||||
{
|
||||
if (obj == null)
|
||||
|
@@ -19,12 +19,20 @@
|
||||
|
||||
package org.alfresco.repo.web.scripts.solr.facet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties;
|
||||
import org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties.CustomProperties;
|
||||
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;
|
||||
import org.json.JSONTokener;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
@@ -60,4 +68,53 @@ public class SolrFacetConfigAdminPost extends AbstractSolrFacetConfigAdminWebScr
|
||||
Map<String, Object> model = new HashMap<String, Object>(1);
|
||||
return model;
|
||||
}
|
||||
|
||||
private SolrFacetProperties parseRequestForFacetProperties(WebScriptRequest req)
|
||||
{
|
||||
JSONObject json = null;
|
||||
try
|
||||
{
|
||||
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
|
||||
|
||||
final String filterID = json.getString(PARAM_FILTER_ID);
|
||||
final String facetQNameStr = json.getString(PARAM_FACET_QNAME);
|
||||
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);
|
||||
// Optional params
|
||||
final String scope = getValue(String.class, json.opt(PARAM_SCOPE), "ALL");
|
||||
final boolean isEnabled = getValue(Boolean.class, json.opt(PARAM_IS_ENABLED), false);
|
||||
JSONArray scopedSitesJsonArray = getValue(JSONArray.class, json.opt(PARAM_SCOPED_SITES), null);
|
||||
final Set<String> scopedSites = getScopedSites(scopedSitesJsonArray);
|
||||
final JSONObject customPropJsonObj = getValue(JSONObject.class, json.opt(PARAM_CUSTOM_PROPERTIES), null);
|
||||
final Set<CustomProperties> customProps = getCustomProperties(customPropJsonObj);
|
||||
|
||||
SolrFacetProperties fp = new SolrFacetProperties.Builder()
|
||||
.filterID(filterID)
|
||||
.facetQName(facetQName)
|
||||
.displayName(displayName)
|
||||
.displayControl(displayControl)
|
||||
.maxFilters(maxFilters)
|
||||
.hitThreshold(hitThreshold)
|
||||
.minFilterValueLength(minFilterValueLength)
|
||||
.sortBy(sortBy)
|
||||
.scope(scope)
|
||||
.isEnabled(isEnabled)
|
||||
.scopedSites(scopedSites)
|
||||
.customProperties(customProps).build();
|
||||
return fp;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", e);
|
||||
}
|
||||
catch (JSONException e)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,16 +19,24 @@
|
||||
|
||||
package org.alfresco.repo.web.scripts.solr.facet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.search.impl.solr.facet.Exceptions.UnrecognisedFacetId;
|
||||
import org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties.CustomProperties;
|
||||
import org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
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.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
@@ -47,7 +55,7 @@ public class SolrFacetConfigAdminPut extends AbstractSolrFacetConfigAdminWebScri
|
||||
|
||||
protected static final String PARAM_RELATIVE_POS = "relativePos";
|
||||
protected static final String URL_PARAM_FILTER_ID = "filterID";
|
||||
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
@@ -119,4 +127,52 @@ public class SolrFacetConfigAdminPut extends AbstractSolrFacetConfigAdminWebScri
|
||||
return model;
|
||||
}
|
||||
|
||||
private SolrFacetProperties parseRequestForFacetProperties(WebScriptRequest req)
|
||||
{
|
||||
JSONObject json = null;
|
||||
try
|
||||
{
|
||||
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
|
||||
|
||||
final String filterID = json.getString(PARAM_FILTER_ID); // Must exist
|
||||
|
||||
final String facetQNameStr = getValue(String.class, json.opt(PARAM_FACET_QNAME), null);
|
||||
final QName facetQName = (facetQNameStr == null) ? null : QName.createQName(facetQNameStr);
|
||||
final String displayName = getValue(String.class, json.opt(PARAM_DISPLAY_NAME), null);
|
||||
final String displayControl = getValue(String.class, json.opt(PARAM_DISPLAY_CONTROL), null);
|
||||
final int maxFilters = getValue(Integer.class, json.opt(PARAM_MAX_FILTERS), -1);
|
||||
final int hitThreshold = getValue(Integer.class, json.opt(PARAM_HIT_THRESHOLD), -1);
|
||||
final int minFilterValueLength = getValue(Integer.class, json.opt(PARAM_MIN_FILTER_VALUE_LENGTH), -1);
|
||||
final String sortBy = getValue(String.class, json.opt(PARAM_SORT_BY), null);
|
||||
final String scope = getValue(String.class, json.opt(PARAM_SCOPE), null);
|
||||
final Boolean isEnabled = getValue(Boolean.class, json.opt(PARAM_IS_ENABLED), null);
|
||||
JSONArray scopedSitesJsonArray = getValue(JSONArray.class, json.opt(PARAM_SCOPED_SITES), null);
|
||||
final Set<String> scopedSites = getScopedSites(scopedSitesJsonArray);
|
||||
final JSONObject customPropJsonObj = getValue(JSONObject.class, json.opt(PARAM_CUSTOM_PROPERTIES), null);
|
||||
final Set<CustomProperties> customProps = getCustomProperties(customPropJsonObj);
|
||||
|
||||
SolrFacetProperties fp = new SolrFacetProperties.Builder()
|
||||
.filterID(filterID)
|
||||
.facetQName(facetQName)
|
||||
.displayName(displayName)
|
||||
.displayControl(displayControl)
|
||||
.maxFilters(maxFilters)
|
||||
.hitThreshold(hitThreshold)
|
||||
.minFilterValueLength(minFilterValueLength)
|
||||
.sortBy(sortBy)
|
||||
.scope(scope)
|
||||
.isEnabled(isEnabled)
|
||||
.scopedSites(scopedSites)
|
||||
.customProperties(customProps).build();
|
||||
return fp;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", e);
|
||||
}
|
||||
catch (JSONException e)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user