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