Search in sources :

Example 1 with DTUser

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);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) DTUser(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUser) User(ca.corefacility.bioinformatics.irida.model.user.User) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) ArrayList(java.util.ArrayList) DTUser(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUser) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with DTUser

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));
}
Also used : Locale(java.util.Locale) PageRequest(org.springframework.data.domain.PageRequest) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) Specification(org.springframework.data.jpa.domain.Specification) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) DTUser(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUser) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) Test(org.junit.Test)

Aggregations

DataTablesResponse (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)2 DataTablesResponseModel (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel)2 DTUser (ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUser)2 PageRequest (org.springframework.data.domain.PageRequest)2 User (ca.corefacility.bioinformatics.irida.model.user.User)1 DataTablesParams (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 Test (org.junit.Test)1 Specification (org.springframework.data.jpa.domain.Specification)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1