Search in sources :

Example 16 with DataTablesResponse

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

the class AnalysesListingService method getPagedSubmissions.

/**
 * Get a {@link DataTablesResponse} for {@link AnalysisSubmission}s based upon the {@link User}, and the {@link Project}
 *
 * @param params  {@link DataTablesParams}
 * @param locale  {@link Locale}
 * @param user    {@link User}
 * @param project {@link Project}
 * @return {@link DataTablesResponse}
 * @throws IridaWorkflowNotFoundException If the requested workflow doesn't exist
 * @throws ExecutionManagerException      If the submission cannot be read properly
 */
public DataTablesResponse getPagedSubmissions(DataTablesParams params, Locale locale, User user, Project project) throws IridaWorkflowNotFoundException, ExecutionManagerException {
    /*
		Check the DataTableParams to see if any search conditions are present
		 */
    Map<String, String> searchMap = params.getSearchMap();
    AnalysisState state = searchMap.containsKey("analysisState") ? AnalysisState.valueOf(searchMap.get("analysisState")) : null;
    String name = searchMap.getOrDefault("name", null);
    /*
		Workflow Ids are a special consideration.
		The actual ids need to be look up based on the name passed.
		 */
    Set<UUID> workflowIds = null;
    if (searchMap.containsKey("workflow")) {
        AnalysisType workflowType = AnalysisType.fromString(searchMap.get("workflow"));
        Set<IridaWorkflow> workflows = iridaWorkflowsService.getAllWorkflowsByType(workflowType);
        workflowIds = workflows.stream().map(IridaWorkflow::getWorkflowIdentifier).collect(Collectors.toSet());
    }
    Page<AnalysisSubmission> page;
    PageRequest pageRequest = new PageRequest(params.getCurrentPage(), params.getLength(), params.getSort());
    if (user != null) {
        // if user is set, get submissions for the user
        page = analysisSubmissionService.listSubmissionsForUser(params.getSearchValue(), name, state, user, workflowIds, pageRequest);
    } else if (project != null) {
        // if the project is set, get submissions for the project
        page = analysisSubmissionService.listSubmissionsForProject(params.getSearchValue(), name, state, workflowIds, project, pageRequest);
    } else {
        // if neither is set, get admin page
        page = analysisSubmissionService.listAllSubmissions(params.getSearchValue(), name, state, workflowIds, pageRequest);
    }
    /*
		IRIDA DataTables response expects and object that implements the DataTablesResponseModel interface.
		 */
    List<DataTablesResponseModel> data = new ArrayList<>();
    for (AnalysisSubmission submission : page.getContent()) {
        // Each AnalysisSubmission needs to be converted into a DTAnalysis.
        data.add(createDataTablesAnalysis(submission, locale));
    }
    return new DataTablesResponse(params, page, data);
}
Also used : AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) AnalysisState(ca.corefacility.bioinformatics.irida.model.enums.AnalysisState) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) PageRequest(org.springframework.data.domain.PageRequest) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)

Example 17 with DataTablesResponse

use of ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse 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 18 with DataTablesResponse

use of ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse 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 19 with DataTablesResponse

use of ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse 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 20 with DataTablesResponse

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

DataTablesResponse (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)22 DataTablesResponseModel (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel)16 DataTablesParams (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams)13 Sort (org.springframework.data.domain.Sort)11 Project (ca.corefacility.bioinformatics.irida.model.project.Project)8 Test (org.junit.Test)8 PageRequest (org.springframework.data.domain.PageRequest)8 User (ca.corefacility.bioinformatics.irida.model.user.User)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 DataTablesRequest (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)3 UserService (ca.corefacility.bioinformatics.irida.service.user.UserService)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Collectors (java.util.stream.Collectors)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Page (org.springframework.data.domain.Page)3 Controller (org.springframework.stereotype.Controller)3 Model (org.springframework.ui.Model)3