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/HEAD/root@126504 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-05-10 11:14:27 +00:00
parent 26201557fc
commit dfdba82274
13 changed files with 400 additions and 73 deletions

View File

@@ -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);
}

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

@@ -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<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

@@ -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());
}
/**

View File

@@ -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))

View File

@@ -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
{

View File

@@ -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<Object> creator = (EntityResourceAction.Create<Object>) resObj;
List<Object> created = creator.create((List<Object>) 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<Object> creator = (EntityResourceAction.Create<Object>) resObj;
List<Object> created = creator.create((List<Object>) 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<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 (resource.getMetaData().isDeleted(RelationshipResourceAction.Create.class))
{
throw new DeletedResourceException("(DELETE) " + resource.getMetaData().getUniqueId());
}
if (resObj instanceof MultiPartRelationshipResourceAction.Create<?> && params.getPassedIn() instanceof FormData)
{
MultiPartRelationshipResourceAction.Create<Object> creator = (MultiPartRelationshipResourceAction.Create<Object>) resObj;
@@ -253,20 +269,48 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
}
else
{
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)
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<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)
{
// 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<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

@@ -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<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;
}
EntityResourceAction.Update<Object> updateEnt = (EntityResourceAction.Update<Object>) 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<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());
}
RelationshipResourceAction.Update<Object> relationUpdater = (RelationshipResourceAction.Update<Object>) resource.getResource();
Object relResult = relationUpdater.update(params.getEntityId(), params.getPassedIn(), params);
return relResult;
}
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()))
{
@@ -205,6 +231,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))
@@ -214,6 +249,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");
}