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:
@@ -2,6 +2,7 @@
|
|||||||
<shortname>Get Property Definitions</shortname>
|
<shortname>Get Property Definitions</shortname>
|
||||||
<description>Get the collection of property definitions</description>
|
<description>Get the collection of property definitions</description>
|
||||||
<url>/api/classes/{classname}/properties?nsp={namespacePrefix?}&n={name?}</url>
|
<url>/api/classes/{classname}/properties?nsp={namespacePrefix?}&n={name?}</url>
|
||||||
|
<url>/api/properties?nsp={namespacePrefix?}&n={name?}</url>
|
||||||
<format default="json">argument</format>
|
<format default="json">argument</format>
|
||||||
<authentication>user</authentication>
|
<authentication>user</authentication>
|
||||||
<transaction allow="readonly">required</transaction>
|
<transaction allow="readonly">required</transaction>
|
||||||
|
@@ -40,7 +40,7 @@
|
|||||||
</#list>
|
</#list>
|
||||||
</#if>-->
|
</#if>-->
|
||||||
],
|
],
|
||||||
"url" : "${"/api/classes/" + url.templateArgs.classname + "/property/" + propertydefs.name.toPrefixString()?replace(":","_")}"
|
"url" : "${"/api/property/" + propertydefs.name.toPrefixString()?replace(":","_")}"
|
||||||
}
|
}
|
||||||
</#escape>
|
</#escape>
|
||||||
</#macro>
|
</#macro>
|
@@ -35,6 +35,7 @@ import org.json.JSONArray;
|
|||||||
public class DictionaryRestApiTest extends BaseWebScriptTest
|
public class DictionaryRestApiTest extends BaseWebScriptTest
|
||||||
{
|
{
|
||||||
private static final String URL_SITES = "/api/classes";
|
private static final String URL_SITES = "/api/classes";
|
||||||
|
private static final String URL_PROPERTIES = "/api/properties";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception
|
protected void setUp() throws Exception
|
||||||
@@ -60,7 +61,7 @@ public class DictionaryRestApiTest extends BaseWebScriptTest
|
|||||||
assertEquals(true, result.get("protected"));
|
assertEquals(true, result.get("protected"));
|
||||||
assertEquals(true, result.get("indexed"));
|
assertEquals(true, result.get("indexed"));
|
||||||
assertEquals(true, result.get("indexedAtomically"));
|
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");
|
GetRequest req = new GetRequest(URL_SITES + "/cm_auditable/properties");
|
||||||
Map< String, String > arguments = new HashMap< String, String >();
|
Map< String, String > arguments = new HashMap< String, String >();
|
||||||
arguments.put("nsp", "cm");
|
arguments.put("nsp", "cm");
|
||||||
arguments.put("n", "created");
|
|
||||||
req.setArgs(arguments);
|
req.setArgs(arguments);
|
||||||
Response response = sendRequest(req, 200);
|
Response response = sendRequest(req, 200);
|
||||||
assertEquals(200,response.getStatus());
|
assertEquals(200,response.getStatus());
|
||||||
|
|
||||||
//JSONObject resultSet = new JSONObject(response.getContentAsString());
|
|
||||||
//validatePropertyDef(resultSet);
|
|
||||||
|
|
||||||
JSONArray result = new JSONArray(response.getContentAsString());
|
JSONArray result = new JSONArray(response.getContentAsString());
|
||||||
assertEquals(200,response.getStatus());
|
assertEquals(200,response.getStatus());
|
||||||
assertEquals(5, result.length());
|
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
|
public void testGetClassDetail() throws Exception
|
||||||
|
@@ -19,11 +19,13 @@
|
|||||||
package org.alfresco.repo.web.scripts.dictionary;
|
package org.alfresco.repo.web.scripts.dictionary;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
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.springframework.extensions.webscripts.Cache;
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
import org.springframework.extensions.webscripts.Status;
|
import org.springframework.extensions.webscripts.Status;
|
||||||
@@ -41,6 +43,7 @@ public class PropertiesGet extends DictionaryWebServiceBase
|
|||||||
{
|
{
|
||||||
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
|
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
|
||||||
private static final String DICTIONARY_CLASS_NAME = "classname";
|
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";
|
private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,29 +51,59 @@ public class PropertiesGet extends DictionaryWebServiceBase
|
|||||||
*/
|
*/
|
||||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||||
{
|
{
|
||||||
|
QName classQName = null;
|
||||||
String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
|
String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
|
||||||
if (className == null || className.length() == 0)
|
if (className != null && className.length() != 0)
|
||||||
{
|
{
|
||||||
// Error
|
classQName = createClassQName(className);
|
||||||
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + className + " - parameter in the URL");
|
|
||||||
|
|
||||||
}
|
|
||||||
QName classQName = createClassQName(className);
|
|
||||||
if (classQName == null)
|
if (classQName == null)
|
||||||
{
|
{
|
||||||
// Error
|
// Error
|
||||||
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + className + " - parameter in the URL");
|
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + className + " - parameter in the URL");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] names = req.getParameterValues(PARAM_NAME);
|
||||||
|
|
||||||
String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
|
String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
|
||||||
|
|
||||||
String namespaceURI = null;
|
String namespaceURI = null;
|
||||||
if (namespacePrefix != null)
|
if (namespacePrefix != null)
|
||||||
{
|
{
|
||||||
namespaceURI = this.namespaceService.getNamespaceURI(namespacePrefix);
|
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());
|
List<PropertyDefinition> props = new ArrayList<PropertyDefinition>(propMap.size());
|
||||||
for (Map.Entry<QName, PropertyDefinition> entry : propMap.entrySet())
|
for (Map.Entry<QName, PropertyDefinition> entry : propMap.entrySet())
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user