Search in sources :

Example 16 with MotechEvent

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

the class MdsDdeBundleIT method testMdsCrudEvents.

@Test
public void testMdsCrudEvents() throws Exception {
    getLogger().info("Test MDS CRUD Events");
    final ArrayList<String> receivedEvents = new ArrayList<>();
    final Map<String, Object> params = new HashMap<>();
    String moduleName = "MOTECH Platform Data Services Test Bundle";
    String simplifiedModuleName = simplifiedModuleName(moduleName);
    String entityName = "TestMdsEntity";
    final String subject = createSubject(moduleName, null, entityName, CrudEventType.CREATE);
    registry.registerListener(new EventListener() {

        @Override
        public void handle(MotechEvent event) {
            receivedEvents.add(event.getSubject());
            params.putAll(event.getParameters());
            synchronized (waitLock) {
                waitLock.notify();
            }
        }

        @Override
        public String getIdentifier() {
            return subject;
        }
    }, subject);
    wait2s();
    testMdsEntityService.create(new TestMdsEntity("string"));
    wait2s();
    assertEquals(1, receivedEvents.size());
    assertEquals(subject, receivedEvents.get(0));
    assertEquals(simplifiedModuleName, params.get(MODULE_NAME));
    assertEquals(entityName, params.get(ENTITY_NAME));
    assertEquals(TestMdsEntity.class.getName(), params.get(ENTITY_CLASS));
    testMdsEntityService.deleteAll();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EventListener(org.motechproject.event.listener.EventListener) MotechEvent(org.motechproject.event.MotechEvent) TestMdsEntity(org.motechproject.mds.test.domain.TestMdsEntity) Test(org.junit.Test)

Example 17 with MotechEvent

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

the class MotechSchedulerActionProxyServiceImpl method scheduleRepeatingJob.

@Override
public // NO CHECKSTYLE More than 7 parameters (found 8).
void scheduleRepeatingJob(// NO CHECKSTYLE More than 7 parameters (found 8).
String subject, Map<Object, Object> parameters, DateTime startTime, DateTime endTime, Integer repeatCount, Integer repeatIntervalInSeconds, Boolean ignorePastFiresAtStart, Boolean useOriginalFireTimeAfterMisfire) {
    MotechEvent motechEvent = new MotechEvent(subject, createMotechEventParameters(parameters));
    RepeatingSchedulableJob job = new RepeatingSchedulableJob();
    job.setMotechEvent(motechEvent);
    job.setStartDate(startTime);
    job.setEndDate(endTime);
    job.setRepeatCount(repeatCount);
    job.setRepeatIntervalInSeconds(repeatIntervalInSeconds);
    job.setIgnorePastFiresAtStart(ignorePastFiresAtStart);
    job.setUseOriginalFireTimeAfterMisfire(useOriginalFireTimeAfterMisfire);
    scheduler.scheduleRepeatingJob(job);
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) MotechEvent(org.motechproject.event.MotechEvent)

Example 18 with MotechEvent

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

the class MotechSchedulerActionProxyServiceImpl method scheduleRunOnceJob.

@Override
public void scheduleRunOnceJob(String subject, Map<Object, Object> parameters, DateTime startDate) {
    MotechEvent motechEvent = new MotechEvent(subject, createMotechEventParameters(parameters));
    RunOnceSchedulableJob job = new RunOnceSchedulableJob(motechEvent, startDate);
    scheduler.scheduleRunOnceJob(job);
}
Also used : MotechEvent(org.motechproject.event.MotechEvent) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob)

Example 19 with MotechEvent

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

the class MotechSchedulerServiceImpl method assertArgumentNotNull.

private MotechEvent assertArgumentNotNull(SchedulableJob schedulableJob) {
    assertArgumentNotNull("SchedulableJob", schedulableJob);
    MotechEvent motechEvent = schedulableJob.getMotechEvent();
    assertArgumentNotNull("Invalid SchedulableJob. MotechEvent of the SchedulableJob", motechEvent);
    return motechEvent;
}
Also used : MotechEvent(org.motechproject.event.MotechEvent)

Example 20 with MotechEvent

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

the class MotechSchedulerServiceImpl method scheduleRunOnceJob.

private void scheduleRunOnceJob(RunOnceSchedulableJob job, boolean update) {
    logObjectIfNotNull(job);
    validateRunOnceSchedulableJob(job);
    MotechEvent motechEvent = job.getMotechEvent();
    JobId jobId = new RunOnceJobId(motechEvent);
    JobDetail jobDetail = newJob(MotechScheduledJob.class).withIdentity(jobId.value(), JOB_GROUP_NAME).build();
    putMotechEventDataToJobDataMap(jobDetail.getJobDataMap(), motechEvent);
    Map<String, Object> metadata = new HashMap<>();
    metadata.put(UI_DEFINED, job.isUiDefined());
    metadata.putAll(motechEvent.getMetadata());
    jobDetail.getJobDataMap().put(EVENT_METADATA, metadata);
    SimpleScheduleBuilder simpleSchedule = simpleSchedule().withRepeatCount(0).withIntervalInSeconds(0).withMisfireHandlingInstructionFireNow();
    Trigger trigger = newTrigger().withIdentity(triggerKey(jobId.value(), JOB_GROUP_NAME)).forJob(jobDetail).withSchedule(simpleSchedule).startAt(DateUtil.toDate(job.getStartDate())).build();
    scheduleJob(jobDetail, trigger, update);
}
Also used : JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) OperableTrigger(org.quartz.spi.OperableTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent) SimpleScheduleBuilder(org.quartz.SimpleScheduleBuilder) RunOnceJobId(org.motechproject.scheduler.contract.RunOnceJobId) JobId(org.motechproject.scheduler.contract.JobId) RepeatingJobId(org.motechproject.scheduler.contract.RepeatingJobId) RepeatingPeriodJobId(org.motechproject.scheduler.contract.RepeatingPeriodJobId) CronJobId(org.motechproject.scheduler.contract.CronJobId) RunOnceJobId(org.motechproject.scheduler.contract.RunOnceJobId)

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