mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Added /api/properties webscript
- Can call /api/properties to get all properties in dictionary, filterable by namespace - Can call with names of required properties, for example /api/properties?name=cm:name&name=cm:title&cm:description - Unit test updated git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18968 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -35,6 +35,7 @@ import org.json.JSONArray;
|
||||
public class DictionaryRestApiTest extends BaseWebScriptTest
|
||||
{
|
||||
private static final String URL_SITES = "/api/classes";
|
||||
private static final String URL_PROPERTIES = "/api/properties";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
@@ -60,7 +61,7 @@ public class DictionaryRestApiTest extends BaseWebScriptTest
|
||||
assertEquals(true, result.get("protected"));
|
||||
assertEquals(true, result.get("indexed"));
|
||||
assertEquals(true, result.get("indexedAtomically"));
|
||||
assertEquals("/api/classes/cm_auditable/property/cm_created", result.get("url"));
|
||||
assertEquals("/api/property/cm_created", result.get("url"));
|
||||
|
||||
}
|
||||
|
||||
@@ -200,14 +201,10 @@ public class DictionaryRestApiTest extends BaseWebScriptTest
|
||||
GetRequest req = new GetRequest(URL_SITES + "/cm_auditable/properties");
|
||||
Map< String, String > arguments = new HashMap< String, String >();
|
||||
arguments.put("nsp", "cm");
|
||||
arguments.put("n", "created");
|
||||
req.setArgs(arguments);
|
||||
Response response = sendRequest(req, 200);
|
||||
assertEquals(200,response.getStatus());
|
||||
|
||||
//JSONObject resultSet = new JSONObject(response.getContentAsString());
|
||||
//validatePropertyDef(resultSet);
|
||||
|
||||
JSONArray result = new JSONArray(response.getContentAsString());
|
||||
assertEquals(200,response.getStatus());
|
||||
assertEquals(5, result.length());
|
||||
@@ -226,6 +223,37 @@ public class DictionaryRestApiTest extends BaseWebScriptTest
|
||||
}
|
||||
}
|
||||
|
||||
// test /api/properties
|
||||
req = new GetRequest(URL_PROPERTIES);
|
||||
response = sendRequest(req, 200);
|
||||
assertEquals(200, response.getStatus());
|
||||
result = new JSONArray(response.getContentAsString());
|
||||
assertEquals(result.length()>0, true);
|
||||
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"));
|
||||
}
|
||||
|
||||
// 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"));
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void testGetClassDetail() throws Exception
|
||||
|
@@ -19,11 +19,13 @@
|
||||
package org.alfresco.repo.web.scripts.dictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
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.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
@@ -41,36 +43,67 @@ public class PropertiesGet extends DictionaryWebServiceBase
|
||||
{
|
||||
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
|
||||
private static final String DICTIONARY_CLASS_NAME = "classname";
|
||||
private static final String PARAM_NAME = "name";
|
||||
private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp";
|
||||
|
||||
|
||||
/**
|
||||
* @Override method from DeclarativeWebScript
|
||||
*/
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
QName classQName = null;
|
||||
String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
|
||||
if (className == null || className.length() == 0)
|
||||
{
|
||||
// Error
|
||||
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + className + " - parameter in the URL");
|
||||
|
||||
}
|
||||
QName classQName = createClassQName(className);
|
||||
if (classQName == null)
|
||||
{
|
||||
// Error
|
||||
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + className + " - parameter in the URL");
|
||||
if (className != null && className.length() != 0)
|
||||
{
|
||||
classQName = createClassQName(className);
|
||||
if (classQName == null)
|
||||
{
|
||||
// Error
|
||||
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + className + " - parameter in the URL");
|
||||
}
|
||||
}
|
||||
|
||||
String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
|
||||
String[] names = req.getParameterValues(PARAM_NAME);
|
||||
|
||||
String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
|
||||
String namespaceURI = null;
|
||||
if (namespacePrefix != null)
|
||||
{
|
||||
namespaceURI = this.namespaceService.getNamespaceURI(namespacePrefix);
|
||||
}
|
||||
|
||||
Map<QName, PropertyDefinition> propMap = dictionaryservice.getClass(classQName).getProperties();
|
||||
Map<QName, PropertyDefinition> propMap = null;
|
||||
if (classQName == null)
|
||||
{
|
||||
if (names != null)
|
||||
{
|
||||
propMap = new HashMap<QName, PropertyDefinition>(names.length);
|
||||
for (String name : names)
|
||||
{
|
||||
QName propQName = QName.createQName(name, namespaceService);
|
||||
PropertyDefinition propDef = dictionaryservice.getProperty(propQName);
|
||||
if (propDef != null)
|
||||
{
|
||||
propMap.put(propQName, propDef);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Collection<QName> propQNames = dictionaryservice.getAllProperties(null);
|
||||
propMap = new HashMap<QName, PropertyDefinition>(propQNames.size());
|
||||
for (QName propQName : propQNames)
|
||||
{
|
||||
propMap.put(propQName, dictionaryservice.getProperty(propQName));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
propMap = dictionaryservice.getClass(classQName).getProperties();
|
||||
}
|
||||
|
||||
List<PropertyDefinition> props = new ArrayList<PropertyDefinition>(propMap.size());
|
||||
for (Map.Entry<QName, PropertyDefinition> entry : propMap.entrySet())
|
||||
{
|
||||
|
Reference in New Issue
Block a user