Merged 5.2.N (5.2.1) to HEAD (5.2)

129168 mmuller: Merged RETURN-OF-THE-API (5.2.0) to 5.2.N (5.2.1)
      128517 jvonka: REPO-874: Improve REST fwk: improve error message if a POST operation is attempted with multiple items
      - rationalise the code when handling POST for an API "operation" or POST to a collection that is marked as "allowMultiple=false"
      - they should now consistently return the same existing error message: "Only 1 entity is supported in the HTTP request body"
      - add api sanity tests to "create site", "create rating" and some of the node op's, such as "/move" & "/copy"


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@129342 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alexandru Epure
2016-08-09 14:12:44 +00:00
parent 2254b1fa0e
commit c3eeea134f
4 changed files with 103 additions and 38 deletions

View File

@@ -103,14 +103,8 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
if (StringUtils.isNotBlank(entityId) && StringUtils.isNotBlank(operationName))
{
Class objectType = resourceMeta.getObjectType(operation);
Object postedObj = null;
if (objectType!= null)
{
//Operations don't support a List as json body
postedObj = ResourceWebScriptHelper.extractJsonContent(req, assistant.getJsonHelper(), objectType);
}
Object postedObj = processRequest(resourceMeta, operation, req);
if (StringUtils.isNotBlank(propertyName))
{
return Params.valueOf(entityId, relationshipId, params, postedObj, req);
@@ -150,20 +144,41 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
*/
private Object extractObjFromJson(ResourceMetadata resourceMeta, ResourceOperation operation, WebScriptRequest req)
{
List<ResourceParameter> params = operation.getParameters();
if (operation == null)
{
return null;
}
Class<?> objType = resourceMeta.getObjectType(operation);
List<ResourceParameter> params = operation.getParameters();
if (!params.isEmpty())
{
for (ResourceParameter resourceParameter : params)
{
if (ResourceParameter.KIND.HTTP_BODY_OBJECT.equals(resourceParameter.getParamType()) && !resourceParameter.isAllowMultiple())
{
// POST to collection may or may not support List as json body, Operations don't support a List as json body
boolean isTypeOperation = resourceMeta.getType().equals(ResourceMetadata.RESOURCE_TYPE.OPERATION);
boolean notMultiple = ((! resourceParameter.isAllowMultiple()) || isTypeOperation);
if (ResourceParameter.KIND.HTTP_BODY_OBJECT.equals(resourceParameter.getParamType()) && notMultiple)
{
// Only allow 1 value.
try
{
Object content = ResourceWebScriptHelper.extractJsonContent(req,assistant.getJsonHelper(), objType);
return Arrays.asList(content);
Object jsonContent = null;
if (objType != null)
{
jsonContent = ResourceWebScriptHelper.extractJsonContent(req,assistant.getJsonHelper(), objType);
}
if (isTypeOperation)
{
return jsonContent;
}
else
{
return Arrays.asList(jsonContent);
}
}
catch (InvalidArgumentException iae)
{