use of ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse in project irida by phac-nml.
the class SearchController method searchSamples.
/**
* Search all {@link Sample}s in projects for a user based on a query string
*
* @param query the query string
* @param global Whether to perform an admin
* global search
* @param params parameters for a datatables response
* @return a {@link DataTablesResponse} to display search results
*/
@RequestMapping("/search/ajax/samples")
@ResponseBody
public DataTablesResponse searchSamples(@RequestParam String query, @RequestParam(required = false, defaultValue = "false") boolean global, @DataTablesRequest DataTablesParams params) {
Sort originalSort = params.getSort();
List<Sort.Order> orders = Lists.newArrayList();
originalSort.forEach(o -> {
orders.add(new Sort.Order(o.getDirection(), "sample." + o.getProperty()));
});
Sort newSort = new Sort(orders);
Page<ProjectSampleJoin> samplePage;
if (global) {
samplePage = sampleService.searchAllSamples(query, params.getCurrentPage(), params.getLength(), newSort);
} else {
samplePage = sampleService.searchSamplesForUser(query, params.getCurrentPage(), params.getLength(), newSort);
}
List<DataTablesResponseModel> samples = samplePage.getContent().stream().map(this::createDataTablesSample).collect(Collectors.toList());
return new DataTablesResponse(params, samplePage, samples);
}
use of ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse in project irida by phac-nml.
the class ProjectSamplesControllerTest method testGetAjaxProjectSampleModels.
@SuppressWarnings("unchecked")
@Test
public void testGetAjaxProjectSampleModels() {
Sample sample = TestDataFactory.constructSample();
when(projectService.read(anyLong())).thenReturn(project);
when(sampleService.getSamplesForProject(any(Project.class))).thenReturn(ImmutableList.of(new ProjectSampleJoin(project, sample, true)));
when(sampleService.getFilteredSamplesForProjects(any(List.class), any(List.class), any(String.class), any(String.class), any(String.class), any(Date.class), any(Date.class), any(Integer.class), any(Integer.class), any(Sort.class))).thenReturn(TestDataFactory.getPageOfProjectSampleJoin());
DataTablesParams params = mock(DataTablesParams.class);
when(params.getSort()).thenReturn(new Sort(Direction.ASC, "sample.sampleName"));
DataTablesResponse response = controller.getProjectSamples(1L, params, ImmutableList.of(), ImmutableList.of(), new UISampleFilter(), Locale.US);
List<DataTablesResponseModel> data = response.getData();
assertEquals("Has the correct number of samples", 1, data.size());
DTProjectSamples sampleData = (DTProjectSamples) data.get(0);
assertEquals("Has the correct sample", "Joined Sample", sampleData.getSampleName());
}
use of ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse in project irida by phac-nml.
the class ProjectsControllerTest method testGetAjaxProjectList.
@Test
public void testGetAjaxProjectList() {
when(userService.getUserByUsername(USER_NAME)).thenReturn(user);
Page<Project> page = getProjectUserJoinPage(user);
when(projectService.findProjectsForUser(any(String.class), any(Integer.class), any(Integer.class), any(Sort.class))).thenReturn(page);
when(sampleService.getSamplesForProject(any(Project.class))).thenReturn(TestDataFactory.constructListJoinProjectSample());
DataTablesParams params = new DataTablesParams(0, 10, 1, "", new Sort(Sort.Direction.ASC, "modifiedDate"), new HashMap<>());
DataTablesResponse response = controller.getAjaxProjectList(params);
assertEquals("Should have 10 data elements, since page size is 10", 10, response.getData().size());
}
use of ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse in project irida by phac-nml.
the class UsersControllerTest method testGetAjaxUserList.
@SuppressWarnings("unchecked")
@Test
public void testGetAjaxUserList() {
when(userService.search(any(Specification.class), any(PageRequest.class))).thenReturn(userPage);
when(messageSource.getMessage(any(String.class), eq(null), any(Locale.class))).thenReturn("User");
DataTablesParams params = mock(DataTablesParams.class);
when(params.getLength()).thenReturn(1);
DataTablesResponse response = controller.getAjaxUserList(params, Locale.US);
List<DataTablesResponseModel> users = response.getData();
assertEquals(NUM_TOTAL_ELEMENTS, users.size());
DTUser firstUser = (DTUser) users.get(0);
assertEquals("Tom", firstUser.getFirstName());
assertEquals("tom@nowhere.com", firstUser.getEmail());
verify(messageSource, times(2)).getMessage(any(String.class), eq(null), any(Locale.class));
}
use of ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse in project irida by phac-nml.
the class AnalysesListingServiceTest method testGetPagedSubmissionsForUser.
@Test
public void testGetPagedSubmissionsForUser() throws IridaWorkflowNotFoundException, ExecutionManagerException {
String searchValue = "";
User user = new User();
DataTablesParams params = new DataTablesParams(1, 10, 1, searchValue, new Sort(Sort.Direction.ASC, "id"), ImmutableMap.of());
when(analysisSubmissionService.listSubmissionsForUser(eq(searchValue), any(String.class), eq(null), eq(user), Matchers.any(), Matchers.any())).thenReturn(AnalysesDataFactory.getPagedAnalysisSubmissions());
DataTablesResponse response = analysesListingService.getPagedSubmissions(params, Locale.US, user, null);
assertEquals("DataTables response should have a draw value of 1", 1, response.getDraw());
assertEquals("DataTables response should have a records filtered value of 150", 150, response.getRecordsFiltered());
assertEquals("DataTables response should have a records total value of 150", 150, response.getRecordsTotal());
assertTrue("Should have data value", response.getData() != null);
verify(analysisSubmissionService).listSubmissionsForUser(eq(searchValue), any(String.class), eq(null), eq(user), Matchers.any(), Matchers.any());
}
Aggregations