Skip to content

Commit

Permalink
Merge pull request #1208 from phac-nml/fix-sync-without-project-hash-rel
Browse files Browse the repository at this point in the history
hotfix: Fixed syncing remote projects from version 20.09 and older.
  • Loading branch information
deepsidhu85 committed Feb 24, 2022
2 parents 2bb2112 + 06b5bc5 commit 9d4c8cd
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 36 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 @@ Changes
--------------
* [REST]: Corrected behaviour of date fields in REST API to return epoch instead of textual string. (22.01.1)
* [Documentation]: Fixed issue that prevented a user from saving analysis results back to a sample and concatenating sequence files. Fixed date format in Swagger REST API documentation. (22.01.2)
* [REST]: Fixed bug that was preventing syncing remote projects from versions 20.09 and older. (22.01.3)

21.09 to 22.01
--------------
Expand Down
13 changes: 8 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.3</version>
<relativePath />
<relativePath/>
</parent>
<groupId>ca.corefacility.bioinformatics</groupId>
<artifactId>irida</artifactId>
<packaging>war</packaging>
<version>22.01.2</version>
<version>22.01.3</version>
<name>irida</name>
<url>http://www.irida.ca</url>

Expand Down Expand Up @@ -587,7 +588,8 @@
<!--suppress UnresolvedMavenProperty -->
<argLine>${failsafeArgLine}</argLine>
<systemPropertyVariables>
<junit.platform.execution.listeners.deactivate>${exclude.test.listeners}</junit.platform.execution.listeners.deactivate>
<junit.platform.execution.listeners.deactivate>${exclude.test.listeners}
</junit.platform.execution.listeners.deactivate>
<spring.profiles.active>test</spring.profiles.active>
<irida.db.profile>it</irida.db.profile>
</systemPropertyVariables>
Expand Down Expand Up @@ -939,7 +941,8 @@
<liquibase.config.url>jdbc:mysql://localhost:3306/irida_test</liquibase.config.url>
<liquibase.config.username>test</liquibase.config.username>
<liquibase.config.password>test</liquibase.config.password>
<liquibase.config.changeLogFile>ca/corefacility/bioinformatics/irida/database/all-changes.xml</liquibase.config.changeLogFile>
<liquibase.config.changeLogFile>ca/corefacility/bioinformatics/irida/database/all-changes.xml
</liquibase.config.changeLogFile>

<!-- URL to a pre-populated SQLite database for Galaxy -->
<!-- Set to 'local' to use the local version stored in irida-api, or set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
import ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus;

/**
* Adds a collection of {@link Link}s to extending objects. Similar to
* {@link RepresentationModel}
*
* @see RepresentationModel
* Adds a collection of {@link Link}s to extending objects. Similar to {@link RepresentationModel}
*
* @see RepresentationModel
*/
@JsonIgnoreProperties(ignoreUnknown = true, value = {"hibernateLazyInitializer"})
@JsonIgnoreProperties(ignoreUnknown = true, value = { "hibernateLazyInitializer" })
public class IridaRepresentationModel {
private final List<Link> links;

Expand All @@ -35,9 +33,8 @@ public IridaRepresentationModel() {

/**
* Adds the given link to the resource.
*
* @param link
* The link to add to the resource
*
* @param link The link to add to the resource
*/
public void add(Link link) {
Assert.notNull(link, "Link must not be null!");
Expand All @@ -46,9 +43,8 @@ public void add(Link link) {

/**
* Adds all given {@link Link}s to the resource.
*
* @param links
* The list of links to add to the resource
*
* @param links The list of links to add to the resource
*/
public void add(Iterable<Link> links) {
Assert.notNull(links, "Given links must not be null!");
Expand All @@ -59,7 +55,7 @@ public void add(Iterable<Link> links) {

/**
* Returns whether the resource contains {@link Link}s at all.
*
*
* @return true/false whether the resource contains the link
*/
public boolean hasLinks() {
Expand All @@ -68,18 +64,17 @@ public boolean hasLinks() {

/**
* Returns whether the resource contains a {@link Link} with the given rel.
*
* @param rel
* The rel name to test
*
* @param rel The rel name to test
* @return true/false if it has a link with the given rel
*/
public boolean hasLink(String rel) {
return getLink(rel) != null;
return getLink(rel).isPresent();
}

/**
* Returns all {@link Link}s contained in this resource.
*
*
* @return The list of links for this resource
*/
@XmlElement(name = "link", namespace = Link.ATOM_NAMESPACE)
Expand All @@ -97,9 +92,8 @@ public void removeLinks() {

/**
* Returns the link with the given rel.
*
* @param rel
* the String rel to get a link for
*
* @param rel the String rel to get a link for
* @return the link with the given rel or {@literal null} if none found.
*/
public Optional<Link> getLink(String rel) {
Expand Down Expand Up @@ -149,9 +143,8 @@ public int hashCode() {
}

/**
* Convenience method for getting the self rel href for an object read from
* a remote site
*
* Convenience method for getting the self rel href for an object read from a remote site
*
* @return String href if available, null otherwise
*/
@JsonIgnore
Expand All @@ -161,21 +154,18 @@ public String getSelfHref() {
}

/**
* Set the {@link RemoteStatus} for this object if it was read from a remote
* source
*
* @param status
* the {@link RemoteStatus} object
* Set the {@link RemoteStatus} for this object if it was read from a remote source
*
* @param status the {@link RemoteStatus} object
*/
// TODO: Make these abstract
public void setRemoteStatus(RemoteStatus status) {

}

/**
* Get the {@link RemoteStatus} for this object if it was read from a remote
* source
*
* Get the {@link RemoteStatus} for this object if it was read from a remote source
*
* @return a {@link RemoteStatus}
*/
@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ca.corefacility.bioinformatics.irida.repositories.remote.impl;

import java.util.Optional;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import ca.corefacility.bioinformatics.irida.exceptions.LinkNotFoundException;
import ca.corefacility.bioinformatics.irida.model.project.Project;
import ca.corefacility.bioinformatics.irida.repositories.remote.ProjectRemoteRepository;
import ca.corefacility.bioinformatics.irida.service.RemoteAPITokenService;
import ca.corefacility.bioinformatics.irida.web.controller.api.projects.RESTProjectsController;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ProjectRemoteRepositoryImplTest {

private ProjectRemoteRepository projectRemoteRepository;
private RemoteAPITokenService tokenService;
private static final String PROJECT_HASH_REL = RESTProjectsController.PROJECT_HASH_REL;

@BeforeEach
public void setUp() {
tokenService = mock(RemoteAPITokenService.class);
projectRemoteRepository = new ProjectRemoteRepositoryImpl(tokenService);
}

@Test
public void testReadProjectHashWithoutProjectHashRel() {
Project remoteProject = mock(Project.class);

when(remoteProject.getLink(PROJECT_HASH_REL)).thenReturn(Optional.empty());

assertThrows(LinkNotFoundException.class, () -> {
projectRemoteRepository.readProjectHash(remoteProject);
});
}
}

0 comments on commit 9d4c8cd

Please sign in to comment.