Class ExpansionHandler

  • All Implemented Interfaces:
    RuleProvider.RuleChangesObserver

    public class ExpansionHandler
    extends Object
    implements RuleProvider.RuleChangesObserver
    The ExpansionHandler allows to fetch multiple a collection of multiple resources in a single GET request. To use the ExpansionHandler the parameter expand=x has to be added. Having a request to a resource defining a collection of resources like this:
     {"acls":["admin","developer"]}
     
    Would lead to a result like this:
     {
      "acls" : {
        "admin" : {
          "all.edit": {
            "methods": [
              "GET",
              "PUT",
              "POST",
              "DELETE"
            ],
            "path": "/.*"
          }
        },
        "developer" : {
          "role_1.menu.display": {},
          "role_2.menu.display": {},
          "gateleen.admin.menu": {}
        }
      }
     }
     
    Author:
    https://github.com/mcweba [Marc-Andre Weber], https://github.com/ljucam [Mario Ljuca]
    • Constructor Detail

      • ExpansionHandler

        public ExpansionHandler​(io.vertx.core.Vertx vertx,
                                org.swisspush.gateleen.core.storage.ResourceStorage storage,
                                io.vertx.core.http.HttpClient httpClient,
                                Map<String,​Object> properties,
                                String serverRoot,
                                String rulesPath)
        Creates a new instance of the ExpansionHandler.
        Parameters:
        vertx - vertx
        storage - storage
        httpClient - httpClient
        properties - properties
        serverRoot - serverRoot
        rulesPath - rulesPath
    • Method Detail

      • getMaxExpansionLevelSoft

        public int getMaxExpansionLevelSoft()
      • getMaxExpansionLevelHard

        public int getMaxExpansionLevelHard()
      • getMaxSubRequestCount

        public int getMaxSubRequestCount()
      • isExpansionRequest

        public boolean isExpansionRequest​(io.vertx.core.http.HttpServerRequest request)
        Returns true when the ExpansionHandler can deal with the given request. The request must be a GET request and must have the parameter expand=x. The method called after this check must be handleExpansionRecursion( ... ).
        Parameters:
        request - request
        Returns:
        boolean
      • isBackendExpand

        protected boolean isBackendExpand​(String uri)
        Check to see whether this request will be expanded by the backend (and therefore the expansionhandler won't do anything).
        Parameters:
        uri - uri to check against the internal list of expandOnBackend urls
        Returns:
        boolean and true if the expand should be done by the backend
      • isStorageExpand

        protected boolean isStorageExpand​(String uri)
        Check to see whether this request is a storageExpand request (will be expanded by in the storage) (and therefore the expansionhandler won't do the subrequests by itself).
        Parameters:
        uri - uri to check against the internal list of storageExpand urls
        Returns:
        boolean and true if the expand should be done in the storage
      • isZipRequest

        public boolean isZipRequest​(io.vertx.core.http.HttpServerRequest request)
        Returns true when the ExpansionHandler can deal with the given request. The request must be a GET request and must have the parameter expand=x&zip=true. The method called after this check must be handleZipRecursion( ... ).
        Parameters:
        request - request
        Returns:
        boolean
      • handleExpansionRecursion

        public void handleExpansionRecursion​(io.vertx.core.http.HttpServerRequest request)
        Handles the request as if it is a recursive expansion.
        Parameters:
        request - request
      • handleZipRecursion

        public void handleZipRecursion​(io.vertx.core.http.HttpServerRequest request)
        Handles the request as if it is a request for a zip stream.
        Parameters:
        request - request
      • isCollection

        public boolean isCollection​(String target)
        Returns true if the given name or path belongs to a collection. In this case ends with a slash.
        Parameters:
        target - target
        Returns:
        boolean