ActionInvocationMemento aim = backgroundService.asActionInvocationMemento(method, targetObject, args);
if(aim != null) {
command.setMemento(aim.asMementoString());
} else {
throw new IsisException(
"Unable to build memento for action " +
owningAction.getIdentifier().toClassAndNameIdentityString());
}
}
// copy over the command execution 'context' (if available)
final CommandFacet commandFacet = getFacetHolder().getFacet(CommandFacet.class);
if(commandFacet != null && !commandFacet.isDisabled()) {
command.setExecuteIn(commandFacet.executeIn());
command.setPersistence(commandFacet.persistence());
} else {
// if no facet, assume do want to execute right now, but only persist (eventually) if hinted.
command.setExecuteIn(ExecuteIn.FOREGROUND);
command.setPersistence(Persistence.IF_HINTED);
}
}
if( command != null &&
command.getExecutor() == Executor.USER &&
command.getExecuteIn() == ExecuteIn.BACKGROUND) {
// persist command so can be this command can be in the 'background'
final CommandService commandService = getServicesInjector().lookupService(CommandService.class);
if(commandService.persistIfPossible(command)) {
// force persistence, then return the command itself.
final ObjectAdapter resultAdapter = getAdapterManager().adapterFor(command);
return InvocationResult.forActionThatReturned(resultAdapter);
} else {
throw new IsisException(
"Unable to schedule action '"
+ owningAction.getIdentifier().toClassAndNameIdentityString() + "' to run in background: "
+ "CommandService does not support persistent commands " );
}
} else {