use of com.github.jmchilton.blend4j.galaxy.beans.LibraryContent in project irida by phac-nml.
the class GalaxyHistoriesServiceIT method setupLibraries.
/**
* Sets up library for test.
* @param testLibrary The library to upload a file to.
* @param galaxyInstanceAdmin The Galaxy Instance to connect to Galaxy.
* @return Returns the id of the file in a library.
* @throws CreateLibraryException
* @throws ExecutionManagerObjectNotFoundException
*/
private String setupLibraries(Library testLibrary, GalaxyInstance galaxyInstanceAdmin) throws CreateLibraryException, ExecutionManagerObjectNotFoundException {
LibrariesClient librariesClient = galaxyInstanceAdmin.getLibrariesClient();
LibraryContent rootFolder = librariesClient.getRootFolder(testLibrary.getId());
assertNotNull(rootFolder);
FilesystemPathsLibraryUpload upload = new FilesystemPathsLibraryUpload();
upload.setFolderId(rootFolder.getId());
upload.setContent(dataFile.toFile().getAbsolutePath());
upload.setName(dataFile.toFile().getName());
upload.setLinkData(true);
upload.setFileType(FILE_TYPE.toString());
assertEquals(ClientResponse.Status.OK, librariesClient.uploadFilesystemPathsRequest(testLibrary.getId(), upload).getClientResponseStatus());
List<LibraryContent> libraryContents = librariesClient.getLibraryContents(testLibrary.getId());
Map<String, List<LibraryContent>> libraryContent = libraryContents.stream().collect(Collectors.groupingBy(LibraryContent::getName));
LibraryContent fileContent = libraryContent.get("/" + dataFile.toFile().getName()).get(0);
assertNotNull(fileContent);
return fileContent.getId();
}
use of com.github.jmchilton.blend4j.galaxy.beans.LibraryContent in project irida by phac-nml.
the class GalaxyLibrariesService method fileToLibrary.
/**
* Uploads the given file to a library with the given information.
*
* @param path
* The path of the file to upload.
* @param fileType
* The type of the file to upload.
* @param library
* The library to upload the file into.
* @param dataStorage
* The {@link DataStorage} method to apply to this dataset.
* @return A dataset id for the dataset in this library.
* @throws UploadException
* If there was an issue uploading the file to the library.
*/
public String fileToLibrary(Path path, InputFileType fileType, Library library, DataStorage dataStorage) throws UploadException {
checkNotNull(path, "path is null");
checkNotNull(fileType, "fileType is null");
checkNotNull(library, "library is null");
checkNotNull(library.getId(), "library id is null");
checkState(path.toFile().exists(), "path " + path + " does not exist");
File file = path.toFile();
try {
LibraryContent rootContent = librariesClient.getRootFolder(library.getId());
FilesystemPathsLibraryUpload upload = new FilesystemPathsLibraryUpload();
upload.setFolderId(rootContent.getId());
upload.setContent(file.getAbsolutePath());
upload.setName(file.getName());
upload.setLinkData(DataStorage.LOCAL.equals(dataStorage));
upload.setFileType(fileType.toString());
GalaxyObject uploadObject = librariesClient.uploadFilesystemPaths(library.getId(), upload);
return uploadObject.getId();
} catch (RuntimeException e) {
throw new UploadException(e);
}
}
use of com.github.jmchilton.blend4j.galaxy.beans.LibraryContent in project irida by phac-nml.
the class AnalysisWorkspaceServiceGalaxyIT method testPrepareAnalysisFilesPairSuccess.
/**
* Tests out successfully preparing paired workflow input files for
* execution.
*
* @throws InterruptedException
* @throws ExecutionManagerException
* @throws IOException
* @throws IridaWorkflowException
*/
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testPrepareAnalysisFilesPairSuccess() throws InterruptedException, ExecutionManagerException, IOException, IridaWorkflowException {
History history = new History();
history.setName("testPrepareAnalysisFilesPairSuccess");
HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
WorkflowsClient workflowsClient = localGalaxy.getGalaxyInstanceAdmin().getWorkflowsClient();
LibrariesClient librariesClient = localGalaxy.getGalaxyInstanceAdmin().getLibrariesClient();
History createdHistory = historiesClient.create(history);
IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(validWorkflowIdPaired);
Path workflowPath = iridaWorkflow.getWorkflowStructure().getWorkflowFile();
String workflowString = new String(Files.readAllBytes(workflowPath), StandardCharsets.UTF_8);
Workflow galaxyWorkflow = workflowsClient.importWorkflow(workflowString);
AnalysisSubmission analysisSubmission = analysisExecutionGalaxyITService.setupPairSubmissionInDatabase(1L, pairSequenceFiles1A, pairSequenceFiles2A, referenceFilePath, validWorkflowIdPaired, false);
analysisSubmission.setRemoteAnalysisId(createdHistory.getId());
analysisSubmission.setRemoteWorkflowId(galaxyWorkflow.getId());
PreparedWorkflowGalaxy preparedWorkflow = analysisWorkspaceService.prepareAnalysisFiles(analysisSubmission);
assertEquals("the response history id should match the input history id", createdHistory.getId(), preparedWorkflow.getRemoteAnalysisId());
WorkflowInputsGalaxy workflowInputsGalaxy = preparedWorkflow.getWorkflowInputs();
assertNotNull("the returned workflow inputs should not be null", workflowInputsGalaxy);
assertNotNull("the returned library id should not be null", preparedWorkflow.getRemoteDataId());
// verify correct library is created
List<LibraryContent> libraryContents = librariesClient.getLibraryContents(preparedWorkflow.getRemoteDataId());
Map<String, List<LibraryContent>> libraryContentsMap = libraryContents.stream().collect(Collectors.groupingBy(LibraryContent::getName));
assertFalse("the returned library should exist in Galaxy", libraryContentsMap.isEmpty());
String sequenceFile1ALibraryName = "/" + sequenceFilePathA.getFileName().toString();
String sequenceFile2ALibraryName = "/" + sequenceFilePath2A.getFileName().toString();
assertEquals("the returned library does not contain the correct number of elements", 3, libraryContentsMap.size());
assertTrue("the returned library does not contain a root folder", libraryContentsMap.containsKey("/"));
assertTrue("the returned library does not contain the correct sequence file", libraryContentsMap.containsKey(sequenceFile1ALibraryName));
assertEquals("the returned library does not contain the correct sequence file", 1, libraryContentsMap.get(sequenceFile1ALibraryName).size());
assertTrue("the returned library does not contain the correct sequence file", libraryContentsMap.containsKey(sequenceFile2ALibraryName));
assertEquals("the returned library does not contain the correct sequence file", 1, libraryContentsMap.get(sequenceFile2ALibraryName).size());
// verify correct files have been uploaded
List<HistoryContents> historyContents = historiesClient.showHistoryContents(createdHistory.getId());
assertEquals("the created history has an invalid number of elements", 4, historyContents.size());
Map<String, HistoryContents> contentsMap = historyContentsAsMap(historyContents);
assertTrue("the created history should contain the file " + sequenceFilePathA.toFile().getName(), contentsMap.containsKey(sequenceFilePathA.toFile().getName()));
assertTrue("the created history should contain the file " + sequenceFilePath2A.toFile().getName(), contentsMap.containsKey(sequenceFilePath2A.toFile().getName()));
assertTrue("the created history should contain the file " + referenceFilePath.toFile().getName(), contentsMap.containsKey(referenceFilePath.toFile().getName()));
assertTrue("the created history should contain the collection with name " + INPUTS_PAIRED_NAME, contentsMap.containsKey(INPUTS_PAIRED_NAME));
// make sure workflow inputs contains correct information
Map<String, WorkflowInput> workflowInputsMap = preparedWorkflow.getWorkflowInputs().getInputsObject().getInputs();
assertEquals("the created workflow inputs has an invalid number of elements", 2, workflowInputsMap.size());
}
use of com.github.jmchilton.blend4j.galaxy.beans.LibraryContent in project irida by phac-nml.
the class AnalysisWorkspaceServiceGalaxyIT method testPrepareAnalysisFilesSingleSuccess.
/**
* Tests out successfully preparing single workflow input files for
* execution.
*
* @throws InterruptedException
* @throws ExecutionManagerException
* @throws IOException
* @throws IridaWorkflowException
*/
@Test
@WithMockUser(username = "aaron", roles = "ADMIN")
public void testPrepareAnalysisFilesSingleSuccess() throws InterruptedException, ExecutionManagerException, IOException, IridaWorkflowException {
History history = new History();
history.setName("testPrepareAnalysisFilesSingleSuccess");
HistoriesClient historiesClient = localGalaxy.getGalaxyInstanceAdmin().getHistoriesClient();
WorkflowsClient workflowsClient = localGalaxy.getGalaxyInstanceAdmin().getWorkflowsClient();
LibrariesClient librariesClient = localGalaxy.getGalaxyInstanceAdmin().getLibrariesClient();
History createdHistory = historiesClient.create(history);
IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(validWorkflowIdSingle);
Path workflowPath = iridaWorkflow.getWorkflowStructure().getWorkflowFile();
String workflowString = new String(Files.readAllBytes(workflowPath), StandardCharsets.UTF_8);
Workflow galaxyWorkflow = workflowsClient.importWorkflow(workflowString);
AnalysisSubmission analysisSubmission = analysisExecutionGalaxyITService.setupSubmissionInDatabase(1L, sequenceFilePathA, referenceFilePath, validWorkflowIdSingle, false);
analysisSubmission.setRemoteAnalysisId(createdHistory.getId());
analysisSubmission.setRemoteWorkflowId(galaxyWorkflow.getId());
PreparedWorkflowGalaxy preparedWorkflow = analysisWorkspaceService.prepareAnalysisFiles(analysisSubmission);
assertEquals("the response history id should match the input history id", createdHistory.getId(), preparedWorkflow.getRemoteAnalysisId());
assertNotNull("the returned workflow inputs should not be null", preparedWorkflow.getWorkflowInputs());
assertNotNull("the returned library id should not be null", preparedWorkflow.getRemoteDataId());
// verify correct library is created
List<LibraryContent> libraryContents = librariesClient.getLibraryContents(preparedWorkflow.getRemoteDataId());
Map<String, List<LibraryContent>> libraryContentsMap = libraryContents.stream().collect(Collectors.groupingBy(LibraryContent::getName));
assertFalse("the returned library should exist in Galaxy", libraryContentsMap.isEmpty());
String sequenceFileALibraryName = "/" + sequenceFilePathA.getFileName().toString();
assertEquals("the returned library does not contain the correct number of elements", 2, libraryContentsMap.size());
assertTrue("the returned library does not contain a root folder", libraryContentsMap.containsKey("/"));
assertTrue("the returned library does not contain the correct sequence file", libraryContentsMap.containsKey(sequenceFileALibraryName));
assertEquals("the returned library does not contain the correct sequence file", 1, libraryContentsMap.get(sequenceFileALibraryName).size());
// verify correct files have been uploaded
List<HistoryContents> historyContents = historiesClient.showHistoryContents(createdHistory.getId());
assertEquals("the created history should contain 3 entries", 3, historyContents.size());
Map<String, HistoryContents> contentsMap = historyContentsAsMap(historyContents);
assertTrue("the created history should contain the file " + sequenceFilePathA.toFile().getName(), contentsMap.containsKey(sequenceFilePathA.toFile().getName()));
assertTrue("the created history should contain the file " + referenceFilePath.toFile().getName(), contentsMap.containsKey(referenceFilePath.toFile().getName()));
assertTrue("the created history should contain the collection with name " + INPUTS_SINGLE_NAME, contentsMap.containsKey(INPUTS_SINGLE_NAME));
// make sure workflow inputs contains correct information
Map<String, WorkflowInput> workflowInputsMap = preparedWorkflow.getWorkflowInputs().getInputsObject().getInputs();
assertEquals("the created workflow inputs has an invalid number of elements", 2, workflowInputsMap.size());
}
Aggregations