use of ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUser in project irida by phac-nml.
the class UsersController method getAjaxUserList.
/**
* Get a list of users based on search criteria.
* @param params {@link DataTablesParams} for the current Users DataTables.
* @param locale {@link Locale}
* @return {@link DataTablesResponse} of the filtered users list.
*/
@RequestMapping(value = "/ajax/list", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public DataTablesResponse getAjaxUserList(@DataTablesRequest DataTablesParams params, Locale locale) {
Page<User> userPage = userService.search(UserSpecification.searchUser(params.getSearchValue()), new PageRequest(params.getCurrentPage(), params.getLength(), params.getSort()));
List<DataTablesResponseModel> usersData = new ArrayList<>();
for (User user : userPage) {
// getting internationalized system role from the message source
String roleMessageName = "systemrole." + user.getSystemRole().getName();
String systemRole = messageSource.getMessage(roleMessageName, null, locale);
usersData.add(new DTUser(user.getId(), user.getUsername(), user.getFirstName(), user.getLastName(), user.getEmail(), systemRole, user.getCreatedDate(), user.getModifiedDate(), user.getLastLogin()));
}
return new DataTablesResponse(params, userPage, usersData);
}
use of ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUser 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));
}
Aggregations