diff --git a/source/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/source/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index 669aa133ce..6f6b4c7d11 100644 --- a/source/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/source/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -32,7 +32,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; @@ -125,14 +127,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); } diff --git a/source/java/org/alfresco/rest/api/quicksharelinks/QuickShareLinkEntityResource.java b/source/java/org/alfresco/rest/api/quicksharelinks/QuickShareLinkEntityResource.java index c37911efa0..7e8e103e25 100644 --- a/source/java/org/alfresco/rest/api/quicksharelinks/QuickShareLinkEntityResource.java +++ b/source/java/org/alfresco/rest/api/quicksharelinks/QuickShareLinkEntityResource.java @@ -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); } diff --git a/source/java/org/alfresco/rest/framework/core/ResourceInspector.java b/source/java/org/alfresco/rest/framework/core/ResourceInspector.java index c4ef07f996..7b54a1e017 100644 --- a/source/java/org/alfresco/rest/framework/core/ResourceInspector.java +++ b/source/java/org/alfresco/rest/framework/core/ResourceInspector.java @@ -83,6 +83,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); @@ -90,11 +98,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); } /** @@ -117,6 +136,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); @@ -163,10 +189,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) { @@ -211,6 +245,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); @@ -629,21 +670,19 @@ public class ResourceInspector Map> embeds = new HashMap>(); List 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 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(ro,annotatedMethod)); + embeds.put(actionPath, new Pair(ro, annotatedMethod)); } } - - } return embeds; } diff --git a/source/java/org/alfresco/rest/framework/core/ResourceInspectorUtil.java b/source/java/org/alfresco/rest/framework/core/ResourceInspectorUtil.java index 9a58f34fbc..435e1756fa 100755 --- a/source/java/org/alfresco/rest/framework/core/ResourceInspectorUtil.java +++ b/source/java/org/alfresco/rest/framework/core/ResourceInspectorUtil.java @@ -63,10 +63,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; @@ -78,8 +78,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()); } /** diff --git a/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptDelete.java b/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptDelete.java index bc28e7888c..03e8868d53 100644 --- a/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptDelete.java +++ b/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptDelete.java @@ -94,24 +94,59 @@ public class ResourceWebScriptDelete extends AbstractResourceWebScript implement switch (resource.getMetaData().getType()) { case ENTITY: - if (resource.getMetaData().isDeleted(EntityResourceAction.Delete.class)) + if (EntityResourceAction.DeleteWithResponse.class.isAssignableFrom(resource.getResource().getClass())) { - throw new DeletedResourceException("(DELETE) "+resource.getMetaData().getUniqueId()); + 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); } - 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 (resource.getMetaData().isDeleted(RelationshipResourceAction.Delete.class)) + if (RelationshipResourceAction.DeleteWithResponse.class.isAssignableFrom(resource.getResource().getClass())) { - throw new DeletedResourceException("(DELETE) "+resource.getMetaData().getUniqueId()); + 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); } - 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)) @@ -123,6 +158,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)) diff --git a/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java b/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java index 6288912b63..619b68c1da 100644 --- a/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java +++ b/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptGet.java @@ -129,6 +129,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(); @@ -147,6 +157,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(); @@ -165,22 +185,45 @@ 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 (resource.getMetaData().isDeleted(RelationshipResourceAction.Read.class)) + { + + if (RelationshipResourceAction.Read.class.isAssignableFrom(resource.getResource().getClass())) { - throw new DeletedResourceException("(GET) "+resource.getMetaData().getUniqueId()); + if (resource.getMetaData().isDeleted(RelationshipResourceAction.Read.class)) + { + throw new DeletedResourceException("(GET) "+resource.getMetaData().getUniqueId()); + } + RelationshipResourceAction.Read relationGetter = (RelationshipResourceAction.Read) resource.getResource(); + 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; } - RelationshipResourceAction.Read relationGetter = (RelationshipResourceAction.Read) resource.getResource(); - CollectionWithPagingInfo relations = relationGetter.readAll(params.getEntityId(),params); - return relations; } - case PROPERTY: if (StringUtils.isNotBlank(params.getEntityId())) { @@ -194,6 +237,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)) @@ -204,6 +257,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 { diff --git a/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java b/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java index 0f28066288..16dc03e0ee 100644 --- a/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java +++ b/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPost.java @@ -183,18 +183,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"); @@ -214,10 +214,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) { @@ -227,25 +223,45 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements } else { - EntityResourceAction.Create creator = (EntityResourceAction.Create) resObj; - List created = creator.create((List) params.getPassedIn(), params); - if (created != null && created.size() == 1) + if (EntityResourceAction.Create.class.isAssignableFrom(resource.getResource().getClass())) { - // return just one object instead of an array - return created.get(0); + if (resource.getMetaData().isDeleted(EntityResourceAction.Create.class)) + { + throw new DeletedResourceException("(DELETE) " + resource.getMetaData().getUniqueId()); + } + EntityResourceAction.Create creator = (EntityResourceAction.Create) resObj; + List created = creator.create((List) params.getPassedIn(), params); + if (created != null && created.size() == 1) + { + // return just one object instead of an array + return created.get(0); + } + else + { + return wrapWithCollectionWithPaging(created); + } } - else + if (EntityResourceAction.CreateWithResponse.class.isAssignableFrom(resource.getResource().getClass())) { - return wrapWithCollectionWithPaging(created); + if (resource.getMetaData().isDeleted(EntityResourceAction.CreateWithResponse.class)) + { + throw new DeletedResourceException("(DELETE) " + resource.getMetaData().getUniqueId()); + } + EntityResourceAction.CreateWithResponse creator = (EntityResourceAction.CreateWithResponse) resObj; + List created = creator.create((List) 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 (resource.getMetaData().isDeleted(RelationshipResourceAction.Create.class)) - { - throw new DeletedResourceException("(DELETE) " + resource.getMetaData().getUniqueId()); - } - if (resObj instanceof MultiPartRelationshipResourceAction.Create && params.getPassedIn() instanceof FormData) { MultiPartRelationshipResourceAction.Create creator = (MultiPartRelationshipResourceAction.Create) resObj; @@ -253,20 +269,48 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements } else { - RelationshipResourceAction.Create createRelation = (RelationshipResourceAction.Create) resource.getResource(); - List createdRel = createRelation.create(params.getEntityId(), (List) params.getPassedIn(), params); - if (createdRel != null && createdRel.size() == 1) + if (RelationshipResourceAction.Create.class.isAssignableFrom(resource.getResource().getClass())) { - // return just one object instead of an array - return createdRel.get(0); + if (resource.getMetaData().isDeleted(RelationshipResourceAction.Create.class)) + { + throw new DeletedResourceException("(DELETE) " + resource.getMetaData().getUniqueId()); + } + + RelationshipResourceAction.Create createRelation = (RelationshipResourceAction.Create) resource.getResource(); + List createdRel = createRelation.create(params.getEntityId(), (List) params.getPassedIn(), params); + if (createdRel != null && createdRel.size() == 1) + { + // return just one object instead of an array + return createdRel.get(0); + } + else + { + return wrapWithCollectionWithPaging(createdRel); + } } - else + + if (RelationshipResourceAction.CreateWithResponse.class.isAssignableFrom(resource.getResource().getClass())) { - return wrapWithCollectionWithPaging(createdRel); + if (resource.getMetaData().isDeleted(RelationshipResourceAction.CreateWithResponse.class)) + { + throw new DeletedResourceException("(DELETE) " + resource.getMetaData().getUniqueId()); + } + + RelationshipResourceAction.CreateWithResponse createRelation = (RelationshipResourceAction.CreateWithResponse) resource.getResource(); + List createdRel = createRelation.create(params.getEntityId(), (List) 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"); } diff --git a/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPut.java b/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPut.java index 9d1573b3a4..e4740daa35 100644 --- a/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPut.java +++ b/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptPut.java @@ -180,21 +180,47 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P switch (resource.getMetaData().getType()) { case ENTITY: - if (resource.getMetaData().isDeleted(EntityResourceAction.Update.class)) + if (EntityResourceAction.Update.class.isAssignableFrom(resource.getResource().getClass())) { - throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId()); + if (resource.getMetaData().isDeleted(EntityResourceAction.Update.class)) + { + throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId()); + } + EntityResourceAction.Update updateEnt = (EntityResourceAction.Update) 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 updateEnt = (EntityResourceAction.UpdateWithResponse) resource.getResource(); + Object result = updateEnt.update(params.getEntityId(), params.getPassedIn(), params, withResponse); + return result; } - EntityResourceAction.Update updateEnt = (EntityResourceAction.Update) resource.getResource(); - Object result = updateEnt.update(params.getEntityId(), params.getPassedIn(), params); - return result; case RELATIONSHIP: - if (resource.getMetaData().isDeleted(RelationshipResourceAction.Update.class)) + if (RelationshipResourceAction.UpdateWithResponse.class.isAssignableFrom(resource.getResource().getClass())) { - throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId()); + if (resource.getMetaData().isDeleted(RelationshipResourceAction.UpdateWithResponse.class)) + { + throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId()); + } + RelationshipResourceAction.UpdateWithResponse relationUpdater = (RelationshipResourceAction.UpdateWithResponse) 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()); + } + RelationshipResourceAction.Update relationUpdater = (RelationshipResourceAction.Update) resource.getResource(); + Object relResult = relationUpdater.update(params.getEntityId(), params.getPassedIn(), params); + return relResult; } - RelationshipResourceAction.Update relationUpdater = (RelationshipResourceAction.Update) resource.getResource(); - Object relResult = relationUpdater.update(params.getEntityId(), params.getPassedIn(), params); - return relResult; case PROPERTY: if (BinaryResourceAction.Update.class.isAssignableFrom(resource.getResource().getClass())) { @@ -205,6 +231,15 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P BinaryResourceAction.Update binUpdater = (BinaryResourceAction.Update) 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 binUpdater = (BinaryResourceAction.UpdateWithResponse) 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)) @@ -214,6 +249,15 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P RelationshipResourceBinaryAction.Update binUpdater = (RelationshipResourceBinaryAction.Update) 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 binUpdater = (RelationshipResourceBinaryAction.UpdateWithResponse) resource.getResource(); + return binUpdater.updateProperty(params.getEntityId(), params.getRelationshipId(), params.getContentInfo(), params.getStream(), params, withResponse); + } default: throw new UnsupportedResourceOperationException("PUT not supported for Actions"); } diff --git a/source/test-java/org/alfresco/rest/framework/tests/api/mocks/CowEntityResource.java b/source/test-java/org/alfresco/rest/framework/tests/api/mocks/CowEntityResource.java new file mode 100644 index 0000000000..3f964d1fe9 --- /dev/null +++ b/source/test-java/org/alfresco/rest/framework/tests/api/mocks/CowEntityResource.java @@ -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, + EntityResourceAction.ReadWithResponse, + EntityResourceAction.CreateWithResponse, + EntityResourceAction.UpdateWithResponse, + EntityResourceAction.DeleteWithResponse{ + + @Override + public Goat readById(String id, Parameters parameters, WithResponse withResponse) + { + return new Goat("Goat"+id); + } + + @Override + public CollectionWithPagingInfo readAll(Parameters params, WithResponse withResponse) + { + return CollectionWithPagingInfo.asPaged(params.getPaging(), Arrays.asList(new Goat("Cow1"))); + } + + @Override + public List create(List 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; + } +} diff --git a/source/test-java/org/alfresco/rest/framework/tests/api/mocks/GrassEntityResource.java b/source/test-java/org/alfresco/rest/framework/tests/api/mocks/GrassEntityResource.java index aa00500694..8b414afaa0 100644 --- a/source/test-java/org/alfresco/rest/framework/tests/api/mocks/GrassEntityResource.java +++ b/source/test-java/org/alfresco/rest/framework/tests/api/mocks/GrassEntityResource.java @@ -7,6 +7,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; @@ -24,14 +25,14 @@ public class GrassEntityResource implements EntityResourceAction.ReadById @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"; } diff --git a/source/test-java/org/alfresco/rest/framework/tests/api/mocks/SheepBaaaahResource.java b/source/test-java/org/alfresco/rest/framework/tests/api/mocks/SheepBaaaahResource.java index e9889a5294..4b613c7a3f 100644 --- a/source/test-java/org/alfresco/rest/framework/tests/api/mocks/SheepBaaaahResource.java +++ b/source/test-java/org/alfresco/rest/framework/tests/api/mocks/SheepBaaaahResource.java @@ -16,6 +16,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 @@ -65,7 +66,7 @@ public class SheepBaaaahResource implements RelationshipResourceAction.Read 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); diff --git a/source/test-java/org/alfresco/rest/framework/tests/core/InspectorTests.java b/source/test-java/org/alfresco/rest/framework/tests/core/InspectorTests.java index 92b662c090..1d58c8ab1c 100644 --- a/source/test-java/org/alfresco/rest/framework/tests/core/InspectorTests.java +++ b/source/test-java/org/alfresco/rest/framework/tests/core/InspectorTests.java @@ -51,6 +51,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; @@ -438,6 +440,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": @@ -447,7 +451,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": @@ -456,7 +460,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: