From e2382dbb4209de80b67eb95fe541abb28811d7f1 Mon Sep 17 00:00:00 2001 From: Mark Rogers Date: Sat, 20 Sep 2014 09:24:45 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud) 84950: Merged PLATFORM1 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 83670: Moved the FacetablePropertyData inner class from SolrFacetService (Java API layer) into FacetablePropertiesGet (REST API layer) as that is a better place for it. ACE-2639. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@85267 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../web-scripts-application-context.xml | 1 + .../scripts/facet/FacetablePropertiesGet.java | 98 ++++++++++++++++++- 2 files changed, 94 insertions(+), 5 deletions(-) diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index 5d75a1ff3d..19358905b8 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1825,6 +1825,7 @@ id="webscript.org.alfresco.repository.facet.facetable-properties.get" class="org.alfresco.repo.web.scripts.facet.FacetablePropertiesGet" parent="baseSolrFacetConfigAdminWebscript"> + executeImpl(final WebScriptRequest req, final Status status, final Cache cache) { @@ -87,11 +91,11 @@ public class FacetablePropertiesGet extends AbstractSolrFacetConfigAdminWebScrip final SortedSet facetableProperties; if (contentClassQName == null) { - facetableProperties = facetService.getFacetableProperties(); + facetableProperties = toFacetablePropertyDataSet(facetService.getFacetableProperties()); } else { - facetableProperties = facetService.getFacetableProperties(contentClassQName); + facetableProperties = toFacetablePropertyDataSet(facetService.getFacetableProperties(contentClassQName)); } // The webscript allows for some further filtering of results: @@ -156,4 +160,88 @@ public class FacetablePropertiesGet extends AbstractSolrFacetConfigAdminWebScrip return filteredResult; } + + /** This method returns a {@link FacetablePropertyData} for the specified {@link PropertyDefinition}. */ + private FacetablePropertyData toFacetablePropertyData(PropertyDefinition propDef) + { + String title = propDef.getTitle(dictionaryService); + return new FacetablePropertyData(propDef, title); + } + + private SortedSet toFacetablePropertyDataSet(Collection propDefs) + { + SortedSet result = new TreeSet<>(); + for (PropertyDefinition propDef : propDefs) + { + result.add(toFacetablePropertyData(propDef)); + } + return result; + } + + /** A simple POJO/DTO intended primarily for use in an FTL model and rendering in the JSON API. */ + public static class FacetablePropertyData implements Comparable + { + 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; + } + + @Override public int compareTo(FacetablePropertyData that) + { + final int modelComparison = this.propDef.getModel().getName().compareTo(that.propDef.getModel().getName()); + return modelComparison != 0 ? modelComparison : + this.propDef.getName().compareTo(that.propDef.getName()); + } + } }