Search in sources :

Example 1 with BatchPart

use of org.apache.olingo.odata2.api.client.batch.BatchPart in project camel by apache.

the class Olingo2AppImpl method addChangeSetParts.

private void addChangeSetParts(ArrayList<BatchPart> parts, ArrayList<BatchChangeSetPart> changeSetParts) {
    final BatchChangeSet changeSet = BatchChangeSet.newBuilder().build();
    for (BatchChangeSetPart changeSetPart : changeSetParts) {
        changeSet.add(changeSetPart);
    }
    parts.add(changeSet);
}
Also used : BatchChangeSet(org.apache.olingo.odata2.api.client.batch.BatchChangeSet) BatchChangeSetPart(org.apache.olingo.odata2.api.client.batch.BatchChangeSetPart)

Example 2 with BatchPart

use of org.apache.olingo.odata2.api.client.batch.BatchPart in project camel by apache.

the class Olingo2AppImpl method parseBatchRequest.

private ODataResponse parseBatchRequest(final Edm edm, final List<Olingo2BatchRequest> batchParts) throws IOException, EntityProviderException, ODataApplicationException, EdmException, URISyntaxException {
    // create Batch request from parts
    final ArrayList<BatchPart> parts = new ArrayList<BatchPart>();
    final ArrayList<BatchChangeSetPart> changeSetParts = new ArrayList<BatchChangeSetPart>();
    final Map<String, String> contentIdMap = new HashMap<String, String>();
    for (Olingo2BatchRequest batchPart : batchParts) {
        if (batchPart instanceof Olingo2BatchQueryRequest) {
            // need to add change set parts collected so far??
            if (!changeSetParts.isEmpty()) {
                addChangeSetParts(parts, changeSetParts);
                changeSetParts.clear();
                contentIdMap.clear();
            }
            // add to request parts
            final UriInfoWithType uriInfo = parseUri(edm, batchPart.getResourcePath(), null);
            parts.add(createBatchQueryPart(uriInfo, (Olingo2BatchQueryRequest) batchPart));
        } else {
            // add to change set parts
            final BatchChangeSetPart changeSetPart = createBatchChangeSetPart(edm, contentIdMap, (Olingo2BatchChangeRequest) batchPart);
            changeSetParts.add(changeSetPart);
        }
    }
    // add any remaining change set parts
    if (!changeSetParts.isEmpty()) {
        addChangeSetParts(parts, changeSetParts);
    }
    final String boundary = BOUNDARY_PREFIX + UUID.randomUUID();
    InputStream batchRequest = EntityProvider.writeBatchRequest(parts, boundary);
    // two blank lines are already added. No need to add extra blank lines
    final String contentHeader = BATCH_CONTENT_TYPE + BOUNDARY_PARAMETER + boundary;
    return ODataResponse.entity(batchRequest).contentHeader(contentHeader).build();
}
Also used : BatchChangeSetPart(org.apache.olingo.odata2.api.client.batch.BatchChangeSetPart) BatchPart(org.apache.olingo.odata2.api.client.batch.BatchPart) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Olingo2BatchRequest(org.apache.camel.component.olingo2.api.batch.Olingo2BatchRequest) Olingo2BatchQueryRequest(org.apache.camel.component.olingo2.api.batch.Olingo2BatchQueryRequest)

Aggregations

BatchChangeSetPart (org.apache.olingo.odata2.api.client.batch.BatchChangeSetPart)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Olingo2BatchQueryRequest (org.apache.camel.component.olingo2.api.batch.Olingo2BatchQueryRequest)1 Olingo2BatchRequest (org.apache.camel.component.olingo2.api.batch.Olingo2BatchRequest)1 BatchChangeSet (org.apache.olingo.odata2.api.client.batch.BatchChangeSet)1 BatchPart (org.apache.olingo.odata2.api.client.batch.BatchPart)1