Search in sources :

Example 1 with MetadataTemplate

use of ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate in project irida by phac-nml.

the class AnalysisController method getMetadataTemplateFields.

/**
 * Generates a list of metadata fields for a five template.
 *
 * @param templateId {@link Long} id for the {@link MetadataTemplate} that the fields are required.
 * @return {@link Map}
 */
@RequestMapping("/ajax/{submissionId}/metadata-template-fields")
@ResponseBody
public Map<String, Object> getMetadataTemplateFields(@RequestParam Long templateId) {
    MetadataTemplate template = metadataTemplateService.read(templateId);
    List<MetadataTemplateField> metadataFields = template.getFields();
    List<String> fields = new ArrayList<>();
    for (MetadataTemplateField metadataField : metadataFields) {
        fields.add(metadataField.getLabel());
    }
    return ImmutableMap.of("fields", fields);
}
Also used : MetadataTemplate(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate) MetadataTemplateField(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplateField)

Example 2 with MetadataTemplate

use of ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate in project irida by phac-nml.

the class AnalysisController method getMetadataTemplatesForAnalysis.

/**
 * Get a list of all {@link MetadataTemplate}s for the {@link AnalysisSubmission}
 *
 * @param submissionId id of the {@link AnalysisSubmission}
 * @return a map of {@link MetadataTemplate}s
 */
@RequestMapping("/ajax/{submissionId}/metadata-templates")
@ResponseBody
public Map<String, Object> getMetadataTemplatesForAnalysis(@PathVariable Long submissionId) {
    AnalysisSubmission submission = analysisSubmissionService.read(submissionId);
    List<Project> projectsUsedInAnalysisSubmission = projectService.getProjectsUsedInAnalysisSubmission(submission);
    Set<Long> projectIds = new HashSet<>();
    Set<Map<String, Object>> templates = new HashSet<>();
    for (Project project : projectsUsedInAnalysisSubmission) {
        if (!projectIds.contains(project.getId())) {
            projectIds.add(project.getId());
            // Get the templates for the project
            List<ProjectMetadataTemplateJoin> templateList = metadataTemplateService.getMetadataTemplatesForProject(project);
            for (ProjectMetadataTemplateJoin projectMetadataTemplateJoin : templateList) {
                MetadataTemplate metadataTemplate = projectMetadataTemplateJoin.getObject();
                Map<String, Object> templateMap = ImmutableMap.of("label", metadataTemplate.getLabel(), "id", metadataTemplate.getId());
                templates.add(templateMap);
            }
        }
    }
    return ImmutableMap.of("templates", templates);
}
Also used : MetadataTemplate(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) ProjectMetadataTemplateJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 3 with MetadataTemplate

use of ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate in project irida by phac-nml.

the class ProjectSettingsController method getSampleMetadataTemplatesPage.

/**
 * Request for a {@link Project} remote settings page
 *
 * @param projectId
 * 		the ID of the {@link Project} to read
 * @param model
 * 		Model for the view
 * @param principal
 * 		Logged in user
 *
 * @return name of the project remote settings page
 */
@RequestMapping("/metadata-templates")
public String getSampleMetadataTemplatesPage(@PathVariable Long projectId, final Model model, final Principal principal) {
    Project project = projectService.read(projectId);
    model.addAttribute("project", project);
    projectControllerUtils.getProjectTemplateDetails(model, principal, project);
    List<ProjectMetadataTemplateJoin> templateJoins = metadataTemplateService.getMetadataTemplatesForProject(project);
    List<MetadataTemplate> templates = new ArrayList<>();
    for (ProjectMetadataTemplateJoin join : templateJoins) {
        templates.add(join.getObject());
    }
    model.addAttribute("templates", templates);
    model.addAttribute(ProjectsController.ACTIVE_NAV, ACTIVE_NAV_SETTINGS);
    model.addAttribute("page", "metadata_templates");
    return "projects/settings/pages/metadata_templates";
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) MetadataTemplate(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate) ArrayList(java.util.ArrayList) ProjectMetadataTemplateJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with MetadataTemplate

use of ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate in project irida by phac-nml.

the class ProjectLineListController method saveMetadataTemplate.

/**
 * Save a list a {@link MetadataTemplateField} as a {@link MetadataTemplate}
 *
 * @param projectId  identifier for the current {@link Project}
 * @param fields     {@link List} of {@link String} names of {@link MetadataTemplateField}
 * @param name       {@link String} name for the new template.
 * @param templateId ID of the template to update.  Will create new template if null
 * @param locale     Locale of teh logged in user
 * @return the saved {@link MetadataTemplate} and a response message
 */
@RequestMapping(value = "/templates", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> saveMetadataTemplate(@PathVariable long projectId, @RequestParam String name, @RequestParam(value = "fields[]") List<String> fields, @RequestParam(required = false) Long templateId, Locale locale) {
    Project project = projectService.read(projectId);
    List<MetadataTemplateField> metadataFields = new ArrayList<>();
    for (String label : fields) {
        // Check to see if this field already exists.
        MetadataTemplateField metadataField = metadataTemplateService.readMetadataFieldByLabel(label);
        // If it does not exist, create a new field.
        if (metadataField == null) {
            metadataField = new MetadataTemplateField(label, "text");
            metadataTemplateService.saveMetadataField(metadataField);
        }
        metadataFields.add(metadataField);
    }
    MetadataTemplate template;
    String message;
    // If the template already has an ID, it is an existing template, so just update it.
    if (templateId != null) {
        template = metadataTemplateService.read(templateId);
        template.setFields(metadataFields);
        template.setName(name);
        metadataTemplateService.updateMetadataTemplateInProject(template);
        message = messageSource.getMessage("linelist.create-template.update-success", new Object[] { name }, locale);
    } else {
        template = new MetadataTemplate(name, metadataFields);
        ProjectMetadataTemplateJoin join = metadataTemplateService.createMetadataTemplateInProject(template, project);
        template = join.getObject();
        message = messageSource.getMessage("linelist.create-template.success", new Object[] { name }, locale);
    }
    return ImmutableMap.of("template", template, "message", message);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) MetadataTemplate(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate) ProjectMetadataTemplateJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin) MetadataTemplateField(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplateField)

Example 5 with MetadataTemplate

use of ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate in project irida by phac-nml.

the class ProjectLineListController method getAllProjectMetadataFields.

/**
 * Get the template the the line list table.  This becomes the table headers.
 *
 * @param projectId
 * 		{@link Long} identifier of the current {@link Project}
 *
 * @return {@link Set} containing unique metadata fields
 */
private List<String> getAllProjectMetadataFields(Long projectId, Locale locale) {
    Project project = projectService.read(projectId);
    Set<String> fields = new HashSet<>();
    List<MetadataTemplateField> metadataFieldsForProject = metadataTemplateService.getMetadataFieldsForProject(project);
    fields.addAll(metadataFieldsForProject.stream().map(MetadataTemplateField::getLabel).collect(Collectors.toSet()));
    // Get all the fields from the templates.
    List<ProjectMetadataTemplateJoin> metadataTemplateJoins = metadataTemplateService.getMetadataTemplatesForProject(project);
    for (ProjectMetadataTemplateJoin join : metadataTemplateJoins) {
        MetadataTemplate template = join.getObject();
        fields.addAll(template.getFields().stream().map(MetadataTemplateField::getLabel).collect(Collectors.toSet()));
    }
    return new ArrayList<>(fields);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) MetadataTemplate(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate) ProjectMetadataTemplateJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin) MetadataTemplateField(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplateField)

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