use of ca.corefacility.bioinformatics.irida.model.project.ReferenceFile in project irida by phac-nml.
the class ReferenceFileController method addIndependentReferenceFile.
/**
* Upload a transient reference file, to be used for a single analysis.
*
* @param file the new reference file
* @param response the response to write errors to.
* @param locale Locale of the current user
* @return Success message with uploaded file id and name
* @throws IOException if the new reference file cannot be saved
*/
@RequestMapping("/new")
public Map<String, Object> addIndependentReferenceFile(@RequestParam(value = "file") final MultipartFile file, final HttpServletResponse response, final Locale locale) throws IOException {
logger.debug("Adding transient reference file for a single pipeline.");
// Prepare a new reference file using the multipart file supplied by the caller
final Path temp = Files.createTempDirectory(null);
final Path target = temp.resolve(file.getOriginalFilename());
file.transferTo(target.toFile());
ReferenceFile referenceFile = new ReferenceFile(target);
try {
referenceFile = referenceFileService.create(referenceFile);
} catch (final UnsupportedReferenceFileContentError e) {
logger.error("User uploaded a reference file that biojava couldn't parse as DNA.", e);
response.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
return ImmutableMap.of("error", messageSource.getMessage("projects.meta.reference-file.invalid-content", new Object[] {}, locale));
}
// Clean up temporary files
Files.deleteIfExists(target);
Files.deleteIfExists(temp);
return ImmutableMap.of("uploaded-file-id", referenceFile.getId(), "uploaded-file-name", referenceFile.getLabel());
}
use of ca.corefacility.bioinformatics.irida.model.project.ReferenceFile in project irida by phac-nml.
the class ReferenceFileController method deleteReferenceFile.
/**
* Delete a reference file. This will remove it from the project.
*
* @param fileId
* The id of the file to remove.
* @param projectId
* the project to delete the reference file for.
* @param response
* {@link HttpServletResponse} required for returning an error
* state.
* @param locale
* the locale specified by the browser.
*
* @return Success or error based on the result of deleting the file.
*/
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> deleteReferenceFile(@RequestParam Long fileId, @RequestParam Long projectId, HttpServletResponse response, Locale locale) {
Map<String, Object> result = new HashMap<>();
Project project = projectService.read(projectId);
ReferenceFile file = referenceFileService.read(fileId);
try {
logger.info("Removing file with id of : " + fileId);
projectService.removeReferenceFileFromProject(project, file);
result.put("result", "success");
result.put("msg", messageSource.getMessage("projects.meta.reference-file.delete-success", new Object[] { file.getLabel(), project.getName() }, locale));
} catch (EntityNotFoundException e) {
// This is required else the client does not know that an error was thrown!
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
logger.error("Failed to upload reference file, reason unknown.", e);
result.put("result", "error");
result.put("msg", messageSource.getMessage("projects.meta.reference-file.delete-error", new Object[] { file.getLabel(), project.getName() }, locale));
}
return result;
}
use of ca.corefacility.bioinformatics.irida.model.project.ReferenceFile in project irida by phac-nml.
the class ProjectServiceImplTest method testAddReferenceFileToProject.
@Test
public void testAddReferenceFileToProject() throws IOException {
Project p = new Project();
Path createTempFile = Files.createTempFile(null, null);
ReferenceFile f = new ReferenceFile(createTempFile);
when(referenceFileRepository.save(f)).thenReturn(f);
projectService.addReferenceFileToProject(p, f);
verify(referenceFileRepository).save(f);
verify(prfjRepository).save(new ProjectReferenceFileJoin(p, f));
}
use of ca.corefacility.bioinformatics.irida.model.project.ReferenceFile in project irida by phac-nml.
the class AnalysisWorkspaceServiceGalaxyTest method setup.
/**
* Sets up variables for testing.
*
* @throws IOException
* @throws GalaxyDatasetException
* @throws UploadException
*/
@Before
public void setup() throws IOException, UploadException, GalaxyDatasetException {
MockitoAnnotations.initMocks(this);
sFileA = new SequenceFile(createTempFile("fileA", "fastq"));
sFileB = new SequenceFile(createTempFile("fileB", "fastq"));
sFileC = new SequenceFile(createTempFile("fileC", "fastq"));
sObjA = new SingleEndSequenceFile(sFileA);
sObjB = new SingleEndSequenceFile(sFileB);
sObjC = new SingleEndSequenceFile(sFileC);
sequenceFilePair = new SequenceFilePair(sFileB, sFileC);
singleEndSequenceFile = sObjA;
Sample sampleA = new Sample();
sampleA.setSampleName("SampleA");
Sample sampleB = new Sample();
sampleB.setSampleName("SampleB");
Sample sampleC = new Sample();
sampleC.setSampleName("SampleC");
sampleSingleSequenceFileMap = ImmutableMap.of(sampleA, singleEndSequenceFile);
sampleSequenceFilePairMap = ImmutableMap.of(sampleB, sequenceFilePair);
sampleSequenceFilePairMapSampleA = ImmutableMap.of(sampleA, sequenceFilePair);
refFile = createTempFile("reference", "fasta");
referenceFile = new ReferenceFile(refFile);
inputFiles = new HashSet<>();
inputFiles.addAll(Arrays.asList(sObjA, sObjB, sObjC));
submission = AnalysisSubmission.builder(workflowId).name("my analysis").inputFiles(inputFiles).referenceFile(referenceFile).build();
workflowHistory = new History();
workflowHistory.setId(HISTORY_ID);
workflowLibrary = new Library();
workflowLibrary.setId(LIBRARY_ID);
workflowDetails = new WorkflowDetails();
workflowDetails.setId(WORKFLOW_ID);
workflowPreparation = new AnalysisWorkspaceServiceGalaxy(galaxyHistoriesService, galaxyWorkflowService, galaxyLibrariesService, iridaWorkflowsService, analysisCollectionServiceGalaxy, analysisProvenanceServiceGalaxy, analysisParameterServiceGalaxy, sequencingObjectService);
output1Dataset = new Dataset();
output1Dataset.setId("1");
output1Dataset.setName("output1.txt");
output2Dataset = new Dataset();
output2Dataset.setId("2");
output2Dataset.setName("output2.txt");
collectionResponseSingle = new CollectionResponse();
collectionResponseSingle.setId(COLLECTION_SINGLE_ID);
collectionResponsePaired = new CollectionResponse();
collectionResponsePaired.setId(COLLECTION_PAIRED_ID);
singleInputFiles = Sets.newHashSet(singleEndSequenceFile);
pairedInputFiles = Sets.newHashSet(sequenceFilePair);
}
use of ca.corefacility.bioinformatics.irida.model.project.ReferenceFile in project irida by phac-nml.
the class ProjectServiceImplIT method testAddReferenceFileToProject.
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testAddReferenceFileToProject() throws IOException, URISyntaxException {
ReferenceFile f = new ReferenceFile();
Path referenceFilePath = Paths.get(getClass().getResource("/ca/corefacility/bioinformatics/irida/service/testReference.fasta").toURI());
Path createTempFile = Files.createTempFile("testReference", ".fasta");
Files.delete(createTempFile);
referenceFilePath = Files.copy(referenceFilePath, createTempFile);
referenceFilePath.toFile().deleteOnExit();
f.setFile(referenceFilePath);
Project p = projectService.read(1L);
Join<Project, ReferenceFile> pr = projectService.addReferenceFileToProject(p, f);
assertEquals("Project was set in the join.", p, pr.getSubject());
// verify that the reference file was persisted beneath the reference
// file directory
ReferenceFile rf = pr.getObject();
assertTrue("reference file should be beneath the base directory for reference files.", rf.getFile().startsWith(referenceFileBaseDirectory));
}
Aggregations