Search in sources :

Example 1 with ClientEntitySet

use of org.apache.olingo.client.api.domain.ClientEntitySet 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;
}
Also used : URIBuilder(org.apache.olingo.client.api.uri.URIBuilder) ClientEntitySet(org.apache.olingo.client.api.domain.ClientEntitySet)

Example 2 with ClientEntitySet

use of org.apache.olingo.client.api.domain.ClientEntitySet 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

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