From 380d87f67e480bd9ad3b76549e8d68441171344a Mon Sep 17 00:00:00 2001 From: Christian Gendreau Date: Wed, 27 Nov 2024 08:36:54 -0500 Subject: [PATCH] Added PcrBatchItem rel to MetagenomicsBatchItem --- .../api/dto/MetagenomicsBatchItemDto.java | 4 ++++ .../api/entities/MetagenomicsBatchItem.java | 5 +++++ .../migrations/54-Add_metagenomics_tables.xml | 4 ++++ .../api/repository/MetagenomicsBatchIT.java | 22 ++++++++++++++++--- .../MetagenomicsBatchItemTestFixture.java | 7 ++++++ .../fixtures/PcrBatchItemTestFixture.java | 7 ++++++ 6 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/main/java/ca/gc/aafc/seqdb/api/dto/MetagenomicsBatchItemDto.java b/src/main/java/ca/gc/aafc/seqdb/api/dto/MetagenomicsBatchItemDto.java index 0cb4d961..4a1d9700 100644 --- a/src/main/java/ca/gc/aafc/seqdb/api/dto/MetagenomicsBatchItemDto.java +++ b/src/main/java/ca/gc/aafc/seqdb/api/dto/MetagenomicsBatchItemDto.java @@ -1,6 +1,7 @@ package ca.gc.aafc.seqdb.api.dto; import ca.gc.aafc.dina.dto.RelatedEntity; +import ca.gc.aafc.seqdb.api.dto.pcr.PcrBatchItemDto; import ca.gc.aafc.seqdb.api.entities.MetagenomicsBatchItem; import io.crnk.core.resource.annotations.JsonApiId; @@ -33,6 +34,9 @@ public class MetagenomicsBatchItemDto { @JsonApiRelation private MetagenomicsBatchDto metagenomicsBatch; + @JsonApiRelation + private PcrBatchItemDto pcrBatchItem; + @JsonApiRelation private NgsIndexDto indexI5; diff --git a/src/main/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatchItem.java b/src/main/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatchItem.java index b49c997a..abf047a3 100644 --- a/src/main/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatchItem.java +++ b/src/main/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatchItem.java @@ -6,6 +6,7 @@ import ca.gc.aafc.dina.entity.DinaEntity; import ca.gc.aafc.seqdb.api.entities.libraryprep.NgsIndex; +import ca.gc.aafc.seqdb.api.entities.pcr.PcrBatchItem; import java.time.OffsetDateTime; import java.util.UUID; @@ -56,6 +57,10 @@ public class MetagenomicsBatchItem implements DinaEntity { @JoinColumn(name = "metagenomics_batch_id") private MetagenomicsBatch metagenomicsBatch; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "pcr_batch_item_id") + private PcrBatchItem pcrBatchItem; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "indexi5_id") private NgsIndex indexI5; diff --git a/src/main/resources/db/changelog/migrations/54-Add_metagenomics_tables.xml b/src/main/resources/db/changelog/migrations/54-Add_metagenomics_tables.xml index ac068296..01993352 100644 --- a/src/main/resources/db/changelog/migrations/54-Add_metagenomics_tables.xml +++ b/src/main/resources/db/changelog/migrations/54-Add_metagenomics_tables.xml @@ -47,6 +47,10 @@ + + + + diff --git a/src/test/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchIT.java b/src/test/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchIT.java index bf3c5caf..dc580dff 100644 --- a/src/test/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchIT.java +++ b/src/test/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchIT.java @@ -4,8 +4,12 @@ import ca.gc.aafc.seqdb.api.dto.MetagenomicsBatchDto; import ca.gc.aafc.seqdb.api.dto.MetagenomicsBatchItemDto; +import ca.gc.aafc.seqdb.api.dto.pcr.PcrBatchDto; +import ca.gc.aafc.seqdb.api.dto.pcr.PcrBatchItemDto; import ca.gc.aafc.seqdb.api.testsupport.fixtures.MetagenomicsBatchItemTestFixture; import ca.gc.aafc.seqdb.api.testsupport.fixtures.MetagenomicsBatchTestFixture; +import ca.gc.aafc.seqdb.api.testsupport.fixtures.PcrBatchItemTestFixture; +import ca.gc.aafc.seqdb.api.testsupport.fixtures.PcrBatchTestFixture; import javax.inject.Inject; @@ -17,14 +21,26 @@ public class MetagenomicsBatchIT extends BaseRepositoryTestV2 { @Inject private MetagenomicsBatchItemRepository metagenomicsBatchItemRepository; + @Inject + private PcrBatchRepository pcrBatchRepository; + + @Inject + private PcrBatchItemRepository pcrBatchItemRepository; + @Test public void onValidDto_dtoSavedWithoutExceptions() { - MetagenomicsBatchDto genericMolecularAnalysisDto = metagenomicsBatchRepository + MetagenomicsBatchDto metagenomicsBatchDto = metagenomicsBatchRepository .create(MetagenomicsBatchTestFixture.newMetagenomicsBatch()); - MetagenomicsBatchItemDto itemDto = MetagenomicsBatchItemTestFixture.newMetagenomicsBatchItem(); - itemDto.setMetagenomicsBatch(genericMolecularAnalysisDto); + PcrBatchDto pcrBatchDto = PcrBatchTestFixture.newPcrBatch(); + pcrBatchDto = pcrBatchRepository.create(pcrBatchDto); + + PcrBatchItemDto pcrBatchItemDto = PcrBatchItemTestFixture.newPcrBatchItem(pcrBatchDto); + pcrBatchItemDto = pcrBatchItemRepository.create(pcrBatchItemDto); + + MetagenomicsBatchItemDto itemDto = MetagenomicsBatchItemTestFixture.newMetagenomicsBatchItem(metagenomicsBatchDto); + itemDto.setPcrBatchItem(pcrBatchItemDto); metagenomicsBatchItemRepository.create(itemDto); } diff --git a/src/test/java/ca/gc/aafc/seqdb/api/testsupport/fixtures/MetagenomicsBatchItemTestFixture.java b/src/test/java/ca/gc/aafc/seqdb/api/testsupport/fixtures/MetagenomicsBatchItemTestFixture.java index 2ac6b8f2..e4f4910e 100644 --- a/src/test/java/ca/gc/aafc/seqdb/api/testsupport/fixtures/MetagenomicsBatchItemTestFixture.java +++ b/src/test/java/ca/gc/aafc/seqdb/api/testsupport/fixtures/MetagenomicsBatchItemTestFixture.java @@ -1,9 +1,16 @@ package ca.gc.aafc.seqdb.api.testsupport.fixtures; +import ca.gc.aafc.seqdb.api.dto.MetagenomicsBatchDto; import ca.gc.aafc.seqdb.api.dto.MetagenomicsBatchItemDto; public class MetagenomicsBatchItemTestFixture { + public static MetagenomicsBatchItemDto newMetagenomicsBatchItem(MetagenomicsBatchDto batchDto) { + MetagenomicsBatchItemDto metagenomicsBatchItemDto = newMetagenomicsBatchItem(); + metagenomicsBatchItemDto.setMetagenomicsBatch(batchDto); + return metagenomicsBatchItemDto; + } + public static MetagenomicsBatchItemDto newMetagenomicsBatchItem() { return MetagenomicsBatchItemDto.builder() .createdBy("test-user") diff --git a/src/test/java/ca/gc/aafc/seqdb/api/testsupport/fixtures/PcrBatchItemTestFixture.java b/src/test/java/ca/gc/aafc/seqdb/api/testsupport/fixtures/PcrBatchItemTestFixture.java index eb6fcd99..f538f3a5 100644 --- a/src/test/java/ca/gc/aafc/seqdb/api/testsupport/fixtures/PcrBatchItemTestFixture.java +++ b/src/test/java/ca/gc/aafc/seqdb/api/testsupport/fixtures/PcrBatchItemTestFixture.java @@ -1,5 +1,6 @@ package ca.gc.aafc.seqdb.api.testsupport.fixtures; +import ca.gc.aafc.seqdb.api.dto.pcr.PcrBatchDto; import ca.gc.aafc.seqdb.api.dto.pcr.PcrBatchItemDto; public class PcrBatchItemTestFixture { @@ -8,6 +9,12 @@ public class PcrBatchItemTestFixture { public static final String CREATED_BY = "created_by"; public static final String RESULT = "Good Band"; + public static PcrBatchItemDto newPcrBatchItem(PcrBatchDto batch) { + PcrBatchItemDto pcrBatchItemDto = newPcrBatchItem(); + pcrBatchItemDto.setPcrBatch(batch); + return pcrBatchItemDto; + } + public static PcrBatchItemDto newPcrBatchItem() { PcrBatchItemDto pcrBatchItemDto = new PcrBatchItemDto(); pcrBatchItemDto.setGroup(GROUP);