Class DataRouteSupportUtil

java.lang.Object
com.broadleafcommerce.common.extension.data.DataRouteSupportUtil

public class DataRouteSupportUtil extends Object
Utility class for processing and handling of route scenarios at runtime.
Author:
Jeff Fischer
  • Constructor Details

    • DataRouteSupportUtil

      public DataRouteSupportUtil()
  • Method Details

    • processFirstOrOnce

      public static boolean processFirstOrOnce(@Nullable List<? extends DataRouteSupporting> supportingRoutes, @NonNull DataRouteSupportUtil.ConfirmingWork work, @NonNull Class<?>... refineTypes)
      Given a piece of confirming work, execute the work against the supplied routes looking for the first positive confirmation. However, if no routes are supplied, simply execute the work and return the response without route support. The ConfirmingWork implementation should take care to make its own validity determination and return immediately with false if it determines itself to not be qualified to execute against the current route.

      This case is considered special and is rarely used.
      Parameters:
      supportingRoutes - Optional list of DataRouteSupporting proxies.
      work - The task to perform.
      refineTypes - One or more specific DataRouteSupporting extension types to filter the supportingRoutes by.
      Returns:
      The result of the confirming work.
    • processAllOrOnce

      public static void processAllOrOnce(@Nullable List<? extends DataRouteSupporting> supportingRoutes, @NonNull DataRouteSupportUtil.VoidWork work, @NonNull Class<?>... refineTypes)
      Given a piece of void work, execute the work repeatedly against all the supplied routes. Or, if no routes are supplied, execute the work once with no routing support.
      Parameters:
      supportingRoutes - Optional list of DataRouteSupporting proxies.
      work - The task to perform.
      refineTypes - One or more specific DataRouteSupporting extension types to filter the supportingRoutes by.
    • processOnRoute

      public static boolean processOnRoute(@NonNull DataRouteSupportUtil.ConfirmingWork work, @Nullable DataRouteSupporting route)
      Given a piece of confirming work, execute the work against the supplied route. If no route is supplied, simply execute the work without route support.
      Parameters:
      work - The task to perform.
      route - The DataRouteSupporting proxy whose lookupKey is in effect during execution of the task.
      Returns:
      The result of the confirming work.
    • processOnRoute

      public static void processOnRoute(@NonNull DataRouteSupportUtil.VoidWork work, @Nullable DataRouteSupporting route)
      Given a piece of void work, execute the work against the supplied route. If no route is supplied, simply execute the work without route support.
      Parameters:
      work - The task to perform.
      route - The DataRouteSupporting proxy whose lookupKey is in effect during execution of the task.
    • processOnRoute

      public static <G extends Exception> void processOnRoute(@NonNull DataRouteSupportUtil.ThrowingVoidWork<G> work, @Nullable DataRouteSupporting route, Class<G> exceptionClass) throws G
      Given a piece of void work, execute the work against the supplied route. If no route is supplied, simply execute the work without route support.
      Type Parameters:
      G - The generic type of the checked exception.
      Parameters:
      work - The task to perform.
      route - The DataRouteSupporting proxy whose lookupKey is in effect during execution of the task.
      exceptionClass - The class of the checked exception that can be thrown by the task execution.
      Throws:
      G - The generic type of the checked exception.
    • processOnRoute

      public static Object processOnRoute(@NonNull DataRouteSupportUtil.ReturningWork work, @Nullable DataRouteSupporting route)
      Given a piece of returning work, execute the work against the supplied route. If no route is supplied, simply execute the work without route support.
      Parameters:
      work - The task to perform.
      route - The DataRouteSupporting proxy whose lookupKey is in effect during execution of the task.
      Returns:
      The response returned from the task execution.
    • proxyForDataRoute

      public static <T> T proxyForDataRoute(@NonNull T bean, @Nullable DataRouteSupporting route)
      Given a component, wrap the component in an AOP proxy that will guarantee any call on the component's API will have the DataRouteSupporting.getLookupKey() set on DataRouteContext.setLookupKey(String) during execution.
      Type Parameters:
      T - The generic type of the bean.
      Parameters:
      bean - The bean instance to wrap in a proxy.
      route - The route whose lookup key is to be used.
      Returns:
      The proxied bean instance.
    • findMembersInScopeByFragment

      public static <T> List<T> findMembersInScopeByFragment(@NonNull List<T> beans, @Nullable DataRouteReference reference, @NonNull String fragment)
      Given a list of bean instances, filter the list based on the package fragment identifying the current flow. This is useful in identifying beans contributed from multiple routes that all participate in pipeline style processing. When on a subset of the processing beans should be used for a particular flow, this method can filter the superset to achieve the right mix. Note, this method is sophisticated enough to include beans defined in common libraries that cross-cut multiple services, as well as those defined specifically in the service itself.
      Type Parameters:
      T - The generic type of the processing components.
      Parameters:
      beans - The list of processing components that should be filtered for the current flow.
      reference - Used to help look up routes based on the fragment.
      fragment - Package fragment identifying the current flow.
      Returns:
      The filtered list.
    • findMembersInScopeByExample

      public static <T> List<T> findMembersInScopeByExample(@NonNull List<T> beans, @Nullable DataRouteReference reference, @NonNull Class<?> example)
      Given a list of bean instances, filter the list based on the example class' package name, which is used to identity the package fragment for the current flow. This is useful in identifying beans contributed from multiple routes that all participate in pipeline style processing. When on a subset of the processing beans should be used for a particular flow, this method can filter the superset to achieve the right mix. Note, this method is sophisticated enough to include beans defined in common libraries that cross-cut multiple services, as well as those defined specifically in the service itself.
      Type Parameters:
      T - The generic type of the processing components.
      Parameters:
      beans - The list of processing components that should be filtered for the current flow.
      reference - Used to help look up routes based on the fragment.
      example - Class whose package name is used to identify the package fragment for the current flow.
      Returns:
      The filtered list.
    • getBestMatchInRoute

      public static <T> T getBestMatchInRoute(@NonNull List<T> beans, @Nullable DataRouteReference reference, T defaultBean)
      Using the current DataRouteContext.getLookupKey() to match a DataRouteSupporting, and find the first bean whose whose class package name has a package fragment match. If no match is found, or the reference param is null, return the default bean.
      Type Parameters:
      T - The type of the bean.
      Parameters:
      beans - The list of beans to filter to the best single match.
      reference - Used to help look up routes based on the fragment.
      defaultBean - The bean to return if no match is found.
      Returns:
      The filtered bean instance.
    • getLookupKeyOnRoute

      public static Optional<String> getLookupKeyOnRoute()
      Check for a current, active DataRouteContext, and return the lookupKey if available.
      Returns:
      The active DataRouteContext.getLookupKey(), if available.