Search in sources :

Example 1 with UIMetadataTemplate

use of ca.corefacility.bioinformatics.irida.ria.web.models.UIMetadataTemplate in project irida by phac-nml.

the class ProjectSamplesMetadataTemplateController method getMetadataTemplateListPage.

/**
 * Get the page to create a new {@link MetadataTemplate}
 *
 * @param projectId
 * 		{@link Long} identifier for a {@link Project}
 * @param model
 * 		{@link Model} spring page model
 * @param principal
 * 		{@link Principal} currently logged in user
 *
 * @return {@link String} path to the new template page
 */
@RequestMapping("/new")
public String getMetadataTemplateListPage(@PathVariable Long projectId, Model model, Principal principal) {
    Project project = projectService.read(projectId);
    // Add an empty MetadataTemplate. This facilitates code reuse for this page
    // since it is used for both creation and updating a template, and the html
    // is looking for a template object.
    model.addAttribute("template", new UIMetadataTemplate());
    projectControllerUtils.getProjectTemplateDetails(model, principal, project);
    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) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with UIMetadataTemplate

use of ca.corefacility.bioinformatics.irida.ria.web.models.UIMetadataTemplate 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 3 with UIMetadataTemplate

use of ca.corefacility.bioinformatics.irida.ria.web.models.UIMetadataTemplate 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

Project (ca.corefacility.bioinformatics.irida.model.project.Project)3 UIMetadataTemplate (ca.corefacility.bioinformatics.irida.ria.web.models.UIMetadataTemplate)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 MetadataTemplate (ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate)2 ProjectMetadataTemplateJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin)1 MetadataTemplateField (ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplateField)1 ArrayList (java.util.ArrayList)1