Class ResourceInspector


  • public class ResourceInspector
    extends Object
    Looks at resources to see what they can do
    Author:
    Gethin James, janv
    • Constructor Detail

      • ResourceInspector

        public ResourceInspector()
    • Method Detail

      • inspectAddressedProperties

        public static void inspectAddressedProperties​(Api api,
                                                      Class<?> resource,
                                                      String entityPath,
                                                      List<ResourceMetadata> metainfo)
        Inspects the entity resource and returns meta data about any addresssed/binary properties
        Parameters:
        api - Api
        entityPath - String
      • inspectOperation

        public static ResourceOperation inspectOperation​(Class<?> resource,
                                                         Method aMethod,
                                                         org.springframework.http.HttpMethod httpMethod)
        Inspects the method and returns meta data about its operations
        Parameters:
        aMethod - Method
        httpMethod - HttpMethod
        Returns:
        ResourceOperation
      • validSuccessCode

        public static int validSuccessCode​(org.springframework.http.HttpMethod httpMethod,
                                           int success)
      • isDeleted

        public static boolean isDeleted​(Method method)
        Returns true if the method has been marked as deleted.
        Parameters:
        method - the method
        Returns:
        true - if is is marked as deleted.
      • isNoAuth

        public static boolean isNoAuth​(Method method)
        Returns true if the method has been marked as no auth required.
        Parameters:
        method - the method
        Returns:
        true - if is is marked as no auth required.
      • findMethod

        public static Method findMethod​(Class<? extends ResourceAction> resourceInterfaceWithOneMethod,
                                        Class<?> resource)
        Returns the method for the interface
        Returns:
        null or a Method
      • findEntityNameByAnnotationAttributes

        protected static String findEntityNameByAnnotationAttributes​(Map<String,​Object> annotAttribs)
        Finds the name of the entity using its annotation.
        Returns:
        the entity name/path
      • findEntityName

        protected static String findEntityName​(EntityResource entityAnnot)
        Finds the name of the entity using its annotation.
        Parameters:
        entityAnnot - EntityResource
        Returns:
        the entity name/path
      • findEntityCollectionNameName

        public static String findEntityCollectionNameName​(ResourceMetadata meta)
        Finds the name of the entity collection using the meta information.
        Parameters:
        meta - ResourceMetadata
        Returns:
        the entity name/path
      • findEmbeddedResources

        public static Map<String,​org.alfresco.util.Pair<String,​Method>> findEmbeddedResources​(Class<?> anyClass)
        For a given class, looks for @EmbeddedEntityResource annotations, using the annotation produce a Map of the property name key and the entity key
        Returns:
        A map of property key name and a value of the entity path name
      • inspectOperations

        public static void inspectOperations​(Api api,
                                             Class<?> resource,
                                             String entityPath,
                                             List<ResourceMetadata> metainfo)
        Inspect a resource to find operations on it.
        Parameters:
        api - Api
        entityPath - String
        metainfo - resource metadata
      • inspectApi

        public static Api inspectApi​(Class<?> resource)
        Inspects the resource to determine what api it belongs to. It does this by looking for the WebApi package annotation.
        Returns:
        Api
      • inspect

        public static List<ResourceMetadata> inspect​(Class resource)
        Inspects the annotated resource to understand its capabilities
        Parameters:
        resource - Class
      • findUniqueId

        public static String findUniqueId​(Object obj)
        Finds the unique id of an object using the @UniqueId annotation.
        Parameters:
        obj - any object
        Returns:
        a String object with the entity id set
      • findUniqueIdMethod

        public static Method findUniqueIdMethod​(Class<?> objClass)
                                         throws IllegalArgumentException
        Finds a single method with the @UniqueId annotation.
        Parameters:
        objClass - any object class
        Returns:
        the Method
        Throws:
        IllegalArgumentException - if there is is more than 1 method annotated with @UniqueId
      • findUniqueIdName

        public static String findUniqueIdName​(Method uniqueIdMethod)
        Finds the property name that is used as the unique id.
        Parameters:
        uniqueIdMethod - Method
        Returns:
        String the property name that is used as the unique id.