Search in sources :

Example 66 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class ChannelServiceImpl method sendChannelUpdatedEvent.

private void sendChannelUpdatedEvent(Channel channel) {
    Map<String, Object> parameters = new HashMap<>();
    parameters.put(CHANNEL_MODULE_NAME, channel.getModuleName());
    eventRelay.sendEventMessage(new MotechEvent(CHANNEL_UPDATE_SUBJECT, parameters));
}
Also used : HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent)

Example 67 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class TaskDataProviderServiceImpl method addProviderImpl.

private void addProviderImpl(final TaskDataProvider provider) {
    // becomes available
    if (dataProviderDataService != null) {
        final TaskDataProvider existing = dataProviderDataService.findByName(provider.getName());
        // Only update data provider when there's actual change
        if (existing != null && !existing.equals(provider)) {
            LOGGER.debug("Updating a task data provider with name: {}", provider.getName());
            existing.setObjects(provider.getObjects());
            dataProviderDataService.update(existing);
            Map<String, Object> parameters = new HashMap<>();
            parameters.put(DATA_PROVIDER_NAME, provider.getName());
            eventRelay.sendEventMessage(new MotechEvent(DATA_PROVIDER_UPDATE_SUBJECT, parameters));
        } else if (existing == null) {
            LOGGER.debug("Creating a task data provider with name: {}", provider.getName());
            dataProviderDataService.create(provider);
        }
    } else {
        LOGGER.debug("DataProviderDataService is not available, storing a task data provider with name: {} for later addition", provider.getName());
        // store for later addition
        providersToAdd.add(provider);
    }
}
Also used : TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent)

Example 68 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class TaskActionExecutorTest method shouldRaiseEventIfActionHasSubject.

@Test
public void shouldRaiseEventIfActionHasSubject() throws ActionNotFoundException, TaskHandlerException {
    TaskActionInformation actionInformation = new TaskActionInformation("action", "channel", "module", "0.1", "actionSubject");
    ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("Action").setSubject("actionSubject").setDescription("").setActionParameters(new TreeSet<>()).build();
    when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
    Task task = new TaskBuilder().addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "actionSubject")).build();
    task.setId(11L);
    Map<String, Object> metadata = new HashMap<>();
    metadata.put(EventDataKeys.TASK_ID, 11L);
    metadata.put(EventDataKeys.TASK_RETRY, null);
    metadata.put(EventDataKeys.TASK_ACTIVITY_ID, TASK_ACTIVITY_ID);
    taskActionExecutor.setBundleContext(bundleContext);
    taskActionExecutor.execute(task, actionInformation, 0, new TaskContext(task, new HashMap<>(), metadata, activityService), TASK_ACTIVITY_ID);
    MotechEvent raisedEvent = new MotechEvent("actionSubject", new HashMap<>(), TasksEventCallbackService.TASKS_EVENT_CALLBACK_NAME, metadata);
    verify(eventRelay).sendEventMessage(raisedEvent);
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) TaskContext(org.motechproject.tasks.service.util.TaskContext) HashMap(java.util.HashMap) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) TreeSet(java.util.TreeSet) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test) ObjectTest(org.motechproject.tasks.domain.ObjectTest)

Example 69 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class EmailPurgerInternal method schedulePurgingJob.

public void schedulePurgingJob(String time, String multiplier) {
    Map<String, Object> params = new HashMap<>();
    params.put("purgeTime", time);
    params.put("purgeMultiplier", multiplier);
    schedulerService.safeScheduleJob(new CronSchedulableJob(new MotechEvent(PurgeEmailEventHandlerImpl.PURGE_EMAIL_SUBJECT, params), "0 0 1 * * ?"));
}
Also used : CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent)

Example 70 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class TestMotechScheduledEvent method newTest.

@Test(expected = IllegalArgumentException.class)
public void newTest() throws Exception {
    MotechEvent motechEvent;
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("JobID", uuidStr);
    motechEvent = new MotechEvent(null, params);
}
Also used : HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Aggregations

MotechEvent (org.motechproject.event.MotechEvent)138 Test (org.junit.Test)87 HashMap (java.util.HashMap)79 CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)28 DateTime (org.joda.time.DateTime)25 DateUtil.newDateTime (org.motechproject.commons.date.util.DateUtil.newDateTime)20 ArrayList (java.util.ArrayList)14 RepeatingSchedulableJob (org.motechproject.scheduler.contract.RepeatingSchedulableJob)13 RunOnceSchedulableJob (org.motechproject.scheduler.contract.RunOnceSchedulableJob)11 JobBasicInfo (org.motechproject.scheduler.contract.JobBasicInfo)10 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)8 Matchers.anyString (org.mockito.Matchers.anyString)7 EventListener (org.motechproject.event.listener.EventListener)7 CronJobId (org.motechproject.scheduler.contract.CronJobId)7 Task (org.motechproject.tasks.domain.mds.task.Task)7 JobId (org.motechproject.scheduler.contract.JobId)6 RepeatingJobId (org.motechproject.scheduler.contract.RepeatingJobId)6 Time (org.motechproject.commons.date.model.Time)5 DayOfWeekSchedulableJob (org.motechproject.scheduler.contract.DayOfWeekSchedulableJob)5 RepeatingPeriodSchedulableJob (org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob)5