Class RequestHelper

java.lang.Object
co.ecg.alpaca.toolkit.messaging.request.RequestHelper

public class RequestHelper extends Object
The Request Helper class contains methods to assist in the generation of Requests objects that will be sent to the BroadWorksServer.
Author:
Matthew Keathley
  • Constructor Details

    • RequestHelper

      public RequestHelper()
  • Method Details

    • requestPerObjectProducer

      public static <R extends Response, T extends BroadWorksObject> void requestPerObjectProducer(BroadWorksServer bws, List<T> objects, Class<? extends BroadWorksObject> typeParameterClass, Class<? extends Request<R>> request, BiConsumer<T,R> consumer, String... expectedErrorCodes) throws RequestException
      Performs a Request using the provided BroadWorksServer across a list of BroadWorksObject taking the request as a single argument.
      Type Parameters:
      R - The Response type.
      T - The BroadWorksObject type.
      Parameters:
      bws - The BroadWorksServer for the procedure.
      objects - The list of objects to invoke the Request.
      typeParameterClass - The BroadWorksObject class.
      request - The Request class.
      consumer - The consumer to accept responses as they are returned.
      Throws:
      RequestException - Thrown if an error occurs while running the process.
    • requestPerObjectProducer

      public static <R extends Response, T extends BroadWorksObject> void requestPerObjectProducer(BroadWorksServer bws, List<T> objects, Class<? extends BroadWorksObject> typeParameterClass, Class<? extends Request<R>> request, BiConsumer<T,R> consumer) throws RequestException
      Performs a Request using the provided BroadWorksServer across a list of BroadWorksObject taking the request as a single argument.
      Type Parameters:
      R - The Response type.
      T - The BroadWorksObject type.
      Parameters:
      bws - The BroadWorksServer for the procedure.
      objects - The list of objects to invoke the Request.
      typeParameterClass - The BroadWorksObject class.
      request - The Request class.
      consumer - The consumer to accept responses as they are returned.
      Throws:
      RequestException - Thrown if an error occurs while running the process.
    • requestPerObjectProducer

      public static <S extends Request<R>, R extends Response, T extends BroadWorksObject> void requestPerObjectProducer(BroadWorksServer bws, List<T> objects, Class<? extends BroadWorksObject> typeParameterClass, Class<S> request, UnaryOperator<S> operator, BiConsumer<T,R> consumer, String... expectedErrorCodes) throws RequestException
      Performs a Request using the provided BroadWorksServer across a list of BroadWorksObject taking the request as a single argument.
      Type Parameters:
      R - The Response type.
      T - The BroadWorksObject type.
      Parameters:
      bws - The BroadWorksServer for the procedure.
      objects - The list of objects to invoke the Request.
      typeParameterClass - The BroadWorksObject class.
      request - The Request class.
      operator - The operator to modify each request prior to processing.
      consumer - The consumer to accept responses as they are returned.
      Throws:
      RequestException - Thrown if an error occurs while running the process.
    • requestPerStringProducer

      public static <S extends Request<R>, R extends Response> void requestPerStringProducer(BroadWorksServer broadWorksServer, List<String> strings, Class<S> requestClass, UnaryOperator<S> operator, BiConsumer<String,R> consumer, String... expectedErrorCodes) throws RequestException
      Performs a Request using the provided BroadWorksServer across a list of String taking the request as a single argument.
      Type Parameters:
      R - The Response type.
      Parameters:
      broadWorksServer - The BroadWorksServer for the procedure.
      strings - The list of Strings to invoke the Request.
      requestClass - The Request class.
      operator - The operator to modify each request prior to processing.
      consumer - The consumer to accept responses as they are returned.
      expectedErrorCodes - The list of expected error codes. If one of these occurs, the error will be ignored.
      Throws:
      RequestException - Thrown if an error occurs while running the process.
    • getResponsePerObjectMap

      public static <R extends Response, T extends BroadWorksObject> Map<T,R> getResponsePerObjectMap(BroadWorksServer bws, List<T> objects, Class<T> typeParameterClass, Class<? extends Request<R>> request) throws RequestException
      Performs a Request using the provided BroadWorksServer across a list of BroadWorksObject taking the request as a single argument and returns the responses in a Map.
      Type Parameters:
      R - The Response type.
      T - The BroadWorksObject type.
      Parameters:
      bws - The BroadWorksServer for the procedure.
      objects - The list of objects to invoke the Request.
      typeParameterClass - The BroadWorksObject class.
      request - The Request class.
      Returns:
      A HashMap of objects to their responses
      Throws:
      RequestException - Thrown if an error occurs while running the process.
    • mapObjects

      public static <E> E mapObjects(E output, Object input) throws RequestException
      Maps two objects by copying 'get' and 'is' methods to matching 'set' methods. This method requires that naming conventions are used.
      Type Parameters:
      E - The output object type.
      Parameters:
      output - The returned object whose fields are modified.
      input - The input object to copy fields from.
      Returns:
      Returns the output object with the fields modified.
      Throws:
      RequestException - Thrown if there the input or output is NULL or if there is a fatal error during mapping.
    • mapObjects

      public static <E> E mapObjects(E output, Object input, boolean mapNullValues) throws RequestException
      Maps two objects by copying 'get' and 'is' methods to matching 'set' methods. This method requires that naming conventions are used.
      Type Parameters:
      E - The output object type.
      Parameters:
      output - The returned object whose fields are modified.
      input - The input object to copy fields from.
      mapNullValues - Sets whether NULL values should be mapped to their corresponding setters.
      Returns:
      Returns the output object with the fields modified.
      Throws:
      RequestException - Thrown if there the input or output is NULL or if there is a fatal error during mapping.
    • mapObjectToRequest

      public static <R extends Request<?>, O extends BroadWorksObject> R mapObjectToRequest(R request, O object) throws RequestException
      Method to map the fields of a BroadWorksObject onto a given request. This would typically be used to Map an object onto a new add or modify request before making the expected changes.
      Type Parameters:
      R - The Request type
      O - The BroadWorksObject type
      Parameters:
      request - The request to map the fields onto.
      object - The object to retrieve available fields.
      Returns:
      Returns the request object with the fields populated.
      Throws:
      RequestException - Thrown if there the input or output is NULL or if there is a fatal error during mapping.