Search in sources :

Example 6 with ProjectMetadataTemplateJoin

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;
}
Also used : ProjectMetadataTemplateJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(javax.transaction.Transactional)

Example 7 with ProjectMetadataTemplateJoin

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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) MetadataTemplate(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate) ProjectMetadataTemplateJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin)

Example 8 with ProjectMetadataTemplateJoin

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());
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) MetadataTemplate(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate) ProjectMetadataTemplateJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin) MetadataTemplateField(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplateField)

Example 9 with ProjectMetadataTemplateJoin

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;
}
Also used : MetadataTemplate(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate) ArrayList(java.util.ArrayList) ProjectMetadataTemplateJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Aggregations

ProjectMetadataTemplateJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin)9 MetadataTemplate (ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate)8 Project (ca.corefacility.bioinformatics.irida.model.project.Project)7 MetadataTemplateField (ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplateField)4 ArrayList (java.util.ArrayList)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)1 UIMetadataTemplate (ca.corefacility.bioinformatics.irida.ria.web.models.UIMetadataTemplate)1 Map (java.util.Map)1 Transactional (javax.transaction.Transactional)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1