Search in sources :

Example 1 with TaskActivityType

use of org.motechproject.tasks.domain.enums.TaskActivityType in project motech by motech.

the class TaskActivityServiceImplTest method shouldReturnPaginatedActivitiesForGivenTask.

@Test
public void shouldReturnPaginatedActivitiesForGivenTask() {
    Set<TaskActivityType> types = new HashSet<>();
    types.addAll(Arrays.asList(TaskActivityType.values()));
    Set<Long> activitiesIds = new HashSet<>();
    QueryParams queryParams = new QueryParams((Order) null);
    boolean lastExecution = false;
    when(taskActivitiesDataService.byTaskAndActivityTypesAndIds(TASK_ID, types, activitiesIds, queryParams)).thenReturn(activities);
    List<TaskActivity> actual = activityService.getTaskActivities(TASK_ID, types, queryParams, lastExecution);
    assertNotNull(actual);
    assertEquals(activities, actual);
}
Also used : TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) TaskActivityType(org.motechproject.tasks.domain.enums.TaskActivityType) QueryParams(org.motechproject.mds.query.QueryParams) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with TaskActivityType

use of org.motechproject.tasks.domain.enums.TaskActivityType in project motech by motech.

the class ActionParametersBundleIT method hasTaskExecuted.

private boolean hasTaskExecuted(Long taskID) {
    Set<TaskActivityType> activityTypes = new HashSet<>();
    Set<Long> activityIds = new HashSet<>();
    activityTypes.add(TaskActivityType.SUCCESS);
    QueryParams queryParams = new QueryParams((Order) null);
    List<TaskActivity> taskActivities = taskActivitiesDataService.byTaskAndActivityTypesAndIds(taskID, activityTypes, activityIds, queryParams);
    return taskActivities.size() == 1;
}
Also used : TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) TaskActivityType(org.motechproject.tasks.domain.enums.TaskActivityType) QueryParams(org.motechproject.mds.query.QueryParams) HashSet(java.util.HashSet)

Example 3 with TaskActivityType

use of org.motechproject.tasks.domain.enums.TaskActivityType 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 4 with TaskActivityType

use of org.motechproject.tasks.domain.enums.TaskActivityType in project motech by motech.

the class TaskActivityTypeTest method shouldFindTypeFromString.

@Test
public void shouldFindTypeFromString() {
    TaskActivityType actual = TaskActivityType.fromString(ERROR.getValue());
    assertNotNull(actual);
    assertEquals(ERROR.getValue(), actual.getValue());
}
Also used : TaskActivityType(org.motechproject.tasks.domain.enums.TaskActivityType) Test(org.junit.Test)

Example 5 with TaskActivityType

use of org.motechproject.tasks.domain.enums.TaskActivityType 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

TaskActivityType (org.motechproject.tasks.domain.enums.TaskActivityType)5 QueryParams (org.motechproject.mds.query.QueryParams)4 HashSet (java.util.HashSet)2 DateTime (org.joda.time.DateTime)2 Test (org.junit.Test)2 TaskActivity (org.motechproject.tasks.domain.mds.task.TaskActivity)2 TaskActivityDto (org.motechproject.tasks.dto.TaskActivityDto)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2