Search in sources :

Example 1 with DataTablesParams

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

the class ProjectExportController method getExportsForProject.

/**
 * Ajax method for getting the {@link NcbiExportSubmission}s for a given
 * {@link Project}
 *
 * @param projectId {@link Project} id
 * @param params    Parameters from the datatables request
 * @return DatatablesResponse of Map of submission params
 */
@RequestMapping("/ajax/projects/{projectId}/export/list")
@ResponseBody
public DataTablesResponse getExportsForProject(@DataTablesRequest DataTablesParams params, @PathVariable Long projectId) {
    Project project = projectService.read(projectId);
    List<NcbiExportSubmission> submissions = exportSubmissionService.getSubmissionsForProject(project);
    List<DataTablesResponseModel> dtExportSubmissions = submissions.stream().map(s -> new DTExportSubmission(s)).collect(Collectors.toList());
    return new DataTablesResponse(params, submissions.size(), dtExportSubmissions);
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Builder(ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles.Builder) java.util(java.util) DTExportSubmission(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTExportSubmission) NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) ProjectService(ca.corefacility.bioinformatics.irida.service.ProjectService) Value(org.springframework.beans.factory.annotation.Value) Model(org.springframework.ui.Model) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) Sort(org.springframework.data.domain.Sort) NcbiExportSubmissionService(ca.corefacility.bioinformatics.irida.service.export.NcbiExportSubmissionService) SequencingObjectService(ca.corefacility.bioinformatics.irida.service.SequencingObjectService) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) DataTablesRequest(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) ca.corefacility.bioinformatics.irida.model.export(ca.corefacility.bioinformatics.irida.model.export) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Principal(java.security.Principal) 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) SampleService(ca.corefacility.bioinformatics.irida.service.sample.SampleService) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) Project(ca.corefacility.bioinformatics.irida.model.project.Project) NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) DTExportSubmission(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTExportSubmission) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)

Example 2 with DataTablesParams

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

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

the class ProjectsControllerTest method testGetAjaxProjectList.

@Test
public void testGetAjaxProjectList() {
    when(userService.getUserByUsername(USER_NAME)).thenReturn(user);
    Page<Project> page = getProjectUserJoinPage(user);
    when(projectService.findProjectsForUser(any(String.class), any(Integer.class), any(Integer.class), any(Sort.class))).thenReturn(page);
    when(sampleService.getSamplesForProject(any(Project.class))).thenReturn(TestDataFactory.constructListJoinProjectSample());
    DataTablesParams params = new DataTablesParams(0, 10, 1, "", new Sort(Sort.Direction.ASC, "modifiedDate"), new HashMap<>());
    DataTablesResponse response = controller.getAjaxProjectList(params);
    assertEquals("Should have 10 data elements, since page size is 10", 10, response.getData().size());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sort(org.springframework.data.domain.Sort) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) Matchers.anyString(org.mockito.Matchers.anyString) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) Test(org.junit.Test)

Example 4 with DataTablesParams

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

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

the class AnalysesListingServiceTest method testGetPagedSubmissionsForUser.

@Test
public void testGetPagedSubmissionsForUser() throws IridaWorkflowNotFoundException, ExecutionManagerException {
    String searchValue = "";
    User user = new User();
    DataTablesParams params = new DataTablesParams(1, 10, 1, searchValue, new Sort(Sort.Direction.ASC, "id"), ImmutableMap.of());
    when(analysisSubmissionService.listSubmissionsForUser(eq(searchValue), any(String.class), eq(null), eq(user), Matchers.any(), Matchers.any())).thenReturn(AnalysesDataFactory.getPagedAnalysisSubmissions());
    DataTablesResponse response = analysesListingService.getPagedSubmissions(params, Locale.US, user, null);
    assertEquals("DataTables response should have a draw value of 1", 1, response.getDraw());
    assertEquals("DataTables response should have a records filtered value of 150", 150, response.getRecordsFiltered());
    assertEquals("DataTables response should have a records total value of 150", 150, response.getRecordsTotal());
    assertTrue("Should have data value", response.getData() != null);
    verify(analysisSubmissionService).listSubmissionsForUser(eq(searchValue), any(String.class), eq(null), eq(user), Matchers.any(), Matchers.any());
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) Sort(org.springframework.data.domain.Sort) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) Test(org.junit.Test)

Aggregations

DataTablesParams (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams)13 DataTablesResponse (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)13 Sort (org.springframework.data.domain.Sort)10 Test (org.junit.Test)8 DataTablesResponseModel (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel)7 Project (ca.corefacility.bioinformatics.irida.model.project.Project)5 User (ca.corefacility.bioinformatics.irida.model.user.User)5 DataTablesRequest (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest)4 Collectors (java.util.stream.Collectors)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Page (org.springframework.data.domain.Page)4 PageRequest (org.springframework.data.domain.PageRequest)4 UserService (ca.corefacility.bioinformatics.irida.service.user.UserService)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Principal (java.security.Principal)3 java.util (java.util)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Controller (org.springframework.stereotype.Controller)3 Model (org.springframework.ui.Model)3