Search in sources :

Example 1 with CommandJdo

use of org.isisaddons.module.command.dom.CommandJdo in project estatio by estatio.

the class FakeScheduler method runBackgroundCommands.

@Action(semantics = SemanticsOf.NON_IDEMPOTENT)
public void runBackgroundCommands(@ParameterLayout(named = "Wait for (ms)") final Integer waitFor) throws InterruptedException {
    List<CommandJdo> commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
    if (commands.isEmpty()) {
        throw new IllegalStateException("There are no commands not yet started");
    }
    transactionService.nextTransaction();
    BackgroundCommandExecutionFromBackgroundCommandServiceJdo backgroundExec = new BackgroundCommandExecutionFromBackgroundCommandServiceJdo();
    final SimpleSession session = new SimpleSession("scheduler_user", new String[] { "admin_role" });
    final Thread thread = new Thread(() -> backgroundExec.execute(session, null));
    thread.start();
    thread.join(waitFor);
    commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
    if (!commands.isEmpty()) {
        throw new IllegalStateException("There are still " + commands.size() + " not yet started");
    }
}
Also used : CommandJdo(org.isisaddons.module.command.dom.CommandJdo) BackgroundCommandExecutionFromBackgroundCommandServiceJdo(org.isisaddons.module.command.dom.BackgroundCommandExecutionFromBackgroundCommandServiceJdo) SimpleSession(org.apache.isis.core.runtime.authentication.standard.SimpleSession) Action(org.apache.isis.applib.annotation.Action)

Example 2 with CommandJdo

use of org.isisaddons.module.command.dom.CommandJdo in project estatio by estatio.

the class CommandReplayAnalyserResultStrSimplified method doAnalyzeReplay.

/**
 * Hook for the slave.
 *
 * Unlike {@link CommandReplayAnalyserResultStr}, this checks only that both are null or both are non-null.
 */
protected String doAnalyzeReplay(final Command command, final CommandDto dto) {
    if (!(command instanceof CommandJdo)) {
        return null;
    }
    final CommandJdo commandJdo = (CommandJdo) command;
    // if there is an exception, then pay attention to this rather than the results
    // (have found that the master may have both a result and an exception, while on the slave have
    // only an exception).
    final String exceptionStr = CommandDtoUtils.getUserData(dto, CommandWithDto.USERDATA_KEY_EXCEPTION);
    if (exceptionStr != null) {
        return null;
    }
    // no exception; check if both master and slave are either both null, or both non-null
    final String masterResultStr = CommandDtoUtils.getUserData(dto, CommandWithDto.USERDATA_KEY_RETURN_VALUE);
    final String slaveResultStr = commandJdo.getResultStr();
    if (masterResultStr == null) {
        return null;
    }
    if (slaveResultStr != null) {
        // don't check for an exact match
        return null;
    }
    return String.format("Results differ.  Master was '%s', slave is null", masterResultStr);
}
Also used : CommandJdo(org.isisaddons.module.command.dom.CommandJdo)

Example 3 with CommandJdo

use of org.isisaddons.module.command.dom.CommandJdo in project estatio by estatio.

the class RunBackgroundCommandsService method runBackgroundCommands.

@Programmatic
public void runBackgroundCommands() throws InterruptedException {
    List<CommandJdo> commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
    assertThat(commands).hasSize(1);
    transactionService.nextTransaction();
    BackgroundCommandExecutionFromBackgroundCommandServiceJdo backgroundExec = new BackgroundCommandExecutionFromBackgroundCommandServiceJdo();
    final SimpleSession session = new SimpleSession("scheduler_user", new String[] { "admin_role" });
    final Thread thread = new Thread(() -> backgroundExec.execute(session, null));
    thread.start();
    thread.join(5000L);
    commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
    assertThat(commands).isEmpty();
}
Also used : CommandJdo(org.isisaddons.module.command.dom.CommandJdo) BackgroundCommandExecutionFromBackgroundCommandServiceJdo(org.isisaddons.module.command.dom.BackgroundCommandExecutionFromBackgroundCommandServiceJdo) SimpleSession(org.apache.isis.core.runtime.authentication.standard.SimpleSession) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 4 with CommandJdo

use of org.isisaddons.module.command.dom.CommandJdo in project estatio by estatio.

the class Smoke_IntegTest method can_send_email.

@Test
public void can_send_email() throws Exception {
    // given
    fixtureScripts.runFixtureScript(new CommandDomModule().getTeardownFixtureWillDelete(), null);
    fixtureScripts.runFixtureScript(new DemoObjectWithNotes_and_DemoInvoice_and_docs_and_comms_create(), null);
    transactionService.nextTransaction();
    // and so given customer with an email
    final DemoObjectWithNotes fred = customerMenu.findDemoObjectsWithNotesByName(DemoObjectWithNote_and_DemoInvoice_create3.FRED_HAS_EMAIL_AND_PHONE).get(0);
    final EmailAddress fredEmail = (EmailAddress) linkRepository.findByOwnerAndCommunicationChannelType(fred, CommunicationChannelType.EMAIL_ADDRESS).get(0).getCommunicationChannel();
    // and with an invoice
    final DemoInvoice fredInvoice = invoiceRepository.findByCustomer(fred).get(0);
    // that has an attached document
    final Paperclip paperclip = paperclipRepository.findByAttachedTo(fredInvoice).get(0);
    final DocumentAbstract document = paperclip.getDocument();
    // when
    final Document_sendByEmail documentEmail = mixin(Document_sendByEmail.class, document);
    final Set<EmailAddress> emailAddresses = documentEmail.choices0Act();
    // then
    assertThat(emailAddresses).contains(fredEmail);
    // and when
    // REVIEW: should be wrapped, however the DocumentCommunicationSupportForDocumentsAttachedToInvoiceForLease
    // vetoes this, and there is current no way to exclude classes that are not part of the "effective" module
    // final Communication comm = wrap(documentEmail).act(fredEmail, null, null, null, null, null);
    final Communication comm = documentEmail.act(fredEmail, null, null, null, null, null);
    // then
    assertThat(comm).isNotNull();
    assertThat(comm.getState()).isEqualTo(CommunicationState.PENDING);
    assertThat(comm.getCreatedAt()).isNotNull();
    assertThat(comm.getType()).isEqualTo(CommunicationChannelType.EMAIL_ADDRESS);
    assertThat(comm.getSubject()).isNotNull();
    assertThat(comm.getSentAt()).isNull();
    final List<CommunicationChannel> correspondentChannels = Lists.newArrayList(comm.getCorrespondents()).stream().map(CommChannelRole::getChannel).filter(Objects::nonNull).collect(Collectors.toList());
    assertThat(correspondentChannels).contains(fredEmail);
    List<EmailMessage> emailMessages = fakeEmailService.listSentEmails();
    assertThat(emailMessages).isEmpty();
    List<CommandJdo> commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
    assertThat(commands.size()).isEqualTo(1);
    // when
    fakeScheduler.runBackgroundCommands(5000);
    // then
    assertThat(comm.getState()).isEqualTo(CommunicationState.SENT);
    assertThat(comm.getSentAt()).isNotNull();
    emailMessages = fakeEmailService.listSentEmails();
    assertThat(emailMessages).isNotEmpty();
}
Also used : Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) DocumentAbstract(org.incode.module.document.dom.impl.docs.DocumentAbstract) EmailMessage(org.incode.platform.dom.communications.integtests.app.services.fakeemail.EmailMessage) CommandJdo(org.isisaddons.module.command.dom.CommandJdo) DemoInvoice(org.incode.platform.dom.communications.integtests.demo.dom.invoice.DemoInvoice) CommChannelRole(org.incode.module.communications.dom.impl.comms.CommChannelRole) EmailAddress(org.incode.module.communications.dom.impl.commchannel.EmailAddress) CommunicationChannel(org.incode.module.communications.dom.impl.commchannel.CommunicationChannel) DemoObjectWithNotes(org.incode.platform.dom.communications.integtests.demo.dom.demowithnotes.DemoObjectWithNotes) Document_sendByEmail(org.incode.module.communications.dom.mixins.Document_sendByEmail) CommandDomModule(org.isisaddons.module.command.dom.CommandDomModule) DemoObjectWithNotes_and_DemoInvoice_and_docs_and_comms_create(org.incode.platform.dom.communications.integtests.dom.communications.fixture.DemoObjectWithNotes_and_DemoInvoice_and_docs_and_comms_create) Communication(org.incode.module.communications.dom.impl.comms.Communication) Test(org.junit.Test)

Example 5 with CommandJdo

use of org.isisaddons.module.command.dom.CommandJdo in project estatio by estatio.

the class FakeScheduler method runBackgroundCommands.

@Action(semantics = SemanticsOf.NON_IDEMPOTENT)
public void runBackgroundCommands(@ParameterLayout(named = "Wait for (ms)") final Integer waitFor) throws InterruptedException {
    List<CommandJdo> commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
    if (commands.isEmpty()) {
        throw new IllegalStateException("There are no commands not yet started");
    }
    transactionService.nextTransaction();
    BackgroundCommandExecutionFromBackgroundCommandServiceJdo backgroundExec = new BackgroundCommandExecutionFromBackgroundCommandServiceJdo();
    final SimpleSession session = new SimpleSession("scheduler_user", new String[] { "admin_role" });
    final Thread thread = new Thread(() -> backgroundExec.execute(session, null));
    thread.start();
    thread.join(waitFor);
    commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
    if (!commands.isEmpty()) {
        throw new IllegalStateException("There are still " + commands.size() + " not yet started");
    }
}
Also used : CommandJdo(org.isisaddons.module.command.dom.CommandJdo) BackgroundCommandExecutionFromBackgroundCommandServiceJdo(org.isisaddons.module.command.dom.BackgroundCommandExecutionFromBackgroundCommandServiceJdo) SimpleSession(org.apache.isis.core.runtime.authentication.standard.SimpleSession) Action(org.apache.isis.applib.annotation.Action)

Aggregations

CommandJdo (org.isisaddons.module.command.dom.CommandJdo)5 SimpleSession (org.apache.isis.core.runtime.authentication.standard.SimpleSession)3 BackgroundCommandExecutionFromBackgroundCommandServiceJdo (org.isisaddons.module.command.dom.BackgroundCommandExecutionFromBackgroundCommandServiceJdo)3 Action (org.apache.isis.applib.annotation.Action)2 Programmatic (org.apache.isis.applib.annotation.Programmatic)1 CommunicationChannel (org.incode.module.communications.dom.impl.commchannel.CommunicationChannel)1 EmailAddress (org.incode.module.communications.dom.impl.commchannel.EmailAddress)1 CommChannelRole (org.incode.module.communications.dom.impl.comms.CommChannelRole)1 Communication (org.incode.module.communications.dom.impl.comms.Communication)1 Document_sendByEmail (org.incode.module.communications.dom.mixins.Document_sendByEmail)1 DocumentAbstract (org.incode.module.document.dom.impl.docs.DocumentAbstract)1 Paperclip (org.incode.module.document.dom.impl.paperclips.Paperclip)1 EmailMessage (org.incode.platform.dom.communications.integtests.app.services.fakeemail.EmailMessage)1 DemoObjectWithNotes (org.incode.platform.dom.communications.integtests.demo.dom.demowithnotes.DemoObjectWithNotes)1 DemoInvoice (org.incode.platform.dom.communications.integtests.demo.dom.invoice.DemoInvoice)1 DemoObjectWithNotes_and_DemoInvoice_and_docs_and_comms_create (org.incode.platform.dom.communications.integtests.dom.communications.fixture.DemoObjectWithNotes_and_DemoInvoice_and_docs_and_comms_create)1 CommandDomModule (org.isisaddons.module.command.dom.CommandDomModule)1 Test (org.junit.Test)1