use of org.motechproject.tasks.domain.mds.task.Task 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);
}
}
use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TasksEventCallbackService method failureCallback.
@Override
public boolean failureCallback(MotechEvent event, Throwable throwable) {
LOGGER.debug("Received failure callback for event subject {}", event.getSubject());
Map<String, Object> metadata = event.getMetadata();
Long activityId = (Long) metadata.get(EventDataKeys.TASK_ACTIVITY_ID);
Task task = taskService.getTask((Long) metadata.get(EventDataKeys.TASK_ID));
postExecutionHandler.handleError(event.getParameters(), metadata, task, new TaskHandlerException(TaskFailureCause.ACTION, "task.error.eventHandlerFailed", throwable), activityId);
return false;
}
use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskControllerTest method shouldImportTask.
@Test
public void shouldImportTask() throws Exception {
ObjectMapper mapper = new ObjectMapper();
StringWriter writer = new StringWriter();
IOUtils.copy(this.getClass().getResourceAsStream("/new-task-version.json"), writer);
ObjectNode node = (ObjectNode) mapper.readTree(writer.toString());
node.remove(asList("validationErrors", "type", "_rev"));
String json = node.toString();
when(taskService.importTask(json.toString())).thenReturn(new Task(null, trigger, null));
when(file.getInputStream()).thenReturn(new ByteArrayInputStream(json.getBytes()));
controller.importTask(file);
verify(taskService).importTask(json);
}
use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskControllerTest method shouldSaveTask.
@Test
public void shouldSaveTask() {
String subject = "trigger1";
TaskActionInformation action = new TaskActionInformation("send", "action1", "action", "0.15", "send", new HashMap<String, String>());
TaskTriggerInformation trigger = new TaskTriggerInformation("trigger", "trigger1", "trigger", "0.16", subject, subject);
Task expected = new Task("name", trigger, asList(action));
when(eventListenerRegistryService.getListeners(subject)).thenReturn(new HashSet<EventListener>());
controller.save(expected);
verify(taskWebService).save(expected);
}
use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskBuilderTest method shouldReturnBuiltTaskObject.
@Test
public void shouldReturnBuiltTaskObject() throws Exception {
TaskBuilder builder = new TaskBuilder();
Task task = builder.withName(TASK_NAME).withDescription(TASK_DESCRIPTION).isEnabled(isEnabled).withTrigger(new TaskTriggerInformation()).addAction(new TaskActionInformation()).withTaskConfig(new TaskConfig()).addFilterSet(new FilterSet()).addDataSource(new DataSource()).build();
assertNotNull(task);
assertEquals(TASK_NAME, task.getName());
assertEquals(TASK_DESCRIPTION, task.getDescription());
assertEquals(isEnabled, task.isEnabled());
assertNotNull(task.getTrigger());
assertNotNull(task.getActions());
assertFalse(task.getActions().isEmpty());
assertNotNull(task.getTaskConfig());
assertFalse(task.getTaskConfig().getDataSources().isEmpty());
assertFalse(task.getTaskConfig().getFilters().isEmpty());
}
Aggregations