Search in sources :

Example 1 with ClientEntitySetIterator

use of org.apache.olingo.client.api.domain.ClientEntitySetIterator in project tdi-studio-se by Talend.

the class DynamicsCRMClient method getEntityType.

/**
     * Get entity type by EntitySet name
     * 
     * @param entitySetName
     * @return entity type value
     */
public String getEntityType(String entitySetName) {
    // TODO need to check whether have another better way
    URIBuilder uriBuilder = odataClient.newURIBuilder(serviceRootURL).appendEntitySetSegment("EntityDefinitions");
    uriBuilder.addQueryOption(QueryOption.SELECT, "EntitySetName,LogicalName");
    uriBuilder.filter("EntitySetName eq '" + entitySetName + "'");
    ODataEntitySetIteratorRequest<ClientEntitySet, ClientEntity> request = odataClient.getRetrieveRequestFactory().getEntitySetIteratorRequest(uriBuilder.build());
    request.addCustomHeader(HttpHeader.AUTHORIZATION, "Bearer " + authResult.getAccessToken());
    ODataRetrieveResponse<ClientEntitySetIterator<ClientEntitySet, ClientEntity>> response = request.execute();
    try {
        ClientEntitySetIterator<ClientEntitySet, ClientEntity> entitySetIterator = response.getBody();
        if (entitySetIterator.hasNext()) {
            ClientProperty localName = entitySetIterator.next().getProperty("LogicalName");
            if (localName != null && localName.getValue() != null) {
                return localName.getValue().toString();
            }
        }
    } finally {
        response.close();
        // Close reponse would also close connection. So here need recreate httpclient
        httpClient = null;
    }
    return null;
}
Also used : ClientEntity(org.apache.olingo.client.api.domain.ClientEntity) ClientProperty(org.apache.olingo.client.api.domain.ClientProperty) ClientEntitySetIterator(org.apache.olingo.client.api.domain.ClientEntitySetIterator) URIBuilder(org.apache.olingo.client.api.uri.URIBuilder) ClientEntitySet(org.apache.olingo.client.api.domain.ClientEntitySet)

Aggregations

ClientEntity (org.apache.olingo.client.api.domain.ClientEntity)1 ClientEntitySet (org.apache.olingo.client.api.domain.ClientEntitySet)1 ClientEntitySetIterator (org.apache.olingo.client.api.domain.ClientEntitySetIterator)1 ClientProperty (org.apache.olingo.client.api.domain.ClientProperty)1 URIBuilder (org.apache.olingo.client.api.uri.URIBuilder)1