java – Pushing entities through multiple levels of abstraction

Let’s say I have an external library that I want to use in my application, which performs some long running operations:

interface ExternalLibrary {

    void operation1(ExternalInput input);

    List<ExternalResult> operation2(String input);

I want to trigger those operations using REST endpoints. operation2 returns a final result, but it can be performed only if operation1 was previously executed successfully.

My idea is to keep track of ongoing process in database (using let’s say RequestEntity) and final result in ResultEntity. I’m thinking of defining a LibraryAdapter, AsyncClient and Service that will be used by REST controller. So something like this:

class Service {

    private LibraryAsyncClient asyncClient;

    // called from some Controller
    Long operation1(RestRequest restRequest) {
        // convert RestRequest to RequestEntity request;

            // update request status after operation is completed
            .thenAccept(it -> request.setStatus(OP1_OK))
            .exceptionally(err -> request.setStatus(OP1_ERROR));

        return request.getId();

    // called from some Controller
    void operation2(RestRequest restRequest) {
        return requestRepository.findById(restRequest.getId())
            .ifPresent(request -> {
                    .thenAccept(result -> {
                    .exceptionally(err -> request.setStatus(OP2_ERROR));
class LibraryAsyncClient {

    private LibraryAdapter adapter;

    CompletableFuture<Void> operation1(RequestEntity request) {
        return supplyAsync(() -> adapter.operation1(input), executorService);

    CompletableFuture<ResultEntity> operation2(RequestEntity request) {
        return supplyAsync(() -> adapter.operation2(input), executorService);
class LibraryAdapterImpl implements LibraryAdapter {

    private ExternalLibrary externalLibrary;

    void operation1(RequestEntity request) {
        // map RequestEntity to ExternalInput etc.

    ResultEntity operation2(RequestEntity request) {
        // map RequestEntity to stringInput etc.
        List<ExternalResult> externalResult = externalLibrary.operation2(stringInput)
        return convertToResult(externalResult);

My main concern is that I’m pushing RequestEntity from Service, through AsyncClient, up to Adapter and ResultEntity the other way. Would it be a better idea to introduce some intermediary data objects? I appreciate any comments regarding this question (or this whole design in general).