Search in sources :

Example 11 with TaskActivity

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

the class TaskActivityServiceImpl method addFailedExecution.

@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void addFailedExecution(Long activityId, Throwable e) {
    TaskActivity activity = taskActivitiesDataService.findById(activityId);
    if (activity == null) {
        return;
    }
    if (activity.getActivityType() != TaskActivityType.ERROR) {
        activity.setMessage(e.getMessage());
        activity.setActivityType(TaskActivityType.ERROR);
        if (e instanceof TaskHandlerException) {
            activity.setFields(((TaskHandlerException) e).getArgs());
        }
        activity.setStackTraceElement(ExceptionUtils.getStackTrace(e));
        taskActivitiesDataService.update(activity);
    }
}
Also used : TaskHandlerException(org.motechproject.tasks.exception.TaskHandlerException) TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with TaskActivity

use of org.motechproject.tasks.domain.mds.task.TaskActivity 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)

Example 13 with TaskActivity

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

the class TaskActivitiesDataServiceBundleIT method setUpActivityRecords.

private void setUpActivityRecords() {
    for (int i = 0; i < 50; i++) {
        TimeFaker.fakeNow(new DateTime(2014, 12, 7, 12, 53, i));
        taskActivitiesDataService.create(new TaskActivity("task executed", 1L, TaskActivityType.SUCCESS));
    }
}
Also used : TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) DateTime(org.joda.time.DateTime)

Example 14 with TaskActivity

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

the class TaskActivitiesDataServiceBundleIT method shouldReturnLatestRecordsOrderedByDate.

@Test
public void shouldReturnLatestRecordsOrderedByDate() {
    setUpActivityRecords();
    List<TaskActivity> allActivities = taskActivitiesDataService.retrieveAll();
    List<TaskActivity> activities = taskActivitiesDataService.retrieveAll(new QueryParams(1, 10, new Order("date", Order.Direction.DESC)));
    // There should always be only 10 records returned
    assertEquals(10, activities.size());
    // The first activity should have the most recent one
    DateTime mostRecentDate = new DateTime(0);
    for (TaskActivity activity : allActivities) {
        if (activity.getDate().isAfter(mostRecentDate)) {
            mostRecentDate = activity.getDate();
        }
    }
    assertEquals(mostRecentDate, activities.get(0).getDate());
    // All recent activities should be sorted by date
    for (int i = 1; i < 10; i++) {
        assertTrue(activities.get(i - 1).getDate().isAfter(activities.get(i).getDate()));
    }
}
Also used : Order(org.motechproject.mds.util.Order) TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) QueryParams(org.motechproject.mds.query.QueryParams) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 15 with TaskActivity

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

the class TaskActivityServiceImplTest method shouldAddTaskSuccessActivity.

@Test
public void shouldAddTaskSuccessActivity() {
    when(taskActivitiesDataService.findById(TASK_ACTIVITY_ID)).thenReturn(createInProgress());
    String messageKey = "task.success.ok";
    ArgumentCaptor<TaskActivity> captor = ArgumentCaptor.forClass(TaskActivity.class);
    activityService.addSuccessfulExecution(TASK_ACTIVITY_ID);
    verify(taskActivitiesDataService).findById(TASK_ACTIVITY_ID);
    verify(taskActivitiesDataService).update(captor.capture());
    TaskActivity activity = captor.getValue();
    assertEquals(1, activity.getTaskExecutionProgress().getActionsSucceeded());
    assertActivity(messageKey, Collections.<String>emptyList(), TASK_ID, TaskActivityType.SUCCESS, null, null, activity);
}
Also used : TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) Test(org.junit.Test)

Aggregations

TaskActivity (org.motechproject.tasks.domain.mds.task.TaskActivity)16 Test (org.junit.Test)6 Transactional (org.springframework.transaction.annotation.Transactional)6 TaskExecutionProgress (org.motechproject.tasks.domain.mds.task.TaskExecutionProgress)4 QueryParams (org.motechproject.mds.query.QueryParams)3 TaskHandlerException (org.motechproject.tasks.exception.TaskHandlerException)3 HashSet (java.util.HashSet)2 DateTime (org.joda.time.DateTime)2 TaskActivityType (org.motechproject.tasks.domain.enums.TaskActivityType)2 Order (org.motechproject.mds.util.Order)1