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";
}
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();
}
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";
}
Aggregations