Search in sources :

Example 1 with TasksEventParser

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);
    }
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) TasksEventParser(org.motechproject.commons.api.TasksEventParser) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

TasksEventParser (org.motechproject.commons.api.TasksEventParser)1 Task (org.motechproject.tasks.domain.mds.task.Task)1 Transactional (org.springframework.transaction.annotation.Transactional)1