From 8393d34e3cde2c800da6c7ce7d145571fc60e95d Mon Sep 17 00:00:00 2001 From: Aryan Gandevia Date: Tue, 1 Aug 2023 15:19:25 -0400 Subject: [PATCH 1/6] [GLT-3978] Allowing Jackson to parse JSON data into these models using Builder notation. --- .../java/ca/on/oicr/gsi/cardea/data/Assay.java | 11 ++++++++--- .../java/ca/on/oicr/gsi/cardea/data/Case.java | 4 ++++ .../java/ca/on/oicr/gsi/cardea/data/Donor.java | 4 ++++ .../java/ca/on/oicr/gsi/cardea/data/Lane.java | 4 ++++ .../java/ca/on/oicr/gsi/cardea/data/Metric.java | 4 ++++ .../oicr/gsi/cardea/data/MetricSubcategory.java | 4 ++++ .../on/oicr/gsi/cardea/data/OmittedSample.java | 4 ++++ .../ca/on/oicr/gsi/cardea/data/Project.java | 4 ++++ .../ca/on/oicr/gsi/cardea/data/Requisition.java | 17 ++++++++++++----- .../on/oicr/gsi/cardea/data/RequisitionQc.java | 4 ++++ .../gsi/cardea/data/RequisitionQcGroup.java | 4 ++++ .../java/ca/on/oicr/gsi/cardea/data/Run.java | 4 ++++ .../oicr/gsi/cardea/data/RunAndLibraries.java | 4 ++++ .../java/ca/on/oicr/gsi/cardea/data/Sample.java | 4 ++++ .../java/ca/on/oicr/gsi/cardea/data/Test.java | 4 ++++ 15 files changed, 72 insertions(+), 8 deletions(-) diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Assay.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Assay.java index 5d92cd0..bbccb25 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Assay.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Assay.java @@ -5,10 +5,13 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; /** * Immutable Assay */ +@JsonDeserialize(builder = Assay.Builder.class) public class Assay { private final String description; @@ -22,9 +25,10 @@ public Assay(Builder builder) { this.name = requireNonNull(builder.name); this.description = builder.description; this.version = requireNonNull(builder.version); - Map> tempMap = builder.metricCategories.entrySet().stream() - .collect(Collectors.toMap(entry -> entry.getKey(), - entry -> Collections.unmodifiableList(entry.getValue()))); + Map> tempMap = + builder.metricCategories.entrySet().stream() + .collect(Collectors.toMap(entry -> entry.getKey(), + entry -> Collections.unmodifiableList(entry.getValue()))); this.metricCategories = Collections.unmodifiableMap(tempMap); } @@ -48,6 +52,7 @@ public String getVersion() { return version; } + @JsonPOJOBuilder(withPrefix = "") public static class Builder { private String description; diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Case.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Case.java index 7207a7a..dbfa10d 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Case.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Case.java @@ -12,10 +12,13 @@ import java.util.stream.Stream; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; /** * Immutable case */ +@JsonDeserialize(builder = Case.Builder.class) public class Case { private final Assay assay; @@ -114,6 +117,7 @@ public boolean isStopped() { return requisition.isStopped(); } + @JsonPOJOBuilder(withPrefix = "") public static class Builder { private Assay assay; diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Donor.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Donor.java index dc38b84..8d2de08 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Donor.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Donor.java @@ -1,10 +1,13 @@ package ca.on.oicr.gsi.cardea.data; import static java.util.Objects.requireNonNull; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; /** * Immutable Donor */ +@JsonDeserialize(builder = Donor.Builder.class) public class Donor { private final String externalName; @@ -29,6 +32,7 @@ public String getName() { return name; } + @JsonPOJOBuilder(withPrefix = "") public static class Builder { private String externalName; diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Lane.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Lane.java index de4bb7f..1cc8b04 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Lane.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Lane.java @@ -2,10 +2,13 @@ import java.math.BigDecimal; import java.util.Objects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; /** * Immutable Lane */ +@JsonDeserialize(builder = Lane.Builder.class) public class Lane { private final Long clustersPf; @@ -48,6 +51,7 @@ public BigDecimal getPercentPfixRead2() { return percentPfixRead2; } + @JsonPOJOBuilder(withPrefix = "") public static class Builder { private Long clustersPf; diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Metric.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Metric.java index f4aedd3..e71582e 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Metric.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Metric.java @@ -3,10 +3,13 @@ import static java.util.Objects.requireNonNull; import java.math.BigDecimal; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; /** * Immutable Metric */ +@JsonDeserialize(builder = Metric.Builder.class) public class Metric { private final String containerModel; @@ -97,6 +100,7 @@ public boolean isNegateTissueType() { return negateTissueType; } + @JsonPOJOBuilder(withPrefix = "") public static class Builder { private String containerModel; diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/MetricSubcategory.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/MetricSubcategory.java index cecc8b5..e6c068e 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/MetricSubcategory.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/MetricSubcategory.java @@ -2,10 +2,13 @@ import java.util.Collections; import java.util.List; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; /** * Immutable MetricSubcategory */ +@JsonDeserialize(builder = MetricSubcategory.Builder.class) public class MetricSubcategory { private final String libraryDesignCode; @@ -36,6 +39,7 @@ public Integer getSortPriority() { return sortPriority; } + @JsonPOJOBuilder(withPrefix = "") public static class Builder { private String libraryDesignCode; diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/OmittedSample.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/OmittedSample.java index d3aabeb..c963536 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/OmittedSample.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/OmittedSample.java @@ -3,10 +3,13 @@ import static java.util.Objects.requireNonNull; import java.time.LocalDate; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; /** * Immutable OmittedSample */ +@JsonDeserialize(builder = OmittedSample.Builder.class) public class OmittedSample { private final Long assayId; @@ -61,6 +64,7 @@ public String getRequisitionName() { return requisitionName; } + @JsonPOJOBuilder(withPrefix = "") public static class Builder { private LocalDate createdDate; diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Project.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Project.java index f1ab3e6..f46ba05 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Project.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Project.java @@ -1,10 +1,13 @@ package ca.on.oicr.gsi.cardea.data; import static java.util.Objects.requireNonNull; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; /** * Immutable Project */ +@JsonDeserialize(builder = Project.Builder.class) public class Project { private final String name; @@ -23,6 +26,7 @@ public String getPipeline() { return pipeline; } + @JsonPOJOBuilder(withPrefix = "") public static class Builder { private String name; diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Requisition.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Requisition.java index 7a884e2..3ea93ef 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Requisition.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Requisition.java @@ -9,10 +9,13 @@ import java.util.Objects; import java.util.function.Function; import java.util.stream.Stream; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; /** * Immutable Requisition */ +@JsonDeserialize(builder = Requisition.Builder.class) public class Requisition { private final Long assayId; @@ -35,11 +38,14 @@ private Requisition(Builder builder) { this.qcGroups = builder.qcGroups == null ? emptyList() : unmodifiableList(builder.qcGroups); this.informaticsReviews = builder.informaticsReviews == null ? emptyList() : unmodifiableList(builder.informaticsReviews); - this.draftReports = builder.draftReports == null ? emptyList() : unmodifiableList(builder.draftReports); - this.finalReports = builder.finalReports == null ? emptyList() : unmodifiableList(builder.finalReports); - this.latestActivityDate = Stream.of(informaticsReviews.stream(), draftReports.stream(), finalReports.stream()) - .flatMap(Function.identity()).map(RequisitionQc::getQcDate).max(LocalDate::compareTo) - .orElse(null); + this.draftReports = + builder.draftReports == null ? emptyList() : unmodifiableList(builder.draftReports); + this.finalReports = + builder.finalReports == null ? emptyList() : unmodifiableList(builder.finalReports); + this.latestActivityDate = + Stream.of(informaticsReviews.stream(), draftReports.stream(), finalReports.stream()) + .flatMap(Function.identity()).map(RequisitionQc::getQcDate).max(LocalDate::compareTo) + .orElse(null); } @Override @@ -99,6 +105,7 @@ public boolean isStopped() { return stopped; } + @JsonPOJOBuilder(withPrefix = "") public static class Builder { private Long assayId; diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/RequisitionQc.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/RequisitionQc.java index e8b09f6..64c5e98 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/RequisitionQc.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/RequisitionQc.java @@ -3,10 +3,13 @@ import static java.util.Objects.requireNonNull; import java.time.LocalDate; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; /** * Immutable RequisitionQc */ +@JsonDeserialize(builder = RequisitionQc.Builder.class) public class RequisitionQc { private final LocalDate qcDate; @@ -31,6 +34,7 @@ public boolean isQcPassed() { return qcPassed; } + @JsonPOJOBuilder(withPrefix = "") public static class Builder { private LocalDate qcDate; diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/RequisitionQcGroup.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/RequisitionQcGroup.java index 1349e72..c8bbf0d 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/RequisitionQcGroup.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/RequisitionQcGroup.java @@ -3,10 +3,13 @@ import static java.util.Objects.requireNonNull; import java.math.BigDecimal; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; /** * Immutable RequisitionQcGroup */ +@JsonDeserialize(builder = RequisitionQcGroup.Builder.class) public class RequisitionQcGroup { private final BigDecimal callability; @@ -61,6 +64,7 @@ public String getTissueType() { return tissueType; } + @JsonPOJOBuilder(withPrefix = "") public static class Builder { private BigDecimal callability; diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Run.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Run.java index 02b0cda..914e58e 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Run.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Run.java @@ -6,10 +6,13 @@ import java.util.Collections; import java.util.List; import java.util.Objects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; /** * Immutable Run */ +@JsonDeserialize(builder = Run.Builder.class) public class Run { private final Long clustersPf; @@ -138,6 +141,7 @@ public int hashCode() { return Objects.hash(id); } + @JsonPOJOBuilder(withPrefix = "") public static class Builder { private Long clustersPf; diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/RunAndLibraries.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/RunAndLibraries.java index a922f78..f2bba52 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/RunAndLibraries.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/RunAndLibraries.java @@ -5,10 +5,13 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; /** * Immutable RunAndLibraries */ +@JsonDeserialize(builder = RunAndLibraries.Builder.class) public class RunAndLibraries { private Set fullDepthSequencings; @@ -33,6 +36,7 @@ public Run getRun() { return run; } + @JsonPOJOBuilder(withPrefix = "") public static class Builder { private Set fullDepthSequencings = new HashSet<>(); diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Sample.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Sample.java index 94bcc5b..7950a4e 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Sample.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Sample.java @@ -5,10 +5,13 @@ import java.time.LocalDate; import java.util.Objects; import java.util.stream.Stream; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; /** * Immutable Sample */ +@JsonDeserialize(builder = Sample.Builder.class) public class Sample { private final Long assayId; @@ -317,6 +320,7 @@ public int hashCode() { return Objects.hash(id, run, sequencingLane); } + @JsonPOJOBuilder(withPrefix = "") public static class Builder { private Integer clustersPerSample; diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Test.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Test.java index 8661e65..8cc818e 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Test.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Test.java @@ -8,10 +8,13 @@ import java.util.List; import java.util.function.Function; import java.util.stream.Stream; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; /** * Immutable Test */ +@JsonDeserialize(builder = Test.Builder.class) public class Test { private final boolean extractionSkipped; @@ -110,6 +113,7 @@ public boolean isLibraryPreparationSkipped() { return libraryPreparationSkipped; } + @JsonPOJOBuilder(withPrefix = "") public static class Builder { private boolean extractionSkipped; From 02d11c17a6587ca185a8c0bed11495a3902e14b7 Mon Sep 17 00:00:00 2001 From: Aryan Gandevia Date: Tue, 1 Aug 2023 15:29:34 -0400 Subject: [PATCH 2/6] Added change file --- changes/add_GLT-3978.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/add_GLT-3978.md diff --git a/changes/add_GLT-3978.md b/changes/add_GLT-3978.md new file mode 100644 index 0000000..9176df3 --- /dev/null +++ b/changes/add_GLT-3978.md @@ -0,0 +1 @@ +capability for Jackson parsing Json strings into data models \ No newline at end of file From f8cb2d2e69fc89292bc586c4e2dc98c5744619ab Mon Sep 17 00:00:00 2001 From: Aryan Gandevia Date: Tue, 1 Aug 2023 15:33:08 -0400 Subject: [PATCH 3/6] added change file --- changes/add_GLT-3978.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changes/add_GLT-3978.md b/changes/add_GLT-3978.md index 9176df3..fb54132 100644 --- a/changes/add_GLT-3978.md +++ b/changes/add_GLT-3978.md @@ -1 +1 @@ -capability for Jackson parsing Json strings into data models \ No newline at end of file +capability for Jackson parsing for data models using Builder notation \ No newline at end of file From 2911ff1a549cdf4d0589e4686d38f39f214d0087 Mon Sep 17 00:00:00 2001 From: Aryan Gandevia Date: Thu, 3 Aug 2023 09:48:24 -0400 Subject: [PATCH 4/6] updated Case to work with WebClient in Dimsum --- .../java/ca/on/oicr/gsi/cardea/data/Case.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Case.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Case.java index dbfa10d..b10ff6f 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Case.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Case.java @@ -39,8 +39,12 @@ private Case(Builder builder) { this.id = requireNonNull(builder.id); this.donor = requireNonNull(builder.donor); this.projects = unmodifiableSet(builder.projects); - this.assay = requireNonNull(builder.assay); - this.assayId = this.assay.getId(); + this.assay = builder.assay; + if (this.assay != null) { + this.assayId = this.assay.getId(); + } else { + this.assayId = builder.assayId; + } this.tissueOrigin = requireNonNull(builder.tissueOrigin); this.tissueType = requireNonNull(builder.tissueType); this.timepoint = builder.timepoint; @@ -48,7 +52,8 @@ private Case(Builder builder) { this.tests = unmodifiableList(builder.tests); this.requisition = builder.requisition; this.startDate = builder.receipts.stream() - .filter(sample -> sample.getRequisitionId().longValue() == builder.requisition.getId()) + .filter(sample -> sample.getRequisitionId() != null + && sample.getRequisitionId().longValue() == builder.requisition.getId()) .map(Sample::getCreatedDate) .min(LocalDate::compareTo).orElse(null); this.latestActivityDate = Stream @@ -59,6 +64,7 @@ private Case(Builder builder) { .orElse(null); } + @JsonIgnore public Assay getAssay() { return assay; @@ -121,6 +127,7 @@ public boolean isStopped() { public static class Builder { private Assay assay; + private long assayId; private Donor donor; private String id; private Set projects; @@ -131,13 +138,18 @@ public static class Builder { private String tissueOrigin; private String tissueType; + public Case build() { + return new Case(this); + } + public Builder assay(Assay assay) { this.assay = assay; return this; } - public Case build() { - return new Case(this); + public Builder assayId(long assayId) { + this.assayId = assayId; + return this; } public Builder donor(Donor donor) { From 94cbf0a53fd53db4ea4821afd8885578d8f3c4a0 Mon Sep 17 00:00:00 2001 From: Aryan Gandevia Date: Wed, 9 Aug 2023 14:55:20 -0400 Subject: [PATCH 5/6] synced up Cases with Dimsum --- cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Case.java | 1 - 1 file changed, 1 deletion(-) diff --git a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Case.java b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Case.java index b10ff6f..074bb7b 100644 --- a/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Case.java +++ b/cardea-data/src/main/java/ca/on/oicr/gsi/cardea/data/Case.java @@ -64,7 +64,6 @@ private Case(Builder builder) { .orElse(null); } - @JsonIgnore public Assay getAssay() { return assay; From f814966fa60f99772e80f78ab9bf375a68bd6713 Mon Sep 17 00:00:00 2001 From: Aryan Gandevia Date: Wed, 9 Aug 2023 14:57:40 -0400 Subject: [PATCH 6/6] change message --- changes/add_GLT-3983.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/add_GLT-3983.md diff --git a/changes/add_GLT-3983.md b/changes/add_GLT-3983.md new file mode 100644 index 0000000..860c46b --- /dev/null +++ b/changes/add_GLT-3983.md @@ -0,0 +1 @@ +Case data model to match Dimsum \ No newline at end of file