Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.