use of org.apache.olingo.client.api.domain.ClientEntity 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.domain.ClientEntity in project wildfly-camel by wildfly-extras.
the class Olingo4IntegrationTest method testCreateUpdateDelete.
@Test
public void testCreateUpdateDelete() throws Exception {
CamelContext camelctx = createCamelContext();
camelctx.addRoutes(new RouteBuilder() {
public void configure() {
from("direct://create-entity").to("olingo4://create/People");
from("direct://update-entity").to("olingo4://update/People('lewisblack')");
from("direct://delete-entity").to("olingo4://delete/People('lewisblack')");
from("direct://read-deleted-entity").to("olingo4://delete/People('lewisblack')");
from("direct://batch").to("olingo4://batch");
}
});
camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
final ClientEntity clientEntity = createEntity();
ClientEntity entity = template.requestBody("direct://create-entity", clientEntity, ClientEntity.class);
Assert.assertNotNull(entity);
Assert.assertEquals("Lewis", entity.getProperty("FirstName").getValue().toString());
Assert.assertEquals("", entity.getProperty("MiddleName").getValue().toString());
// update
clientEntity.getProperties().add(objFactory.newPrimitiveProperty("MiddleName", objFactory.newPrimitiveValueBuilder().buildString("Lewis")));
HttpStatusCode status = template.requestBody("direct://update-entity", clientEntity, HttpStatusCode.class);
Assert.assertNotNull("Update status", status);
Assert.assertEquals("Update status", HttpStatusCode.NO_CONTENT.getStatusCode(), status.getStatusCode());
LOG.info("Update entity status: {}", status);
// delete
status = template.requestBody("direct://delete-entity", null, HttpStatusCode.class);
Assert.assertNotNull("Delete status", status);
Assert.assertEquals("Delete status", HttpStatusCode.NO_CONTENT.getStatusCode(), status.getStatusCode());
LOG.info("Delete status: {}", status);
// check for delete
try {
template.requestBody("direct://read-deleted-entity", null, HttpStatusCode.class);
} catch (CamelExecutionException e) {
Assert.assertEquals("Resource Not Found [HTTP/1.1 404 Not Found]", e.getCause().getMessage());
}
} finally {
camelctx.stop();
}
}
use of org.apache.olingo.client.api.domain.ClientEntity in project wildfly-camel by wildfly-extras.
the class Olingo4IntegrationTest method createEntity.
private ClientEntity createEntity() {
ClientEntity clientEntity = objFactory.newEntity(null);
clientEntity.getProperties().add(objFactory.newPrimitiveProperty("UserName", objFactory.newPrimitiveValueBuilder().buildString("lewisblack")));
clientEntity.getProperties().add(objFactory.newPrimitiveProperty("FirstName", objFactory.newPrimitiveValueBuilder().buildString("Lewis")));
clientEntity.getProperties().add(objFactory.newPrimitiveProperty("LastName", objFactory.newPrimitiveValueBuilder().buildString("Black")));
return clientEntity;
}
use of org.apache.olingo.client.api.domain.ClientEntity in project wildfly-camel by wildfly-extras.
the class Olingo4IntegrationTest method testRead.
@Test
public void testRead() throws Exception {
CamelContext camelctx = createCamelContext();
camelctx.addRoutes(new RouteBuilder() {
public void configure() {
// test routes for read
from("direct://readmetadata").to("olingo4://read/$metadata");
from("direct://readdocument").to("olingo4://read/");
from("direct://readentities").to("olingo4://read/People?$top=5&$orderby=FirstName asc");
from("direct://readcount").to("olingo4://read/People/$count");
from("direct://readvalue").to("olingo4://read/People('russellwhyte')/Gender/$value");
from("direct://readsingleprop").to("olingo4://read/Airports('KSFO')/Name");
from("direct://readcomplexprop").to("olingo4://read/Airports('KSFO')/Location");
from("direct://readentitybyid").to("olingo4://read/People('russellwhyte')");
from("direct://callunboundfunction").to("olingo4://read/GetNearestAirport(lat=33,lon=-118)");
}
});
camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
final Map<String, Object> headers = new HashMap<String, Object>();
// Read metadata ($metadata) object
final Edm metadata = (Edm) template.requestBodyAndHeaders("direct://readmetadata", null, headers);
Assert.assertNotNull(metadata);
Assert.assertEquals(1, metadata.getSchemas().size());
// Read service document object
final ClientServiceDocument document = (ClientServiceDocument) template.requestBodyAndHeaders("direct://readdocument", null, headers);
Assert.assertNotNull(document);
Assert.assertTrue(document.getEntitySets().size() > 1);
LOG.info("Service document has {} entity sets", document.getEntitySets().size());
// Read entity set of the People object
final ClientEntitySet entities = (ClientEntitySet) template.requestBodyAndHeaders("direct://readentities", null, headers);
Assert.assertNotNull(entities);
Assert.assertEquals(5, entities.getEntities().size());
// Read object count with query options passed through header
final Long count = (Long) template.requestBodyAndHeaders("direct://readcount", null, headers);
Assert.assertEquals(20, count.intValue());
final ClientPrimitiveValue value = (ClientPrimitiveValue) template.requestBodyAndHeaders("direct://readvalue", null, headers);
LOG.info("Client value \"{}\" has type {}", value.toString(), value.getTypeName());
Assert.assertEquals("Male", value.asPrimitive().toString());
final ClientPrimitiveValue singleProperty = (ClientPrimitiveValue) template.requestBodyAndHeaders("direct://readsingleprop", null, headers);
Assert.assertTrue(singleProperty.isPrimitive());
Assert.assertEquals("San Francisco International Airport", singleProperty.toString());
final ClientComplexValue complexProperty = (ClientComplexValue) template.requestBodyAndHeaders("direct://readcomplexprop", null, headers);
Assert.assertTrue(complexProperty.isComplex());
Assert.assertEquals("San Francisco", complexProperty.get("City").getComplexValue().get("Name").getValue().toString());
final ClientEntity entity = (ClientEntity) template.requestBodyAndHeaders("direct://readentitybyid", null, headers);
Assert.assertNotNull(entity);
Assert.assertEquals("Russell", entity.getProperty("FirstName").getValue().toString());
final ClientEntity unbFuncReturn = (ClientEntity) template.requestBodyAndHeaders("direct://callunboundfunction", null, headers);
Assert.assertNotNull(unbFuncReturn);
} finally {
camelctx.stop();
}
}
use of org.apache.olingo.client.api.domain.ClientEntity in project syndesis by syndesisio.
the class AbstractODataConnector method createEndpointUri.
@Override
public String createEndpointUri(final String scheme, final Map<String, String> options) throws URISyntaxException {
// set serviceUri on delegate component
Olingo4Component delegate = getCamelContext().getComponent(scheme, Olingo4Component.class);
Olingo4Configuration configuration = new Olingo4Configuration();
configuration.setServiceUri(this.serviceUri);
delegate.setConfiguration(configuration);
setAfterProducer(exchange -> {
if (!exchange.isFailed()) {
ClientEntity clientEntity = exchange.getIn().getBody(ClientEntity.class);
if (clientEntity != null) {
// convert client entity to JSON
final StringWriter writer = new StringWriter();
final Entity entity = odataClient.getBinder().getEntity(clientEntity);
final ODataSerializer serializer = odataClient.getSerializer(APPLICATION_JSON);
serializer.write(writer, entity);
exchange.getIn().setBody(writer.toString());
}
}
// TODO handle failure on missing resource 404
});
return super.createEndpointUri(scheme, options);
}
Aggregations