diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryRestApiTest.java b/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryRestApiTest.java index 37bae5aa7d..207f5ec8a7 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryRestApiTest.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryRestApiTest.java @@ -235,23 +235,32 @@ public class DictionaryRestApiTest extends BaseWebScriptTest { validatePropertyDef(result.getJSONObject(i)); } - //System.out.println(result.getJSONObject(i).get("name")); + +// String title = ""; +// if (result.getJSONObject(i).has("title") == true) +// { +// title = result.getJSONObject(i).getString("title"); +// } +// System.out.println(title + " - " + result.getJSONObject(i).getString("name")); } +// System.out.println("/n/n"); + // test /api/properties?name=cm:name&name=cm:title&name=cm:description req = new GetRequest(URL_PROPERTIES + "?name=cm:name&name=cm:title&name=cm:description"); response = sendRequest(req, 200); assertEquals(200, response.getStatus()); result = new JSONArray(response.getContentAsString()); assertEquals(3, result.length()); - //for (int i = 0; i < result.length(); i++) - //{ - //if(result.getJSONObject(i).get("name").equals("cm:created")) - //{ - // validatePropertyDef(result.getJSONObject(i)); - //} - // System.out.println(result.getJSONObject(i).get("name")); - //} +// for (int i = 0; i < result.length(); i++) +// { +// String title = ""; +// if (result.getJSONObject(i).has("title") == true) +// { +// title = result.getJSONObject(i).getString("title"); +// } +// System.out.println(title + " - " + result.getJSONObject(i).getString("name")); +// } } diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/PropertiesGet.java b/source/java/org/alfresco/repo/web/scripts/dictionary/PropertiesGet.java index cdb226cfdc..51cac24276 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/PropertiesGet.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/PropertiesGet.java @@ -20,13 +20,15 @@ package org.alfresco.repo.web.scripts.dictionary; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import org.alfresco.service.cmr.dictionary.PropertyDefinition; -import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; +import org.apache.commons.collections.comparators.ComparatorChain; import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptException; @@ -101,9 +103,11 @@ public class PropertiesGet extends DictionaryWebServiceBase } else { + // Get all the property definitions for the class propMap = dictionaryservice.getClass(classQName).getProperties(); } + // Filter the properties by URI List props = new ArrayList(propMap.size()); for (Map.Entry entry : propMap.entrySet()) { @@ -115,10 +119,45 @@ public class PropertiesGet extends DictionaryWebServiceBase } } + // Order property definitions by title + Collections.sort(props, new PropertyDefinitionComparator()); + + // Pass list of property definitions to template Map model = new HashMap(); model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, props); return model; } + + /** + * Property definition comparator. + * + * Used to order property definitions by title. + */ + private class PropertyDefinitionComparator implements Comparator + { + public int compare(PropertyDefinition arg0, PropertyDefinition arg1) + { + int result = 0; + + String title0 = arg0.getTitle(); + String title1 = arg1.getTitle(); + + if (title0 == null && title1 != null) + { + result = 1; + } + else if (title0 != null && title1 == null) + { + result = -1; + } + else if (title0 != null && title1 != null) + { + result = String.CASE_INSENSITIVE_ORDER.compare(arg0.getTitle(), arg1.getTitle()); + } + + return result; + } + } } \ No newline at end of file