Search in sources :

Example 6 with HistoryContents

use of com.github.jmchilton.blend4j.galaxy.beans.HistoryContents in project irida by phac-nml.

the class GalaxyHistoriesService method getDatasetForFileInHistory.

/**
 * Gets a Dataset object for a file with the given name in the given history.
 * @param filename  The name of the file to get a Dataset object for.
 * @param historyId  The history id to look for the dataset.
 * @return The corresponding dataset for the given file name.
 * @throws GalaxyDatasetException If there was an issue when searching for a dataset.
 */
public Dataset getDatasetForFileInHistory(String filename, String historyId) throws GalaxyDatasetException {
    checkNotNull(filename, "filename is null");
    checkNotNull(historyId, "historyId is null");
    List<HistoryContents> historyContentsList = historiesClient.showHistoryContents(historyId);
    List<HistoryContents> matchingHistoryContents = historyContentsList.stream().filter((historyContents) -> filename.equals(historyContents.getName())).collect(Collectors.toList());
    // if more than one matching history item
    if (matchingHistoryContents.size() > 1) {
        String historyIds = "[";
        for (HistoryContents content : matchingHistoryContents) {
            historyIds += content.getId() + ",";
        }
        historyIds += "]";
        throw new GalaxyDatasetException("Found " + matchingHistoryContents.size() + " datasets for file " + filename + ": " + historyIds);
    } else if (matchingHistoryContents.size() == 1) {
        String dataId = matchingHistoryContents.get(0).getId();
        if (dataId != null) {
            Dataset dataset = historiesClient.showDataset(historyId, dataId);
            if (dataset != null) {
                return dataset;
            }
        }
    }
    throw new GalaxyDatasetNotFoundException("dataset for file " + filename + " not found in Galaxy history " + historyId);
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) GalaxyWorkflowStatus(ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.GalaxyWorkflowStatus) ExecutionManagerException(ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) DeleteGalaxyObjectFailedException(ca.corefacility.bioinformatics.irida.exceptions.galaxy.DeleteGalaxyObjectFailedException) ClientResponse(com.sun.jersey.api.client.ClientResponse) LoggerFactory(org.slf4j.LoggerFactory) UploadException(ca.corefacility.bioinformatics.irida.exceptions.UploadException) HashMap(java.util.HashMap) HistoryDeleteResponse(com.github.jmchilton.blend4j.galaxy.beans.HistoryDeleteResponse) NoGalaxyHistoryException(ca.corefacility.bioinformatics.irida.exceptions.galaxy.NoGalaxyHistoryException) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) GalaxyDatasetException(ca.corefacility.bioinformatics.irida.exceptions.galaxy.GalaxyDatasetException) Map(java.util.Map) HistoriesClient(com.github.jmchilton.blend4j.galaxy.HistoriesClient) Source(com.github.jmchilton.blend4j.galaxy.beans.HistoryDataset.Source) ExecutionManagerDownloadException(ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerDownloadException) Path(java.nio.file.Path) DataStorage(ca.corefacility.bioinformatics.irida.pipeline.upload.DataStorage) Logger(org.slf4j.Logger) HistoryDataset(com.github.jmchilton.blend4j.galaxy.beans.HistoryDataset) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) IOException(java.io.IOException) FileUploadRequest(com.github.jmchilton.blend4j.galaxy.ToolsClient.FileUploadRequest) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) InputFileType(ca.corefacility.bioinformatics.irida.model.workflow.execution.InputFileType) File(java.io.File) CollectionResponse(com.github.jmchilton.blend4j.galaxy.beans.collection.response.CollectionResponse) Preconditions.checkState(com.google.common.base.Preconditions.checkState) WorkflowException(ca.corefacility.bioinformatics.irida.exceptions.WorkflowException) GalaxyDatasetNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.galaxy.GalaxyDatasetNotFoundException) Library(com.github.jmchilton.blend4j.galaxy.beans.Library) List(java.util.List) ToolsClient(com.github.jmchilton.blend4j.galaxy.ToolsClient) History(com.github.jmchilton.blend4j.galaxy.beans.History) CollectionDescription(com.github.jmchilton.blend4j.galaxy.beans.collection.request.CollectionDescription) HistoryDetails(com.github.jmchilton.blend4j.galaxy.beans.HistoryDetails) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) Optional(java.util.Optional) ExecutionManagerObjectNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerObjectNotFoundException) HistoryContentsProvenance(com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance) GalaxyDatasetException(ca.corefacility.bioinformatics.irida.exceptions.galaxy.GalaxyDatasetException) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) HistoryDataset(com.github.jmchilton.blend4j.galaxy.beans.HistoryDataset) GalaxyDatasetNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.galaxy.GalaxyDatasetNotFoundException)

Example 7 with HistoryContents

use of com.github.jmchilton.blend4j.galaxy.beans.HistoryContents in project irida by phac-nml.

the class Util method getIdForFileInHistory.

/**
 * Given a file within a Galaxy history, finds the id of that file.
 * @param filename  The name of the file within a history.
 * @param historyId  The id of the history.
 * @param galaxyInstance  The GalaxyInstance to use for connections.
 * @return  The id of the file in this history, or null if no such file.
 */
public static String getIdForFileInHistory(String filename, String historyId, GalaxyInstance galaxyInstance) {
    String dataId = null;
    List<HistoryContents> historyContentsList = galaxyInstance.getHistoriesClient().showHistoryContents(historyId);
    for (HistoryContents contents : historyContentsList) {
        if (filename.equals(contents.getName())) {
            dataId = contents.getId();
            break;
        }
    }
    return dataId;
}
Also used : HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents)

Example 8 with HistoryContents

use of com.github.jmchilton.blend4j.galaxy.beans.HistoryContents in project irida by phac-nml.

the class GalaxyHistoriesServiceTest method testFileToHistoryFailFindDataset.

/**
 * Tests failing to find a Dataset object after uploading a file to a history.
 * @throws UploadException
 * @throws GalaxyDatasetException
 */
@Test(expected = GalaxyDatasetNotFoundException.class)
public void testFileToHistoryFailFindDataset() throws UploadException, GalaxyDatasetException {
    String filename = dataFile.toFile().getName();
    History createdHistory = new History();
    createdHistory.setId(HISTORY_ID);
    List<HistoryContents> historyContentsList = buildHistoryContentsList(filename, DATA_ID);
    when(toolsClient.uploadRequest(any(FileUploadRequest.class))).thenReturn(okayResponse);
    when(historiesClient.showHistoryContents(HISTORY_ID)).thenReturn(historyContentsList);
    galaxyHistory.fileToHistory(dataFile, FILE_TYPE, createdHistory);
}
Also used : FileUploadRequest(com.github.jmchilton.blend4j.galaxy.ToolsClient.FileUploadRequest) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) History(com.github.jmchilton.blend4j.galaxy.beans.History) Test(org.junit.Test)

Example 9 with HistoryContents

use of com.github.jmchilton.blend4j.galaxy.beans.HistoryContents in project irida by phac-nml.

the class GalaxyHistoriesServiceTest method testFileToHistorySuccess.

/**
 * Tests uploading a file to a history.
 * @throws UploadException
 * @throws GalaxyDatasetException
 */
@Test
public void testFileToHistorySuccess() throws UploadException, GalaxyDatasetException {
    String filename = dataFile.toFile().getName();
    History createdHistory = new History();
    Dataset dataset = new Dataset();
    createdHistory.setId(HISTORY_ID);
    List<HistoryContents> historyContentsList = buildHistoryContentsList(filename, DATA_ID);
    when(toolsClient.uploadRequest(any(FileUploadRequest.class))).thenReturn(okayResponse);
    when(historiesClient.showHistoryContents(HISTORY_ID)).thenReturn(historyContentsList);
    when(historiesClient.showDataset(HISTORY_ID, DATA_ID)).thenReturn(dataset);
    assertEquals(dataset, galaxyHistory.fileToHistory(dataFile, FILE_TYPE, createdHistory));
}
Also used : FileUploadRequest(com.github.jmchilton.blend4j.galaxy.ToolsClient.FileUploadRequest) Dataset(com.github.jmchilton.blend4j.galaxy.beans.Dataset) HistoryDataset(com.github.jmchilton.blend4j.galaxy.beans.HistoryDataset) HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) History(com.github.jmchilton.blend4j.galaxy.beans.History) Test(org.junit.Test)

Example 10 with HistoryContents

use of com.github.jmchilton.blend4j.galaxy.beans.HistoryContents in project irida by phac-nml.

the class GalaxyHistoriesServiceTest method buildHistoryContentsList.

private List<HistoryContents> buildHistoryContentsList(String filename, String id) {
    HistoryContents datasetHistoryContent = new HistoryContents();
    datasetHistoryContent.setName(filename);
    datasetHistoryContent.setId(id);
    List<HistoryContents> datasetHistoryContents = new ArrayList<HistoryContents>();
    datasetHistoryContents.add(datasetHistoryContent);
    return Arrays.asList(datasetHistoryContent);
}
Also used : HistoryContents(com.github.jmchilton.blend4j.galaxy.beans.HistoryContents) ArrayList(java.util.ArrayList)

Aggregations

HistoryContents (com.github.jmchilton.blend4j.galaxy.beans.HistoryContents)22 Test (org.junit.Test)18 History (com.github.jmchilton.blend4j.galaxy.beans.History)11 HistoriesClient (com.github.jmchilton.blend4j.galaxy.HistoriesClient)9 HistoryContentsProvenance (com.github.jmchilton.blend4j.galaxy.beans.HistoryContentsProvenance)8 WithMockUser (org.springframework.security.test.context.support.WithMockUser)8 Path (java.nio.file.Path)7 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)6 PreparedWorkflowGalaxy (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.PreparedWorkflowGalaxy)6 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)6 WorkflowsClient (com.github.jmchilton.blend4j.galaxy.WorkflowsClient)6 Tool (com.github.jmchilton.blend4j.galaxy.beans.Tool)6 Workflow (com.github.jmchilton.blend4j.galaxy.beans.Workflow)6 ToolExecution (ca.corefacility.bioinformatics.irida.model.workflow.analysis.ToolExecution)5 WorkflowInputsGalaxy (ca.corefacility.bioinformatics.irida.model.workflow.execution.galaxy.WorkflowInputsGalaxy)5 JobDetails (com.github.jmchilton.blend4j.galaxy.beans.JobDetails)5 LibrariesClient (com.github.jmchilton.blend4j.galaxy.LibrariesClient)4 HashMap (java.util.HashMap)4 List (java.util.List)4 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)3