Headless access

This section tackles the topic of enabling access to an Apache Isis application directly, or at least, not through either the Wicket or Restful viewers.

There are a number of use-cases:

  • implementing a REST end point that needs to reach into the Apache Isis runtime

    • this could be a custom UI

    • this could be to integrate from other systems, eg a subscriber on a pub/sub event bus, pushing changes through an Apache Isis domain model.

  • calling from Quartz for a background batch process

Note that the calling thread runs in the same process space as the Apache Isis domain object model (must be physically linked to the JAR files containing the domain classes).

The SimpleApp starter app demonstrates the pattern with a custom UI controller:

@RestController
@RequiredArgsConstructor
class CustomController {

    private final InteractionFactory interactionFactory;
    private final TransactionalProcessor transactionalProcessor;
    private final SimpleObjects simpleObjects;

    @GetMapping("/custom/simpleObjects")
    List<SimpleObject> all() {
        return callAuthenticated(newAuthentication(), () -> simpleObjects.listAll())
                .optionalElseFail() (1)
                .orElse(Collections.emptyList()); (2)
    }

    private SimpleAuthentication newAuthentication() {
        return SimpleAuthentication.validOf(UserMemento.ofName("sven")); (3)
    }

    private <T> Result<T> callAuthenticated(
            final Authentication authentication,
            final Callable<T> task) {

        return interactionFactory.callAuthenticated(
                authentication,
                () -> transactionalProcessor
                      .callWithinCurrentTransactionElseCreateNew(task));
    }
}
1 re-throws exception that has occurred, if any
2 handles null case, if required
3 a more sophisticated implementation could inspect the HTTP request

The API described here is reasonably low-level, allowing code to interact very directly with the Apache Isis metamodel and runtime. Such callers should be considered trusted: they do not (by default) honour any business rules eg implicit in the Isis annotations or hide/disable/validate methods.