Skip to content

Commit

Permalink
[GLT-4129] added tests for Jackson serial/deserialization (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
djcooke committed May 3, 2024
1 parent 7fa3091 commit 15d7961
Show file tree
Hide file tree
Showing 11 changed files with 878 additions and 32 deletions.
17 changes: 14 additions & 3 deletions cardea-data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- explicitly control property locations, so local config is never included -->
<argLine>-Dspring.config.location=classpath:/application.yml,classpath:/application-noauth.yml,classpath:/application-test.properties</argLine>
<argLine>
-Dspring.config.location=classpath:/application.yml,classpath:/application-noauth.yml,classpath:/application-test.properties</argLine>
</configuration>
<groupId>org.apache.maven.plugins</groupId>
</plugin>
Expand All @@ -42,9 +43,19 @@
<dependency>
<artifactId>javax.annotation-api</artifactId>
<groupId>javax.annotation</groupId>
<!-- <scope>provided</scope>-->
<version>1.3.2</version>
</dependency>

<dependency>
<artifactId>spring-boot-starter-json</artifactId>
<groupId>org.springframework.boot</groupId>
<scope>test</scope>
</dependency>
<dependency>
<artifactId>spring-boot-starter-test</artifactId>
<groupId>org.springframework.boot</groupId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Assay {
private final String version;
private final AssayTargets targets;

public Assay(Builder builder) {
private Assay(Builder builder) {
this.id = requireNonNull(builder.id);
this.name = requireNonNull(builder.name);
this.description = builder.description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.LocalDate;
import java.util.List;
import java.util.Set;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

@JsonDeserialize(as = CaseImpl.class)
Expand Down Expand Up @@ -52,6 +53,7 @@ public interface Case {

int getPauseDays();

@JsonIgnore
boolean isStopped();

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ private CaseDeliverableImpl(Builder builder) {
this.releaseApprovalDaysSpent = builder.releaseApprovalDaysSpent;
this.releaseDaysSpent = builder.releaseDaysSpent;
this.deliverableDaysSpent = builder.deliverableDaysSpent;
this.latestActivityDate = Stream
.concat(
releases == null ? Stream.empty() : releases.stream().map(CaseRelease::getQcDate),
Stream.of(analysisReviewQcDate, releaseApprovalQcDate))
.filter(Objects::nonNull)
.max(LocalDate::compareTo)
.orElse(null);

if (builder.latestActivityDate != null) {
this.latestActivityDate = builder.latestActivityDate;
} else {
this.latestActivityDate = Stream
.concat(
releases == null ? Stream.empty() : releases.stream().map(CaseRelease::getQcDate),
Stream.of(analysisReviewQcDate, releaseApprovalQcDate))
.filter(Objects::nonNull)
.max(LocalDate::compareTo)
.orElse(null);
}
}

@Override
Expand Down Expand Up @@ -146,6 +151,7 @@ public static class Builder {
private int releaseApprovalDaysSpent;
private int releaseDaysSpent;
private int deliverableDaysSpent;
private LocalDate latestActivityDate;

public Builder deliverableType(DeliverableType deliverableType) {
this.deliverableType = deliverableType;
Expand Down Expand Up @@ -217,6 +223,11 @@ public Builder deliverableDaysSpent(int deliverableDaysSpent) {
return this;
}

public Builder latestActivityDate(LocalDate latestActivityDate) {
this.latestActivityDate = latestActivityDate;
return this;
}

public CaseDeliverableImpl build() {
return new CaseDeliverableImpl(this);
}
Expand Down
26 changes: 18 additions & 8 deletions cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/CaseImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,18 @@ private CaseImpl(Builder builder) {
this.requisition = requireNonNull(builder.requisition);
this.startDate = requireNonNull(builder.startDate);

this.latestActivityDate = Stream
.concat(Stream.of(receipts.stream().map(Sample::getLatestActivityDate),
tests.stream().map(Test::getLatestActivityDate))
.flatMap(Function.identity()),
deliverables == null ? Stream.empty()
: deliverables.stream().map(CaseDeliverable::getLatestActivityDate))
.filter(Objects::nonNull).max(LocalDate::compareTo)
.orElse(null);
if (builder.latestActivityDate != null) {
this.latestActivityDate = builder.latestActivityDate;
} else {
this.latestActivityDate = Stream
.concat(Stream.of(receipts.stream().map(Sample::getLatestActivityDate),
tests.stream().map(Test::getLatestActivityDate))
.flatMap(Function.identity()),
deliverables == null ? Stream.empty()
: deliverables.stream().map(CaseDeliverable::getLatestActivityDate))
.filter(Objects::nonNull).max(LocalDate::compareTo)
.orElse(null);
}
this.receiptDaysSpent = builder.receiptDaysSpent;
this.analysisReviewDaysSpent = builder.analysisReviewDaysSpent;
this.releaseApprovalDaysSpent = builder.releaseApprovalDaysSpent;
Expand Down Expand Up @@ -219,6 +223,7 @@ public static class Builder {
private int releaseDaysSpent;
private int caseDaysSpent;
private int pauseDays;
private LocalDate latestActivityDate;

public Case build() {
return new CaseImpl(this);
Expand Down Expand Up @@ -328,5 +333,10 @@ public Builder pauseDays(int days) {
this.pauseDays = days;
return this;
}

public Builder latestActivityDate(LocalDate latestActivityDate) {
this.latestActivityDate = latestActivityDate;
return this;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package ca.on.oicr.gsi.cardea.data;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

public enum CaseStatus {
ACTIVE, COMPLETED, STOPPED;

@JsonValue
public String getLabel() {
return name().toLowerCase();
}
}

@JsonCreator
public static CaseStatus fromString(String string) {
return string == null ? null : CaseStatus.valueOf(string.toUpperCase());
}
}
14 changes: 12 additions & 2 deletions cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Sample.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ private Sample(Builder builder) {
this.dataReviewUser = builder.dataReviewUser;
this.dataReviewDate = builder.dataReviewDate;
this.sequencingLane = builder.sequencingLane;
this.latestActivityDate = Stream.of(createdDate, qcDate, dataReviewDate)
.filter(Objects::nonNull).max(LocalDate::compareTo).orElseThrow();
if (builder.latestActivityDate != null) {
this.latestActivityDate = builder.latestActivityDate;
} else {
this.latestActivityDate = Stream.of(createdDate, qcDate, dataReviewDate)
.filter(Objects::nonNull).max(LocalDate::compareTo).orElseThrow();
}
}

@Override
Expand Down Expand Up @@ -393,6 +397,7 @@ public static class Builder {
private BigDecimal relativeCpgInRegions;
private BigDecimal methylationBeta;
private Integer peReads;
private LocalDate latestActivityDate;

public Sample build() {
return new Sample(this);
Expand Down Expand Up @@ -652,5 +657,10 @@ public Builder peReads(Integer peReads) {
return this;
}

public Builder latestActivityDate(LocalDate latestActivityDate) {
this.latestActivityDate = latestActivityDate;
return this;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@

import java.util.Optional;
import java.util.Set;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

/**
* Immutable ShesmuCase
*/
@JsonDeserialize(builder = ShesmuCase.Builder.class)
public class ShesmuCase {

private final String assayName;
private final String assayVersion;
private final String caseIdentifier;
private final String caseStatus;
private final CaseStatus caseStatus;
private final Optional<Instant> completedDate;
private final Set<String> limsIds;
private final long requisitionId;
Expand All @@ -30,7 +33,7 @@ private ShesmuCase(Builder builder) {
this.assayName = requireNonNull(builder.assayName);
this.assayVersion = requireNonNull(builder.assayVersion);
this.caseIdentifier = requireNonNull(builder.caseIdentifier);
this.caseStatus = requireNonNull(builder.caseStatus.getLabel());
this.caseStatus = requireNonNull(builder.caseStatus);
this.completedDate = builder.completedDate;
this.limsIds = unmodifiableSet(requireNonNull(builder.limsIds));
this.requisitionId = requireNonNull(builder.requisitionId);
Expand All @@ -49,7 +52,7 @@ public String getCaseIdentifier() {
return caseIdentifier;
}

public String getCaseStatus() {
public CaseStatus getCaseStatus() {
return caseStatus;
}

Expand All @@ -69,6 +72,7 @@ public String getRequisitionName() {
return requisitionName;
}

@JsonPOJOBuilder(withPrefix = "")
public static class Builder {

private String assayName;
Expand Down Expand Up @@ -104,7 +108,12 @@ public Builder caseIdentifier(String caseIdentifier) {
return this;
}

public Builder completedDate(LocalDate completedDate) {
public Builder completedDate(Instant completedDate) {
this.completedDate = completedDate == null ? Optional.empty() : Optional.of(completedDate);
return this;
}

public Builder completedDateLocal(LocalDate completedDate) {
this.completedDate = convertCompletedDate(completedDate);
return this;
}
Expand Down
22 changes: 17 additions & 5 deletions cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,17 @@ private Test(Builder builder) {
: unmodifiableList(builder.libraryQualifications);
this.fullDepthSequencings = builder.fullDepthSequencings == null ? emptyList()
: unmodifiableList(builder.fullDepthSequencings);
this.latestActivityDate = Stream
.of(extractions.stream(), libraryPreparations.stream(), libraryQualifications.stream(),
fullDepthSequencings.stream())
.flatMap(Function.identity()).map(Sample::getLatestActivityDate).max(LocalDate::compareTo)
.orElse(null);

if (builder.latestActivityDate != null) {
this.latestActivityDate = builder.latestActivityDate;
} else {
this.latestActivityDate = Stream
.of(extractions.stream(), libraryPreparations.stream(), libraryQualifications.stream(),
fullDepthSequencings.stream())
.flatMap(Function.identity()).map(Sample::getLatestActivityDate).max(LocalDate::compareTo)
.orElse(null);
}

this.extractionDaysSpent = builder.extractionDaysSpent;
this.libraryPreparationDaysSpent = builder.libraryPreparationDaysSpent;
this.libraryQualificationDaysSpent = builder.libraryQualificationDaysSpent;
Expand Down Expand Up @@ -164,6 +170,7 @@ public static class Builder {
private int libraryPreparationDaysSpent;
private int libraryQualificationDaysSpent;
private int fullDepthSequencingDaysSpent;
private LocalDate latestActivityDate;

public Test build() {
return new Test(this);
Expand Down Expand Up @@ -258,5 +265,10 @@ public Builder fullDepthSequencingDaysSpent(int days) {
this.fullDepthSequencingDaysSpent = days;
return this;
}

public Builder latestActivityDate(LocalDate latestActivityDate) {
this.latestActivityDate = latestActivityDate;
return this;
}
}
}
Loading

0 comments on commit 15d7961

Please sign in to comment.