Search in sources :

Example 6 with OAuthTokenRestTemplate

use of ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.OAuthTokenRestTemplate in project irida by phac-nml.

the class SequenceFileRemoteRepositoryImpl method downloadRemoteSequenceFile.

/**
 * {@inheritDoc}
 */
@Override
public Path downloadRemoteSequenceFile(String uri, RemoteAPI remoteAPI, MediaType... mediaTypes) {
    SequenceFile file = read(uri, remoteAPI);
    OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);
    // add the sequence file message converter
    List<HttpMessageConverter<?>> converters = restTemplate.getMessageConverters();
    converters.add(new SequenceFileMessageConverter(file.getFileName()));
    restTemplate.setMessageConverters(converters);
    // add the application/fastq accept header
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAccept(Arrays.asList(mediaTypes));
    HttpEntity<Path> requestEntity = new HttpEntity<Path>(requestHeaders);
    // get the file
    ResponseEntity<Path> exchange = restTemplate.exchange(uri, HttpMethod.GET, requestEntity, Path.class);
    return exchange.getBody();
}
Also used : SequenceFileMessageConverter(ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.SequenceFileMessageConverter) Path(java.nio.file.Path) HttpHeaders(org.springframework.http.HttpHeaders) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) HttpEntity(org.springframework.http.HttpEntity) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) OAuthTokenRestTemplate(ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.OAuthTokenRestTemplate)

Aggregations

OAuthTokenRestTemplate (ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.OAuthTokenRestTemplate)6 ListResourceWrapper (ca.corefacility.bioinformatics.irida.model.remote.resource.ListResourceWrapper)3 RemoteAPI (ca.corefacility.bioinformatics.irida.model.RemoteAPI)2 ResourceWrapper (ca.corefacility.bioinformatics.irida.model.remote.resource.ResourceWrapper)2 MetadataEntry (ca.corefacility.bioinformatics.irida.model.sample.metadata.MetadataEntry)1 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)1 SequenceFileMessageConverter (ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.SequenceFileMessageConverter)1 RemoteAPITokenService (ca.corefacility.bioinformatics.irida.service.RemoteAPITokenService)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 Before (org.junit.Before)1 Link (org.springframework.hateoas.Link)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)1