use of org.apache.olingo.odata2.api.ep.feed.ODataFeed in project camel by apache.
the class Olingo2AppAPITest method testReadFeed.
@Test
public void testReadFeed() throws Exception {
final TestOlingo2ResponseHandler<ODataFeed> responseHandler = new TestOlingo2ResponseHandler<ODataFeed>();
olingoApp.read(edm, MANUFACTURERS, null, responseHandler);
final ODataFeed dataFeed = responseHandler.await();
assertNotNull("Data feed", dataFeed);
LOG.info("Entries: {}", prettyPrint(dataFeed));
}
use of org.apache.olingo.odata2.api.ep.feed.ODataFeed in project camel by apache.
the class Olingo2ComponentTest method testRead.
@Test
public void testRead() throws Exception {
final Map<String, Object> headers = new HashMap<String, Object>();
// read ServiceDocument
final ServiceDocument document = requestBodyAndHeaders("direct://READSERVICEDOC", null, headers);
assertNotNull(document);
assertFalse("ServiceDocument entity sets", document.getEntitySetsInfo().isEmpty());
LOG.info("Service document has {} entity sets", document.getEntitySetsInfo().size());
// parameter type is java.util.Map
final HashMap<String, String> queryParams = new HashMap<String, String>();
queryParams.put(SystemQueryOption.$top.name(), "5");
headers.put("CamelOlingo2.queryParams", queryParams);
// read ODataFeed
final ODataFeed manufacturers = requestBodyAndHeaders("direct://READFEED", null, headers);
assertNotNull(manufacturers);
final List<ODataEntry> manufacturersEntries = manufacturers.getEntries();
assertFalse("Manufacturers empty entries", manufacturersEntries.isEmpty());
LOG.info("Manufacturers feed has {} entries", manufacturersEntries.size());
// read ODataEntry
headers.clear();
headers.put(Olingo2Constants.PROPERTY_PREFIX + "keyPredicate", "'1'");
final ODataEntry manufacturer = requestBodyAndHeaders("direct://READENTRY", null, headers);
assertNotNull(manufacturer);
final Map<String, Object> properties = manufacturer.getProperties();
assertEquals("Manufacturer Id", "1", properties.get(ID_PROPERTY));
LOG.info("Manufacturer: {}", properties.toString());
}
use of org.apache.olingo.odata2.api.ep.feed.ODataFeed in project camel by apache.
the class Olingo2AppImpl method readContent.
@SuppressWarnings("unchecked")
private <T> T readContent(UriInfoWithType uriInfo, InputStream content) throws EntityProviderException, ODataApplicationException {
T response;
switch(uriInfo.getUriType()) {
case URI0:
// service document
response = (T) EntityProvider.readServiceDocument(content, SERVICE_DOCUMENT_CONTENT_TYPE.toString());
break;
case URI8:
// $metadata
response = (T) EntityProvider.readMetadata(content, false);
break;
case URI7A:
// link
response = (T) EntityProvider.readLink(getContentType(), uriInfo.getTargetEntitySet(), content);
break;
case URI7B:
// links
response = (T) EntityProvider.readLinks(getContentType(), uriInfo.getTargetEntitySet(), content);
break;
case URI3:
// complex property
final List<EdmProperty> complexPropertyPath = uriInfo.getPropertyPath();
final EdmProperty complexProperty = complexPropertyPath.get(complexPropertyPath.size() - 1);
response = (T) EntityProvider.readProperty(getContentType(), complexProperty, content, EntityProviderReadProperties.init().build());
break;
case URI4:
case URI5:
// simple property
final List<EdmProperty> simplePropertyPath = uriInfo.getPropertyPath();
final EdmProperty simpleProperty = simplePropertyPath.get(simplePropertyPath.size() - 1);
if (uriInfo.isValue()) {
response = (T) EntityProvider.readPropertyValue(simpleProperty, content);
} else {
response = (T) EntityProvider.readProperty(getContentType(), simpleProperty, content, EntityProviderReadProperties.init().build());
}
break;
case URI15:
case URI16:
case URI50A:
case URI50B:
// $count
final String stringCount = new String(EntityProvider.readBinary(content), Consts.UTF_8);
response = (T) Long.valueOf(stringCount);
break;
case URI1:
case URI6B:
if (uriInfo.getCustomQueryOptions().containsKey("!deltatoken")) {
// ODataDeltaFeed
response = (T) EntityProvider.readDeltaFeed(getContentType(), uriInfo.getTargetEntitySet(), content, EntityProviderReadProperties.init().build());
} else {
// ODataFeed
response = (T) EntityProvider.readFeed(getContentType(), uriInfo.getTargetEntitySet(), content, EntityProviderReadProperties.init().build());
}
break;
case URI2:
case URI6A:
response = (T) EntityProvider.readEntry(getContentType(), uriInfo.getTargetEntitySet(), content, EntityProviderReadProperties.init().build());
break;
// Function Imports
case URI10:
case URI11:
case URI12:
case URI13:
case URI14:
response = (T) EntityProvider.readFunctionImport(getContentType(), uriInfo.getFunctionImport(), content, EntityProviderReadProperties.init().build());
break;
default:
throw new ODataApplicationException("Unsupported resource type " + uriInfo.getTargetType(), Locale.ENGLISH);
}
return response;
}
use of org.apache.olingo.odata2.api.ep.feed.ODataFeed in project camel by apache.
the class Olingo2AppAPITest method prettyPrint.
private static String prettyPrint(ODataFeed dataFeed) {
StringBuilder builder = new StringBuilder();
builder.append("[\n");
for (ODataEntry entry : dataFeed.getEntries()) {
builder.append(prettyPrint(entry.getProperties(), 1)).append('\n');
}
builder.append("]\n");
return builder.toString();
}
use of org.apache.olingo.odata2.api.ep.feed.ODataFeed in project camel by apache.
the class Olingo2AppAPITest method testReadUnparsedFeed.
@Test
public void testReadUnparsedFeed() throws Exception {
final TestOlingo2ResponseHandler<InputStream> responseHandler = new TestOlingo2ResponseHandler<InputStream>();
olingoApp.uread(edm, MANUFACTURERS, null, responseHandler);
final InputStream rawfeed = responseHandler.await();
assertNotNull("Data feed", rawfeed);
// for this test, we just let EP to verify the stream data
final ODataFeed dataFeed = EntityProvider.readFeed(TEST_FORMAT_STRING, edmEntitySetMap.get(MANUFACTURERS), rawfeed, EntityProviderReadProperties.init().build());
LOG.info("Entries: {}", prettyPrint(dataFeed));
}
Aggregations