Search in sources :

Example 31 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.

the class ProjectsController method syncProject.

/**
 * Get a {@link Project} from a remote api and mark it to be synchronized in
 * this IRIDA installation
 *
 * @param url           the URL of the remote project
 * @param syncFrequency How often to sync the project
 * @param model         Model for the view
 * @return Redirect to the new project. If an oauth exception occurs it will
 * be forwarded back to the creation page.
 */
@RequestMapping(value = "/projects/synchronize", method = RequestMethod.POST)
public String syncProject(@RequestParam String url, @RequestParam ProjectSyncFrequency syncFrequency, Model model) {
    try {
        Project read = projectRemoteService.read(url);
        read.setId(null);
        read.getRemoteStatus().setSyncStatus(SyncStatus.MARKED);
        read.setSyncFrequency(syncFrequency);
        read = projectService.create(read);
        return "redirect:/projects/" + read.getId() + "/metadata";
    } catch (IridaOAuthException ex) {
        Map<String, String> errors = new HashMap<>();
        errors.put("oauthError", ex.getMessage());
        model.addAttribute("errors", errors);
        return getSynchronizeProjectPage(model);
    } catch (EntityNotFoundException ex) {
        Map<String, String> errors = new HashMap<>();
        errors.put("urlError", ex.getMessage());
        model.addAttribute("errors", errors);
        return getSynchronizeProjectPage(model);
    }
}
Also used : IridaOAuthException(ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException) DTProject(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTProject) Project(ca.corefacility.bioinformatics.irida.model.project.Project) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) ImmutableMap(com.google.common.collect.ImmutableMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 32 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.

the class ProjectsController method getProjectAnalysisList.

/**
 * Get the page for analyses shared with a given {@link Project}
 *
 * @param projectId
 *            the ID of the {@link Project}
 * @param principal
 *            the logged in user
 * @param model
 *            model for view variables
 * @return name of the analysis view page
 */
@RequestMapping("/projects/{projectId}/analyses")
public String getProjectAnalysisList(@PathVariable Long projectId, Principal principal, Model model) {
    Project project = projectService.read(projectId);
    model.addAttribute("project", project);
    projectControllerUtils.getProjectTemplateDetails(model, principal, project);
    model.addAttribute("ajaxURL", "/analysis/ajax/project/" + projectId + "/list");
    model.addAttribute("states", AnalysisState.values());
    model.addAttribute("analysisTypes", workflowsService.getRegisteredWorkflowTypes());
    model.addAttribute(ACTIVE_NAV, ACTIVE_NAV_ANALYSES);
    return PROJECT_ANALYSES_PAGE;
}
Also used : DTProject(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTProject) Project(ca.corefacility.bioinformatics.irida.model.project.Project) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project 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);
}
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 34 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project 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);
}
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 35 with Project

use of ca.corefacility.bioinformatics.irida.model.project.Project in project irida by phac-nml.

the class ProjectSampleMetadataController method saveProjectSampleMetadata.

/**
 * Save uploaded metadata to the
 *
 * @param locale
 * 		{@link Locale} of the current user.
 * @param session
 * 		{@link HttpSession}
 * @param projectId
 * 		{@link Long} identifier for the current project
 *
 * @return {@link Map} of potential errors.
 */
@RequestMapping(value = "/upload/save", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> saveProjectSampleMetadata(Locale locale, HttpSession session, @PathVariable long projectId) {
    Map<String, Object> errors = new HashMap<>();
    Project project = projectService.read(projectId);
    SampleMetadataStorage stored = (SampleMetadataStorage) session.getAttribute("pm-" + projectId);
    if (stored == null) {
        errors.put("stored-error", true);
    }
    List<Sample> samplesToUpdate = new ArrayList<>();
    List<Map<String, String>> found = stored.getFound();
    if (found != null) {
        // Lets try to get a sample
        String sampleNameColumn = stored.getSampleNameColumn();
        List<String> errorList = new ArrayList<>();
        try {
            for (Map<String, String> row : found) {
                String name = row.get(sampleNameColumn);
                Sample sample = sampleService.getSampleBySampleName(project, name);
                row.remove(sampleNameColumn);
                Map<MetadataTemplateField, MetadataEntry> newData = new HashMap<>();
                // Need to overwrite duplicate keys
                for (Entry<String, String> entry : row.entrySet()) {
                    MetadataTemplateField key = metadataTemplateService.readMetadataFieldByLabel(entry.getKey());
                    if (key == null) {
                        key = metadataTemplateService.saveMetadataField(new MetadataTemplateField(entry.getKey(), "text"));
                    }
                    newData.put(key, new MetadataEntry(entry.getValue(), "text"));
                }
                sample.mergeMetadata(newData);
                // Save metadata back to the sample
                samplesToUpdate.add(sample);
            }
            sampleService.updateMultiple(samplesToUpdate);
        } catch (EntityNotFoundException e) {
            // This really should not happen, but hey, you never know!
            errorList.add(messageSource.getMessage("metadata.results.save.sample-not-found", new Object[] { e.getMessage() }, locale));
        }
        if (errorList.size() > 0) {
            errors.put("save-errors", errorList);
        }
    } else {
        errors.put("found-error", messageSource.getMessage("metadata.results.save.found-error", new Object[] {}, locale));
    }
    if (errors.size() == 0) {
        return ImmutableMap.of("success", messageSource.getMessage("metadata.results.save.success", new Object[] { found.size() }, locale));
    }
    return errors;
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) Project(ca.corefacility.bioinformatics.irida.model.project.Project) SampleMetadataStorage(ca.corefacility.bioinformatics.irida.ria.utilities.SampleMetadataStorage) MetadataEntry(ca.corefacility.bioinformatics.irida.model.sample.metadata.MetadataEntry) MetadataTemplateField(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplateField) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Project (ca.corefacility.bioinformatics.irida.model.project.Project)331 Test (org.junit.Test)190 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)120 User (ca.corefacility.bioinformatics.irida.model.user.User)88 WithMockUser (org.springframework.security.test.context.support.WithMockUser)80 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)71 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)62 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)51 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)37 ArrayList (java.util.ArrayList)34 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)30 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)30 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)27 ProjectRole (ca.corefacility.bioinformatics.irida.model.enums.ProjectRole)25 ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)23 ProjectEvent (ca.corefacility.bioinformatics.irida.model.event.ProjectEvent)22 ProjectAnalysisSubmissionJoin (ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)22 List (java.util.List)22 UserRoleSetProjectEvent (ca.corefacility.bioinformatics.irida.model.event.UserRoleSetProjectEvent)21 ImmutableMap (com.google.common.collect.ImmutableMap)21