Search in sources :

Example 11 with MetadataTemplate

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();
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) MetadataTemplate(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate) UIMetadataTemplate(ca.corefacility.bioinformatics.irida.ria.web.models.UIMetadataTemplate) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) ServletOutputStream(javax.servlet.ServletOutputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell) MetadataTemplateField(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplateField) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with MetadataTemplate

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;
}
Also used : MetadataTemplate(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate) ArrayList(java.util.ArrayList) ProjectMetadataTemplateJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Aggregations

MetadataTemplate (ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate)12 Project (ca.corefacility.bioinformatics.irida.model.project.Project)9 ProjectMetadataTemplateJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin)8 MetadataTemplateField (ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplateField)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 UIMetadataTemplate (ca.corefacility.bioinformatics.irida.ria.web.models.UIMetadataTemplate)3 ArrayList (java.util.ArrayList)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)1 Map (java.util.Map)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 XSSFCell (org.apache.poi.xssf.usermodel.XSSFCell)1 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)1 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1