Search in sources :

Example 1 with EntityProviderWriteProperties

use of org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties in project camel by apache.

the class Olingo2AppImpl method writeContent.

private ODataResponse writeContent(Edm edm, UriInfoWithType uriInfo, Object content) throws ODataApplicationException, EdmException, EntityProviderException, URISyntaxException, IOException {
    String responseContentType = getContentType();
    ODataResponse response;
    switch(uriInfo.getUriType()) {
        case URI4:
        case URI5:
            // simple property
            final List<EdmProperty> simplePropertyPath = uriInfo.getPropertyPath();
            final EdmProperty simpleProperty = simplePropertyPath.get(simplePropertyPath.size() - 1);
            responseContentType = simpleProperty.getMimeType();
            if (uriInfo.isValue()) {
                response = EntityProvider.writePropertyValue(simpleProperty, content);
                responseContentType = TEXT_PLAIN_WITH_CS_UTF_8.toString();
            } else {
                response = EntityProvider.writeProperty(getContentType(), simpleProperty, content);
            }
            break;
        case URI3:
            // complex property
            final List<EdmProperty> complexPropertyPath = uriInfo.getPropertyPath();
            final EdmProperty complexProperty = complexPropertyPath.get(complexPropertyPath.size() - 1);
            response = EntityProvider.writeProperty(responseContentType, complexProperty, content);
            break;
        case URI7A:
            // $links with 0..1 cardinality property
            final EdmEntitySet targetLinkEntitySet = uriInfo.getTargetEntitySet();
            EntityProviderWriteProperties linkProperties = EntityProviderWriteProperties.serviceRoot(new URI(serviceUri + SEPARATOR)).build();
            @SuppressWarnings("unchecked") final Map<String, Object> linkMap = (Map<String, Object>) content;
            response = EntityProvider.writeLink(responseContentType, targetLinkEntitySet, linkMap, linkProperties);
            break;
        case URI7B:
            // $links with * cardinality property
            final EdmEntitySet targetLinksEntitySet = uriInfo.getTargetEntitySet();
            EntityProviderWriteProperties linksProperties = EntityProviderWriteProperties.serviceRoot(new URI(serviceUri + SEPARATOR)).build();
            @SuppressWarnings("unchecked") final List<Map<String, Object>> linksMap = (List<Map<String, Object>>) content;
            response = EntityProvider.writeLinks(responseContentType, targetLinksEntitySet, linksMap, linksProperties);
            break;
        case URI1:
        case URI2:
        case URI6A:
        case URI6B:
            // Entity
            final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
            EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(new URI(serviceUri + SEPARATOR)).build();
            @SuppressWarnings("unchecked") final Map<String, Object> objectMap = (Map<String, Object>) content;
            response = EntityProvider.writeEntry(responseContentType, targetEntitySet, objectMap, properties);
            break;
        case URI9:
            // $batch
            @SuppressWarnings("unchecked") final List<Olingo2BatchRequest> batchParts = (List<Olingo2BatchRequest>) content;
            response = parseBatchRequest(edm, batchParts);
            break;
        default:
            // notify exception and return!!!
            throw new ODataApplicationException("Unsupported resource type " + uriInfo.getTargetType(), Locale.ENGLISH);
    }
    return response.getContentHeader() != null ? response : ODataResponse.fromResponse(response).contentHeader(responseContentType).build();
}
Also used : Olingo2BatchRequest(org.apache.camel.component.olingo2.api.batch.Olingo2BatchRequest) EntityProviderWriteProperties(org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties) URI(java.net.URI) ODataApplicationException(org.apache.olingo.odata2.api.exception.ODataApplicationException) ODataResponse(org.apache.olingo.odata2.api.processor.ODataResponse) List(java.util.List) ArrayList(java.util.ArrayList) EdmEntitySet(org.apache.olingo.odata2.api.edm.EdmEntitySet) EdmProperty(org.apache.olingo.odata2.api.edm.EdmProperty) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Olingo2BatchRequest (org.apache.camel.component.olingo2.api.batch.Olingo2BatchRequest)1 EdmEntitySet (org.apache.olingo.odata2.api.edm.EdmEntitySet)1 EdmProperty (org.apache.olingo.odata2.api.edm.EdmProperty)1 EntityProviderWriteProperties (org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties)1 ODataApplicationException (org.apache.olingo.odata2.api.exception.ODataApplicationException)1 ODataResponse (org.apache.olingo.odata2.api.processor.ODataResponse)1