Search in sources :

Example 1 with DTUserGroup

use of ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup in project irida by phac-nml.

the class GroupsController method getGroups.

/**
 * Search/filter/page with datatables for {@link UserGroup}.
 * @param params {@link DataTablesParams} for the current DataTable
 * @param principal Currently logged in user
 * @return {@link DataTablesResponse} for the current table base on the parameters.
 */
@RequestMapping("/ajax/list")
@ResponseBody
public DataTablesResponse getGroups(@DataTablesRequest final DataTablesParams params, final Principal principal) {
    Page<UserGroup> groups = userGroupService.search(UserGroupSpecification.searchUserGroup(params.getSearchValue()), new PageRequest(params.getCurrentPage(), params.getLength(), params.getSort()));
    User currentUser = userService.getUserByUsername(principal.getName());
    List<DataTablesResponseModel> groupsWithOwnership = groups.getContent().stream().map(ug -> new DTUserGroup(ug, isGroupOwner(currentUser, ug), currentUser.getSystemRole().equals(Role.ROLE_ADMIN))).collect(Collectors.toList());
    return new DataTablesResponse(params, groups, groupsWithOwnership);
}
Also used : UserGroupWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.UserGroupWithoutOwnerException) java.util(java.util) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroupSpecification(ca.corefacility.bioinformatics.irida.repositories.specification.UserGroupSpecification) EntityExistsException(ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) Model(org.springframework.ui.Model) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) ImmutableList(com.google.common.collect.ImmutableList) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) ConstraintViolation(javax.validation.ConstraintViolation) DTGroupMember(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTGroupMember) MessageSource(org.springframework.context.MessageSource) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) Role(ca.corefacility.bioinformatics.irida.model.user.Role) DataTablesRequest(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest) UserGroupRole(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) PageRequest(org.springframework.data.domain.PageRequest) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) UserGroupService(ca.corefacility.bioinformatics.irida.service.user.UserGroupService) Principal(java.security.Principal) ConstraintViolationException(javax.validation.ConstraintViolationException) UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) User(ca.corefacility.bioinformatics.irida.model.user.User) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) PageRequest(org.springframework.data.domain.PageRequest) User(ca.corefacility.bioinformatics.irida.model.user.User) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

Aggregations

EntityExistsException (ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException)1 UserGroupWithoutOwnerException (ca.corefacility.bioinformatics.irida.exceptions.UserGroupWithoutOwnerException)1 Role (ca.corefacility.bioinformatics.irida.model.user.Role)1 User (ca.corefacility.bioinformatics.irida.model.user.User)1 UserGroup (ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)1 UserGroupJoin (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin)1 UserGroupRole (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole)1 UserGroupSpecification (ca.corefacility.bioinformatics.irida.repositories.specification.UserGroupSpecification)1 DataTablesParams (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams)1 DataTablesResponse (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)1 DataTablesRequest (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest)1 DataTablesResponseModel (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel)1 DTGroupMember (ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTGroupMember)1 DTUserGroup (ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup)1 UserGroupService (ca.corefacility.bioinformatics.irida.service.user.UserGroupService)1 UserService (ca.corefacility.bioinformatics.irida.service.user.UserService)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Principal (java.security.Principal)1 java.util (java.util)1