Search in sources :

Example 11 with DataTablesResponseModel

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

the class ProjectMembersController method getProjectGroupMembers.

/**
 * Get a page of groups on the project for display in a DataTable.
 *
 * @param params
 *            the datatables criteria for filtering/sorting groups
 * @param projectId
 *            the id of the project we're looking at
 * @return a {@link DataTablesResponseModel} of groups on the project
 */
@RequestMapping(value = "/{projectId}/settings/ajax/groups")
@ResponseBody
public DataTablesResponse getProjectGroupMembers(@DataTablesRequest DataTablesParams params, @PathVariable final Long projectId) {
    final Project project = projectService.read(projectId);
    final Page<UserGroupProjectJoin> userGroupsForProject = userGroupService.getUserGroupsForProject(params.getSearchValue(), project, params.getCurrentPage(), params.getLength(), params.getSort());
    List<DataTablesResponseModel> responseModels = new ArrayList<>();
    for (UserGroupProjectJoin userGroupProjectJoin : userGroupsForProject) {
        responseModels.add(new DTProjectGroup(userGroupProjectJoin));
    }
    return new DataTablesResponse(params, userGroupsForProject, responseModels);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DTProjectGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTProjectGroup) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)

Example 12 with DataTablesResponseModel

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

the class ProjectSamplesController method getProjectSamples.

/**
 * Generate the {@link Sample}s for the {@link Project} table based on the filter criteria.
 *
 * @param projectId   identifier for the current {@link Project}
 * @param params      for the current DataTable.
 * @param sampleNames List of {@link Sample} names to filter by.
 * @param associated  List of associated {@link Project} identifiers currently displayed in the table.
 * @param filter      for specific {@link Sample} attributes.
 * @param locale      for the current user.
 * @return {@link DTProjectSamples} that meet the requirements
 */
@RequestMapping(value = "/projects/{projectId}/ajax/samples", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
@ResponseBody
public DataTablesResponse getProjectSamples(@PathVariable Long projectId, @DataTablesRequest DataTablesParams params, @RequestParam(required = false, name = "sampleNames[]", defaultValue = "") List<String> sampleNames, @RequestParam(required = false, name = "associated[]", defaultValue = "") List<Long> associated, UISampleFilter filter, Locale locale) {
    List<Project> projects = new ArrayList<>();
    // Check to see if any associated projects need to be added to the query.
    if (!associated.isEmpty()) {
        projects = (List<Project>) projectService.readMultiple(associated);
    }
    // This project is always in the query.
    projects.add(projectService.read(projectId));
    final Page<ProjectSampleJoin> page = sampleService.getFilteredSamplesForProjects(projects, sampleNames, filter.getName(), params.getSearchValue(), filter.getOrganism(), filter.getStartDate(), filter.getEndDate(), params.getCurrentPage(), params.getLength(), params.getSort());
    // Create DataTables representation of the page.
    List<DataTablesResponseModel> models = new ArrayList<>();
    for (ProjectSampleJoin psj : page.getContent()) {
        models.add(buildProjectSampleDataTablesModel(psj, locale));
    }
    return new DataTablesResponse(params, page, models);
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)

Example 13 with DataTablesResponseModel

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

the class AnnouncementsController method getUserAnnouncementInfoTable.

/**
 * Get user read status for current announcement
 * @param announcementID {@link Long} identifier for the {@link Announcement}
 * @param params {@link DataTablesParams} parameters for current DataTable
 * @return {@link DataTablesResponse} containing the list of users.
 */
@RequestMapping(value = "/{announcementID}/details/ajax/list", method = RequestMethod.GET)
@PreAuthorize("hasRole('ROLE_ADMIN')")
@ResponseBody
public DataTablesResponse getUserAnnouncementInfoTable(@PathVariable Long announcementID, @DataTablesRequest final DataTablesParams params) {
    final Announcement currentAnnouncement = announcementService.read(announcementID);
    final Page<User> page = userService.search(UserSpecification.searchUser(params.getSearchValue()), new PageRequest(params.getCurrentPage(), params.getLength(), params.getSort()));
    final List<DataTablesResponseModel> announcementUsers = page.getContent().stream().map(user -> new DTAnnouncementUser(user, userHasRead(user, currentAnnouncement))).collect(Collectors.toList());
    return new DataTablesResponse(params, page, announcementUsers);
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Controller(org.springframework.stereotype.Controller) Announcement(ca.corefacility.bioinformatics.irida.model.announcements.Announcement) Model(org.springframework.ui.Model) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) AnnouncementSpecification(ca.corefacility.bioinformatics.irida.repositories.specification.AnnouncementSpecification) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) Logger(org.slf4j.Logger) DTAnnouncementUser(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTAnnouncementUser) DataTablesRequest(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest) PageRequest(org.springframework.data.domain.PageRequest) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) IOException(java.io.IOException) DTAnnouncementAdmin(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTAnnouncementAdmin) Page(org.springframework.data.domain.Page) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) UserSpecification(ca.corefacility.bioinformatics.irida.repositories.specification.UserSpecification) List(java.util.List) Principal(java.security.Principal) UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) Optional(java.util.Optional) AnnouncementUserJoin(ca.corefacility.bioinformatics.irida.model.announcements.AnnouncementUserJoin) User(ca.corefacility.bioinformatics.irida.model.user.User) AnnouncementService(ca.corefacility.bioinformatics.irida.service.AnnouncementService) Collections(java.util.Collections) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) PageRequest(org.springframework.data.domain.PageRequest) DTAnnouncementUser(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTAnnouncementUser) User(ca.corefacility.bioinformatics.irida.model.user.User) Announcement(ca.corefacility.bioinformatics.irida.model.announcements.Announcement) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DTAnnouncementUser(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTAnnouncementUser) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 14 with DataTablesResponseModel

use of ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel 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)

Example 15 with DataTablesResponseModel

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

the class ClientsController method getAjaxClientsList.

/**
 * Get a {@link DataTablesResponse} for the Clients page.
 *
 * @param params
 * 		{@link DataTablesParams} for the current DataTable.
 *
 * @return {@link DataTablesResponse}
 */
@RequestMapping(value = "/ajax/list", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public DataTablesResponse getAjaxClientsList(@DataTablesRequest DataTablesParams params) {
    Specification<IridaClientDetails> specification = IridaClientDetailsSpecification.searchClient(params.getSearchValue());
    Page<IridaClientDetails> page = clientDetailsService.search(specification, new PageRequest(params.getCurrentPage(), params.getLength(), params.getSort()));
    List<DataTablesResponseModel> models = new ArrayList<>();
    for (IridaClientDetails client : page.getContent()) {
        models.add(new DTClient(client, clientDetailsService.countActiveTokensForClient(client)));
    }
    return new DataTablesResponse(params, page, models);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DTClient(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTClient) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) IridaClientDetails(ca.corefacility.bioinformatics.irida.model.IridaClientDetails) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

DataTablesResponse (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)15 DataTablesResponseModel (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel)15 PageRequest (org.springframework.data.domain.PageRequest)8 DataTablesParams (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams)6 Project (ca.corefacility.bioinformatics.irida.model.project.Project)5 User (ca.corefacility.bioinformatics.irida.model.user.User)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)3 DataTablesRequest (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest)3 UserService (ca.corefacility.bioinformatics.irida.service.user.UserService)3 Sort (org.springframework.data.domain.Sort)3 IridaClientDetails (ca.corefacility.bioinformatics.irida.model.IridaClientDetails)2 Announcement (ca.corefacility.bioinformatics.irida.model.announcements.Announcement)2 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 UserGroup (ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)2 UserGroupJoin (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin)2 UserGroupProjectJoin (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin)2 DTUser (ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUser)2 Principal (java.security.Principal)2