Results from api/properties now ordered alphabetically by title.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19044 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2010-03-03 22:41:38 +00:00
parent 9cc0148e8c
commit 79ed296131
2 changed files with 58 additions and 10 deletions

View File

@@ -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"));
// }
}

View File

@@ -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<PropertyDefinition> props = new ArrayList<PropertyDefinition>(propMap.size());
for (Map.Entry<QName, PropertyDefinition> 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<String, Object> model = new HashMap<String, Object>();
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<PropertyDefinition>
{
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;
}
}
}