Search in sources :

Example 16 with Task

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);
    }
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task)

Example 17 with 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);
    }
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) Channel(org.motechproject.tasks.domain.mds.channel.Channel) HandlerPredicates.tasksWithRegisteredChannel(org.motechproject.tasks.service.util.HandlerPredicates.tasksWithRegisteredChannel) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) MotechListener(org.motechproject.event.listener.annotations.MotechListener) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with Task

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

Example 19 with Task

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;
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) JsonNode(org.codehaus.jackson.JsonNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with 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());
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task)

Aggregations

Task (org.motechproject.tasks.domain.mds.task.Task)86 Test (org.junit.Test)65 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)35 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)26 HashMap (java.util.HashMap)21 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)19 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)19 ArrayList (java.util.ArrayList)18 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)17 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)16 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)15 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)14 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)13 Channel (org.motechproject.tasks.domain.mds.channel.Channel)12 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)11 KeyInformation (org.motechproject.tasks.domain.KeyInformation)10 TreeSet (java.util.TreeSet)9 MotechEvent (org.motechproject.event.MotechEvent)9 ObjectTest (org.motechproject.tasks.domain.ObjectTest)9 TaskDataProviderObject (org.motechproject.tasks.domain.mds.task.TaskDataProviderObject)9