Search in sources :

Example 1 with FilesystemPathsLibraryUpload

use of com.github.jmchilton.blend4j.galaxy.beans.FilesystemPathsLibraryUpload 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();
}
Also used : LibraryContent(com.github.jmchilton.blend4j.galaxy.beans.LibraryContent) List(java.util.List) LibrariesClient(com.github.jmchilton.blend4j.galaxy.LibrariesClient) FilesystemPathsLibraryUpload(com.github.jmchilton.blend4j.galaxy.beans.FilesystemPathsLibraryUpload)

Example 2 with FilesystemPathsLibraryUpload

use of com.github.jmchilton.blend4j.galaxy.beans.FilesystemPathsLibraryUpload 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);
    }
}
Also used : GalaxyObject(com.github.jmchilton.blend4j.galaxy.beans.GalaxyObject) LibraryContent(com.github.jmchilton.blend4j.galaxy.beans.LibraryContent) UploadException(ca.corefacility.bioinformatics.irida.exceptions.UploadException) File(java.io.File) FilesystemPathsLibraryUpload(com.github.jmchilton.blend4j.galaxy.beans.FilesystemPathsLibraryUpload)

Aggregations

FilesystemPathsLibraryUpload (com.github.jmchilton.blend4j.galaxy.beans.FilesystemPathsLibraryUpload)2 LibraryContent (com.github.jmchilton.blend4j.galaxy.beans.LibraryContent)2 UploadException (ca.corefacility.bioinformatics.irida.exceptions.UploadException)1 LibrariesClient (com.github.jmchilton.blend4j.galaxy.LibrariesClient)1 GalaxyObject (com.github.jmchilton.blend4j.galaxy.beans.GalaxyObject)1 File (java.io.File)1 List (java.util.List)1