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();
}
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);
}
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);
}
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;
}
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);
}
Aggregations