Skip to content

Commit

Permalink
Merge pull request #1484 from apetkau/fix/sync-old-irida
Browse files Browse the repository at this point in the history
hotfix/sync old irida
  • Loading branch information
ericenns authored Apr 17, 2023
2 parents 93b7cfd + 946aef3 commit 3719474
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [UI]: Fixed bug that caused all metadata fields to be removed when single field was removed from a template. See [PR 1482](https://github.com/phac-nml/irida/pull/1482)
* [Developer]: Fixed bug which allowed duplicated entries in the user_group_project table which prevented the user group from being removed. Fixed bug which was preventing analyses with `html` file outputs from completing. See [PR 1483](https://github.com/phac-nml/irida/pull/1483)
* [Developer]: Fixed flaky PipelinesPhylogenomicsPageIT test. See [PR 1482](https://github.com/phac-nml/irida/pull/1482)
* [REST]: Fixed issues with syncing between newer IRIDA (>22.09) and older IRIDA (<=20.09) by disabling requests for `application/xml` for some of the REST requests and only requesting data as `application/json`. See [PR 1484](https://github.com/phac-nml/irida/pull/1484).


## [23.01.1] - 2023/03/21
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ca.corefacility.bioinformatics.irida.repositories.remote.impl;

import com.google.common.collect.ImmutableList;
import ca.corefacility.bioinformatics.irida.exceptions.LinkNotFoundException;
import ca.corefacility.bioinformatics.irida.model.RemoteAPI;
import ca.corefacility.bioinformatics.irida.model.project.Project;
Expand All @@ -11,10 +12,12 @@
import ca.corefacility.bioinformatics.irida.service.user.UserService;
import ca.corefacility.bioinformatics.irida.web.assembler.resource.ProjectHashResource;
import ca.corefacility.bioinformatics.irida.web.controller.api.projects.RESTProjectsController;
import org.springframework.http.MediaType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Repository;
Expand Down Expand Up @@ -64,8 +67,12 @@ public Integer readProjectHash(Project project) {
OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);
Link link = project.getLink(HASH_REL).map(i -> i).orElse(null);

HttpHeaders headers = new HttpHeaders();
headers.setAccept(ImmutableList.of(MediaType.APPLICATION_JSON));
HttpEntity<Object> request = new HttpEntity<Object>(headers);

ResponseEntity<ResourceWrapper<ProjectHashResource>> exchange = restTemplate.exchange(link.getHref(),
HttpMethod.GET, HttpEntity.EMPTY, projectHashReference);
HttpMethod.GET, request, projectHashReference);

Integer projectHash = exchange.getBody().getResource().getProjectHash();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import java.util.List;

import com.google.common.collect.ImmutableList;
import org.springframework.http.MediaType;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
Expand Down Expand Up @@ -64,7 +67,12 @@ public RemoteRepositoryImpl(RemoteAPITokenService tokenService, UserService user
@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,

HttpHeaders headers = new HttpHeaders();
headers.setAccept(ImmutableList.of(MediaType.APPLICATION_JSON));
HttpEntity<Object> request = new HttpEntity<Object>(headers);

ResponseEntity<ResourceWrapper<Type>> exchange = restTemplate.exchange(uri, HttpMethod.GET, request,
objectTypeReference);

Type resource = exchange.getBody().getResource();
Expand All @@ -79,8 +87,13 @@ public Type read(String uri, RemoteAPI remoteAPI) {
@Override
public List<Type> list(String uri, RemoteAPI remoteAPI) {
OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);

HttpHeaders headers = new HttpHeaders();
headers.setAccept(ImmutableList.of(MediaType.APPLICATION_JSON));
HttpEntity<Object> request = new HttpEntity<Object>(headers);

ResponseEntity<ListResourceWrapper<Type>> exchange = restTemplate.exchange(uri, HttpMethod.GET,
HttpEntity.EMPTY, listTypeReference);
request, listTypeReference);

List<Type> resources = exchange.getBody().getResource().getResources();
for (Type r : resources) {
Expand All @@ -95,7 +108,12 @@ public List<Type> list(String uri, RemoteAPI remoteAPI) {
@Override
public boolean getServiceStatus(RemoteAPI remoteAPI) {
OAuthTokenRestTemplate restTemplate = new OAuthTokenRestTemplate(tokenService, remoteAPI);
ResponseEntity<String> forEntity = restTemplate.getForEntity(remoteAPI.getServiceURI(), String.class);

HttpHeaders headers = new HttpHeaders();
headers.setAccept(ImmutableList.of(MediaType.APPLICATION_JSON));
HttpEntity<Object> request = new HttpEntity<Object>(headers);

ResponseEntity<String> forEntity = restTemplate.exchange(remoteAPI.getServiceURI(), HttpMethod.GET, request, String.class);

return forEntity.getStatusCode() == HttpStatus.OK;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import java.util.List;
import java.util.Map;

import com.google.common.collect.ImmutableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.hateoas.Link;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Repository;
Expand Down Expand Up @@ -74,9 +77,13 @@ public Map<String, MetadataEntry> getSampleMetadata(Sample sample) {
// get the metadata link
Link metadataLink = sample.getLink(METADATA_REL).map(i -> i).orElse(null);

HttpHeaders headers = new HttpHeaders();
headers.setAccept(ImmutableList.of(MediaType.APPLICATION_JSON));
HttpEntity<Object> request = new HttpEntity<Object>(headers);

// request metadata response
ResponseEntity<ResourceWrapper<SampleMetadataWrapper>> exchange = restTemplate.exchange(metadataLink.getHref(),
HttpMethod.GET, HttpEntity.EMPTY, metadataTypeReference);
HttpMethod.GET, request, metadataTypeReference);

// pull metadata response from request
Map<String, MetadataEntry> resource = exchange.getBody().getResource().getMetadata();
Expand Down

0 comments on commit 3719474

Please sign in to comment.