Skip to content

Commit

Permalink
Merge pull request #1353 from phac-nml/unify-sample-validation
Browse files Browse the repository at this point in the history
Unify validate sample names
  • Loading branch information
ericenns authored Sep 6, 2022
2 parents 5f549af + 18c083e commit f500c39
Show file tree
Hide file tree
Showing 19 changed files with 334 additions and 347 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* [Developer]: Updated OAuth2 implementation to use Spring Security 5 OAuth2 libraries. See [PR 1339](https://github.com/phac-nml/irida/pull/1339)
* [Developer]: Add identifier to project drop-downs. See [PR 1352](https://github.com/phac-nml/irida/pull/1352)
* [UI]: Fixed issue with Biohansel pipeline being launched without selecting an option for a required parameter. See [PR 1356](https://github.com/phac-nml/irida/pull/1356)
* [Developer]: Unified validate sample names into one endpoint. See [PR 1353](https://github.com/phac-nml/irida/pull/1353)

## [22.05.5] - 2022/06/28
* [UI]: Fixed bug preventing export of project samples table due to invalid url. [PR 1331](https://github.com/phac-nml/irida/pull/1331)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.List;
import java.util.Set;

import javax.persistence.Tuple;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.EntityGraph;
Expand Down Expand Up @@ -34,7 +36,7 @@ public interface SampleRepository extends IridaJpaRepository<Sample, Long>, Samp
public List<Sample> getSamplesForProjectShallow(Project project);

/**
* Get a {@link Sample} with the given string sample identifier from a specific project.
* Get a {@link Sample} with the given string sample name from a specific project.
*
* @param p The {@link Project} that the {@link Sample} belongs to.
* @param sampleName The string sample name for a sample
Expand All @@ -44,6 +46,18 @@ public interface SampleRepository extends IridaJpaRepository<Sample, Long>, Samp
@Query("select j.sample from ProjectSampleJoin j where j.project = ?1 and j.sample.sampleName = ?2")
public Sample getSampleBySampleName(Project p, String sampleName) throws EntityNotFoundException;

/**
* Get the {@link Sample} identifiers with the given list of sample names from a list of projects.
*
* @param projectIds The {@link Project} identifiers that the {@link Sample} belongs to.
* @param sampleNames The list of sample names
* @return A list of {@link Sample} identifiers
* @throws EntityNotFoundException if a sample with this identifier doesn't exist
*/
@Query("select j.sample.sampleName, j.sample.id from ProjectSampleJoin j where j.project.id in ?1 and j.sample.sampleName in ?2")
public List<Tuple> getSampleIdsBySampleNameInProjects(List<Long> projectIds, List<String> sampleNames)
throws EntityNotFoundException;

/**
* Get a {@link Page} of {@link Sample}s based on a list of {@link Sample} names
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;

import ca.corefacility.bioinformatics.irida.model.sample.Sample;
import ca.corefacility.bioinformatics.irida.ria.web.ajax.dto.CreateSampleRequest;
import ca.corefacility.bioinformatics.irida.ria.web.ajax.dto.SampleFilesResponse;
import ca.corefacility.bioinformatics.irida.ria.web.ajax.dto.SampleNameValidationResponse;
import ca.corefacility.bioinformatics.irida.ria.web.ajax.dto.ajax.AjaxErrorResponse;
import ca.corefacility.bioinformatics.irida.ria.web.ajax.dto.ajax.AjaxResponse;
import ca.corefacility.bioinformatics.irida.ria.web.ajax.dto.ajax.AjaxSuccessResponse;
import ca.corefacility.bioinformatics.irida.ria.web.ajax.projects.dto.ValidateSampleNamesRequest;
import ca.corefacility.bioinformatics.irida.ria.web.exceptions.UIShareSamplesException;
import ca.corefacility.bioinformatics.irida.ria.web.models.tables.AntTableResponse;
import ca.corefacility.bioinformatics.irida.ria.web.projects.dto.DownloadRequest;
Expand Down Expand Up @@ -119,8 +119,7 @@ public ResponseEntity<AjaxResponse> mergeSamples(@PathVariable Long projectId, @
String response = uiSampleService.mergeSamples(projectId, request, locale);
return ResponseEntity.ok(new AjaxSuccessResponse(response));
} catch (SampleMergeException e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(new AjaxErrorResponse(e.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new AjaxErrorResponse(e.getMessage()));
}
}

Expand Down Expand Up @@ -169,28 +168,6 @@ public void downloadSamplesSpreadsheet(@PathVariable long projectId, @RequestPar
uiSampleService.downloadSamplesSpreadsheet(projectId, type, request, response, locale);
}

/**
* Get a list of all {@link Sample} identifiers within a specific project
*
* @param id Identifier for a Project
* @return {@link List} of {@link Sample} identifiers
*/
@GetMapping("/identifiers")
public List<Long> getSampleIdsForProject(@RequestParam Long id) {
return uiSampleService.getSampleIdsForProject(id);
}

/**
* Get a list of all {@link Sample} names within a specific project
*
* @param id Identifier for a Project
* @return {@link List} of {@link Sample} names
*/
@GetMapping("/names")
public List<String> getSampleNamesForProject(@RequestParam Long id) {
return uiSampleService.getSampleNamesForProject(id);
}

/**
* Share / Move samples between projects
*
Expand All @@ -205,8 +182,7 @@ public ResponseEntity<AjaxResponse> shareSamplesWithProject(@RequestBody ShareSa
uiSampleService.shareSamplesWithProject(request, locale);
return ResponseEntity.ok(new AjaxSuccessResponse(""));
} catch (UIShareSamplesException e) {
return ResponseEntity.status(HttpStatus.FORBIDDEN)
.body(new AjaxErrorResponse(e.getLocalizedMessage()));
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(new AjaxErrorResponse(e.getLocalizedMessage()));
}
}

Expand All @@ -221,4 +197,18 @@ public ResponseEntity<AjaxResponse> shareSamplesWithProject(@RequestBody ShareSa
public SampleFilesResponse getFilesForSamples(@RequestParam List<Long> ids, @PathVariable Long projectId) {
return uiSampleService.getFilesForSamples(ids, projectId);
}

/**
* Validate a list of samples names
*
* @param projectId project identifier
* @param request {@link ValidateSampleNamesRequest} details about the sample names to validate
* @return a list of validated sample names
*/
@PostMapping("/validate")
public ResponseEntity<AjaxResponse> validateSampleNames(@PathVariable Long projectId,
@RequestBody ValidateSampleNamesRequest request) {
return ResponseEntity.ok(uiProjectSampleService.validateSampleNames(projectId, request));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ca.corefacility.bioinformatics.irida.ria.web.ajax.projects.dto;

import java.util.List;

/**
* Model for UI to represent a sample.
*/
public class ValidateSampleNameModel {
private List<Long> ids;
private String name;

public ValidateSampleNameModel(List<Long> ids, String name) {
this.ids = ids;
this.name = name;
}

public List<Long> getIds() {
return ids;
}

public void setIds(List<Long> ids) {
this.ids = ids;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ca.corefacility.bioinformatics.irida.ria.web.ajax.projects.dto;

import java.util.List;

/**
* UI request to validate sample names.
*/
public class ValidateSampleNamesRequest {
private List<ValidateSampleNameModel> samples;
private List<Long> associatedProjectIds;

public ValidateSampleNamesRequest() {
}

public List<ValidateSampleNameModel> getSamples() {
return samples;
}

public void setSamples(List<ValidateSampleNameModel> samples) {
this.samples = samples;
}

public List<Long> getAssociatedProjectIds() {
return associatedProjectIds;
}

public void setAssociatedProjectIds(List<Long> associatedProjectIds) {
this.associatedProjectIds = associatedProjectIds;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ca.corefacility.bioinformatics.irida.ria.web.ajax.projects.dto;

import java.util.List;

import ca.corefacility.bioinformatics.irida.ria.web.ajax.dto.ajax.AjaxResponse;

/**
* Return a list of sample names.
*/
public class ValidateSampleNamesResponse extends AjaxResponse {
private List<ValidateSampleNameModel> samples;

public ValidateSampleNamesResponse(List<ValidateSampleNameModel> samples) {
this.samples = samples;
}

public List<ValidateSampleNameModel> getSamples() {
return samples;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile;
import ca.corefacility.bioinformatics.irida.ria.web.ajax.dto.ajax.AjaxResponse;
import ca.corefacility.bioinformatics.irida.ria.web.samples.dto.SampleDetails;
import ca.corefacility.bioinformatics.irida.ria.web.samples.dto.SampleNameCheckRequest;
import ca.corefacility.bioinformatics.irida.ria.web.samples.dto.SampleNameCheckResponse;
import ca.corefacility.bioinformatics.irida.ria.web.services.UISampleService;
import ca.corefacility.bioinformatics.irida.service.GenomeAssemblyService;
import ca.corefacility.bioinformatics.irida.service.SequencingObjectService;
Expand Down Expand Up @@ -101,7 +99,7 @@ public ResponseEntity<String> uploadSequenceFiles(@PathVariable Long sampleId, M
*/
@RequestMapping(value = "/{sampleId}/fast5/upload", method = RequestMethod.POST)
public ResponseEntity<String> uploadFast5Files(@PathVariable Long sampleId, MultipartHttpServletRequest request,
Locale locale) {
Locale locale) {
Sample sample = sampleService.read(sampleId);
Iterator<String> fileNames = request.getFileNames();
List<MultipartFile> files = new ArrayList<>();
Expand All @@ -114,7 +112,7 @@ public ResponseEntity<String> uploadFast5Files(@PathVariable Long sampleId, Mult
createFast5FileInSample(file, sample);
}
return ResponseEntity.ok(messageSource.getMessage("server.SampleFileUploader.success",
new Object[]{sample.getSampleName()}, locale));
new Object[] { sample.getSampleName() }, locale));
} catch (IOException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("");
}
Expand Down Expand Up @@ -181,17 +179,6 @@ public ResponseEntity<AjaxResponse> getFilesForSample(@PathVariable Long id,
return ResponseEntity.ok(uiSampleService.getSampleFiles(id, projectId));
}

/**
* Check if a list of sample names exist within a project
*
* @param request {@link SampleNameCheckRequest} containing the project id and sample names
* @return {@link SampleNameCheckResponse} containing list of valid and invalid sample names
*/
@PostMapping("/validate")
public SampleNameCheckResponse checkSampleNames(@RequestBody SampleNameCheckRequest request) {
return uiSampleService.checkSampleNames(request);
}

/**
* Create {@link SequenceFile}'s then add them as {@link SequenceFilePair} to a {@link Sample}
*
Expand Down Expand Up @@ -230,8 +217,7 @@ private void createFast5FileInSample(MultipartFile file, Sample sample) throws I
}

/**
* Private method to move the sequence file into the correct directory and
* create the {@link SequenceFile} object.
* Private method to move the sequence file into the correct directory and create the {@link SequenceFile} object.
*
* @param file {@link MultipartFile} sequence file uploaded.
* @return {@link SequenceFile}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit f500c39

Please sign in to comment.