Search in sources :

Example 1 with ReferenceFile

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());
}
Also used : Path(java.nio.file.Path) ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) UnsupportedReferenceFileContentError(ca.corefacility.bioinformatics.irida.exceptions.UnsupportedReferenceFileContentError) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ReferenceFile

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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) HashMap(java.util.HashMap) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with ReferenceFile

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));
}
Also used : Path(java.nio.file.Path) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) ProjectReferenceFileJoin(ca.corefacility.bioinformatics.irida.model.project.ProjectReferenceFileJoin) Test(org.junit.Test)

Example 4 with ReferenceFile

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);
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) AnalysisWorkspaceServiceGalaxy(ca.corefacility.bioinformatics.irida.service.analysis.workspace.galaxy.AnalysisWorkspaceServiceGalaxy) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) CollectionResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionResponse) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Before(org.junit.Before)

Example 5 with ReferenceFile

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));
}
Also used : Path(java.nio.file.Path) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ReferenceFile(ca.corefacility.bioinformatics.irida.model.project.ReferenceFile) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Aggregations

ReferenceFile (ca.corefacility.bioinformatics.irida.model.project.ReferenceFile)30 Project (ca.corefacility.bioinformatics.irida.model.project.Project)15 Test (org.junit.Test)12 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)10 Path (java.nio.file.Path)10 WithMockUser (org.springframework.security.test.context.support.WithMockUser)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)5 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)5 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)4 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)4 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)3 IridaWorkflowDescription (ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription)3 ProjectAnalysisSubmissionJoin (ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 UnsupportedReferenceFileContentError (ca.corefacility.bioinformatics.irida.exceptions.UnsupportedReferenceFileContentError)2