Search in sources :

Example 1 with TaskExecutionProgress

use of org.motechproject.tasks.domain.mds.task.TaskExecutionProgress in project motech by motech.

the class TaskActivitiesDataServiceBundleIT method shouldFindTaskActivitiesByTaskId.

@Test
public void shouldFindTaskActivitiesByTaskId() {
    TaskActivity errorMsg = new TaskActivity(ERROR.getValue(), FIELD, TASK_ID_1, ERROR, new TaskExecutionProgress(1));
    TaskActivity successMsg = new TaskActivity(SUCCESS.getValue(), TASK_ID_1, SUCCESS);
    TaskActivity warningMsg = new TaskActivity(WARNING.getValue(), TASK_ID_2, WARNING);
    taskActivitiesDataService.create(errorMsg);
    taskActivitiesDataService.create(warningMsg);
    taskActivitiesDataService.create(successMsg);
    assertEquals(asList(errorMsg, warningMsg, successMsg), taskActivitiesDataService.retrieveAll());
    List<TaskActivity> messages = taskActivitiesDataService.byTask(TASK_ID_1);
    assertEquals(asList(errorMsg, successMsg), messages);
    assertEquals(ERROR, messages.get(0).getActivityType());
    assertEquals(TASK_ID_1, messages.get(0).getTask());
    assertEquals(ERROR.getValue(), messages.get(0).getMessage());
    assertEquals(FIELD, messages.get(0).getFields());
    assertEquals(SUCCESS, messages.get(1).getActivityType());
    assertEquals(TASK_ID_1, messages.get(1).getTask());
    assertEquals(SUCCESS.getValue(), messages.get(1).getMessage());
    messages = taskActivitiesDataService.byTask(TASK_ID_2);
    assertEquals(asList(warningMsg), messages);
    assertEquals(WARNING, messages.get(0).getActivityType());
    assertEquals(TASK_ID_2, messages.get(0).getTask());
    assertEquals(WARNING.getValue(), messages.get(0).getMessage());
}
Also used : TaskExecutionProgress(org.motechproject.tasks.domain.mds.task.TaskExecutionProgress) TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) Test(org.junit.Test)

Example 2 with TaskExecutionProgress

use of org.motechproject.tasks.domain.mds.task.TaskExecutionProgress in project motech by motech.

the class TaskActivityServiceImpl method addSuccessfulExecution.

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public boolean addSuccessfulExecution(Long activityId) {
    TaskActivity activity = taskActivitiesDataService.findById(activityId);
    if (activity == null) {
        return false;
    }
    TaskExecutionProgress progress = activity.getTaskExecutionProgress();
    progress.addSuccess();
    return updateTaskProgress(progress, activity);
}
Also used : TaskExecutionProgress(org.motechproject.tasks.domain.mds.task.TaskExecutionProgress) TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with TaskExecutionProgress

use of org.motechproject.tasks.domain.mds.task.TaskExecutionProgress in project motech by motech.

the class TaskActivityServiceImpl method addTaskStarted.

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public long addTaskStarted(Task task, Map<String, Object> parameters) {
    int totalActions = task.getActions().size();
    TaskActivity activity = taskActivitiesDataService.create(new TaskActivity(TASK_IN_PROGRESS, Arrays.asList("0", String.valueOf(totalActions)), task.getId(), task.getTrigger().getDisplayName(), TaskActivityType.IN_PROGRESS, null, parameters, new TaskExecutionProgress(totalActions)));
    return activity.getId();
}
Also used : TaskExecutionProgress(org.motechproject.tasks.domain.mds.task.TaskExecutionProgress) TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with TaskExecutionProgress

use of org.motechproject.tasks.domain.mds.task.TaskExecutionProgress in project motech by motech.

the class TaskActivityServiceImpl method addFilteredExecution.

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void addFilteredExecution(Long activityId) {
    TaskActivity activity = taskActivitiesDataService.findById(activityId);
    if (activity != null) {
        TaskExecutionProgress progress = activity.getTaskExecutionProgress();
        progress.addActionFiltered();
        updateTaskProgress(progress, activity);
    }
}
Also used : TaskExecutionProgress(org.motechproject.tasks.domain.mds.task.TaskExecutionProgress) TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

TaskActivity (org.motechproject.tasks.domain.mds.task.TaskActivity)4 TaskExecutionProgress (org.motechproject.tasks.domain.mds.task.TaskExecutionProgress)4 Transactional (org.springframework.transaction.annotation.Transactional)3 Test (org.junit.Test)1