Search in sources :

Example 1 with FileUploadRequest

use of com.github.jmchilton.blend4j.galaxy.ToolsClient.FileUploadRequest in project irida by phac-nml.

the class GalaxyHistoriesService method fileToHistory.

/**
 * Uploads a file to a given history.
 * @param path  The path to the file to upload.
 * @param fileType The file type of the file to upload.
 * @param history  The history to upload the file into.
 * @return A Dataset object for the uploaded file.
 * @throws UploadException  If there was an issue uploading the file to Galaxy.
 * @throws GalaxyDatasetException  If there was an issue finding the corresponding Dataset for the file
 * 	in the history.
 */
public Dataset fileToHistory(Path path, InputFileType fileType, History history) throws UploadException, GalaxyDatasetException {
    checkNotNull(path, "path is null");
    checkNotNull(fileType, "fileType is null");
    checkNotNull(history, "history is null");
    checkNotNull(history.getId(), "history id is null");
    checkState(path.toFile().exists(), "path " + path + " does not exist");
    File file = path.toFile();
    FileUploadRequest uploadRequest = new FileUploadRequest(history.getId(), file);
    uploadRequest.setFileType(fileType.toString());
    ClientResponse clientResponse = toolsClient.uploadRequest(uploadRequest);
    if (clientResponse == null) {
        throw new UploadException("Could not upload " + file + " to history " + history.getId() + " ClientResponse is null");
    } else if (!ClientResponse.Status.OK.equals(clientResponse.getClientResponseStatus())) {
        String message = "Could not upload " + file + " to history " + history.getId() + " ClientResponse: " + clientResponse.getClientResponseStatus() + " " + clientResponse.getEntity(String.class);
        logger.error(message);
        throw new UploadException(message);
    } else {
        return getDatasetForFileInHistory(file.getName(), history.getId());
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FileUploadRequest(com.github.jmchilton.blend4j.galaxy.ToolsClient.FileUploadRequest) UploadException(ca.corefacility.bioinformatics.irida.exceptions.UploadException) File(java.io.File)

Example 2 with FileUploadRequest

use of com.github.jmchilton.blend4j.galaxy.ToolsClient.FileUploadRequest in project irida by phac-nml.

the class GalaxyWorkflowsIT method fileToHistory.

private Dataset fileToHistory(Path path, String fileType, String historyId) throws GalaxyDatasetException {
    FileUploadRequest uploadRequest = new FileUploadRequest(historyId, path.toFile());
    uploadRequest.setFileType(fileType.toString());
    toolsClient.uploadRequest(uploadRequest);
    return galaxyHistory.getDatasetForFileInHistory(path.toFile().getName(), historyId);
}
Also used : FileUploadRequest(com.github.jmchilton.blend4j.galaxy.ToolsClient.FileUploadRequest)

Aggregations

FileUploadRequest (com.github.jmchilton.blend4j.galaxy.ToolsClient.FileUploadRequest)2 UploadException (ca.corefacility.bioinformatics.irida.exceptions.UploadException)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 File (java.io.File)1