use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin in project irida by phac-nml.
the class MetadataTemplateServiceImpl method createMetadataTemplateInProject.
/**
* {@inheritDoc}
*/
@Override
@PreAuthorize("hasPermission(#project, 'isProjectOwner')")
@Transactional
public ProjectMetadataTemplateJoin createMetadataTemplateInProject(MetadataTemplate template, Project project) {
template = create(template);
ProjectMetadataTemplateJoin join = pmtRepository.save(new ProjectMetadataTemplateJoin(project, template));
return join;
}
use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin 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.joins.impl.ProjectMetadataTemplateJoin 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.joins.impl.ProjectMetadataTemplateJoin in project irida by phac-nml.
the class ProjectControllerUtils method getTemplateNames.
/**
* Get a {@link List} of {@link MetadataTemplate}s available for the current {@link Project}
*
* @param locale
* {@link Locale} users current locale
* @param project
* {@link Project} the project to get {@link MetadataTemplate}s for
*
* @return {@link List} of {@link MetadataTemplate}
*/
public List<Map<String, String>> getTemplateNames(Locale locale, Project project) {
List<ProjectMetadataTemplateJoin> metadataTemplatesForProject = metadataTemplateService.getMetadataTemplatesForProject(project);
List<Map<String, String>> templates = new ArrayList<>();
for (ProjectMetadataTemplateJoin projectMetadataTemplateJoin : metadataTemplatesForProject) {
MetadataTemplate template = projectMetadataTemplateJoin.getObject();
templates.add(ImmutableMap.of("label", template.getLabel(), "id", String.valueOf(template.getId())));
}
return templates;
}
Aggregations