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 4a1d9700..f398075c 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 @@ -9,6 +9,9 @@ import io.crnk.core.resource.annotations.JsonApiResource; import java.time.OffsetDateTime; import java.util.UUID; + +import org.javers.core.metamodel.annotation.ShallowReference; + import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -37,6 +40,10 @@ public class MetagenomicsBatchItemDto { @JsonApiRelation private PcrBatchItemDto pcrBatchItem; + @ShallowReference + @JsonApiRelation + private MolecularAnalysisRunItemDto molecularAnalysisRunItem; + @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 abf047a3..f28fc972 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 @@ -61,6 +61,10 @@ public class MetagenomicsBatchItem implements DinaEntity { @JoinColumn(name = "pcr_batch_item_id") private PcrBatchItem pcrBatchItem; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "molecular_analysis_run_item_id") + private MolecularAnalysisRunItem molecularAnalysisRunItem; + @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 01993352..67d44fa1 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 @@ -1,9 +1,9 @@ + xmlns="http://www.liquibase.org/xml/ns/dbchangelog" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://local.xsd/dbchangelog-4.4.xsd" + objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS"> @@ -14,19 +14,20 @@ - + - + - + - + - + - + @@ -39,24 +40,31 @@ - + - + - + - + + + + - - + - + - + \ No newline at end of file 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 dc580dff..26f6d6e5 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,10 +4,16 @@ import ca.gc.aafc.seqdb.api.dto.MetagenomicsBatchDto; import ca.gc.aafc.seqdb.api.dto.MetagenomicsBatchItemDto; +import ca.gc.aafc.seqdb.api.dto.MolecularAnalysisResultDto; +import ca.gc.aafc.seqdb.api.dto.MolecularAnalysisRunDto; +import ca.gc.aafc.seqdb.api.dto.MolecularAnalysisRunItemDto; 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.MolecularAnalysisResultFixture; +import ca.gc.aafc.seqdb.api.testsupport.fixtures.MolecularAnalysisRunItemTestFixture; +import ca.gc.aafc.seqdb.api.testsupport.fixtures.MolecularAnalysisRunTestFixture; import ca.gc.aafc.seqdb.api.testsupport.fixtures.PcrBatchItemTestFixture; import ca.gc.aafc.seqdb.api.testsupport.fixtures.PcrBatchTestFixture; @@ -27,11 +33,20 @@ public class MetagenomicsBatchIT extends BaseRepositoryTestV2 { @Inject private PcrBatchItemRepository pcrBatchItemRepository; + @Inject + private MolecularAnalysisRunRepository molecularAnalysisRunRepository; + + @Inject + private MolecularAnalysisRunItemRepository molecularAnalysisRunItemRepository; + + @Inject + private MolecularAnalysisResultRepository molecularAnalysisResultRepository; + @Test public void onValidDto_dtoSavedWithoutExceptions() { MetagenomicsBatchDto metagenomicsBatchDto = metagenomicsBatchRepository - .create(MetagenomicsBatchTestFixture.newMetagenomicsBatch()); + .create(MetagenomicsBatchTestFixture.newMetagenomicsBatch()); PcrBatchDto pcrBatchDto = PcrBatchTestFixture.newPcrBatch(); pcrBatchDto = pcrBatchRepository.create(pcrBatchDto); @@ -39,8 +54,22 @@ public void onValidDto_dtoSavedWithoutExceptions() { PcrBatchItemDto pcrBatchItemDto = PcrBatchItemTestFixture.newPcrBatchItem(pcrBatchDto); pcrBatchItemDto = pcrBatchItemRepository.create(pcrBatchItemDto); + MolecularAnalysisRunDto runDto = molecularAnalysisRunRepository + .create(MolecularAnalysisRunTestFixture.newMolecularAnalysisRun()); + + MolecularAnalysisResultDto resultDto = molecularAnalysisResultRepository + .create(MolecularAnalysisResultFixture.newMolecularAnalysisResult()); + + MolecularAnalysisRunItemDto runItemDto = MolecularAnalysisRunItemTestFixture + .newMolecularAnalysisRunItem(); + runItemDto.setRun(runDto); + runItemDto.setResult(resultDto); + + runItemDto = molecularAnalysisRunItemRepository.create(runItemDto); + MetagenomicsBatchItemDto itemDto = MetagenomicsBatchItemTestFixture.newMetagenomicsBatchItem(metagenomicsBatchDto); itemDto.setPcrBatchItem(pcrBatchItemDto); + itemDto.setMolecularAnalysisRunItem(runItemDto); metagenomicsBatchItemRepository.create(itemDto); }