Class ResourceInspector


  • public class ResourceInspector
    extends java.lang.Object
    Looks at resources to see what they can do
    Author:
    Gethin James, janv
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Map<java.lang.String,​org.alfresco.util.Pair<java.lang.String,​java.lang.reflect.Method>> findEmbeddedResources​(java.lang.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
      static java.lang.String findEntityCollectionNameName​(ResourceMetadata meta)
      Finds the name of the entity collection using the meta information.
      protected static java.lang.String findEntityName​(EntityResource entityAnnot)
      Finds the name of the entity using its annotation.
      protected static java.lang.String findEntityNameByAnnotationAttributes​(java.util.Map<java.lang.String,​java.lang.Object> annotAttribs)
      Finds the name of the entity using its annotation.
      static java.lang.reflect.Method findMethod​(java.lang.Class<? extends ResourceAction> resourceInterfaceWithOneMethod, java.lang.Class<?> resource)
      Returns the method for the interface
      static java.lang.String findUniqueId​(java.lang.Object obj)
      Finds the unique id of an object using the @UniqueId annotation.
      static java.lang.reflect.Method findUniqueIdMethod​(java.lang.Class<?> objClass)
      Finds a single method with the @UniqueId annotation.
      static java.lang.String findUniqueIdName​(java.lang.reflect.Method uniqueIdMethod)
      Finds the property name that is used as the unique id.
      static java.util.List<ResourceMetadata> inspect​(java.lang.Class resource)
      Inspects the annotated resource to understand its capabilities
      static void inspectAddressedProperties​(Api api, java.lang.Class<?> resource, java.lang.String entityPath, java.util.List<ResourceMetadata> metainfo)
      Inspects the entity resource and returns meta data about any addresssed/binary properties
      static Api inspectApi​(java.lang.Class<?> resource)
      Inspects the resource to determine what api it belongs to.
      static ResourceOperation inspectOperation​(java.lang.Class<?> resource, java.lang.reflect.Method aMethod, org.springframework.http.HttpMethod httpMethod)
      Inspects the method and returns meta data about its operations
      static void inspectOperations​(Api api, java.lang.Class<?> resource, java.lang.String entityPath, java.util.List<ResourceMetadata> metainfo)
      Inspect a resource to find operations on it.
      static boolean isDeleted​(java.lang.reflect.Method method)
      Returns true if the method has been marked as deleted.
      static boolean isNoAuth​(java.lang.reflect.Method method)
      Returns true if the method has been marked as no auth required.
      static int validSuccessCode​(org.springframework.http.HttpMethod httpMethod, int success)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ResourceInspector

        public ResourceInspector()
    • Method Detail

      • inspectAddressedProperties

        public static void inspectAddressedProperties​(Api api,
                                                      java.lang.Class<?> resource,
                                                      java.lang.String entityPath,
                                                      java.util.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​(java.lang.Class<?> resource,
                                                         java.lang.reflect.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​(java.lang.reflect.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​(java.lang.reflect.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 java.lang.reflect.Method findMethod​(java.lang.Class<? extends ResourceAction> resourceInterfaceWithOneMethod,
                                                          java.lang.Class<?> resource)
        Returns the method for the interface
        Returns:
        null or a Method
      • findEntityNameByAnnotationAttributes

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

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

        public static java.lang.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 java.util.Map<java.lang.String,​org.alfresco.util.Pair<java.lang.String,​java.lang.reflect.Method>> findEmbeddedResources​(java.lang.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,
                                             java.lang.Class<?> resource,
                                             java.lang.String entityPath,
                                             java.util.List<ResourceMetadata> metainfo)
        Inspect a resource to find operations on it.
        Parameters:
        api - Api
        entityPath - String
        metainfo - resource metadata
      • inspectApi

        public static Api inspectApi​(java.lang.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 java.util.List<ResourceMetadata> inspect​(java.lang.Class resource)
        Inspects the annotated resource to understand its capabilities
        Parameters:
        resource - Class
      • findUniqueId

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

        public static java.lang.String findUniqueIdName​(java.lang.reflect.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.