use of ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate in project irida by phac-nml.
the class ProjectSamplesMetadataTemplateController method downloadTemplate.
/**
* Download a {@link MetadataTemplate} as an Excel file.
*
* @param templateId
* {@link Long} identifier for a {@link MetadataTemplate}
* @param response
* {@link HttpServletResponse}
*
* @throws IOException
* thrown if output stream cannot be used.
*/
@RequestMapping(value = "/{templateId}/excel")
public void downloadTemplate(@PathVariable Long templateId, HttpServletResponse response) throws IOException {
MetadataTemplate template = metadataTemplateService.read(templateId);
List<MetadataTemplateField> fields = template.getFields();
List<String> headers = fields.stream().map(MetadataTemplateField::getLabel).collect(Collectors.toList());
String label = template.getLabel().replace(" ", "_");
// Blank workbook
XSSFWorkbook workbook = new XSSFWorkbook();
// Create a blank sheet
XSSFSheet worksheet = workbook.createSheet(label);
// Write the headers
XSSFRow headerRow = worksheet.createRow(0);
for (int i = 0; i < headers.size(); i++) {
XSSFCell cell = headerRow.createCell(i);
cell.setCellValue(headers.get(i));
}
response.setHeader("Content-Disposition", "attachment; filename=\"" + label + ".xlsx\"");
ServletOutputStream stream = response.getOutputStream();
workbook.write(stream);
stream.flush();
}
use of ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate in project irida by phac-nml.
the class ProjectControllerUtils method getTemplateNames.
/**
* Get a {@link List} of {@link MetadataTemplate}s available for the current {@link Project}
*
* @param locale
* {@link Locale} users current locale
* @param project
* {@link Project} the project to get {@link MetadataTemplate}s for
*
* @return {@link List} of {@link MetadataTemplate}
*/
public List<Map<String, String>> getTemplateNames(Locale locale, Project project) {
List<ProjectMetadataTemplateJoin> metadataTemplatesForProject = metadataTemplateService.getMetadataTemplatesForProject(project);
List<Map<String, String>> templates = new ArrayList<>();
for (ProjectMetadataTemplateJoin projectMetadataTemplateJoin : metadataTemplatesForProject) {
MetadataTemplate template = projectMetadataTemplateJoin.getObject();
templates.add(ImmutableMap.of("label", template.getLabel(), "id", String.valueOf(template.getId())));
}
return templates;
}
Aggregations