Skip to content

Instantly share code, notes, and snippets.

@danhaywood
Created July 21, 2016 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danhaywood/5b3a106ee7c06a53cc33d76f88a04c75 to your computer and use it in GitHub Desktop.
Save danhaywood/5b3a106ee7c06a53cc33d76f88a04c75 to your computer and use it in GitHub Desktop.
package org.isisaddons.module.command.dom.direct;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
import org.apache.isis.applib.annotation.DomainService;
import org.apache.isis.applib.annotation.NatureOfService;
import org.apache.isis.applib.annotation.Programmatic;
import org.apache.isis.applib.services.command.Command;
import org.apache.isis.applib.services.registry.ServiceRegistry2;
import org.apache.isis.core.runtime.services.background.BackgroundCommandExecution;
import org.isisaddons.module.command.dom.CommandJdo;
/**
* Utility service to allow previously persisted commands to be executed "in the background", but synchronously and using the caller's credentials.
* The {@link CommandJdo} is *not* updated; that is the responsibility of the caller.
*/
@DomainService(nature = NatureOfService.DOMAIN)
public class DirectExecutionService {
@Programmatic
public void execute(final CommandJdo command) {
final DirectBackgroundCommandExecution dbce =
serviceRegistry.injectServicesInto(new DirectBackgroundCommandExecution(command));
dbce.doExecute(null);
}
@Inject
ServiceRegistry2 serviceRegistry;
private static class DirectBackgroundCommandExecution extends BackgroundCommandExecution {
private final Command command;
public DirectBackgroundCommandExecution(final Command command) {
this.command = command;
}
@Override
protected List<? extends Command> findBackgroundCommandsToExecute() {
return Collections.singletonList(command);
}
@Override
public void doExecute(Object context) {
super.doExecute(context);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment