mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD (5.2) to 5.2.N (5.2.1)
126420 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 121807 gjames: RA-774 Added basic action support git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126766 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
19
source/java/org/alfresco/rest/framework/Action.java
Executable file
19
source/java/org/alfresco/rest/framework/Action.java
Executable file
@@ -0,0 +1,19 @@
|
||||
package org.alfresco.rest.framework;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* An action as on an entity in the Rest API
|
||||
*
|
||||
* @author Gethin James
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Action
|
||||
{
|
||||
String value();
|
||||
}
|
||||
|
@@ -37,6 +37,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.rest.framework.Action;
|
||||
import org.alfresco.rest.framework.Api;
|
||||
import org.alfresco.rest.framework.BinaryProperties;
|
||||
import org.alfresco.rest.framework.WebApi;
|
||||
@@ -134,12 +135,12 @@ public class ResourceInspector
|
||||
helper.operations, api, helper.apiDeleted, null));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inspectAddressedProperties(api, resource, urlPath, metainfo);
|
||||
inspectActions(api, resource, urlPath, metainfo);
|
||||
return metainfo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inspects the entity resource and returns meta data about any addresssed/binary properties
|
||||
* @param api Api
|
||||
@@ -323,8 +324,7 @@ public class ResourceInspector
|
||||
}
|
||||
if (paramsCount(params,ResourceParameter.KIND.HTTP_BODY_OBJECT) == 0)
|
||||
{
|
||||
Class<?> dType = ResourceInspectorUtil.determineType(resource,aMethod);
|
||||
params.add(ResourceParameter.valueOf(dType.getSimpleName().toUpperCase(), "The entity", "Unique entity properties", true, ResourceParameter.KIND.HTTP_BODY_OBJECT, true, dType));
|
||||
inspectBodyParamAndReturnType(resource, aMethod, params);
|
||||
}
|
||||
break;
|
||||
case PUT:
|
||||
@@ -339,8 +339,7 @@ public class ResourceInspector
|
||||
}
|
||||
if (paramsCount(params,ResourceParameter.KIND.HTTP_BODY_OBJECT)== 0)
|
||||
{
|
||||
Class<?> dType = ResourceInspectorUtil.determineType(resource,aMethod);
|
||||
params.add(ResourceParameter.valueOf(dType.getSimpleName().toUpperCase(), "The entity", "Unique entity properties", true, ResourceParameter.KIND.HTTP_BODY_OBJECT, true, dType));
|
||||
inspectBodyParamAndReturnType(resource, aMethod, params);
|
||||
}
|
||||
break;
|
||||
case GET:
|
||||
@@ -385,6 +384,12 @@ public class ResourceInspector
|
||||
return params;
|
||||
}
|
||||
|
||||
private static void inspectBodyParamAndReturnType(Class<?> resource, Method aMethod, List<ResourceParameter> params)
|
||||
{
|
||||
Class<?> dType = ResourceInspectorUtil.determineType(resource,aMethod);
|
||||
params.add(ResourceParameter.valueOf(dType.getSimpleName().toUpperCase(), "The entity", "Unique entity properties", true, KIND.HTTP_BODY_OBJECT, true, dType));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Indicates the number of params of the Kind specified
|
||||
@@ -536,6 +541,61 @@ public class ResourceInspector
|
||||
return embeds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inspect a resource to find actions on it.
|
||||
* @param api Api
|
||||
* @param resource Class<?>
|
||||
* @param entityPath String
|
||||
* @param metainfo List<ResourceMetadata>
|
||||
*/
|
||||
public static void inspectActions(Api api, Class<?> resource, final String entityPath, List<ResourceMetadata> metainfo)
|
||||
{
|
||||
Map<String,Pair<ResourceOperation,Method>> operations = findActions(entityPath, resource);
|
||||
if (operations != null && !operations.isEmpty())
|
||||
{
|
||||
for (Entry<String, Pair<ResourceOperation, Method>> opera : operations.entrySet())
|
||||
{
|
||||
if (isDeleted(opera.getValue().getSecond()))
|
||||
{
|
||||
metainfo.add(new ResourceMetadata(opera.getKey(), RESOURCE_TYPE.ACTION, null, api, new HashSet(Arrays.asList(opera.getValue().getFirst())), null));
|
||||
}
|
||||
else
|
||||
{
|
||||
metainfo.add(new ResourceMetadata(opera.getKey(), RESOURCE_TYPE.ACTION, Arrays.asList(opera.getValue().getFirst()), api, null, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds actions on an entity
|
||||
* @param entityPath path to the entity
|
||||
* @param anyClass resource clause
|
||||
* @return The operations
|
||||
*/
|
||||
private static Map<String,Pair<ResourceOperation,Method>> findActions(String entityPath, Class<?> anyClass)
|
||||
{
|
||||
Map<String, Pair<ResourceOperation,Method>> embeds = new HashMap<String, Pair<ResourceOperation,Method>>();
|
||||
List<Method> annotatedMethods = ResourceInspectorUtil.findMethodsByAnnotation(anyClass, Action.class);
|
||||
if (annotatedMethods != null && !annotatedMethods.isEmpty())
|
||||
{
|
||||
for (Method annotatedMethod : annotatedMethods)
|
||||
{
|
||||
Annotation annot = AnnotationUtils.findAnnotation(annotatedMethod, Action.class);
|
||||
if (annot != null)
|
||||
{
|
||||
Map<String, Object> annotAttribs = AnnotationUtils.getAnnotationAttributes(annot);
|
||||
String actionName = String.valueOf(annotAttribs.get("value"));
|
||||
String actionPath = ResourceDictionary.resourceKey(entityPath,actionName);
|
||||
ResourceOperation ro = inspectOperation(anyClass, annotatedMethod, HttpMethod.POST);
|
||||
embeds.put(actionPath, new Pair<ResourceOperation,Method>(ro,annotatedMethod));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return embeds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inspects the resource to determine what api it belongs to.
|
||||
* It does this by looking for the WebApi package annotation.
|
||||
|
@@ -78,7 +78,7 @@ public class ResourceInspectorUtil
|
||||
* @return - the List of Method or an empty List
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected static List<Method> findMethodsByAnnotation(Class objClass, Class<? extends Annotation> annotationType)
|
||||
public static List<Method> findMethodsByAnnotation(Class objClass, Class<? extends Annotation> annotationType)
|
||||
{
|
||||
|
||||
List<Method> annotatedMethods = new ArrayList<Method>();
|
||||
|
@@ -42,7 +42,7 @@ import org.springframework.http.HttpMethod;
|
||||
*/
|
||||
public class ResourceMetadata
|
||||
{
|
||||
public enum RESOURCE_TYPE {ENTITY,RELATIONSHIP, PROPERTY};
|
||||
public enum RESOURCE_TYPE {ENTITY, RELATIONSHIP, PROPERTY, ACTION};
|
||||
private final String uniqueId;
|
||||
private final RESOURCE_TYPE type;
|
||||
private final List<ResourceOperation> operations;
|
||||
|
Reference in New Issue
Block a user