Class RequestHelper
java.lang.Object
co.ecg.alpaca.toolkit.messaging.request.RequestHelper
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <R extends Response,
T extends BroadWorksObject>
Map<T,R> getResponsePerObjectMap
(BroadWorksServer bws, List<T> objects, Class<T> typeParameterClass, Class<? extends Request<R>> request) Performs aRequest
using the providedBroadWorksServer
across a list ofBroadWorksObject
taking the request as a single argument and returns the responses in a Map.static <E> E
mapObjects
(E output, Object input) Maps two objects by copying 'get' and 'is' methods to matching 'set' methods.static <E> E
mapObjects
(E output, Object input, boolean mapNullValues) Maps two objects by copying 'get' and 'is' methods to matching 'set' methods.static <R extends Request<?>,
O extends BroadWorksObject>
RmapObjectToRequest
(R request, O object) Method to map the fields of a BroadWorksObject onto a given request.static <R extends Response,
T extends BroadWorksObject>
voidrequestPerObjectProducer
(BroadWorksServer bws, List<T> objects, Class<? extends BroadWorksObject> typeParameterClass, Class<? extends Request<R>> request, BiConsumer<T, R> consumer) Performs aRequest
using the providedBroadWorksServer
across a list ofBroadWorksObject
taking the request as a single argument.static <R extends Response,
T extends BroadWorksObject>
voidrequestPerObjectProducer
(BroadWorksServer bws, List<T> objects, Class<? extends BroadWorksObject> typeParameterClass, Class<? extends Request<R>> request, BiConsumer<T, R> consumer, String... expectedErrorCodes) Performs aRequest
using the providedBroadWorksServer
across a list ofBroadWorksObject
taking the request as a single argument.static <S extends Request<R>,
R extends Response, T extends BroadWorksObject>
voidrequestPerObjectProducer
(BroadWorksServer bws, List<T> objects, Class<? extends BroadWorksObject> typeParameterClass, Class<S> request, UnaryOperator<S> operator, BiConsumer<T, R> consumer, String... expectedErrorCodes) Performs aRequest
using the providedBroadWorksServer
across a list ofBroadWorksObject
taking the request as a single argument.requestPerStringProducer
(BroadWorksServer broadWorksServer, List<String> strings, Class<S> requestClass, UnaryOperator<S> operator, BiConsumer<String, R> consumer, String... expectedErrorCodes) Performs aRequest
using the providedBroadWorksServer
across a list ofString
taking the request as a single argument.
-
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 RequestExceptionPerforms aRequest
using the providedBroadWorksServer
across a list ofBroadWorksObject
taking the request as a single argument.- Type Parameters:
R
- TheResponse
type.T
- TheBroadWorksObject
type.- Parameters:
bws
- The BroadWorksServer for the procedure.objects
- The list of objects to invoke theRequest
.typeParameterClass
- TheBroadWorksObject
class.request
- TheRequest
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 RequestExceptionPerforms aRequest
using the providedBroadWorksServer
across a list ofBroadWorksObject
taking the request as a single argument.- Type Parameters:
R
- TheResponse
type.T
- TheBroadWorksObject
type.- Parameters:
bws
- The BroadWorksServer for the procedure.objects
- The list of objects to invoke theRequest
.typeParameterClass
- TheBroadWorksObject
class.request
- TheRequest
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, void requestPerObjectProducerT extends BroadWorksObject> (BroadWorksServer bws, List<T> objects, Class<? extends BroadWorksObject> typeParameterClass, Class<S> request, UnaryOperator<S> operator, BiConsumer<T, R> consumer, String... expectedErrorCodes) throws RequestExceptionPerforms aRequest
using the providedBroadWorksServer
across a list ofBroadWorksObject
taking the request as a single argument.- Type Parameters:
R
- TheResponse
type.T
- TheBroadWorksObject
type.- Parameters:
bws
- The BroadWorksServer for the procedure.objects
- The list of objects to invoke theRequest
.typeParameterClass
- TheBroadWorksObject
class.request
- TheRequest
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 RequestExceptionPerforms aRequest
using the providedBroadWorksServer
across a list ofString
taking the request as a single argument.- Type Parameters:
R
- TheResponse
type.- Parameters:
broadWorksServer
- The BroadWorksServer for the procedure.strings
- The list of Strings to invoke theRequest
.requestClass
- TheRequest
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 aRequest
using the providedBroadWorksServer
across a list ofBroadWorksObject
taking the request as a single argument and returns the responses in a Map.- Type Parameters:
R
- TheResponse
type.T
- TheBroadWorksObject
type.- Parameters:
bws
- The BroadWorksServer for the procedure.objects
- The list of objects to invoke theRequest
.typeParameterClass
- TheBroadWorksObject
class.request
- TheRequest
class.- Returns:
- A HashMap of objects to their responses
- Throws:
RequestException
- Thrown if an error occurs while running the process.
-
mapObjects
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
- TheRequest
typeO
- TheBroadWorksObject
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.
-