Skip to content

Commit

Permalink
Added PcrBatchItem rel to MetagenomicsBatchItem
Browse files Browse the repository at this point in the history
  • Loading branch information
cgendreau committed Nov 27, 2024
1 parent 5386a12 commit 380d87f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,6 +34,9 @@ public class MetagenomicsBatchItemDto {
@JsonApiRelation
private MetagenomicsBatchDto metagenomicsBatch;

@JsonApiRelation
private PcrBatchItemDto pcrBatchItem;

@JsonApiRelation
private NgsIndexDto indexI5;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
<constraints foreignKeyName="fk_metagenomics_batch_item_to_batch_id" references="metagenomics_batch(id)"/>
</column>

<column name="pcr_batch_item_id" type="integer">
<constraints foreignKeyName="fk_metagenomics_batch_item_to_pcr_batch_item" references="pcr_batch_item(id)"/>
</column>

<column name="indexi5_id" type="integer">
<constraints foreignKeyName="fk_metagenomics_batch_item_indexi5_to_ngsindex" references="ngsindexes(id)"/>
</column>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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);
Expand Down

0 comments on commit 380d87f

Please sign in to comment.