mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)
85028: Merged PLATFORM1 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 84196: Addition of what I'm calling 'synthetic' facetable properties to SolrFacetService and REST API as part of ACE-2639. A synthetic property is something that is technically *NOT* a property, but which can be treated as such for the purposes of SOLR facetting/filtering. Currently we only support two synthetic properties: size and mimetype, which are defined within any Alfresco property of type d:content. This includes, but is not limited to, the cm:content property in all cm:content types in Alfresco. (Be careful with your cm:content. That name is heavily overloaded.) This checkin only supports what we need for 5.0. It is expressly not designed for resuse/extension in a general way. However, I have tried to push the less stable parts of this work into the implementation of the service and REST API and limit what's in the service interface to the more stable parts of the work. Also note that I had to add some l10n/i18n key-values for these synthetic properties. I've called the mimetype 'MIME type' in the l10n'd text as I have translations for that in all languages. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@85343 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -38,7 +38,6 @@ import org.alfresco.service.namespace.QName;
|
||||
*/
|
||||
public interface SolrFacetService
|
||||
{
|
||||
|
||||
/**
|
||||
* Gets all the available facets.
|
||||
*
|
||||
@@ -117,9 +116,42 @@ public interface SolrFacetService
|
||||
* This method offers a convenient access point for getting all Facetable
|
||||
* content properties defined on the specified content class (type or aspect) or any of its inherited properties.
|
||||
* @param contentClass the QName of an aspect or type, whose facetable properties are sought.
|
||||
* @param includeInheritedProperties {@code true} to include properties defined on supertypes.
|
||||
* @return a collection of facetable {@link PropertyDefinition}s.
|
||||
* @see Facetable
|
||||
*/
|
||||
public List<PropertyDefinition> getFacetableProperties(QName contentClass);
|
||||
|
||||
/**
|
||||
* This method gets all synthetic, facetable properties across all content models in the repository.
|
||||
*/
|
||||
public List<SyntheticPropertyDefinition> getFacetableSyntheticProperties();
|
||||
|
||||
/**
|
||||
* This method gets all synthetic, facetable properties defined on the specified content class (type or aspect) or any of its inherited properties.
|
||||
* @param contentClass the QName of an aspect or type, whose synthetic, facetable properties are sought.
|
||||
*/
|
||||
public List<SyntheticPropertyDefinition> getFacetableSyntheticProperties(QName contentClass);
|
||||
|
||||
/**
|
||||
* This class represents a special case of a property, examples being file size and MIME type, which
|
||||
* are not modelled as Alfresco content model properties, but are instead stored as components
|
||||
* within properties of type {@code cm:content}.
|
||||
*/
|
||||
public class SyntheticPropertyDefinition
|
||||
{
|
||||
public final PropertyDefinition containingPropertyDef;
|
||||
public final String syntheticPropertyName;
|
||||
public final QName dataTypeDefinition;
|
||||
|
||||
public SyntheticPropertyDefinition(PropertyDefinition containingPropertyDef, String syntheticPropertyName,
|
||||
QName syntheticDataTypeDefinition)
|
||||
{
|
||||
this.containingPropertyDef = containingPropertyDef;
|
||||
this.syntheticPropertyName = syntheticPropertyName;
|
||||
this.dataTypeDefinition = syntheticDataTypeDefinition;
|
||||
}
|
||||
|
||||
@Override public String toString() { return SyntheticPropertyDefinition.class.getSimpleName() +
|
||||
"[" + this.syntheticPropertyName + "]"; }
|
||||
}
|
||||
}
|
||||
|
@@ -791,24 +791,25 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
|
||||
|
||||
if (propertyDefs != null)
|
||||
{
|
||||
for (Map.Entry<QName, PropertyDefinition> prop : propertyDefs.entrySet())
|
||||
for (final Map.Entry<QName, PropertyDefinition> prop : propertyDefs.entrySet())
|
||||
{
|
||||
final Facetable propIsFacetable = prop.getValue().getFacetable();
|
||||
final PropertyDefinition propDef = prop.getValue();
|
||||
final Facetable propIsFacetable = propDef.getFacetable();
|
||||
|
||||
switch (propIsFacetable)
|
||||
{
|
||||
case TRUE:
|
||||
result.add(prop.getValue());
|
||||
result.add(propDef);
|
||||
break;
|
||||
case FALSE:
|
||||
// The value is not facetable. Do nothing.
|
||||
break;
|
||||
case UNSET:
|
||||
// These values may be facetable.
|
||||
final DataTypeDefinition datatype = prop.getValue().getDataType();
|
||||
final DataTypeDefinition datatype = propDef.getDataType();
|
||||
if (isNumeric(datatype) || isDateLike(datatype) || isFacetableText(datatype))
|
||||
{
|
||||
result.add(prop.getValue());
|
||||
result.add(propDef);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -822,7 +823,54 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
|
||||
return result;
|
||||
}
|
||||
|
||||
// TODO Consider moving into dictionary code.
|
||||
@Override public List<SyntheticPropertyDefinition> getFacetableSyntheticProperties()
|
||||
{
|
||||
final List<SyntheticPropertyDefinition> result = new ArrayList<>();
|
||||
|
||||
final List<QName> allContentClasses = CollectionUtils.flatten(dictionaryService.getAllAspects(), dictionaryService.getAllTypes());
|
||||
|
||||
for (QName contentClass : allContentClasses)
|
||||
{
|
||||
result.addAll(getFacetableSyntheticProperties(contentClass));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override public List<SyntheticPropertyDefinition> getFacetableSyntheticProperties(QName contentClass)
|
||||
{
|
||||
final List<SyntheticPropertyDefinition> result = new ArrayList<>();
|
||||
|
||||
final Map<QName, PropertyDefinition> propertyDefs = dictionaryService.getPropertyDefs(contentClass);
|
||||
|
||||
if (propertyDefs != null)
|
||||
{
|
||||
for (final Map.Entry<QName, PropertyDefinition> prop : propertyDefs.entrySet())
|
||||
{
|
||||
final PropertyDefinition propDef = prop.getValue();
|
||||
|
||||
// Only properties of type cm:content can expand to synthetic properties.
|
||||
if (DataTypeDefinition.CONTENT.equals(propDef.getDataType().getName()))
|
||||
{
|
||||
// We do not want to treat the cm:content property itself as facetable.
|
||||
// It is a content URL whose value is not suitable for facetting.
|
||||
// e.g. 2010/1/22/13/14/6e228904-d5d2-4a99-b7b1-8fe7c03c71f3.bin|mimetype=application/octet-stream|size=728|encoding=UTF-8|locale=en_GB_
|
||||
//
|
||||
// However there are elements within that content URL which *are* facetable and are correctly treated as such by SOLR.
|
||||
// As these are not actually Alfresco content properties, we must return artificial PropertyDefinition objects:
|
||||
result.add(new SyntheticPropertyDefinition(propDef, "size", DataTypeDefinition.LONG));
|
||||
result.add(new SyntheticPropertyDefinition(propDef, "mimetype", DataTypeDefinition.TEXT));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Intentionally empty. Only cm:content's size and mimetype are currently supported.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isNumeric(DataTypeDefinition datatype)
|
||||
{
|
||||
boolean result;
|
||||
|
Reference in New Issue
Block a user