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);
}
}
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);
}
}
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));
}
}
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()));
}
}
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);
}
Aggregations