use of org.apache.olingo.odata2.api.ep.feed.ODataDeltaFeed 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.ODataDeltaFeed in project camel by apache.
the class Olingo2AppAPITest method prettyPrint.
private static String prettyPrint(Map<String, Object> properties, int level) {
StringBuilder b = new StringBuilder();
Set<Map.Entry<String, Object>> entries = properties.entrySet();
for (Map.Entry<String, Object> entry : entries) {
indent(b, level);
b.append(entry.getKey()).append(": ");
Object value = entry.getValue();
if (value instanceof Map) {
@SuppressWarnings("unchecked") final Map<String, Object> objectMap = (Map<String, Object>) value;
value = prettyPrint(objectMap, level + 1);
b.append(value).append(NEW_LINE);
} else if (value instanceof Calendar) {
Calendar cal = (Calendar) value;
value = DateFormat.getInstance().format(cal.getTime());
b.append(value).append(NEW_LINE);
} else if (value instanceof ODataDeltaFeed) {
ODataDeltaFeed feed = (ODataDeltaFeed) value;
List<ODataEntry> inlineEntries = feed.getEntries();
b.append("{");
for (ODataEntry oDataEntry : inlineEntries) {
value = prettyPrint(oDataEntry.getProperties(), level + 1);
b.append("\n[\n").append(value).append("\n],");
}
b.deleteCharAt(b.length() - 1);
indent(b, level);
b.append("}\n");
} else {
b.append(value).append(NEW_LINE);
}
}
// remove last line break
b.deleteCharAt(b.length() - 1);
return b.toString();
}
Aggregations