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());
}
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);
}
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);
}
Aggregations