Access Refiner through StreamLink

Client applications use the StreamLink API to send Caplin Refiner filter and sort requests. Here's an example of how to do this.

The example's written in Java, using the StreamLink Java API. The filter and sort criteria follow the rules explained in How can I... Filter and Sort in Refiner.

The relevant classes are:

  • caplin.streamlink.ContainerSubscriptionParameters,
  • caplin.streamlink.ContainerFilterFactory
  • caplin.streamlink.​FilterExpression.

You build filter expressions in an instance of FilterExpression that's returned by ContainerFilterFactory. Use the select() method of ContainerSubscriptionParameters to add in any sorting and grouping criteria, and then subscribe to the container, passing the ContainerSubscriptionParameters in the subscription request. The request is then routed to Refiner. 

The example shows how to build the filter expression (FIELD1 > 0.1) & (FIELD3 = "ab") and request that the results be sorted in ascending order of the text field FIELD1

// Get an instance of ContainerSubscriptionParameters
​ContainerSubscriptionParameters containerSubscriptionParameters = streamLink.createContainerSubscriptionParameters();

// Create the filter expression FIELD1 > 0.1​
FilterExpression exp1 = ContainerFilterFactory.create("FIELD1", FilterExpressionOperator.GREATER_THAN, "0.1");

// Create the filter expression FIELD3 = "ab"​
FilterExpression exp2 = ContainerFilterFactory.create("FIELD3", FilterExpressionOperator.EQUAL, "ab");

// Create the combined filter expression (FIELD1 > 0.1) & (FIELD3 = "ab")​
FilterExpression exp1Andexp2 = ContainerFilterFactory.createLogical(FilterExpressionLogicalOperator.AND, exp1, exp2);

// Convert the filter expression to a string for submission to Refiner.
// Also specify an ascending text sort on the field "FIELD3"
// The results aren't grouped (third argument is null)
containerSubscriptionParameters.select(exp1Andexp2.toFilterString(), "FIELD1 ASC TEXT", null);

//Send the subscription request to Liberator, and hence on to Refiner in Transformer
Subscription subscription = streamlink.subscribe("/container", subscriptionListener, containerSubscriptionParameters);

If you only want to sort and/or group the container contents without filtering them, just specify the filter string argument of containerSubscriptionParameters.select() (the first argument) as null:

containerSubscriptionParameters.select(null, "FIELD1 ASC TEXT", "FIELD4"); 
Subscription subscription = streamlink.subscribe("/container", \subscriptionListener, containerSubscriptionParameters);

In Refiner 7.0.0 and later, you can sort on multiple fields. In the select() method of ContainerSubscriptionParameters, you supply the sort criteria separated by a comma.  Here's an example where the sort is on the fields FIELD1 (text, ascending order) and FIELD2 (numeric, descending order):

containerSubscriptionParameters.select(null, "FIELD1 ASC TEXT,FIELD2 DESC NUMBER", "FIELD4"); 

Subscription subscription = streamlink.subscribe("/container", \containerSubscriptionParameters.select(null, "field1 ASC TEXT,field2 DESC NUMBER", "field1"); ​subscriptionListener, containerSubscriptionParameters);
Tip: The exact way in which your client application should set up filter and sort criteria for Refiner depends on which StreamLink API you are using. For details, consult the API Reference document for your particular client implementation language and operating system platform (StreamLink JS, StreamLink Java, StreamLink iOS, and so on).
Tip: For information about how Caplin Trader uses Refiner to sort and filter data in grids, see How Can I...  Configure sorting and filtering (in Caplin Trader 4 grids).

See also: