Search in sources :

Example 6 with DataTablesResponseModel

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

the class SearchController method searchSamples.

/**
 * Search all {@link Sample}s in projects for a user based on a query string
 *
 * @param query  the query string
 * @param global Whether to perform an admin
 *               global search
 * @param params parameters for a datatables response
 * @return a {@link DataTablesResponse} to display search results
 */
@RequestMapping("/search/ajax/samples")
@ResponseBody
public DataTablesResponse searchSamples(@RequestParam String query, @RequestParam(required = false, defaultValue = "false") boolean global, @DataTablesRequest DataTablesParams params) {
    Sort originalSort = params.getSort();
    List<Sort.Order> orders = Lists.newArrayList();
    originalSort.forEach(o -> {
        orders.add(new Sort.Order(o.getDirection(), "sample." + o.getProperty()));
    });
    Sort newSort = new Sort(orders);
    Page<ProjectSampleJoin> samplePage;
    if (global) {
        samplePage = sampleService.searchAllSamples(query, params.getCurrentPage(), params.getLength(), newSort);
    } else {
        samplePage = sampleService.searchSamplesForUser(query, params.getCurrentPage(), params.getLength(), newSort);
    }
    List<DataTablesResponseModel> samples = samplePage.getContent().stream().map(this::createDataTablesSample).collect(Collectors.toList());
    return new DataTablesResponse(params, samplePage, samples);
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) Sort(org.springframework.data.domain.Sort) 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 7 with DataTablesResponseModel

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

the class ProjectSamplesControllerTest method testGetAjaxProjectSampleModels.

@SuppressWarnings("unchecked")
@Test
public void testGetAjaxProjectSampleModels() {
    Sample sample = TestDataFactory.constructSample();
    when(projectService.read(anyLong())).thenReturn(project);
    when(sampleService.getSamplesForProject(any(Project.class))).thenReturn(ImmutableList.of(new ProjectSampleJoin(project, sample, true)));
    when(sampleService.getFilteredSamplesForProjects(any(List.class), any(List.class), any(String.class), any(String.class), any(String.class), any(Date.class), any(Date.class), any(Integer.class), any(Integer.class), any(Sort.class))).thenReturn(TestDataFactory.getPageOfProjectSampleJoin());
    DataTablesParams params = mock(DataTablesParams.class);
    when(params.getSort()).thenReturn(new Sort(Direction.ASC, "sample.sampleName"));
    DataTablesResponse response = controller.getProjectSamples(1L, params, ImmutableList.of(), ImmutableList.of(), new UISampleFilter(), Locale.US);
    List<DataTablesResponseModel> data = response.getData();
    assertEquals("Has the correct number of samples", 1, data.size());
    DTProjectSamples sampleData = (DTProjectSamples) data.get(0);
    assertEquals("Has the correct sample", "Joined Sample", sampleData.getSampleName());
}
Also used : DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) UISampleFilter(ca.corefacility.bioinformatics.irida.ria.web.models.UISampleFilter) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) DTProjectSamples(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTProjectSamples) Sort(org.springframework.data.domain.Sort) ImmutableList(com.google.common.collect.ImmutableList) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) Test(org.junit.Test)

Example 8 with DataTablesResponseModel

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

Example 9 with DataTablesResponseModel

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

the class ClientsControllerTest method testGetAjaxClientList.

@SuppressWarnings("unchecked")
@Test
public void testGetAjaxClientList() {
    IridaClientDetails client1 = new IridaClientDetails();
    client1.setId(1L);
    IridaClientDetails client2 = new IridaClientDetails();
    client2.setId(2L);
    Page<IridaClientDetails> clientPage = new PageImpl<>(Lists.newArrayList(client1, client2));
    when(clientDetailsService.search(any(Specification.class), any(PageRequest.class))).thenReturn(clientPage);
    DataTablesParams params = new DataTablesParams(1, 10, 1, "", new Sort(Sort.Direction.ASC, "createdDate"), new HashMap<>());
    DataTablesResponse response = controller.getAjaxClientsList(params);
    List<DataTablesResponseModel> models = response.getData();
    assertEquals(2, models.size());
    verify(clientDetailsService).search(any(Specification.class), any(PageRequest.class));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) PageRequest(org.springframework.data.domain.PageRequest) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) Sort(org.springframework.data.domain.Sort) Specification(org.springframework.data.jpa.domain.Specification) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) IridaClientDetails(ca.corefacility.bioinformatics.irida.model.IridaClientDetails) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) Test(org.junit.Test)

Example 10 with DataTablesResponseModel

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

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