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;
}
Aggregations