Search in sources :

Example 1 with ODataFeed

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));
}
Also used : ODataFeed(org.apache.olingo.odata2.api.ep.feed.ODataFeed) Test(org.junit.Test)

Example 2 with ODataFeed

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());
}
Also used : ODataFeed(org.apache.olingo.odata2.api.ep.feed.ODataFeed) HashMap(java.util.HashMap) ServiceDocument(org.apache.olingo.odata2.api.servicedocument.ServiceDocument) ODataEntry(org.apache.olingo.odata2.api.ep.entry.ODataEntry) Test(org.junit.Test)

Example 3 with ODataFeed

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;
}
Also used : EdmProperty(org.apache.olingo.odata2.api.edm.EdmProperty) ODataApplicationException(org.apache.olingo.odata2.api.exception.ODataApplicationException)

Example 4 with ODataFeed

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();
}
Also used : ODataEntry(org.apache.olingo.odata2.api.ep.entry.ODataEntry)

Example 5 with ODataFeed

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));
}
Also used : ODataFeed(org.apache.olingo.odata2.api.ep.feed.ODataFeed) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

ODataFeed (org.apache.olingo.odata2.api.ep.feed.ODataFeed)5 Test (org.junit.Test)5 ODataEntry (org.apache.olingo.odata2.api.ep.entry.ODataEntry)4 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Olingo2BatchRequest (org.apache.camel.component.olingo2.api.batch.Olingo2BatchRequest)2 Olingo2BatchResponse (org.apache.camel.component.olingo2.api.batch.Olingo2BatchResponse)2 InputStream (java.io.InputStream)1 List (java.util.List)1 Edm (org.apache.olingo.odata2.api.edm.Edm)1 EdmProperty (org.apache.olingo.odata2.api.edm.EdmProperty)1 ODataApplicationException (org.apache.olingo.odata2.api.exception.ODataApplicationException)1 ServiceDocument (org.apache.olingo.odata2.api.servicedocument.ServiceDocument)1