use of org.apache.olingo.client.api.uri.URIBuilder in project tdi-studio-se by Talend.
the class DynamicsCRMClient method createEntityRetrieveRequest.
/**
* Create EntitySet Iterator request
*
* @param entirySet entirySet the EntitySet name which you want to retrieve records
* @param queryOption
* @return EntitySet iterator request
*/
public ODataEntitySetRequest<ClientEntitySet> createEntityRetrieveRequest(QueryOptionConfig queryOption) {
URIBuilder uriBuilder = odataClient.newURIBuilder(serviceRootURL).appendEntitySetSegment(entitySet);
if (queryOption.getReturnEntityProperties() != null) {
uriBuilder.select(queryOption.getReturnEntityProperties());
}
if (queryOption.getTop() > 0) {
uriBuilder.top(queryOption.getTop());
}
if (!StringUtils.isEmpty(queryOption.getOrderBy())) {
uriBuilder.orderBy(queryOption.getOrderBy());
}
if (!StringUtils.isEmpty(queryOption.getFilter())) {
uriBuilder.filter(queryOption.getFilter());
}
ODataEntitySetRequest<ClientEntitySet> request = odataClient.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
request.addCustomHeader(HttpHeader.AUTHORIZATION, "Bearer " + authResult.getAccessToken());
return request;
}
use of org.apache.olingo.client.api.uri.URIBuilder 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;
}
use of org.apache.olingo.client.api.uri.URIBuilder in project tdi-studio-se by Talend.
the class DynamicsCRMClient method updateEntity.
/**
* Update entity with provided content
*
* @param entitySet entitySet the EntitySet name which you want to update records
* @param entity provide to update
* @param updateType UpdateType.REPLACE(Full updates) or UpdateType.PATCH(Partial updates )
*
* @throws ServiceUnavailableException
*/
public HttpResponse updateEntity(ClientEntity entity, String keySegment) throws ServiceUnavailableException {
URIBuilder updateURIBuilder = odataClient.newURIBuilder(serviceRootURL).appendEntitySetSegment(entitySet).appendKeySegment(UUID.fromString(keySegment));
HttpEntity httpEntity = convertToHttpEntity(entity);
return createAndExecuteRequest(updateURIBuilder.build(), httpEntity, HttpMethod.PATCH);
}
use of org.apache.olingo.client.api.uri.URIBuilder in project tdi-studio-se by Talend.
the class DynamicsCRMClient method insertEntity.
/**
* Create entity
*
* @param entitySet entitySet the EntitySet name which you want to create record
* @param entity provided content for create
*
* @throws ServiceUnavailableException
*/
public HttpResponse insertEntity(ClientEntity entity) throws ServiceUnavailableException {
URIBuilder insertURIBuilder = odataClient.newURIBuilder(serviceRootURL).appendEntitySetSegment(entitySet);
HttpEntity httpEntity = convertToHttpEntity(entity);
return createAndExecuteRequest(insertURIBuilder.build(), httpEntity, HttpMethod.POST);
}
Aggregations