Extending an Adapter

Following on the previous training module — Creating a RET Adapter — we will now extend the Calendar Adapter to generate some new, customised behaviour. Extension points are a key feature in RET Adapter development as they enable you to extend a function or a feature belonging to an adapter, to suit your own needs. Convenient extension points exist throughout the adapter code, in this module we will look at exposing some, and using them to modify the behaviour of the Calendar Adapter.

Objectives

You are going to change the default behaviour of the calendar adapter by configuring an extension point, where you will:

  • Create an extension point that will modify tenor dates
  • Test the new extension by making and viewing subject requests in the Liberator Explorer

Extension points are adapter features which can be overridden by custom code that is loaded via a configuration class. Each extension point is defined by an interface. This interface is used to determine the behaviour of that particular feature.

Configuring an extension point

All adapters available with the RET Adapter Suite are configured in the same way, where extensions are added via methods on an interface.  In the case of the Calendar Adapter, a builder named CalendarConfigurationBuilder is created by calling the newConfigurationBuilder()method on CalendarConfiguration - extensions are then called via this method. Once all extensions have been set up, we call build() on the builder to create a CalendarConfiguration object. 

All extension points have a default implementation. So the class CalendarAdapterExample would run according to its default behaviour - with the following as its main method:

new CalendarAdapter().start()

Take a look at the CalendarAdapterExample class in your Calendar Adapter workspace. This class creates a  CalendarConfigurationBuilder and also adds two custom implementations to your configuration. The CalendarConfiguration should be passed as an argument in to the CalendarAdapter constructor when any defaults have been overridden. When start() is called the adapter will be initialised, and the extensions as well as any other defaults will be created:

CalendarConfiguration calendarConfiguration = CalendarConfiguration.newConfigurationBuilder()
                    .setUserManager(new FileBasedUserManager())
                    .setDataTransformer(new ExampleDataTransformer())
                    .build();
                    
CalendarAdapter adapter = new CalendarAdapter(calendarConfiguration);
adapter.start();

The source code for the default extensions can be found in <RETAdapterToolikt>/src/, and serves as a useful starting-point for development.

Extending the Calendar

The Reuters Electronic Trading - Automated Dealing (RET-AD) system responds to requests for settlement and tenor dates with a set of ISO 8601 formatted dates. The CalendarDataTransformer extension allows us to make changes to these dates in more or less any way we like, however it is particularly useful for altering data formats that are to be sent to the client. With the following instructions we are going to make a small change to the format of tenor dates:

Follow the steps below:

  1. Begin by opening the file src/main/java/com/caplin/example/ret/ExampleDataTransformer.java

  2. Next, you will transform the date string values in the Tenor String map — tenorDates — using a method that can be used to transform the String map. Instead of an ISO 8601 date format, you will provide dates in the format year/day-of-year.

    Do this by updating the onTenorDatesReceived()method with the following code:

    @Override
    public Map<Tenor, String> onTenorDatesReceived(String currencyPair, Map<Tenor, String> tenorDates) {
        for (Map.Entry<Tenor, String> date : tenorDates.entrySet()) {
            try {
                Date retDate = ISO_FORMAT.parse(date.getValue());
                date.setValue(CUSTOM_FORMAT.format(retDate));
            } catch (ParseException ignored) {}
        }
        return tenorDates;
    }

    Save the file when you're done!

  3. Open a command-line interface and rebuild the adapter by executing the following command:

    java -jar <cis-blade-toolkit> build CalendarAdapter
  4. Now run the adapter using this command:

    java -jar <cis-blade-toolkit> run CalendarAdapter -m com.caplin.example.ret.CalendarAdapterExample

    The adapter is now ready to receive a request!

  5. Finally, you will test the changes you just made using the Liberator Explorer. Navigate to http://localhost:18080/ and click on Diagnostics above, then click on the liberatorexplorer URL link. Note: If prompted for a username/password this will be admin/admin.

    Now, in the field labelled 'Record' type /CALENDAR/TENORDATES/GBPUSD and press Go. This will make a request to the Calendar Adapter to send back Tenor Dates for GBPUSD in your newly defined format.

    You can view the changes to fields in the Tenor column.

Making and Receiving Requests

A simple way to test an adapter is to make a request via the Liberator Explorer as you did earlier with Tenor formats. However,  a permissions level might be required when making such requests. In this part we will look at making changes to user permissions by assigning groups.

Follow the steps below:

  1. Open the Liberator explorer and log in as an Admin. Do this by navigating to http://localhost:18080/ and clicking on Diagnostics above, then click on the liberatorexplorer URL link. If you are prompted for a username/password this will be admin/admin.
  2. Next, open the file logins.xml in the Permissioning Adapter and add the group Global to the admin users's set of groups. It should be similar to the following:

    <admins>
        <user ssoName="admin" password="admin" groups="Global LiberatorStatus" />
    </admins>
  3. Restart the Permissioning Adapter and Liberator. Do this by opening a Cygwin console on your machine and navigating to your Deployment Framework's topmost directory.​ Then execute the following command:

    ./dfw start

    More information on this process is available in this guide: Start and stop components and blades

  4. Finally, navigate back to the Liberator Explorer (Step 1). In the record field, enter the subject /CALENDAR/TENORDATES/GBPUSD. You should then receive a response with your custom formatted data (from previous instructions) in the Tenor field.  

The subject /CALENDAR/TENORDATES can be configured in the file <workspace>/CalendarAdapter/Blade/overrides/CalendarAdapter/Liberator/etc/rttpd.conf