Search in sources :

Example 1 with CustomProperties

use of org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties.CustomProperties in project alfresco-remote-api by Alfresco.

the class AbstractSolrFacetConfigAdminWebScript method getCustomProperties.

protected Set<CustomProperties> getCustomProperties(JSONObject customPropsJsonObj) throws JSONException {
    if (customPropsJsonObj == null) {
        return null;
    }
    JSONArray keys = customPropsJsonObj.names();
    if (keys == null) {
        return Collections.emptySet();
    }
    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;
}
Also used : Serializable(java.io.Serializable) JSONObject(org.json.JSONObject) QName(org.alfresco.service.namespace.QName) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject) CustomProperties(org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties.CustomProperties) HashSet(java.util.HashSet)

Example 2 with CustomProperties

use of org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties.CustomProperties in project alfresco-remote-api by Alfresco.

the class SolrFacetConfigAdminPut method parseRequestForFacetProperties.

private SolrFacetProperties parseRequestForFacetProperties(WebScriptRequest req) {
    JSONObject json = null;
    try {
        json = new JSONObject(new JSONTokener(req.getContent().getContent()));
        // Must exist
        final String filterID = json.getString(PARAM_FILTER_ID);
        final String facetQNameStr = getValue(String.class, json.opt(PARAM_FACET_QNAME), null);
        // Note that in resolving the QName string here, we expect there to be some facet QNames which are not
        // really QNames. These are SOLR/SearchService 'specials', examples being "SITE" or "TAG".
        // These will be resolved here to a QName with no namespace.
        final QName facetQName = (facetQNameStr == null) ? null : FacetQNameUtils.createQName(facetQNameStr, namespaceService);
        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);
    }
}
Also used : QName(org.alfresco.service.namespace.QName) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IOException(java.io.IOException) SolrFacetProperties(org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties) JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) CustomProperties(org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties.CustomProperties)

Example 3 with CustomProperties

use of org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties.CustomProperties in project alfresco-remote-api by Alfresco.

the class SolrFacetConfigAdminPost method parseRequestForFacetProperties.

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);
        validateFilterID(filterID);
        final String facetQNameStr = json.getString(PARAM_FACET_QNAME);
        // Note: we're using this util class here because we need to be able to deal with
        // qnames without a URI e.g. "{}SITE" and *not* have them default to the cm: namespace
        // which happens with the 'normal' Alfresco QName code.
        final QName facetQName = FacetQNameUtils.createQName(facetQNameStr, namespaceService);
        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);
    }
}
Also used : QName(org.alfresco.service.namespace.QName) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IOException(java.io.IOException) SolrFacetProperties(org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties) JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) CustomProperties(org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties.CustomProperties)

Aggregations

CustomProperties (org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties.CustomProperties)3 QName (org.alfresco.service.namespace.QName)3 JSONArray (org.json.JSONArray)3 JSONObject (org.json.JSONObject)3 IOException (java.io.IOException)2 SolrFacetProperties (org.alfresco.repo.search.impl.solr.facet.SolrFacetProperties)2 JSONException (org.json.JSONException)2 JSONTokener (org.json.JSONTokener)2 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1