Search in sources :

Example 1 with GalaxyObject

use of com.github.jmchilton.blend4j.galaxy.beans.GalaxyObject 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

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