Search in sources :

Example 1 with JobsRecords

use of org.motechproject.scheduler.web.domain.JobsRecords in project motech by motech.

the class JobsControllerTest method shouldGetJobsRecords.

@Test
public void shouldGetJobsRecords() throws SchedulerException, SQLException {
    List<JobBasicInfo> jobBasicInfos = getTestJobBasicInfos();
    JobsSearchSettings jobsSearchSettings = getDefaultGridSettings();
    when(motechSchedulerDatabaseService.getScheduledJobsBasicInfo(jobsSearchSettings)).thenReturn(jobBasicInfos);
    JobsRecords result = jobsController.retrieveJobInfo(jobsSearchSettings);
    assertEquals(jobBasicInfos, result.getRows());
    verify(motechSchedulerDatabaseService).getScheduledJobsBasicInfo(jobsSearchSettings);
}
Also used : JobsRecords(org.motechproject.scheduler.web.domain.JobsRecords) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) Test(org.junit.Test)

Example 2 with JobsRecords

use of org.motechproject.scheduler.web.domain.JobsRecords in project motech by motech.

the class JobsController method retrieveJobInfo.

/**
 * Returns job information sorted and filtered as defined in {@code jobsGridSettings}.
 *
 * @param jobsSearchSettings  the setting by which returned records are sorted and filtered
 * @return sorted and filtered job records
 */
@RequestMapping(value = "/jobs", method = RequestMethod.GET)
@ResponseBody
public JobsRecords retrieveJobInfo(JobsSearchSettings jobsSearchSettings) throws SchedulerException, SQLException {
    List<JobBasicInfo> jobs = motechSchedulerDatabaseService.getScheduledJobsBasicInfo(jobsSearchSettings);
    int rowCount = jobs.size() == 0 ? 0 : motechSchedulerDatabaseService.countJobs(jobsSearchSettings);
    if (jobsSearchSettings.getRows() == null) {
        int defaultRowsNumber = 10;
        jobsSearchSettings.setRows(defaultRowsNumber);
    }
    if (jobsSearchSettings.getPage() == null) {
        int defaultPage = 1;
        jobsSearchSettings.setPage(defaultPage);
    }
    previousJobsRecords = new JobsRecords(jobsSearchSettings.getPage(), jobsSearchSettings.getRows(), rowCount, jobs);
    return previousJobsRecords;
}
Also used : JobsRecords(org.motechproject.scheduler.web.domain.JobsRecords) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with JobsRecords

use of org.motechproject.scheduler.web.domain.JobsRecords in project motech by motech.

the class JobsControllerTest method shouldGetAllJobsRecordsWhenNoFiltersSet.

@Test
public void shouldGetAllJobsRecordsWhenNoFiltersSet() throws SchedulerException, SQLException {
    List<JobBasicInfo> jobBasicInfos = getTestJobBasicInfos();
    JobsSearchSettings jobsSearchSettings = new JobsSearchSettings();
    when(motechSchedulerDatabaseService.getScheduledJobsBasicInfo(jobsSearchSettings)).thenReturn(jobBasicInfos);
    JobsRecords result = jobsController.retrieveJobInfo(jobsSearchSettings);
    assertEquals(jobBasicInfos, result.getRows());
    verify(motechSchedulerDatabaseService).getScheduledJobsBasicInfo(jobsSearchSettings);
}
Also used : JobsRecords(org.motechproject.scheduler.web.domain.JobsRecords) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) Test(org.junit.Test)

Aggregations

JobBasicInfo (org.motechproject.scheduler.contract.JobBasicInfo)3 JobsRecords (org.motechproject.scheduler.web.domain.JobsRecords)3 Test (org.junit.Test)2 JobsSearchSettings (org.motechproject.scheduler.contract.JobsSearchSettings)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1