use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin 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);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin 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";
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin 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);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin 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);
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin 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();
}
Aggregations