use of org.apache.olingo.client.api.domain.ClientProperty 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;
}
Aggregations