Search in sources :

Example 1 with DTProjectSamples

use of ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTProjectSamples 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 2 with DTProjectSamples

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

the class ProjectSamplesController method exportProjectSamplesTable.

/**
 * Export {@link Sample} from a {@link Project} as either Excel or CSV formatted.
 *
 * @param projectId   identifier for the current {@link Project}
 * @param type        of file to export (.csv or .xlsx)
 * @param params      DataTable parameters.
 * @param sampleNames List of {@link Sample} names the {@link Project} is filtered on
 * @param associated  List of acitve associated {@link Project} identifiers.
 * @param filter      {@link Sample} attribute filters applied.
 * @param request     {@link HttpServletRequest}
 * @param response    {@link HttpServletResponse}
 * @param locale      of the current user.
 * @throws IOException if the exported file cannot be written
 */
@RequestMapping(value = "/projects/{projectId}/samples/export")
public void exportProjectSamplesTable(@PathVariable Long projectId, @RequestParam DataTablesExportTypes type, @DataTablesRequest DataTablesParams params, @RequestParam(required = false, defaultValue = "") List<String> sampleNames, @RequestParam(required = false, defaultValue = "") List<Long> associated, UISampleFilter filter, HttpServletRequest request, HttpServletResponse response, Locale locale) throws IOException {
    Project project = projectService.read(projectId);
    List<Project> projects = new ArrayList<>();
    if (!associated.isEmpty()) {
        projects = (List<Project>) projectService.readMultiple(associated);
    }
    projects.add(project);
    final Page<ProjectSampleJoin> page = sampleService.getFilteredSamplesForProjects(projects, sampleNames, filter.getName(), params.getSearchValue(), filter.getOrganism(), filter.getStartDate(), filter.getEndDate(), 0, Integer.MAX_VALUE, params.getSort());
    // Create DataTables representation of the page.
    List<DTProjectSamples> models = new ArrayList<>();
    for (ProjectSampleJoin psj : page.getContent()) {
        models.add(buildProjectSampleDataTablesModel(psj, locale));
    }
    List<String> headers = models.get(0).getExportableTableHeaders(messageSource, locale);
    DataTablesExportToFile.writeFile(type, response, project.getLabel().replace(" ", "_"), models, headers);
}
Also used : 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)

Example 3 with DTProjectSamples

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

the class ProjectSamplesController method buildProjectSampleDataTablesModel.

/**
 * Build a {@link ProjectSampleModel} object for a given {@link Sample}
 *
 * @param sso    a {@link ProjectSampleJoin} to build the {@link ProjectSampleModel} from
 * @param locale of the current user.
 * @return a newly constructed {@link ProjectSampleModel}
 */
private DTProjectSamples buildProjectSampleDataTablesModel(ProjectSampleJoin sso, Locale locale) {
    Project p = sso.getSubject();
    List<QCEntry> qcEntriesForSample = sampleService.getQCEntriesForSample(sso.getObject());
    List<String> list = new ArrayList<>();
    for (QCEntry q : qcEntriesForSample) {
        q.addProjectSettings(p);
        String status = q.getStatus().toString();
        if (q.getStatus() == QCEntry.QCEntryStatus.NEGATIVE) {
            list.add(messageSource.getMessage("sample.files.qc." + q.getType(), new Object[] { q.getMessage() }, locale));
        }
    }
    return new DTProjectSamples(sso, list);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) DTProjectSamples(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTProjectSamples) QCEntry(ca.corefacility.bioinformatics.irida.model.sample.QCEntry)

Aggregations

Project (ca.corefacility.bioinformatics.irida.model.project.Project)3 DTProjectSamples (ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTProjectSamples)3 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)2 QCEntry (ca.corefacility.bioinformatics.irida.model.sample.QCEntry)1 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)1 DataTablesParams (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams)1 DataTablesResponse (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)1 DataTablesResponseModel (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel)1 UISampleFilter (ca.corefacility.bioinformatics.irida.ria.web.models.UISampleFilter)1 ImmutableList (com.google.common.collect.ImmutableList)1 Test (org.junit.Test)1 Sort (org.springframework.data.domain.Sort)1