Search in sources :

Example 1 with TaskActivityDto

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;
    }
}
Also used : TaskActivityType(org.motechproject.tasks.domain.enums.TaskActivityType) QueryParams(org.motechproject.mds.query.QueryParams) TaskActivityDto(org.motechproject.tasks.dto.TaskActivityDto) DateTime(org.joda.time.DateTime) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with TaskActivityDto

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);
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) ArrayList(java.util.ArrayList) TaskActivityDto(org.motechproject.tasks.dto.TaskActivityDto) QueryParams(org.motechproject.mds.query.QueryParams) Before(org.junit.Before)

Example 3 with TaskActivityDto

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;
    }
}
Also used : TaskActivityType(org.motechproject.tasks.domain.enums.TaskActivityType) QueryParams(org.motechproject.mds.query.QueryParams) TaskActivityDto(org.motechproject.tasks.dto.TaskActivityDto) DateTime(org.joda.time.DateTime) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

QueryParams (org.motechproject.mds.query.QueryParams)3 TaskActivityDto (org.motechproject.tasks.dto.TaskActivityDto)3 DateTime (org.joda.time.DateTime)2 TaskActivityType (org.motechproject.tasks.domain.enums.TaskActivityType)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Task (org.motechproject.tasks.domain.mds.task.Task)1