Search in sources :

Example 6 with MetadataTemplate

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

the class ProjectSamplesMetadataTemplateController method saveMetadataTemplate.

/**
 * Save or update a {@link MetadataTemplate} within a {@link Project}
 *
 * @param projectId
 * 		{@link Long} identifier for a {@link Project}
 * @param template
 * 		A {@link UIMetadataTemplate} to save to a {@link Project}
 *
 * @return {@link String} redirects to the template page.
 */
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String saveMetadataTemplate(@PathVariable Long projectId, UIMetadataTemplate template) {
    Project project = projectService.read(projectId);
    List<MetadataTemplateField> metadataFields = new ArrayList<>();
    for (String field : template.getFields()) {
        MetadataTemplateField metadataTemplateField = metadataTemplateService.readMetadataFieldByLabel(field);
        if (metadataTemplateField == null) {
            metadataTemplateField = new MetadataTemplateField(field, "text");
            metadataTemplateService.saveMetadataField(metadataTemplateField);
        }
        metadataFields.add(metadataTemplateField);
    }
    MetadataTemplate metadataTemplate;
    if (template.getId() != null) {
        metadataTemplate = metadataTemplateService.read(template.getId());
        metadataTemplate.setName(template.getName());
        metadataTemplate.setFields(metadataFields);
        metadataTemplateService.updateMetadataTemplateInProject(metadataTemplate);
    } else {
        ProjectMetadataTemplateJoin projectMetadataTemplateJoin = metadataTemplateService.createMetadataTemplateInProject(new MetadataTemplate(template.getName(), metadataFields), project);
        metadataTemplate = projectMetadataTemplateJoin.getObject();
    }
    return "redirect:/projects/" + projectId + "/metadata-templates/" + metadataTemplate.getId();
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) MetadataTemplate(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate) UIMetadataTemplate(ca.corefacility.bioinformatics.irida.ria.web.models.UIMetadataTemplate) ArrayList(java.util.ArrayList) ProjectMetadataTemplateJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin) MetadataTemplateField(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplateField) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with MetadataTemplate

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

the class ProjectLineListController method getMetadataTemplates.

/**
 * Get a {@link List} of {@link MetadataTemplate}s for a specific {@link Project}
 *
 * @param projectId
 * 		{@link Long} identifier for a {@link Project}
 * @param locale
 * 		users current {@link Locale}
 *
 * @return {@link List} of {@link MetadataTemplate}
 */
@RequestMapping(value = "/templates", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<MetadataTemplate> getMetadataTemplates(@PathVariable long projectId, Locale locale) {
    Project project = projectService.read(projectId);
    List<ProjectMetadataTemplateJoin> joins = metadataTemplateService.getMetadataTemplatesForProject(project);
    List<MetadataTemplate> templates = new ArrayList<>();
    for (ProjectMetadataTemplateJoin join : joins) {
        templates.add(join.getObject());
    }
    return templates;
}
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)

Example 8 with MetadataTemplate

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

the class ProjectLineListController method saveLinelistTemplate.

/**
 * Save a new line list template.
 *
 * @param projectId    {@link Long} id for the current project
 * @param templateName {@link String} name for the new template
 * @param fields       The fields to save to the template
 * @return The result of saving.
 */
@RequestMapping(value = "/linelist-templates/save-template/{templateName}", consumes = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> saveLinelistTemplate(@PathVariable Long projectId, @PathVariable String templateName, @RequestBody List<Map<String, String>> fields) {
    Project project = projectService.read(projectId);
    List<MetadataTemplateField> metadataFields = new ArrayList<>();
    for (Map<String, String> field : fields) {
        String label = field.get("label");
        // Label and identifier are default that are always in the list.
        MetadataTemplateField metadataField;
        if (field.containsKey("identifier")) {
            // Identifier would indicate an existing field.  Therefore we should use the existing field
            // instead of creating a new one.
            metadataField = metadataTemplateService.readMetadataField(Long.parseLong(field.get("identifier")));
        } else {
            // Check to see if the field already exists
            metadataField = metadataTemplateService.readMetadataFieldByLabel(label);
            if (metadataField == null) {
                metadataField = new MetadataTemplateField(label, field.get("type"));
                metadataTemplateService.saveMetadataField(metadataField);
            }
        }
        metadataFields.add(metadataField);
    }
    MetadataTemplate metadataTemplate = new MetadataTemplate(templateName, metadataFields);
    ProjectMetadataTemplateJoin projectMetadataTemplateJoin = metadataTemplateService.createMetadataTemplateInProject(metadataTemplate, project);
    return ImmutableMap.of("templateId", projectMetadataTemplateJoin.getObject().getId());
}
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 9 with MetadataTemplate

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

the class ProjectLineListController method deleteMetadataTemplate.

/**
 * Ajax request handler for deleting a specific {@link MetadataTemplate}
 *
 * @param projectId  {@link Long} identifier for a {@link Project}
 * @param templateId {@link Long} identifier for a {@link MetadataTemplate}
 * @param locale     {@link Locale}
 * @return {@link Map} of success message.
 */
@RequestMapping(value = "/templates/{templateId}", method = RequestMethod.DELETE)
@ResponseBody
public Map<String, String> deleteMetadataTemplate(@PathVariable Long projectId, @PathVariable Long templateId, Locale locale) {
    Project project = projectService.read(projectId);
    MetadataTemplate template = metadataTemplateService.read(templateId);
    metadataTemplateService.deleteMetadataTemplateFromProject(project, templateId);
    return ImmutableMap.of("message", messageSource.getMessage("linelist.create-template.delete-success", new Object[] { template.getLabel(), project.getLabel() }, locale));
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) MetadataTemplate(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate)

Example 10 with MetadataTemplate

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

the class ProjectSamplesMetadataTemplateController method getMetadataTemplatePage.

/**
 * Get a the page for a specific {@link MetadataTemplate}
 *
 * @param projectId
 * 		{@link Long} identifier for a {@link Project}
 * @param templateId
 * 		{@link Long} identifier for a {@link MetadataTemplate}
 * @param principal
 * 		{@link Principal} currently logged in user
 * @param model
 * 		{@link Model} spring page model
 *
 * @return {@link String} path to template page
 */
@RequestMapping("/{templateId}")
public String getMetadataTemplatePage(@PathVariable Long projectId, @PathVariable Long templateId, Principal principal, Model model) {
    Project project = projectService.read(projectId);
    projectControllerUtils.getProjectTemplateDetails(model, principal, project);
    MetadataTemplate metadataTemplate = metadataTemplateService.read(templateId);
    UIMetadataTemplate template = new UIMetadataTemplate(metadataTemplate);
    model.addAttribute("template", template);
    return "projects/project_samples_metadata_template";
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) UIMetadataTemplate(ca.corefacility.bioinformatics.irida.ria.web.models.UIMetadataTemplate) MetadataTemplate(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate) UIMetadataTemplate(ca.corefacility.bioinformatics.irida.ria.web.models.UIMetadataTemplate) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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