Odata Olingo lib JAVA

Hi,


I am trying to use Apache Olingo library(java based) for consuming the DSS REST API. I am not able to find any examples or documentation to do that. Wanted to check if someone has used this before.

Code Sample:

Just doing a POC to write an equivalent code using Apache Olingo for the below DSS2Java Example


/**
* This is a composite On Demand Extraction Request
*
* Here is the reference doc for the Async mechanism:
* https://hosted.datascopeapi.reuters.com/RestApi.Help/Home/KeyMechanisms#sectionAsync
*
*/
public void compositeRequest() {

try {
HttpPost httppost = new HttpPost(urlHost + "/Extractions/ExtractWithNotes");

httppost.addHeader("content-type", "application/json;odata.metadata=minimal");
httppost.addHeader("Authorization", "Token " + sessionToken);
// Use the 1st line for your program, the 2nd line to test a timeout (HTTP status 202):
httppost.addHeader("Prefer", "respond-async");
//httppost.addHeader("Prefer", "respond-async, wait=5");

JSONOrderedObject compositeExtractJSONObject = new JSONOrderedObject()
.put("ExtractionRequest", new JSONOrderedObject()
.put("@odata.type", "#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.CompositeExtractionRequest")
.put("ContentFieldNames", new JSONArray()
.put("RIC")
.put("CUSIP")
.put("ISIN")
.put("SEDOL")
.put("Issuer OrgID")
.put("Currency Code")
.put("Annualized Dividend Period Start Date")
.put("Annualized Dividend Adjusted Gross Amount")
.put("Balance Sheet - Enterprise Value")
.put("Balance Sheet - Market Value"))
.put("IdentifierList", new JSONOrderedObject()
.put("@odata.type", "#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.InstrumentIdentifierList")
.put("InstrumentIdentifiers", new JSONArray()
.put(new JSONObject()
.put("Identifier", "00209tab1")
.put("IdentifierType", "Cusip"))
.put(new JSONObject()
.put("Identifier", "IBM.N")
.put("IdentifierType", "Ric"))
.put(new JSONObject()
.put("Identifier", "US4592001014")
.put("IdentifierType", "Isin"))
.put(new JSONObject()
.put("Identifier", "B1YW440")
.put("IdentifierType", "Sedol")))));

System.out.println("Composite extraction JSON request content:\n"+ compositeExtractJSONObject.toString() +"\n");
StringEntity requestBody = new StringEntity(compositeExtractJSONObject.toString());

httppost.setEntity(requestBody);

// NOTE: If the extraction request takes more than 30 seconds the async mechanism will be used.
System.out.println("We submit the request, a response should arrive in approximately 30 seconds ...\n");
HttpResponse response = httpclient.execute(httppost);

StringBuffer result = new StringBuffer();

// Get the response status code
int respStatusCode = response.getStatusLine().getStatusCode();


Sample Code using Olingo: (Snapshot)

ODataClient client = ODataClientFactory.getClient();


client.getConfiguration()
.setHttpClientFactory(new BasicAuthHttpClientFactory("<username>", "<password>"));




ODataRetrieveRequest<ClientEntitySet> request = client.getRetrieveRequestFactory()
.getEntitySetRequest(client.newURIBuilder(urlHost)
.appendActionCallSegment("Extractions/CompositeExtractionRequest")
.build());

/request.addCustomHeader("Authorization", "Token <token>");
final ODataRetrieveResponse<ClientEntitySet> response = request.execute();
final ClientEntitySet entitySet = response.getBody();
System.out.println(entitySet);

Best Answer

  • Jirapongse
    Jirapongse ✭✭✭✭✭
    Answer ✓

    @srinivastemburni

    I am also new to Apache Olingo. After trying to use it for a while, the code could be like this:

        public void CompositeExtractionRequest() {
             ClientEntity newEntity = client.getObjectFactory().newEntity(new FullQualifiedName("ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.CompositeExtractionRequest"));
             
             newEntity.getProperties()
                 .add(client.getObjectFactory().newComplexProperty("ExtractionRequest",
                         client.getObjectFactory().newComplexValue("ExtractionRequest")
                         .add(client.getObjectFactory().newPrimitiveProperty("@odata.type", client.getObjectFactory().newPrimitiveValueBuilder().buildString("#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.CompositeExtractionRequest")))
                         .add(client.getObjectFactory().newCollectionProperty("ContentFieldNames", client.getObjectFactory().newCollectionValue("ContentFieldNames")
                                 .add(client.getObjectFactory().newPrimitiveValueBuilder().buildString("RIC"))
                                 .add(client.getObjectFactory().newPrimitiveValueBuilder().buildString("CUSIP"))
                                 .add(client.getObjectFactory().newPrimitiveValueBuilder().buildString("ISIN"))
                                 .add(client.getObjectFactory().newPrimitiveValueBuilder().buildString("SEDOL"))
                                 .add(client.getObjectFactory().newPrimitiveValueBuilder().buildString("Issuer OrgID"))
                                 .add(client.getObjectFactory().newPrimitiveValueBuilder().buildString("Currency Code"))
                                 .add(client.getObjectFactory().newPrimitiveValueBuilder().buildString("Annualized Dividend Period Start Date"))
                                 .add(client.getObjectFactory().newPrimitiveValueBuilder().buildString("Annualized Dividend Adjusted Gross Amount"))
                                 .add(client.getObjectFactory().newPrimitiveValueBuilder().buildString("Balance Sheet - Enterprise Value"))
                                 .add(client.getObjectFactory().newPrimitiveValueBuilder().buildString("Balance Sheet - Market Value"))
                         ))
                         .add(client.getObjectFactory().newComplexProperty("IdentifierList", client.getObjectFactory().newComplexValue("IdentifierList")
                                 .add(client.getObjectFactory().newPrimitiveProperty("@odata.type", client.getObjectFactory().newPrimitiveValueBuilder().buildString("#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.InstrumentIdentifierList")))
                                 .add(client.getObjectFactory().newCollectionProperty("InstrumentIdentifiers", client.getObjectFactory().newCollectionValue("InstrumentIdentifiers")
                                         .add(client.getObjectFactory().newComplexValue("Ident1")
                                             .add(client.getObjectFactory().newPrimitiveProperty("Identifier", client.getObjectFactory().newPrimitiveValueBuilder().buildString("00209tab1")))
                                             .add(client.getObjectFactory().newPrimitiveProperty("IdentifierType", client.getObjectFactory().newPrimitiveValueBuilder().buildString("Cusip")))
                                             )
                                         .add(client.getObjectFactory().newComplexValue("Ident2")
                                             .add(client.getObjectFactory().newPrimitiveProperty("Identifier", client.getObjectFactory().newPrimitiveValueBuilder().buildString("IBM.N")))
                                             .add(client.getObjectFactory().newPrimitiveProperty("IdentifierType", client.getObjectFactory().newPrimitiveValueBuilder().buildString("Ric")))
                                             )
                                         .add(client.getObjectFactory().newComplexValue("Ident3")
                                             .add(client.getObjectFactory().newPrimitiveProperty("Identifier", client.getObjectFactory().newPrimitiveValueBuilder().buildString("US4592001014")))
                                             .add(client.getObjectFactory().newPrimitiveProperty("IdentifierType", client.getObjectFactory().newPrimitiveValueBuilder().buildString("Isin")))
                                             )
                                         .add(client.getObjectFactory().newComplexValue("Ident4")
                                             .add(client.getObjectFactory().newPrimitiveProperty("Identifier", client.getObjectFactory().newPrimitiveValueBuilder().buildString("B1YW440")))
                                             .add(client.getObjectFactory().newPrimitiveProperty("IdentifierType", client.getObjectFactory().newPrimitiveValueBuilder().buildString("Sedol")))
                                             )
                                         )
                                         )
                                 )
                                 )
                         ));
             
              ODataEntityCreateRequest<ClientEntity> createRequest = client.getCUDRequestFactory().getEntityCreateRequest(
                        client.newURIBuilder(serviceUrl).appendEntitySetSegment("Extractions/ExtractWithNotes").build(),
                        newEntity);
                createRequest.addCustomHeader("Authorization", "Token "+token);
                ODataEntityCreateResponse<ClientEntity> createResponse = createRequest.execute();
                ClientEntity createdEntity = createResponse.getBody();
                System.out.println(createdEntity.toString());
        }

    The full example is olingoexamplejava.txt

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.