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);
}
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;
}
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);
}
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));
}
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);
}
Aggregations