use of org.motechproject.commons.api.TasksEventParser in project motech by motech.
the class TaskTriggerHandler method handle.
@Override
@Transactional
public void handle(MotechEvent event) {
LOGGER.info("Handling the motech event with subject: {}", event.getSubject());
// Look for custom event parser
Map<String, Object> eventParams = event.getParameters();
eventParams.putAll(event.getMetadata());
TasksEventParser parser = null;
if (eventParams != null) {
parser = taskService.findCustomParser((String) eventParams.get(TasksEventParser.CUSTOM_PARSER_EVENT_KEY));
}
// Use custom event parser, if it exists, to modify event
String triggerSubject = parser == null ? event.getSubject() : parser.parseEventSubject(event.getSubject(), eventParams);
Map<String, Object> parameters = parser == null ? eventParams : parser.parseEventParameters(event.getSubject(), eventParams);
List<Task> tasks = taskService.findActiveTasksForTriggerSubject(triggerSubject);
// Handle all tasks one by one
for (Task task : tasks) {
checkAndHandleTask(task, parameters);
}
}
Aggregations