Search in sources :

Example 56 with ProjectSampleJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.

the class ProjectSamplesController method getProjectSamples.

/**
 * Generate the {@link Sample}s for the {@link Project} table based on the filter criteria.
 *
 * @param projectId   identifier for the current {@link Project}
 * @param params      for the current DataTable.
 * @param sampleNames List of {@link Sample} names to filter by.
 * @param associated  List of associated {@link Project} identifiers currently displayed in the table.
 * @param filter      for specific {@link Sample} attributes.
 * @param locale      for the current user.
 * @return {@link DTProjectSamples} that meet the requirements
 */
@RequestMapping(value = "/projects/{projectId}/ajax/samples", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
@ResponseBody
public DataTablesResponse getProjectSamples(@PathVariable Long projectId, @DataTablesRequest DataTablesParams params, @RequestParam(required = false, name = "sampleNames[]", defaultValue = "") List<String> sampleNames, @RequestParam(required = false, name = "associated[]", defaultValue = "") List<Long> associated, UISampleFilter filter, Locale locale) {
    List<Project> projects = new ArrayList<>();
    // Check to see if any associated projects need to be added to the query.
    if (!associated.isEmpty()) {
        projects = (List<Project>) projectService.readMultiple(associated);
    }
    // This project is always in the query.
    projects.add(projectService.read(projectId));
    final Page<ProjectSampleJoin> page = sampleService.getFilteredSamplesForProjects(projects, sampleNames, filter.getName(), params.getSearchValue(), filter.getOrganism(), filter.getStartDate(), filter.getEndDate(), params.getCurrentPage(), params.getLength(), params.getSort());
    // Create DataTables representation of the page.
    List<DataTablesResponseModel> models = new ArrayList<>();
    for (ProjectSampleJoin psj : page.getContent()) {
        models.add(buildProjectSampleDataTablesModel(psj, locale));
    }
    return new DataTablesResponse(params, page, models);
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)

Example 57 with ProjectSampleJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.

the class ProjectSamplesController method exportProjectSamplesTable.

/**
 * Export {@link Sample} from a {@link Project} as either Excel or CSV formatted.
 *
 * @param projectId   identifier for the current {@link Project}
 * @param type        of file to export (.csv or .xlsx)
 * @param params      DataTable parameters.
 * @param sampleNames List of {@link Sample} names the {@link Project} is filtered on
 * @param associated  List of acitve associated {@link Project} identifiers.
 * @param filter      {@link Sample} attribute filters applied.
 * @param request     {@link HttpServletRequest}
 * @param response    {@link HttpServletResponse}
 * @param locale      of the current user.
 * @throws IOException if the exported file cannot be written
 */
@RequestMapping(value = "/projects/{projectId}/samples/export")
public void exportProjectSamplesTable(@PathVariable Long projectId, @RequestParam DataTablesExportTypes type, @DataTablesRequest DataTablesParams params, @RequestParam(required = false, defaultValue = "") List<String> sampleNames, @RequestParam(required = false, defaultValue = "") List<Long> associated, UISampleFilter filter, HttpServletRequest request, HttpServletResponse response, Locale locale) throws IOException {
    Project project = projectService.read(projectId);
    List<Project> projects = new ArrayList<>();
    if (!associated.isEmpty()) {
        projects = (List<Project>) projectService.readMultiple(associated);
    }
    projects.add(project);
    final Page<ProjectSampleJoin> page = sampleService.getFilteredSamplesForProjects(projects, sampleNames, filter.getName(), params.getSearchValue(), filter.getOrganism(), filter.getStartDate(), filter.getEndDate(), 0, Integer.MAX_VALUE, params.getSort());
    // Create DataTables representation of the page.
    List<DTProjectSamples> models = new ArrayList<>();
    for (ProjectSampleJoin psj : page.getContent()) {
        models.add(buildProjectSampleDataTablesModel(psj, locale));
    }
    List<String> headers = models.get(0).getExportableTableHeaders(messageSource, locale);
    DataTablesExportToFile.writeFile(type, response, project.getLabel().replace(" ", "_"), models, headers);
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) DTProjectSamples(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTProjectSamples)

Example 58 with ProjectSampleJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.

the class ProjectSamplesController method shareSampleToProject.

/**
 * Share or move samples from one project to another
 *
 * @param projectId    The original project id
 * @param sampleIds    the sample identifiers to share
 * @param newProjectId The new project id
 * @param remove       true/false whether to remove the samples from the original  project
 * @param giveOwner    whether to give ownership of the sample to the new project
 * @param locale       the locale specified by the browser.
 * @return A list of warnings
 */
@RequestMapping(value = "/projects/{projectId}/ajax/samples/copy", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> shareSampleToProject(@PathVariable Long projectId, @RequestParam(value = "sampleIds[]") List<Long> sampleIds, @RequestParam Long newProjectId, @RequestParam(required = false) boolean remove, @RequestParam(required = false, defaultValue = "false") boolean giveOwner, Locale locale) {
    Project originalProject = projectService.read(projectId);
    Project newProject = projectService.read(newProjectId);
    Map<String, Object> response = new HashMap<>();
    List<String> warnings = new ArrayList<>();
    Iterable<Sample> samples = sampleService.readMultiple(sampleIds);
    List<ProjectSampleJoin> successful = new ArrayList<>();
    try {
        if (remove) {
            successful = projectService.moveSamples(originalProject, newProject, Lists.newArrayList(samples), giveOwner);
        } else {
            successful = projectService.shareSamples(originalProject, newProject, Lists.newArrayList(samples), giveOwner);
        }
    } catch (EntityExistsException ex) {
        logger.warn("Attempt to add project to sample failed", ex);
        warnings.add(ex.getLocalizedMessage());
    } catch (AccessDeniedException ex) {
        logger.warn("Access denied adding samples to project " + newProjectId, ex);
        String msg = remove ? "project.samples.move.sample-denied" : "project.samples.copy.sample-denied";
        warnings.add(messageSource.getMessage(msg, new Object[] { newProject.getName() }, locale));
    }
    if (!warnings.isEmpty() || successful.size() == 0) {
        response.put("result", "warning");
        response.put("warnings", warnings);
    } else {
        response.put("result", "success");
    }
    // 2. Only one sample moved
    if (successful.size() == 1) {
        if (remove) {
            response.put("message", messageSource.getMessage("project.samples.move-single-success-message", new Object[] { successful.get(0).getObject().getSampleName(), newProject.getName() }, locale));
        } else {
            response.put("message", messageSource.getMessage("project.samples.copy-single-success-message", new Object[] { successful.get(0).getObject().getSampleName(), newProject.getName() }, locale));
        }
    } else // 4. Multiple samples moved
    if (successful.size() > 1) {
        if (remove) {
            response.put("message", messageSource.getMessage("project.samples.move-multiple-success-message", new Object[] { successful.size(), newProject.getName() }, locale));
        } else {
            response.put("message", messageSource.getMessage("project.samples.copy-multiple-success-message", new Object[] { successful.size(), newProject.getName() }, locale));
        }
    }
    response.put("successful", successful.stream().map(ProjectSampleJoin::getId).collect(Collectors.toList()));
    return response;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) EntityExistsException(ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException) ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project)

Example 59 with ProjectSampleJoin

use of ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin in project irida by phac-nml.

the class AssemblyFileProcessorTest method testAssemblyDisabled.

@Test
public void testAssemblyDisabled() {
    Long sequenceFileId = 1L;
    SequenceFilePair pair = new SequenceFilePair();
    Sample sample = new Sample();
    Project project = new Project();
    project.setAssembleUploads(false);
    when(objectRepository.findOne(sequenceFileId)).thenReturn(pair);
    when(ssoRepository.getSampleForSequencingObject(pair)).thenReturn(new SampleSequencingObjectJoin(sample, pair));
    when(psjRepository.getProjectForSample(sample)).thenReturn(ImmutableList.of(new ProjectSampleJoin(project, sample, true)));
    assertFalse("processor should not want to assemble file", processor.shouldProcessFile(sequenceFileId));
    verifyZeroInteractions(submissionRepository);
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) Test(org.junit.Test)

Aggregations

ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)59 Project (ca.corefacility.bioinformatics.irida.model.project.Project)51 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)51 Test (org.junit.Test)43 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)15 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)15 ArrayList (java.util.ArrayList)11 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)8 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)8 WithMockUser (org.springframework.security.test.context.support.WithMockUser)8 User (ca.corefacility.bioinformatics.irida.model.user.User)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 Authentication (org.springframework.security.core.Authentication)7 Transactional (org.springframework.transaction.annotation.Transactional)7 EntityExistsException (ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException)6 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)6 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)6 LaunchesProjectEvent (ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent)5 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)5 RelatedProjectJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.RelatedProjectJoin)5