Search in sources :

Example 1 with OAuthTokenRestTemplate

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

the class OAuthTokenRestTemplateTest method setUp.

@Before
public void setUp() throws URISyntaxException {
    tokenService = mock(RemoteAPITokenService.class);
    serviceURI = new URI("http://uri");
    remoteAPI = new RemoteAPI("service name", serviceURI.toString(), "a service", "clientId", "clientSecret");
    restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) URI(java.net.URI) RemoteAPITokenService(ca.corefacility.bioinformatics.irida.service.RemoteAPITokenService) OAuthTokenRestTemplate(ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.OAuthTokenRestTemplate) Before(org.junit.Before)

Example 2 with OAuthTokenRestTemplate

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

the class RemoteRepositoryImpl method getServiceStatus.

/**
 * {@inheritDoc}
 */
@Override
public boolean getServiceStatus(RemoteAPI remoteAPI) {
    OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);
    ResponseEntity<String> forEntity = restTemplate.getForEntity(remoteAPI.getServiceURI(), String.class);
    return forEntity.getStatusCode() == HttpStatus.OK;
}
Also used : OAuthTokenRestTemplate(ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.OAuthTokenRestTemplate)

Example 3 with OAuthTokenRestTemplate

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

the class RemoteRepositoryImpl method list.

/**
 * {@inheritDoc}
 */
@Override
public List<Type> list(String uri, RemoteAPI remoteAPI) {
    OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);
    ResponseEntity<ListResourceWrapper<Type>> exchange = restTemplate.exchange(uri, HttpMethod.GET, HttpEntity.EMPTY, listTypeReference);
    List<Type> resources = exchange.getBody().getResource().getResources();
    for (Type r : resources) {
        r = setRemoteStatus(r, remoteAPI);
    }
    return resources;
}
Also used : ListResourceWrapper(ca.corefacility.bioinformatics.irida.model.remote.resource.ListResourceWrapper) OAuthTokenRestTemplate(ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.OAuthTokenRestTemplate)

Example 4 with OAuthTokenRestTemplate

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

the class RemoteRepositoryImpl method read.

/**
 * {@inheritDoc}
 */
@Override
public Type read(String uri, RemoteAPI remoteAPI) {
    OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);
    ResponseEntity<ResourceWrapper<Type>> exchange = restTemplate.exchange(uri, HttpMethod.GET, HttpEntity.EMPTY, objectTypeReference);
    Type resource = exchange.getBody().getResource();
    resource = setRemoteStatus(resource, remoteAPI);
    return resource;
}
Also used : ResourceWrapper(ca.corefacility.bioinformatics.irida.model.remote.resource.ResourceWrapper) ListResourceWrapper(ca.corefacility.bioinformatics.irida.model.remote.resource.ListResourceWrapper) OAuthTokenRestTemplate(ca.corefacility.bioinformatics.irida.repositories.remote.resttemplate.OAuthTokenRestTemplate)

Example 5 with OAuthTokenRestTemplate

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

the class SampleRemoteRepositoryImpl method getSampleMetadata.

/**
 * {@inheritDoc}
 */
public Map<String, MetadataEntry> getSampleMetadata(Sample sample) {
    logger.trace("Requesting sample metadata for sample " + sample.getSelfHref());
    RemoteAPI remoteAPI = sample.getRemoteStatus().getApi();
    OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);
    // get the metadata link
    Link metadataLink = sample.getLink(METADATA_REL);
    // request metadata response
    ResponseEntity<ResourceWrapper<SampleMetadataWrapper>> exchange = restTemplate.exchange(metadataLink.getHref(), HttpMethod.GET, HttpEntity.EMPTY, metadataTypeReference);
    // pull metadata response from request
    Map<String, MetadataEntry> resource = exchange.getBody().getResource().getMetadata();
    return resource;
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) ResourceWrapper(ca.corefacility.bioinformatics.irida.model.remote.resource.ResourceWrapper) ListResourceWrapper(ca.corefacility.bioinformatics.irida.model.remote.resource.ListResourceWrapper) MetadataEntry(ca.corefacility.bioinformatics.irida.model.sample.metadata.MetadataEntry) Link(org.springframework.hateoas.Link) 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