mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
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:
@@ -235,23 +235,32 @@ public class DictionaryRestApiTest extends BaseWebScriptTest
|
|||||||
{
|
{
|
||||||
validatePropertyDef(result.getJSONObject(i));
|
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
|
// 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");
|
req = new GetRequest(URL_PROPERTIES + "?name=cm:name&name=cm:title&name=cm:description");
|
||||||
response = sendRequest(req, 200);
|
response = sendRequest(req, 200);
|
||||||
assertEquals(200, response.getStatus());
|
assertEquals(200, response.getStatus());
|
||||||
result = new JSONArray(response.getContentAsString());
|
result = new JSONArray(response.getContentAsString());
|
||||||
assertEquals(3, result.length());
|
assertEquals(3, result.length());
|
||||||
//for (int i = 0; i < result.length(); i++)
|
// for (int i = 0; i < result.length(); i++)
|
||||||
//{
|
// {
|
||||||
//if(result.getJSONObject(i).get("name").equals("cm:created"))
|
// String title = "";
|
||||||
//{
|
// if (result.getJSONObject(i).has("title") == true)
|
||||||
// validatePropertyDef(result.getJSONObject(i));
|
// {
|
||||||
//}
|
// title = result.getJSONObject(i).getString("title");
|
||||||
// System.out.println(result.getJSONObject(i).get("name"));
|
// }
|
||||||
//}
|
// System.out.println(title + " - " + result.getJSONObject(i).getString("name"));
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -20,13 +20,15 @@ package org.alfresco.repo.web.scripts.dictionary;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||||
import org.alfresco.service.namespace.NamespaceService;
|
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.apache.commons.collections.comparators.ComparatorChain;
|
||||||
import org.springframework.extensions.webscripts.Cache;
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
import org.springframework.extensions.webscripts.Status;
|
import org.springframework.extensions.webscripts.Status;
|
||||||
import org.springframework.extensions.webscripts.WebScriptException;
|
import org.springframework.extensions.webscripts.WebScriptException;
|
||||||
@@ -101,9 +103,11 @@ public class PropertiesGet extends DictionaryWebServiceBase
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Get all the property definitions for the class
|
||||||
propMap = dictionaryservice.getClass(classQName).getProperties();
|
propMap = dictionaryservice.getClass(classQName).getProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filter the properties by URI
|
||||||
List<PropertyDefinition> props = new ArrayList<PropertyDefinition>(propMap.size());
|
List<PropertyDefinition> props = new ArrayList<PropertyDefinition>(propMap.size());
|
||||||
for (Map.Entry<QName, PropertyDefinition> entry : propMap.entrySet())
|
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>();
|
Map<String, Object> model = new HashMap<String, Object>();
|
||||||
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, props);
|
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, props);
|
||||||
return model;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user