Search in sources :

Example 1 with URIBuilder

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

Example 2 with URIBuilder

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;
}
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)

Example 3 with URIBuilder

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);
}
Also used : HttpEntity(org.apache.http.HttpEntity) URIBuilder(org.apache.olingo.client.api.uri.URIBuilder)

Example 4 with URIBuilder

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);
}
Also used : HttpEntity(org.apache.http.HttpEntity) URIBuilder(org.apache.olingo.client.api.uri.URIBuilder)

Aggregations

URIBuilder (org.apache.olingo.client.api.uri.URIBuilder)4 HttpEntity (org.apache.http.HttpEntity)2 ClientEntitySet (org.apache.olingo.client.api.domain.ClientEntitySet)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