Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)

84922: Merged PLATFORM1 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud)
      83457: Refactoring the facetable properties.get response and some of the service API. Part of ACE-2639.
      This checkin changes the JSON structure slightly (array, not map), adds a displayName.
      The localised title and displayName are still in the server locale. I'll fix that to client locale next. Also need to add paging.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@85239 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2014-09-20 09:11:04 +00:00
parent f9dee792a5
commit 2798ba02dd
2 changed files with 74 additions and 18 deletions

View File

@@ -29,7 +29,6 @@ import org.alfresco.repo.search.impl.solr.facet.Exceptions.UnrecognisedFacetId;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
/**
* Solr Facet service configuration API.
@@ -109,17 +108,78 @@ public interface SolrFacetService
/**
* This method offers a convenient access point for getting all Facetable
* content properties defined in the repository.
* @return a collection of facetable {@link PropertyDefinition}s, as follows: Pair<title, propDef>.
* @return a collection of facetable {@link FacetablePropertyData}s.
* @see Facetable
*/
public Set<Pair<String, PropertyDefinition>> getFacetableProperties();
public Set<FacetablePropertyData> getFacetableProperties();
/**
* This method offers a convenient access point for getting all Facetable
* content properties defined on the specified content class (type or aspect).
* @param contentClass the QName of an aspect or type, whose facetable properties are sought.
* @return a collection of facetable {@link PropertyDefinition}s, as follows: Pair<title, propDef>.
* @return a collection of facetable {@link FacetablePropertyData}s.
* @see Facetable
*/
public Set<Pair<String, PropertyDefinition>> getFacetableProperties(QName contentClass);
public Set<FacetablePropertyData> getFacetableProperties(QName contentClass);
/** A simple POJO/DTO intended primarily for use in an FTL model and rendering in the JSON API. */
public static class FacetablePropertyData
{
private final PropertyDefinition propDef;
private final String localisedTitle;
private final String displayName;
public FacetablePropertyData(PropertyDefinition propDef, String localisedTitle)
{
this.propDef = propDef;
this.localisedTitle = localisedTitle;
this.displayName = propDef.getName().getPrefixString() +
(localisedTitle == null ? "" : " (" + localisedTitle + ")");
}
public PropertyDefinition getPropertyDefinition() { return this.propDef; }
public String getLocalisedTitle() { return this.localisedTitle; }
public String getDisplayName() { return this.displayName; }
@Override public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((displayName == null) ? 0 : displayName.hashCode());
result = prime * result + ((localisedTitle == null) ? 0 : localisedTitle.hashCode());
result = prime * result + ((propDef == null) ? 0 : propDef.hashCode());
return result;
}
@Override public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
FacetablePropertyData other = (FacetablePropertyData) obj;
if (displayName == null)
{
if (other.displayName != null)
return false;
} else if (!displayName.equals(other.displayName))
return false;
if (localisedTitle == null)
{
if (other.localisedTitle != null)
return false;
} else if (!localisedTitle.equals(other.localisedTitle))
return false;
if (propDef == null)
{
if (other.propDef != null)
return false;
} else if (!propDef.equals(other.propDef))
return false;
return true;
}
}
}

View File

@@ -66,7 +66,6 @@ import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.alfresco.util.ParameterCheck;
import org.alfresco.util.collections.CollectionUtils;
import org.apache.commons.logging.Log;
@@ -770,9 +769,9 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
}
}
@Override public Set<Pair<String, PropertyDefinition>> getFacetableProperties()
@Override public Set<FacetablePropertyData> getFacetableProperties()
{
final Set<Pair<String, PropertyDefinition>> result = new HashSet<>();
final Set<FacetablePropertyData> result = new HashSet<>();
final List<QName> allContentClasses = CollectionUtils.flatten(dictionaryService.getAllAspects(), dictionaryService.getAllTypes());
@@ -784,9 +783,9 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
return result;
}
@Override public Set<Pair<String, PropertyDefinition>> getFacetableProperties(QName contentClass)
@Override public Set<FacetablePropertyData> getFacetableProperties(QName contentClass)
{
final Set<Pair<String, PropertyDefinition>> result = new HashSet<>();
final Set<FacetablePropertyData> result = new HashSet<>();
final Map<QName, PropertyDefinition> propertyDefs = dictionaryService.getPropertyDefs(contentClass);
@@ -799,7 +798,7 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
switch (propIsFacetable)
{
case TRUE:
result.add(toTitledPropDef(prop.getValue()));
result.add(toFacetablePropertyData(prop.getValue()));
break;
case FALSE:
// The value is not facetable. Do nothing.
@@ -809,7 +808,7 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
final DataTypeDefinition datatype = prop.getValue().getDataType();
if (isNumeric(datatype) || isDateLike(datatype) || isFacetableText(datatype))
{
result.add(toTitledPropDef(prop.getValue()));
result.add(toFacetablePropertyData(prop.getValue()));
break;
}
break;
@@ -823,14 +822,11 @@ public class SolrFacetServiceImpl extends AbstractLifecycleBean implements SolrF
return result;
}
/**
* This method returns a {@link Pair} of the user-displayable property title (if available)
* and the {@link PropertyDefinition} itself.
*/
private Pair<String, PropertyDefinition> toTitledPropDef(PropertyDefinition propDef)
/** This method returns a {@link FacetablePropertyData} for the specified {@link PropertyDefinition}. */
private FacetablePropertyData toFacetablePropertyData(PropertyDefinition propDef)
{
String title = propDef.getTitle(dictionaryService);
return new Pair<>(title, propDef);
return new FacetablePropertyData(propDef, title);
}
// TODO Consider moving into dictionary code.