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

126504 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
      122759 gjames: RA-211: Changing execution actions to handle WithResponse. Rework>Java7


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126848 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ancuta Morarasu
2016-05-11 11:46:15 +00:00
parent 754269a751
commit 642e497a69
13 changed files with 400 additions and 73 deletions

View File

@@ -39,7 +39,9 @@ import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAct
import org.alfresco.rest.framework.resource.content.BasicContentInfo;
import org.alfresco.rest.framework.resource.content.BinaryResource;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.webscripts.WithResponse;
import org.alfresco.util.ParameterCheck;
import org.apache.lucene.store.Lock;
import org.springframework.beans.factory.InitializingBean;
import java.io.InputStream;
@@ -132,14 +134,14 @@ public class NodesEntityResource implements
@Operation("copy")
@WebApiDescription(title = "Copy Node", description="Copy one or more nodes (files or folders) to a new target folder, with option to rename.")
public Node copyById(String nodeId, NodeTarget target, Parameters parameters)
public Node copyById(String nodeId, NodeTarget target, Parameters parameters, WithResponse withResponse)
{
return nodes.moveOrCopyNode(nodeId, target.getTargetParentId(), target.getName(), parameters, true);
}
@Operation("move")
@WebApiDescription(title = "Move Node", description="Moves one or more nodes (files or folders) to a new target folder, with option to rename.")
public Node moveById(String nodeId, NodeTarget target, Parameters parameters)
public Node moveById(String nodeId, NodeTarget target, Parameters parameters, WithResponse withResponse)
{
return nodes.moveOrCopyNode(nodeId, target.getTargetParentId(), target.getName(), parameters, false);
}

View File

@@ -32,6 +32,7 @@ import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAct
import org.alfresco.rest.framework.resource.content.BinaryResource;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.webscripts.WithResponse;
import org.alfresco.util.ParameterCheck;
import org.springframework.beans.factory.InitializingBean;
@@ -131,7 +132,7 @@ public class QuickShareLinkEntityResource implements EntityResourceAction.ReadBy
@Operation("email")
@WebApiDescription(title = "Email shared link", description = "Email the shared link")
public void email(String nodeId, QuickShareLinkEmailRequest emailRequest, Parameters parameters)
public void email(String nodeId, QuickShareLinkEmailRequest emailRequest, Parameters parameters, WithResponse withResponse)
{
quickShareLinks.emailSharedLink(nodeId, emailRequest, parameters);
}

View File

@@ -91,6 +91,14 @@ public class ResourceInspector
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.Update.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.Delete.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(BinaryResourceAction.Read.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.CreateWithResponse.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.ReadWithResponse.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.ReadByIdWithResponse.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.UpdateWithResponse.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.DeleteWithResponse.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(BinaryResourceAction.ReadWithResponse.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(MultiPartResourceAction.Create.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Create.class);
@@ -98,11 +106,22 @@ public class ResourceInspector
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.ReadById.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Update.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Delete.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.CreateWithResponse.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.ReadWithResponse.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.ReadByIdWithResponse.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.UpdateWithResponse.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.DeleteWithResponse.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(MultiPartRelationshipResourceAction.Create.class);
ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.Read.class);
ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.Delete.class);
ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.Update.class);
ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.ReadWithResponse.class);
ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.DeleteWithResponse.class);
ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.UpdateWithResponse.class);
}
/**
@@ -125,6 +144,13 @@ public class ResourceInspector
findOperation(EntityResourceAction.ReadById.class, HttpMethod.GET, helper);
findOperation(EntityResourceAction.Update.class, HttpMethod.PUT, helper);
findOperation(EntityResourceAction.Delete.class, HttpMethod.DELETE, helper);
findOperation(EntityResourceAction.CreateWithResponse.class, HttpMethod.POST, helper);
findOperation(EntityResourceAction.ReadWithResponse.class, HttpMethod.GET, helper);
findOperation(EntityResourceAction.ReadByIdWithResponse.class, HttpMethod.GET, helper);
findOperation(EntityResourceAction.UpdateWithResponse.class, HttpMethod.PUT, helper);
findOperation(EntityResourceAction.DeleteWithResponse.class, HttpMethod.DELETE, helper);
findOperation(MultiPartResourceAction.Create.class, HttpMethod.POST, helper);
boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class);
@@ -171,10 +197,18 @@ public class ResourceInspector
findOperation(BinaryResourceAction.Delete.class, HttpMethod.DELETE, helperForAddressProps);
findOperation(BinaryResourceAction.Update.class, HttpMethod.PUT, helperForAddressProps);
findOperation(BinaryResourceAction.ReadWithResponse.class, HttpMethod.GET, helperForAddressProps);
findOperation(BinaryResourceAction.DeleteWithResponse.class, HttpMethod.DELETE, helperForAddressProps);
findOperation(BinaryResourceAction.UpdateWithResponse.class, HttpMethod.PUT, helperForAddressProps);
findOperation(RelationshipResourceBinaryAction.Read.class, HttpMethod.GET, helperForAddressProps);
findOperation(RelationshipResourceBinaryAction.Delete.class, HttpMethod.DELETE, helperForAddressProps);
findOperation(RelationshipResourceBinaryAction.Update.class, HttpMethod.PUT, helperForAddressProps);
findOperation(RelationshipResourceBinaryAction.ReadWithResponse.class, HttpMethod.GET, helperForAddressProps);
findOperation(RelationshipResourceBinaryAction.DeleteWithResponse.class, HttpMethod.DELETE, helperForAddressProps);
findOperation(RelationshipResourceBinaryAction.UpdateWithResponse.class, HttpMethod.PUT, helperForAddressProps);
boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class);
if (noAuth)
{
@@ -219,6 +253,13 @@ public class ResourceInspector
findOperation(RelationshipResourceAction.ReadById.class, HttpMethod.GET, helper);
findOperation(RelationshipResourceAction.Update.class, HttpMethod.PUT, helper);
findOperation(RelationshipResourceAction.Delete.class, HttpMethod.DELETE, helper);
findOperation(RelationshipResourceAction.CreateWithResponse.class, HttpMethod.POST, helper);
findOperation(RelationshipResourceAction.ReadWithResponse.class, HttpMethod.GET, helper);
findOperation(RelationshipResourceAction.ReadByIdWithResponse.class, HttpMethod.GET, helper);
findOperation(RelationshipResourceAction.UpdateWithResponse.class, HttpMethod.PUT, helper);
findOperation(RelationshipResourceAction.DeleteWithResponse.class, HttpMethod.DELETE, helper);
findOperation(MultiPartRelationshipResourceAction.Create.class, HttpMethod.POST, helper);
boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class);
@@ -637,21 +678,19 @@ public class ResourceInspector
Map<String, Pair<ResourceOperation,Method>> embeds = new HashMap<String, Pair<ResourceOperation,Method>>();
List<Method> annotatedMethods = ResourceInspectorUtil.findMethodsByAnnotation(anyClass, Operation.class);
if (annotatedMethods != null && !annotatedMethods.isEmpty())
{
for (Method annotatedMethod : annotatedMethods)
{
//validateOperationMethod(annotatedMethod, anyClass);
Annotation annot = AnnotationUtils.findAnnotation(annotatedMethod, Operation.class);
if (annot != null)
{
Map<String, Object> annotAttribs = AnnotationUtils.getAnnotationAttributes(annot);
String actionName = String.valueOf(annotAttribs.get("value"));
String actionPath = ResourceDictionary.propertyResourceKey(entityPath,actionName);
String actionPath = ResourceDictionary.propertyResourceKey(entityPath, actionName);
ResourceOperation ro = inspectOperation(anyClass, annotatedMethod, HttpMethod.POST);
embeds.put(actionPath, new Pair<ResourceOperation,Method>(ro,annotatedMethod));
embeds.put(actionPath, new Pair<ResourceOperation, Method>(ro, annotatedMethod));
}
}
}
return embeds;
}

View File

@@ -88,10 +88,10 @@ public class ResourceInspectorUtil
{
switch (paramTypes.length)
{
case 3:
//EntityResource operation by id, same logic as RelationshipEntityResource operation by id
case 4:
int position = paramTypes.length-2;
//EntityResource operation by id, same logic as RelationshipEntityResource operation by id
case 5:
int position = paramTypes.length-3;
if (Void.class.equals(paramTypes[position]))
{
return null;
@@ -103,8 +103,8 @@ public class ResourceInspectorUtil
}
}
throw new IllegalArgumentException("An operation method signature should have 3 parameters (uniqueId, typePassedin, Parameters)," +
" use Void if you are not interested in the second argument.");
throw new IllegalArgumentException("Your method signature should have 4 parameters (uniqueId, typePassedin, Parameters, WithResponse)," +
" use Void if you are not interested in the second argument. "+resource.getName()+ " "+ method.getName());
}
/**

View File

@@ -119,24 +119,59 @@ public class ResourceWebScriptDelete extends AbstractResourceWebScript implement
switch (resource.getMetaData().getType())
{
case ENTITY:
if (EntityResourceAction.DeleteWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(EntityResourceAction.DeleteWithResponse.class))
{
throw new DeletedResourceException("(DELETE) "+resource.getMetaData().getUniqueId());
}
EntityResourceAction.DeleteWithResponse entityDeleter = (EntityResourceAction.DeleteWithResponse) resource.getResource();
entityDeleter.delete(params.getEntityId(), params, withResponse);
}
else
{
if (resource.getMetaData().isDeleted(EntityResourceAction.Delete.class))
{
throw new DeletedResourceException("(DELETE) "+resource.getMetaData().getUniqueId());
}
EntityResourceAction.Delete entityDeleter = (EntityResourceAction.Delete) resource.getResource();
entityDeleter.delete(params.getEntityId(), params);
}
//Don't pass anything to the callback - its just successful
return null;
case RELATIONSHIP:
if (RelationshipResourceAction.DeleteWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(RelationshipResourceAction.DeleteWithResponse.class))
{
throw new DeletedResourceException("(DELETE) "+resource.getMetaData().getUniqueId());
}
RelationshipResourceAction.DeleteWithResponse relationDeleter = (RelationshipResourceAction.DeleteWithResponse) resource.getResource();
relationDeleter.delete(params.getEntityId(), params.getRelationshipId(), params, withResponse);
}
else
{
if (resource.getMetaData().isDeleted(RelationshipResourceAction.Delete.class))
{
throw new DeletedResourceException("(DELETE) "+resource.getMetaData().getUniqueId());
}
RelationshipResourceAction.Delete relationDeleter = (RelationshipResourceAction.Delete) resource.getResource();
relationDeleter.delete(params.getEntityId(), params.getRelationshipId(), params);
}
//Don't pass anything to the callback - its just successful
return null;
case PROPERTY:
if (BinaryResourceAction.DeleteWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(BinaryResourceAction.DeleteWithResponse.class))
{
throw new DeletedResourceException("(DELETE) "+resource.getMetaData().getUniqueId());
}
BinaryResourceAction.DeleteWithResponse binDeleter = (BinaryResourceAction.DeleteWithResponse) resource.getResource();
binDeleter.deleteProperty(params.getEntityId(), params, withResponse);
//Don't pass anything to the callback - its just successful
return null;
}
if (BinaryResourceAction.Delete.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(BinaryResourceAction.Delete.class))
@@ -148,6 +183,17 @@ public class ResourceWebScriptDelete extends AbstractResourceWebScript implement
//Don't pass anything to the callback - its just successful
return null;
}
if (RelationshipResourceBinaryAction.DeleteWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.DeleteWithResponse.class))
{
throw new DeletedResourceException("(DELETE) "+resource.getMetaData().getUniqueId());
}
RelationshipResourceBinaryAction.DeleteWithResponse binDeleter = (RelationshipResourceBinaryAction.DeleteWithResponse) resource.getResource();
binDeleter.deleteProperty(params.getEntityId(), params.getRelationshipId(), params, withResponse);
//Don't pass anything to the callback - its just successful
return null;
}
if (RelationshipResourceBinaryAction.Delete.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.Delete.class))

View File

@@ -136,6 +136,16 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
CollectionWithPagingInfo<?> resources = getter.readAll(params);
return resources;
}
else if (EntityResourceAction.ReadWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(EntityResourceAction.ReadWithResponse.class))
{
throw new DeletedResourceException("(GET) "+resource.getMetaData().getUniqueId());
}
EntityResourceAction.ReadWithResponse<?> getter = (EntityResourceAction.ReadWithResponse<?>) resource.getResource();
CollectionWithPagingInfo<?> resources = getter.readAll(params, withResponse);
return resources;
}
else
{
throw new UnsupportedResourceOperationException();
@@ -154,6 +164,16 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
Object result = entityGetter.readById(params.getEntityId(), params);
return result;
}
else if (EntityResourceAction.ReadByIdWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(EntityResourceAction.ReadByIdWithResponse.class))
{
throw new DeletedResourceException("(GET by id) "+resource.getMetaData().getUniqueId());
}
EntityResourceAction.ReadByIdWithResponse<?> entityGetter = (EntityResourceAction.ReadByIdWithResponse<?>) resource.getResource();
Object result = entityGetter.readById(params.getEntityId(), params, withResponse);
return result;
}
else
{
throw new UnsupportedResourceOperationException();
@@ -172,12 +192,25 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
Object result = relationGetter.readById(params.getEntityId(), params.getRelationshipId(), params);
return result;
}
else if (RelationshipResourceAction.ReadByIdWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(RelationshipResourceAction.ReadByIdWithResponse.class))
{
throw new DeletedResourceException("(GET by id) "+resource.getMetaData().getUniqueId());
}
RelationshipResourceAction.ReadByIdWithResponse<?> relationGetter = (RelationshipResourceAction.ReadByIdWithResponse<?>) resource.getResource();
Object result = relationGetter.readById(params.getEntityId(), params.getRelationshipId(), params, withResponse);
return result;
}
else
{
throw new UnsupportedResourceOperationException();
}
}
else
{
if (RelationshipResourceAction.Read.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(RelationshipResourceAction.Read.class))
{
@@ -187,7 +220,17 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
CollectionWithPagingInfo<?> relations = relationGetter.readAll(params.getEntityId(),params);
return relations;
}
else
{
if (resource.getMetaData().isDeleted(RelationshipResourceAction.ReadWithResponse.class))
{
throw new DeletedResourceException("(GET) "+resource.getMetaData().getUniqueId());
}
RelationshipResourceAction.ReadWithResponse<?> relationGetter = (RelationshipResourceAction.ReadWithResponse<?>) resource.getResource();
CollectionWithPagingInfo<?> relations = relationGetter.readAll(params.getEntityId(),params,withResponse);
return relations;
}
}
case PROPERTY:
if (StringUtils.isNotBlank(params.getEntityId()))
{
@@ -201,6 +244,16 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
BinaryResource prop = getter.readProperty(params.getEntityId(), params);
return prop;
}
if (BinaryResourceAction.ReadWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(BinaryResourceAction.ReadWithResponse.class))
{
throw new DeletedResourceException("(GET) "+resource.getMetaData().getUniqueId());
}
BinaryResourceAction.ReadWithResponse getter = (BinaryResourceAction.ReadWithResponse) resource.getResource();
BinaryResource prop = getter.readProperty(params.getEntityId(), params, withResponse);
return prop;
}
if (RelationshipResourceBinaryAction.Read.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.Read.class))
@@ -211,6 +264,16 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
BinaryResource prop = getter.readProperty(params.getEntityId(), params.getRelationshipId(), params);
return prop;
}
if (RelationshipResourceBinaryAction.ReadWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.ReadWithResponse.class))
{
throw new DeletedResourceException("(GET) "+resource.getMetaData().getUniqueId());
}
RelationshipResourceBinaryAction.ReadWithResponse getter = (RelationshipResourceBinaryAction.ReadWithResponse) resource.getResource();
BinaryResource prop = getter.readProperty(params.getEntityId(), params.getRelationshipId(), params, withResponse);
return prop;
}
}
else
{

View File

@@ -189,18 +189,18 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
* @param params
* @return the result of the execution.
*/
private Object executeOperation(ResourceWithMetadata resource, Params params) throws Throwable
private Object executeOperation(ResourceWithMetadata resource, Params params, WithResponse withResponse) throws Throwable
{
OperationResourceMetaData operationResourceMetaData = (OperationResourceMetaData) resource.getMetaData();
switch (operationResourceMetaData.getOperationMethod().getParameterTypes().length)
{
case 3:
//EntityResource operation by id
return ResourceInspectorUtil.invokeMethod(operationResourceMetaData.getOperationMethod(),resource.getResource(), params.getEntityId(), params.getPassedIn(), params);
case 4:
//EntityResource operation by id
return ResourceInspectorUtil.invokeMethod(operationResourceMetaData.getOperationMethod(),resource.getResource(), params.getEntityId(), params.getPassedIn(), params, withResponse);
case 5:
//RelationshipEntityResource operation by id
return ResourceInspectorUtil.invokeMethod(operationResourceMetaData.getOperationMethod(),resource.getResource(), params.getEntityId(), params.getRelationshipId(), params.getPassedIn(), params);
return ResourceInspectorUtil.invokeMethod(operationResourceMetaData.getOperationMethod(),resource.getResource(), params.getEntityId(), params.getRelationshipId(), params.getPassedIn(), params, withResponse);
}
throw new UnsupportedResourceOperationException("The operation method has an invalid signature");
@@ -220,10 +220,6 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
switch (resource.getMetaData().getType())
{
case ENTITY:
if (resource.getMetaData().isDeleted(EntityResourceAction.Create.class))
{
throw new DeletedResourceException("(DELETE) " + resource.getMetaData().getUniqueId());
}
if (resObj instanceof MultiPartResourceAction.Create<?> && params.getPassedIn() instanceof FormData)
{
@@ -233,6 +229,12 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
}
else
{
if (EntityResourceAction.Create.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(EntityResourceAction.Create.class))
{
throw new DeletedResourceException("(DELETE) " + resource.getMetaData().getUniqueId());
}
EntityResourceAction.Create<Object> creator = (EntityResourceAction.Create<Object>) resObj;
List<Object> created = creator.create((List<Object>) params.getPassedIn(), params);
if (created != null && created.size() == 1)
@@ -245,13 +247,27 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
return wrapWithCollectionWithPaging(created);
}
}
case RELATIONSHIP:
if (resource.getMetaData().isDeleted(RelationshipResourceAction.Create.class))
if (EntityResourceAction.CreateWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(EntityResourceAction.CreateWithResponse.class))
{
throw new DeletedResourceException("(DELETE) " + resource.getMetaData().getUniqueId());
}
EntityResourceAction.CreateWithResponse<Object> creator = (EntityResourceAction.CreateWithResponse<Object>) resObj;
List<Object> created = creator.create((List<Object>) params.getPassedIn(), params, withResponse);
if (created != null && created.size() == 1)
{
// return just one object instead of an array
return created.get(0);
}
else
{
return wrapWithCollectionWithPaging(created);
}
}
}
case RELATIONSHIP:
if (resObj instanceof MultiPartRelationshipResourceAction.Create<?> && params.getPassedIn() instanceof FormData)
{
MultiPartRelationshipResourceAction.Create<Object> creator = (MultiPartRelationshipResourceAction.Create<Object>) resObj;
@@ -259,6 +275,13 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
}
else
{
if (RelationshipResourceAction.Create.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(RelationshipResourceAction.Create.class))
{
throw new DeletedResourceException("(DELETE) " + resource.getMetaData().getUniqueId());
}
RelationshipResourceAction.Create<Object> createRelation = (RelationshipResourceAction.Create<Object>) resource.getResource();
List<Object> createdRel = createRelation.create(params.getEntityId(), (List<Object>) params.getPassedIn(), params);
if (createdRel != null && createdRel.size() == 1)
@@ -271,8 +294,29 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
return wrapWithCollectionWithPaging(createdRel);
}
}
if (RelationshipResourceAction.CreateWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(RelationshipResourceAction.CreateWithResponse.class))
{
throw new DeletedResourceException("(DELETE) " + resource.getMetaData().getUniqueId());
}
RelationshipResourceAction.CreateWithResponse<Object> createRelation = (RelationshipResourceAction.CreateWithResponse<Object>) resource.getResource();
List<Object> createdRel = createRelation.create(params.getEntityId(), (List<Object>) params.getPassedIn(), params, withResponse);
if (createdRel != null && createdRel.size() == 1)
{
// return just one object instead of an array
return createdRel.get(0);
}
else
{
return wrapWithCollectionWithPaging(createdRel);
}
}
}
case OPERATION:
return executeOperation(resource, params);
return executeOperation(resource, params, withResponse);
default:
throw new UnsupportedResourceOperationException("POST not supported for Actions");
}

View File

@@ -186,6 +186,8 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
switch (resource.getMetaData().getType())
{
case ENTITY:
if (EntityResourceAction.Update.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(EntityResourceAction.Update.class))
{
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
@@ -193,7 +195,30 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
EntityResourceAction.Update<Object> updateEnt = (EntityResourceAction.Update<Object>) resource.getResource();
Object result = updateEnt.update(params.getEntityId(), params.getPassedIn(), params);
return result;
}
else
{
if (resource.getMetaData().isDeleted(EntityResourceAction.UpdateWithResponse.class))
{
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
}
EntityResourceAction.UpdateWithResponse<Object> updateEnt = (EntityResourceAction.UpdateWithResponse<Object>) resource.getResource();
Object result = updateEnt.update(params.getEntityId(), params.getPassedIn(), params, withResponse);
return result;
}
case RELATIONSHIP:
if (RelationshipResourceAction.UpdateWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(RelationshipResourceAction.UpdateWithResponse.class))
{
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
}
RelationshipResourceAction.UpdateWithResponse<Object> relationUpdater = (RelationshipResourceAction.UpdateWithResponse<Object>) resource.getResource();
Object relResult = relationUpdater.update(params.getEntityId(), params.getPassedIn(), params, withResponse);
return relResult;
}
else
{
if (resource.getMetaData().isDeleted(RelationshipResourceAction.Update.class))
{
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
@@ -201,6 +226,7 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
RelationshipResourceAction.Update<Object> relationUpdater = (RelationshipResourceAction.Update<Object>) resource.getResource();
Object relResult = relationUpdater.update(params.getEntityId(), params.getPassedIn(), params);
return relResult;
}
case PROPERTY:
if (BinaryResourceAction.Update.class.isAssignableFrom(resource.getResource().getClass()))
{
@@ -211,6 +237,15 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
BinaryResourceAction.Update<Object> binUpdater = (BinaryResourceAction.Update<Object>) resource.getResource();
return binUpdater.updateProperty(params.getEntityId(), params.getContentInfo(), params.getStream(), params);
}
if (BinaryResourceAction.UpdateWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(BinaryResourceAction.UpdateWithResponse.class))
{
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
}
BinaryResourceAction.UpdateWithResponse<Object> binUpdater = (BinaryResourceAction.UpdateWithResponse<Object>) resource.getResource();
return binUpdater.updateProperty(params.getEntityId(), params.getContentInfo(), params.getStream(), params, withResponse);
}
if (RelationshipResourceBinaryAction.Update.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.Update.class))
@@ -220,6 +255,15 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
RelationshipResourceBinaryAction.Update<Object> binUpdater = (RelationshipResourceBinaryAction.Update<Object>) resource.getResource();
return binUpdater.updateProperty(params.getEntityId(), params.getRelationshipId(), params.getContentInfo(), params.getStream(), params);
}
if (RelationshipResourceBinaryAction.UpdateWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
{
if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.UpdateWithResponse.class))
{
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
}
RelationshipResourceBinaryAction.UpdateWithResponse<Object> binUpdater = (RelationshipResourceBinaryAction.UpdateWithResponse<Object>) resource.getResource();
return binUpdater.updateProperty(params.getEntityId(), params.getRelationshipId(), params.getContentInfo(), params.getStream(), params, withResponse);
}
default:
throw new UnsupportedResourceOperationException("PUT not supported for Actions");
}

View File

@@ -0,0 +1,49 @@
package org.alfresco.rest.framework.tests.api.mocks;
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
import org.alfresco.rest.framework.resource.EntityResource;
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.webscripts.WithResponse;
import java.util.Arrays;
import java.util.List;
@EntityResource(name="cow", title="Cow")
public class CowEntityResource implements EntityResourceAction.ReadByIdWithResponse<Goat>,
EntityResourceAction.ReadWithResponse<Goat>,
EntityResourceAction.CreateWithResponse<Goat>,
EntityResourceAction.UpdateWithResponse<Goat>,
EntityResourceAction.DeleteWithResponse{
@Override
public Goat readById(String id, Parameters parameters, WithResponse withResponse)
{
return new Goat("Goat"+id);
}
@Override
public CollectionWithPagingInfo<Goat> readAll(Parameters params, WithResponse withResponse)
{
return CollectionWithPagingInfo.asPaged(params.getPaging(), Arrays.asList(new Goat("Cow1")));
}
@Override
public List<Goat> create(List<Goat> entities, Parameters parameters, WithResponse withResponse)
{
return entities;
}
@Override
public void delete(String id, Parameters parameters, WithResponse withResponse)
{
}
@Override
public Goat update(String id, Goat entity, Parameters parameters, WithResponse withResponse)
{
return entity;
}
}

View File

@@ -32,6 +32,7 @@ import org.alfresco.rest.framework.core.ResourceParameter;
import org.alfresco.rest.framework.resource.EntityResource;
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.webscripts.WithResponse;
import org.springframework.extensions.webscripts.Status;
import java.util.List;
@@ -49,14 +50,14 @@ public class GrassEntityResource implements EntityResourceAction.ReadById<Grass>
@Operation("cut")
@WebApiDescription(title = "Cut the grass",successStatus = Status.STATUS_NOT_IMPLEMENTED)
public String cutLawn(String id, Void notused, Parameters parameters) {
public String cutLawn(String id, Void notused, Parameters parameters, WithResponse withResponse) {
return "All done";
}
@Operation("grow")
@WebApiDescription(title = "Grow the grass",successStatus = Status.STATUS_ACCEPTED)
@WebApiParam(name = "Grass", title = "The grass.",required=true, kind = ResourceParameter.KIND.HTTP_BODY_OBJECT)
public String growTheLawn(String id, Grass grass, Parameters parameters) {
public String growTheLawn(String id, Grass grass, Parameters parameters, WithResponse withResponse) {
return "Growing well";
}

View File

@@ -41,6 +41,7 @@ import org.alfresco.rest.framework.resource.content.BasicContentInfo;
import org.alfresco.rest.framework.resource.content.BinaryResource;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.webscripts.WithResponse;
/**
* Implements Get
@@ -90,7 +91,7 @@ public class SheepBaaaahResource implements RelationshipResourceAction.Read<Shee
}
@Operation("chew")
public String chewTheGrass(String entityId, String id, Void notused, Parameters parameters) {
public String chewTheGrass(String entityId, String id, Void notused, Parameters parameters, WithResponse withResponse) {
return "All done";
}
}

View File

@@ -6,6 +6,7 @@ import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import org.alfresco.rest.framework.Api;
import org.alfresco.rest.framework.core.ResourceLocator;
import org.alfresco.rest.framework.core.ResourceLookupDictionary;
import org.alfresco.rest.framework.core.ResourceWithMetadata;
import org.alfresco.rest.framework.jacksonextensions.ExecutionResult;
@@ -13,6 +14,7 @@ import org.alfresco.rest.framework.resource.actions.ActionExecutor;
import org.alfresco.rest.framework.resource.content.ContentInfo;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Params;
import org.alfresco.rest.framework.tests.api.mocks.Goat;
import org.alfresco.rest.framework.tests.api.mocks.Grass;
import org.alfresco.rest.framework.tests.api.mocks.Sheep;
import org.alfresco.rest.framework.webscripts.AbstractResourceWebScript;
@@ -28,6 +30,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Tests the execution of resources
@@ -45,6 +49,13 @@ public class ExecutionTests extends AbstractContextTest
Object result = executor.execute(entityResource, Params.valueOf((String)null, null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), true);
assertNotNull(result);
entityResource = locator.locateEntityResource(api,"cow", HttpMethod.GET);
result = executor.execute(entityResource, Params.valueOf((String)null, null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), true);
assertNotNull(result);
result = executor.execute(entityResource, Params.valueOf("543", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), true);
assertNotNull(result);
ResourceWithMetadata baa = locator.locateRelationResource(api,"sheep", "baaahh", HttpMethod.GET);
result = executor.execute(baa, Params.valueOf("4", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), true);
assertNotNull(result);
@@ -74,9 +85,22 @@ public class ExecutionTests extends AbstractContextTest
result = executor.execute(grassResource, Params.valueOf("654", null, NULL_PARAMS, Arrays.asList(grr), mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertEquals(grr,((ExecutionResult)result).getRoot());
ResourceWithMetadata cowresource = locator.locateEntityResource(api,"cow", HttpMethod.POST);
result = executor.execute(cowresource, Params.valueOf("654", null, NULL_PARAMS, Arrays.asList(grr), mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertEquals(grr,((ExecutionResult)result).getRoot());
ResourceWithMetadata entityResource = locator.locateRelationResource(api,"grass", "grow", HttpMethod.POST);
result = executor.execute(entityResource, Params.valueOf("654", null, NULL_PARAMS, grr, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertEquals("Growing well",result);
Map<String, String> templateVars = new HashMap();
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "sheep");
templateVars.put(ResourceLocator.ENTITY_ID, "sheepId");
templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "baaahh");
templateVars.put(ResourceLocator.PROPERTY, "chew");
ResourceWithMetadata collResource = locator.locateResource(api, templateVars, HttpMethod.POST);
result = executor.execute(collResource, Params.valueOf("654", "345", NULL_PARAMS, null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertEquals("All done",result);
}
@Test
@@ -87,6 +111,10 @@ public class ExecutionTests extends AbstractContextTest
Object result = executor.execute(grassResource, Params.valueOf("4", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNull(result);
ResourceWithMetadata cowResource = locator.locateEntityResource(api,"cow", HttpMethod.DELETE);
result = executor.execute(cowResource, Params.valueOf("4", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNull(result);
ResourceWithMetadata resource = locator.locateRelationResource(api, "sheep", "blacksheep", HttpMethod.DELETE);
result = executor.execute(resource, Params.valueOf("4", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNull(result);
@@ -103,11 +131,16 @@ public class ExecutionTests extends AbstractContextTest
ResourceWithMetadata entityResource = locator.locateEntityResource(api,"sheep", HttpMethod.PUT);
AbstractResourceWebScript executor = (AbstractResourceWebScript) applicationContext.getBean("executorOfPut");
final Sheep aSheep = new Sheep("xyz");
Object result = executor.execute(entityResource, Params.valueOf("654", null, NULL_PARAMS, aSheep, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNotNull(result);
assertEquals(aSheep,((ExecutionResult)result).getRoot());
final Goat goat = new Goat("xyz");
ResourceWithMetadata cowResource = locator.locateEntityResource(api,"cow", HttpMethod.PUT);
result = executor.execute(cowResource, Params.valueOf("654", null, NULL_PARAMS, goat, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNotNull(result);
assertEquals(goat,((ExecutionResult)result).getRoot());
ResourceWithMetadata resource = locator.locateRelationResource(api, "sheep", "blacksheep", HttpMethod.PUT);
result = executor.execute(resource, Params.valueOf("654", null, NULL_PARAMS, aSheep, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNotNull(result);

View File

@@ -76,6 +76,8 @@ import org.alfresco.rest.framework.tests.api.mocks3.GrassEntityResourceNowDelete
import org.alfresco.rest.framework.tests.api.mocks3.SheepBlackSheepResourceIsNoMore;
import org.alfresco.rest.framework.tests.api.mocks3.SheepEntityResourceWithDeletedMethods;
import org.alfresco.rest.framework.tests.api.mocks3.SlimGoat;
import org.alfresco.rest.framework.webscripts.ApiWebScript;
import org.alfresco.rest.framework.webscripts.WithResponse;
import org.alfresco.util.Pair;
import org.junit.Test;
import org.springframework.extensions.webscripts.Status;
@@ -463,6 +465,8 @@ public class InspectorTests
OperationResourceMetaData operationResourceMetaData = (OperationResourceMetaData) resourceMetadata;
Method actionMethod = operationResourceMetaData.getOperationMethod();
String result = null;
final WithResponse wr = new WithResponse(Status.STATUS_OK, ApiWebScript.DEFAULT_JSON_CONTENT, ApiWebScript.CACHE_NEVER);
switch (resourceMetadata.getUniqueId())
{
case "/-root-/{id}/grow":
@@ -472,7 +476,7 @@ public class InspectorTests
assertEquals("grow should return ACCEPTED", Status.STATUS_ACCEPTED, op.getSuccessStatus());
Class paramType = resourceMetadata.getObjectType(op);
Object paramObj = paramType.newInstance();
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod,grassEntityResource, "xyz", paramObj, Params.valueOf("notUsed", null, mock(WebScriptRequest.class)));
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod,grassEntityResource, "xyz", paramObj, Params.valueOf("notUsed", null, mock(WebScriptRequest.class)), wr);
assertEquals("Growing well",result);
break;
case "/-root-/{id}/cut":
@@ -481,7 +485,7 @@ public class InspectorTests
op = resourceMetadata.getOperation(HttpMethod.POST);
assertNull(resourceMetadata.getObjectType(op));
assertEquals("cut should return ACCEPTED", Status.STATUS_NOT_IMPLEMENTED, op.getSuccessStatus());
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod,grassEntityResource, "xyz", null, Params.valueOf("notUsed", null, mock(WebScriptRequest.class)));
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod,grassEntityResource, "xyz", null, Params.valueOf("notUsed", null, mock(WebScriptRequest.class)), wr);
assertEquals("All done",result);
break;
default: