@Test public void shouldAddErrorActivityWithTaskException() { when(taskActivitiesDataService.findById(TASK_ACTIVITY_ID)).thenReturn(createInProgress()); String messageKey = "error.notFoundTrigger"; TaskHandlerException exception = new TaskHandlerException(TRIGGER, messageKey, ERROR_FIELD.get(0)); ArgumentCaptor<TaskActivity> captor = ArgumentCaptor.forClass(TaskActivity.class); activityService.addFailedExecution(TASK_ACTIVITY_ID, exception); verify(taskActivitiesDataService).update(captor.capture()); assertActivity(messageKey, ERROR_FIELD, TASK_ID, TaskActivityType.ERROR, getStackTrace(exception), null, captor.getValue()); }
@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); } }
TaskActivityServiceImpl implements TaskActivityService { @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); } } }
TaskActivityServiceImpl implements TaskActivityService { @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); } } @Autowired  TaskActivityServiceImpl(TaskActivitiesDataService taskActivitiesDataService); }
TaskActivityServiceImpl implements TaskActivityService { @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); } } @Autowired  TaskActivityServiceImpl(TaskActivitiesDataService taskActivitiesDataService); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) long addTaskStarted(Task task, Map<String, Object> parameters); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void addTaskFiltered(Long activityId); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) boolean addSuccessfulExecution(Long activityId); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void addFilteredExecution(Long activityId); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void addFailedExecution(Long activityId, Throwable e); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void addTaskDisabledWarning(Task task); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void addWarning(Task task, String key, String field); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void addWarningWithException(Task task, String key, String field, Exception e); @Override @Transactional void deleteActivitiesForTask(Long taskId); @Override @Transactional TaskActivity getTaskActivityById(Long activityId); @Override @Transactional List<TaskActivity> getLatestActivities(); @Override @Transactional List<TaskActivity> getAllActivities(Set<TaskActivityType> activityTypes, QueryParams queryParams, boolean lastExecution); @Override @Transactional List<TaskActivity> getAllActivities(Set<TaskActivityType> activityTypes, Range<DateTime> dateRange,
                                               QueryParams queryParams, boolean lastExecution); @Override @Transactional List<TaskActivity> getTaskActivities(Long taskId, Set<TaskActivityType> activityTypes, QueryParams queryParams, boolean lastExecution); @Override @Transactional List<TaskActivity> getTaskActivities(Long taskId, Set<TaskActivityType> activityTypes, Range<DateTime> dateRange,
                                                QueryParams queryParams, boolean lastExecution); @Override @Transactional long getTaskActivitiesCount(Long taskId, Set<TaskActivityType> activityTypes, boolean lastExecution); @Override @Transactional long getTaskActivitiesCount(Long taskId, TaskActivityType type); @Override @Transactional long getTaskActivitiesCount(Long taskId, Set<TaskActivityType> activityTypes, Range<DateTime> dateRange, boolean lastExecution); @Override @Transactional long getAllTaskActivitiesCount(Set<TaskActivityType> activityTypes, boolean lastExecution); @Override @Transactional long getAllTaskActivitiesCount(Set<TaskActivityType> activityTypes, Range<DateTime> dateRange, boolean lastExecution); }
TaskActivityServiceImpl implements TaskActivityService { @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); } } @Autowired  TaskActivityServiceImpl(TaskActivitiesDataService taskActivitiesDataService); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) long addTaskStarted(Task task, Map<String, Object> parameters); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void addTaskFiltered(Long activityId); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) boolean addSuccessfulExecution(Long activityId); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void addFilteredExecution(Long activityId); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void addFailedExecution(Long activityId, Throwable e); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void addTaskDisabledWarning(Task task); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void addWarning(Task task, String key, String field); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void addWarningWithException(Task task, String key, String field, Exception e); @Override @Transactional void deleteActivitiesForTask(Long taskId); @Override @Transactional TaskActivity getTaskActivityById(Long activityId); @Override @Transactional List<TaskActivity> getLatestActivities(); @Override @Transactional List<TaskActivity> getAllActivities(Set<TaskActivityType> activityTypes, QueryParams queryParams, boolean lastExecution); @Override @Transactional List<TaskActivity> getAllActivities(Set<TaskActivityType> activityTypes, Range<DateTime> dateRange,
                                               QueryParams queryParams, boolean lastExecution); @Override @Transactional List<TaskActivity> getTaskActivities(Long taskId, Set<TaskActivityType> activityTypes, QueryParams queryParams, boolean lastExecution); @Override @Transactional List<TaskActivity> getTaskActivities(Long taskId, Set<TaskActivityType> activityTypes, Range<DateTime> dateRange,
                                                QueryParams queryParams, boolean lastExecution); @Override @Transactional long getTaskActivitiesCount(Long taskId, Set<TaskActivityType> activityTypes, boolean lastExecution); @Override @Transactional long getTaskActivitiesCount(Long taskId, TaskActivityType type); @Override @Transactional long getTaskActivitiesCount(Long taskId, Set<TaskActivityType> activityTypes, Range<DateTime> dateRange, boolean lastExecution); @Override @Transactional long getAllTaskActivitiesCount(Set<TaskActivityType> activityTypes, boolean lastExecution); @Override @Transactional long getAllTaskActivitiesCount(Set<TaskActivityType> activityTypes, Range<DateTime> dateRange, boolean lastExecution);  }