use of org.motechproject.tasks.dto.TaskActivityDto in project motech by motech.
the class ActivityController method getTaskActivities.
/**
* Returns the list of activities for task with the given ID.
*
* @param taskId the ID of the task
* @return the list of activities
*/
@RequestMapping(value = "/activity/{taskId}", method = RequestMethod.GET)
@ResponseBody
public TaskActivityRecords getTaskActivities(@PathVariable Long taskId, GridSettings settings) {
if (settings != null) {
QueryParams params = getParams(settings);
Set<TaskActivityType> types = settings.getTypesFromString();
Range<DateTime> dateTimeRange = settings.convertToDateRange(settings.getDateTimeFrom(), settings.getDateTimeTo());
List<TaskActivityDto> activities;
long count;
if (dateTimeRange != null) {
activities = taskWebService.getTaskActivities(taskId, types, dateTimeRange, params, settings.isLastExecution());
count = activityService.getTaskActivitiesCount(taskId, types, dateTimeRange, settings.isLastExecution());
} else {
activities = taskWebService.getTaskActivities(taskId, types, params, settings.isLastExecution());
count = activityService.getTaskActivitiesCount(taskId, types, settings.isLastExecution());
}
int totalPages = (int) Math.ceil((double) count / settings.getRows());
return new TaskActivityRecords(settings.getPage(), totalPages, count, activities);
} else {
return null;
}
}
use of org.motechproject.tasks.dto.TaskActivityDto in project motech by motech.
the class ActivityControllerTest method setup.
@Before
public void setup() throws Exception {
initMocks(this);
controller = new ActivityController(activityService, taskTriggerHandler, taskWebService);
params = new HashMap<String, Object>();
params.put("errorKey", "errorValue");
expected = new ArrayList<>();
expected.add(new TaskActivityDto(SUCCESS.getValue(), TASK_ID, SUCCESS));
expected.add(new TaskActivityDto(WARNING.getValue(), TASK_ID, WARNING));
expected.add(new TaskActivityDto(ERROR.getValue(), TASK_ID, ERROR));
expected.add(new TaskActivityDto(ACTIVITY_ID, ERROR.getValue(), TASK_ID, new ArrayList<>(), null, ERROR, null, params));
activityTypes = new HashSet<>();
activityTypes.addAll(Arrays.asList(TaskActivityType.values()));
queryParams = new QueryParams(page, pageSize);
task = new Task();
task.setId(TASK_ID);
}
use of org.motechproject.tasks.dto.TaskActivityDto in project motech by motech.
the class ActivityController method getAllActivities.
/**
* Returns the list of all the task activities.
*
* @return the list of activities
*/
@RequestMapping(value = "/activity/all", method = RequestMethod.GET)
@ResponseBody
public TaskActivityRecords getAllActivities(GridSettings settings) {
if (settings != null) {
QueryParams params = getParams(settings);
Set<TaskActivityType> types = settings.getTypesFromString();
Range<DateTime> dateTimeRange = settings.convertToDateRange(settings.getDateTimeFrom(), settings.getDateTimeTo());
List<TaskActivityDto> activities;
long count;
if (dateTimeRange != null) {
activities = taskWebService.getAllActivities(types, dateTimeRange, params, settings.isLastExecution());
count = activityService.getAllTaskActivitiesCount(types, dateTimeRange, settings.isLastExecution());
} else {
activities = taskWebService.getAllActivities(types, params, settings.isLastExecution());
count = activityService.getAllTaskActivitiesCount(types, settings.isLastExecution());
}
int totalPages = (int) Math.ceil((double) count / settings.getRows());
return new TaskActivityRecords(settings.getPage(), totalPages, count, activities);
} else {
return null;
}
}
Aggregations