Search in sources :

Example 1 with SyntheticPropertyDefinition

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

the class FacetablePropertiesGet method unprotectedExecuteImpl.

@Override
protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache) {
    // We use any provided locale to localise some elements of the webscript response, but not all.
    final String userLocaleString = req.getParameter(QUERY_PARAM_LOCALE);
    final Locale userLocale = (userLocaleString == null) ? Locale.getDefault() : new Locale(userLocaleString);
    // There are multiple defined URIs for this REST endpoint. Some define a "classname" template var.
    final Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    final String contentClassName = templateVars.get(TEMPLATE_VAR_CLASSNAME);
    final QName contentClassQName;
    try {
        contentClassQName = contentClassName == null ? null : QName.createQName(contentClassName, namespaceService);
    } catch (NamespaceException e) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Unrecognised classname: " + contentClassName, e);
    }
    // Build an FTL model of facetable properties - this includes normal Alfresco properties and also
    // 'synthetic' properties like size and mimetype. See below for more details.
    final Map<String, Object> model = new HashMap<>();
    final SortedSet<FacetablePropertyFTL<?>> facetableProperties;
    if (contentClassQName == null) {
        facetableProperties = toFacetablePropertyModel(facetService.getFacetableProperties(), userLocale);
        final List<SyntheticPropertyDefinition> facetableSyntheticProperties = facetService.getFacetableSyntheticProperties();
        facetableProperties.addAll(toFacetablePropertyModel_(facetableSyntheticProperties, userLocale));
    } else {
        facetableProperties = toFacetablePropertyModel(facetService.getFacetableProperties(contentClassQName), userLocale);
        final List<SyntheticPropertyDefinition> facetableSyntheticProperties = facetService.getFacetableSyntheticProperties(contentClassQName);
        facetableProperties.addAll(toFacetablePropertyModel_(facetableSyntheticProperties, userLocale));
    }
    // Always add some hard-coded facetable "properties"
    // Note: TAG and SITE are Solr specials and don’t have namespaces
    facetableProperties.add(new SpecialFacetablePropertyFTL("TAG", "Tag"));
    facetableProperties.add(new SpecialFacetablePropertyFTL("SITE", "Site"));
    // The webscript allows for some further filtering of results:
    List<ResultFilter> filters = new ArrayList<>();
    // Filter by property QName namespace:
    final String namespaceFilter = req.getParameter(QUERY_PARAM_NAMESPACE);
    if (namespaceFilter != null) {
        filters.add(new ResultFilter() {

            @Override
            public boolean filter(FacetablePropertyFTL<?> facetableProperty) {
                final QName propQName = facetableProperty.getQname();
                Collection<String> prefixes = namespaceService.getPrefixes(propQName.getNamespaceURI());
                return prefixes.contains(namespaceFilter);
            }
        });
    }
    List<FacetablePropertyFTL<?>> filteredFacetableProperties = filter(facetableProperties, filters);
    if (logger.isDebugEnabled()) {
        logger.debug("Retrieved " + facetableProperties.size() + " available facets; filtered to " + filteredFacetableProperties.size());
    }
    // Create paging
    ScriptPagingDetails paging = new ScriptPagingDetails(getNonNegativeIntParameter(req, QUERY_PARAM_MAX_ITEMS, DEFAULT_MAX_ITEMS_PER_PAGE), getNonNegativeIntParameter(req, QUERY_PARAM_SKIP_COUNT, 0));
    model.put(PROPERTIES_KEY, ModelUtil.page(filteredFacetableProperties, paging));
    model.put("paging", ModelUtil.buildPaging(paging));
    return model;
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) SpecialFacetablePropertyFTL(org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.SpecialFacetablePropertyFTL) StandardFacetablePropertyFTL(org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.StandardFacetablePropertyFTL) SyntheticFacetablePropertyFTL(org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.SyntheticFacetablePropertyFTL) SpecialFacetablePropertyFTL(org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.SpecialFacetablePropertyFTL) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) SyntheticPropertyDefinition(org.alfresco.repo.search.impl.solr.facet.SolrFacetService.SyntheticPropertyDefinition) NamespaceException(org.alfresco.service.namespace.NamespaceException) Collection(java.util.Collection) ScriptPagingDetails(org.alfresco.util.ScriptPagingDetails)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 SyntheticPropertyDefinition (org.alfresco.repo.search.impl.solr.facet.SolrFacetService.SyntheticPropertyDefinition)1 SpecialFacetablePropertyFTL (org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.SpecialFacetablePropertyFTL)1 StandardFacetablePropertyFTL (org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.StandardFacetablePropertyFTL)1 SyntheticFacetablePropertyFTL (org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.SyntheticFacetablePropertyFTL)1 NamespaceException (org.alfresco.service.namespace.NamespaceException)1 QName (org.alfresco.service.namespace.QName)1 ScriptPagingDetails (org.alfresco.util.ScriptPagingDetails)1 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)1