use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TasksPostExecutionHandler method handleActionExecuted.
/**
* Handles successful execution of a single task action. If all actions of the task have been successfully executed,
* it sends an event with the message about successful execution, resets the task failures in row count and passes the
* info about successful execution to {@link TaskRetryHandler}.
*
* @param params trigger event parameters that invoked the task
* @param activityId the id of an activity
*/
public void handleActionExecuted(Map<String, Object> params, Map<String, Object> metadata, Long activityId) {
boolean taskFinished = activityService.addSuccessfulExecution(activityId);
if (taskFinished) {
Long taskId = activityService.getTaskActivityById(activityId).getTask();
Task task = taskService.getTask(taskId);
handleSuccess(params, task);
}
}
use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskServiceImpl method validateTasksAfterChannelUpdate.
@MotechListener(subjects = CHANNEL_UPDATE_SUBJECT)
@Transactional
public void validateTasksAfterChannelUpdate(MotechEvent event) {
String moduleName = event.getParameters().get(CHANNEL_MODULE_NAME).toString();
Channel channel = channelService.getChannel(moduleName);
LOGGER.debug("Handling Channel update: {} for module: {}", channel.getDisplayName(), moduleName);
List<Task> tasks = findTasksDependentOnModule(moduleName);
for (Task task : tasks) {
Set<TaskError> errors;
if (task.getTrigger() != null) {
errors = validateTrigger(task);
handleValidationErrors(task, errors, TASK_TRIGGER_VALIDATION_ERRORS);
}
errors = validateActions(task, channel);
handleValidationErrors(task, errors, TASK_ACTION_VALIDATION_ERRORS);
}
}
use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskServiceImpl method deleteTask.
@Override
@Transactional
public void deleteTask(Long taskId) {
Task t = getTask(taskId);
if (t == null) {
throw new TaskNotFoundException(taskId);
}
LOGGER.info("Deleted task: {} with ID: {}", t.getName(), taskId);
tasksDataService.delete(t);
}
use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskServiceImpl method importTask.
@Override
@Transactional
public Task importTask(String json) throws IOException {
LOGGER.info("Importing a task from json");
LOGGER.trace("The json file: {}", json);
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree(json);
removeIgnoredFields(node);
Task task = mapper.readValue(node, Task.class);
taskMigrationManager.migrateTask(task);
save(task);
return task;
}
use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskServiceImpl method addOrUpdate.
private void addOrUpdate(final Task task) {
Task existing = tasksDataService.findById(task.getId());
if (null != existing) {
LOGGER.debug("Updating task: {} with ID: {}", existing.getName(), existing.getId());
existing.setActions(task.getActions());
existing.setDescription(task.getDescription());
existing.setFailuresInRow(task.getFailuresInRow());
if (!existing.isEnabled() && task.isEnabled()) {
existing.resetFailuresInRow();
}
existing.setEnabled(task.isEnabled());
existing.setHasRegisteredChannel(task.hasRegisteredChannel());
existing.setTaskConfig(task.getTaskConfig());
existing.setTrigger(task.getTrigger());
existing.setName(task.getName());
existing.setValidationErrors(task.getValidationErrors());
existing.setRetryTaskOnFailure(task.isRetryTaskOnFailure());
existing.setNumberOfRetries(task.getNumberOfRetries());
existing.setRetryIntervalInMilliseconds(task.getRetryIntervalInMilliseconds());
existing.setUseTimeWindow(task.isUsingTimeWindow());
existing.setStartTime(task.getStartTime());
existing.setEndTime(task.getEndTime());
existing.setDays(task.getDays());
checkChannelAvailableInTask(existing);
tasksDataService.update(existing);
} else {
LOGGER.debug("Creating task: {}", task.getName());
checkChannelAvailableInTask(task);
tasksDataService.create(task);
}
LOGGER.info("Saved task: {}", task.getName());
}
Aggregations