Class DefaultInboundRequestService.InboundRequestPartsCoordinator

  • Enclosing class:
    DefaultInboundRequestService

    protected static class DefaultInboundRequestService.InboundRequestPartsCoordinator
    extends java.lang.Object
    Receives collections of the parts, from which an InboundRequest is created, and coordinates access to the collections in a way that after each iteration the state contains parts (batch entry, change set entry and media) related to exactly same InboundRequest.
    • Constructor Detail

      • InboundRequestPartsCoordinator

        protected InboundRequestPartsCoordinator​(java.util.Collection<RequestBatchEntity> requests,
                                                 java.util.Collection<ResponseChangeSetEntity> responses,
                                                 java.util.Collection<InboundRequestMediaModel> medias)
        Instantiates this coordinator.
        Parameters:
        requests - all RequestBatchEntitys, for which InboundRequests need to be created. They represent batches received in the original request.
        responses - all ResponseChangeSetEntitys related to the batch entities. There is no one-to-one relation between batch extracted from the request and change sets extracted from the response. In case of success there will be a change set for every change set received in the request, e.g. if the original request contain a single batch with two change sets, then requests will contain only one RequestBatchEntity for the batch but responses will contain two ResponseChangeSetEntity for the change sets. In case of an error, there will be only one ResponseChangeSetEntity for the corresponding batch regardless of how many changes were in the batch received in the request. And finally, for a global error, e.g. limit of batches per request is exceeded, there will be only one ResponseChangeSetEntity in the responses regardless of how many batches were present in the request.
        medias - bodies of the batches present in the request persisted as medias. Normally it's expected to have number of medias equal to number of requests.
    • Method Detail

      • hasNext

        protected boolean hasNext()
        Determines whether there are more batches not yet iterated.
        Returns:
        true, if there is at least one more not iterated batch; false, otherwise.
        See Also:
        next()
      • next

        protected void next()
        Advances to the next record by iterating across all collections. Since InboundRequests correspond to RequestBatchEntity, this method uses the collection of RequestBatchEntity as the leader. It iterates that collection and then advances to the ResponseChangeSetEntity and InboundRequestMediaModel corresponding to the batch entity in other collections.
      • rollToLastChangeSetInBatch

        protected ResponseChangeSetEntity rollToLastChangeSetInBatch()
        The number of the change sets returned from the parser is not consistent. In case of success, there is a ResponseChangeSetEntity created for every change set received with the request. In case of the error, however, it's always only one ResponseChangeSetEntity regardless of how many change sets were submitted in the batch in the request body. That is because if one change set fails, the whole batch is rolled back and therefore a status for the whole batch is returned rather then for each of its change sets.
        Returns:
        last change set for the current RequestBatchEntity.

        Note: this method relies on the RequestBatchEntity iterated first before this method is called, so that the current batch record would be correctly set. Implementations ensure this order in the next() method or, if the order has changed, this method also needs to be overridden to account for it.

        See Also:
        next()